From d1aa6dbb2661a85171ef75826563f19a178289d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20den=20Berg?= Date: Sat, 14 May 2016 21:50:04 +0200 Subject: [PATCH 1/2] Added a "setHideOnTouchTarget" option. Added a "setHideOnTouchTarget" option, which allows for hiding when the specified target is touched. --- .../amlcurran/showcaseview/ShowcaseView.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) 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..20ea62fa0 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,10 @@ public boolean onTouch(View view, MotionEvent motionEvent) { if (blocked) { mEventListener.onShowcaseViewTouchBlocked(motionEvent); } + + if (hideOnTouchTarget && distanceFromFocus <= showcaseDrawer.getBlockedRadius()) { + this.hide(); + } return blocked; } @@ -538,6 +547,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. From 14da45607ef3f74f6f83a5070f6dea2446346a44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20den=20Berg?= Date: Sun, 15 May 2016 17:56:18 +0200 Subject: [PATCH 2/2] Only trigger this.hide() once Made sure that this.hide() only gets triggered on MotionEvent.ACTION_UP --- .../java/com/github/amlcurran/showcaseview/ShowcaseView.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 20ea62fa0..c534ebea6 100644 --- a/library/src/main/java/com/github/amlcurran/showcaseview/ShowcaseView.java +++ b/library/src/main/java/com/github/amlcurran/showcaseview/ShowcaseView.java @@ -391,7 +391,8 @@ public boolean onTouch(View view, MotionEvent motionEvent) { mEventListener.onShowcaseViewTouchBlocked(motionEvent); } - if (hideOnTouchTarget && distanceFromFocus <= showcaseDrawer.getBlockedRadius()) { + if (MotionEvent.ACTION_UP == motionEvent.getAction() && + hideOnTouchTarget && distanceFromFocus <= showcaseDrawer.getBlockedRadius()) { this.hide(); } return blocked;