@Override protected void drawableStateChanged() { super.drawableStateChanged(); if (mColorStateList != null && mColorStateList.isStateful()) { updateTintColor(); } }
@Override public boolean isStateful() { boolean isStateful = false; if (textBg != null) { isStateful = textBg.isStateful(); } if (textColorStateList != null) { isStateful = isStateful | textColorStateList.isStateful(); } isStateful = isStateful | src.isStateful(); return isStateful; }
public void testColorStateList() throws NotFoundException, XmlPullParserException, IOException { final int[][] state = new int[][] {{0}, {0}}; final int[] colors = new int[] {Color.RED, Color.BLUE}; ColorStateList c = new ColorStateList(state, colors); assertTrue(c.isStateful()); assertEquals(Color.RED, c.getDefaultColor()); final int alpha = 36; final ColorStateList c1 = c.withAlpha(alpha); assertNotSame(Color.RED, c1.getDefaultColor()); // check alpha assertEquals(alpha, c1.getDefaultColor() >>> 24); assertEquals(Color.RED & 0x00FF0000, c1.getDefaultColor() & 0x00FF0000); final int xmlId = R.drawable.testcolor; final int colorInXml = 0xFFA6C839; // this color value is define in testcolor.xml file. final Resources res = getContext().getResources(); c = ColorStateList.createFromXml(res, res.getXml(xmlId)); assertEquals(colorInXml, c.getDefaultColor()); assertEquals(0, c.describeContents()); assertFalse(c.isStateful()); assertNotNull(c.toString()); assertEquals(colorInXml, c.getColorForState(new int[] {0}, 0)); c = ColorStateList.valueOf(Color.GRAY); assertEquals(Color.GRAY, c.getDefaultColor()); final Parcel parcel = Parcel.obtain(); c.writeToParcel(parcel, 0); parcel.setDataPosition(0); ColorStateList actual = ColorStateList.CREATOR.createFromParcel(parcel); // can only compare the state and the default color. because no API to // get every color of ColorStateList assertEquals(c.isStateful(), actual.isStateful()); assertEquals(c.getDefaultColor(), actual.getDefaultColor()); }
private ColorStateList createSwitchThumbColorStateList(Context paramContext) { int[][] arrayOfInt = new int[3][]; int[] arrayOfInt1 = new int[3]; ColorStateList localColorStateList = ThemeUtils.getThemeAttrColorStateList(paramContext, R.attr.colorSwitchThumbNormal); if ((localColorStateList != null) && (localColorStateList.isStateful())) { arrayOfInt[0] = ThemeUtils.DISABLED_STATE_SET; arrayOfInt1[0] = localColorStateList.getColorForState(arrayOfInt[0], 0); arrayOfInt[1] = ThemeUtils.CHECKED_STATE_SET; arrayOfInt1[1] = ThemeUtils.getThemeAttrColor(paramContext, R.attr.colorControlActivated); arrayOfInt[2] = ThemeUtils.EMPTY_STATE_SET; arrayOfInt1[2] = localColorStateList.getDefaultColor(); } for (; ; ) { return new ColorStateList(arrayOfInt, arrayOfInt1); arrayOfInt[0] = ThemeUtils.DISABLED_STATE_SET; arrayOfInt1[0] = ThemeUtils.getDisabledThemeAttrColor(paramContext, R.attr.colorSwitchThumbNormal); arrayOfInt[1] = ThemeUtils.CHECKED_STATE_SET; arrayOfInt1[1] = ThemeUtils.getThemeAttrColor(paramContext, R.attr.colorControlActivated); arrayOfInt[2] = ThemeUtils.EMPTY_STATE_SET; arrayOfInt1[2] = ThemeUtils.getThemeAttrColor(paramContext, R.attr.colorSwitchThumbNormal); } }
@Override public boolean isStateful() { return (mTint != null && mTint.isStateful()) || (mBackground != null && mBackground.isStateful()) || super.isStateful(); }
@SuppressWarnings("deprecation") public static Drawable createFromXmlInner( Context c, Resources r, XmlPullParser parser, AttributeSet attrs) throws XmlPullParserException, IOException { Drawable drawable; final String name = parser.getName(); // TODO: add the remaining drawables that are not covered. if (name.equals("selector")) { drawable = new StateListMaterialDrawable(c); // } else if (name.equals("animated-selector")) { // } else if (name.equals("level-list")) { } else if (name.equals("layer-list")) { drawable = new LayerMaterialDrawable(c); // } else if (name.equals("transition")) { } else if (name.equals("ripple")) { drawable = new RippleMaterialDrawable(c); } else if (name.equals("color")) { drawable = new ColorMaterialDrawable(c); } else if (name.equals("shape")) { drawable = new GradientMaterialDrawable(c); // } else if (name.equals("vector")) { // } else if (name.equals("animated-vector")) { // } else if (name.equals("scale")) { // } else if (name.equals("clip")) { // } else if (name.equals("rotate")) { // } else if (name.equals("animated-rotate")) { } else if (name.equals("animation-list")) { drawable = new AnimationMaterialDrawable(c); } else if (name.equals("inset")) { drawable = new InsetMaterialDrawable(c); } else if (name.equals("bitmap")) { drawable = new BitmapDrawable(); if (r != null) { ((BitmapDrawable) drawable).setTargetDensity(r.getDisplayMetrics()); } drawable = new TintDrawable(c, drawable); } else if (name.equals("nine-patch")) { drawable = new NinePatchDrawable(null, null); if (r != null) { ((NinePatchDrawable) drawable).setTargetDensity(r.getDisplayMetrics()); } drawable = new TintDrawable(c, drawable); } else { drawable = null; } if (drawable != null) { drawable.inflate(r, parser, attrs); if (drawable instanceof GradientMaterialDrawable) { // Before Lollipop, GradientDrawable does not support a ColorStateList solid color. // In the case of a stateful solid color, enclose the drawable inside a TintDrawable. ColorStateList solidColor = ((GradientMaterialDrawable) drawable).getSolidColor(); if (solidColor != null && solidColor.isStateful()) { drawable = new TintDrawable(c, drawable, solidColor); } } } else { drawable = Drawable.createFromXmlInner(r, parser, attrs); } return drawable; }
public boolean isStateful() { return mTintList != null && mTintList.isStateful() || mDrawable.isStateful(); }
@Override public boolean isStateful() { return colorStateList != null && colorStateList.isStateful(); }
@Override public boolean isStateful() { return mBorderColor.isStateful(); }