summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Ashley Rose <ashleyrose@google.com> 2018-08-24 11:32:40 -0400
committer Ashley Rose <ashleyrose@google.com> 2018-08-24 14:36:14 -0400
commit931435cf2649a2ebbadd1ebb27979e9389e71bed (patch)
tree8f618a02afc2a0bf9f8ab9242176ba0d408cf503
parent8f7a800095796d2dcf705912c23478b7038d433f (diff)
Implement #mutate for ColorStateListDrawable
ColorStateListDrawable did not implement #mutate correctly. This adds an implementation for it. Change-Id: I823b2096194ebc4e3424283ad5bad9d0f8df10df Fixes: 113099852 Test: atest ColorStateListDrawable
-rw-r--r--graphics/java/android/graphics/drawable/ColorStateListDrawable.java35
1 files changed, 34 insertions, 1 deletions
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() {