Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 35d91b29 authored by Teng-Hui Zhu's avatar Teng-Hui Zhu Committed by The Android Automerger
Browse files

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 4f1acfb5)
parent e4c85fb9
Loading
Loading
Loading
Loading
+6 −3
Original line number Diff line number Diff line
@@ -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;