Example usage for android.text Spannable subSequence

List of usage examples for android.text Spannable subSequence

Introduction

In this page you can find the example usage for android.text Spannable subSequence.

Prototype

CharSequence subSequence(int start, int end);

Source Link

Document

Returns a CharSequence that is a subsequence of this sequence.

Usage

From source file:com.silentcircle.common.util.ViewUtil.java

public static Intent createIntentForLinks(TextView view) {

    CharSequence text = view.getText();

    if (text instanceof Spannable) {

        Spannable stext = (Spannable) text;
        URLSpan[] spans = stext.getSpans(0, stext.length(), URLSpan.class);

        if (spans != null && spans.length > 0) {
            ChooserBuilder chooser = new ChooserBuilder(view.getContext());
            chooser.label(R.string.view);
            for (URLSpan span : spans) {
                String url = span.getURL();
                CharSequence label = stext.subSequence(stext.getSpanStart(span), stext.getSpanEnd(span));
                chooser.intent(new Intent(Intent.ACTION_VIEW, Uri.parse(url)), label);
            }/*from w  ww.  j  a  va 2  s.c  o  m*/
            return chooser.build();

        }
    }
    return null;
}

From source file:com.dwdesign.tweetings.activity.ComposeActivity.java

private final void gatherLinks(ArrayList<Hyperlink> links, Spannable s, Pattern pattern) {
    // Matcher matching the pattern
    Matcher m = pattern.matcher(s);

    while (m.find()) {
        int start = m.start();
        int end = m.end();

        /*//www . j a va  2  s .co  m
        *  Hyperlink is basically used like a structure for storing the information about
        *  where the link was found.
        */
        Hyperlink spec = new Hyperlink();

        spec.textSpan = s.subSequence(start, end);
        spec.span = new InternalURLSpan(spec.textSpan.toString());
        spec.start = start;
        spec.end = end;

        links.add(spec);
    }
}