3185132: Allow dropping on adjacent homescreen targets
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 @@
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 @@
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 @@
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 @@
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 @@
// 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 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 void onExitScrollArea() {
if (mInScrollArea) {
mInScrollArea = false;
+ mPendingScrollDirection = DragController.SCROLL_NONE;
clearAllHovers();
}
}