diff options
author | Winson Chung <winsonc@google.com> | 2011-07-01 15:35:26 -0700 |
---|---|---|
committer | Winson Chung <winsonc@google.com> | 2011-07-06 20:48:45 -0700 |
commit | c07918d0053fc7d2a19d7b013565a5d2e7d4af51 (patch) | |
tree | 1fe589183691f04dcc6d2a280e283d49faa6f6e7 /src/com/android/launcher2/Workspace.java | |
parent | d044526d82e7938cf35b296978d9d5302f98b4af (diff) | |
download | android_packages_apps_Trebuchet-c07918d0053fc7d2a19d7b013565a5d2e7d4af51.tar.gz android_packages_apps_Trebuchet-c07918d0053fc7d2a19d7b013565a5d2e7d4af51.tar.bz2 android_packages_apps_Trebuchet-c07918d0053fc7d2a19d7b013565a5d2e7d4af51.zip |
Cleaning up some spring-loaded related dragging code. Allow cancel spring loaded mode.
Change-Id: Ie1f0468c563bed7abc1aa6416e222cdb0853c03a
Diffstat (limited to 'src/com/android/launcher2/Workspace.java')
-rw-r--r-- | src/com/android/launcher2/Workspace.java | 334 |
1 files changed, 162 insertions, 172 deletions
diff --git a/src/com/android/launcher2/Workspace.java b/src/com/android/launcher2/Workspace.java index 88405c7ea..caf62b49e 100644 --- a/src/com/android/launcher2/Workspace.java +++ b/src/com/android/launcher2/Workspace.java @@ -198,10 +198,6 @@ public class Workspace extends SmoothPagedView // info about the last drag private DragView mLastDragView; - private int mLastDragOriginX; - private int mLastDragOriginY; - private int mLastDragXOffset; - private int mLastDragYOffset; // Variables relating to the creation of user folders by hovering shortcuts over shortcuts private static final int FOLDER_CREATION_TIMEOUT = 250; @@ -330,13 +326,6 @@ public class Workspace extends SmoothPagedView public void onAnimationEnd(Animator animation) { mIsInUnshrinkAnimation = false; mSyncWallpaperOffsetWithScroll = true; - if (mShrinkState == ShrinkState.SPRING_LOADED) { - View layout = null; - if (mLastDragView != null) { - layout = findMatchingPageForDragOver(mLastDragView, mLastDragOriginX, - mLastDragOriginY, mLastDragXOffset, mLastDragYOffset); - } - } mWallpaperOffset.setOverrideHorizontalCatchupConstant(false); mAnimator = null; enableChildrenLayers(false); @@ -1157,11 +1146,9 @@ public class Workspace extends SmoothPagedView } else { super.dispatchDraw(canvas); - final int width = getWidth(); - final int height = getHeight(); - - // In portrait orientation, draw the glowing edge when dragging to adjacent screens - if (mInScrollArea && (height > width)) { + if (mInScrollArea && !LauncherApplication.isScreenLarge()) { + final int width = getWidth(); + final int height = getHeight(); final int pageHeight = getChildAt(0).getHeight(); // This determines the height of the glowing edge: 90% of the page height @@ -1629,7 +1616,6 @@ public class Workspace extends SmoothPagedView // we call this method whenever a drag and drop in Launcher finishes, even if Workspace was // never dragged over public void onDragStopped(boolean success) { - mLastDragView = null; // In the success case, DragController has already called onDragExit() if (!success) { doDragExit(null); @@ -1657,18 +1643,10 @@ public class Workspace extends SmoothPagedView public void enterSpringLoadedDragMode(CellLayout clThatWasClicked) { mShrinkState = ShrinkState.SPRING_LOADED; unshrink(clThatWasClicked, true); - mDragTargetLayout = getCurrentDropLayout(); - mDragTargetLayout.onDragEnter(); - mDragTargetLayout.setIsDragOverlapping(true); - showOutlines(); } public void exitSpringLoadedDragMode(ShrinkState shrinkState) { shrink(shrinkState); - if (mDragTargetLayout != null) { - mDragTargetLayout.onDragExit(); - mDragTargetLayout = null; - } } public void exitWidgetResizeMode() { @@ -2323,24 +2301,45 @@ public class Workspace extends SmoothPagedView } public void onDragEnter(DragObject d) { - mLastDragOverView = null; if (mDragTargetLayout != null) { + mDragTargetLayout.setIsDragOverlapping(false); mDragTargetLayout.onDragExit(); - mDragTargetLayout = null; // Reset the drag state } + mDragTargetLayout = getCurrentDropLayout(); + mDragTargetLayout.setIsDragOverlapping(true); + mDragTargetLayout.onDragEnter(); + mLastDragView = d.dragView; - if (!mIsSmall) { - mDragTargetLayout = getCurrentDropLayout(); - mDragTargetLayout.onDragEnter(); + // Because we don't have space in the Phone UI (the CellLayouts run to the edge) we + // don't need to show the outlines + if (LauncherApplication.isScreenLarge()) { + showOutlines(); + } + } - // Because we don't have space in the Phone UI (the CellLayouts run to the edge) we - // don't need to show the outlines - if (!LauncherApplication.isScreenLarge()) { - showOutlines(); - } + private void doDragExit(DragObject d) { + // Clean up folders + cleanupFolderCreation(d); + + // Reset the scroll area and previous drag target + onResetScrollArea(); + + if (mDragTargetLayout != null) { + mDragTargetLayout.setIsDragOverlapping(false); + mDragTargetLayout.onDragExit(); + } + mLastDragView = null; + mLastDragOverView = null; + + if (!mIsPageMoving) { + hideOutlines(); } } + public void onDragExit(DragObject d) { + doDragExit(d); + } + public DropTarget getDropTargetDelegate(DragObject d) { return null; } @@ -2577,6 +2576,10 @@ public class Workspace extends SmoothPagedView */ private CellLayout findMatchingPageForDragOver( DragView dragView, int originX, int originY, int offsetX, int offsetY) { + return findMatchingPageForDragOver(dragView, originX, originY, offsetX, offsetY, false); + } + private CellLayout findMatchingPageForDragOver( + DragView dragView, int originX, int originY, int offsetX, int offsetY, boolean exact) { // We loop through all the screens (ie CellLayouts) and see which ones overlap // with the item being dragged and then choose the one that's closest to the touch point final int screenCount = getChildCount(); @@ -2600,7 +2603,7 @@ public class Workspace extends SmoothPagedView return cl; } - if (overlaps(cl, dragView, originX, originY, mTempInverseMatrix)) { + if (!exact && overlaps(cl, dragView, originX, originY, mTempInverseMatrix)) { // Get the center of the cell layout in screen coordinates final float[] cellLayoutCenter = mTempCellLayoutCenterCoordinates; cellLayoutCenter[0] = cl.getWidth()/2; @@ -2656,114 +2659,115 @@ public class Workspace extends SmoothPagedView } public void onDragOver(DragObject d) { - // When touch is inside the scroll area, skip dragOver actions for the current screen - if (!mInScrollArea) { - CellLayout layout; + // Skip drag over events while we are dragging over side pages + if (mInScrollArea) return; + if (mIsInUnshrinkAnimation) return; + + CellLayout layout; + ItemInfo item = (ItemInfo) d.dragInfo; + + // Ensure that we have proper spans for the item that we are dropping + if (item.spanX < 0 || item.spanY < 0) throw new RuntimeException("Improper spans found"); + + // Identify whether we have dragged over a side page + if (mIsSmall) { int left = d.x - d.xOffset; int top = d.y - d.yOffset; + layout = findMatchingPageForDragOver(d.dragView, left, top, d.xOffset, d.yOffset, true); + if (layout != mDragTargetLayout) { + // Cancel all intermediate folder states + cleanupFolderCreation(d); - mDragViewVisualCenter = getDragViewVisualCenter(d.x, d.y, d.xOffset, d.yOffset, - d.dragView, mDragViewVisualCenter); + if (mDragTargetLayout != null) { + mDragTargetLayout.setIsDragOverlapping(false); + mDragTargetLayout.onDragExit(); + } + mDragTargetLayout = layout; + if (mDragTargetLayout != null) { + mDragTargetLayout.setIsDragOverlapping(true); + mDragTargetLayout.onDragEnter(); + } else { + mLastDragOverView = null; + } - boolean shrunken = mIsSmall || mIsInUnshrinkAnimation; - if (shrunken) { - mLastDragView = d.dragView; - mLastDragOriginX = left; - mLastDragOriginY = top; - mLastDragXOffset = d.xOffset; - mLastDragYOffset = d.yOffset; - layout = findMatchingPageForDragOver(d.dragView, left, top, d.xOffset, d.yOffset); - - if (layout != null && layout != mDragTargetLayout) { - if (mDragTargetLayout != null) { - mDragTargetLayout.setIsDragOverlapping(false); - mDragTargetLayout.clearDragOutlines(); - } - mDragTargetLayout = layout; - - // In spring-loaded mode, we still want the user to be able to hover over a - // full screen (which is traditionally set to not accept drops) if they want - // to get to pages beyond the screen that is full. - boolean isInSpringLoadedMode = (mShrinkState == ShrinkState.SPRING_LOADED); - boolean allowDragOver = (mDragTargetLayout != null); - if (allowDragOver) { - if (isInSpringLoadedMode) { - mSpringLoadedDragController.setAlarm(mDragTargetLayout); - } - mDragTargetLayout.setIsDragOverlapping(true); - } + boolean isInSpringLoadedMode = (mShrinkState == ShrinkState.SPRING_LOADED); + if (isInSpringLoadedMode) { + mSpringLoadedDragController.setAlarm(mDragTargetLayout); } - } else { - layout = getCurrentDropLayout(); - if (layout != mDragTargetLayout) { - if (mDragTargetLayout != null) { - mDragTargetLayout.onDragExit(); - } - layout.onDragEnter(); - mDragTargetLayout = layout; + } + } else { + layout = getCurrentDropLayout(); + if (layout != mDragTargetLayout) { + if (mDragTargetLayout != null) { + mDragTargetLayout.setIsDragOverlapping(false); + mDragTargetLayout.onDragExit(); } + mDragTargetLayout = layout; + mDragTargetLayout.setIsDragOverlapping(true); + mDragTargetLayout.onDragEnter(); } - if (!shrunken || mShrinkState == ShrinkState.SPRING_LOADED) { - layout = getCurrentDropLayout(); + } - final ItemInfo item = (ItemInfo) d.dragInfo; - if (d.dragInfo instanceof LauncherAppWidgetInfo) { - LauncherAppWidgetInfo widgetInfo = (LauncherAppWidgetInfo) d.dragInfo; + // Handle the drag over + if (mDragTargetLayout != null) { + final View child = (mDragInfo == null) ? null : mDragInfo.cell; - if (widgetInfo.spanX == -1) { - // Calculate the grid spans needed to fit this widget - int[] spans = layout.rectToCell(widgetInfo.minWidth, - widgetInfo.minHeight, null); - item.spanX = spans[0]; - item.spanY = spans[1]; - } - } + mDragViewVisualCenter = getDragViewVisualCenter(d.x, d.y, d.xOffset, d.yOffset, + d.dragView, mDragViewVisualCenter); - if (mDragTargetLayout != null) { - final View child = (mDragInfo == null) ? null : mDragInfo.cell; - // We want the point to be mapped to the dragTarget. - mapPointFromSelfToChild(mDragTargetLayout, mDragViewVisualCenter, null); - ItemInfo info = (ItemInfo) d.dragInfo; - - mTargetCell = findNearestArea((int) mDragViewVisualCenter[0], - (int) mDragViewVisualCenter[1], 1, 1, mDragTargetLayout, mTargetCell); - final View dragOverView = mDragTargetLayout.getChildAt(mTargetCell[0], - mTargetCell[1]); - - boolean userFolderPending = willCreateUserFolder(info, mDragTargetLayout, - mTargetCell, false); - boolean isOverFolder = dragOverView instanceof FolderIcon; - if (dragOverView != mLastDragOverView) { - cancelFolderCreation(); - if (mLastDragOverView != null && mLastDragOverView instanceof FolderIcon) { - ((FolderIcon) mLastDragOverView).onDragExit(d.dragInfo); - } - } + // We want the point to be mapped to the dragTarget. + mapPointFromSelfToChild(mDragTargetLayout, mDragViewVisualCenter, null); + ItemInfo info = (ItemInfo) d.dragInfo; - if (userFolderPending && dragOverView != mLastDragOverView) { - mFolderCreationAlarm.setOnAlarmListener(new - FolderCreationAlarmListener(mDragTargetLayout, mTargetCell[0], mTargetCell[1])); - mFolderCreationAlarm.setAlarm(FOLDER_CREATION_TIMEOUT); - } + mTargetCell = findNearestArea((int) mDragViewVisualCenter[0], + (int) mDragViewVisualCenter[1], 1, 1, mDragTargetLayout, mTargetCell); + final View dragOverView = mDragTargetLayout.getChildAt(mTargetCell[0], + mTargetCell[1]); + + boolean userFolderPending = willCreateUserFolder(info, mDragTargetLayout, + mTargetCell, false); + boolean isOverFolder = dragOverView instanceof FolderIcon; + if (dragOverView != mLastDragOverView) { + cancelFolderCreation(); + if (mLastDragOverView != null && mLastDragOverView instanceof FolderIcon) { + ((FolderIcon) mLastDragOverView).onDragExit(d.dragInfo); + } + } - if (dragOverView != mLastDragOverView && isOverFolder) { - ((FolderIcon) dragOverView).onDragEnter(d.dragInfo); - if (mDragTargetLayout != null) { - mDragTargetLayout.clearDragOutlines(); - } - } - mLastDragOverView = dragOverView; + if (userFolderPending && dragOverView != mLastDragOverView) { + mFolderCreationAlarm.setOnAlarmListener(new + FolderCreationAlarmListener(mDragTargetLayout, mTargetCell[0], mTargetCell[1])); + mFolderCreationAlarm.setAlarm(FOLDER_CREATION_TIMEOUT); + } - if (!mCreateUserFolderOnDrop && !isOverFolder) { - mDragTargetLayout.visualizeDropLocation(child, mDragOutline, - (int) mDragViewVisualCenter[0], (int) mDragViewVisualCenter[1], - item.spanX, item.spanY); - } + if (dragOverView != mLastDragOverView && isOverFolder) { + ((FolderIcon) dragOverView).onDragEnter(d.dragInfo); + if (mDragTargetLayout != null) { + mDragTargetLayout.clearDragOutlines(); } } + mLastDragOverView = dragOverView; + + if (!mCreateUserFolderOnDrop && !isOverFolder) { + mDragTargetLayout.visualizeDropLocation(child, mDragOutline, + (int) mDragViewVisualCenter[0], (int) mDragViewVisualCenter[1], + item.spanX, item.spanY); + } } } + private void cleanupFolderCreation(DragObject d) { + if (mDragFolderRingAnimator != null && mCreateUserFolderOnDrop) { + mDragFolderRingAnimator.animateToNaturalState(); + } + if (mLastDragOverView != null && mLastDragOverView instanceof FolderIcon) { + if (d != null) { + ((FolderIcon) mLastDragOverView).onDragExit(d.dragInfo); + } + } + mFolderCreationAlarm.cancelAlarm(); + } + private void cancelFolderCreation() { if (mDragFolderRingAnimator != null && mCreateUserFolderOnDrop) { mDragFolderRingAnimator.animateToNaturalState(); @@ -2796,30 +2800,6 @@ public class Workspace extends SmoothPagedView } } - private void doDragExit(DragObject d) { - if (mDragFolderRingAnimator != null && mCreateUserFolderOnDrop) { - mDragFolderRingAnimator.animateToNaturalState(); - } - if (mLastDragOverView != null && mLastDragOverView instanceof FolderIcon) { - if (d != null) { - ((FolderIcon) mLastDragOverView).onDragExit(d.dragInfo); - } - } - mFolderCreationAlarm.cancelAlarm(); - - if (mDragTargetLayout != null) { - mDragTargetLayout.onDragExit(); - } - if (!mIsPageMoving) { - hideOutlines(); - } - clearAllHovers(); - } - - public void onDragExit(DragObject d) { - doDragExit(d); - } - @Override public void getHitRect(Rect outRect) { // We want the workspace to have the whole area of the display (it will find the correct @@ -3056,40 +3036,50 @@ public class Workspace extends SmoothPagedView cancelFolderCreation(); if (layout != null) { - layout.setIsDragOverlapping(true); - + // Exit the current layout and mark the overlapping layout if (mDragTargetLayout != null) { + mDragTargetLayout.setIsDragOverlapping(false); mDragTargetLayout.onDragExit(); - mDragTargetLayout = layout; } - // In portrait, need to redraw the edge glow when entering the scroll area - if (getHeight() > getWidth()) { - invalidate(); - } - } - } - } - - private void clearAllHovers() { - final int childCount = getChildCount(); - for (int i = 0; i < childCount; i++) { - ((CellLayout) getChildAt(i)).setIsDragOverlapping(false); - } + mDragTargetLayout = layout; + mDragTargetLayout.setIsDragOverlapping(true); - // In portrait, workspace is responsible for drawing the edge glow on adjacent pages, - // so we need to redraw the workspace when this may have changed. - if (getHeight() > getWidth()) { - invalidate(); + // Workspace is responsible for drawing the edge glow on adjacent pages, + // so we need to redraw the workspace when this may have changed. + invalidate(); + } } } @Override public void onExitScrollArea() { if (mInScrollArea) { - mInScrollArea = false; + if (mDragTargetLayout != null) { + // Unmark the overlapping layout and re-enter the current layout + mDragTargetLayout.setIsDragOverlapping(false); + mDragTargetLayout = getCurrentDropLayout(); + mDragTargetLayout.onDragEnter(); + + // Workspace is responsible for drawing the edge glow on adjacent pages, + // so we need to redraw the workspace when this may have changed. + invalidate(); + } mPendingScrollDirection = DragController.SCROLL_NONE; - clearAllHovers(); + mInScrollArea = false; + } + } + + private void onResetScrollArea() { + if (mDragTargetLayout != null) { + // Unmark the overlapping layout + mDragTargetLayout.setIsDragOverlapping(false); + + // Workspace is responsible for drawing the edge glow on adjacent pages, + // so we need to redraw the workspace when this may have changed. + invalidate(); } + mPendingScrollDirection = DragController.SCROLL_NONE; + mInScrollArea = false; } public Folder getFolderForTag(Object tag) { |