Revert "Switch ScrimView to use view alpha"

This reverts commit 99c4becf246726dcfeea16bd65c134f4fc875293.

Reason for revert: b/287488354

Change-Id: Ic4db08ca771f1d744ba2c19eb55b9f2d277ad529
diff --git a/quickstep/src/com/android/launcher3/uioverrides/touchcontrollers/NoButtonQuickSwitchTouchController.java b/quickstep/src/com/android/launcher3/uioverrides/touchcontrollers/NoButtonQuickSwitchTouchController.java
index 9f9cb00..d3ef589 100644
--- a/quickstep/src/com/android/launcher3/uioverrides/touchcontrollers/NoButtonQuickSwitchTouchController.java
+++ b/quickstep/src/com/android/launcher3/uioverrides/touchcontrollers/NoButtonQuickSwitchTouchController.java
@@ -16,6 +16,7 @@
 package com.android.launcher3.uioverrides.touchcontrollers;
 
 import static android.view.MotionEvent.ACTION_DOWN;
+import static android.view.MotionEvent.ACTION_MOVE;
 
 import static com.android.app.animation.Interpolators.ACCELERATE_0_75;
 import static com.android.app.animation.Interpolators.DECELERATE_3;
@@ -261,7 +262,7 @@
         xAnim.setFloat(mRecentsView, ADJACENT_PAGE_HORIZONTAL_OFFSET, scaleAndOffset[1], LINEAR);
         // Use QuickSwitchState instead of OverviewState to determine scrim color,
         // since we need to take potential taskbar into account.
