Adding fade when dragging items outside of the customization tray.

Change-Id: Ie8dad00bc0278053707f81d948528929e6bb6f5c
diff --git a/res/values-xlarge/config.xml b/res/values-xlarge/config.xml
index 62f1671..d8ed214 100644
--- a/res/values-xlarge/config.xml
+++ b/res/values-xlarge/config.xml
@@ -1,6 +1,12 @@
 <resources>
     <!--  NOTE: Many of the all apps values here are also used for the customization drawer -->
 
+    <!-- Duration in milliseconds of the fade-in/out of the icons as they are being dragged
+         from the AllApps or Customization trays -->
+    <integer name="icon_allAppsCustomizeFadeInTime">150</integer>
+    <integer name="icon_allAppsCustomizeFadeOutTime">200</integer>
+    <integer name="icon_allAppsCustomizeFadeAlpha">102</integer>
+
     <!-- Duration in milliseconds of the all apps / configuration zoom-in animation. -->
     <!-- NB: This should be less than the workspaceShrinkTime as they happen together. -->
     <integer name="config_allAppsZoomInTime">700</integer>
diff --git a/src/com/android/launcher2/AllAppsPagedView.java b/src/com/android/launcher2/AllAppsPagedView.java
index caa1406..a424bc6 100644
--- a/src/com/android/launcher2/AllAppsPagedView.java
+++ b/src/com/android/launcher2/AllAppsPagedView.java
@@ -263,6 +263,10 @@
 
             // Toggle the selection on the dragged app
             Checkable checkable = (Checkable) v;
+
+            // Note: we toggle the checkable state to actually cause an alpha fade for the duration
+            // of the drag of the item.  (The fade-in will occur when all checked states are
+            // disabled when dragging ends)
             checkable.toggle();
         }
 
diff --git a/src/com/android/launcher2/ApplicationInfoDropTarget.java b/src/com/android/launcher2/ApplicationInfoDropTarget.java
index 9d421c6..f944022 100644
--- a/src/com/android/launcher2/ApplicationInfoDropTarget.java
+++ b/src/com/android/launcher2/ApplicationInfoDropTarget.java
@@ -51,11 +51,15 @@
         int colour = getContext().getResources().getColor(R.color.app_info_filter);
         mHoverPaint.setColorFilter(new PorterDuffColorFilter(colour, PorterDuff.Mode.SRC_ATOP));
 
-        // For the application info drop target, we just ignore the left padding since we don't want
-        // to overlap with the delete zone padding
-        int tb = getResources().getDimensionPixelSize(R.dimen.delete_zone_vertical_drag_padding);
-        int lr = getResources().getDimensionPixelSize(R.dimen.delete_zone_horizontal_drag_padding);
-        setDragPadding(tb, lr, tb, 0);
+        if (LauncherApplication.isScreenXLarge()) {
+            // For the application info drop target, we just ignore the left padding since we don't want
+            // to overlap with the delete zone padding
+            int tb = getResources().getDimensionPixelSize(
+                    R.dimen.delete_zone_vertical_drag_padding);
+            int lr = getResources().getDimensionPixelSize(
+                    R.dimen.delete_zone_horizontal_drag_padding);
+            setDragPadding(tb, lr, tb, 0);
+        }
     }
 
     public boolean acceptDrop(DragSource source, int x, int y, int xOffset, int yOffset,
diff --git a/src/com/android/launcher2/BubbleTextView.java b/src/com/android/launcher2/BubbleTextView.java
index 6e2a58b..2d04924 100644
--- a/src/com/android/launcher2/BubbleTextView.java
+++ b/src/com/android/launcher2/BubbleTextView.java
@@ -88,13 +88,10 @@
         mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
         mPaint.setColor(bubbleColor);
         mBubbleColorAlpha = Color.alpha(bubbleColor) / 255.0f;
-        mFocusedOutlineColor =
-            getResources().getColor(R.color.workspace_item_focused_outline_color);
-        mFocusedGlowColor = getResources().getColor(R.color.workspace_item_focused_glow_color);
-        mPressedOutlineColor =
-            getResources().getColor(R.color.workspace_item_pressed_outline_color);
-        mPressedGlowColor =
-            getResources().getColor(R.color.workspace_item_pressed_glow_color);
+        mFocusedOutlineColor = res.getColor(R.color.workspace_item_focused_outline_color);
+        mFocusedGlowColor = res.getColor(R.color.workspace_item_focused_glow_color);
+        mPressedOutlineColor = res.getColor(R.color.workspace_item_pressed_outline_color);
+        mPressedGlowColor = res.getColor(R.color.workspace_item_pressed_glow_color);
     }
 
     protected int getCacheTopPadding() {
diff --git a/src/com/android/launcher2/CustomizePagedView.java b/src/com/android/launcher2/CustomizePagedView.java
index 60f1c90..ec9d52e 100644
--- a/src/com/android/launcher2/CustomizePagedView.java
+++ b/src/com/android/launcher2/CustomizePagedView.java
@@ -54,6 +54,7 @@
 import android.view.View;
 import android.view.animation.DecelerateInterpolator;
 import android.view.animation.Interpolator;
+import android.widget.Checkable;
 import android.widget.ImageView;
 import android.widget.LinearLayout;
 import android.widget.TextView;
@@ -327,6 +328,7 @@
 
     @Override
     public void onDropCompleted(View target, boolean success) {
+        resetCheckedGrandchildren();
         mLauncher.getWorkspace().onDragStopped();
     }
 
@@ -498,6 +500,7 @@
         }
         super.beginDragging(v);
 
