diff options
author | Patrick Dubroy <dubroy@google.com> | 2010-09-27 11:15:43 -0700 |
---|---|---|
committer | Patrick Dubroy <dubroy@google.com> | 2010-09-29 11:14:28 -0700 |
commit | de7658b5e02ae10010e44fcf8d9c5814f54d9eb0 (patch) | |
tree | 211fe8fc0219dbf99f883138fd2df57d06a5aab7 /src/com/android/launcher2/DragController.java | |
parent | 5c1f9f1de66cef31ba646b7e9ec7ae5634ca3691 (diff) | |
download | android_packages_apps_Trebuchet-de7658b5e02ae10010e44fcf8d9c5814f54d9eb0.tar.gz android_packages_apps_Trebuchet-de7658b5e02ae10010e44fcf8d9c5814f54d9eb0.tar.bz2 android_packages_apps_Trebuchet-de7658b5e02ae10010e44fcf8d9c5814f54d9eb0.zip |
Show crosshairs when dragging items around the workspace.
Diffstat (limited to 'src/com/android/launcher2/DragController.java')
-rw-r--r-- | src/com/android/launcher2/DragController.java | 126 |
1 files changed, 62 insertions, 64 deletions
diff --git a/src/com/android/launcher2/DragController.java b/src/com/android/launcher2/DragController.java index 87b3473a1..185f704e2 100644 --- a/src/com/android/launcher2/DragController.java +++ b/src/com/android/launcher2/DragController.java @@ -18,7 +18,6 @@ package com.android.launcher2; import android.content.Context; import android.graphics.Bitmap; -import android.graphics.Canvas; import android.graphics.Rect; import android.graphics.RectF; import android.os.Handler; @@ -311,6 +310,8 @@ public class DragController { } dragView.show(mWindowToken, (int)mMotionDownX, (int)mMotionDownY); + + handleMoveEvent((int) mMotionDownX, (int) mMotionDownY); } /** @@ -437,12 +438,68 @@ public class DragController { return mMoveTarget != null && mMoveTarget.dispatchUnhandledMove(focused, direction); } + private void handleMoveEvent(int x, int y) { + mDragView.move(x, y); + + // Drop on someone? + final int[] coordinates = mCoordinatesTemp; + DropTarget dropTarget = findDropTarget(x, y, coordinates); + if (dropTarget != null) { + DropTarget delegate = dropTarget.getDropTargetDelegate( + mDragSource, coordinates[0], coordinates[1], + (int) mTouchOffsetX, (int) mTouchOffsetY, mDragView, mDragInfo); + if (delegate != null) { + dropTarget = delegate; + } + + if (mLastDropTarget != dropTarget) { + if (mLastDropTarget != null) { + mLastDropTarget.onDragExit(mDragSource, coordinates[0], coordinates[1], + (int) mTouchOffsetX, (int) mTouchOffsetY, mDragView, mDragInfo); + } + dropTarget.onDragEnter(mDragSource, coordinates[0], coordinates[1], + (int) mTouchOffsetX, (int) mTouchOffsetY, mDragView, mDragInfo); + } + dropTarget.onDragOver(mDragSource, coordinates[0], coordinates[1], + (int) mTouchOffsetX, (int) mTouchOffsetY, mDragView, mDragInfo); + } else { + if (mLastDropTarget != null) { + mLastDropTarget.onDragExit(mDragSource, coordinates[0], coordinates[1], + (int) mTouchOffsetX, (int) mTouchOffsetY, mDragView, mDragInfo); + } + } + mLastDropTarget = dropTarget; + + // Scroll, maybe, but not if we're in the delete region. + boolean inDeleteRegion = false; + if (mDeleteRegion != null) { + inDeleteRegion = mDeleteRegion.contains(x, y); + } + if (!inDeleteRegion && x < SCROLL_ZONE) { + if (mScrollState == SCROLL_OUTSIDE_ZONE) { + mScrollState = SCROLL_WAITING_IN_ZONE; + mScrollRunnable.setDirection(SCROLL_LEFT); + mHandler.postDelayed(mScrollRunnable, SCROLL_DELAY); + } + } else if (!inDeleteRegion && x > mScrollView.getWidth() - SCROLL_ZONE) { + if (mScrollState == SCROLL_OUTSIDE_ZONE) { + mScrollState = SCROLL_WAITING_IN_ZONE; + mScrollRunnable.setDirection(SCROLL_RIGHT); + mHandler.postDelayed(mScrollRunnable, SCROLL_DELAY); + } + } else { + if (mScrollState == SCROLL_WAITING_IN_ZONE) { + mScrollState = SCROLL_OUTSIDE_ZONE; + mScrollRunnable.setDirection(SCROLL_RIGHT); + mHandler.removeCallbacks(mScrollRunnable); + } + } + } + /** * Call this from a drag source view. */ public boolean onTouchEvent(MotionEvent ev) { - View scrollView = mScrollView; - if (!mDragging) { return false; } @@ -457,74 +514,15 @@ public class DragController { mMotionDownX = screenX; mMotionDownY = screenY; - if ((screenX < SCROLL_ZONE) || (screenX > scrollView.getWidth() - SCROLL_ZONE)) { + if ((screenX < SCROLL_ZONE) || (screenX > mScrollView.getWidth() - SCROLL_ZONE)) { mScrollState = SCROLL_WAITING_IN_ZONE; mHandler.postDelayed(mScrollRunnable, SCROLL_DELAY); } else { mScrollState = SCROLL_OUTSIDE_ZONE; } - break; case MotionEvent.ACTION_MOVE: - // Update the drag view. Don't use the clamped pos here so the dragging looks - // like it goes off screen a little, intead of bumping up against the edge. - mDragView.move((int)ev.getRawX(), (int)ev.getRawY()); - - // Drop on someone? - final int[] coordinates = mCoordinatesTemp; - DropTarget dropTarget = findDropTarget(screenX, screenY, coordinates); - if (dropTarget != null) { - DropTarget delegate = dropTarget.getDropTargetDelegate( - mDragSource, coordinates[0], coordinates[1], - (int) mTouchOffsetX, (int) mTouchOffsetY, mDragView, mDragInfo); - if (delegate != null) { - dropTarget = delegate; - } - - if (mLastDropTarget == dropTarget) { - dropTarget.onDragOver(mDragSource, coordinates[0], coordinates[1], - (int) mTouchOffsetX, (int) mTouchOffsetY, mDragView, mDragInfo); - } else { - if (mLastDropTarget != null) { - mLastDropTarget.onDragExit(mDragSource, coordinates[0], coordinates[1], - (int) mTouchOffsetX, (int) mTouchOffsetY, mDragView, mDragInfo); - } - dropTarget.onDragEnter(mDragSource, coordinates[0], coordinates[1], - (int) mTouchOffsetX, (int) mTouchOffsetY, mDragView, mDragInfo); - } - } else { - if (mLastDropTarget != null) { - mLastDropTarget.onDragExit(mDragSource, coordinates[0], coordinates[1], - (int) mTouchOffsetX, (int) mTouchOffsetY, mDragView, mDragInfo); - } - } - mLastDropTarget = dropTarget; - - // Scroll, maybe, but not if we're in the delete region. - boolean inDeleteRegion = false; - if (mDeleteRegion != null) { - inDeleteRegion = mDeleteRegion.contains(screenX, screenY); - } - if (!inDeleteRegion && screenX < SCROLL_ZONE) { - if (mScrollState == SCROLL_OUTSIDE_ZONE) { - mScrollState = SCROLL_WAITING_IN_ZONE; - mScrollRunnable.setDirection(SCROLL_LEFT); - mHandler.postDelayed(mScrollRunnable, SCROLL_DELAY); - } - } else if (!inDeleteRegion && screenX > scrollView.getWidth() - SCROLL_ZONE) { - if (mScrollState == SCROLL_OUTSIDE_ZONE) { - mScrollState = SCROLL_WAITING_IN_ZONE; - mScrollRunnable.setDirection(SCROLL_RIGHT); - mHandler.postDelayed(mScrollRunnable, SCROLL_DELAY); - } - } else { - if (mScrollState == SCROLL_WAITING_IN_ZONE) { - mScrollState = SCROLL_OUTSIDE_ZONE; - mScrollRunnable.setDirection(SCROLL_RIGHT); - mHandler.removeCallbacks(mScrollRunnable); - } - } - + handleMoveEvent(screenX, screenY); break; case MotionEvent.ACTION_UP: mHandler.removeCallbacks(mScrollRunnable); |