@SuppressLint("SetTextI18n") @Test public void testRichTextViewFocusChangesWithTextChange() { RichTextView textView = new RichTextView(application); textView.setText("Thou shall not be focusable!"); assertFalse(textView.isFocusable()); assertFalse(textView.isFocusableInTouchMode()); SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder("I am focusable"); spannableStringBuilder.setSpan(new Annotation("link", "focus:on_me"), 0, 1, 0); textView.setText(spannableStringBuilder); assertTrue(textView.isFocusable()); if (VERSION.SDK_INT >= VERSION_CODES.N_MR1) { assertTrue(textView.isFocusableInTouchMode()); assertFalse(textView.getRevealOnFocusHint()); } else { assertFalse(textView.isFocusableInTouchMode()); } }
@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);  }