diff --git a/library/src/main/java/com/github/amlcurran/showcaseview/ShowcaseView.java b/library/src/main/java/com/github/amlcurran/showcaseview/ShowcaseView.java index 9c9746714..c534ebea6 100644 --- a/library/src/main/java/com/github/amlcurran/showcaseview/ShowcaseView.java +++ b/library/src/main/java/com/github/amlcurran/showcaseview/ShowcaseView.java @@ -79,6 +79,7 @@ public class ShowcaseView extends RelativeLayout private boolean hasCustomClickListener = false; private boolean blockTouches = true; private boolean hideOnTouch = false; + private boolean hideOnTouchTarget = false; private OnShowcaseEventListener mEventListener = OnShowcaseEventListener.NONE; private boolean hasAlteredText = false; @@ -274,6 +275,10 @@ public void setButtonText(CharSequence text) { mEndButton.setText(text); } } + + public void setHideOnTouchTarget(boolean hideOnTouchTarget){ + this.hideOnTouchTarget = hideOnTouchTarget; + } private void recalculateText() { boolean recalculatedCling = showcaseAreaCalculator.calculateShowcaseRect(showcaseX, showcaseY, showcaseDrawer); @@ -385,6 +390,11 @@ public boolean onTouch(View view, MotionEvent motionEvent) { if (blocked) { mEventListener.onShowcaseViewTouchBlocked(motionEvent); } + + if (MotionEvent.ACTION_UP == motionEvent.getAction() && + hideOnTouchTarget && distanceFromFocus <= showcaseDrawer.getBlockedRadius()) { + this.hide(); + } return blocked; } @@ -538,6 +548,19 @@ public Builder setTarget(Target target) { showcaseView.setTarget(target); return this; } + + + /** + * Set whether the showcase should hide when the target is touched. + * + * @param hideOnTouchTarget true if this showcase should hide when the specified target is + * touched. The showcase will hide when a touch is performed anywhere inside the + * focus area. + */ + public Builder setHideOnTouchTarget(boolean hideOnTouchTarget){ + showcaseView.setHideOnTouchTarget(hideOnTouchTarget); + return this; + } /** * Set the style of the ShowcaseView. See the sample app for example styles.