Merge "Improve feedback during spring loaded mode" into honeycomb
diff --git a/src/com/android/launcher2/CellLayout.java b/src/com/android/launcher2/CellLayout.java
index c105c36..de75fd3 100644
--- a/src/com/android/launcher2/CellLayout.java
+++ b/src/com/android/launcher2/CellLayout.java
@@ -1245,6 +1245,13 @@
         return result;
     }
 
+    public int[] cellSpansToSize(int hSpans, int vSpans) {
+        int[] size = new int[2];
+        size[0] = hSpans * mCellWidth + (hSpans - 1) * mWidthGap;
+        size[1] = vSpans * mCellHeight + (vSpans - 1) * mHeightGap;
+        return size;
+    }
+
     /**
      * Calculate the grid spans needed to fit given item
      */
diff --git a/src/com/android/launcher2/CustomizePagedView.java b/src/com/android/launcher2/CustomizePagedView.java
index c74e5f4..e934efa 100644
--- a/src/com/android/launcher2/CustomizePagedView.java
+++ b/src/com/android/launcher2/CustomizePagedView.java
@@ -479,8 +479,9 @@
         }
     }
 
-    Bitmap drawableToBitmap(Drawable d, View v) {
-        Bitmap b = Bitmap.createBitmap(v.getWidth(), v.getHeight(), Bitmap.Config.ARGB_8888);
+    Bitmap drawableToBitmap(Drawable d, View v, boolean clipHeight) {
+        int height = clipHeight ? v.getPaddingTop() + d.getIntrinsicHeight() : v.getHeight();
+        Bitmap b = Bitmap.createBitmap(v.getWidth(), height, Bitmap.Config.ARGB_8888);
         Canvas c = new Canvas(b);
         c.translate((v.getWidth() - d.getIntrinsicWidth()) / 2, v.getPaddingTop());
         d.draw(c);
@@ -508,8 +509,7 @@
                 // Get the widget preview as the drag representation
                 final LinearLayout l = (LinearLayout) v;
                 final ImageView i = (ImageView) l.findViewById(R.id.widget_preview);
-                final Drawable icon = i.getDrawable();
-                Bitmap b = drawableToBitmap(icon, i);
+                Bitmap b = drawableToBitmap(i.getDrawable(), i, true);
                 PendingAddWidgetInfo createWidgetInfo = (PendingAddWidgetInfo) v.getTag();
 
                 int[] spanXY = CellLayout.rectToCell(
@@ -529,7 +529,7 @@
                 // get icon (top compound drawable, index is 1)
                 final TextView tv = (TextView) v;
                 final Drawable icon = tv.getCompoundDrawables()[1];
-                Bitmap b = drawableToBitmap(icon, tv);
+                Bitmap b = drawableToBitmap(icon, tv, false);
                 PendingAddItemInfo createItemInfo = (PendingAddItemInfo) v.getTag();
 
                 mLauncher.getWorkspace().onDragStartedWithItemSpans(1, 1, b);
@@ -546,7 +546,7 @@
                 // get icon (top compound drawable, index is 1)
                 final TextView tv = (TextView) v;
                 final Drawable icon = tv.getCompoundDrawables()[1];
-                Bitmap b = drawableToBitmap(icon, tv);
+                Bitmap b = drawableToBitmap(icon, tv, false);
                 ApplicationInfo app = (ApplicationInfo) v.getTag();
                 app = new ApplicationInfo(app);
 
diff --git a/src/com/android/launcher2/DragView.java b/src/com/android/launcher2/DragView.java
index 433dab8..c0776a9 100644
--- a/src/com/android/launcher2/DragView.java
+++ b/src/com/android/launcher2/DragView.java
@@ -48,7 +48,6 @@
     private int mDragRegionHeight;
 
     ValueAnimator mAnim;
-    private float mScale = 1.0f;
     private float mOffsetX = 0.0f;
     private float mOffsetY = 0.0f;
 
@@ -144,22 +143,6 @@
         mOnDrawRunnable = r;
     }
 
-    public int getScaledDragRegionXOffset() {
-        return -(int)((mScale - 1.0f) * mDragRegionWidth / 2);
-    }
-
-    public int getScaledDragRegionWidth() {
-        return (int)(mScale * mDragRegionWidth);
-    }
-
-    public int getScaledDragRegionYOffset() {
-        return -(int)((mScale - 1.0f) * mDragRegionHeight / 2);
-    }
-
-    public int getScaledDragRegionHeight() {
-        return (int)(mScale * mDragRegionWidth);
-    }
-
     public int getDragRegionLeft() {
         return mDragRegionLeft;
     }
diff --git a/src/com/android/launcher2/Workspace.java b/src/com/android/launcher2/Workspace.java
index fd90b06..270027b 100644
--- a/src/com/android/launcher2/Workspace.java
+++ b/src/com/android/launcher2/Workspace.java
@@ -1488,8 +1488,10 @@
         // We need to add extra padding to the bitmap to make room for the glow effect
         final int bitmapPadding = HolographicOutlineHelper.MAX_OUTER_BLUR_RADIUS;
 
+        CellLayout cl = (CellLayout) getChildAt(0);
+        int[] desiredSize = cl.cellSpansToSize(spanX, spanY);
         // The outline is used to visualize where the item will land if dropped
-        mDragOutline = createDragOutline(b, canvas, bitmapPadding);
+        mDragOutline = createDragOutline(b, canvas, bitmapPadding, desiredSize[0], desiredSize[1]);
 
         updateWhichPagesAcceptDropsDuringDrag(mShrinkState, spanX, spanY);
     }
@@ -1685,13 +1687,24 @@
      * Returns a new bitmap to be used as the object outline, e.g. to visualize the drop location.
      * Responsibility for the bitmap is transferred to the caller.
      */
-    private Bitmap createDragOutline(Bitmap orig, Canvas canvas, int padding) {
+    private Bitmap createDragOutline(Bitmap orig, Canvas canvas, int padding, int w, int h) {
         final int outlineColor = getResources().getColor(R.color.drag_outline_color);
-        final Bitmap b = Bitmap.createBitmap(
-                orig.getWidth() + padding, orig.getHeight() + padding, Bitmap.Config.ARGB_8888);
-
+        final Bitmap b = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
         canvas.setBitmap(b);
-        canvas.drawBitmap(orig, 0, 0, new Paint());
+
+        Rect src = new Rect(0, 0, orig.getWidth(), orig.getHeight());
+        float scaleFactor = Math.min((w - padding) / (float) orig.getWidth(),
+                (h - padding) / (float) orig.getHeight());
+        int scaledWidth = (int) (scaleFactor * orig.getWidth());
+        int scaledHeight = (int) (scaleFactor * orig.getHeight());
+        Rect dst = new Rect(0, 0, scaledWidth, scaledHeight);
+
+        // center the image
+        dst.offset((w - scaledWidth) / 2, (h - scaledHeight) / 2);
+
+        Paint p = new Paint();
+        p.setFilterBitmap(true);
+        canvas.drawBitmap(orig, src, dst, p);
         mOutlineHelper.applyMediumExpensiveOutlineWithBlur(b, canvas, outlineColor, outlineColor);
 
         return b;
@@ -2229,11 +2242,11 @@
             int dragViewX, int dragViewY, Matrix cachedInverseMatrix) {
         // Transform the coordinates of the item being dragged to the CellLayout's coordinates
         final float[] draggedItemTopLeft = mTempDragCoordinates;
-        draggedItemTopLeft[0] = dragViewX + dragView.getScaledDragRegionXOffset();
-        draggedItemTopLeft[1] = dragViewY + dragView.getScaledDragRegionYOffset();
+        draggedItemTopLeft[0] = dragViewX;
+        draggedItemTopLeft[1] = dragViewY;
         final float[] draggedItemBottomRight = mTempDragBottomRightCoordinates;
-        draggedItemBottomRight[0] = draggedItemTopLeft[0] + dragView.getScaledDragRegionWidth();
-        draggedItemBottomRight[1] = draggedItemTopLeft[1] + dragView.getScaledDragRegionHeight();
+        draggedItemBottomRight[0] = draggedItemTopLeft[0] + dragView.getDragRegionWidth();
+        draggedItemBottomRight[1] = draggedItemTopLeft[1] + dragView.getDragRegionHeight();
 
         // Transform the dragged item's top left coordinates
         // to the CellLayout's local coordinates