From 068976dad49bb9ec1b67eeb71f2a55b508ac7ab6 Mon Sep 17 00:00:00 2001 From: Saket Narayan Date: Sun, 18 Feb 2018 19:00:17 +0530 Subject: [PATCH] #9: avoid starting a long-press timer if touch does not start on a ClickableSpan --- .../bettermovementmethod/BetterLinkMovementMethod.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/better-link-movement-method/src/main/java/me/saket/bettermovementmethod/BetterLinkMovementMethod.java b/better-link-movement-method/src/main/java/me/saket/bettermovementmethod/BetterLinkMovementMethod.java index ea7477f..97a6441 100644 --- a/better-link-movement-method/src/main/java/me/saket/bettermovementmethod/BetterLinkMovementMethod.java +++ b/better-link-movement-method/src/main/java/me/saket/bettermovementmethod/BetterLinkMovementMethod.java @@ -214,6 +214,9 @@ public boolean onTouchEvent(final TextView textView, Spannable text, MotionEvent } final ClickableSpan clickableSpanUnderTouch = findClickableSpanUnderTouch(textView, text, event); + if (event.getAction() == MotionEvent.ACTION_DOWN) { + clickableSpanUnderTouchOnActionDown = clickableSpanUnderTouch; + } final boolean touchStartedOverALink = clickableSpanUnderTouchOnActionDown != null; switch (event.getAction()) { @@ -234,8 +237,6 @@ public void onTimerReached() { }; startTimerForRegisteringLongClick(textView, longClickListener); } - - clickableSpanUnderTouchOnActionDown = clickableSpanUnderTouch; return touchStartedOverALink; case MotionEvent.ACTION_UP: @@ -278,6 +279,7 @@ public void onTimerReached() { private void cleanupOnTouchUp(TextView textView) { wasLongPressRegistered = false; + clickableSpanUnderTouchOnActionDown = null; removeUrlHighlightColor(textView); removeLongPressCallback(textView); }