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

Commit 11a520e3 authored by Tracy Zhou's avatar Tracy Zhou
Browse files

Refetch shadePanel and notificationScrim colors when theme changes or isBlurSupported changes

Bug: 405048838
Test: manual
Flag: com.android.systemui.notification_shade_blur
Change-Id: I0c31ed038637f384b0ea2f6219a6eb6312e6bc1f
parent 98b21a0b
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -44,8 +44,8 @@ import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalLayoutDirection
import androidx.compose.ui.platform.LocalResources
import androidx.compose.ui.res.dimensionResource
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
@@ -195,12 +195,12 @@ object OverlayShade {
        val ScrimBackground: Color
            @Composable
            @ReadOnlyComposable
            get() = Color(LocalResources.current.notificationScrim(Flags.notificationShadeBlur()))
            get() = Color(notificationScrim(LocalContext.current, Flags.notificationShadeBlur()))

        val PanelBackground: Color
            @Composable
            @ReadOnlyComposable
            get() = Color(LocalResources.current.shadePanel(Flags.notificationShadeBlur()))
            get() = Color(shadePanel(LocalContext.current, Flags.notificationShadeBlur()))
    }

    object Dimensions {
+15 −15
Original line number Diff line number Diff line
@@ -16,34 +16,34 @@

package com.android.systemui.shade.ui

import android.content.res.Resources
import android.content.Context
import android.graphics.Color
import com.android.internal.graphics.ColorUtils
import com.android.systemui.res.R

object ShadeColors {
    @JvmStatic
    fun Resources.shadePanel(blurSupported: Boolean): Int {
    fun shadePanel(context: Context, blurSupported: Boolean): Int {
        return if (blurSupported) {
            shadePanelStandard()
            shadePanelStandard(context)
        } else {
            shadePanelFallback()
            shadePanelFallback(context)
        }
    }

    @JvmStatic
    fun Resources.notificationScrim(blurSupported: Boolean): Int {
    fun notificationScrim(context: Context, blurSupported: Boolean): Int {
        return if (blurSupported) {
            notificationScrimStandard()
            notificationScrimStandard(context)
        } else {
            notificationScrimFallback()
            notificationScrimFallback(context)
        }
    }

    @JvmStatic
    private fun Resources.shadePanelStandard(): Int {
    private fun shadePanelStandard(context: Context): Int {
        val layerAbove = ColorUtils.setAlphaComponent(
            getColor(R.color.shade_panel_base, null),
            context.getColor(R.color.shade_panel_base),
            (0.4f * 255).toInt()
        )
        val layerBelow = ColorUtils.setAlphaComponent(Color.WHITE, (0.1f * 255).toInt())
@@ -51,20 +51,20 @@ object ShadeColors {
    }

    @JvmStatic
    private fun Resources.shadePanelFallback(): Int {
        return getColor(R.color.shade_panel_fallback, null)
    private fun shadePanelFallback(context: Context): Int {
        return context.getColor(R.color.shade_panel_fallback)
    }

    @JvmStatic
    private fun Resources.notificationScrimStandard(): Int {
    private fun notificationScrimStandard(context: Context): Int {
        return ColorUtils.setAlphaComponent(
            getColor(R.color.notification_scrim_base, null),
            context.getColor(R.color.notification_scrim_base),
            (0.5f * 255).toInt(),
        )
    }

    @JvmStatic
    private fun Resources.notificationScrimFallback(): Int {
        return getColor(R.color.notification_scrim_fallback, null)
    private fun notificationScrimFallback(context: Context): Int {
        return context.getColor(R.color.notification_scrim_fallback)
    }
}
+16 −3
Original line number Diff line number Diff line
@@ -76,6 +76,7 @@ import com.android.systemui.scene.shared.model.Scenes;
import com.android.systemui.scrim.ScrimView;
import com.android.systemui.shade.ShadeViewController;
import com.android.systemui.shade.transition.LargeScreenShadeInterpolator;
import com.android.systemui.shade.ui.ShadeColors;
import com.android.systemui.statusbar.notification.stack.ViewState;
import com.android.systemui.statusbar.policy.ConfigurationController;
import com.android.systemui.statusbar.policy.KeyguardStateController;
@@ -433,8 +434,7 @@ public class ScrimController implements ViewTreeObserver.OnPreDrawListener, Dump

        final ScrimState[] states = ScrimState.values();
        for (int i = 0; i < states.length; i++) {
            states[i].init(mScrimInFront, mScrimBehind, mDozeParameters, mDockManager,
                    this::isBlurCurrentlySupported);
            states[i].init(mScrimInFront, mScrimBehind, mDozeParameters, mDockManager);
            states[i].setScrimBehindAlphaKeyguard(mScrimBehindAlphaKeyguard);
            states[i].setDefaultScrimAlpha(getDefaultScrimAlpha());
        }
@@ -540,7 +540,10 @@ public class ScrimController implements ViewTreeObserver.OnPreDrawListener, Dump
            }
        }
        if (Flags.notificationShadeBlur()) {
            mState.prepare(mState);
            for (ScrimState state : ScrimState.values()) {
                state.setNotificationScrimColor(getNotificationsScrimColor());
                state.setShadePanelColor(getShadePanelColor());
            }
        }
        applyAndDispatchState();
    }
@@ -1639,11 +1642,21 @@ public class ScrimController implements ViewTreeObserver.OnPreDrawListener, Dump
                com.android.internal.R.color.materialColorSurface);
        for (ScrimState state : ScrimState.values()) {
            state.setSurfaceColor(surface);
            state.setShadePanelColor(getShadePanelColor());
            state.setNotificationScrimColor(getNotificationsScrimColor());
        }

        mNeedsDrawableColorUpdate = true;
    }

    private int getNotificationsScrimColor() {
        return ShadeColors.notificationScrim(mContext, isBlurCurrentlySupported());
    }

    private int getShadePanelColor() {
        return ShadeColors.shadePanel(mContext, isBlurCurrentlySupported());
    }

    private void onThemeChanged() {
        updateThemeColors();
        scheduleUpdate();
+123 −32
Original line number Diff line number Diff line
@@ -25,7 +25,6 @@ import com.android.systemui.Flags;
import com.android.systemui.dock.DockManager;
import com.android.systemui.res.R;
import com.android.systemui.scrim.ScrimView;
import com.android.systemui.shade.ui.ShadeColors;
import com.android.systemui.statusbar.notification.stack.StackStateAnimator;

import kotlinx.coroutines.ExperimentalCoroutinesApi;
@@ -90,8 +89,7 @@ public enum ScrimState {
            }
            if (Flags.notificationShadeBlur()) {
                mBehindTint = Color.TRANSPARENT;
                mNotifTint = ShadeColors.notificationScrim(mScrimBehind.getResources(),
                        mIsBlurSupported.get());
                mNotifTint = mNotificationScrimColor;
                mBehindAlpha = 0.0f;
                mNotifAlpha = 0.0f;
                mFrontAlpha = 0.0f;
@@ -106,7 +104,16 @@ public enum ScrimState {
                    updateScrimColor(mScrimBehind, 1f /* alpha */, mBackgroundColor);
                }
            }
        }

        @Override
        public void setNotificationScrimColor(int notificationScrimColor) {
            super.setNotificationScrimColor(notificationScrimColor);
            if (Flags.notificationShadeBlur()) {
                // TODO(b/406208846): the keyguard scrims alpha need to be greater than 0.2.
                // They should be updated here as well.
                mNotifTint = mNotificationScrimColor;
            }
        }
    },

@@ -189,12 +196,10 @@ public enum ScrimState {
        @Override
        public void prepare(ScrimState previousState) {
            if (Flags.notificationShadeBlur()) {
                mBehindTint = ShadeColors.shadePanel(mScrimBehind.getResources(),
                        mIsBlurSupported.get());
                mBehindAlpha = Color.alpha(mBehindTint) / 255.0f;
                mNotifTint = ShadeColors.notificationScrim(mScrimBehind.getResources(),
                        mIsBlurSupported.get());
                mNotifAlpha = Color.alpha(mNotifTint) / 255.0f;
                mBehindTint = mShadePanelColor;
                mBehindAlpha = getColorAlpha(mBehindTint);
                mNotifTint = mNotificationScrimColor;
                mNotifAlpha = getColorAlpha(mNotifTint);
                mFrontAlpha = 0.0f;
            } else {
                if (Flags.bouncerUiRevamp()) {
@@ -216,6 +221,24 @@ public enum ScrimState {
                }
            }
        }

        @Override
        public void setShadePanelColor(int shadePanelColor) {
            super.setShadePanelColor(shadePanelColor);
            if (Flags.notificationShadeBlur()) {
                mBehindTint = mShadePanelColor;
                mBehindAlpha = getColorAlpha(mBehindTint);
            }
        }

        @Override
        public void setNotificationScrimColor(int notificationScrimColor) {
            super.setNotificationScrimColor(notificationScrimColor);
            if (Flags.notificationShadeBlur()) {
                mNotifTint = mNotificationScrimColor;
                mNotifAlpha = getColorAlpha(mNotifTint);
            }
        }
    },

    /**
@@ -321,12 +344,10 @@ public enum ScrimState {
                mBehindTint = mBackgroundColor;
                mBlankScreen = true;
            } else if (Flags.notificationShadeBlur()) {
                mBehindTint = ShadeColors.shadePanel(mScrimBehind.getResources(),
                        mIsBlurSupported.get());
                mBehindAlpha = Color.alpha(mBehindTint) / 255.0f;
                mNotifTint = ShadeColors.notificationScrim(mScrimBehind.getResources(),
                        mIsBlurSupported.get());
                mNotifAlpha = Color.alpha(mNotifTint) / 255.0f;
                mBehindTint = mShadePanelColor;
                mBehindAlpha = getColorAlpha(mBehindTint);
                mNotifTint = mNotificationScrimColor;
                mNotifAlpha = getColorAlpha(mNotifTint);
                mFrontAlpha = 0.0f;
                return;
            }
@@ -335,6 +356,24 @@ public enum ScrimState {
                updateScrimColor(mScrimBehind, 1f /* alpha */, mBackgroundColor);
            }
        }

        @Override
        public void setShadePanelColor(int shadePanelColor) {
            super.setShadePanelColor(shadePanelColor);
            if (Flags.notificationShadeBlur()) {
                mBehindTint = mShadePanelColor;
                mBehindAlpha = getColorAlpha(mBehindTint);
            }
        }

        @Override
        public void setNotificationScrimColor(int notificationScrimColor) {
            super.setNotificationScrimColor(notificationScrimColor);
            if (Flags.notificationShadeBlur()) {
                mNotifTint = mNotificationScrimColor;
                mNotifAlpha = getColorAlpha(mNotifTint);
            }
        }
    },

    DREAMING {
@@ -343,12 +382,10 @@ public enum ScrimState {
            if (Flags.notificationShadeBlur()) {
                // Scrim parameters should match SHADE_LOCKED like other activities occluding
                // keyguard.
                mBehindTint = ShadeColors.shadePanel(mScrimBehind.getResources(),
                        mIsBlurSupported.get());
                mBehindAlpha = Color.alpha(mBehindTint) / 255.0f;
                mNotifTint = ShadeColors.notificationScrim(mScrimBehind.getResources(),
                        mIsBlurSupported.get());
                mNotifAlpha = Color.alpha(mNotifTint) / 255.0f;
                mBehindTint = mShadePanelColor;
                mBehindAlpha = getColorAlpha(mBehindTint);
                mNotifTint = mNotificationScrimColor;
                mNotifAlpha = getColorAlpha(mNotifTint);
                mFrontAlpha = 0.0f;
            } else {
                mFrontTint = Color.TRANSPARENT;
@@ -366,6 +403,24 @@ public enum ScrimState {
                }
            }
        }

        @Override
        public void setShadePanelColor(int shadePanelColor) {
            super.setShadePanelColor(shadePanelColor);
            if (Flags.notificationShadeBlur()) {
                mBehindTint = mShadePanelColor;
                mBehindAlpha = getColorAlpha(mBehindTint);
            }
        }

        @Override
        public void setNotificationScrimColor(int notificationScrimColor) {
            super.setNotificationScrimColor(notificationScrimColor);
            if (Flags.notificationShadeBlur()) {
                mNotifTint = mNotificationScrimColor;
                mNotifAlpha = getColorAlpha(mNotifTint);
            }
        }
    },

    /**
@@ -379,8 +434,7 @@ public enum ScrimState {
            if (Flags.notificationShadeBlur()) {
                // Scrim parameters should match KEYGUARD as we're showing on top of keyguard.
                mBehindTint = Color.TRANSPARENT;
                mNotifTint = ShadeColors.notificationScrim(mScrimBehind.getResources(),
                        mIsBlurSupported.get());
                mNotifTint = mNotificationScrimColor;
                mBehindAlpha = 0.0f;
                mNotifAlpha = 0.0f;
                mFrontAlpha = 0.0f;
@@ -395,6 +449,14 @@ public enum ScrimState {
                mNotifTint = mClipQsScrim ? mBackgroundColor : Color.TRANSPARENT;
            }
        }

        @Override
        public void setNotificationScrimColor(int notificationScrimColor) {
            super.setNotificationScrimColor(notificationScrimColor);
            if (Flags.notificationShadeBlur()) {
                mNotifTint = mNotificationScrimColor;
            }
        }
    },

    /**
@@ -410,12 +472,10 @@ public enum ScrimState {
        public void prepare(ScrimState previousState) {
            if (Flags.notificationShadeBlur()) {
                // Scrim parameters should match DREAM as hub is showing while on top of the dream.
                mBehindTint = ShadeColors.shadePanel(mScrimBehind.getResources(),
                        mIsBlurSupported.get());
                mBehindAlpha = Color.alpha(mBehindTint) / 255.0f;
                mNotifTint = ShadeColors.notificationScrim(mScrimBehind.getResources(),
                        mIsBlurSupported.get());
                mNotifAlpha = Color.alpha(mNotifTint) / 255.0f;
                mBehindTint = mShadePanelColor;
                mBehindAlpha = getColorAlpha(mBehindTint);
                mNotifTint = mNotificationScrimColor;
                mNotifAlpha = getColorAlpha(mNotifTint);
                mFrontAlpha = 0.0f;
            } else {
                // No scrims should be visible by default in this state.
@@ -428,6 +488,24 @@ public enum ScrimState {
                mNotifTint = mClipQsScrim ? mBackgroundColor : Color.TRANSPARENT;
            }
        }

        @Override
        public void setShadePanelColor(int shadePanelColor) {
            super.setShadePanelColor(shadePanelColor);
            if (Flags.notificationShadeBlur()) {
                mBehindTint = mShadePanelColor;
                mBehindAlpha = getColorAlpha(mBehindTint);
            }
        }

        @Override
        public void setNotificationScrimColor(int notificationScrimColor) {
            super.setNotificationScrimColor(notificationScrimColor);
            if (Flags.notificationShadeBlur()) {
                mNotifTint = mNotificationScrimColor;
                mNotifAlpha = getColorAlpha(mNotifTint);
            }
        }
    };

    boolean mBlankScreen = false;
@@ -437,6 +515,9 @@ public enum ScrimState {
    int mNotifTint = Color.TRANSPARENT;
    int mSurfaceColor = Color.TRANSPARENT;

    int mShadePanelColor = Color.TRANSPARENT;
    int mNotificationScrimColor = Color.TRANSPARENT;

    boolean mAnimateChange = true;
    float mAodFrontScrimAlpha;
    float mFrontAlpha;
@@ -451,7 +532,6 @@ public enum ScrimState {
    DozeParameters mDozeParameters;
    DockManager mDockManager;
    boolean mDisplayRequiresBlanking;
    protected Supplier<Boolean> mIsBlurSupported;
    boolean mLaunchingAffordanceWithPreview;
    boolean mOccludeAnimationPlaying;
    boolean mWakeLockScreenSensorActive;
@@ -465,7 +545,7 @@ public enum ScrimState {
    protected float mNotifBlurRadius = 0.0f;

    public void init(ScrimView scrimInFront, ScrimView scrimBehind, DozeParameters dozeParameters,
            DockManager dockManager, Supplier<Boolean> isBlurSupported) {
            DockManager dockManager) {
        mBackgroundColor = scrimBehind.getContext().getColor(R.color.shade_scrim_background_dark);
        mScrimInFront = scrimInFront;
        mScrimBehind = scrimBehind;
@@ -473,7 +553,6 @@ public enum ScrimState {
        mDozeParameters = dozeParameters;
        mDockManager = dockManager;
        mDisplayRequiresBlanking = dozeParameters.getDisplayNeedsBlanking();
        mIsBlurSupported = isBlurSupported;
    }

    /** Prepare state for transition. */
@@ -556,6 +635,14 @@ public enum ScrimState {
        mSurfaceColor = surfaceColor;
    }

    public void setShadePanelColor(int shadePanelColor) {
        mShadePanelColor = shadePanelColor;
    }

    public void setNotificationScrimColor(int notificationScrimColor) {
        mNotificationScrimColor = notificationScrimColor;
    }

    public void setLaunchingAffordanceWithPreview(boolean launchingAffordanceWithPreview) {
        mLaunchingAffordanceWithPreview = launchingAffordanceWithPreview;
    }
@@ -588,4 +675,8 @@ public enum ScrimState {
    public void setNotifBlurRadius(float value) {
        mNotifBlurRadius = value;
    }

    private static float getColorAlpha(int color) {
        return Color.alpha(color) / 255.0f;
    }
}