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
This commit is contained in:
Selim Cinek
2016-12-29 16:49:26 +01:00
parent 2b6eb803ef
commit fb6ee6d60c
4 changed files with 43 additions and 16 deletions

View File

@@ -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,9 +1022,13 @@ public abstract class ActivatableNotificationView extends ExpandableOutlineView
@Override
public void setFakeShadowIntensity(float shadowIntensity, float outlineAlpha, int shadowYEnd,
int outlineTranslation) {
mFakeShadow.setFakeShadowTranslationZ(shadowIntensity * (getTranslationZ()
+ FakeShadowView.SHADOW_SIBLING_TRESHOLD), outlineAlpha, shadowYEnd,
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() {

View File

@@ -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;
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;
boolean belowThresholdBefore = mScrimAlphaBelowThreshold;
mScrimAlphaBelowThreshold = mScrimAlpha < NAV_BAR_INVERSION_SCRIM_ALPHA_THRESHOLD;
if (mHasLightNavigationBar && belowThresholdBefore != mScrimAlphaBelowThreshold) {
reevaluate();
}
}
private boolean isLight(int vis, int barMode, int flag) {

View File

@@ -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) {

View File

@@ -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,8 +446,11 @@ public class NotificationStackScrollLayout extends ViewGroup
+ alphaInv * Color.green(scrimColor)),
(int) (mBackgroundFadeAmount * Color.blue(mBgColor)
+ alphaInv * Color.blue(scrimColor)));
mBackgroundPaint.setColor(color);
invalidate();
if (mCachedBackgroundColor != color) {
mCachedBackgroundColor = color;
mBackgroundPaint.setColor(color);
invalidate();
}
}
private void initView(Context context) {
@@ -2092,9 +2096,14 @@ public class NotificationStackScrollLayout extends ViewGroup
* Update the background bounds to the new desired bounds
*/
private void updateBackgroundBounds() {
getLocationInWindow(mTempInt2);
mBackgroundBounds.left = mTempInt2[0];
mBackgroundBounds.right = mTempInt2[0] + getWidth();
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;