summaryrefslogtreecommitdiffstats
path: root/src/com/android/launcher2
diff options
context:
space:
mode:
authorMichael Jurka <mikejurka@google.com>2011-01-25 22:41:40 -0800
committerMichael Jurka <mikejurka@google.com>2011-01-25 22:42:27 -0800
commitf12c75cb48f87955600c56ccbe0aac84b0c11b28 (patch)
tree43932592576b117bd089f48777740ed345e7ff10 /src/com/android/launcher2
parent878aaca1fee925805e4fc210317540bb5ef933ae (diff)
downloadandroid_packages_apps_Trebuchet-f12c75cb48f87955600c56ccbe0aac84b0c11b28.tar.gz
android_packages_apps_Trebuchet-f12c75cb48f87955600c56ccbe0aac84b0c11b28.tar.bz2
android_packages_apps_Trebuchet-f12c75cb48f87955600c56ccbe0aac84b0c11b28.zip
Improve feedback during spring loaded mode
- Uniformly scale the outlines of items on the screens to match the correct grid size as closely as possible - Fix bug with drag + drop that was reporting dragged items' height wrong - Remove unused code
Diffstat (limited to 'src/com/android/launcher2')
-rw-r--r--src/com/android/launcher2/CellLayout.java7
-rw-r--r--src/com/android/launcher2/CustomizePagedView.java12
-rw-r--r--src/com/android/launcher2/DragView.java17
-rw-r--r--src/com/android/launcher2/Workspace.java33
4 files changed, 36 insertions, 33 deletions
diff --git a/src/com/android/launcher2/CellLayout.java b/src/com/android/launcher2/CellLayout.java
index c105c3624..de75fd344 100644
--- a/src/com/android/launcher2/CellLayout.java
+++ b/src/com/android/launcher2/CellLayout.java
@@ -1245,6 +1245,13 @@ public class CellLayout extends ViewGroup {
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 c74e5f42e..e934efa9c 100644
--- a/src/com/android/launcher2/CustomizePagedView.java
+++ b/src/com/android/launcher2/CustomizePagedView.java
@@ -479,8 +479,9 @@ public class CustomizePagedView extends PagedViewWithDraggableItems
}
}
- 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 @@ public class CustomizePagedView extends PagedViewWithDraggableItems
// 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 @@ public class CustomizePagedView extends PagedViewWithDraggableItems
// 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 @@ public class CustomizePagedView extends PagedViewWithDraggableItems
// 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 433dab8c6..c0776a9f2 100644
--- a/src/com/android/launcher2/DragView.java
+++ b/src/com/android/launcher2/DragView.java
@@ -48,7 +48,6 @@ public class DragView extends View {
private int mDragRegionHeight;
ValueAnimator mAnim;
- private float mScale = 1.0f;
private float mOffsetX = 0.0f;
private float mOffsetY = 0.0f;
@@ -144,22 +143,6 @@ public class DragView extends View {
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 fd90b0625..270027bfc 100644
--- a/src/com/android/launcher2/Workspace.java
+++ b/src/com/android/launcher2/Workspace.java
@@ -1488,8 +1488,10 @@ public class Workspace extends SmoothPagedView
// 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 @@ public class Workspace extends SmoothPagedView
* 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 @@ public class Workspace extends SmoothPagedView
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