summaryrefslogtreecommitdiff
path: root/com/android/setupwizardlib/view/RichTextView.java
diff options
context:
space:
mode:
Diffstat (limited to 'com/android/setupwizardlib/view/RichTextView.java')
-rw-r--r--com/android/setupwizardlib/view/RichTextView.java25
1 files changed, 23 insertions, 2 deletions
diff --git a/com/android/setupwizardlib/view/RichTextView.java b/com/android/setupwizardlib/view/RichTextView.java
index aab3238b..fa68a68f 100644
--- a/com/android/setupwizardlib/view/RichTextView.java
+++ b/com/android/setupwizardlib/view/RichTextView.java
@@ -20,16 +20,18 @@ import android.content.Context;
import android.text.Annotation;
import android.text.SpannableString;
import android.text.Spanned;
-import android.text.method.LinkMovementMethod;
+import android.text.method.MovementMethod;
import android.text.style.ClickableSpan;
import android.text.style.TextAppearanceSpan;
import android.util.AttributeSet;
import android.util.Log;
+import android.view.MotionEvent;
import android.widget.TextView;
import com.android.setupwizardlib.span.LinkSpan;
import com.android.setupwizardlib.span.LinkSpan.OnLinkClickListener;
import com.android.setupwizardlib.span.SpanHelper;
+import com.android.setupwizardlib.view.TouchableMovementMethod.TouchableLinkMovementMethod;
/**
* An extension of TextView that automatically replaces the annotation tags as specified in
@@ -112,7 +114,7 @@ public class RichTextView extends TextView implements OnLinkClickListener {
// nullifying any return values of MovementMethod.onTouchEvent.
// To still allow propagating touch events to the parent when this view doesn't have
// links, we only set the movement method here if the text contains links.
- setMovementMethod(LinkMovementMethod.getInstance());
+ setMovementMethod(TouchableLinkMovementMethod.getInstance());
} else {
setMovementMethod(null);
}
@@ -137,6 +139,25 @@ public class RichTextView extends TextView implements OnLinkClickListener {
return false;
}
+ @Override
+ @SuppressWarnings("ClickableViewAccessibility") // super.onTouchEvent is called
+ public boolean onTouchEvent(MotionEvent event) {
+ // Since View#onTouchEvent always return true if the view is clickable (which is the case
+ // when a TextView has a movement method), override the implementation to allow the movement
+ // method, if it implements TouchableMovementMethod, to say that the touch is not handled,
+ // allowing the event to bubble up to the parent view.
+ boolean superResult = super.onTouchEvent(event);
+ MovementMethod movementMethod = getMovementMethod();
+ if (movementMethod instanceof TouchableMovementMethod) {
+ TouchableMovementMethod touchableMovementMethod =
+ (TouchableMovementMethod) movementMethod;
+ if (touchableMovementMethod.getLastTouchEvent() == event) {
+ return touchableMovementMethod.isLastTouchEventHandled();
+ }
+ }
+ return superResult;
+ }
+
public void setOnLinkClickListener(OnLinkClickListener listener) {
mOnLinkClickListener = listener;
}