Search in sources :

Example 41 with ColorStateList

use of android.content.res.ColorStateList in project Carbon by ZieIony.

the class RippleDrawableFroyo method updateStateFromTypedArray.

/**
     * Initializes the constant state from the values in the typed array.
     */
private void updateStateFromTypedArray(TypedArray a) throws XmlPullParserException {
    final RippleState state = mState;
    // Account for any configuration changes.
    state.mChangingConfigurations |= TypedArrayCompat.getChangingConfigurations(a);
    // Extract the theme attributes, if any.
    state.mTouchThemeAttrs = TypedArrayCompat.extractThemeAttrs(a);
    final ColorStateList color = a.getColorStateList(R.styleable.RippleDrawable_android_color);
    if (color != null) {
        mState.mColor = color;
    }
    mState.mMaxRadius = a.getDimensionPixelSize(R.styleable.RippleDrawable_android_radius, mState.mMaxRadius);
    verifyRequiredAttributes(a);
}
Also used : ColorStateList(android.content.res.ColorStateList)

Example 42 with ColorStateList

use of android.content.res.ColorStateList in project Carbon by ZieIony.

the class Button method drawableStateChanged.

@Override
protected void drawableStateChanged() {
    super.drawableStateChanged();
    if (rippleDrawable != null && rippleDrawable.getStyle() != RippleDrawable.Style.Background)
        rippleDrawable.setState(getDrawableState());
    if (stateAnimator != null)
        stateAnimator.setState(getDrawableState());
    ColorStateList textColors = getTextColors();
    if (textColors instanceof AnimatedColorStateList)
        ((AnimatedColorStateList) textColors).setState(getDrawableState());
    if (tint != null && tint instanceof AnimatedColorStateList)
        ((AnimatedColorStateList) tint).setState(getDrawableState());
    if (backgroundTint != null && backgroundTint instanceof AnimatedColorStateList)
        ((AnimatedColorStateList) backgroundTint).setState(getDrawableState());
    if (shadow != null && shadowColor != null)
        shadowColorFilter = new PorterDuffColorFilter(shadowColor.getColorForState(getDrawableState(), shadowColor.getDefaultColor()), PorterDuff.Mode.MULTIPLY);
}
Also used : ColorStateList(android.content.res.ColorStateList) DefaultPrimaryColorStateList(carbon.drawable.DefaultPrimaryColorStateList) AnimatedColorStateList(carbon.animation.AnimatedColorStateList) PorterDuffColorFilter(android.graphics.PorterDuffColorFilter) AnimatedColorStateList(carbon.animation.AnimatedColorStateList)

Example 43 with ColorStateList

use of android.content.res.ColorStateList in project Carbon by ZieIony.

the class EditText method drawableStateChanged.

@Override
protected void drawableStateChanged() {
    super.drawableStateChanged();
    if (rippleDrawable != null && rippleDrawable.getStyle() != RippleDrawable.Style.Background)
        rippleDrawable.setState(getDrawableState());
    if (stateAnimator != null)
        stateAnimator.setState(getDrawableState());
    ColorStateList textColors = getTextColors();
    if (textColors instanceof AnimatedColorStateList)
        ((AnimatedColorStateList) textColors).setState(getDrawableState());
    if (tint != null && tint instanceof AnimatedColorStateList)
        ((AnimatedColorStateList) tint).setState(getDrawableState());
    if (backgroundTint != null && backgroundTint instanceof AnimatedColorStateList)
        ((AnimatedColorStateList) backgroundTint).setState(getDrawableState());
}
Also used : ColorStateList(android.content.res.ColorStateList) DefaultNormalColorStateList(carbon.drawable.DefaultNormalColorStateList) DefaultColorStateList(carbon.drawable.DefaultColorStateList) AnimatedColorStateList(carbon.animation.AnimatedColorStateList) AnimatedColorStateList(carbon.animation.AnimatedColorStateList)

Example 44 with ColorStateList

use of android.content.res.ColorStateList in project remusic by aa112901.

the class ColorStateListUtils method createColorStateList.

