diff options
author | Michael Jurka <mikejurka@google.com> | 2010-09-27 17:35:12 -0700 |
---|---|---|
committer | Michael Jurka <mikejurka@google.com> | 2010-09-27 18:35:18 -0700 |
commit | 6a1435d78d5133b1f37274c4d358bf6d22e10229 (patch) | |
tree | 769b7e34e3b146ac8bf4edfbe84eca7cf859eaf9 /src | |
parent | 959f603a93cdb378b52e852e06c9e32c514ccd84 (diff) | |
download | android_packages_apps_Trebuchet-6a1435d78d5133b1f37274c4d358bf6d22e10229.tar.gz android_packages_apps_Trebuchet-6a1435d78d5133b1f37274c4d358bf6d22e10229.tar.bz2 android_packages_apps_Trebuchet-6a1435d78d5133b1f37274c4d358bf6d22e10229.zip |
Fix issue where items could not be moved back
to their original positions
This also fixes crash 3038168
Change-Id: I4142a1fe32954e76e6ab02ea09f50d4bdefec67c
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/launcher2/CellLayout.java | 27 | ||||
-rw-r--r-- | src/com/android/launcher2/Workspace.java | 8 |
2 files changed, 30 insertions, 5 deletions
diff --git a/src/com/android/launcher2/CellLayout.java b/src/com/android/launcher2/CellLayout.java index 62e32d254..585d1c3f7 100644 --- a/src/com/android/launcher2/CellLayout.java +++ b/src/com/android/launcher2/CellLayout.java @@ -698,8 +698,30 @@ public class CellLayout extends ViewGroup { * @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 @@ public class CellLayout extends ViewGroup { } } } + 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 1934cd5bb..356286d4d 100644 --- a/src/com/android/launcher2/Workspace.java +++ b/src/com/android/launcher2/Workspace.java @@ -788,7 +788,7 @@ public class Workspace extends SmoothPagedView 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 @@ public class Workspace extends SmoothPagedView 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 @@ public class Workspace extends SmoothPagedView /** * 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 @@ public class Workspace extends SmoothPagedView // Find the best target drop location return layout.findNearestVacantArea( - mTempEstimate[0], mTempEstimate[1], spanX, spanY, recycle); + mTempEstimate[0], mTempEstimate[1], spanX, spanY, ignoreView, recycle); } /** |