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) {