summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Teng-Hui Zhu <ztenghui@google.com> 2016-06-29 16:56:40 -0700
committer Tenghui Zhu <ztenghui@google.com> 2016-06-30 16:30:02 +0000
commit4f1acfb5f507798daaff2ff0da47d2b15607ded4 (patch)
treea4ce79e60003b380173ef16e9fc2fd9ba9fec733
parent74f7f2ec0d1f60fc692934ad0e72d667f0fc04cd (diff)
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. b/29870392 Change-Id: I7a5ef91091e547a930368286defc7ab96aeb9471
-rw-r--r--graphics/java/android/graphics/drawable/VectorDrawable.java9
1 files changed, 6 insertions, 3 deletions
diff --git a/graphics/java/android/graphics/drawable/VectorDrawable.java b/graphics/java/android/graphics/drawable/VectorDrawable.java
index c34f474762f0..4f6368c69975 100644
--- a/graphics/java/android/graphics/drawable/VectorDrawable.java
+++ b/graphics/java/android/graphics/drawable/VectorDrawable.java
@@ -243,9 +243,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);
}
@@ -391,6 +389,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;