Maintaining separate alpha for x and y translations

Bug: 29504823
Change-Id: I6150fec43653c8da4c5841ddbd6c5de739f205b8
diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java
index 0e4fe8b..24736d4 100644
--- a/src/com/android/launcher3/Workspace.java
+++ b/src/com/android/launcher3/Workspace.java
@@ -199,6 +199,21 @@
         }
     }
 
+    // Direction used for moving the workspace and hotseat UI
+    public enum Direction {
+        X  (TRANSLATION_X),
+        Y  (TRANSLATION_Y);
+
+        private final Property<View, Float> viewProperty;
+
+        Direction(Property<View, Float> viewProperty) {
+            this.viewProperty = viewProperty;
+        }
+    }
+
+    private float[] mPageAlpha = new float[] {1, 1};
+    private float[] mHotseatAlpha = new float[] {1, 1};
+
     @ViewDebug.ExportedProperty(category = "launcher")
     private State mState = State.NORMAL;
     private boolean mIsSwitchingState = false;
@@ -1388,50 +1403,56 @@
         // TODO(adamcohen): figure out a final effect here. We may need to recommend
         // different effects based on device performance. On at least one relatively high-end
         // device I've tried, translating the launcher causes things to get quite laggy.
-        setWorkspaceTranslation(TRANSLATION_X, transX, alpha);
-        setHotseatTranslation(TRANSLATION_X, transX, alpha);
+        setWorkspaceTranslation(Direction.X, transX, alpha);
+        setHotseatTranslation(Direction.X, transX, alpha);
     }
 
     /**
      * Moves the workspace UI in the provided direction.
-     * @param direction either {@link #TRANSLATION_X} or {@link #TRANSLATION_Y}
-     * @param translation the amound of shift.
+     * @param direction the direction to move the workspace
+     * @param translation the amount of shift.
      * @param alpha the alpha for the workspace page
      */
-    public void setWorkspaceTranslation(
-            Property<View, Float> direction, float translation, float alpha) {
+    public void setWorkspaceTranslation(Direction direction, float translation, float alpha) {
+        Property<View, Float> property = direction.viewProperty;
+        mPageAlpha[direction.ordinal()] = alpha;
+        float finalAlpha = mPageAlpha[0] * mPageAlpha[1];
+
         View currentChild = getChildAt(getCurrentPage());
         if (currentChild != null) {
-            direction.set(currentChild, translation);
-            currentChild.setAlpha(alpha);
+            property.set(currentChild, translation);
+            currentChild.setAlpha(finalAlpha);
         }
 
         // When the animation finishes, reset all pages, just in case we missed a page.
         if (Float.compare(translation, 0) == 0) {
             for (int i = getChildCount() - 1; i >= 0; i--) {
                 View child = getChildAt(i);
-                direction.set(child, translation);
-                child.setAlpha(alpha);
+                property.set(child, translation);
+                child.setAlpha(finalAlpha);
             }
         }
     }
 
     /**
      * Moves the Hotseat UI in the provided direction.
-     * @param direction either {@link #TRANSLATION_X} or {@link #TRANSLATION_Y}
+     * @param direction the direction to move the workspace
      * @param translation the amound of shift.
      * @param alpha the alpha for the hotseat page
      */
-    public void setHotseatTranslation(
-            Property<View, Float> direction, float translation, float alpha) {
+    public void setHotseatTranslation(Direction direction, float translation, float alpha) {
+        Property<View, Float> property = direction.viewProperty;
+        mHotseatAlpha[direction.ordinal()] = alpha;
+        float finalAlpha = mHotseatAlpha[0] * mHotseatAlpha[1];
+
         View pageIndicator = getPageIndicator();
         if (pageIndicator != null) {
-            direction.set(pageIndicator, translation);
-            pageIndicator.setAlpha(alpha);
+            property.set(pageIndicator, translation);
+            pageIndicator.setAlpha(finalAlpha);
         }
 
-        direction.set(mLauncher.getHotseat(), translation);
-        mLauncher.getHotseat().setAlpha(alpha);
+        property.set(mLauncher.getHotseat(), translation);
+        mLauncher.getHotseat().setAlpha(finalAlpha);
     }
 
     @Override
diff --git a/src/com/android/launcher3/allapps/AllAppsTransitionController.java b/src/com/android/launcher3/allapps/AllAppsTransitionController.java
index c443b1e..5f34c1a 100644
--- a/src/com/android/launcher3/allapps/AllAppsTransitionController.java
+++ b/src/com/android/launcher3/allapps/AllAppsTransitionController.java
@@ -20,6 +20,7 @@
 import com.android.launcher3.LauncherAnimUtils;
 import com.android.launcher3.PagedView;
 import com.android.launcher3.Workspace;
+import com.android.launcher3.Workspace.Direction;
 import com.android.launcher3.util.TouchController;
 
 /**
@@ -239,10 +240,10 @@
                 mDecelInterpolator.getInterpolation(alpha))));
         mAppsView.getContentView().setAlpha(alpha);
         mAppsView.setTranslationY(progress);
-        mWorkspace.setWorkspaceTranslation(View.TRANSLATION_Y,
+        mWorkspace.setWorkspaceTranslation(Direction.Y,
                 PARALLAX_COEFFICIENT *(-mTranslation + progress),
                 mAccelInterpolator.getInterpolation(workspaceHotseatAlpha));
-        mWorkspace.setHotseatTranslation(View.TRANSLATION_Y, -mTranslation + progress,
+        mWorkspace.setHotseatTranslation(Direction.Y, -mTranslation + progress,
                 mAccelInterpolator.getInterpolation(workspaceHotseatAlpha));
     }