summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWinson Chung <winsonc@google.com>2011-07-11 13:40:52 -0700
committerWinson Chung <winsonc@google.com>2011-07-11 14:00:02 -0700
commit273c1022405bcc5e0840450b9195622e7476c9dd (patch)
treea3d9bce7a3586c2e3f9cfbcab919d2fc8c4ce9dc
parenta71cb1778dc0c7e76132d21296c58da777183e26 (diff)
downloadandroid_packages_apps_Trebuchet-273c1022405bcc5e0840450b9195622e7476c9dd.tar.gz
android_packages_apps_Trebuchet-273c1022405bcc5e0840450b9195622e7476c9dd.tar.bz2
android_packages_apps_Trebuchet-273c1022405bcc5e0840450b9195622e7476c9dd.zip
Clamping touch positions to drag layer rect to prevent dragging outside of bounds.
- Fixing small issue with default widget preview aspect ratios Change-Id: I2dca0524e8aa7c48345b424bad889736fa345386
-rw-r--r--res/drawable-hdpi/default_widget_preview.9.pngbin1393 -> 0 bytes
-rw-r--r--src/com/android/launcher2/AppsCustomizePagedView.java22
-rw-r--r--src/com/android/launcher2/DragController.java23
3 files changed, 33 insertions, 12 deletions
diff --git a/res/drawable-hdpi/default_widget_preview.9.png b/res/drawable-hdpi/default_widget_preview.9.png
deleted file mode 100644
index 833daff11..000000000
--- a/res/drawable-hdpi/default_widget_preview.9.png
+++ /dev/null
Binary files differ
diff --git a/src/com/android/launcher2/AppsCustomizePagedView.java b/src/com/android/launcher2/AppsCustomizePagedView.java
index 33472ea56..fcc495388 100644
--- a/src/com/android/launcher2/AppsCustomizePagedView.java
+++ b/src/com/android/launcher2/AppsCustomizePagedView.java
@@ -829,19 +829,25 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen
// Generate a preview image if we couldn't load one
if (drawable == null) {
Resources resources = mLauncher.getResources();
-
- // Specify the dimensions of the bitmap
- if (info.minWidth >= info.minHeight) {
- expectedWidth = cellWidth;
- expectedHeight = mWidgetPreviewIconPaddedDimension;
+ int bitmapWidth;
+ int bitmapHeight;
+
+ // Specify the dimensions of the bitmap (since we are using a default preview bg with
+ // the full icon, we only imply the aspect ratio of the widget)
+ if (cellHSpan == cellVSpan) {
+ bitmapWidth = bitmapHeight = cellWidth;
+ expectedWidth = expectedHeight = mWidgetPreviewIconPaddedDimension;
+ } else if (cellHSpan >= cellVSpan) {
+ bitmapWidth = expectedWidth = cellWidth;
+ bitmapHeight = expectedHeight = mWidgetPreviewIconPaddedDimension;
} else {
// Note that in vertical widgets, we might not have enough space due to the text
// label, so be conservative and use the width as a height bound
- expectedWidth = mWidgetPreviewIconPaddedDimension;
- expectedHeight = cellWidth;
+ bitmapWidth = expectedWidth = mWidgetPreviewIconPaddedDimension;
+ bitmapHeight = expectedHeight = cellWidth;
}
- preview = Bitmap.createBitmap(expectedWidth, expectedHeight, Config.ARGB_8888);
+ preview = Bitmap.createBitmap(bitmapWidth, bitmapHeight, Config.ARGB_8888);
renderDrawableToBitmap(mDefaultWidgetBackground, preview, 0, 0, expectedWidth,
expectedHeight, 1f,1f);
diff --git a/src/com/android/launcher2/DragController.java b/src/com/android/launcher2/DragController.java
index f6058a0a2..5aecede0e 100644
--- a/src/com/android/launcher2/DragController.java
+++ b/src/com/android/launcher2/DragController.java
@@ -110,6 +110,9 @@ public class DragController {
private int mLastTouch[] = new int[2];
private int mDistanceSinceScroll = 0;
+ private int mTmpPoint[] = new int[2];
+ private Rect mDragLayerRect = new Rect();
+
/**
* Interface to receive notifications when a drag starts or stops
*/
@@ -385,6 +388,16 @@ public class DragController {
}
/**
+ * Clamps the position to the drag layer bounds.
+ */
+ private int[] getClampedDragLayerPos(float x, float y) {
+ mLauncher.getDragLayer().getLocalVisibleRect(mDragLayerRect);
+ mTmpPoint[0] = (int) Math.max(mDragLayerRect.left, Math.min(x, mDragLayerRect.right - 1));
+ mTmpPoint[1] = (int) Math.max(mDragLayerRect.top, Math.min(y, mDragLayerRect.bottom - 1));
+ return mTmpPoint;
+ }
+
+ /**
* Call this from a drag source view.
*/
public boolean onInterceptTouchEvent(MotionEvent ev) {
@@ -394,8 +407,9 @@ public class DragController {
}
final int action = ev.getAction();
- final int dragLayerX = (int) ev.getX();
- final int dragLayerY = (int) ev.getY();
+ final int[] dragLayerPos = getClampedDragLayerPos(ev.getX(), ev.getY());
+ final int dragLayerX = dragLayerPos[0];
+ final int dragLayerY = dragLayerPos[1];
switch (action) {
case MotionEvent.ACTION_MOVE:
@@ -506,8 +520,9 @@ public class DragController {
}
final int action = ev.getAction();
- final int dragLayerX = (int) ev.getX();
- final int dragLayerY = (int) ev.getY();
+ final int[] dragLayerPos = getClampedDragLayerPos(ev.getX(), ev.getY());
+ final int dragLayerX = dragLayerPos[0];
+ final int dragLayerY = dragLayerPos[1];
switch (action) {
case MotionEvent.ACTION_DOWN: