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: I40d257867eb0a092ce580b9c4338ddc7406a031d
This commit is contained in:
Alan Viverette
2014-11-25 10:40:24 -08:00
parent 59093d925d
commit 8dcd533786
5 changed files with 81 additions and 37 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);