Skip to content
This repository was archived by the owner on Apr 24, 2018. It is now read-only.

Commit 37e2b8a

Browse files
committed
Merge pull request #304 from martinbonnin/allow_to_add_the_showcase_view_to_a_custom_parent
Allow to add the showcase view to a custom parent
2 parents f9556fe + 946b1e8 commit 37e2b8a

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

library/src/main/java/com/github/amlcurran/showcaseview/ShowcaseView.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -358,8 +358,8 @@ public boolean onTouch(View view, MotionEvent motionEvent) {
358358
return blockTouches && distanceFromFocus > showcaseDrawer.getBlockedRadius();
359359
}
360360

361-
private static void insertShowcaseView(ShowcaseView showcaseView, Activity activity) {
362-
((ViewGroup) activity.getWindow().getDecorView()).addView(showcaseView);
361+
private static void insertShowcaseView(ShowcaseView showcaseView, ViewGroup parent, int parentIndex) {
362+
parent.addView(showcaseView, parentIndex);
363363
if (!showcaseView.hasShot()) {
364364
showcaseView.show();
365365
} else {
@@ -403,6 +403,9 @@ public static class Builder {
403403
final ShowcaseView showcaseView;
404404
private final Activity activity;
405405

406+
private ViewGroup parent;
407+
private int parentIndex;
408+
406409
public Builder(Activity activity) {
407410
this(activity, false);
408411
}
@@ -417,6 +420,9 @@ public Builder(Activity activity, boolean useNewStyle) {
417420
this.activity = activity;
418421
this.showcaseView = new ShowcaseView(activity, useNewStyle);
419422
this.showcaseView.setTarget(Target.NONE);
423+
424+
this.parent = ((ViewGroup) activity.getWindow().getDecorView());
425+
this.parentIndex = -1;
420426
}
421427

422428
/**
@@ -425,7 +431,7 @@ public Builder(Activity activity, boolean useNewStyle) {
425431
* @return the created ShowcaseView
426432
*/
427433
public ShowcaseView build() {
428-
insertShowcaseView(showcaseView, activity);
434+
insertShowcaseView(showcaseView, parent, parentIndex);
429435
return showcaseView;
430436
}
431437

@@ -559,6 +565,12 @@ public Builder setShowcaseEventListener(OnShowcaseEventListener showcaseEventLis
559565
return this;
560566
}
561567

568+
public Builder setParent(ViewGroup parent, int index) {
569+
this.parent = parent;
570+
this.parentIndex = index;
571+
return this;
572+
}
573+
562574
/**
563575
* Sets the paint that will draw the text as specified by {@link #setContentText(CharSequence)}
564576
* or {@link #setContentText(int)}

0 commit comments

Comments
 (0)