diff options
author | Patrick Dubroy <dubroy@google.com> | 2010-11-17 12:18:45 -0800 |
---|---|---|
committer | Patrick Dubroy <dubroy@google.com> | 2010-11-17 13:41:37 -0800 |
commit | 54fa3b95557c283976e8c1aa8a157b460b0b4513 (patch) | |
tree | 9e6f95bfeb2bef7051be5c706ff427c30c05ea59 | |
parent | 82a556e82340c58c1e2e132893af549506032578 (diff) | |
download | packages_apps_trebuchet-54fa3b95557c283976e8c1aa8a157b460b0b4513.zip packages_apps_trebuchet-54fa3b95557c283976e8c1aa8a157b460b0b4513.tar.gz packages_apps_trebuchet-54fa3b95557c283976e8c1aa8a157b460b0b4513.tar.bz2 |
3185132: Allow dropping on adjacent homescreen targets
-rw-r--r-- | src/com/android/launcher2/DragController.java | 1 | ||||
-rw-r--r-- | src/com/android/launcher2/SmoothPagedView.java | 2 | ||||
-rw-r--r-- | src/com/android/launcher2/Workspace.java | 47 |
3 files changed, 39 insertions, 11 deletions
diff --git a/src/com/android/launcher2/DragController.java b/src/com/android/launcher2/DragController.java index 272bf8b..2b566b7 100644 --- a/src/com/android/launcher2/DragController.java +++ b/src/com/android/launcher2/DragController.java @@ -57,6 +57,7 @@ public class DragController { private static final int SCROLL_OUTSIDE_ZONE = 0; private static final int SCROLL_WAITING_IN_ZONE = 1; + static final int SCROLL_NONE = -1; static final int SCROLL_LEFT = 0; static final int SCROLL_RIGHT = 1; diff --git a/src/com/android/launcher2/SmoothPagedView.java b/src/com/android/launcher2/SmoothPagedView.java index 56037ff..8e729e4 100644 --- a/src/com/android/launcher2/SmoothPagedView.java +++ b/src/com/android/launcher2/SmoothPagedView.java @@ -131,7 +131,7 @@ public abstract class SmoothPagedView extends PagedView { snapToPageWithVelocity(whichPage, 0, true); } - void snapToPageWithVelocity(int whichPage, int velocity, boolean settle) { + private void snapToPageWithVelocity(int whichPage, int velocity, boolean settle) { // if (!mScroller.isFinished()) return; whichPage = Math.max(0, Math.min(whichPage, getChildCount() - 1)); diff --git a/src/com/android/launcher2/Workspace.java b/src/com/android/launcher2/Workspace.java index b5b0c56..169f53f 100644 --- a/src/com/android/launcher2/Workspace.java +++ b/src/com/android/launcher2/Workspace.java @@ -155,8 +155,14 @@ public class Workspace extends SmoothPagedView private ShrinkPosition mWaitingToShrinkPosition; private AnimatorSet mAnimator; + /** Is the user is dragging an item near the edge of a page? */ private boolean mInScrollArea = false; + /** If mInScrollArea is true, the direction of the scroll. */ + private int mPendingScrollDirection = DragController.SCROLL_NONE; + + private boolean mInDragMode = false; + private final HolographicOutlineHelper mOutlineHelper = new HolographicOutlineHelper(); private Bitmap mDragOutline = null; private final Rect mTempRect = new Rect(); @@ -1423,16 +1429,32 @@ public class Workspace extends SmoothPagedView onDropExternal(originX, originY, dragInfo, mDragTargetLayout); } else if (mDragInfo != null) { final View cell = mDragInfo.cell; - if (mDragTargetLayout != null) { + CellLayout dropTargetLayout = mDragTargetLayout; + + // Handle the case where the user drops when in the scroll area. + // This is treated as a drop on the adjacent page. + if (dropTargetLayout == null && mInScrollArea) { + if (mPendingScrollDirection == DragController.SCROLL_LEFT) { + dropTargetLayout = (CellLayout) getChildAt(mCurrentPage - 1); + } else if (mPendingScrollDirection == DragController.SCROLL_RIGHT) { + dropTargetLayout = (CellLayout) getChildAt(mCurrentPage + 1); + } + } + + if (dropTargetLayout != null) { // Move internally mTargetCell = findNearestVacantArea(originX, originY, - mDragInfo.spanX, mDragInfo.spanY, cell, mDragTargetLayout, + mDragInfo.spanX, mDragInfo.spanY, cell, dropTargetLayout, mTargetCell); - if (mTargetCell == null) { - snapToPage(mDragInfo.screen); - } else { - int screen = indexOfChild(mDragTargetLayout); + final int screen = (mTargetCell == null) ? + mDragInfo.screen : indexOfChild(dropTargetLayout); + + if (screen != mCurrentPage) { + snapToPage(screen); + } + + if (mTargetCell != null) { if (screen != mDragInfo.screen) { // Reparent the view ((CellLayout) getChildAt(mDragInfo.screen)).removeView(cell); @@ -1443,7 +1465,7 @@ public class Workspace extends SmoothPagedView // update the item's position after drop final ItemInfo info = (ItemInfo) cell.getTag(); CellLayout.LayoutParams lp = (CellLayout.LayoutParams) cell.getLayoutParams(); - mDragTargetLayout.onMove(cell, mTargetCell[0], mTargetCell[1]); + dropTargetLayout.onMove(cell, mTargetCell[0], mTargetCell[1]); lp.cellX = mTargetCell[0]; lp.cellY = mTargetCell[1]; cell.setId(LauncherModel.getCellLayoutChildId(-1, mDragInfo.screen, @@ -2079,9 +2101,13 @@ public class Workspace extends SmoothPagedView public void onEnterScrollArea(int direction) { if (!mIsSmall && !mIsInUnshrinkAnimation) { mInScrollArea = true; - final int screen = getCurrentPage() + ((direction == DragController.SCROLL_LEFT) ? -1 : 1); - if (0 <= screen && screen < getChildCount()) { - ((CellLayout) getChildAt(screen)).setHover(true); + mPendingScrollDirection = direction; + + final int page = mCurrentPage + (direction == DragController.SCROLL_LEFT ? -1 : 1); + final CellLayout layout = (CellLayout) getChildAt(page); + + if (layout != null) { + layout.setHover(true); if (mDragTargetLayout != null) { mDragTargetLayout.onDragExit(); @@ -2102,6 +2128,7 @@ public class Workspace extends SmoothPagedView public void onExitScrollArea() { if (mInScrollArea) { mInScrollArea = false; + mPendingScrollDirection = DragController.SCROLL_NONE; clearAllHovers(); } } |