@Test public void testLegacyContextOnClickListener() { Annotation link = new Annotation("link", "foobar"); SpannableStringBuilder ssb = new SpannableStringBuilder("Hello world"); ssb.setSpan(link, 1, 2, 0 ); TestContext context = spy(new TestContext(application)); RichTextView textView = new RichTextView(context); textView.setText(ssb); CharSequence text = textView.getText(); LinkSpan[] spans = ((Spanned) text).getSpans(0, text.length(), LinkSpan.class); spans[0].onClick(textView); verify(context).onClick(eq(spans[0])); }
@Override public void setText(CharSequence text, BufferType type) { text = getRichText(getContext(), text); super.setText(text, type); boolean hasLinks = hasLinks(text); if (hasLinks) { setMovementMethod(TouchableLinkMovementMethod.getInstance()); } else { setMovementMethod(null); } setFocusable(hasLinks); setRevealOnFocusHint(false); setFocusableInTouchMode(hasLinks); }
RichTextView extends TextView implements OnLinkClickListener { @Override public void setText(CharSequence text, BufferType type) { text = getRichText(getContext(), text); super.setText(text, type); boolean hasLinks = hasLinks(text); if (hasLinks) { setMovementMethod(TouchableLinkMovementMethod.getInstance()); } else { setMovementMethod(null); } setFocusable(hasLinks); setRevealOnFocusHint(false); setFocusableInTouchMode(hasLinks); } }
RichTextView extends TextView implements OnLinkClickListener { @Override public void setText(CharSequence text, BufferType type) { text = getRichText(getContext(), text); super.setText(text, type); boolean hasLinks = hasLinks(text); if (hasLinks) { setMovementMethod(TouchableLinkMovementMethod.getInstance()); } else { setMovementMethod(null); } setFocusable(hasLinks); setRevealOnFocusHint(false); setFocusableInTouchMode(hasLinks); } RichTextView(Context context);  RichTextView(Context context, AttributeSet attrs); }
RichTextView extends TextView implements OnLinkClickListener { @Override public void setText(CharSequence text, BufferType type) { text = getRichText(getContext(), text); super.setText(text, type); boolean hasLinks = hasLinks(text); if (hasLinks) { setMovementMethod(TouchableLinkMovementMethod.getInstance()); } else { setMovementMethod(null); } setFocusable(hasLinks); setRevealOnFocusHint(false); setFocusableInTouchMode(hasLinks); } RichTextView(Context context);  RichTextView(Context context, AttributeSet attrs); static CharSequence getRichText(Context context, CharSequence text); @Override void setText(CharSequence text, BufferType type); @Override @SuppressWarnings("ClickableViewAccessibility") // super.onTouchEvent is called boolean onTouchEvent(MotionEvent event); void setOnLinkClickListener(OnLinkClickListener listener); OnLinkClickListener getOnLinkClickListener(); @Override boolean onLinkClick(LinkSpan span); }
RichTextView extends TextView implements OnLinkClickListener { @Override public void setText(CharSequence text, BufferType type) { text = getRichText(getContext(), text); super.setText(text, type); boolean hasLinks = hasLinks(text); if (hasLinks) { setMovementMethod(TouchableLinkMovementMethod.getInstance()); } else { setMovementMethod(null); } setFocusable(hasLinks); setRevealOnFocusHint(false); setFocusableInTouchMode(hasLinks); } RichTextView(Context context);  RichTextView(Context context, AttributeSet attrs); static CharSequence getRichText(Context context, CharSequence text); @Override void setText(CharSequence text, BufferType type); @Override @SuppressWarnings("ClickableViewAccessibility") // super.onTouchEvent is called boolean onTouchEvent(MotionEvent event); void setOnLinkClickListener(OnLinkClickListener listener); OnLinkClickListener getOnLinkClickListener(); @Override boolean onLinkClick(LinkSpan span);  }