static ColorStateList createColorStateList(Context context, int resId) {
    if (resId <= 0)
        return null;
    TypedValue value = new TypedValue();
    context.getResources().getValue(resId, value, true);
    ColorStateList cl = null;
    if (value.type >= TypedValue.TYPE_FIRST_COLOR_INT && value.type <= TypedValue.TYPE_LAST_COLOR_INT) {
        //Assume that "color/theme_color_primary" and "color/theme_color_profile" have the same color value;
        //However, "color/theme_color_primary" need to replace by themeId, "color/theme_color_profile" not.
        //If use value.data may cause "color/theme_color_profile" still been replaced by themeId
        cl = ColorStateList.valueOf(ThemeUtils.replaceColorById(context, value.resourceId));
    } else {
        final String file = value.string.toString();
        try {
            if (file.endsWith("xml")) {
                final XmlResourceParser rp = context.getResources().getAssets().openXmlResourceParser(value.assetCookie, file);
                final AttributeSet attrs = Xml.asAttributeSet(rp);
                int type;
                while ((type = rp.next()) != XmlPullParser.START_TAG && type != XmlPullParser.END_DOCUMENT) {
                // Seek parser to start tag.
                }
                if (type != XmlPullParser.START_TAG) {
                    throw new XmlPullParserException("No start tag found");
                }
                cl = createFromXmlInner(context, rp, attrs);
                rp.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        } catch (XmlPullParserException e) {
            e.printStackTrace();
        }
    }
    return cl;
}
Also used : XmlResourceParser(android.content.res.XmlResourceParser) AttributeSet(android.util.AttributeSet) ColorStateList(android.content.res.ColorStateList) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) IOException(java.io.IOException) TypedValue(android.util.TypedValue)

Example 45 with ColorStateList

use of android.content.res.ColorStateList in project remusic by aa112901.

the class ColorStateListUtils method inflateColorStateList.

static ColorStateList inflateColorStateList(Context context, XmlPullParser parser, AttributeSet attrs) throws IOException, XmlPullParserException {
    final int innerDepth = parser.getDepth() + 1;
    int depth;
    int type;
    LinkedList<int[]> stateList = new LinkedList<>();
    LinkedList<Integer> colorList = new LinkedList<>();
    while ((type = parser.next()) != XmlPullParser.END_DOCUMENT && ((depth = parser.getDepth()) >= innerDepth || type != XmlPullParser.END_TAG)) {
        if (type != XmlPullParser.START_TAG || depth > innerDepth || !parser.getName().equals("item")) {
            continue;
        }
        TypedArray a1 = context.obtainStyledAttributes(attrs, new int[] { android.R.attr.color });
        final int value = a1.getResourceId(0, Color.MAGENTA);
        final int baseColor = value == Color.MAGENTA ? Color.MAGENTA : ThemeUtils.replaceColorById(context, value);
        a1.recycle();
        TypedArray a2 = context.obtainStyledAttributes(attrs, new int[] { android.R.attr.alpha });
        final float alphaMod = a2.getFloat(0, 1.0f);
        a2.recycle();
        colorList.add(alphaMod != 1.0f ? ColorUtils.setAlphaComponent(baseColor, Math.round(Color.alpha(baseColor) * alphaMod)) : baseColor);
        stateList.add(extractStateSet(attrs));
    }
    if (stateList.size() > 0 && stateList.size() == colorList.size()) {
        int[] colors = new int[colorList.size()];
        for (int i = 0; i < colorList.size(); i++) {
            colors[i] = colorList.get(i);
        }
        return new ColorStateList(stateList.toArray(new int[stateList.size()][]), colors);
    }
    return null;
}
Also used : TypedArray(android.content.res.TypedArray) ColorStateList(android.content.res.ColorStateList) LinkedList(java.util.LinkedList)

Aggregations

ColorStateList (android.content.res.ColorStateList)280 Paint (android.graphics.Paint)90 TypedArray (android.content.res.TypedArray)76 Drawable (android.graphics.drawable.Drawable)48 TextPaint (android.text.TextPaint)42 Resources (android.content.res.Resources)25 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)22 TypedValue (android.util.TypedValue)21 TextView (android.widget.TextView)19 Context (android.content.Context)18 SuppressLint (android.annotation.SuppressLint)17 SmallTest (android.test.suitebuilder.annotation.SmallTest)13 AllCapsTransformationMethod (android.text.method.AllCapsTransformationMethod)13 RippleDrawable (android.graphics.drawable.RippleDrawable)12 StateListDrawable (android.graphics.drawable.StateListDrawable)12 View (android.view.View)12 Nullable (android.annotation.Nullable)10 Bitmap (android.graphics.Bitmap)10 TextAppearanceSpan (android.text.style.TextAppearanceSpan)9 PorterDuff (android.graphics.PorterDuff)8