Search in sources :

Example 51 with TextAppearanceSpan

use of android.text.style.TextAppearanceSpan in project android_frameworks_base by crdroidandroid.

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 52 with TextAppearanceSpan

use of android.text.style.TextAppearanceSpan in project android_frameworks_base by crdroidandroid.

the class NotificationColorUtil method invertCharSequenceColors.

/**
     * Inverts all the grayscale colors set by {@link android.text.style.TextAppearanceSpan}s on
     * the text.
     *
     * @param charSequence The text to process.
     * @return The color inverted text.
     */
public CharSequence invertCharSequenceColors(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 (span instanceof TextAppearanceSpan) {
                resultSpan = processTextAppearanceSpan((TextAppearanceSpan) span);
            }
            builder.setSpan(resultSpan, ss.getSpanStart(span), ss.getSpanEnd(span), ss.getSpanFlags(span));
        }
        return builder;
    }
    return charSequence;
}
Also used : TextAppearanceSpan(android.text.style.TextAppearanceSpan) Spanned(android.text.Spanned) SpannableStringBuilder(android.text.SpannableStringBuilder)

Aggregations

TextAppearanceSpan (android.text.style.TextAppearanceSpan)52 SpannableString (android.text.SpannableString)21 SpannableStringBuilder (android.text.SpannableStringBuilder)15 Spanned (android.text.Spanned)15 TypedValue (android.util.TypedValue)15 View (android.view.View)10 ColorStateList (android.content.res.ColorStateList)9 SmallTest (android.test.suitebuilder.annotation.SmallTest)6 Intent (android.content.Intent)5 TypedArray (android.content.res.TypedArray)5 Espresso.onView (android.support.test.espresso.Espresso.onView)5 NoMatchingViewException (android.support.test.espresso.NoMatchingViewException)5 ViewAssertion (android.support.test.espresso.ViewAssertion)5 RootMatchers.withDecorView (android.support.test.espresso.matcher.RootMatchers.withDecorView)5 TextPaint (android.text.TextPaint)5 AbsoluteSizeSpan (android.text.style.AbsoluteSizeSpan)5 CharacterStyle (android.text.style.CharacterStyle)5 RelativeSizeSpan (android.text.style.RelativeSizeSpan)5 SuggestionSpan (android.text.style.SuggestionSpan)5 ImageView (android.widget.ImageView)5