Take account of bounds set on drag drawables.

If bounds are set on a compound drawable in a textview, drawing it into a
bitmap set to the intrinsic size of the drawable results in it being scaled
down in the top corner. Scaling it down again into the grid icon size then
gives a tiny icon.

Use the drawable bounds if any are set, otherwise use the intrinsic size.

Bug: 14103508
Change-Id: Idadd7bb891dc33d092eb9ceb3025b9a5d9e1bfd8
This commit is contained in:
Mathew Inwood
2014-04-16 14:17:39 +01:00
parent 1a1fdf4185
commit 859002985e
+17 -5
View File
@@ -1992,6 +1992,15 @@ public class Workspace extends SmoothPagedView
mDragOutline = createDragOutline(v, canvas, DRAG_BITMAP_PADDING);
}
private Rect getDrawableBounds(Drawable d) {
Rect bounds = new Rect();
d.copyBounds(bounds);
if (bounds.width() == 0 || bounds.height() == 0) {
bounds.set(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
}
return bounds;
}
public void onExternalDragStartedWithItem(View v) {
final Canvas canvas = new Canvas();
@@ -2006,8 +2015,9 @@ public class Workspace extends SmoothPagedView
if (v instanceof TextView) {
TextView tv = (TextView) v;
Drawable d = tv.getCompoundDrawables()[1];
bmpWidth = d.getIntrinsicWidth();
bmpHeight = d.getIntrinsicHeight();
Rect bounds = getDrawableBounds(d);
bmpWidth = bounds.width();
bmpHeight = bounds.height();
}
// Compose the bitmap to create the icon from
@@ -2527,7 +2537,8 @@ public class Workspace extends SmoothPagedView
destCanvas.save();
if (v instanceof TextView && pruneToDrawable) {
Drawable d = ((TextView) v).getCompoundDrawables()[1];
clipRect.set(0, 0, d.getIntrinsicWidth() + padding, d.getIntrinsicHeight() + padding);
Rect bounds = getDrawableBounds(d);
clipRect.set(0, 0, bounds.width() + padding, bounds.height() + padding);
destCanvas.translate(padding / 2, padding / 2);
d.draw(destCanvas);
} else {
@@ -2568,8 +2579,9 @@ public class Workspace extends SmoothPagedView
if (v instanceof TextView) {
Drawable d = ((TextView) v).getCompoundDrawables()[1];
b = Bitmap.createBitmap(d.getIntrinsicWidth() + padding,
d.getIntrinsicHeight() + padding, Bitmap.Config.ARGB_8888);
Rect bounds = getDrawableBounds(d);
b = Bitmap.createBitmap(bounds.width() + padding,
bounds.height() + padding, Bitmap.Config.ARGB_8888);
} else {
b = Bitmap.createBitmap(
v.getWidth() + padding, v.getHeight() + padding, Bitmap.Config.ARGB_8888);