Search in sources :

Example 36 with SpannableStringBuilder

use of android.text.SpannableStringBuilder in project android_frameworks_base by ResurrectionRemix.

the class NumberKeyListener method filter.

public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {
    char[] accept = getAcceptedChars();
    boolean filter = false;
    int i;
    for (i = start; i < end; i++) {
        if (!ok(accept, source.charAt(i))) {
            break;
        }
    }
    if (i == end) {
        // It was all OK.
        return null;
    }
    if (end - start == 1) {
        // It was not OK, and there is only one char, so nothing remains.
        return "";
    }
    SpannableStringBuilder filtered = new SpannableStringBuilder(source, start, end);
    i -= start;
    end -= start;
    int len = end - start;
    // Only count down to i because the chars before that were all OK.
    for (int j = end - 1; j >= i; j--) {
        if (!ok(accept, source.charAt(j))) {
            filtered.delete(j, j + 1);
        }
    }
    return filtered;
}
Also used : SpannableStringBuilder(android.text.SpannableStringBuilder)

Example 37 with SpannableStringBuilder

use of android.text.SpannableStringBuilder in project android_frameworks_base by ResurrectionRemix.

the class SearchView method getDecoratedHint.

private CharSequence getDecoratedHint(CharSequence hintText) {
    // then don't add the search icon to the hint.
    if (!mIconifiedByDefault || mSearchHintIcon == null) {
        return hintText;
    }
    final int textSize = (int) (mSearchSrcTextView.getTextSize() * 1.25);
    mSearchHintIcon.setBounds(0, 0, textSize, textSize);
    final SpannableStringBuilder ssb = new SpannableStringBuilder("   ");
    ssb.setSpan(new ImageSpan(mSearchHintIcon), 1, 2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    ssb.append(hintText);
    return ssb;
}
Also used : SpannableStringBuilder(android.text.SpannableStringBuilder) ImageSpan(android.text.style.ImageSpan)

Example 38 with SpannableStringBuilder

use of android.text.SpannableStringBuilder in project android_frameworks_base by ResurrectionRemix.

the class Notification method removeTextSizeSpans.

private static CharSequence removeTextSizeSpans(CharSequence charSequence) {
    if (charSequence instanceof Spanned) {
        Spanned ss = (Spanned) charSequence;
        Object[] spans = ss.getSpans(0, ss.length(), Object.class);
        SpannableStringBuilder builder = new SpannableStringBuilder(ss.toString());
        for (Object span : spans) {
            Object resultSpan = span;
            if (resultSpan instanceof CharacterStyle) {
                resultSpan = ((CharacterStyle) span).getUnderlying();
            }
            if (resultSpan instanceof TextAppearanceSpan) {
                TextAppearanceSpan originalSpan = (TextAppearanceSpan) resultSpan;
                resultSpan = new TextAppearanceSpan(originalSpan.getFamily(), originalSpan.getTextStyle(), -1, originalSpan.getTextColor(), originalSpan.getLinkTextColor());
            } else if (resultSpan instanceof RelativeSizeSpan || resultSpan instanceof AbsoluteSizeSpan) {
                continue;
            } else {
                resultSpan = span;
            }
            builder.setSpan(resultSpan, ss.getSpanStart(span), ss.getSpanEnd(span), ss.getSpanFlags(span));
        }
        return builder;
    }
    return charSequence;
}
Also used : TextAppearanceSpan(android.text.style.TextAppearanceSpan) RelativeSizeSpan(android.text.style.RelativeSizeSpan) Spanned(android.text.Spanned) SpannableStringBuilder(android.text.SpannableStringBuilder) CharacterStyle(android.text.style.CharacterStyle) AbsoluteSizeSpan(android.text.style.AbsoluteSizeSpan)

Example 39 with SpannableStringBuilder

use of android.text.SpannableStringBuilder in project RichText by zzhoujay.

the class RichText method cache.

private static void cache(String source, SpannableStringBuilder ssb) {
    ssb = new SpannableStringBuilder(ssb);
    ssb.setSpan(new CachedSpannedParser.Cached(), 0, ssb.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    richCache.put(MD5.generate(source), new SoftReference<>(ssb));
}
Also used : CachedSpannedParser(com.zzhoujay.richtext.parser.CachedSpannedParser) SpannableStringBuilder(android.text.SpannableStringBuilder)

Example 40 with SpannableStringBuilder

use of android.text.SpannableStringBuilder in project bilibili-android-client by HotBitmapGG.

the class HomeRecommendedSection method onBindHeaderViewHolder.

@SuppressLint("SetTextI18n")
@Override
public void onBindHeaderViewHolder(RecyclerView.ViewHolder holder) {
    HeaderViewHolder headerViewHolder = (HeaderViewHolder) holder;
    setTypeIcon(headerViewHolder);
    headerViewHolder.mTypeTv.setText(title);
    headerViewHolder.mTypeRankBtn.setOnClickListener(v -> mContext.startActivity(new Intent(mContext, OriginalRankActivity.class)));
    switch(type) {
        case TYPE_RECOMMENDED:
            headerViewHolder.mTypeMore.setVisibility(View.GONE);
            headerViewHolder.mTypeRankBtn.setVisibility(View.VISIBLE);
            headerViewHolder.mAllLiveNum.setVisibility(View.GONE);
            break;
        case TYPE_LIVE:
            headerViewHolder.mTypeRankBtn.setVisibility(View.GONE);
            headerViewHolder.mTypeMore.setVisibility(View.VISIBLE);
            headerViewHolder.mAllLiveNum.setVisibility(View.VISIBLE);
            SpannableStringBuilder stringBuilder = new SpannableStringBuilder("当前" + liveCount + "个直播");
            ForegroundColorSpan foregroundColorSpan = new ForegroundColorSpan(mContext.getResources().getColor(R.color.pink_text_color));
            stringBuilder.setSpan(foregroundColorSpan, 2, stringBuilder.length() - 3, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            headerViewHolder.mAllLiveNum.setText(stringBuilder);
            break;
        default:
            headerViewHolder.mTypeRankBtn.setVisibility(View.GONE);
            headerViewHolder.mTypeMore.setVisibility(View.VISIBLE);
            headerViewHolder.mAllLiveNum.setVisibility(View.GONE);
            break;
    }
}
Also used : ForegroundColorSpan(android.text.style.ForegroundColorSpan) Intent(android.content.Intent) SpannableStringBuilder(android.text.SpannableStringBuilder) SuppressLint(android.annotation.SuppressLint)

Aggregations

SpannableStringBuilder (android.text.SpannableStringBuilder)705 TextView (android.widget.TextView)114 ForegroundColorSpan (android.text.style.ForegroundColorSpan)112 View (android.view.View)100 StyleSpan (android.text.style.StyleSpan)85 ImageSpan (android.text.style.ImageSpan)77 Test (org.junit.Test)65 SpannableString (android.text.SpannableString)55 Drawable (android.graphics.drawable.Drawable)44 TextPaint (android.text.TextPaint)43 Intent (android.content.Intent)42 Spanned (android.text.Spanned)38 RelativeSizeSpan (android.text.style.RelativeSizeSpan)38 Paint (android.graphics.Paint)34 Spannable (android.text.Spannable)33 ImageView (android.widget.ImageView)31 ArrayList (java.util.ArrayList)28 Typeface (android.graphics.Typeface)26 Context (android.content.Context)25 SuppressLint (android.annotation.SuppressLint)24