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

Commit 19f2034a authored by Tracy Zhou's avatar Tracy Zhou Committed by Android (Google) Code Review
Browse files

Merge "Fix rotation button background not showing after first boot." into qt-dev

parents c0c88c6e 7974a7d6
Loading
Loading
Loading
Loading
+17 −2
Original line number Diff line number Diff line
@@ -16,8 +16,10 @@

package com.android.systemui.statusbar.phone;

import android.annotation.ColorInt;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Color;
import android.graphics.PixelFormat;
import android.view.ContextThemeWrapper;
import android.view.Gravity;
@@ -26,6 +28,7 @@ import android.view.Surface;
import android.view.View;
import android.view.WindowManager;

import com.android.settingslib.Utils;
import com.android.systemui.R;
import com.android.systemui.statusbar.policy.KeyButtonDrawable;
import com.android.systemui.statusbar.policy.KeyButtonView;
@@ -33,6 +36,8 @@ import com.android.systemui.statusbar.policy.KeyButtonView;
/** Containing logic for the rotation button on the physical left bottom corner of the screen. */
public class FloatingRotationButton implements RotationButton {

    private static final float BACKGROUND_ALPHA = 0.92f;

    private final Context mContext;
    private final WindowManager mWindowManager;
    private final KeyButtonView mKeyButtonView;
@@ -151,8 +156,18 @@ public class FloatingRotationButton implements RotationButton {
    public KeyButtonDrawable getImageDrawable() {
        Context context = new ContextThemeWrapper(mContext.getApplicationContext(),
                mRotationButtonController.getStyleRes());
        return KeyButtonDrawable.create(context, R.drawable.ic_sysbar_rotate_button,
                false /* shadow */, true /* hasOvalBg */);
        final int dualToneDarkTheme = Utils.getThemeAttr(context, R.attr.darkIconTheme);
        final int dualToneLightTheme = Utils.getThemeAttr(context, R.attr.lightIconTheme);
        Context lightContext = new ContextThemeWrapper(context, dualToneLightTheme);
        Context darkContext = new ContextThemeWrapper(context, dualToneDarkTheme);
        @ColorInt int darkColor = Utils.getColorAttrDefaultColor(darkContext,
                R.attr.singleToneColor);
        Color ovalBackgroundColor = Color.valueOf(Color.red(darkColor), Color.green(darkColor),
                Color.blue(darkColor), BACKGROUND_ALPHA);

        return KeyButtonDrawable.create(lightContext,
                Utils.getColorAttrDefaultColor(lightContext, R.attr.singleToneColor), darkColor,
                R.drawable.ic_sysbar_rotate_button, false /* shadow */, ovalBackgroundColor);
    }

    @Override
+1 −2
Original line number Diff line number Diff line
@@ -24,7 +24,6 @@ import android.content.Context;
import android.view.ContextThemeWrapper;
import android.view.View;

import com.android.systemui.shared.system.QuickStepContract;
import com.android.systemui.statusbar.policy.KeyButtonDrawable;

/** Containing logic for the rotation button in nav bar. */
@@ -61,7 +60,7 @@ public class RotationContextButton extends ContextualButton implements
        Context context = new ContextThemeWrapper(getContext().getApplicationContext(),
                mRotationButtonController.getStyleRes());
        return KeyButtonDrawable.create(context, mIconResId, false /* shadow */,
                QuickStepContract.isGesturalMode(mNavBarMode));
                null /* ovalBackgroundColor */);
    }

    @Override
