Fix issue where items could not be moved back
to their original positions
This also fixes crash 3038168
Change-Id: I4142a1fe32954e76e6ab02ea09f50d4bdefec67c
diff --git a/src/com/android/launcher2/CellLayout.java b/src/com/android/launcher2/CellLayout.java
index 62e32d2..585d1c3 100644
--- a/src/com/android/launcher2/CellLayout.java
+++ b/src/com/android/launcher2/CellLayout.java
@@ -698,8 +698,30 @@
* @return The X, Y cell of a vacant area that can contain this object,
* nearest the requested location.
*/
- int[] findNearestVacantArea(int pixelX, int pixelY, int spanX, int spanY, int[] recycle) {
+ int[] findNearestVacantArea(
+ int pixelX, int pixelY, int spanX, int spanY, int[] recycle) {
+ return findNearestVacantArea(pixelX, pixelY, spanX, spanY, null, recycle);
+ }
+ /**
+ * Find a vacant area that will fit the given bounds nearest the requested
+ * cell location. Uses Euclidean distance to score multiple vacant areas.
+ *
+ * @param pixelX The X location at which you want to search for a vacant area.
+ * @param pixelY The Y location at which you want to search for a vacant area.
+ * @param spanX Horizontal span of the object.
+ * @param spanY Vertical span of the object.
+ * @param vacantCells Pre-computed set of vacant cells to search.
+ * @param recycle Previously returned value to possibly recycle.
+ * @param ignoreView Considers space occupied by this view as unoccupied
+ * @return The X, Y cell of a vacant area that can contain this object,
+ * nearest the requested location.
+ */
+ int[] findNearestVacantArea(
+ int pixelX, int pixelY, int spanX, int spanY, View ignoreView, int[] recycle) {
+ if (ignoreView != null) {
+ markCellsAsUnoccupiedForView(ignoreView);
+ }
// Keep track of best-scoring drop area
final int[] bestXY = recycle != null ? recycle : new int[2];
double bestDistance = Double.MAX_VALUE;
@@ -729,6 +751,9 @@
}
}
}
+ if (ignoreView != null) {
+ markCellsAsOccupiedForView(ignoreView);
+ }
// Return null if no suitable location found
if (bestDistance < Double.MAX_VALUE) {
diff --git a/src/com/android/launcher2/Workspace.java b/src/com/android/launcher2/Workspace.java
index 1934cd5..356286d 100644
--- a/src/com/android/launcher2/Workspace.java
+++ b/src/com/android/launcher2/Workspace.java
@@ -788,7 +788,7 @@
mDragInfo.spanX, mDragInfo.spanY);
}
- mTargetCell = estimateDropCell(originX, originY,
+ mTargetCell = findNearestVacantArea(originX, originY,
mDragInfo.spanX, mDragInfo.spanY, cell, cellLayout,
mTargetCell);
cellLayout.onDropChild(cell);
@@ -1085,7 +1085,7 @@
if (view == null) {
cellLayout.onDragExit();
} else {
- mTargetCell = estimateDropCell(x, y, 1, 1, view, cellLayout, mTargetCell);
+ mTargetCell = findNearestVacantArea(x, y, 1, 1, view, cellLayout, mTargetCell);
addInScreen(view, indexOfChild(cellLayout), mTargetCell[0],
mTargetCell[1], info.spanX, info.spanY, insertAtFirst);
cellLayout.onDropChild(view);
@@ -1148,7 +1148,7 @@
/**
* Calculate the nearest cell where the given object would be dropped.
*/
- private int[] estimateDropCell(int pixelX, int pixelY,
+ private int[] findNearestVacantArea(int pixelX, int pixelY,
int spanX, int spanY, View ignoreView, CellLayout layout, int[] recycle) {
final int[] cellXY = mTempCell;
@@ -1159,7 +1159,7 @@
// Find the best target drop location
return layout.findNearestVacantArea(
- mTempEstimate[0], mTempEstimate[1], spanX, spanY, recycle);
+ mTempEstimate[0], mTempEstimate[1], spanX, spanY, ignoreView, recycle);
}
/**