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

Commit 3d36dd83 authored by Lucas Dupin's avatar Lucas Dupin
Browse files

Light scrim on pulsing state

New scrim opacity - 20% - and also keeping the pulse state bright,
so it's more similar to lock screen.

Bug: 111405682
Test: visual
Test: atest ScrimControllerTest
Change-Id: Iecf86f5eeb5fcab9ada198e97f7da2f4e362e22f
parent 61ae7ed2
Loading
Loading
Loading
Loading
+0 −3
Original line number Diff line number Diff line
@@ -5219,9 +5219,6 @@ public class NotificationStackScrollLayout extends ViewGroup implements ScrollAd
        // another "changeViewPosition" call is ever added.
        changeViewPosition(mShelf,
                getChildCount() - offsetFromEnd);

        // Scrim opacity varies based on notification count
        mScrimController.setNotificationCount(getNotGoneChildCount());
    }

    @ShadeViewRefactor(RefactorComponent.SHADE_VIEW)
+4 −27
Original line number Diff line number Diff line
@@ -88,16 +88,12 @@ public class ScrimController implements ViewTreeObserver.OnPreDrawListener, OnCo
    /**
     * Default alpha value for most scrims.
     */
    public static final float GRADIENT_SCRIM_ALPHA = 0.45f;
    public static final float GRADIENT_SCRIM_ALPHA = 0.2f;
    /**
     * A scrim varies its opacity based on a busyness factor, for example
     * how many notifications are currently visible.
     */
    public static final float GRADIENT_SCRIM_ALPHA_BUSY = 0.7f;
    /**
     * Scrim opacity when a wallpaper doesn't support ambient mode.
     */
    public static final float PULSING_WALLPAPER_SCRIM_ALPHA = 0.6f;

    /**
     * The most common scrim, the one under the keyguard.
@@ -154,7 +150,6 @@ public class ScrimController implements ViewTreeObserver.OnPreDrawListener, OnCo
    private Callback mCallback;
    private boolean mWallpaperSupportsAmbientMode;
    private boolean mScreenOn;
    private float mNotificationDensity;

    // Scrim blanking callbacks
    private Runnable mPendingFrameCallback;
@@ -245,7 +240,7 @@ public class ScrimController implements ViewTreeObserver.OnPreDrawListener, OnCo
        mCurrentInFrontTint = state.getFrontTint();
        mCurrentBehindTint = state.getBehindTint();
        mCurrentInFrontAlpha = state.getFrontAlpha();
        mCurrentBehindAlpha = state.getBehindAlpha(mNotificationDensity);
        mCurrentBehindAlpha = state.getBehindAlpha();
        applyExpansionToAlpha();

        // Scrim might acquire focus when user is navigating with a D-pad or a keyboard.
@@ -416,7 +411,7 @@ public class ScrimController implements ViewTreeObserver.OnPreDrawListener, OnCo
            // Either darken of make the scrim transparent when you
            // pull down the shade
            float interpolatedFract = getInterpolatedFraction();
            float alphaBehind = mState.getBehindAlpha(mNotificationDensity);
            float alphaBehind = mState.getBehindAlpha();
            if (mDarkenWhileDragging) {
                mCurrentBehindAlpha = MathUtils.lerp(GRADIENT_SCRIM_ALPHA_BUSY, alphaBehind,
                        interpolatedFract);
@@ -429,24 +424,6 @@ public class ScrimController implements ViewTreeObserver.OnPreDrawListener, OnCo
        }
    }

    /**
     * Keyguard and shade scrim opacity varies according to how many notifications are visible.
     * @param notificationCount Number of visible notifications.
     */
    public void setNotificationCount(int notificationCount) {
        final float maxNotificationDensity = 3;
        float notificationDensity = Math.min(notificationCount / maxNotificationDensity, 1f);
        if (mNotificationDensity == notificationDensity) {
            return;
        }
        mNotificationDensity = notificationDensity;

        if (mState == ScrimState.KEYGUARD) {
            applyExpansionToAlpha();
            scheduleUpdate();
        }
    }

    /**
     * Sets the given drawable as the background of the scrim that shows up behind the
     * notifications.
@@ -909,7 +886,7 @@ public class ScrimController implements ViewTreeObserver.OnPreDrawListener, OnCo
        // Backdrop event may arrive after state was already applied,
        // in this case, back-scrim needs to be re-evaluated
        if (mState == ScrimState.AOD || mState == ScrimState.PULSING) {
            float newBehindAlpha = mState.getBehindAlpha(mNotificationDensity);
            float newBehindAlpha = mState.getBehindAlpha();
            if (mCurrentBehindAlpha != newBehindAlpha) {
                mCurrentBehindAlpha = newBehindAlpha;
                updateScrims();
+3 −18
Original line number Diff line number Diff line
@@ -18,7 +18,6 @@ package com.android.systemui.statusbar.phone;

import android.graphics.Color;
import android.os.Trace;
import android.util.MathUtils;

import com.android.systemui.statusbar.ScrimView;
import com.android.systemui.statusbar.notification.stack.StackStateAnimator;
@@ -57,13 +56,6 @@ public enum ScrimState {
            mCurrentBehindAlpha = mScrimBehindAlphaKeyguard;
            mCurrentInFrontAlpha = 0;
        }

        @Override
        public float getBehindAlpha(float busynessFactor) {
            return MathUtils.map(0 /* start */, 1 /* stop */,
                    mScrimBehindAlphaKeyguard, ScrimController.GRADIENT_SCRIM_ALPHA_BUSY,
                    busynessFactor);
        }
    },

    /**
@@ -117,7 +109,7 @@ public enum ScrimState {
        }

        @Override
        public float getBehindAlpha(float busyness) {
        public float getBehindAlpha() {
            return mWallpaperSupportsAmbientMode && !mHasBackdrop ? 0f : 1f;
        }

@@ -134,16 +126,9 @@ public enum ScrimState {
        @Override
        public void prepare(ScrimState previousState) {
            mCurrentInFrontAlpha = 0;
            mCurrentInFrontTint = Color.BLACK;
            mCurrentBehindTint = Color.BLACK;
            mCurrentBehindAlpha = mScrimBehindAlphaKeyguard;
            mBlankScreen = mDisplayRequiresBlanking;
        }

        @Override
        public float getBehindAlpha(float busyness) {
            return mWallpaperSupportsAmbientMode && !mHasBackdrop ? 0f
                    : ScrimController.PULSING_WALLPAPER_SCRIM_ALPHA;
        }
    },

    /**
@@ -235,7 +220,7 @@ public enum ScrimState {
        return mCurrentInFrontAlpha;
    }

    public float getBehindAlpha(float busyness) {
    public float getBehindAlpha() {
        return mCurrentBehindAlpha;
    }

+3 −49
Original line number Diff line number Diff line
@@ -133,10 +133,10 @@ public class ScrimControllerTest extends SysuiTestCase {
        // Back scrim should be transparent
        assertScrimVisibility(VISIBILITY_FULLY_TRANSPARENT, VISIBILITY_FULLY_TRANSPARENT);

        // Move on to PULSING and check if the back scrim is still transparent
        // Move on to PULSING and check if the back scrim was updated
        mScrimController.transitionTo(ScrimState.PULSING);
        mScrimController.finishAnimationsImmediately();
        assertScrimVisibility(VISIBILITY_FULLY_TRANSPARENT, VISIBILITY_FULLY_TRANSPARENT);
        assertScrimVisibility(VISIBILITY_FULLY_TRANSPARENT, VISIBILITY_SEMI_TRANSPARENT);
    }

    @Test
@@ -224,7 +224,7 @@ public class ScrimControllerTest extends SysuiTestCase {
        // Back scrim should be semi-transparent so the user can see the wallpaper
        // Pulse callback should have been invoked
        assertScrimVisibility(VISIBILITY_FULLY_TRANSPARENT, VISIBILITY_SEMI_TRANSPARENT);
        assertScrimTint(mScrimBehind, true /* tinted */);
        assertScrimTint(mScrimBehind, false /* tinted */);
    }

    @Test
