diff --git a/src/com/android/launcher3/CellLayout.java b/src/com/android/launcher3/CellLayout.java index bd1d736ab4..c9befe8451 100644 --- a/src/com/android/launcher3/CellLayout.java +++ b/src/com/android/launcher3/CellLayout.java @@ -461,7 +461,7 @@ public class CellLayout extends ViewGroup { cellToRect(x, y, 1, 1, cellBounds); cellBoundsWithSpacing.set(cellBounds); cellBoundsWithSpacing.inset(-mBorderSpace.x / 2, -mBorderSpace.y / 2); - cellToCenterPoint(x, y, cellCenter); + getWorkspaceCellVisualCenter(x, y, cellCenter); canvas.save(); canvas.clipRect(cellBoundsWithSpacing); @@ -854,11 +854,30 @@ public class CellLayout extends ViewGroup { result[1] = mTempRect.centerY(); } - public float getDistanceFromCell(float x, float y, int[] cell) { - cellToCenterPoint(cell[0], cell[1], mTmpPoint); + /** + * Returns the distance between the given coordinate and the visual center of the given cell. + */ + public float getDistanceFromWorkspaceCellVisualCenter(float x, float y, int[] cell) { + getWorkspaceCellVisualCenter(cell[0], cell[1], mTmpPoint); return (float) Math.hypot(x - mTmpPoint[0], y - mTmpPoint[1]); } + private void getWorkspaceCellVisualCenter(int cellX, int cellY, int[] outPoint) { + View child = getChildAt(cellX, cellY); + if (child instanceof DraggableView) { + DraggableView draggableChild = (DraggableView) child; + if (draggableChild.getViewType() == DRAGGABLE_ICON) { + cellToPoint(cellX, cellY, outPoint); + draggableChild.getWorkspaceVisualDragBounds(mTempRect); + mTempRect.offset(outPoint[0], outPoint[1]); + outPoint[0] = mTempRect.centerX(); + outPoint[1] = mTempRect.centerY(); + return; + } + } + cellToCenterPoint(cellX, cellY, outPoint); + } + /** * Returns the max distance from the center of a cell that can accept a drop to create a folder. */ diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java index bac71013ae..2345f51694 100644 --- a/src/com/android/launcher3/Workspace.java +++ b/src/com/android/launcher3/Workspace.java @@ -1751,8 +1751,8 @@ public class Workspace extends PagedView mTargetCell = findNearestArea((int) mDragViewVisualCenter[0], (int) mDragViewVisualCenter[1], minSpanX, minSpanY, dropTargetLayout, mTargetCell); - float distance = dropTargetLayout.getDistanceFromCell(mDragViewVisualCenter[0], - mDragViewVisualCenter[1], mTargetCell); + float distance = dropTargetLayout.getDistanceFromWorkspaceCellVisualCenter( + mDragViewVisualCenter[0], mDragViewVisualCenter[1], mTargetCell); if (mCreateUserFolderOnDrop && willCreateUserFolder(d.dragInfo, dropTargetLayout, mTargetCell, distance, true)) { return true; @@ -1966,8 +1966,8 @@ public class Workspace extends PagedView mTargetCell = findNearestArea((int) mDragViewVisualCenter[0], (int) mDragViewVisualCenter[1], spanX, spanY, dropTargetLayout, mTargetCell); - float distance = dropTargetLayout.getDistanceFromCell(mDragViewVisualCenter[0], - mDragViewVisualCenter[1], mTargetCell); + float distance = dropTargetLayout.getDistanceFromWorkspaceCellVisualCenter( + mDragViewVisualCenter[0], mDragViewVisualCenter[1], mTargetCell); // If the item being dropped is a shortcut and the nearest drop // cell also contains a shortcut, then create a folder with the two shortcuts. @@ -2395,7 +2395,7 @@ public class Workspace extends PagedView setCurrentDropOverCell(mTargetCell[0], mTargetCell[1]); - float targetCellDistance = mDragTargetLayout.getDistanceFromCell( + float targetCellDistance = mDragTargetLayout.getDistanceFromWorkspaceCellVisualCenter( mDragViewVisualCenter[0], mDragViewVisualCenter[1], mTargetCell); manageFolderFeedback(targetCellDistance, d); @@ -2651,8 +2651,8 @@ public class Workspace extends PagedView if (pendingInfo.itemType == LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT) { mTargetCell = findNearestArea(touchXY[0], touchXY[1], spanX, spanY, cellLayout, mTargetCell); - float distance = cellLayout.getDistanceFromCell(mDragViewVisualCenter[0], - mDragViewVisualCenter[1], mTargetCell); + float distance = cellLayout.getDistanceFromWorkspaceCellVisualCenter( + mDragViewVisualCenter[0], mDragViewVisualCenter[1], mTargetCell); if (willCreateUserFolder(d.dragInfo, cellLayout, mTargetCell, distance, true) || willAddToExistingUserFolder( d.dragInfo, cellLayout, mTargetCell, distance)) { @@ -2751,8 +2751,8 @@ public class Workspace extends PagedView if (touchXY != null) { mTargetCell = findNearestArea(touchXY[0], touchXY[1], spanX, spanY, cellLayout, mTargetCell); - float distance = cellLayout.getDistanceFromCell(mDragViewVisualCenter[0], - mDragViewVisualCenter[1], mTargetCell); + float distance = cellLayout.getDistanceFromWorkspaceCellVisualCenter( + mDragViewVisualCenter[0], mDragViewVisualCenter[1], mTargetCell); if (createUserFolderIfNecessary(view, container, cellLayout, mTargetCell, distance, true, d)) { return;