Add a background scrim to launcher for text protection.

This is a temporary approach to dim the wallpaper. Flip on ENABLE_WALLPAPER_SCRIM to enable the scrim.

In the long term we'll dim the wallpaper layer directly.

Test: Manual
Bug: 185890335
Change-Id: Ia88597bbcba6ae1536015d1b2a35260cab4a4453
This commit is contained in:
Shan Huang
2021-05-06 15:09:15 +08:00
parent 739420bc38
commit 18caa92dba
4 changed files with 27 additions and 3 deletions

View File

@@ -58,5 +58,6 @@
<color name="text_color_tertiary_dark">#CCFFFFFF</color>
<color name="wallpaper_popup_scrim">?android:attr/colorAccent</color>
<color name="wallpaper_scrim_color">#0D878787</color>
</resources>

View File

@@ -4,6 +4,6 @@
<entry id="@color/delete_target_hover_tint" />
<entry id="@color/delete_target_hover_tint" />
<entry id="@color/delete_target_hover_tint" />
<entry id="@color/wallpaper_scrim_color" />
</DynamicResources>
</DynamicResources>

View File

@@ -240,6 +240,10 @@ public final class FeatureFlags {
public static final BooleanFlag PROTOTYPE_APP_CLOSE = getDebugFlag(
"PROTOTYPE_APP_CLOSE", false, "Enables new app close");
public static final BooleanFlag ENABLE_WALLPAPER_SCRIM = getDebugFlag(
"ENABLE_WALLPAPER_SCRIM", false,
"Enables scrim over wallpaper for text protection.");
public static void initialize(Context context) {
synchronized (sDebugFlags) {
for (DebugFlag flag : sDebugFlags) {

View File

@@ -45,7 +45,10 @@ import com.android.launcher3.BaseDraggingActivity;
import com.android.launcher3.R;
import com.android.launcher3.ResourceUtils;
import com.android.launcher3.Utilities;
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.util.DynamicResource;
import com.android.launcher3.util.Themes;
import com.android.systemui.plugins.ResourceProvider;
/**
* View scrim which draws behind hotseat and workspace
@@ -101,8 +104,10 @@ public class SysUiScrim implements View.OnAttachStateChangeListener {
private static final int ALPHA_MASK_BITMAP_DP = 200;
private static final int ALPHA_MASK_WIDTH_DP = 2;
private boolean mDrawTopScrim, mDrawBottomScrim;
private boolean mDrawTopScrim, mDrawBottomScrim, mDrawWallpaperScrim;
private final RectF mWallpaperScrimRect = new RectF();
private final Paint mWallpaperScrimPaint = new Paint();
private final RectF mFinalMaskRect = new RectF();
private final Paint mBottomMaskPaint = new Paint(Paint.FILTER_BITMAP_FLAG);
private final Bitmap mBottomMask;
@@ -117,6 +122,7 @@ public class SysUiScrim implements View.OnAttachStateChangeListener {
private boolean mAnimateScrimOnNextDraw = false;
private float mSysUiAnimMultiplier = 1;
private int mWallpaperScrimMaxAlpha;
public SysUiScrim(View view) {
mRoot = view;
@@ -127,6 +133,14 @@ public class SysUiScrim implements View.OnAttachStateChangeListener {
mBottomMask = mTopScrim == null ? null : createDitheredAlphaMask();
mHideSysUiScrim = mTopScrim == null;
mDrawWallpaperScrim = FeatureFlags.ENABLE_WALLPAPER_SCRIM.get()
&& !Themes.getAttrBoolean(view.getContext(), R.attr.isMainColorDark)
&& !Themes.getAttrBoolean(view.getContext(), R.attr.isWorkspaceDarkText);
ResourceProvider rp = DynamicResource.provider(view.getContext());
int wallpaperScrimColor = rp.getColor(R.color.wallpaper_scrim_color);
mWallpaperScrimMaxAlpha = Color.alpha(wallpaperScrimColor);
mWallpaperScrimPaint.setColor(wallpaperScrimColor);
view.addOnAttachStateChangeListener(this);
}
@@ -151,6 +165,9 @@ public class SysUiScrim implements View.OnAttachStateChangeListener {
mAnimateScrimOnNextDraw = false;
}
if (mDrawWallpaperScrim) {
canvas.drawRect(mWallpaperScrimRect, mWallpaperScrimPaint);
}
if (mDrawTopScrim) {
mTopScrim.draw(canvas);
}
@@ -214,6 +231,7 @@ public class SysUiScrim implements View.OnAttachStateChangeListener {
mTopScrim.setBounds(0, 0, w, h);
mFinalMaskRect.set(0, h - mMaskHeight, w, h);
}
mWallpaperScrimRect.set(0, 0, w, h);
}
private void setSysUiProgress(float progress) {
@@ -236,6 +254,7 @@ public class SysUiScrim implements View.OnAttachStateChangeListener {
if (mTopScrim != null) {
mTopScrim.setAlpha(Math.round(255 * factor));
}
mWallpaperScrimPaint.setAlpha(Math.round(mWallpaperScrimMaxAlpha * factor));
}
private Bitmap createDitheredAlphaMask() {