Changing AllApps checked visualization, fixing drag offset issue in AllApps/Customize.

- fixing previous change which clobbered pressed/focused state padding

Change-Id: I229d803322554e51bc9c1f15d3687b01b0f6679f
diff --git a/src/com/android/launcher2/AllAppsPagedView.java b/src/com/android/launcher2/AllAppsPagedView.java
index 2fd0b65..1ad7e07 100644
--- a/src/com/android/launcher2/AllAppsPagedView.java
+++ b/src/com/android/launcher2/AllAppsPagedView.java
@@ -23,6 +23,7 @@
 import android.content.res.TypedArray;
 import android.graphics.Bitmap;
 import android.graphics.Canvas;
+import android.graphics.Color;
 import android.graphics.drawable.Drawable;
 import android.util.AttributeSet;
 import android.util.Log;
@@ -246,16 +247,6 @@
             return false;
         }
 
-        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 c = (Checkable) v;
-            c.toggle();
-        }
-
         // Start drag mode after the item is selected
         setupDragMode();
 
@@ -263,13 +254,30 @@
         app = new ApplicationInfo(app);
 
         // get icon (top compound drawable, index is 1)
-        final Drawable icon = ((TextView) v).getCompoundDrawables()[1];
-        Bitmap b = Bitmap.createBitmap(icon.getIntrinsicWidth(), icon.getIntrinsicHeight(),
+        final TextView tv = (TextView) v;
+        final Drawable icon = tv.getCompoundDrawables()[1];
+        Bitmap b = Bitmap.createBitmap(v.getWidth(), v.getHeight(),
                 Bitmap.Config.ARGB_8888);
         Canvas c = new Canvas(b);
+        c.translate((v.getWidth() - icon.getIntrinsicWidth()) / 2, v.getPaddingTop());
         icon.draw(c);
+
+        // 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;
+            checkable.toggle();
+        }
+
+        // Start the drag
         mLauncher.getWorkspace().onDragStartedWithItemSpans(1, 1, b);
         mDragController.startDrag(v, b, this, app, DragController.DRAG_ACTION_COPY, null);
+        b.recycle();
         return true;
     }
 
diff --git a/src/com/android/launcher2/CustomizePagedView.java b/src/com/android/launcher2/CustomizePagedView.java
index 799e017..694d4d0 100644
--- a/src/com/android/launcher2/CustomizePagedView.java
+++ b/src/com/android/launcher2/CustomizePagedView.java
@@ -24,10 +24,10 @@
 import org.xmlpull.v1.XmlPullParser;
 
 import android.animation.Animator;
+import android.animation.Animator.AnimatorListener;
 import android.animation.ObjectAnimator;
 import android.animation.PropertyValuesHolder;
 import android.animation.TimeInterpolator;
-import android.animation.Animator.AnimatorListener;
 import android.app.WallpaperManager;
 import android.appwidget.AppWidgetManager;
 import android.appwidget.AppWidgetProviderInfo;
@@ -41,8 +41,9 @@
 import android.content.res.TypedArray;
 import android.content.res.XmlResourceParser;
 import android.graphics.Bitmap;
-import android.graphics.Canvas;
 import android.graphics.Bitmap.Config;
+import android.graphics.Canvas;
+import android.graphics.Color;
 import android.graphics.drawable.Drawable;
 import android.util.AttributeSet;
 import android.util.Log;
@@ -571,10 +572,10 @@
         return super.onTouchEvent(ev);
     }
 
-    Bitmap drawableToBitmap(Drawable d) {
-        Bitmap b = Bitmap.createBitmap(d.getIntrinsicWidth(), d.getIntrinsicHeight(),
-                Bitmap.Config.ARGB_8888);
+    Bitmap drawableToBitmap(Drawable d, View v) {
+        Bitmap b = Bitmap.createBitmap(v.getWidth(), v.getHeight(), Bitmap.Config.ARGB_8888);
         Canvas c = new Canvas(b);
+        c.translate((v.getWidth() - d.getIntrinsicWidth()) / 2, v.getPaddingTop());
         d.draw(c);
         return b;
     }
@@ -595,10 +596,10 @@
         case WidgetCustomization: {
             // Get the widget preview as the drag representation
             final LinearLayout l = (LinearLayout) v;
-            final Drawable icon = ((ImageView) l.findViewById(R.id.widget_preview)).getDrawable();
-            Bitmap b = drawableToBitmap(icon);
+            final ImageView i = (ImageView) l.findViewById(R.id.widget_preview);
+            final Drawable icon = i.getDrawable();
+            Bitmap b = drawableToBitmap(icon, i);
             PendingAddWidgetInfo createWidgetInfo = (PendingAddWidgetInfo) v.getTag();
-            final View dragView = v.findViewById(R.id.widget_preview);
 
             int[] spanXY = CellLayout.rectToCell(
                     getResources(), createWidgetInfo.minWidth, createWidgetInfo.minHeight, null);
@@ -606,30 +607,35 @@
             createWidgetInfo.spanY = spanXY[1];
             mLauncher.getWorkspace().onDragStartedWithItemSpans(spanXY[0], spanXY[1], b);
             mDragController.startDrag(
-                    v, b, this, createWidgetInfo, DragController.DRAG_ACTION_COPY, null);
-
+                    i, b, this, createWidgetInfo, DragController.DRAG_ACTION_COPY, null);
+            b.recycle();
             return true;
         }
         case ShortcutCustomization: {
             // get icon (top compound drawable, index is 1)
-            final Drawable icon = ((TextView) v).getCompoundDrawables()[1];
-            Bitmap b = drawableToBitmap(icon);
+            final TextView tv = (TextView) v;
+            final Drawable icon = tv.getCompoundDrawables()[1];
+            Bitmap b = drawableToBitmap(icon, tv);
             PendingAddItemInfo createItemInfo = (PendingAddItemInfo) v.getTag();
-            mDragController.startDrag(
-                    v, b, this, createItemInfo, DragController.DRAG_ACTION_COPY, null);
+
             mLauncher.getWorkspace().onDragStartedWithItemSpans(1, 1, b);
+            mDragController.startDrag(v, b, this, createItemInfo, DragController.DRAG_ACTION_COPY,
+                    null);
+            b.recycle();
             return true;
         }
         case ApplicationCustomization: {
             // Pick up the application for dropping
             // get icon (top compound drawable, index is 1)
-            final Drawable icon = ((TextView) v).getCompoundDrawables()[1];
-            Bitmap b = drawableToBitmap(icon);
+            final TextView tv = (TextView) v;
+            final Drawable icon = tv.getCompoundDrawables()[1];
+            Bitmap b = drawableToBitmap(icon, tv);
             ApplicationInfo app = (ApplicationInfo) v.getTag();
             app = new ApplicationInfo(app);
 
-            mDragController.startDrag(v, b, this, app, DragController.DRAG_ACTION_COPY, null);
             mLauncher.getWorkspace().onDragStartedWithItemSpans(1, 1, b);
+            mDragController.startDrag(v, b, this, app, DragController.DRAG_ACTION_COPY, null);
+            b.recycle();
             return true;
         }
         }
