From 273c1022405bcc5e0840450b9195622e7476c9dd Mon Sep 17 00:00:00 2001 From: Winson Chung Date: Mon, 11 Jul 2011 13:40:52 -0700 Subject: [PATCH] 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 --- .../default_widget_preview.9.png | Bin 1393 -> 0 bytes .../launcher2/AppsCustomizePagedView.java | 20 +++++++++------ src/com/android/launcher2/DragController.java | 23 +++++++++++++++--- 3 files changed, 32 insertions(+), 11 deletions(-) delete mode 100644 res/drawable-hdpi/default_widget_preview.9.png 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 833daff11067068d46740738c2a8b698359ed21b..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1393 zcmV-%1&;cOP)1n6 zZDY|QHr=Yu%J?JWuc*vFS~wrm&s>+YcJv<;YP`0NJOBgm{w`+e9Ts4?jH#M<-4D+O zknP8Si;U3UApq>(#9#j_et!vp^|UB5wm9Z209>SifPKaX+7!7{90F2c@q>4ggJVyXV*hl#Y;OE#IS`GpJ?$g8|07Pem zLhCV*J6FkydHMh@uu{CvTg9DO8Regc6 z8vxd_(HeFDszZjaKSY|bF2Mmj=pN?HKDj-NwDFF$!u#I=R)l9>BT!Kp5s&HXVmIp| zfK~4G(0c&4;K{c4PXQ_{wu+!_pXR{_JjCks!&AsXtn&bVi(X@zD*!fRYb(Mt01wo4 zwFOYs!_BH5ZUeM+IY7hl12v-4BzfryhZy7X-U2|8_g9L%e*+-Ti`C@+ZQyYu%|3u1 zW`p;4snR44V6S^gT`uSmWC`G!2@ex(>blz6KY0HqKwA!WXpfEn@S%||0MV~|7F4AB zG^VW%J^{3Duv_&O{sCB8yiT4Ms{q#|JlqYEo`>G2cMQ@zvq7P&%P|lgka_Fo0CN2O zG^nl*H`{Ws10dDG9!+@!AiiytZt1@=19TZMh^TcAfUK?Cg z)!QNwR}-w$X2hJ?pitUX&O1cApad4vptddt;@buyZ3x~25JH&tH3ldqPA9%?>HM^H zIXF?v7EOoC8szZAF4&FDwfPDYRnU}OnaI(E88|=C)B613DP*{q80qu%5o*n`(0V|3Dsy>np{<9X0I<$UXuBhnB4=zrDbC7&lIK1c$v4`{**vqGUF>sGy@_1JhO75~O))G2#Ke`Qb(b^*wGbvo;b zZ`;tFaK2U8k}+AOH-{_clF#HPh`iAbS7vA>n$uNpJ`}~yfQxGQsbJBJEH(*gF=^XM!CA& zqRfo$1MI4KaSMF{kmtSCrNv(WsEYoWxT{?T^c=)p+l|~+^TLbY2WUKH!h5XDrEcKn zuawzg_7NahHnu%aA@&E7%vWT^sw`YRh9Of{(vvEQ>ge@lfo+Zcv20{*hpSJS@B%U$ z6nfd!*gHdNKhGY33v5(Tb?0sHkB?hSoNh5qX9CA9CNHO2O!h>JDT}!LkUHT__w%z$ zd4V=7jqX!Hz|a3md@q}H1usgy`(J#I{!sn}wW^%!er5Q700000NkvXXu0mjfJ79~& diff --git a/src/com/android/launcher2/AppsCustomizePagedView.java b/src/com/android/launcher2/AppsCustomizePagedView.java index 33472ea56c..fcc4953880 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(); + int bitmapWidth; + int bitmapHeight; - // Specify the dimensions of the bitmap - if (info.minWidth >= info.minHeight) { - expectedWidth = cellWidth; - expectedHeight = mWidgetPreviewIconPaddedDimension; + // 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 f6058a0a29..5aecede0ec 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 */ @@ -384,6 +387,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. */ @@ -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: