Example usage for android.text.style TextAppearanceSpan getTextColor

List of usage examples for android.text.style TextAppearanceSpan getTextColor

Introduction

In this page you can find the example usage for android.text.style TextAppearanceSpan getTextColor.

Prototype

public ColorStateList getTextColor() 

Source Link

Document

Returns the text color specified by this span, or null if it does not specify one.

Usage

From source file:tk.wasdennnoch.androidn_ify.utils.NotificationColorUtil.java

private TextAppearanceSpan processTextAppearanceSpan(TextAppearanceSpan span) {
    ColorStateList colorStateList = span.getTextColor();
    if (colorStateList != null) {
        int[] colors = (int[]) XposedHelpers.callMethod(colorStateList, "getColors");
        boolean changed = false;
        for (int i = 0; i < colors.length; i++) {
            if (ImageUtils.isGrayscale(colors[i])) {

                // Allocate a new array so we don't change the colors in the old color state
                // list.
                if (!changed) {
                    colors = Arrays.copyOf(colors, colors.length);
                }/*  w ww.j a v a 2  s  .c o m*/
                colors[i] = processColor(colors[i]);
                changed = true;
            }
        }
        if (changed) {
            return new TextAppearanceSpan(span.getFamily(), span.getTextStyle(), span.getTextSize(),
                    new ColorStateList((int[][]) XposedHelpers.callMethod(colorStateList, "getStates"), colors),
                    span.getLinkTextColor());
        }
    }
    return span;
}

From source file:com.waz.zclient.controllers.notifications.NotificationsController.java

@TargetApi(21)
private SpannableString getMessageSpannable(String header, String body) {
    SpannableString messageSpannable = new SpannableString(header + body);
    final int textAppearance;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        textAppearance = android.R.style.TextAppearance_Material_Notification_Title;
    } else {//from  www. j a  va 2  s  . c  om
        textAppearance = android.R.style.TextAppearance_StatusBar_EventContent_Title;
    }
    final TextAppearanceSpan textAppearanceSpan = new TextAppearanceSpan(context, textAppearance);
    messageSpannable.setSpan(new ForegroundColorSpan(textAppearanceSpan.getTextColor().getDefaultColor()), 0,
            header.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    return messageSpannable;
}