class RichTextView extends TextView implements OnLinkClickListener {

  @Override
  public void setText(CharSequence text, BufferType type) {
    text = getRichText(getContext(), text);
    // Set text first before doing anything else because setMovementMethod internally calls
    // setText. This in turn ends up calling this method with mText as the first parameter
    super.setText(text, type);
    boolean hasLinks = hasLinks(text);

    if (hasLinks) {
      // When a TextView has a movement method, it will set the view to clickable. This makes
      // View.onTouchEvent always return true and consumes the touch event, essentially
      // 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(TouchableLinkMovementMethod.getInstance());
    } else {
      setMovementMethod(null);
    }
    // ExploreByTouchHelper automatically enables focus for RichTextView
    // even though it may not have any links. Causes problems during talkback
    // as individual TextViews consume touch events and thereby reducing the focus window
    // shown by Talkback. Disable focus if there are no links
    setFocusable(hasLinks);
    // Do not "reveal" (i.e. scroll to) this view when this view is focused. Since this view is
    // focusable in touch mode, we may be focused when the screen is first shown, and starting
    // a screen halfway scrolled down is confusing to the user.
    setRevealOnFocusHint(false);
    setFocusableInTouchMode(hasLinks);
  }

  public  RichTextView(Context context);
  public  RichTextView(Context context, AttributeSet attrs);

}