From c6ee42e25f203e408826e7eab4ad8faf67ed2ff9 Mon Sep 17 00:00:00 2001 From: Michael Jurka Date: Thu, 30 Sep 2010 12:04:50 -0700 Subject: [PATCH] Fix: dragging items to adjacent screens would not properly show the available/unavailable cells Change-Id: I47d1405315db01f87dfcce3536295d2a0d0dc444 --- src/com/android/launcher2/CellLayout.java | 23 +++++++++++------------ src/com/android/launcher2/Workspace.java | 18 ++++++++++-------- 2 files changed, 21 insertions(+), 20 deletions(-) diff --git a/src/com/android/launcher2/CellLayout.java b/src/com/android/launcher2/CellLayout.java index 84b26f21c3..a55990b1ef 100644 --- a/src/com/android/launcher2/CellLayout.java +++ b/src/com/android/launcher2/CellLayout.java @@ -766,9 +766,9 @@ public class CellLayout extends ViewGroup { */ int[] findNearestVacantArea( int pixelX, int pixelY, int spanX, int spanY, View ignoreView, int[] result) { - if (ignoreView != null) { - markCellsAsUnoccupiedForView(ignoreView); - } + // mark space take by ignoreView as available (method checks if ignoreView is null) + markCellsAsUnoccupiedForView(ignoreView); + // Keep track of best-scoring drop area final int[] bestXY = result != null ? result : new int[2]; double bestDistance = Double.MAX_VALUE; @@ -802,9 +802,8 @@ public class CellLayout extends ViewGroup { } } } - if (ignoreView != null) { - markCellsAsOccupiedForView(ignoreView); - } + // re-mark space taken by ignoreView as occupied + markCellsAsOccupiedForView(ignoreView); // Return null if no suitable location found if (bestDistance < Double.MAX_VALUE) { @@ -872,9 +871,8 @@ public class CellLayout extends ViewGroup { */ boolean findCellForSpanThatIntersectsIgnoring(int[] cellXY, int spanX, int spanY, int intersectX, int intersectY, View ignoreView) { - if (ignoreView != null) { - markCellsAsUnoccupiedForView(ignoreView); - } + // mark space take by ignoreView as available (method checks if ignoreView is null) + markCellsAsUnoccupiedForView(ignoreView); boolean foundCell = false; while (true) { @@ -927,9 +925,8 @@ public class CellLayout extends ViewGroup { } } - if (ignoreView != null) { - markCellsAsOccupiedForView(ignoreView); - } + // re-mark space taken by ignoreView as occupied + markCellsAsOccupiedForView(ignoreView); return foundCell; } @@ -1123,11 +1120,13 @@ out: for (int i = x; i < x + spanX - 1 && x < xCount; i++) { } private void markCellsAsOccupiedForView(View view) { + if (view == null || view.getParent() != this) return; LayoutParams lp = (LayoutParams) view.getLayoutParams(); markCellsForView(lp.cellX, lp.cellY, lp.cellHSpan, lp.cellVSpan, true); } private void markCellsAsUnoccupiedForView(View view) { + if (view == null || view.getParent() != this) return; LayoutParams lp = (LayoutParams) view.getLayoutParams(); markCellsForView(lp.cellX, lp.cellY, lp.cellHSpan, lp.cellVSpan, false); } diff --git a/src/com/android/launcher2/Workspace.java b/src/com/android/launcher2/Workspace.java index ffb8fdeb56..3ccfaf8596 100644 --- a/src/com/android/launcher2/Workspace.java +++ b/src/com/android/launcher2/Workspace.java @@ -774,23 +774,25 @@ public class Workspace extends SmoothPagedView } else { cellLayout = getCurrentDropLayout(); } + if (source != this) { onDropExternal(originX, originY, dragInfo, cellLayout); } else { // Move internally if (mDragInfo != null) { final View cell = mDragInfo.cell; - int index = mScroller.isFinished() ? mCurrentPage : mNextPage; - if (index != mDragInfo.screen) { - final CellLayout originalCellLayout = (CellLayout) getChildAt(mDragInfo.screen); - originalCellLayout.removeView(cell); - addInScreen(cell, index, mDragInfo.cellX, mDragInfo.cellY, - mDragInfo.spanX, mDragInfo.spanY); - } mTargetCell = findNearestVacantArea(originX, originY, mDragInfo.spanX, mDragInfo.spanY, cell, cellLayout, mTargetCell); + + int screen = indexOfChild(cellLayout); + if (screen != mDragInfo.screen) { + final CellLayout originalCellLayout = (CellLayout) getChildAt(mDragInfo.screen); + originalCellLayout.removeView(cell); + addInScreen(cell, screen, mTargetCell[0], mTargetCell[1], + mDragInfo.spanX, mDragInfo.spanY); + } cellLayout.onDropChild(cell); // update the item's position after drop @@ -803,7 +805,7 @@ public class Workspace extends SmoothPagedView mTargetCell[0], mTargetCell[1], mDragInfo.spanX, mDragInfo.spanY)); LauncherModel.moveItemInDatabase(mLauncher, info, - LauncherSettings.Favorites.CONTAINER_DESKTOP, index, + LauncherSettings.Favorites.CONTAINER_DESKTOP, screen, lp.cellX, lp.cellY); } }