Merge "Switch ScrimView to use view alpha" into udc-qpr-dev
diff --git a/quickstep/src/com/android/launcher3/uioverrides/touchcontrollers/NoButtonQuickSwitchTouchController.java b/quickstep/src/com/android/launcher3/uioverrides/touchcontrollers/NoButtonQuickSwitchTouchController.java
index d3ef589..9f9cb00 100644
--- a/quickstep/src/com/android/launcher3/uioverrides/touchcontrollers/NoButtonQuickSwitchTouchController.java
+++ b/quickstep/src/com/android/launcher3/uioverrides/touchcontrollers/NoButtonQuickSwitchTouchController.java
@@ -16,7 +16,6 @@
 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;
@@ -262,7 +261,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.setViewBackgroundColor(mLauncher.getScrimView(),
+        xAnim.setScrimViewBackgroundColor(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 8a9e04e..ca8381b 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.setViewBackgroundColor(mActivity.getScrimView(), state.getScrimColor(mActivity),
+        setter.setScrimViewBackgroundColor(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 c20f323..51abfd3 100644
--- a/src/com/android/launcher3/LauncherAnimUtils.java
+++ b/src/com/android/launcher3/LauncherAnimUtils.java
@@ -30,6 +30,7 @@
 import android.widget.TextView;
 
 import com.android.launcher3.util.MultiScalePropertyFactory;
+import com.android.launcher3.views.ScrimView;
 
 public class LauncherAnimUtils {
     /**
@@ -194,6 +195,10 @@
 
                 @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 e4f34ae..1404a92 100644
--- a/src/com/android/launcher3/WorkspaceStateTransitionAnimation.java
+++ b/src/com/android/launcher3/WorkspaceStateTransitionAnimation.java
@@ -199,7 +199,7 @@
         propertySetter.setFloat(sysUiScrim.getSysUIProgress(), AnimatedFloat.VALUE,
                 state.hasFlag(FLAG_HAS_SYS_UI_SCRIM) ? 1 : 0, LINEAR);
 
-        propertySetter.setViewBackgroundColor(mLauncher.getScrimView(),
+        propertySetter.setScrimViewBackgroundColor(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 82e645a..ff6bdec 100644
--- a/src/com/android/launcher3/anim/AnimatedPropertySetter.java
+++ b/src/com/android/launcher3/anim/AnimatedPropertySetter.java
@@ -24,13 +24,14 @@
 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;
 
 /**
@@ -62,9 +63,9 @@
     }
 
     @Override
-    public Animator setViewBackgroundColor(View view, int color, TimeInterpolator interpolator) {
-        if (view == null || (view.getBackground() instanceof ColorDrawable
-                && ((ColorDrawable) view.getBackground()).getColor() == color)) {
+    public Animator setScrimViewBackgroundColor(ScrimView view, int color,
+            TimeInterpolator interpolator) {
+        if (view == null || view.getBackgroundColor() == 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 6ba58b6..0b2858d 100644
--- a/src/com/android/launcher3/anim/PropertySetter.java
+++ b/src/com/android/launcher3/anim/PropertySetter.java
@@ -25,6 +25,8 @@
 
 import androidx.annotation.NonNull;
 
+import com.android.launcher3.views.ScrimView;
+
 import java.util.function.Consumer;
 
 /**
@@ -62,7 +64,8 @@
      * Sets the background color of the provided view using the provided interpolator.
      */
     @NonNull
-    public Animator setViewBackgroundColor(View view, int color, TimeInterpolator interpolator) {
+    public Animator setScrimViewBackgroundColor(ScrimView 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 ca80c51..6a9aedf 100644
--- a/src/com/android/launcher3/views/ScrimView.java
+++ b/src/com/android/launcher3/views/ScrimView.java
@@ -21,7 +21,6 @@
 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;
 
@@ -63,18 +62,16 @@
     }
 
     @Override
-    protected boolean onSetAlpha(int alpha) {
-        updateSysUiColors();
-        dispatchVisibilityListenersIfNeeded();
-        return super.onSetAlpha(alpha);
-    }
-
-    @Override
     public void setBackgroundColor(int color) {
         mBackgroundColor = color;
-        updateSysUiColors();
         dispatchVisibilityListenersIfNeeded();
-        super.setBackgroundColor(color);
+        if (Color.alpha(color) == 0) {
+            setAlpha(0);
+        } else {
+            setAlpha(1);
+            super.setBackgroundColor(color);
+        }
+        updateSysUiColors();
     }
 
     public int getBackgroundColor() {
@@ -89,7 +86,7 @@
     }
 
     public boolean isFullyOpaque() {
-        return mIsVisible && getAlpha() == 1 && Color.alpha(mBackgroundColor) == 255;
+        return mIsVisible && getAlpha() == 1;
     }
 
     @Override
@@ -120,8 +117,7 @@
         // status bar.
         final float threshold = STATUS_BAR_COLOR_FORCE_UPDATE_THRESHOLD;
         boolean forceChange = getVisibility() == VISIBLE
-                && getAlpha() > threshold
-                && (Color.alpha(mBackgroundColor) / 255f) > threshold;
+                && getAlpha() > threshold;
         if (forceChange) {
             getSystemUiController().updateUiState(UI_STATE_SCRIM_VIEW, !isScrimDark());
         } else {
@@ -148,13 +144,7 @@
     }
 
     private boolean isScrimDark() {
-        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;
+        return ColorUtils.calculateLuminance(mBackgroundColor) < 0.5f;
     }
 
     /**