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
diff --git a/res/values/colors.xml b/res/values/colors.xml
index 83d2deb..56a0e6b 100644
--- a/res/values/colors.xml
+++ b/res/values/colors.xml
@@ -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>
diff --git a/res/xml/dynamic_resources.xml b/res/xml/dynamic_resources.xml
index f5d2628..3a3e239 100644
--- a/res/xml/dynamic_resources.xml
+++ b/res/xml/dynamic_resources.xml
@@ -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>
\ No newline at end of file
+</DynamicResources>
diff --git a/src/com/android/launcher3/config/FeatureFlags.java b/src/com/android/launcher3/config/FeatureFlags.java
index 3b88a0b..ba5101b 100644
--- a/src/com/android/launcher3/config/FeatureFlags.java
+++ b/src/com/android/launcher3/config/FeatureFlags.java
@@ -240,6 +240,10 @@
     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) {
diff --git a/src/com/android/launcher3/graphics/SysUiScrim.java b/src/com/android/launcher3/graphics/SysUiScrim.java
index c09dac8..f0766c5 100644
--- a/src/com/android/launcher3/graphics/SysUiScrim.java
+++ b/src/com/android/launcher3/graphics/SysUiScrim.java
@@ -45,7 +45,10 @@
 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 @@
     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 @@
 
     private boolean mAnimateScrimOnNextDraw = false;
     private float mSysUiAnimMultiplier = 1;
+    private int mWallpaperScrimMaxAlpha;
 
     public SysUiScrim(View view) {
         mRoot = view;
@@ -127,6 +133,14 @@
         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 @@
                 mAnimateScrimOnNextDraw = false;
             }
 
+            if (mDrawWallpaperScrim) {
+                canvas.drawRect(mWallpaperScrimRect, mWallpaperScrimPaint);
+            }
             if (mDrawTopScrim) {
                 mTopScrim.draw(canvas);
             }
@@ -214,6 +231,7 @@
             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 @@
         if (mTopScrim != null) {
             mTopScrim.setAlpha(Math.round(255 * factor));
         }
+        mWallpaperScrimPaint.setAlpha(Math.round(mWallpaperScrimMaxAlpha * factor));
     }
 
     private Bitmap createDitheredAlphaMask() {