-        xAnim.setScrimViewBackgroundColor(mLauncher.getScrimView(),
+        xAnim.setViewBackgroundColor(mLauncher.getScrimView(),
                 QUICK_SWITCH_FROM_HOME.getWorkspaceScrimColor(mLauncher), LINEAR);
         if (mRecentsView.getTaskViewCount() == 0) {
             xAnim.addFloat(mRecentsView, CONTENT_ALPHA, 0f, 1f, LINEAR);
diff --git a/quickstep/src/com/android/quickstep/fallback/FallbackRecentsStateController.java b/quickstep/src/com/android/quickstep/fallback/FallbackRecentsStateController.java
index ca8381b..8a9e04e 100644
--- a/quickstep/src/com/android/quickstep/fallback/FallbackRecentsStateController.java
+++ b/quickstep/src/com/android/quickstep/fallback/FallbackRecentsStateController.java
@@ -114,7 +114,7 @@
         setter.setFloat(mRecentsView, TASK_THUMBNAIL_SPLASH_ALPHA,
                 state.showTaskThumbnailSplash() ? 1f : 0f, INSTANT);
 
-        setter.setScrimViewBackgroundColor(mActivity.getScrimView(), state.getScrimColor(mActivity),
+        setter.setViewBackgroundColor(mActivity.getScrimView(), state.getScrimColor(mActivity),
                 config.getInterpolator(ANIM_SCRIM_FADE, LINEAR));
 
         RecentsState currentState = mActivity.getStateManager().getState();
diff --git a/src/com/android/launcher3/LauncherAnimUtils.java b/src/com/android/launcher3/LauncherAnimUtils.java
index 51abfd3..c20f323 100644
--- a/src/com/android/launcher3/LauncherAnimUtils.java
+++ b/src/com/android/launcher3/LauncherAnimUtils.java
@@ -30,7 +30,6 @@
 import android.widget.TextView;
 
 import com.android.launcher3.util.MultiScalePropertyFactory;
-import com.android.launcher3.views.ScrimView;
 
 public class LauncherAnimUtils {
     /**
@@ -195,10 +194,6 @@
 
                 @Override
                 public Integer get(View view) {
-                    if (view instanceof ScrimView) {
-                        return ((ScrimView) view).getBackgroundColor();
-                    }
-
                     if (!(view.getBackground() instanceof ColorDrawable)) {
                         return Color.TRANSPARENT;
                     }
diff --git a/src/com/android/launcher3/WorkspaceStateTransitionAnimation.java b/src/com/android/launcher3/WorkspaceStateTransitionAnimation.java
index 68c4ba0..c04cdfd 100644
--- a/src/com/android/launcher3/WorkspaceStateTransitionAnimation.java
+++ b/src/com/android/launcher3/WorkspaceStateTransitionAnimation.java
@@ -199,7 +199,7 @@
         propertySetter.setFloat(sysUiScrim, SYSUI_PROGRESS,
                 state.hasFlag(FLAG_HAS_SYS_UI_SCRIM) ? 1 : 0, LINEAR);
 
-        propertySetter.setScrimViewBackgroundColor(mLauncher.getScrimView(),
+        propertySetter.setViewBackgroundColor(mLauncher.getScrimView(),
                 state.getWorkspaceScrimColor(mLauncher),
                 config.getInterpolator(ANIM_SCRIM_FADE, ACCELERATE_2));
     }
diff --git a/src/com/android/launcher3/anim/AnimatedPropertySetter.java b/src/com/android/launcher3/anim/AnimatedPropertySetter.java
index ff6bdec..82e645a 100644
--- a/src/com/android/launcher3/anim/AnimatedPropertySetter.java
+++ b/src/com/android/launcher3/anim/AnimatedPropertySetter.java
@@ -24,14 +24,13 @@
 import android.animation.ObjectAnimator;
 import android.animation.TimeInterpolator;
 import android.animation.ValueAnimator;
+import android.graphics.drawable.ColorDrawable;
 import android.util.FloatProperty;
 import android.util.IntProperty;
 import android.view.View;
 
 import androidx.annotation.NonNull;
 
-import com.android.launcher3.views.ScrimView;
-
 import java.util.function.Consumer;
 
 /**
@@ -63,9 +62,9 @@
     }
 
     @Override
-    public Animator setScrimViewBackgroundColor(ScrimView view, int color,
-            TimeInterpolator interpolator) {
-        if (view == null || view.getBackgroundColor() == color) {
+    public Animator setViewBackgroundColor(View view, int color, TimeInterpolator interpolator) {
+        if (view == null || (view.getBackground() instanceof ColorDrawable
+                && ((ColorDrawable) view.getBackground()).getColor() == color)) {
             return NO_OP;
         }
         ObjectAnimator anim = ObjectAnimator.ofArgb(view, VIEW_BACKGROUND_COLOR, color);
diff --git a/src/com/android/launcher3/anim/PropertySetter.java b/src/com/android/launcher3/anim/PropertySetter.java
index 0b2858d..6ba58b6 100644
--- a/src/com/android/launcher3/anim/PropertySetter.java
+++ b/src/com/android/launcher3/anim/PropertySetter.java
@@ -25,8 +25,6 @@
 
 import androidx.annotation.NonNull;
 
-import com.android.launcher3.views.ScrimView;
-
 import java.util.function.Consumer;
 
 /**
@@ -64,8 +62,7 @@
      * Sets the background color of the provided view using the provided interpolator.
      */
     @NonNull
-    public Animator setScrimViewBackgroundColor(ScrimView view, int color,
-            TimeInterpolator interpolator) {
+    public Animator setViewBackgroundColor(View view, int color, TimeInterpolator interpolator) {
         if (view != null) {
             view.setBackgroundColor(color);
         }
diff --git a/src/com/android/launcher3/views/ScrimView.java b/src/com/android/launcher3/views/ScrimView.java
index 6a9aedf..ca80c51 100644
--- a/src/com/android/launcher3/views/ScrimView.java
+++ b/src/com/android/launcher3/views/ScrimView.java
@@ -21,6 +21,7 @@
 import android.graphics.Canvas;
 import android.graphics.Color;
 import android.graphics.Rect;
+import android.graphics.drawable.ColorDrawable;
 import android.util.AttributeSet;
 import android.view.View;
 
@@ -62,16 +63,18 @@
     }
 
     @Override
+    protected boolean onSetAlpha(int alpha) {
+        updateSysUiColors();
+        dispatchVisibilityListenersIfNeeded();
+        return super.onSetAlpha(alpha);
+    }
+
+    @Override
     public void setBackgroundColor(int color) {
         mBackgroundColor = color;
-        dispatchVisibilityListenersIfNeeded();
-        if (Color.alpha(color) == 0) {
-            setAlpha(0);
-        } else {
-            setAlpha(1);
-            super.setBackgroundColor(color);
-        }
         updateSysUiColors();
+        dispatchVisibilityListenersIfNeeded();
+        super.setBackgroundColor(color);
     }
 
     public int getBackgroundColor() {
@@ -86,7 +89,7 @@
     }
 
     public boolean isFullyOpaque() {
-        return mIsVisible && getAlpha() == 1;
+        return mIsVisible && getAlpha() == 1 && Color.alpha(mBackgroundColor) == 255;
     }
 
     @Override
@@ -117,7 +120,8 @@
         // status bar.
         final float threshold = STATUS_BAR_COLOR_FORCE_UPDATE_THRESHOLD;
         boolean forceChange = getVisibility() == VISIBLE
-                && getAlpha() > threshold;
+                && getAlpha() > threshold
+                && (Color.alpha(mBackgroundColor) / 255f) > threshold;
         if (forceChange) {
             getSystemUiController().updateUiState(UI_STATE_SCRIM_VIEW, !isScrimDark());
         } else {
@@ -144,7 +148,13 @@
     }
 
     private boolean isScrimDark() {
-        return ColorUtils.calculateLuminance(mBackgroundColor) < 0.5f;
+        if (!(getBackground() instanceof ColorDrawable)) {
+            throw new IllegalStateException(
+                    "ScrimView must have a ColorDrawable background, this one has: "
+                            + getBackground());
+        }
+        return ColorUtils.calculateLuminance(
+                ((ColorDrawable) getBackground()).getColor()) < 0.5f;
     }
 
     /**