From f0ebee91f86eafc1fb7b4c377f3cd1d6ce3fe38e Mon Sep 17 00:00:00 2001 From: Andrei Stingaceanu Date: Mon, 6 Feb 2017 17:03:28 +0000 Subject: [PATCH] Clickable spans - trigger onClick onSingleTapUp Previously (post Android N) we decided to introduce a gesture detector in textView and trigger the onClick() over a clickable span when onSingleTapConfirmed was called. The problem is that onSingleTapConfirmed also waits for double tap timeout to make sure (to confirm). This has a chance to break some apps so relax the rule to only look for onSingleTapUp. * the bug for which the initial change was made is still fixed * slightly amended the ClickableSpan JavaDoc to specify that the onClick gets triggered if the span is selected when clicked (note that this behavior is unchanged since ClickableSpan exists, added just an extra hint to devs) Bug: 23692690 Test: in the attached CL (same topic) Change-Id: Iead434aa558301d61879c27edc48dc4148ca187f --- core/java/android/text/style/ClickableSpan.java | 2 +- core/java/android/widget/TextView.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/core/java/android/text/style/ClickableSpan.java b/core/java/android/text/style/ClickableSpan.java index a183427a44d0b..b098f16da1eda 100644 --- a/core/java/android/text/style/ClickableSpan.java +++ b/core/java/android/text/style/ClickableSpan.java @@ -22,7 +22,7 @@ import android.view.View; /** * If an object of this type is attached to the text of a TextView * with a movement method of LinkMovementMethod, the affected spans of - * text can be selected. If clicked, the {@link #onClick} method will + * text can be selected. If selected and clicked, the {@link #onClick} method will * be called. */ public abstract class ClickableSpan extends CharacterStyle implements UpdateAppearance { diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java index 4a8ec94962d14..a5ff29119dc9d 100644 --- a/core/java/android/widget/TextView.java +++ b/core/java/android/widget/TextView.java @@ -9639,7 +9639,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener return new GestureDetector(mContext, new GestureDetector.SimpleOnGestureListener() { @Override - public boolean onSingleTapConfirmed(MotionEvent e) { + public boolean onSingleTapUp(MotionEvent e) { if (shouldUseClickableSpanOnClickGestureDetector()) { ClickableSpan[] links = ((Spannable) mText).getSpans( getSelectionStart(), getSelectionEnd(),