@@ -560,34 +560,6 @@ public class ScrimControllerTest extends SysuiTestCase {
        Assert.assertTrue(mScrimController.wasAnimationJustCancelled());
    }

    /**
     * Number of visible notifications affects scrim opacity.
     */
    @Test
    public void testNotificationDensity() {
        mScrimController.transitionTo(ScrimState.KEYGUARD);
        mScrimController.finishAnimationsImmediately();

        mScrimController.setNotificationCount(0);
        mScrimController.finishAnimationsImmediately();
        Assert.assertEquals("lower density when no notifications",
                ScrimController.GRADIENT_SCRIM_ALPHA,  mScrimBehind.getViewAlpha(), 0.01f);

        mScrimController.setNotificationCount(3);
        mScrimController.finishAnimationsImmediately();
        Assert.assertEquals("stronger density when notifications are visible",
                ScrimController.GRADIENT_SCRIM_ALPHA_BUSY,  mScrimBehind.getViewAlpha(), 0.01f);
    }

    /**
     * Moving from/to states conserves old notification density.
     */
    @Test
    public void testConservesNotificationDensity() {
        testConservesNotificationDensity(0 /* count */, ScrimController.GRADIENT_SCRIM_ALPHA);
        testConservesNotificationDensity(3 /* count */, ScrimController.GRADIENT_SCRIM_ALPHA_BUSY);
    }

    @Test
    public void testScrimFocus() {
        mScrimController.transitionTo(ScrimState.AOD);
@@ -662,24 +634,6 @@ public class ScrimControllerTest extends SysuiTestCase {
                mScrimBehind.getDefaultFocusHighlightEnabled());
    }

    /**
     * Conserves old notification density after leaving state and coming back.
     *
     * @param count How many notification.
     * @param expectedAlpha Expected alpha.
     */
    private void testConservesNotificationDensity(int count, float expectedAlpha) {
        mScrimController.setNotificationCount(count);
        mScrimController.transitionTo(ScrimState.UNLOCKED);
        mScrimController.finishAnimationsImmediately();

        mScrimController.transitionTo(ScrimState.KEYGUARD);
        mScrimController.finishAnimationsImmediately();

        Assert.assertEquals("Doesn't respect notification busyness after transition",
                expectedAlpha,  mScrimBehind.getViewAlpha(), 0.01f);
    }

    private void assertScrimTint(ScrimView scrimView, boolean tinted) {
        final boolean viewIsTinted = scrimView.getTint() != Color.TRANSPARENT;
        final String name = scrimView == mScrimInFront ? "front" : "back";