Search in sources :

Example 11 with StyleSpan

use of android.text.style.StyleSpan in project Signal-Android by WhisperSystems.

the class SpanUtil method bold.

public static CharSequence bold(CharSequence sequence) {
    SpannableString spannable = new SpannableString(sequence);
    spannable.setSpan(new StyleSpan(Typeface.BOLD), 0, sequence.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    return spannable;
}
Also used : SpannableString(android.text.SpannableString) StyleSpan(android.text.style.StyleSpan)

Example 12 with StyleSpan

use of android.text.style.StyleSpan in project remusic by aa112901.

the class TintProgressDialog method handleMessage.

@Override
public boolean handleMessage(Message msg) {
    /* Update the number and percent */
    int progress = mProgress.getProgress();
    int max = mProgress.getMax();
    if (mProgressNumberFormat != null) {
        String format = mProgressNumberFormat;
        mProgressNumber.setText(String.format(format, progress, max));
    } else {
        mProgressNumber.setText("");
    }
    if (mProgressPercentFormat != null) {
        double percent = (double) progress / (double) max;
        SpannableString tmp = new SpannableString(mProgressPercentFormat.format(percent));
        tmp.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 0, tmp.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        mProgressPercent.setText(tmp);
    } else {
        mProgressPercent.setText("");
    }
    return true;
}
Also used : SpannableString(android.text.SpannableString) StyleSpan(android.text.style.StyleSpan) SpannableString(android.text.SpannableString)

Example 13 with StyleSpan

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

the class AndroidNotifications method getNotificationTextFull.

private CharSequence getNotificationTextFull(Notification notification, Messenger messenger) {
    SpannableStringBuilder res = new SpannableStringBuilder();
    if (!messenger.getFormatter().isLargeDialogMessage(notification.getContentDescription().getContentType())) {
        res.append(getNotificationSender(notification));
        res.append(": ");
        res.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), 0, res.length(), 0);
    }
    res.append(messenger.getFormatter().formatNotificationText(notification));
    return res;
}
Also used : StyleSpan(android.text.style.StyleSpan) SpannableStringBuilder(android.text.SpannableStringBuilder)

Example 14 with StyleSpan

use of android.text.style.StyleSpan in project LuaViewSDK by alibaba.

the class UDSpannableString method initSpannableStringBuilder.