+        boolean result = false;
         switch (mCustomizationType) {
         case WidgetCustomization: {
             // Get the widget preview as the drag representation
@@ -515,7 +518,8 @@
             mDragController.startDrag(
                     i, b, this, createWidgetInfo, DragController.DRAG_ACTION_COPY, null);
             b.recycle();
-            return true;
+            result = true;
+            break;
         }
         case ShortcutCustomization: {
             // get icon (top compound drawable, index is 1)
@@ -528,7 +532,8 @@
             mDragController.startDrag(v, b, this, createItemInfo, DragController.DRAG_ACTION_COPY,
                     null);
             b.recycle();
-            return true;
+            result = true;
+            break;
         }
         case ApplicationCustomization: {
             // Pick up the application for dropping
@@ -542,10 +547,28 @@
             mLauncher.getWorkspace().onDragStartedWithItemSpans(1, 1, b);
             mDragController.startDrag(v, b, this, app, DragController.DRAG_ACTION_COPY, null);
             b.recycle();
-            return true;
+            result = true;
+            break;
         }
         }
-        return false;
+
+        // We toggle the checked state _after_ we create the view for the drag in case toggling the
+        // checked state changes the view's look
+        if (v instanceof Checkable) {
+            // In preparation for drag, we always reset the checked grand children regardless of
+            // what choice mode we are in
+            resetCheckedGrandchildren();
+
+            // Toggle the selection on the dragged app
+            Checkable checkable = (Checkable) v;
+
+            // Note: we toggle the checkable state to actually cause an alpha fade for the duration
+            // of the drag of the item.  (The fade-in will occur when all checked states are
+            // disabled when dragging ends)
+            checkable.toggle();
+        }
+
+        return result;
     }
 
     /**
diff --git a/src/com/android/launcher2/DeleteZone.java b/src/com/android/launcher2/DeleteZone.java
index 4bed84c..98d2b83 100644
--- a/src/com/android/launcher2/DeleteZone.java
+++ b/src/com/android/launcher2/DeleteZone.java
@@ -70,9 +70,13 @@
         mOrientation = a.getInt(R.styleable.DeleteZone_direction, ORIENTATION_HORIZONTAL);
         a.recycle();
 
-        int tb = getResources().getDimensionPixelSize(R.dimen.delete_zone_vertical_drag_padding);
-        int lr = getResources().getDimensionPixelSize(R.dimen.delete_zone_horizontal_drag_padding);
-        setDragPadding(tb, lr, tb, lr);
+        if (LauncherApplication.isScreenXLarge()) {
+            int tb = getResources().getDimensionPixelSize(
+                    R.dimen.delete_zone_vertical_drag_padding);
+            int lr = getResources().getDimensionPixelSize(
+                    R.dimen.delete_zone_horizontal_drag_padding);
+            setDragPadding(tb, lr, tb, lr);
+        }
     }
 
     @Override
diff --git a/src/com/android/launcher2/PagedViewIcon.java b/src/com/android/launcher2/PagedViewIcon.java
index d91daf9..e4049eb 100644
--- a/src/com/android/launcher2/PagedViewIcon.java
+++ b/src/com/android/launcher2/PagedViewIcon.java
@@ -20,6 +20,7 @@
 import android.content.Context;
 import android.content.pm.PackageManager;
 import android.content.pm.ResolveInfo;
+import android.content.res.Resources;
 import android.content.res.TypedArray;
 import android.graphics.Bitmap;
 import android.graphics.Canvas;
@@ -57,9 +58,9 @@
 
     private boolean mIsChecked;
     private ObjectAnimator mCheckedAlphaAnimator;
-    private final static float sCheckedAlpha = 0.4f;
-    private final static int sCheckedFadeInDuration = 150;
-    private final static int sCheckedFadeOutDuration = 200;
+    private float mCheckedAlpha = 1.0f;
+    private int mCheckedFadeInDuration;
+    private int mCheckedFadeOutDuration;
 
     // Highlight colors
     private int mHoloBlurColor;
@@ -116,6 +117,15 @@
             sHolographicOutlineHelper = new HolographicOutlineHelper();
         }
 
+        // Set up fade in/out constants
+        final Resources r = context.getResources();
+        final int alpha = r.getInteger(R.integer.icon_allAppsCustomizeFadeAlpha);
+        if (alpha > 0) {
+            mCheckedAlpha = r.getInteger(R.integer.icon_allAppsCustomizeFadeAlpha) / 256.0f;
+            mCheckedFadeInDuration = r.getInteger(R.integer.icon_allAppsCustomizeFadeInTime);
+            mCheckedFadeOutDuration = r.getInteger(R.integer.icon_allAppsCustomizeFadeOutTime);
+        }
+
         setFocusable(true);
         setBackgroundDrawable(null);
     }
@@ -230,11 +240,11 @@
             float alpha;
             int duration;
             if (mIsChecked) {
-                alpha = sCheckedAlpha;
-                duration = sCheckedFadeInDuration;
+                alpha = mCheckedAlpha;
+                duration = mCheckedFadeInDuration;
             } else {
                 alpha = 1.0f;
-                duration = sCheckedFadeOutDuration;
+                duration = mCheckedFadeOutDuration;
             }
 
             // Initialize the animator
diff --git a/src/com/android/launcher2/PagedViewWidget.java b/src/com/android/launcher2/PagedViewWidget.java
index 5f5844f..8c729b1 100644
--- a/src/com/android/launcher2/PagedViewWidget.java
+++ b/src/com/android/launcher2/PagedViewWidget.java
@@ -16,34 +16,34 @@
 
 package com.android.launcher2;
 
+import android.animation.ObjectAnimator;
 import android.appwidget.AppWidgetProviderInfo;
 import android.content.Context;
 import android.content.pm.PackageManager;
 import android.content.pm.ResolveInfo;
+import android.content.res.Resources;
 import android.content.res.TypedArray;
 import android.graphics.Bitmap;
 import android.graphics.Canvas;
 import android.graphics.Color;
 import android.graphics.Paint;
-import android.graphics.PorterDuffXfermode;
 import android.graphics.PorterDuff.Mode;
-import android.graphics.drawable.Drawable;
 import android.os.Handler;
 import android.os.HandlerThread;
 import android.os.Message;
 import android.util.AttributeSet;
 import android.view.MotionEvent;
+import android.widget.Checkable;
 import android.widget.ImageView;
 import android.widget.LinearLayout;
 import android.widget.TextView;
 
 import com.android.launcher.R;
-import com.android.launcher2.PagedView.PagedViewIconCache;
 
 /**
  * The linear layout used strictly for the widget/wallpaper tab of the customization tray
  */
