Example usage for android.text.style URLSpan URLSpan

List of usage examples for android.text.style URLSpan URLSpan

Introduction

In this page you can find the example usage for android.text.style URLSpan URLSpan.

Prototype

public URLSpan(@NonNull Parcel src) 

Source Link

Document

Constructs a URLSpan from a parcel.

Usage

From source file:Main.java

public static void makeTextViewHyperlink(TextView tv) {
    SpannableStringBuilder ssb = new SpannableStringBuilder();
    ssb.append(tv.getText());/*from w w  w.ja v a2 s .c  o  m*/
    ssb.setSpan(new URLSpan("#"), 0, ssb.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    tv.setText(ssb, TextView.BufferType.SPANNABLE);
}

From source file:Main.java

public static SpannableString setTextURL(String content, int startIndex, int endIndex, String url) {
    if (TextUtils.isEmpty(content) || startIndex < 0 || endIndex >= content.length()
            || startIndex >= endIndex) {
        return null;
    }/*from  w  w  w. ja v a2  s  . c  o m*/

    SpannableString spannableString = new SpannableString(content);
    spannableString.setSpan(new URLSpan(url), startIndex, endIndex, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    return spannableString;
}

From source file:Main.java

public static CharSequence handleAcUrl(CharSequence content) {
    Matcher m = AC_PATTERN.matcher(content);

    Spannable spannable = null;/*from   w  w w .j a v  a  2  s.  co m*/
    while (m.find()) {
        // Ensure spannable
        if (spannable == null) {
            if (content instanceof Spannable) {
                spannable = (Spannable) content;
            } else {
                spannable = new SpannableString(content);
            }
        }

        int start = m.start();
        int end = m.end();

        URLSpan[] links = spannable.getSpans(start, end, URLSpan.class);
        if (links.length > 0) {
            // There has been URLSpan already, leave it alone
            continue;
        }

        URLSpan urlSpan = new URLSpan("http://www.acfun.tv/v/" + m.group(0));
        spannable.setSpan(urlSpan, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    }

    return spannable == null ? content : spannable;
}

From source file:Main.java

public static CharSequence handleTextUrl(CharSequence content) {
    Matcher m = URL_PATTERN.matcher(content);

    Spannable spannable = null;/*from   w  w w  .  j ava2s .co m*/
    while (m.find()) {
        // Ensure spannable
        if (spannable == null) {
            if (content instanceof Spannable) {
                spannable = (Spannable) content;
            } else {
                spannable = new SpannableString(content);
            }
        }

        int start = m.start();
        int end = m.end();

        URLSpan[] links = spannable.getSpans(start, end, URLSpan.class);
        if (links.length > 0) {
            // There has been URLSpan already, leave it alone
            continue;
        }

        URLSpan urlSpan = new URLSpan(m.group(0));
        spannable.setSpan(urlSpan, start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    }

    return spannable == null ? content : spannable;
}

From source file:com.robomorphine.fragment.AboutDialogFragment.java

private CharSequence linkify(String text, String link) {
    SpannableStringBuilder builder = new SpannableStringBuilder();
    URLSpan span = new URLSpan(link);

    builder.append(text);//w  w  w  .j a v a2 s.  c  om
    builder.setSpan(span, 0, builder.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
    return builder;
}

From source file:org.mariotaku.twidere.util.HtmlSpanBuilder.java

private static Object createSpan(TagInfo info) {
    switch (info.name.toLowerCase(Locale.US)) {
    case "a": {
        return new URLSpan(info.getAttribute("href"));
    }/*from w w  w.j  a  v a 2s .  c o  m*/
    case "b":
    case "strong": {
        return new StyleSpan(Typeface.BOLD);
    }
    case "em":
    case "cite":
    case "dfn":
    case "i": {
        return new StyleSpan(Typeface.ITALIC);
    }
    }
    return null;
}

From source file:cl.monsoon.s1next.binding.TextViewBindingAdapter.java

@BindingAdapter({ "eventBus", "post" })
public static void setCount(TextView textView, EventBus eventBus, Post post) {
    String text = "#" + post.getCount();
    // there is no need to quote #1
    if ("1".equals(post.getCount())) {
        textView.setText(text);//from  w ww.  j a  v a2 s  . co m
    } else {
        Spannable spannable = new SpannableString(text);
        URLSpan urlSpan = new URLSpan(StringUtils.EMPTY) {
            @Override
            public void onClick(@NonNull View widget) {
                eventBus.post(new QuoteEvent(post.getId(), post.getCount()));
            }
        };
        spannable.setSpan(urlSpan, 0, spannable.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        textView.setText(spannable);
    }
}

From source file:codepath.watsiapp.utils.Util.java

/**
 * Sets a hyperlink style to the textview.
 *///from  w  ww.ja  v a2s.  c  o m
public static void makeTextViewHyperlink(TextView tv) {
    SpannableStringBuilder ssb = new SpannableStringBuilder();
    ssb.append(tv.getText());
    ssb.setSpan(new URLSpan("#"), 0, ssb.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    tv.setText(ssb, TextView.BufferType.SPANNABLE);
}

From source file:com.pocketsoap.admin.UserDetailFragment.java

private void bindUi() {
    // header section
    setText(R.id.detail_name, user.Name);
    setText(R.id.detail_username, user.Username);
    setText(R.id.detail_title, user.Title);

    // contact section
    setText(R.id.contact_email, user.Email);
    setText(R.id.contact_phone, user.Phone);
    setText(R.id.contact_mobile, user.MobilePhone);

    // no auto link for SMS, so we need to build our own URLSpan for it.
    if (user.MobilePhone != null && user.MobilePhone.length() > 0) {
        SpannableStringBuilder b = new SpannableStringBuilder(user.MobilePhone);
        b.setSpan(new URLSpan("smsto:" + user.MobilePhone), 0, user.MobilePhone.length(),
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        setText(R.id.contact_mobile_text, b).setMovementMethod(LinkMovementMethod.getInstance());
    } else {//from  w w  w  .j av a  2  s. co m
        setText(R.id.contact_mobile_text, "");
    }

    //action section
    isActive.setChecked(user.IsActive);
    isActive.setOnClickListener(new ToggleActive());

    // user photo
    // the default person image is https://blah/.../005/T but we don't want to bother fetching that, we'll just use our local default instead.
    if (user.SmallPhotoUrl != null && user.SmallPhotoUrl.length() > 0
            && !user.SmallPhotoUrl.endsWith("/005/T")) {
        PhotoLoaderTask photoLoader = new PhotoLoaderTask(getActivityHelper());
        photoLoader.execute(user.SmallPhotoUrl);
    } else {
        this.userPhoto.setImageResource(R.drawable.ic_contact_picture);
    }
}

From source file:eu.lucazanini.arpav.fragment.CreditsFragment.java

private SpannableString getTextWithLink(SpannableString text, String link, String site) {
    int start = text.toString().indexOf(link);
    int end = start + link.length();
    text.setSpan(new URLSpan(site), start, end, 0);
    return text;/*from  www  . j  av a 2  s  . c  o m*/
}