From 00618753e9f0ad941c13efb0b6804e4a06ecb076 Mon Sep 17 00:00:00 2001 From: Adam Cohen Date: Wed, 20 Jul 2011 12:06:04 -0700 Subject: [PATCH] Fixing issue 4083181, making springloaded dragging accurate Change-Id: Iaa69903220b2fe62e3b3009989094487e3125843 --- src/com/android/launcher2/Workspace.java | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/com/android/launcher2/Workspace.java b/src/com/android/launcher2/Workspace.java index ed4ae20f84..d40d77fdfe 100644 --- a/src/com/android/launcher2/Workspace.java +++ b/src/com/android/launcher2/Workspace.java @@ -2611,7 +2611,7 @@ public class Workspace extends SmoothPagedView * */ private CellLayout findMatchingPageForDragOver( - DragView dragView, int originX, int originY, int offsetX, int offsetY, boolean exact) { + DragView dragView, float originX, float originY, boolean exact) { // We loop through all the screens (ie CellLayouts) and see which ones overlap // with the item being dragged and then choose the one that's closest to the touch point final int screenCount = getChildCount(); @@ -2621,10 +2621,7 @@ public class Workspace extends SmoothPagedView for (int i = 0; i < screenCount; i++) { CellLayout cl = (CellLayout) getChildAt(i); - final float[] touchXy = mTempTouchCoordinates; - touchXy[0] = originX + offsetX; - touchXy[1] = originY + offsetY; - + final float[] touchXy = {originX, originY}; // Transform the touch coordinates to the CellLayout's local coordinates // If the touch point is within the bounds of the cell layout, we can return immediately cl.getMatrix().invert(mTempInverseMatrix); @@ -2635,15 +2632,15 @@ public class Workspace extends SmoothPagedView return cl; } - if (!exact && overlaps(cl, dragView, originX, originY, mTempInverseMatrix)) { + if (!exact && overlaps(cl, dragView, (int) originX, (int) originY, mTempInverseMatrix)) { // Get the center of the cell layout in screen coordinates final float[] cellLayoutCenter = mTempCellLayoutCenterCoordinates; cellLayoutCenter[0] = cl.getWidth()/2; cellLayoutCenter[1] = cl.getHeight()/2; mapPointFromChildToSelf(cl, cellLayoutCenter); - touchXy[0] = originX + offsetX; - touchXy[1] = originY + offsetY; + touchXy[0] = originX; + touchXy[1] = originY; // Calculate the distance between the center of the CellLayout // and the touch point @@ -2701,11 +2698,15 @@ public class Workspace extends SmoothPagedView // Ensure that we have proper spans for the item that we are dropping if (item.spanX < 0 || item.spanY < 0) throw new RuntimeException("Improper spans found"); + mDragViewVisualCenter = getDragViewVisualCenter(d.x, d.y, d.xOffset, d.yOffset, + d.dragView, mDragViewVisualCenter); + // Identify whether we have dragged over a side page if (isSmall()) { int left = d.x - d.xOffset; int top = d.y - d.yOffset; - layout = findMatchingPageForDragOver(d.dragView, left, top, d.xOffset, d.yOffset, true); + layout = findMatchingPageForDragOver(d.dragView, mDragViewVisualCenter[0], + mDragViewVisualCenter[1], true); if (layout != mDragTargetLayout) { // Cancel all intermediate folder states cleanupFolderCreation(d); @@ -2754,9 +2755,6 @@ public class Workspace extends SmoothPagedView if (mDragTargetLayout != null) { final View child = (mDragInfo == null) ? null : mDragInfo.cell; - mDragViewVisualCenter = getDragViewVisualCenter(d.x, d.y, d.xOffset, d.yOffset, - d.dragView, mDragViewVisualCenter); - // We want the point to be mapped to the dragTarget. if (mLauncher.isHotseatLayout(mDragTargetLayout)) { mapPointFromSelfToSibling(mLauncher.getHotseat(), mDragViewVisualCenter);