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

Commit fb6ee6d6 authored by Selim Cinek's avatar Selim Cinek
Browse files

Improved the performance of the shelf / scrim

We are now caching the light status bar state and
are only reevaluating it if it changed / alpha changed.
Similarly, we now cache the background color for the
scrim, since that usually doesn't even change
in the shade, only on the lockscreen with transparency.

Change-Id: I417bf8286b8ccdfcfb143e8ea365b01c2b348be7
Test: runtest systemui-jank -c android.platform.systemui.tests.jank.SystemUiJankTests -m testNotificationListPull_manyNotifications
Bug: 33252359
parent 2b6eb803
Loading
Loading
Loading
Loading
+9 −3
Original line number Diff line number Diff line
@@ -182,6 +182,7 @@ public abstract class ActivatableNotificationView extends ExpandableOutlineView
    private int mStartTint;
    private int mOverrideTint;
    private float mOverrideAmount;
    private boolean mShadowHidden;

    public ActivatableNotificationView(Context context, AttributeSet attrs) {
        super(context, attrs);
@@ -210,6 +211,7 @@ public abstract class ActivatableNotificationView extends ExpandableOutlineView
        super.onFinishInflate();
        mBackgroundNormal = (NotificationBackgroundView) findViewById(R.id.backgroundNormal);
        mFakeShadow = (FakeShadowView) findViewById(R.id.fake_shadow);
        mShadowHidden = mFakeShadow.getVisibility() != VISIBLE;
        mBackgroundDimmed = (NotificationBackgroundView) findViewById(R.id.backgroundDimmed);
        mBackgroundNormal.setCustomBackground(R.drawable.notification_material_bg);
        mBackgroundDimmed.setCustomBackground(R.drawable.notification_material_bg_dim);
@@ -1020,10 +1022,14 @@ public abstract class ActivatableNotificationView extends ExpandableOutlineView
    @Override
    public void setFakeShadowIntensity(float shadowIntensity, float outlineAlpha, int shadowYEnd,
            int outlineTranslation) {
        boolean hiddenBefore = mShadowHidden;
        mShadowHidden = shadowIntensity == 0.0f;
        if (!mShadowHidden || !hiddenBefore) {
            mFakeShadow.setFakeShadowTranslationZ(shadowIntensity * (getTranslationZ()
                            + FakeShadowView.SHADOW_SIBLING_TRESHOLD), outlineAlpha, shadowYEnd,
                    outlineTranslation);
        }
    }

    public int getBackgroundColorWithoutTint() {
        return calculateBgColor(false /* withTint */, false /* withOverride */);
+19 −7
Original line number Diff line number Diff line
@@ -43,7 +43,18 @@ public class LightBarController implements BatteryController.BatteryStateChangeC
    private boolean mDockedLight;
    private int mLastStatusBarMode;
    private int mLastNavigationBarMode;

    /**
     * Whether the navigation bar should be light factoring in already how much alpha the scrim has
     */
    private boolean mNavigationLight;

    /**
     * Whether the flags indicate that a light status bar is requested. This doesn't factor in the
     * scrim alpha yet.
     */
    private boolean mHasLightNavigationBar;
    private boolean mScrimAlphaBelowThreshold;
    private float mScrimAlpha;

    private final Rect mLastFullscreenBounds = new Rect();
@@ -90,7 +101,9 @@ public class LightBarController implements BatteryController.BatteryStateChangeC
        if ((diffVis & View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR) != 0
                || nbModeChanged) {
            boolean last = mNavigationLight;
            mNavigationLight = isNavigationLight(newVis, navigationBarMode);
            mHasLightNavigationBar = isLight(vis, navigationBarMode,
                    View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR);
            mNavigationLight = mHasLightNavigationBar && mScrimAlphaBelowThreshold;
            if (mNavigationLight != last) {
                updateNavigation();
            }
@@ -113,12 +126,11 @@ public class LightBarController implements BatteryController.BatteryStateChangeC

    public void setScrimAlpha(float alpha) {
        mScrimAlpha = alpha;
        boolean belowThresholdBefore = mScrimAlphaBelowThreshold;
        mScrimAlphaBelowThreshold = mScrimAlpha < NAV_BAR_INVERSION_SCRIM_ALPHA_THRESHOLD;
        if (mHasLightNavigationBar && belowThresholdBefore != mScrimAlphaBelowThreshold) {
            reevaluate();
        }

    private boolean isNavigationLight(int vis, int barMode) {
        return isLight(vis, barMode, View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR)
                && mScrimAlpha < NAV_BAR_INVERSION_SCRIM_ALPHA_THRESHOLD;
    }

    private boolean isLight(int vis, int barMode, int flag) {
+1 −1
Original line number Diff line number Diff line
@@ -338,13 +338,13 @@ public class ScrimController implements ViewTreeObserver.OnPreDrawListener,
    private void setCurrentScrimAlpha(View scrim, float alpha) {
        if (scrim == mScrimBehind) {
            mCurrentBehindAlpha = alpha;
            mLightBarController.setScrimAlpha(mCurrentBehindAlpha);
        } else if (scrim == mScrimInFront) {
            mCurrentInFrontAlpha = alpha;
        } else {
            alpha = Math.max(0.0f, Math.min(1.0f, alpha));
            mCurrentHeadsUpAlpha = alpha;
        }
        mLightBarController.setScrimAlpha(mCurrentBehindAlpha);
    }

    protected void updateScrimColor(View scrim) {
+14 −5
Original line number Diff line number Diff line
@@ -359,6 +359,7 @@ public class NotificationStackScrollLayout extends ViewGroup
    private boolean mInHeadsUpPinnedMode;
    private boolean mHeadsUpAnimatingAway;
    private int mStatusBarState;
    private int mCachedBackgroundColor;

    public NotificationStackScrollLayout(Context context) {
        this(context, null);
@@ -445,9 +446,12 @@ public class NotificationStackScrollLayout extends ViewGroup
                        + alphaInv * Color.green(scrimColor)),
                (int) (mBackgroundFadeAmount * Color.blue(mBgColor)
                        + alphaInv * Color.blue(scrimColor)));
        if (mCachedBackgroundColor != color) {
            mCachedBackgroundColor = color;
            mBackgroundPaint.setColor(color);
            invalidate();
        }
    }

    private void initView(Context context) {
        mScroller = new OverScroller(getContext());
@@ -2092,9 +2096,14 @@ public class NotificationStackScrollLayout extends ViewGroup
     * Update the background bounds to the new desired bounds
     */
    private void updateBackgroundBounds() {
        if (mAmbientState.isPanelFullWidth()) {
            mBackgroundBounds.left = 0;
            mBackgroundBounds.right = getWidth();
        } else {
            getLocationInWindow(mTempInt2);
            mBackgroundBounds.left = mTempInt2[0];
            mBackgroundBounds.right = mTempInt2[0] + getWidth();
        }
        if (!mIsExpanded) {
            mBackgroundBounds.top = 0;
            mBackgroundBounds.bottom = 0;