Design adjustments for transition from workspace to
All apps.

Change-Id: I0aeb8da7f0eebdf677ca7bda06fb538f08a6ee51
diff --git a/res/layout-land/launcher.xml b/res/layout-land/launcher.xml
index 565728c..1e82f22 100644
--- a/res/layout-land/launcher.xml
+++ b/res/layout-land/launcher.xml
@@ -32,8 +32,6 @@
         android:layout_width="match_parent"
         android:layout_height="match_parent">
 
-        <include layout="@layout/gradient_scrim" />
-
         <!-- The workspace contains 5 screens of cells -->
         <!-- DO NOT CHANGE THE ID -->
         <com.android.launcher3.Workspace
@@ -44,6 +42,8 @@
             android:layout_gravity="center"
             launcher:pageIndicator="@id/page_indicator" />
 
+        <include layout="@layout/gradient_scrim" />
+
         <!-- DO NOT CHANGE THE ID -->
         <include layout="@layout/hotseat"
             android:id="@+id/hotseat"
diff --git a/res/layout-port/launcher.xml b/res/layout-port/launcher.xml
index eccb824..c15e53d 100644
--- a/res/layout-port/launcher.xml
+++ b/res/layout-port/launcher.xml
@@ -33,8 +33,6 @@
         android:layout_width="match_parent"
         android:layout_height="match_parent">
 
-        <include layout="@layout/gradient_scrim" />
-
         <!-- The workspace contains 5 screens of cells -->
         <!-- DO NOT CHANGE THE ID -->
         <com.android.launcher3.Workspace
@@ -46,6 +44,8 @@
             launcher:pageIndicator="@+id/page_indicator">
         </com.android.launcher3.Workspace>
 
+        <include layout="@layout/gradient_scrim" />
+
         <!-- DO NOT CHANGE THE ID -->
         <include layout="@layout/hotseat"
             android:id="@+id/hotseat"
diff --git a/res/layout-sw720dp/launcher.xml b/res/layout-sw720dp/launcher.xml
index 7fad517..c516c46 100644
--- a/res/layout-sw720dp/launcher.xml
+++ b/res/layout-sw720dp/launcher.xml
@@ -32,8 +32,6 @@
         android:layout_width="match_parent"
         android:layout_height="match_parent">
 
-        <include layout="@layout/gradient_scrim" />
-
         <!-- The workspace contains 5 screens of cells -->
         <!-- DO NOT CHANGE THE ID -->
         <com.android.launcher3.Workspace
@@ -45,6 +43,8 @@
             launcher:pageIndicator="@id/page_indicator">
         </com.android.launcher3.Workspace>
 
+        <include layout="@layout/gradient_scrim" />
+
         <!-- DO NOT CHANGE THE ID -->
         <include layout="@layout/hotseat"
             android:id="@+id/hotseat"
diff --git a/res/layout/gradient_scrim.xml b/res/layout/gradient_scrim.xml
index 02c39eb..c40c5fc 100644
--- a/res/layout/gradient_scrim.xml
+++ b/res/layout/gradient_scrim.xml
@@ -15,7 +15,7 @@
 -->
 <merge xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:app="http://schemas.android.com/apk/res-auto">
-    <com.android.launcher3.graphics.RadialGradientView
+    <com.android.launcher3.graphics.GradientView
         android:id="@+id/gradient_bg"
         android:layout_width="match_parent"
         android:layout_height="match_parent"
diff --git a/src/com/android/launcher3/allapps/AllAppsTransitionController.java b/src/com/android/launcher3/allapps/AllAppsTransitionController.java
index 97aa54a..7c6ff51 100644
--- a/src/com/android/launcher3/allapps/AllAppsTransitionController.java
+++ b/src/com/android/launcher3/allapps/AllAppsTransitionController.java
@@ -24,7 +24,7 @@
 import com.android.launcher3.Workspace;
 import com.android.launcher3.config.FeatureFlags;
 import com.android.launcher3.dynamicui.ExtractedColors;
-import com.android.launcher3.graphics.RadialGradientView;
+import com.android.launcher3.graphics.GradientView;
 import com.android.launcher3.graphics.ScrimView;
 import com.android.launcher3.userevent.nano.LauncherLogProto.Action;
 import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType;
@@ -47,7 +47,8 @@
     private static final String TAG = "AllAppsTrans";
     private static final boolean DBG = false;
 