-public class PagedViewWidget extends LinearLayout {
+public class PagedViewWidget extends LinearLayout implements Checkable {
     static final String TAG = "PagedViewWidgetLayout";
 
     private final Paint mPaint = new Paint();
@@ -59,6 +59,12 @@
     private int mHoloBlurColor;
     private int mHoloOutlineColor;
 
+    private boolean mIsChecked;
+    private ObjectAnimator mCheckedAlphaAnimator;
+    private float mCheckedAlpha = 1.0f;
+    private int mCheckedFadeInDuration;
+    private int mCheckedFadeOutDuration;
+
     private static final HandlerThread sWorkerThread = new HandlerThread("pagedviewwidget-helper");
     static {
         sWorkerThread.start();
@@ -118,6 +124,15 @@
             sHolographicOutlineHelper = new HolographicOutlineHelper();
         }
 
+        // Set up fade in/out constants
+        final Resources r = context.getResources();
+        final int alpha = r.getInteger(R.integer.icon_allAppsCustomizeFadeAlpha);
+        if (alpha > 0) {
+            mCheckedAlpha = r.getInteger(R.integer.icon_allAppsCustomizeFadeAlpha) / 256.0f;
+            mCheckedFadeInDuration = r.getInteger(R.integer.icon_allAppsCustomizeFadeInTime);
+            mCheckedFadeOutDuration = r.getInteger(R.integer.icon_allAppsCustomizeFadeOutTime);
+        }
+
         setFocusable(true);
         setWillNotDraw(false);
         setClipToPadding(false);
@@ -219,4 +234,41 @@
         super.onDetachedFromWindow();
         sWorker.removeMessages(MESSAGE_CREATE_HOLOGRAPHIC_OUTLINE, this);
     }
+
+    @Override
+    public void setChecked(boolean checked) {
+        if (mIsChecked != checked) {
+            mIsChecked = checked;
+
+            float alpha;
+            int duration;
+            if (mIsChecked) {
+                alpha = mCheckedAlpha;
+                duration = mCheckedFadeInDuration;
+            } else {
+                alpha = 1.0f;
+                duration = mCheckedFadeOutDuration;
+            }
+
+            // Initialize the animator
+            if (mCheckedAlphaAnimator != null) {
+                mCheckedAlphaAnimator.cancel();
+            }
+            mCheckedAlphaAnimator = ObjectAnimator.ofFloat(this, "alpha", getAlpha(), alpha);
+            mCheckedAlphaAnimator.setDuration(duration);
+            mCheckedAlphaAnimator.start();
+
+            invalidate();
+        }
+    }
+
+    @Override
+    public boolean isChecked() {
+        return mIsChecked;
+    }
+
+    @Override
+    public void toggle() {
+        setChecked(!mIsChecked);
+    }
 }