Ensure calling mutate() on DrawableContainer creates a new state

Previously, a new state would only be created on newDrawable(), which
caused the first drawable loaded for a resource to share constant state
with the cached version. Even if mutate() was called, the constant
state was still shared and any changes were applied to the cached copy.

BUG: 18504919
Change-Id: I1ce76fbbc144e9c0c93261e3a12cc613d0c74b83
This commit is contained in:
Alan Viverette
2014-11-24 11:11:05 -08:00
parent 29dc496a42
commit d7dab349c2
5 changed files with 75 additions and 35 deletions

View File

@@ -342,12 +342,17 @@ public class AnimationDrawable extends DrawableContainer implements Runnable, An
@Override
public Drawable mutate() {
if (!mMutated && super.mutate() == this) {
mAnimationState.mDurations = mAnimationState.mDurations.clone();
mAnimationState.mutate();
mMutated = true;
}
return this;
}
@Override
AnimationState cloneConstantState() {
return new AnimationState(mAnimationState, this, null);
}
/**
* @hide
*/
@@ -373,6 +378,10 @@ public class AnimationDrawable extends DrawableContainer implements Runnable, An
}
}
private void mutate() {
mDurations = mDurations.clone();
}
@Override
public Drawable newDrawable() {
return new AnimationDrawable(this, null);