am 4c58c48: Fixes #1844053. Home was accepting all drops, even when ther

Merge commit '4c58c485d8c02f8ca7e8b4d93140440f6a3a5131'

* commit '4c58c485d8c02f8ca7e8b4d93140440f6a3a5131':
  Fixes #1844053. Home was accepting all drops, even when there was no room left for a drop. This change fixes this while retaining the 'snap to vacant cell' ability added in Cupcake.
This commit is contained in:
Romain Guy 2009-05-12 19:06:23 -07:00 committed by The Android Open Source Project
commit 77bd393b66
2 changed files with 32 additions and 12 deletions

View File

@ -939,7 +939,7 @@ out: for (int i = x; i < x + spanX - 1 && x < xCount; i++) {
int maxVacantSpanYSpanX; int maxVacantSpanYSpanX;
final Rect current = new Rect(); final Rect current = new Rect();
private void clearVacantCells() { void clearVacantCells() {
final ArrayList<VacantCell> list = vacantCells; final ArrayList<VacantCell> list = vacantCells;
final int count = list.size(); final int count = list.size();
@ -980,6 +980,10 @@ out: for (int i = x; i < x + spanX - 1 && x < xCount; i++) {
* @return True if a vacant cell of the specified dimension was found, false otherwise. * @return True if a vacant cell of the specified dimension was found, false otherwise.
*/ */
boolean findCellForSpan(int[] cellXY, int spanX, int spanY) { boolean findCellForSpan(int[] cellXY, int spanX, int spanY) {
return findCellForSpan(cellXY, spanX, spanY, true);
}
boolean findCellForSpan(int[] cellXY, int spanX, int spanY, boolean clear) {
final ArrayList<VacantCell> list = vacantCells; final ArrayList<VacantCell> list = vacantCells;
final int count = list.size(); final int count = list.size();
@ -1013,7 +1017,7 @@ out: for (int i = x; i < x + spanX - 1 && x < xCount; i++) {
} }
} }
clearVacantCells(); if (clear) clearVacantCells();
return found; return found;
} }

View File

@ -272,6 +272,7 @@ public class Workspace extends ViewGroup implements DropTarget, DragSource, Drag
* @param currentScreen * @param currentScreen
*/ */
void setCurrentScreen(int currentScreen) { void setCurrentScreen(int currentScreen) {
clearVacantCache();
mCurrentScreen = Math.max(0, Math.min(currentScreen, getChildCount() - 1)); mCurrentScreen = Math.max(0, Math.min(currentScreen, getChildCount() - 1));
scrollTo(mCurrentScreen * getWidth(), 0); scrollTo(mCurrentScreen * getWidth(), 0);
invalidate(); invalidate();
@ -345,6 +346,8 @@ public class Workspace extends ViewGroup implements DropTarget, DragSource, Drag
throw new IllegalStateException("The screen must be >= 0 and < " + getChildCount()); throw new IllegalStateException("The screen must be >= 0 and < " + getChildCount());
} }
clearVacantCache();
final CellLayout group = (CellLayout) getChildAt(screen); final CellLayout group = (CellLayout) getChildAt(screen);
CellLayout.LayoutParams lp = (CellLayout.LayoutParams) child.getLayoutParams(); CellLayout.LayoutParams lp = (CellLayout.LayoutParams) child.getLayoutParams();
if (lp == null) { if (lp == null) {
@ -379,6 +382,13 @@ public class Workspace extends ViewGroup implements DropTarget, DragSource, Drag
return null; return null;
} }
private void clearVacantCache() {
if (mVacantCache != null) {
mVacantCache.clearVacantCells();
mVacantCache = null;
}
}
/** /**
* Returns the coordinate of a vacant cell for the current screen. * Returns the coordinate of a vacant cell for the current screen.
*/ */
@ -840,6 +850,7 @@ public class Workspace extends ViewGroup implements DropTarget, DragSource, Drag
void snapToScreen(int whichScreen) { void snapToScreen(int whichScreen) {
if (!mScroller.isFinished()) return; if (!mScroller.isFinished()) return;
clearVacantCache();
enableChildrenCache(); enableChildrenCache();
whichScreen = Math.max(0, Math.min(whichScreen, getChildCount() - 1)); whichScreen = Math.max(0, Math.min(whichScreen, getChildCount() - 1));
@ -934,7 +945,7 @@ public class Workspace extends ViewGroup implements DropTarget, DragSource, Drag
public void onDragEnter(DragSource source, int x, int y, int xOffset, int yOffset, public void onDragEnter(DragSource source, int x, int y, int xOffset, int yOffset,
Object dragInfo) { Object dragInfo) {
mVacantCache = null; clearVacantCache();
} }
public void onDragOver(DragSource source, int x, int y, int xOffset, int yOffset, public void onDragOver(DragSource source, int x, int y, int xOffset, int yOffset,
@ -943,7 +954,7 @@ public class Workspace extends ViewGroup implements DropTarget, DragSource, Drag
public void onDragExit(DragSource source, int x, int y, int xOffset, int yOffset, public void onDragExit(DragSource source, int x, int y, int xOffset, int yOffset,
Object dragInfo) { Object dragInfo) {
mVacantCache = null; clearVacantCache();
} }
private void onDropExternal(int x, int y, Object dragInfo, CellLayout cellLayout) { private void onDropExternal(int x, int y, Object dragInfo, CellLayout cellLayout) {
@ -1001,8 +1012,17 @@ public class Workspace extends ViewGroup implements DropTarget, DragSource, Drag
*/ */
public boolean acceptDrop(DragSource source, int x, int y, public boolean acceptDrop(DragSource source, int x, int y,
int xOffset, int yOffset, Object dragInfo) { int xOffset, int yOffset, Object dragInfo) {
// Workspaces accept everything final CellLayout layout = getCurrentDropLayout();
return true; final CellLayout.CellInfo cellInfo = mDragInfo;
final int spanX = cellInfo == null ? 1 : cellInfo.spanX;
final int spanY = cellInfo == null ? 1 : cellInfo.spanY;
if (mVacantCache == null) {
final View ignoreView = cellInfo == null ? null : cellInfo.cell;
mVacantCache = layout.findAllVacantCells(null, ignoreView);
}
return mVacantCache.findCellForSpan(mTempEstimate, spanX, spanY, false);
} }
/** /**
@ -1080,14 +1100,14 @@ public class Workspace extends ViewGroup implements DropTarget, DragSource, Drag
} }
public void scrollLeft() { public void scrollLeft() {
mVacantCache = null; clearVacantCache();
if (mNextScreen == INVALID_SCREEN && mCurrentScreen > 0 && mScroller.isFinished()) { if (mNextScreen == INVALID_SCREEN && mCurrentScreen > 0 && mScroller.isFinished()) {
snapToScreen(mCurrentScreen - 1); snapToScreen(mCurrentScreen - 1);
} }
} }
public void scrollRight() { public void scrollRight() {
mVacantCache = null; clearVacantCache();
if (mNextScreen == INVALID_SCREEN && mCurrentScreen < getChildCount() -1 && if (mNextScreen == INVALID_SCREEN && mCurrentScreen < getChildCount() -1 &&
mScroller.isFinished()) { mScroller.isFinished()) {
snapToScreen(mCurrentScreen + 1); snapToScreen(mCurrentScreen + 1);
@ -1269,10 +1289,6 @@ public class Workspace extends ViewGroup implements DropTarget, DragSource, Drag
} }
} }
// TODO: remove widgets when appwidgetmanager tells us they're gone
// void removeAppWidgetsForProvider() {
// }
void moveToDefaultScreen() { void moveToDefaultScreen() {
snapToScreen(mDefaultScreen); snapToScreen(mDefaultScreen);
getChildAt(mDefaultScreen).requestFocus(); getChildAt(mDefaultScreen).requestFocus();