From ab1cbc2c53f051aaafe4d43242d6acfd08cbf158 Mon Sep 17 00:00:00 2001 From: Teng-Hui Zhu Date: Wed, 29 Jun 2016 16:56:40 -0700 Subject: Mutate the drawable if a valid state change happen In another word, create another cached bitmap, when the current VectorDrawable will look differently when state changed. Bug: 29870392 Bug: 29854240 Change-Id: I7a5ef91091e547a930368286defc7ab96aeb9471 (cherry picked from commit 4f1acfb5f507798daaff2ff0da47d2b15607ded4) --- graphics/java/android/graphics/drawable/VectorDrawable.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/graphics/java/android/graphics/drawable/VectorDrawable.java b/graphics/java/android/graphics/drawable/VectorDrawable.java index 7b8dc52bc3b4..c855c4c6d17b 100644 --- a/graphics/java/android/graphics/drawable/VectorDrawable.java +++ b/graphics/java/android/graphics/drawable/VectorDrawable.java @@ -240,9 +240,7 @@ public class VectorDrawable extends Drawable { * constructors to set the state and initialize local properties. */ private VectorDrawable(@NonNull VectorDrawableState state, @Nullable Resources res) { - // Constant state sharing is disabled until we fix onStateChanged() - // affecting the shared bitmap. - mVectorState = new VectorDrawableState(state); + mVectorState = state; updateLocalState(res); } @@ -388,6 +386,11 @@ public class VectorDrawable extends Drawable { protected boolean onStateChange(int[] stateSet) { boolean changed = false; + // When the VD is stateful, we need to mutate the drawable such that we don't share the + // cache bitmap with others. Such that the state change only affect this new cached bitmap. + if (isStateful()) { + mutate(); + } final VectorDrawableState state = mVectorState; if (state.onStateChange(stateSet)) { changed = true; -- cgit v1.2.3-59-g8ed1b