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

Commit 419aa7ad authored by Alan Viverette's avatar Alan Viverette
Browse files

Propagate DrawableContainer state on mutate, fix ColorDrawable theming

BUG: 18542282
BUG: 18467568
Change-Id: Id1d75cfe47fde3206ab40e5360289e0cb2504402
parent 4357d4ea
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -251,6 +251,11 @@ public class ColorDrawable extends Drawable {
        state.mUseColor = state.mBaseColor;
    }

    @Override
    public boolean canApplyTheme() {
        return mColorState.canApplyTheme() || super.canApplyTheme();
    }

    @Override
    public void applyTheme(Theme t) {
        super.applyTheme(t);
+48 −30
Original line number Diff line number Diff line
@@ -447,12 +447,48 @@ public class DrawableContainer extends Drawable implements Drawable.Callback {
            mCurrDrawable = d;
            mCurIndex = idx;
            if (d != null) {
                d.mutate();
                if (mDrawableContainerState.mEnterFadeDuration > 0) {
                    mEnterAnimationEnd = now + mDrawableContainerState.mEnterFadeDuration;
                } else if (mHasAlpha) {
                }
                initializeDrawableForDisplay(d);
            }
        } else {
            mCurrDrawable = null;
            mCurIndex = -1;
        }

        if (mEnterAnimationEnd != 0 || mExitAnimationEnd != 0) {
            if (mAnimationRunnable == null) {
                mAnimationRunnable = new Runnable() {
                    @Override public void run() {
                        animate(true);
                        invalidateSelf();
                    }
                };
            } else {
                unscheduleSelf(mAnimationRunnable);
            }
            // Compute first frame and schedule next animation.
            animate(true);
        }

        invalidateSelf();

        return true;
    }

    /**
     * Initializes a drawable for display in this container.
     *
     * @param d The drawable to initialize.
     */
    private void initializeDrawableForDisplay(Drawable d) {
        d.mutate();

        if (mDrawableContainerState.mEnterFadeDuration <= 0 && mHasAlpha) {
            d.setAlpha(mAlpha);
        }

        if (mDrawableContainerState.mHasColorFilter) {
            // Color filter always overrides tint.
            d.setColorFilter(mDrawableContainerState.mColorFilter);
@@ -464,6 +500,7 @@ public class DrawableContainer extends Drawable implements Drawable.Callback {
                d.setTintMode(mDrawableContainerState.mTintMode);
            }
        }

        d.setVisible(isVisible(), true);
        d.setDither(mDrawableContainerState.mDither);
        d.setState(getState());
@@ -478,30 +515,6 @@ public class DrawableContainer extends Drawable implements Drawable.Callback {
                    hotspotBounds.right, hotspotBounds.bottom);
        }
    }
        } else {
            mCurrDrawable = null;
            mCurIndex = -1;
        }

        if (mEnterAnimationEnd != 0 || mExitAnimationEnd != 0) {
            if (mAnimationRunnable == null) {
                mAnimationRunnable = new Runnable() {
                    @Override public void run() {
                        animate(true);
                        invalidateSelf();
                    }
                };
            } else {
                unscheduleSelf(mAnimationRunnable);
            }
            // Compute first frame and schedule next animation.
            animate(true);
        }

        invalidateSelf();

        return true;
    }

    void animate(boolean schedule) {
        mHasAlpha = true;
@@ -1136,9 +1149,14 @@ public class DrawableContainer extends Drawable implements Drawable.Callback {
        // The locally cached drawables may have changed.
        if (mCurIndex >= 0) {
            mCurrDrawable = state.getChild(mCurIndex);
            if (mCurrDrawable != null) {
                initializeDrawableForDisplay(mCurrDrawable);
            }
        if (mLastIndex >= 0) {
            mLastDrawable = state.getChild(mLastIndex);
        }

        // Clear out the last drawable. We don't have enough information to
        // propagate local state from the past.
        mLastIndex = -1;
        mLastDrawable = null;
    }
}