Fix misaligned folder creation drag over target
Previously, the folder creation distance was based on the center of the cell, rather than the *visual* center, i.e. around the icon. Updated to use existing getWorkspaceVisualDragBounds() to handle this.
Test: with DEBUG_VISUALIZE_OCCUPIED=true, ensure green circles are centered around the app icons; manually drag and drop to check the drawn regions are correct
Bug: 204406063
Change-Id: I691a5cbbfc18c88436b88b7bda42f7920b9a5750
diff --git a/src/com/android/launcher3/CellLayout.java b/src/com/android/launcher3/CellLayout.java
index bd1d736..c9befe8 100644
--- a/src/com/android/launcher3/CellLayout.java
+++ b/src/com/android/launcher3/CellLayout.java
@@ -461,7 +461,7 @@
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 @@
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 bac7101..2345f51 100644
--- a/src/com/android/launcher3/Workspace.java
+++ b/src/com/android/launcher3/Workspace.java
@@ -1751,8 +1751,8 @@
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 @@
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 @@
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 @@
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 @@
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;