Removing ViewScrim and cutom drawing code

Bug: 109828640
Change-Id: I2cab0215a32c2ca6bc331d48083fcc00ada05c3b
diff --git a/src/com/android/launcher3/InsettableFrameLayout.java b/src/com/android/launcher3/InsettableFrameLayout.java
index 1db1fc0..faa18b8 100644
--- a/src/com/android/launcher3/InsettableFrameLayout.java
+++ b/src/com/android/launcher3/InsettableFrameLayout.java
@@ -68,7 +68,7 @@
     }
 
     public static class LayoutParams extends FrameLayout.LayoutParams {
-        boolean ignoreInsets = false;
+        public boolean ignoreInsets = false;
 
         public LayoutParams(Context c, AttributeSet attrs) {
             super(c, attrs);
diff --git a/src/com/android/launcher3/dragndrop/DragLayer.java b/src/com/android/launcher3/dragndrop/DragLayer.java
index 6d2d3cb..f005ce7 100644
--- a/src/com/android/launcher3/dragndrop/DragLayer.java
+++ b/src/com/android/launcher3/dragndrop/DragLayer.java
@@ -47,7 +47,6 @@
 import com.android.launcher3.anim.Interpolators;
 import com.android.launcher3.folder.Folder;
 import com.android.launcher3.folder.FolderIcon;
-import com.android.launcher3.graphics.ViewScrim;
 import com.android.launcher3.graphics.WorkspaceAndHotseatScrim;
 import com.android.launcher3.keyboard.ViewGroupFocusHelper;
 import com.android.launcher3.uioverrides.UiFactory;
@@ -125,15 +124,6 @@
     }
 
     @Override
-    protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
-        ViewScrim scrim = ViewScrim.get(child);
-        if (scrim != null) {
-            scrim.draw(canvas, getWidth(), getHeight());
-        }
-        return super.drawChild(canvas, child, drawingTime);
-    }
-
-    @Override
     protected boolean findActiveController(MotionEvent ev) {
         if (mActivity.getStateManager().getState().disableInteraction) {
             // You Shall Not Pass!!!
diff --git a/src/com/android/launcher3/graphics/ColorScrim.java b/src/com/android/launcher3/graphics/ColorScrim.java
deleted file mode 100644
index 5c1081a..0000000
--- a/src/com/android/launcher3/graphics/ColorScrim.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Copyright (C) 2018 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package com.android.launcher3.graphics;
-
-import android.graphics.Canvas;
-import android.graphics.Color;
-import android.view.View;
-import android.view.animation.Interpolator;
-
-import com.android.launcher3.R;
-import com.android.launcher3.anim.Interpolators;
-import com.android.launcher3.uioverrides.WallpaperColorInfo;
-
-import androidx.core.graphics.ColorUtils;
-
-/**
- * Simple scrim which draws a color
- */
-public class ColorScrim extends ViewScrim {
-
-    private final int mColor;
-    private final Interpolator mInterpolator;
-    private int mCurrentColor;
-
-    public ColorScrim(View view, int color, Interpolator interpolator) {
-        super(view);
-        mColor = color;
-        mInterpolator = interpolator;
-    }
-
-    @Override
-    protected void onProgressChanged() {
-        mCurrentColor = ColorUtils.setAlphaComponent(mColor,
-                Math.round(mInterpolator.getInterpolation(mProgress) * Color.alpha(mColor)));
-    }
-
-    @Override
-    public void draw(Canvas canvas, int width, int height) {
-        if (mProgress > 0) {
-            canvas.drawColor(mCurrentColor);
-        }
-    }
-
-    public static ColorScrim createExtractedColorScrim(View view) {
-        WallpaperColorInfo colors = WallpaperColorInfo.getInstance(view.getContext());
-        int alpha = view.getResources().getInteger(R.integer.extracted_color_gradient_alpha);
-        ColorScrim scrim = new ColorScrim(view, ColorUtils.setAlphaComponent(
-                colors.getSecondaryColor(), alpha), Interpolators.LINEAR);
-        scrim.attach();
-        return scrim;
-    }
-}
diff --git a/src/com/android/launcher3/graphics/ViewScrim.java b/src/com/android/launcher3/graphics/ViewScrim.java
deleted file mode 100644
index e1727e0..0000000
--- a/src/com/android/launcher3/graphics/ViewScrim.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * Copyright (C) 2018 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.android.launcher3.graphics;
-
-import android.graphics.Canvas;
-import android.util.Property;
-import android.view.View;
-import android.view.ViewParent;
-
-import com.android.launcher3.R;
-
-/**
- * A utility class that can be used to draw a scrim behind a view
- */
-public abstract class ViewScrim<T extends View> {
-
-    public static Property<ViewScrim, Float> PROGRESS =
-            new Property<ViewScrim, Float>(Float.TYPE, "progress") {
-                @Override
-                public Float get(ViewScrim viewScrim) {
-                    return viewScrim.mProgress;
-                }
-
-                @Override
-                public void set(ViewScrim object, Float value) {
-                    object.setProgress(value);
-                }
-            };
-
-    protected final T mView;
-    protected float mProgress = 0;
-
-    public ViewScrim(T view) {
-        mView = view;
-    }
-
-    public void attach() {
-        mView.setTag(R.id.view_scrim, this);
-    }
-
-    public void setProgress(float progress) {
-        if (mProgress != progress) {
-            mProgress = progress;
-            onProgressChanged();
-            invalidate();
-        }
-    }
-
-    public abstract void draw(Canvas canvas, int width, int height);
-
-    protected void onProgressChanged() { }
-
-    public void invalidate() {
-        ViewParent parent = mView.getParent();
-        if (parent != null) {
-            ((View) parent).invalidate();
-        }
-    }
-
-    public static ViewScrim get(View view) {
-        return (ViewScrim) view.getTag(R.id.view_scrim);
-    }
-}
diff --git a/src/com/android/launcher3/widget/BaseWidgetSheet.java b/src/com/android/launcher3/widget/BaseWidgetSheet.java
index 20c8876..48c18f8 100644
--- a/src/com/android/launcher3/widget/BaseWidgetSheet.java
+++ b/src/com/android/launcher3/widget/BaseWidgetSheet.java
@@ -15,6 +15,8 @@
  */
 package com.android.launcher3.widget;
 
+import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
+
 import static com.android.launcher3.logging.LoggerUtils.newContainerTarget;
 
 import android.content.Context;
@@ -31,13 +33,16 @@
 import com.android.launcher3.R;
 import com.android.launcher3.Utilities;
 import com.android.launcher3.dragndrop.DragOptions;
-import com.android.launcher3.graphics.ColorScrim;
 import com.android.launcher3.touch.ItemLongClickListener;
+import com.android.launcher3.uioverrides.WallpaperColorInfo;
 import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType;
 import com.android.launcher3.userevent.nano.LauncherLogProto.Target;
 import com.android.launcher3.util.SystemUiController;
 import com.android.launcher3.util.Themes;
 import com.android.launcher3.views.AbstractSlideInView;
+import com.android.launcher3.views.BaseDragLayer;
+
+import androidx.core.graphics.ColorUtils;
 
 /**
  * Base class for various widgets popup
@@ -49,11 +54,11 @@
     /* Touch handling related member variables. */
     private Toast mWidgetInstructionToast;
 
-    protected final ColorScrim mColorScrim;
+    protected final View mColorScrim;
 
     public BaseWidgetSheet(Context context, AttributeSet attrs, int defStyleAttr) {
         super(context, attrs, defStyleAttr);
-        mColorScrim = ColorScrim.createExtractedColorScrim(this);
+        mColorScrim = createColorScrim(context);
     }
 
     @Override
@@ -80,9 +85,14 @@
         return true;
     }
 
+    protected void attachToContainer() {
+        getPopupContainer().addView(mColorScrim);
+        getPopupContainer().addView(this);
+    }
+
     protected void setTranslationShift(float translationShift) {
         super.setTranslationShift(translationShift);
-        mColorScrim.setProgress(1 - mTranslationShift);
+        mColorScrim.setAlpha(1 - mTranslationShift);
     }
 
     private boolean beginDraggingWidget(WidgetCell v) {
@@ -115,6 +125,7 @@
 
     protected void onCloseComplete() {
         super.onCloseComplete();
+        getPopupContainer().removeView(mColorScrim);
         clearNavBarColor();
     }
 
@@ -148,4 +159,19 @@
     protected SystemUiController getSystemUiController() {
         return mLauncher.getSystemUiController();
     }
+
+    private static View createColorScrim(Context context) {
+        View view = new View(context);
+        view.forceHasOverlappingRendering(false);
+
+        WallpaperColorInfo colors = WallpaperColorInfo.getInstance(context);
+        int alpha = context.getResources().getInteger(R.integer.extracted_color_gradient_alpha);
+        view.setBackgroundColor(ColorUtils.setAlphaComponent(colors.getSecondaryColor(), alpha));
+
+        BaseDragLayer.LayoutParams lp = new BaseDragLayer.LayoutParams(MATCH_PARENT, MATCH_PARENT);
+        lp.ignoreInsets = true;
+        view.setLayoutParams(lp);
+
+        return view;
+    }
 }
diff --git a/src/com/android/launcher3/widget/WidgetsBottomSheet.java b/src/com/android/launcher3/widget/WidgetsBottomSheet.java
index 4ba6b5b..4bd6234 100644
--- a/src/com/android/launcher3/widget/WidgetsBottomSheet.java
+++ b/src/com/android/launcher3/widget/WidgetsBottomSheet.java
@@ -70,8 +70,7 @@
                 R.string.widgets_bottom_sheet_title, mOriginalItemInfo.title));
 
         onWidgetsBound();
-
-        getPopupContainer().addView(this);
+        attachToContainer();
         mIsOpen = false;
         animateOpen();
     }
diff --git a/src/com/android/launcher3/widget/WidgetsFullSheet.java b/src/com/android/launcher3/widget/WidgetsFullSheet.java
index f7ff69a..1112686 100644
--- a/src/com/android/launcher3/widget/WidgetsFullSheet.java
+++ b/src/com/android/launcher3/widget/WidgetsFullSheet.java
@@ -220,8 +220,8 @@
     public static WidgetsFullSheet show(Launcher launcher, boolean animate) {
         WidgetsFullSheet sheet = (WidgetsFullSheet) launcher.getLayoutInflater()
                 .inflate(R.layout.widgets_full_sheet, launcher.getDragLayer(), false);
+        sheet.attachToContainer();
         sheet.mIsOpen = true;
-        sheet.getPopupContainer().addView(sheet);
         sheet.open(animate);
         return sheet;
     }