private void addLinks(final SpannableString string,final long accountId,final long extraId,final int type,final boolean sensitive,final OnLinkClickListener listener,final int highlightOption){
switch (type) {
case LINK_TYPE_MENTION:
{
      addMentionOrListLinks(string,accountId,extraId,highlightOption,listener);
      break;
    }
case LINK_TYPE_HASHTAG:
{
    addHashtagLinks(string,accountId,extraId,listener,highlightOption);
    break;
  }
case LINK_TYPE_LINK:
{
  final URLSpan[] spans=string.getSpans(0,string.length(),URLSpan.class);
  for (  final URLSpan span : spans) {
    final int start=string.getSpanStart(span);
    final int end=string.getSpanEnd(span);
    if (start < 0 || end > string.length() || start > end) {
      continue;
    }
    string.removeSpan(span);
    applyLink(span.getURL(),start,end,string,accountId,extraId,LINK_TYPE_LINK,sensitive,highlightOption,listener);
  }
  final List<Extractor.Entity> urls=mExtractor.extractURLsWithIndices(ParseUtils.parseString(string));
  for (  final Extractor.Entity entity : urls) {
    final int start=entity.getStart(), end=entity.getEnd();
    if (entity.getType() != Extractor.Entity.Type.URL || string.getSpans(start,end,URLSpan.class).length > 0) {
      continue;
    }
    applyLink(entity.getValue(),start,end,string,accountId,extraId,LINK_TYPE_LINK,sensitive,highlightOption,listener);
  }
  break;
}
case LINK_TYPE_STATUS:
{
final URLSpan[] spans=string.getSpans(0,string.length(),URLSpan.class);
for (final URLSpan span : spans) {
  final Matcher matcher=PATTERN_TWITTER_STATUS.matcher(span.getURL());
  if (matcher.matches()) {
    final int start=string.getSpanStart(span);
    final int end=string.getSpanEnd(span);
    final String url=matcherGroup(matcher,GROUP_ID_TWITTER_STATUS_STATUS_ID);
    string.removeSpan(span);
    applyLink(url,start,end,string,accountId,extraId,LINK_TYPE_STATUS,sensitive,highlightOption,listener);
  }
}
break;
}
case LINK_TYPE_CASHTAG:
{
addCashtagLinks(string,accountId,extraId,listener,highlightOption);
break;
}
default :
{
return;
}
}
}

private void addLinks ( final SpannableString string , final long accountId , final long extraId , final int type , final boolean sensitive , final OnLinkClickListener listener , final int highlightOption ) { switch ( type ) { case LINK_TYPE_MENTION : { addMentionOrListLinks ( string , accountId , extraId , highlightOption , listener ) ; break ; } case LINK_TYPE_HASHTAG : { addHashtagLinks ( string , accountId , extraId , listener , highlightOption ) ; break ; } case LINK_TYPE_LINK : { final URLSpan [ ] spans = string . getSpans ( 0 , string . length ( ) , URLSpan . class ) ; for ( final URLSpan span : spans ) { final int start = string . getSpanStart ( span ) ; final int end = string . getSpanEnd ( span ) ; if ( start < 0 || end > string . length ( ) || start > end ) { continue ; } string . removeSpan ( span ) ; applyLink ( span . getURL ( ) , start , end , string , accountId , extraId , LINK_TYPE_LINK , sensitive , highlightOption , listener ) ; } final List < Extractor . Entity > urls = mExtractor . extractURLsWithIndices ( ParseUtils . parseString ( string ) ) ; for ( final Extractor . Entity entity : urls ) { final int start = entity . getStart ( ) , end = entity . getEnd ( ) ; if ( entity . getType ( ) != Extractor . Entity . Type . URL || string . getSpans ( start , end , URLSpan . class ) . length > 0 ) { continue ; } applyLink ( entity . getValue ( ) , start , end , string , accountId , extraId , LINK_TYPE_LINK , sensitive , highlightOption , listener ) ; } break ; } case LINK_TYPE_STATUS : { final URLSpan [ ] spans = string . getSpans ( 0 , string . length ( ) , URLSpan . class ) ; for ( final URLSpan span : spans ) { final Matcher matcher = PATTERN_TWITTER_STATUS . matcher ( span . getURL ( ) ) ; if ( matcher . matches ( ) ) { final int start = string . getSpanStart ( span ) ; final int end = string . getSpanEnd ( span ) ; final String url = matcherGroup ( matcher , GROUP_ID_TWITTER_STATUS_STATUS_ID ) ; string . removeSpan ( span ) ; applyLink ( url , start , end , string , accountId , extraId , LINK_TYPE_STATUS , sensitive , highlightOption , listener ) ; } } break ; } case LINK_TYPE_CASHTAG : { addCashtagLinks ( string , accountId , extraId , listener , highlightOption ) ; break ; } default : { return ; } } }
applies a regex to the text of a textview turning the matches into links . if links are found then urlspans are applied to the link text match areas , and the movement method for the text is changed to linkmovementmethod .