-    private final Interpolator mAccelInterpolator = new AccelerateInterpolator(2f);
+    private final Interpolator mWorkspaceAccelnterpolator = new AccelerateInterpolator(2f);
+    private final Interpolator mHotseatAccelInterpolator = new AccelerateInterpolator(.5f);
     private final Interpolator mDecelInterpolator = new DecelerateInterpolator(3f);
     private final Interpolator mFastOutSlowInInterpolator = new FastOutSlowInInterpolator();
     private final VerticalPullDetector.ScrollInterpolator mScrollInterpolator
@@ -95,7 +96,7 @@
     // Used in discovery bounce animation to provide the transition without workspace changing.
     private boolean mIsTranslateWithoutWorkspace = false;
     private AnimatorSet mDiscoBounceAnimation;
-    private RadialGradientView mGradientView;
+    private GradientView mGradientView;
     private ScrimView mScrimView;
 
     public AllAppsTransitionController(Launcher l) {
@@ -275,7 +276,7 @@
     private void updateAllAppsBg(float progress) {
         // gradient
         if (mGradientView == null) {
-            mGradientView = (RadialGradientView) mLauncher.findViewById(R.id.gradient_bg);
+            mGradientView = (GradientView) mLauncher.findViewById(R.id.gradient_bg);
             mGradientView.setVisibility(View.VISIBLE);
             onExtractedColorsChanged();
         }
@@ -313,7 +314,8 @@
 
         float workspaceHotseatAlpha = Utilities.boundToRange(progress, 0f, 1f);
         float alpha = 1 - workspaceHotseatAlpha;
-        float interpolation = mAccelInterpolator.getInterpolation(workspaceHotseatAlpha);
+        float workspaceAlpha = mWorkspaceAccelnterpolator.getInterpolation(workspaceHotseatAlpha);
+        float hotseatAlpha = mHotseatAccelInterpolator.getInterpolation(workspaceHotseatAlpha);
 
         int color = (Integer) mEvaluator.evaluate(mDecelInterpolator.getInterpolation(alpha),
                 mHotseatBackgroundColor, mAllAppsBackgroundColor);
@@ -331,18 +333,18 @@
 
         if (!mLauncher.getDeviceProfile().isVerticalBarLayout()) {
             mWorkspace.setHotseatTranslationAndAlpha(Workspace.Direction.Y, -mShiftRange + shiftCurrent,
-                    interpolation);
+                    hotseatAlpha);
         } else {
             mWorkspace.setHotseatTranslationAndAlpha(Workspace.Direction.Y,
                     PARALLAX_COEFFICIENT * (-mShiftRange + shiftCurrent),
-                    interpolation);
+                    hotseatAlpha);
         }
 
         if (mIsTranslateWithoutWorkspace) {
             return;
         }
         mWorkspace.setWorkspaceYTranslationAndAlpha(
-                PARALLAX_COEFFICIENT * (-mShiftRange + shiftCurrent), interpolation);
+                PARALLAX_COEFFICIENT * (-mShiftRange + shiftCurrent), workspaceAlpha);
 
         if (!mDetector.isDraggingState()) {
             mContainerVelocity = mDetector.computeVelocity(shiftCurrent - shiftPrevious,
diff --git a/src/com/android/launcher3/graphics/RadialGradientView.java b/src/com/android/launcher3/graphics/GradientView.java
similarity index 65%
rename from src/com/android/launcher3/graphics/RadialGradientView.java
rename to src/com/android/launcher3/graphics/GradientView.java
index cf6851c..c5b7693 100644
--- a/src/com/android/launcher3/graphics/RadialGradientView.java
+++ b/src/com/android/launcher3/graphics/GradientView.java
@@ -27,7 +27,8 @@
 import android.graphics.Shader;
 import android.util.AttributeSet;
 import android.view.View;
-import android.view.animation.DecelerateInterpolator;
+import android.view.animation.AccelerateInterpolator;
+import android.view.animation.Interpolator;
 
 import com.android.launcher3.R;
 import com.android.launcher3.Utilities;
@@ -36,63 +37,50 @@
  * Draws a translucent radial gradient background from an initial state with progress 0.0 to a
  * final state with progress 1.0;
  */
-public class RadialGradientView extends View {
+public class GradientView extends View {
 
-    public static final int DEFAULT_COLOR_1 = Color.WHITE;
-    public static final int DEFAULT_COLOR_2 = Color.BLACK;
+    private static final int DEFAULT_COLOR = Color.WHITE;
+    private static final float GRADIENT_ALPHA_MASK_LENGTH_DP = 300;
+    private static final float FINAL_GRADIENT_ALPHA = 0.75f;
+    private static final boolean DEBUG = false;
 
     private static Bitmap sFinalGradientMask;
     private static Bitmap sAlphaGradientMask;
 
-    // TODO needs to be cleaned up once design finalizes
-    static class Config {
-        // dimens
-        final float gradientCenterX = 0.5f;
-        final float gradientCenterY = 1.05f;
-        final float gradientHeadStartFactor = 0.35f;
-        final float gradientAlphaMaskLengthDp = 700;
-        // interpolation
-        final boolean useGradientAlphaDecel = false;
-        final float decelFactorForGradientAlpha = 2f;
-        // colors
-        final float finalGradientAlpha = 0.75f;
-        int color1 = DEFAULT_COLOR_1;
-        int color2 = DEFAULT_COLOR_2;
-    }
-
+    private int mColor1 = DEFAULT_COLOR;
+    private int mColor2 = DEFAULT_COLOR;
+    private int mWidth;
+    private int mHeight;
     private final RectF mAlphaMaskRect = new RectF();
     private final RectF mFinalMaskRect = new RectF();
     private final Paint mPaint = new Paint();
-    private final Config mConfig = new Config();
-    private final DecelerateInterpolator mDecelInterpolator;
     private float mProgress;
-    private int mWidth;
-    private int mHeight;
     private final int mMaskHeight;
     private final Context mAppContext;
+    private final Paint mDebugPaint = DEBUG ? new Paint() : null;
+    private final Interpolator mAccelerator = new AccelerateInterpolator();
 
-    public RadialGradientView(Context context, AttributeSet attrs) {
+    public GradientView(Context context, AttributeSet attrs) {
         super(context, attrs);
         this.mAppContext = context.getApplicationContext();
-        this.mDecelInterpolator = new DecelerateInterpolator(mConfig.decelFactorForGradientAlpha);
-        this.mMaskHeight = Utilities.pxFromDp(mConfig.gradientAlphaMaskLengthDp,
+        this.mMaskHeight = Utilities.pxFromDp(GRADIENT_ALPHA_MASK_LENGTH_DP,
                 mAppContext.getResources().getDisplayMetrics());
 
         if (sFinalGradientMask == null) {
             sFinalGradientMask = Utilities.convertToAlphaMask(
-                    Utilities.createOnePixBitmap(), mConfig.finalGradientAlpha);
+                    Utilities.createOnePixBitmap(), FINAL_GRADIENT_ALPHA);
         }
         if (sAlphaGradientMask == null) {
             Bitmap alphaMaskFromResource = BitmapFactory.decodeResource(context.getResources(),
                     R.drawable.all_apps_alpha_mask);
             sAlphaGradientMask = Utilities.convertToAlphaMask(
-                    alphaMaskFromResource, mConfig.finalGradientAlpha);
+                    alphaMaskFromResource, FINAL_GRADIENT_ALPHA);
         }
     }
 
     public void onExtractedColorsChanged(int color1, int color2) {
-        mConfig.color1 = color1;
-        mConfig.color2 = color2;
+        this.mColor1 = color1;
+        this.mColor2 = color2;
         if (mWidth + mHeight > 0) {
             createRadialShader();
         }
@@ -110,14 +98,15 @@
 
     // only being called when colors change
     private void createRadialShader() {
-        float radius = Math.max(mHeight, mWidth) * mConfig.gradientCenterY;
+        final float gradientCenterY = 1.05f;
+        float radius = Math.max(mHeight, mWidth) * gradientCenterY;
 
         float posScreenBottom = (radius - mHeight) / radius; // center lives below screen
         RadialGradient shader = new RadialGradient(
-                mWidth * mConfig.gradientCenterX,
-                mHeight * mConfig.gradientCenterY,
+                mWidth * 0.5f,
+                mHeight * gradientCenterY,
                 radius,
-                new int[] {mConfig.color1, mConfig.color1, mConfig.color2},
+                new int[] {mColor1, mColor1, mColor2},
                 new float[] {0f, posScreenBottom, 1f},
                 Shader.TileMode.CLAMP);
         mPaint.setShader(shader);
@@ -130,17 +119,22 @@
 
     @Override
     protected void onDraw(Canvas canvas) {
-        float head = mConfig.gradientHeadStartFactor;
+        float head = 0.29f;
         float linearProgress = head + (mProgress * (1f - head));
-        float adjustProgress = mConfig.useGradientAlphaDecel
-                ? mDecelInterpolator.getInterpolation(linearProgress)
-                : linearProgress;
-        float startMaskY = (1f - adjustProgress) * mHeight - mMaskHeight * adjustProgress;
-
+        float startMaskY = (1f - linearProgress) * mHeight - mMaskHeight * linearProgress;
+        float startAlpha = 100;
+        float interpolatedAlpha = (255 - startAlpha) * mAccelerator.getInterpolation(mProgress);
+        mPaint.setAlpha((int) (startAlpha + interpolatedAlpha));
         mAlphaMaskRect.set(0, startMaskY, mWidth, startMaskY + mMaskHeight);
         mFinalMaskRect.set(0, startMaskY + mMaskHeight, mWidth, mHeight);
         canvas.drawBitmap(sAlphaGradientMask, null, mAlphaMaskRect, mPaint);
         canvas.drawBitmap(sFinalGradientMask, null, mFinalMaskRect, mPaint);
+
+        if (DEBUG) {
+            mDebugPaint.setColor(0xFF00FF00);
+            canvas.drawLine(0, startMaskY, mWidth, startMaskY, mDebugPaint);
+            canvas.drawLine(0, startMaskY + mMaskHeight, mWidth, startMaskY + mMaskHeight, mDebugPaint);
+        }
     }
 
 }
\ No newline at end of file
diff --git a/src/com/android/launcher3/graphics/ScrimView.java b/src/com/android/launcher3/graphics/ScrimView.java
index 521fbed..feb3f03 100644
--- a/src/com/android/launcher3/graphics/ScrimView.java
+++ b/src/com/android/launcher3/graphics/ScrimView.java
@@ -26,18 +26,22 @@
 import android.support.v4.graphics.ColorUtils;
 import android.util.AttributeSet;
 import android.view.View;
+import android.view.animation.AccelerateInterpolator;
+import android.view.animation.Interpolator;
 
 import com.android.launcher3.R;
 import com.android.launcher3.Utilities;
 
 public class ScrimView extends View {
 
-    // Config
-    private static final int MASK_HEIGHT_DP = 600;
-    private static final float MASK_START_LENGTH_FACTOR = 0.4f;
+    private static final boolean DEBUG = false;
+
+    private static final int MASK_HEIGHT_DP = 300;
+    private static final float MASK_START_LENGTH_FACTOR = 1f;
     private static final float FINAL_ALPHA = 0.87f;
     private static final int SCRIM_COLOR = ColorUtils.setAlphaComponent(
             Color.WHITE, (int) (FINAL_ALPHA * 255));
+    private static final boolean APPLY_ALPHA = true;
 
     private static Bitmap sFinalScrimMask;
     private static Bitmap sAlphaScrimMask;
@@ -50,6 +54,8 @@
     private final RectF mFinalMaskRect = new RectF();
     private final Paint mPaint = new Paint();
     private float mProgress;
+    private final Interpolator mAccelerator = new AccelerateInterpolator();
+    private final Paint mDebugPaint = DEBUG ? new Paint() : null;
 
     public ScrimView(Context context, AttributeSet attrs) {
         super(context, attrs);
@@ -73,17 +79,22 @@
         super.onMeasure(widthMeasureSpec, heightMeasureSpec);
         int width = MeasureSpec.getSize(widthMeasureSpec);
         mVisibleHeight = MeasureSpec.getSize(heightMeasureSpec);
-        int fullHeight = mVisibleHeight * 2 + mMaskHeight;
-        setMeasuredDimension(width, fullHeight);
+        setMeasuredDimension(width, mVisibleHeight * 2);
         setProgress(mProgress);
     }
 
     public void setProgress(float progress) {
         mProgress = progress;
         float initialY = mVisibleHeight - mHeadStart;
-        float fullTranslationY = mMaskHeight + initialY + mVisibleHeight;
-        float translationY = initialY - progress * fullTranslationY;
-        setTranslationY(translationY);
+        float fullTranslationY = mVisibleHeight;
+        float linTranslationY = initialY - progress * fullTranslationY;
+        setTranslationY(linTranslationY);
+
+        if (APPLY_ALPHA) {
+            int alpha = 55 + (int) (200f * mAccelerator.getInterpolation(progress));
+            mPaint.setAlpha(alpha);
+            invalidate();
+        }
     }
 
     @Override
@@ -92,6 +103,12 @@
         mFinalMaskRect.set(0, mMaskHeight, getWidth(), getHeight());
         canvas.drawBitmap(sAlphaScrimMask, null, mAlphaMaskRect, mPaint);
         canvas.drawBitmap(sFinalScrimMask, null, mFinalMaskRect, mPaint);
+
+        if (DEBUG) {
+            mDebugPaint.setColor(0xFF0000FF);
+            canvas.drawLine(0, mAlphaMaskRect.top, getWidth(), mAlphaMaskRect.top, mDebugPaint);
+            canvas.drawLine(0, mAlphaMaskRect.bottom, getWidth(), mAlphaMaskRect.bottom, mDebugPaint);
+        }
     }
 
 }