Adding initial background protection to AllApps/Customize drawer.

Change-Id: Id5e2b2dd82c2ee82526ae5c5179345275af246c6
diff --git a/src/com/android/launcher2/Workspace.java b/src/com/android/launcher2/Workspace.java
index 169f53f..a898177 100644
--- a/src/com/android/launcher2/Workspace.java
+++ b/src/com/android/launcher2/Workspace.java
@@ -92,13 +92,22 @@
     private static final float EXTRA_SCALE_FACTOR_1 = 1.0f;
     private static final float EXTRA_SCALE_FACTOR_2 = 1.10f;
 
-    private static final int BACKGROUND_FADE_OUT_DELAY = 300;
-    private static final int BACKGROUND_FADE_OUT_DURATION = 300;
-    private static final int BACKGROUND_FADE_IN_DURATION = 100;
+    private static final int CHILDREN_OUTLINE_FADE_OUT_DELAY = 300;
+    private static final int CHILDREN_OUTLINE_FADE_OUT_DURATION = 300;
+    private static final int CHILDREN_OUTLINE_FADE_IN_DURATION = 100;
 
-    // These animators are used to fade the background
+    private static final int BACKGROUND_FADE_OUT_DURATION = 450;
+    private static final int BACKGROUND_FADE_IN_DURATION = 350;
+
+    // These animators are used to fade the children's outlines
+    private ObjectAnimator mChildrenOutlineFadeInAnimation;
+    private ObjectAnimator mChildrenOutlineFadeOutAnimation;
+    private float mChildrenOutlineAlpha = 0;
+
+    // These properties refer to the background protection gradient used for AllApps and Customize
     private ObjectAnimator mBackgroundFadeInAnimation;
     private ObjectAnimator mBackgroundFadeOutAnimation;
+    private Drawable mBackground;
     private float mBackgroundAlpha = 0;
 
     private final WallpaperManager mWallpaperManager;
@@ -236,6 +245,9 @@
         mExternalDragOutlinePaint.setAntiAlias(true);
         setWillNotDraw(false);
 