private void initSpannableStringBuilder(LuaValue text, LuaValue config) {
    SpannableStringBuilder spannableStringBuilder = getSpannableStringBuilder();
    if (text != null && text.isstring()) {
        spannableStringBuilder = spannableStringBuilder.append(text.tojstring());
    }
    if (spannableStringBuilder.length() > 0) {
        if (config != null && config.istable()) {
            final int end = spannableStringBuilder.length();
            final int fontSize = DimenUtil.spToPx(config.get("fontSize").optint(-1));
            final Integer fontColor = ColorUtil.parse(LuaUtil.getValue(config, "fontColor"));
            final String fontName = config.get("fontName").optjstring(null);
            final LuaValue weightValue = config.get("fontWeight");
            final int fontWeight = LuaUtil.isNumber(weightValue) ? weightValue.optint(UDFontWeight.WEIGHT_NORMAL_INT) : UDFontWeight.getValue(weightValue.optjstring(UDFontWeight.WEIGHT_NORMAL));
            final LuaValue styleValue = config.get("fontStyle");
            final int fontStyle = LuaUtil.isNumber(styleValue) ? styleValue.optint(Typeface.NORMAL) : UDFontStyle.getValue(styleValue.optjstring(UDFontStyle.STYLE_NORMAL));
            final Integer backgroundColor = ColorUtil.parse(LuaUtil.getValue(config, "backgroundColor"));
            final boolean strikethrough = config.get("strikethrough").optboolean(false);
            final boolean underline = config.get("underline").optboolean(false);
            if (fontSize != -1) {
                //字体大小
                spannableStringBuilder.setSpan(new AbsoluteSizeSpan(fontSize), 0, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            }
            if (fontColor != null) {
                //字体颜色
                spannableStringBuilder.setSpan(new ForegroundColorSpan(fontColor), 0, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            }
            if (fontName != null && getLuaResourceFinder() != null) {
                //字体
                spannableStringBuilder.setSpan(new CustomTypefaceSpan(fontName, getLuaResourceFinder().findTypeface(fontName)), 0, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            }
            if (fontWeight != -1 && fontWeight > UDFontWeight.WEIGHT_NORMAL_INT) {
                //文字Weight
                spannableStringBuilder.setSpan(new WeightStyleSpan(fontWeight), 0, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            }
            if (fontStyle != -1 && (fontStyle >= Typeface.NORMAL && fontStyle <= Typeface.BOLD_ITALIC)) {
                //文字样式
                spannableStringBuilder.setSpan(new StyleSpan(fontStyle), 0, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            }
            if (backgroundColor != null) {
                //背景色
                spannableStringBuilder.setSpan(new BackgroundColorSpan(backgroundColor), 0, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            }
            if (strikethrough) {
                //删除线
                spannableStringBuilder.setSpan(new StrikethroughSpan(), 0, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            }
            if (underline) {
                //下划线
                spannableStringBuilder.setSpan(new UnderlineSpan(), 0, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            }
        }
    }
}
Also used : ForegroundColorSpan(android.text.style.ForegroundColorSpan) CustomTypefaceSpan(com.taobao.luaview.extend.CustomTypefaceSpan) WeightStyleSpan(com.taobao.luaview.extend.WeightStyleSpan) UnderlineSpan(android.text.style.UnderlineSpan) AbsoluteSizeSpan(android.text.style.AbsoluteSizeSpan) StyleSpan(android.text.style.StyleSpan) WeightStyleSpan(com.taobao.luaview.extend.WeightStyleSpan) LuaValue(org.luaj.vm2.LuaValue) SpannableStringBuilder(android.text.SpannableStringBuilder) BackgroundColorSpan(android.text.style.BackgroundColorSpan) StrikethroughSpan(android.text.style.StrikethroughSpan)

Example 15 with StyleSpan

use of android.text.style.StyleSpan in project materialistic by hidroh.

the class HackerNewsItem method createAuthorSpannable.

@NonNull
private SpannableString createAuthorSpannable(boolean authorLink) {
    SpannableString bySpannable = new SpannableString(AUTHOR_SEPARATOR + by);
    if (!authorLink) {
        return bySpannable;
    }
    bySpannable.setSpan(new StyleSpan(Typeface.BOLD), AUTHOR_SEPARATOR.length(), bySpannable.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
    ClickableSpan clickableSpan = new ClickableSpan() {

        @Override
        public void onClick(View view) {
            view.getContext().startActivity(new Intent(Intent.ACTION_VIEW).setData(AppUtils.createUserUri(getBy())));
        }

        @Override
        public void updateDrawState(TextPaint ds) {
            super.updateDrawState(ds);
            ds.setUnderlineText(false);
        }
    };
    bySpannable.setSpan(clickableSpan, AUTHOR_SEPARATOR.length(), bySpannable.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
    return bySpannable;
}
Also used : SpannableString(android.text.SpannableString) StyleSpan(android.text.style.StyleSpan) Intent(android.content.Intent) ClickableSpan(android.text.style.ClickableSpan) View(android.view.View) TextPaint(android.text.TextPaint) NonNull(android.support.annotation.NonNull)

Aggregations

StyleSpan (android.text.style.StyleSpan)143 SpannableString (android.text.SpannableString)56 SpannableStringBuilder (android.text.SpannableStringBuilder)34 RelativeSizeSpan (android.text.style.RelativeSizeSpan)32 ForegroundColorSpan (android.text.style.ForegroundColorSpan)25 View (android.view.View)18 TextView (android.widget.TextView)17 UnderlineSpan (android.text.style.UnderlineSpan)16 Spannable (android.text.Spannable)14 StrikethroughSpan (android.text.style.StrikethroughSpan)13 TypefaceSpan (android.text.style.TypefaceSpan)12 TypedArray (android.content.res.TypedArray)10 TextPaint (android.text.TextPaint)10 SubscriptSpan (android.text.style.SubscriptSpan)10 SuperscriptSpan (android.text.style.SuperscriptSpan)10 Handler (android.os.Handler)9 Message (android.os.Message)9 URLSpan (android.text.style.URLSpan)8 JustifiedSpan (com.bluejamesbond.text.style.JustifiedSpan)8 ArticleBuilder (com.bluejamesbond.text.util.ArticleBuilder)8