+23 −23
Original line number Diff line number Diff line
@@ -82,9 +82,9 @@ public class KeyButtonDrawable extends Drawable {
    private AnimatedVectorDrawable mAnimatedDrawable;

    public KeyButtonDrawable(Drawable d, @ColorInt int lightColor, @ColorInt int darkColor,
            boolean horizontalFlip, boolean hasOvalBg) {
            boolean horizontalFlip, Color ovalBackgroundColor) {
        this(d, new ShadowDrawableState(lightColor, darkColor,
                d instanceof AnimatedVectorDrawable, horizontalFlip, hasOvalBg));
                d instanceof AnimatedVectorDrawable, horizontalFlip, ovalBackgroundColor));
    }

    private KeyButtonDrawable(Drawable d, ShadowDrawableState state) {
@@ -166,7 +166,7 @@ public class KeyButtonDrawable extends Drawable {
    public void setColorFilter(ColorFilter colorFilter) {
        mIconPaint.setColorFilter(colorFilter);
        if (mAnimatedDrawable != null) {
            if (mState.mHasOvalBg) {
            if (hasOvalBg()) {
                mAnimatedDrawable.setColorFilter(
                        new PorterDuffColorFilter(mState.mLightColor, PorterDuff.Mode.SRC_IN));
            } else {
@@ -212,15 +212,6 @@ public class KeyButtonDrawable extends Drawable {
        return mState.mBaseWidth + (mState.mShadowSize + Math.abs(mState.mShadowOffsetX)) * 2;
    }

    /** Return if the drawable has oval background. */
    public boolean hasOvalBg() {
        return mState.mHasOvalBg;
    }

    public int getDarkColor() {
        return mState.mDarkColor;
    }

    public boolean canAnimate() {
        return mState.mSupportsAnimation;
    }
@@ -290,6 +281,14 @@ public class KeyButtonDrawable extends Drawable {
        return mState.canApplyTheme();
    }

    @ColorInt int getDrawableBackgroundColor() {
        return mState.mOvalBackgroundColor.toArgb();
    }

    boolean hasOvalBg() {
        return mState.mOvalBackgroundColor != null;
    }

    private void regenerateBitmapIconCache() {
        final int width = getIntrinsicWidth();
        final int height = getIntrinsicHeight();
@@ -394,16 +393,16 @@ public class KeyButtonDrawable extends Drawable {
        final int mLightColor;
        final int mDarkColor;
        final boolean mSupportsAnimation;
        final boolean mHasOvalBg;
        final Color mOvalBackgroundColor;

        public ShadowDrawableState(@ColorInt int lightColor, @ColorInt int darkColor,
                boolean animated, boolean horizontalFlip, boolean hasOvalBg) {
                boolean animated, boolean horizontalFlip, Color ovalBackgroundColor) {
            mLightColor = lightColor;
            mDarkColor = darkColor;
            mSupportsAnimation = animated;
            mAlpha = 255;
            mHorizontalFlip = horizontalFlip;
            mHasOvalBg = hasOvalBg;
            mOvalBackgroundColor = ovalBackgroundColor;
        }

        @Override
@@ -428,16 +427,17 @@ public class KeyButtonDrawable extends Drawable {
     * @param ctx Context to get the drawable and determine the dark and light theme
     * @param icon the icon resource id
     * @param hasShadow if a shadow will appear with the drawable
     * @param hasOvalBg if an oval bg will be drawn
     * @param ovalBackgroundColor the color of the oval bg that will be drawn
     * @return KeyButtonDrawable
     */
    public static KeyButtonDrawable create(@NonNull Context ctx, @DrawableRes int icon,
            boolean hasShadow, boolean hasOvalBg) {
            boolean hasShadow, Color ovalBackgroundColor) {
        final int dualToneDarkTheme = Utils.getThemeAttr(ctx, R.attr.darkIconTheme);
        final int dualToneLightTheme = Utils.getThemeAttr(ctx, R.attr.lightIconTheme);
        Context lightContext = new ContextThemeWrapper(ctx, dualToneLightTheme);
        Context darkContext = new ContextThemeWrapper(ctx, dualToneDarkTheme);
        return KeyButtonDrawable.create(lightContext, darkContext, icon, hasShadow, hasOvalBg);
        return KeyButtonDrawable.create(lightContext, darkContext, icon, hasShadow,
                ovalBackgroundColor);
    }

    /**
@@ -446,7 +446,7 @@ public class KeyButtonDrawable extends Drawable {
     */
    public static KeyButtonDrawable create(@NonNull Context ctx, @DrawableRes int icon,
            boolean hasShadow) {
        return create(ctx, icon, hasShadow, false /* hasOvalBg */);
        return create(ctx, icon, hasShadow, null /* ovalBackgroundColor */);
    }

    /**
@@ -454,11 +454,11 @@ public class KeyButtonDrawable extends Drawable {
     * {@link #create(Context, int, boolean, boolean)}.
     */
    public static KeyButtonDrawable create(Context lightContext, Context darkContext,
            @DrawableRes int iconResId, boolean hasShadow, boolean hasOvalBg) {
            @DrawableRes int iconResId, boolean hasShadow, Color ovalBackgroundColor) {
        return create(lightContext,
            Utils.getColorAttrDefaultColor(lightContext, R.attr.singleToneColor),
            Utils.getColorAttrDefaultColor(darkContext, R.attr.singleToneColor),
            iconResId, hasShadow, hasOvalBg);
            iconResId, hasShadow, ovalBackgroundColor);
    }

    /**
@@ -467,12 +467,12 @@ public class KeyButtonDrawable extends Drawable {
     */
    public static KeyButtonDrawable create(Context context, @ColorInt int lightColor,
            @ColorInt int darkColor, @DrawableRes int iconResId, boolean hasShadow,
            boolean hasOvalBg) {
            Color ovalBackgroundColor) {
        final Resources res = context.getResources();
        boolean isRtl = res.getConfiguration().getLayoutDirection() == View.LAYOUT_DIRECTION_RTL;
        Drawable d = context.getDrawable(iconResId);
        final KeyButtonDrawable drawable = new KeyButtonDrawable(d, lightColor, darkColor,
                isRtl && d.isAutoMirrored(), hasOvalBg);
                isRtl && d.isAutoMirrored(), ovalBackgroundColor);
        if (hasShadow) {
            int offsetX = res.getDimensionPixelSize(R.dimen.nav_key_button_shadow_offset_x);
            int offsetY = res.getDimensionPixelSize(R.dimen.nav_key_button_shadow_offset_y);
+21 −9
Original line number Diff line number Diff line
@@ -79,6 +79,7 @@ public class KeyButtonView extends ImageView implements ButtonInterface {
    private final MetricsLogger mMetricsLogger = Dependency.get(MetricsLogger.class);
    private final InputManager mInputManager;
    private final Paint mOvalBgPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG);
    private float mDarkIntensity;
    private boolean mHasOvalBg = false;

    private final Runnable mCheckLongPress = new Runnable() {
@@ -304,6 +305,23 @@ public class KeyButtonView extends ImageView implements ButtonInterface {
        return true;
    }

    @Override
    public void setImageDrawable(Drawable drawable) {
        super.setImageDrawable(drawable);

        if (drawable == null) {
            return;
        }
        KeyButtonDrawable keyButtonDrawable = (KeyButtonDrawable) drawable;
        keyButtonDrawable.setDarkIntensity(mDarkIntensity);
        mHasOvalBg = keyButtonDrawable.hasOvalBg();
        if (mHasOvalBg) {
            mOvalBgPaint.setColor(keyButtonDrawable.getDrawableBackgroundColor());
        }
        mRipple.setType(keyButtonDrawable.hasOvalBg() ? KeyButtonRipple.Type.OVAL
                : KeyButtonRipple.Type.ROUNDED_RECT);
    }

    public void playSoundEffect(int soundConstant) {
        if (!mPlaySounds) return;
        mAudioManager.playSoundEffect(soundConstant, ActivityManager.getCurrentUser());
@@ -360,17 +378,11 @@ public class KeyButtonView extends ImageView implements ButtonInterface {

    @Override
    public void setDarkIntensity(float darkIntensity) {
        mDarkIntensity = darkIntensity;

        Drawable drawable = getDrawable();
        if (drawable != null) {
            KeyButtonDrawable keyButtonDrawable = (KeyButtonDrawable) drawable;
            keyButtonDrawable.setDarkIntensity(darkIntensity);
            mHasOvalBg = keyButtonDrawable.hasOvalBg();
            if (mHasOvalBg) {
                mOvalBgPaint.setColor(keyButtonDrawable.getDarkColor());
            }
            mRipple.setType(keyButtonDrawable.hasOvalBg() ? KeyButtonRipple.Type.OVAL
                    : KeyButtonRipple.Type.ROUNDED_RECT);

            ((KeyButtonDrawable) drawable).setDarkIntensity(darkIntensity);
            // Since we reuse the same drawable for multiple views, we need to invalidate the view
            // manually.
            invalidate();
+2 −2
Original line number Diff line number Diff line
@@ -180,9 +180,9 @@ public class NavigationBarContextTest extends SysuiTestCase {
        final Drawable d = mock(Drawable.class);
        final ContextualButton button = spy(mBtn0);
        final KeyButtonDrawable kbd1 = spy(new KeyButtonDrawable(d, unusedColor, unusedColor,
                false /* horizontalFlip */, false /* hasOvalBg */));
                false /* horizontalFlip */, null /* ovalBackgroundColor */));
        final KeyButtonDrawable kbd2 = spy(new KeyButtonDrawable(d, unusedColor, unusedColor,
                false /* horizontalFlip */, false /* hasOvalBg */));
                false /* horizontalFlip */, null /* ovalBackgroundColor */));
        kbd1.setDarkIntensity(TEST_DARK_INTENSITY);
        kbd2.setDarkIntensity(0f);