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
This commit is contained in:
Andrei Stingaceanu
2017-02-06 17:03:28 +00:00
parent 6c149326d8
commit f0ebee91f8
2 changed files with 2 additions and 2 deletions

View File

@@ -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 {

View File

@@ -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(),