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;
}
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;
}
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;
}
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));
}
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;
}
}
Aggregations