diff --git a/src/com/android/launcher2/PagedViewIcon.java b/src/com/android/launcher2/PagedViewIcon.java
index fbc67d8..884884e 100644
--- a/src/com/android/launcher2/PagedViewIcon.java
+++ b/src/com/android/launcher2/PagedViewIcon.java
@@ -16,6 +16,7 @@
 
 package com.android.launcher2;
 
+import android.animation.ObjectAnimator;
 import android.content.Context;
 import android.content.pm.PackageManager;
 import android.content.pm.ResolveInfo;
@@ -28,7 +29,6 @@
 import android.os.Message;
 import android.util.AttributeSet;
 import android.widget.Checkable;
-import android.widget.TextView;
 
 import com.android.launcher.R;
 import com.android.launcher2.PagedView.PagedViewIconCache;
@@ -56,6 +56,10 @@
     private int mHolographicAlpha;
 
     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;
 
     // Highlight colors
     private int mHoloBlurColor;
@@ -230,19 +234,24 @@
         if (mIsChecked != checked) {
             mIsChecked = checked;
 
+            float alpha;
+            int duration;
             if (mIsChecked) {
-                mCheckedOutline = Bitmap.createBitmap(mIcon.getWidth(), mIcon.getHeight(),
-                        Bitmap.Config.ARGB_8888);
-                Canvas checkedOutlineCanvas = new Canvas(mCheckedOutline);
-                mPaint.setAlpha(255);
-                checkedOutlineCanvas.drawBitmap(mIcon, 0, 0, mPaint);
-
-                sHolographicOutlineHelper.applyThickExpensiveOutlineWithBlur(mCheckedOutline,
-                        checkedOutlineCanvas, mCheckedBlurColor, mCheckedOutlineColor);
+                alpha = sCheckedAlpha;
+                duration = sCheckedFadeInDuration;
             } else {
-                invalidateCheckedImage();
+                alpha = 1.0f;
+                duration = sCheckedFadeOutDuration;
             }
 
+            // Initialize the animator
+            if (mCheckedAlphaAnimator != null) {
+                mCheckedAlphaAnimator.cancel();
+            }
+            mCheckedAlphaAnimator = ObjectAnimator.ofFloat(this, "alpha", alpha);
+            mCheckedAlphaAnimator.setDuration(duration);
+            mCheckedAlphaAnimator.start();
+
             invalidate();
         }
     }
diff --git a/src/com/android/launcher2/Workspace.java b/src/com/android/launcher2/Workspace.java
index 969fbd7..705453d 100644
--- a/src/com/android/launcher2/Workspace.java
+++ b/src/com/android/launcher2/Workspace.java
@@ -21,12 +21,12 @@
 import java.util.List;
 
 import android.animation.Animator;
+import android.animation.Animator.AnimatorListener;
 import android.animation.AnimatorSet;
 import android.animation.ObjectAnimator;
 import android.animation.PropertyValuesHolder;
 import android.animation.TimeInterpolator;
 import android.animation.ValueAnimator;
-import android.animation.Animator.AnimatorListener;
 import android.animation.ValueAnimator.AnimatorUpdateListener;
 import android.app.AlertDialog;
 import android.app.WallpaperManager;
@@ -44,6 +44,7 @@
 import android.graphics.Bitmap;
 import android.graphics.Camera;
 import android.graphics.Canvas;
+import android.graphics.Color;
 import android.graphics.Matrix;
 import android.graphics.Paint;
 import android.graphics.Rect;