From 931435cf2649a2ebbadd1ebb27979e9389e71bed Mon Sep 17 00:00:00 2001 From: Ashley Rose Date: Fri, 24 Aug 2018 11:32:40 -0400 Subject: Implement #mutate for ColorStateListDrawable ColorStateListDrawable did not implement #mutate correctly. This adds an implementation for it. Change-Id: I823b2096194ebc4e3424283ad5bad9d0f8df10df Fixes: 113099852 Test: atest ColorStateListDrawable --- .../graphics/drawable/ColorStateListDrawable.java | 35 +++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/graphics/java/android/graphics/drawable/ColorStateListDrawable.java b/graphics/java/android/graphics/drawable/ColorStateListDrawable.java index 40ba5d159261..c0c6a4f424a1 100644 --- a/graphics/java/android/graphics/drawable/ColorStateListDrawable.java +++ b/graphics/java/android/graphics/drawable/ColorStateListDrawable.java @@ -33,6 +33,7 @@ import android.util.MathUtils; public class ColorStateListDrawable extends Drawable implements Drawable.Callback { private ColorDrawable mColorDrawable; private ColorStateListDrawableState mState; + private boolean mMutated = false; public ColorStateListDrawable() { mState = new ColorStateListDrawableState(); @@ -139,7 +140,7 @@ public class ColorStateListDrawable extends Drawable implements Drawable.Callbac int color = mState.mColor.getColorForState(state, mState.mColor.getDefaultColor()); if (mState.mAlpha != -1) { - color = color & 0xFFFFFF | MathUtils.constrain(mState.mAlpha, 0, 255) << 24; + color = (color & 0xFFFFFF) | MathUtils.constrain(mState.mAlpha, 0, 255) << 24; } if (color != mColorDrawable.getColor()) { @@ -183,6 +184,8 @@ public class ColorStateListDrawable extends Drawable implements Drawable.Callbac @Override public ConstantState getConstantState() { + mState.mChangingConfigurations = mState.mChangingConfigurations + | (getChangingConfigurations() & ~mState.getChangingConfigurations()); return mState; } @@ -200,6 +203,29 @@ public class ColorStateListDrawable extends Drawable implements Drawable.Callbac } } + @Override + public int getChangingConfigurations() { + return super.getChangingConfigurations() | mState.getChangingConfigurations(); + } + + @Override + public Drawable mutate() { + if (!mMutated && super.mutate() == this) { + mState = new ColorStateListDrawableState(mState); + mMutated = true; + } + return this; + } + + /** + * @hide + */ + @Override + public void clearMutated() { + super.clearMutated(); + mMutated = false; + } + /** * Replace this Drawable's ColorStateList. It is not copied, so changes will propagate on the * next call to {@link #setState(int[])}. @@ -221,6 +247,13 @@ public class ColorStateListDrawable extends Drawable implements Drawable.Callbac ColorStateListDrawableState() { } + ColorStateListDrawableState(ColorStateListDrawableState state) { + mColor = state.mColor; + mTint = state.mTint; + mAlpha = state.mAlpha; + mTintMode = state.mTintMode; + mChangingConfigurations = state.mChangingConfigurations; + } @Override public Drawable newDrawable() { -- cgit v1.2.3-59-g8ed1b