Search in sources :

Example 66 with URLSpan

use of android.text.style.URLSpan in project J2ME-Loader by nikita36078.

the class StringItem method getItemContentView.

@Override
public View getItemContentView() {
    if (textview == null) {
        Context context = getOwnerForm().getParentActivity();
        if (appearanceMode == BUTTON) {
            textview = new AppCompatButton(context);
        } else {
            textview = new AppCompatTextView(context);
        }
        textview.setTextAppearance(context, android.R.style.TextAppearance_Small);
        if (appearanceMode == HYPERLINK && text != null) {
            SpannableStringBuilder s = new SpannableStringBuilder(text);
            s.setSpan(new URLSpan(text), 0, s.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
            textview.setText(s);
        } else {
            textview.setText(text);
        }
        textview.setOnClickListener(v -> fireDefaultCommandAction());
    }
    return textview;
}
Also used : Context(android.content.Context) AppCompatTextView(androidx.appcompat.widget.AppCompatTextView) URLSpan(android.text.style.URLSpan) SpannableStringBuilder(android.text.SpannableStringBuilder) AppCompatButton(androidx.appcompat.widget.AppCompatButton)

Example 67 with URLSpan

use of android.text.style.URLSpan in project actor-platform by actorapp.

the class ChatListProcessor method fixLinkifyCustomLinks.

private boolean fixLinkifyCustomLinks(Spannable spannable, Pattern p, boolean isMention) {
    Matcher m = p.matcher(spannable.toString());
    boolean res = false;
    while (m.find()) {
        boolean found = false;
        String nick = "";
        UserVM user;
        int userId = 0;
        if (isGroup) {
            for (GroupMember member : group.getMembers().get()) {
                user = users().get(member.getUid());
                nick = user.getNick().get();
                if (nick != null && !nick.isEmpty() && nick.equals(m.group().substring(1, m.group().length()))) {
                    userId = user.getId();
                    found = true;
                    break;
                }
            }
        }
        if (isMention && !found) {
            return false;
        }
        URLSpan span = (isMention && isGroup && found) ? new MentionSpan(nick, userId, false) : new BaseUrlSpan(m.group(), false);
        spannable.setSpan(span, m.start(), m.end(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        res = true;
    }
    return res;
}
Also used : GroupMember(im.actor.core.entity.GroupMember) UserVM(im.actor.core.viewmodel.UserVM) Matcher(java.util.regex.Matcher) MentionSpan(im.actor.sdk.controllers.conversation.view.MentionSpan) BaseUrlSpan(im.actor.sdk.view.BaseUrlSpan) SpannableString(android.text.SpannableString) URLSpan(android.text.style.URLSpan)

Example 68 with URLSpan

use of android.text.style.URLSpan in project platform_frameworks_base by android.

the class LinkSpec method applyLink.

private static final void applyLink(String url, int start, int end, Spannable text) {
    URLSpan span = new URLSpan(url);
    text.setSpan(span, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
Also used : URLSpan(android.text.style.URLSpan)

Example 69 with URLSpan

use of android.text.style.URLSpan in project plaid by nickbutcher.

the class HtmlUtils method linkifyPlainLinks.

private static SpannableStringBuilder linkifyPlainLinks(CharSequence input, ColorStateList linkTextColor, @ColorInt int linkHighlightColor) {
    // copy of input
    final SpannableString plainLinks = new SpannableString(input);
    // Linkify doesn't seem to work as expected on M+
    // TODO: figure out why
    //Linkify.addLinks(plainLinks, Linkify.WEB_URLS);
    final URLSpan[] urlSpans = plainLinks.getSpans(0, plainLinks.length(), URLSpan.class);
    // add any plain links to the output
    final SpannableStringBuilder ssb = new SpannableStringBuilder(input);
    for (URLSpan urlSpan : urlSpans) {
        ssb.removeSpan(urlSpan);
        ssb.setSpan(new TouchableUrlSpan(urlSpan.getURL(), linkTextColor, linkHighlightColor), plainLinks.getSpanStart(urlSpan), plainLinks.getSpanEnd(urlSpan), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
    return ssb;
}
Also used : SpannableString(android.text.SpannableString) TouchableUrlSpan(in.uncod.android.bypass.style.TouchableUrlSpan) URLSpan(android.text.style.URLSpan) SpannableStringBuilder(android.text.SpannableStringBuilder)

Example 70 with URLSpan

use of android.text.style.URLSpan in project android_frameworks_base by ParanoidAndroid.

the class HtmlToSpannedConverter method endA.

private static void endA(SpannableStringBuilder text) {
    int len = text.length();
    Object obj = getLast(text, Href.class);
    int where = text.getSpanStart(obj);
    text.removeSpan(obj);
    if (where != len) {
        Href h = (Href) obj;
        if (h.mHref != null) {
            text.setSpan(new URLSpan(h.mHref), where, len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
    }
}
Also used : URLSpan(android.text.style.URLSpan)

Aggregations

URLSpan (android.text.style.URLSpan)134 SpannableString (android.text.SpannableString)36 Spannable (android.text.Spannable)22 SpannableStringBuilder (android.text.SpannableStringBuilder)21 TextPaint (android.text.TextPaint)21 Spanned (android.text.Spanned)20 TextView (android.widget.TextView)19 ForegroundColorSpan (android.text.style.ForegroundColorSpan)16 StyleSpan (android.text.style.StyleSpan)16 UnderlineSpan (android.text.style.UnderlineSpan)14 Paint (android.graphics.Paint)13 ImageSpan (android.text.style.ImageSpan)13 StrikethroughSpan (android.text.style.StrikethroughSpan)13 TypefaceSpan (android.text.style.TypefaceSpan)13 View (android.view.View)13 Intent (android.content.Intent)12 AbsoluteSizeSpan (android.text.style.AbsoluteSizeSpan)12 BackgroundColorSpan (android.text.style.BackgroundColorSpan)12 ClickableSpan (android.text.style.ClickableSpan)12 SubscriptSpan (android.text.style.SubscriptSpan)12