Simplifying scrim drawable initialization.

Scrim drawable is initialized as null in certain cases in code, but it is also
initialized as null in sytle. Only using the style definition as source of
truth to avoid missing null checks

Bug: 118450709
Change-Id: I9dab18405932d1b5c0e697838738a1392f97021c
This commit is contained in:
Sunny Goyal 2018-10-31 13:57:15 -07:00
parent b3fe661860
commit 7fbc503b9a
1 changed files with 17 additions and 23 deletions

View File

@ -121,7 +121,6 @@ public class WorkspaceAndHotseatScrim implements
private Workspace mWorkspace; private Workspace mWorkspace;
private final boolean mHasSysUiScrim;
private boolean mDrawTopScrim, mDrawBottomScrim; private boolean mDrawTopScrim, mDrawBottomScrim;
private final RectF mFinalMaskRect = new RectF(); private final RectF mFinalMaskRect = new RectF();
@ -149,15 +148,9 @@ public class WorkspaceAndHotseatScrim implements
mMaskHeight = Utilities.pxFromDp(ALPHA_MASK_BITMAP_DP, mMaskHeight = Utilities.pxFromDp(ALPHA_MASK_BITMAP_DP,
view.getResources().getDisplayMetrics()); view.getResources().getDisplayMetrics());
mTopScrim = Themes.getAttrDrawable(view.getContext(), R.attr.workspaceStatusBarScrim);
mHasSysUiScrim = !mWallpaperColorInfo.supportsDarkText(); mBottomMask = mTopScrim == null ? null : createDitheredAlphaMask();
if (mHasSysUiScrim) { mHideSysUiScrim = mTopScrim == null;
mTopScrim = Themes.getAttrDrawable(view.getContext(), R.attr.workspaceStatusBarScrim);
mBottomMask = createDitheredAlphaMask();
} else {
mTopScrim = null;
mBottomMask = null;
}
view.addOnAttachStateChangeListener(this); view.addOnAttachStateChangeListener(this);
onExtractedColorsChanged(mWallpaperColorInfo); onExtractedColorsChanged(mWallpaperColorInfo);
@ -185,7 +178,7 @@ public class WorkspaceAndHotseatScrim implements
canvas.restore(); canvas.restore();
} }
if (!mHideSysUiScrim && mHasSysUiScrim) { if (!mHideSysUiScrim) {
if (mSysUiProgress <= 0) { if (mSysUiProgress <= 0) {
mAnimateScrimOnNextDraw = false; mAnimateScrimOnNextDraw = false;
return; return;
@ -213,8 +206,9 @@ public class WorkspaceAndHotseatScrim implements
} }
public void onInsetsChanged(Rect insets) { public void onInsetsChanged(Rect insets) {
mDrawTopScrim = insets.top > 0; mDrawTopScrim = mTopScrim != null && insets.top > 0;
mDrawBottomScrim = !mLauncher.getDeviceProfile().isVerticalBarLayout(); mDrawBottomScrim = mBottomMask != null &&
!mLauncher.getDeviceProfile().isVerticalBarLayout();
} }
private void setScrimProgress(float progress) { private void setScrimProgress(float progress) {
@ -230,7 +224,7 @@ public class WorkspaceAndHotseatScrim implements
mWallpaperColorInfo.addOnChangeListener(this); mWallpaperColorInfo.addOnChangeListener(this);
onExtractedColorsChanged(mWallpaperColorInfo); onExtractedColorsChanged(mWallpaperColorInfo);
if (mHasSysUiScrim) { if (mTopScrim != null) {
IntentFilter filter = new IntentFilter(ACTION_SCREEN_OFF); IntentFilter filter = new IntentFilter(ACTION_SCREEN_OFF);
filter.addAction(ACTION_USER_PRESENT); // When the device wakes up + keyguard is gone filter.addAction(ACTION_USER_PRESENT); // When the device wakes up + keyguard is gone
mRoot.getContext().registerReceiver(mReceiver, filter); mRoot.getContext().registerReceiver(mReceiver, filter);
@ -240,7 +234,7 @@ public class WorkspaceAndHotseatScrim implements
@Override @Override
public void onViewDetachedFromWindow(View view) { public void onViewDetachedFromWindow(View view) {
mWallpaperColorInfo.removeOnChangeListener(this); mWallpaperColorInfo.removeOnChangeListener(this);
if (mHasSysUiScrim) { if (mTopScrim != null) {
mRoot.getContext().unregisterReceiver(mReceiver); mRoot.getContext().unregisterReceiver(mReceiver);
} }
} }
@ -259,14 +253,14 @@ public class WorkspaceAndHotseatScrim implements
} }
public void setSize(int w, int h) { public void setSize(int w, int h) {
if (mHasSysUiScrim) { if (mTopScrim != null) {
mTopScrim.setBounds(0, 0, w, h); mTopScrim.setBounds(0, 0, w, h);
mFinalMaskRect.set(0, h - mMaskHeight, w, h); mFinalMaskRect.set(0, h - mMaskHeight, w, h);
} }
} }
public void hideSysUiScrim(boolean hideSysUiScrim) { public void hideSysUiScrim(boolean hideSysUiScrim) {
mHideSysUiScrim = hideSysUiScrim; mHideSysUiScrim = hideSysUiScrim || (mTopScrim == null);
if (!hideSysUiScrim) { if (!hideSysUiScrim) {
mAnimateScrimOnNextDraw = true; mAnimateScrimOnNextDraw = true;
} }
@ -281,18 +275,18 @@ public class WorkspaceAndHotseatScrim implements
} }
private void reapplySysUiAlpha() { private void reapplySysUiAlpha() {
if (mHasSysUiScrim) { reapplySysUiAlphaNoInvalidate();
reapplySysUiAlphaNoInvalidate(); if (!mHideSysUiScrim) {
if (!mHideSysUiScrim) { invalidate();
invalidate();
}
} }
} }
private void reapplySysUiAlphaNoInvalidate() { private void reapplySysUiAlphaNoInvalidate() {
float factor = mSysUiProgress * mSysUiAnimMultiplier; float factor = mSysUiProgress * mSysUiAnimMultiplier;
mBottomMaskPaint.setAlpha(Math.round(MAX_HOTSEAT_SCRIM_ALPHA * factor)); mBottomMaskPaint.setAlpha(Math.round(MAX_HOTSEAT_SCRIM_ALPHA * factor));
mTopScrim.setAlpha(Math.round(255 * factor)); if (mTopScrim != null) {
mTopScrim.setAlpha(Math.round(255 * factor));
}
} }
public void invalidate() { public void invalidate() {