+        final Resources res = getResources();
+        mBackground = res.getDrawable(R.drawable.all_apps_bg_gradient);
+
         mUnshrinkAnimationListener = new LauncherAnimatorListenerAdapter() {
             @Override
             public void onAnimationStart(Animator animation) {
@@ -539,33 +551,58 @@
 
     public void showOutlines() {
         if (!mIsSmall && !mIsInUnshrinkAnimation) {
-            if (mBackgroundFadeOutAnimation != null) mBackgroundFadeOutAnimation.cancel();
-            if (mBackgroundFadeInAnimation != null) mBackgroundFadeInAnimation.cancel();
-            mBackgroundFadeInAnimation = ObjectAnimator.ofFloat(this, "backgroundAlpha", 1.0f);
-            mBackgroundFadeInAnimation.setDuration(BACKGROUND_FADE_IN_DURATION);
-            mBackgroundFadeInAnimation.start();
+            if (mChildrenOutlineFadeOutAnimation != null) mChildrenOutlineFadeOutAnimation.cancel();
+            if (mChildrenOutlineFadeInAnimation != null) mChildrenOutlineFadeInAnimation.cancel();
+            mChildrenOutlineFadeInAnimation = ObjectAnimator.ofFloat(this, "childrenOutlineAlpha", 1.0f);
+            mChildrenOutlineFadeInAnimation.setDuration(CHILDREN_OUTLINE_FADE_IN_DURATION);
+            mChildrenOutlineFadeInAnimation.start();
         }
     }
 
     public void hideOutlines() {
         if (!mIsSmall && !mIsInUnshrinkAnimation) {
-            if (mBackgroundFadeInAnimation != null) mBackgroundFadeInAnimation.cancel();
-            if (mBackgroundFadeOutAnimation != null) mBackgroundFadeOutAnimation.cancel();
-            mBackgroundFadeOutAnimation = ObjectAnimator.ofFloat(this, "backgroundAlpha", 0.0f);
-            mBackgroundFadeOutAnimation.setDuration(BACKGROUND_FADE_OUT_DURATION);
-            mBackgroundFadeOutAnimation.setStartDelay(BACKGROUND_FADE_OUT_DELAY);
-            mBackgroundFadeOutAnimation.start();
+            if (mChildrenOutlineFadeInAnimation != null) mChildrenOutlineFadeInAnimation.cancel();
+            if (mChildrenOutlineFadeOutAnimation != null) mChildrenOutlineFadeOutAnimation.cancel();
+            mChildrenOutlineFadeOutAnimation = ObjectAnimator.ofFloat(this, "childrenOutlineAlpha", 0.0f);
+            mChildrenOutlineFadeOutAnimation.setDuration(CHILDREN_OUTLINE_FADE_OUT_DURATION);
+            mChildrenOutlineFadeOutAnimation.setStartDelay(CHILDREN_OUTLINE_FADE_OUT_DELAY);
+            mChildrenOutlineFadeOutAnimation.start();
         }
     }
 
-    public void setBackgroundAlpha(float alpha) {
-        mBackgroundAlpha = alpha;
+    public void setChildrenOutlineAlpha(float alpha) {
+        mChildrenOutlineAlpha = alpha;
         for (int i = 0; i < getChildCount(); i++) {
             CellLayout cl = (CellLayout) getChildAt(i);
             cl.setBackgroundAlpha(alpha);
         }
     }
 
+    public float getChildrenOutlineAlpha() {
+        return mChildrenOutlineAlpha;
+    }
+
+    public void showBackgroundGradient() {
+        if (mBackgroundFadeOutAnimation != null) mBackgroundFadeOutAnimation.cancel();
+        if (mBackgroundFadeInAnimation != null) mBackgroundFadeInAnimation.cancel();
+        mBackgroundFadeInAnimation = ObjectAnimator.ofFloat(this, "backgroundAlpha", 1.0f);
+        mBackgroundFadeInAnimation.setDuration(BACKGROUND_FADE_IN_DURATION);
+        mBackgroundFadeInAnimation.start();
+    }
+
+    public void hideBackgroundGradient() {
+        if (mBackgroundFadeInAnimation != null) mBackgroundFadeInAnimation.cancel();
+        if (mBackgroundFadeOutAnimation != null) mBackgroundFadeOutAnimation.cancel();
+        mBackgroundFadeOutAnimation = ObjectAnimator.ofFloat(this, "backgroundAlpha", 0.0f);
+        mBackgroundFadeOutAnimation.setDuration(BACKGROUND_FADE_OUT_DURATION);
+        mBackgroundFadeOutAnimation.start();
+    }
+
+    public void setBackgroundAlpha(float alpha) {
+        mBackgroundAlpha = alpha;
+        invalidate();
+    }
+
     public float getBackgroundAlpha() {
         return mBackgroundAlpha;
     }
@@ -644,6 +681,18 @@
     }
 
     @Override
+    protected void onDraw(Canvas canvas) {
+        // Draw the background gradient if necessary
+        if (mBackgroundAlpha > 0.0f) {
+            mBackground.setAlpha((int) (mBackgroundAlpha * 255));
+            mBackground.setBounds(mScrollX, 0, mScrollX + getMeasuredWidth(), getMeasuredHeight());
+            mBackground.draw(canvas);
+        }
+
+        super.onDraw(canvas);
+    }
+
+    @Override
     protected void dispatchDraw(Canvas canvas) {
         if (mIsSmall || mIsInUnshrinkAnimation) {
             // Draw all the workspaces if we're small
@@ -822,6 +871,8 @@
 
     // we use this to shrink the workspace for the all apps view and the customize view
     private void shrink(ShrinkPosition shrinkPosition, boolean animated) {
+        showBackgroundGradient();
+
         if (mFirstLayout) {
             // (mFirstLayout == "first layout has not happened yet")
             // if we get a call to shrink() as part of our initialization (for example, if
@@ -1103,6 +1154,8 @@
     }
 
     void unshrink(boolean animated) {
+        hideBackgroundGradient();
+
         if (mIsSmall) {
             mIsSmall = false;
             if (mAnimator != null) {