diff options
Diffstat (limited to 'src/com/android/launcher3/Workspace.java')
-rw-r--r-- | src/com/android/launcher3/Workspace.java | 338 |
1 files changed, 127 insertions, 211 deletions
diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java index 71df12d8e..778bff7b6 100644 --- a/src/com/android/launcher3/Workspace.java +++ b/src/com/android/launcher3/Workspace.java @@ -28,12 +28,10 @@ import android.appwidget.AppWidgetHostView; import android.appwidget.AppWidgetProviderInfo; import android.content.ComponentName; import android.content.Context; -import android.content.SharedPreferences; import android.content.res.Resources; import android.content.res.TypedArray; import android.graphics.Bitmap; import android.graphics.Canvas; -import android.graphics.Matrix; import android.graphics.Paint; import android.graphics.Point; import android.graphics.PointF; @@ -50,7 +48,6 @@ import android.util.AttributeSet; import android.util.Log; import android.util.SparseArray; import android.view.Choreographer; -import android.view.Display; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; @@ -68,6 +65,12 @@ import com.android.launcher3.accessibility.LauncherAccessibilityDelegate; import com.android.launcher3.accessibility.LauncherAccessibilityDelegate.AccessibilityDragSource; import com.android.launcher3.accessibility.OverviewScreenAccessibilityDelegate; import com.android.launcher3.compat.UserHandleCompat; +import com.android.launcher3.config.ProviderConfig; +import com.android.launcher3.dragndrop.DragController; +import com.android.launcher3.dragndrop.DragLayer; +import com.android.launcher3.dragndrop.DragScroller; +import com.android.launcher3.dragndrop.DragView; +import com.android.launcher3.dragndrop.SpringLoadedDragController; import com.android.launcher3.util.LongArrayMap; import com.android.launcher3.util.Thunk; import com.android.launcher3.util.WallpaperUtils; @@ -92,13 +95,17 @@ public class Workspace extends PagedView private static boolean ENFORCE_DRAG_EVENT_ORDER = false; - protected static final int SNAP_OFF_EMPTY_SCREEN_DURATION = 400; - protected static final int FADE_EMPTY_SCREEN_DURATION = 150; + private static final int SNAP_OFF_EMPTY_SCREEN_DURATION = 400; + private static final int FADE_EMPTY_SCREEN_DURATION = 150; private static final int ADJACENT_SCREEN_DROP_DURATION = 300; - static final boolean MAP_NO_RECURSE = false; - static final boolean MAP_RECURSE = true; + private static final boolean MAP_NO_RECURSE = false; + private static final boolean MAP_RECURSE = true; + + // The screen id used for the empty screen always present to the right. + public final static long EXTRA_EMPTY_SCREEN_ID = -201; + private final static long CUSTOM_CONTENT_SCREEN_ID = -301; private static final long CUSTOM_CONTENT_GESTURE_DELAY = 200; private long mTouchDownTime = -1; @@ -113,10 +120,6 @@ public class Workspace extends PagedView private ShortcutAndWidgetContainer mDragSourceInternal; - // The screen id used for the empty screen always present to the right. - final static long EXTRA_EMPTY_SCREEN_ID = -201; - private final static long CUSTOM_CONTENT_SCREEN_ID = -301; - @Thunk LongArrayMap<CellLayout> mWorkspaceScreens = new LongArrayMap<>(); @Thunk ArrayList<Long> mScreenOrder = new ArrayList<Long>(); @@ -136,9 +139,6 @@ public class Workspace extends PagedView private int mDragOverX = -1; private int mDragOverY = -1; - static Rect mLandscapeCellLayoutMetrics = null; - static Rect mPortraitCellLayoutMetrics = null; - CustomContentCallbacks mCustomContentCallbacks; boolean mCustomContentShowing; private float mLastCustomContentScrollProgress = -1f; @@ -164,12 +164,11 @@ public class Workspace extends PagedView // These are temporary variables to prevent having to allocate a new object just to // return an (x, y) value from helper functions. Do NOT use them to maintain other state. - private int[] mTempCell = new int[2]; - private int[] mTempPt = new int[2]; - private int[] mTempEstimate = new int[2]; + private static final Rect sTempRect = new Rect(); + private final int[] mTempXY = new int[2]; @Thunk float[] mDragViewVisualCenter = new float[2]; private float[] mTempCellLayoutCenterCoordinates = new float[2]; - private Matrix mTempInverseMatrix = new Matrix(); + private int[] mTempVisiblePagesRange = new int[2]; private SpringLoadedDragController mSpringLoadedDragController; private float mSpringLoadedShrinkFactor; @@ -200,7 +199,6 @@ public class Workspace extends PagedView private boolean mIsSwitchingState = false; boolean mAnimatingViewIntoPlace = false; - boolean mIsDragOccuring = false; boolean mChildrenLayersEnabled = true; private boolean mStripScreensOnPageStopMoving = false; @@ -210,9 +208,6 @@ public class Workspace extends PagedView private HolographicOutlineHelper mOutlineHelper; @Thunk Bitmap mDragOutline = null; - private static final Rect sTempRect = new Rect(); - private final int[] mTempXY = new int[2]; - private int[] mTempVisiblePagesRange = new int[2]; public static final int DRAG_BITMAP_PADDING = 2; private boolean mWorkspaceFadeInAdjacentScreens; @@ -223,7 +218,6 @@ public class Workspace extends PagedView @Thunk Runnable mDelayedResizeRunnable; private Runnable mDelayedSnapToPageRunnable; - private Point mDisplaySize = new Point(); // Variables relating to the creation of user folders by hovering shortcuts over shortcuts private static final int FOLDER_CREATION_TIMEOUT = 0; @@ -277,19 +271,13 @@ public class Workspace extends PagedView boolean mStartedSendingScrollEvents; boolean mShouldSendPageSettled; int mLastOverlaySroll = 0; + private boolean mForceDrawAdjacentPages = false; // Handles workspace state transitions private WorkspaceStateTransitionAnimation mStateTransitionAnimation; private AccessibilityDelegate mPagesAccessibilityDelegate; - private final Runnable mBindPages = new Runnable() { - @Override - public void run() { - mLauncher.getModel().bindRemainingSynchronousPages(); - } - }; - /** * Used to inflate the Workspace from XML. * @@ -381,12 +369,11 @@ public class Workspace extends PagedView } @Override - public void onDragStart(final DragSource source, Object info, int dragAction) { + public void onDragStart(final DragSource source, ItemInfo info, int dragAction) { if (ENFORCE_DRAG_EVENT_ORDER) { enfoceDragParity("onDragStart", 0, 0); } - mIsDragOccuring = true; updateChildrenLayersEnabled(false); mLauncher.lockScreenOrientation(); mLauncher.onInteractionBegin(); @@ -417,7 +404,6 @@ public class Workspace extends PagedView removeExtraEmptyScreen(true, mDragSourceInternal != null); } - mIsDragOccuring = false; updateChildrenLayersEnabled(false); mLauncher.unlockScreenOrientation(false); @@ -445,8 +431,6 @@ public class Workspace extends PagedView setupLayoutTransition(); mWallpaperOffset = new WallpaperOffsetInterpolator(); - Display display = mLauncher.getWindowManager().getDefaultDisplay(); - display.getSize(mDisplaySize); mMaxDistanceForFolderCreation = (0.55f * grid.iconSizePx); @@ -578,6 +562,7 @@ public class Workspace extends PagedView CellLayout customScreen = (CellLayout) mLauncher.getLayoutInflater().inflate(R.layout.workspace_screen, this, false); customScreen.disableDragTarget(); + customScreen.disableJailContent(); mWorkspaceScreens.put(CUSTOM_CONTENT_SCREEN_ID, customScreen); mScreenOrder.add(0, CUSTOM_CONTENT_SCREEN_ID); @@ -1318,12 +1303,12 @@ public class Workspace extends PagedView protected void setWallpaperDimension() { new AsyncTask<Void, Void, Void>() { public Void doInBackground(Void ... args) { - String spKey = LauncherFiles.WALLPAPER_CROP_PREFERENCES_KEY; - SharedPreferences sp = - mLauncher.getSharedPreferences(spKey, Context.MODE_MULTI_PROCESS); - WallpaperUtils.suggestWallpaperDimension(mLauncher.getResources(), - sp, mLauncher.getWindowManager(), mWallpaperManager, - mLauncher.overrideWallpaperDimensions()); + if (Utilities.ATLEAST_KITKAT) { + WallpaperUtils.suggestWallpaperDimension(mLauncher); + } else { + WallpaperUtils.suggestWallpaperDimensionPreK(mLauncher, + mLauncher.overrideWallpaperDimensions()); + } return null; } }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, (Void) null); @@ -1597,6 +1582,7 @@ public class Workspace extends PagedView setOnClickListener(mLauncher); } mLauncher.getSearchDropTargetBar().enableAccessibleDrag(enable); + mLauncher.getAppInfoDropTargetBar().enableAccessibleDrag(enable); mLauncher.getHotseat().getLayout() .enableAccessibleDrag(enable, CellLayout.WORKSPACE_ACCESSIBILITY_DRAG); } @@ -1727,14 +1713,6 @@ public class Workspace extends PagedView } @Override - protected void onDraw(Canvas canvas) { - super.onDraw(canvas); - - // Call back to LauncherModel to finish binding after the first draw - post(mBindPages); - } - - @Override protected boolean onRequestFocusInDescendants(int direction, Rect previouslyFocusedRect) { if (!mLauncher.isAppsViewVisible()) { final Folder openFolder = getOpenFolder(); @@ -1860,8 +1838,18 @@ public class Workspace extends PagedView updateChildrenLayersEnabled(false); } + @Override + protected void getVisiblePages(int[] range) { + super.getVisiblePages(range); + if (mForceDrawAdjacentPages) { + // In overview mode, make sure that the two side pages are visible. + range[0] = Utilities.boundInRange(getCurrentPage() - 1, numCustomPages(), range[1]); + range[1] = Utilities.boundInRange(getCurrentPage() + 1, range[0], getPageCount() - 1); + } + } + protected void onWallpaperTap(MotionEvent ev) { - final int[] position = mTempCell; + final int[] position = mTempXY; getLocationOnScreen(position); int pointerIndex = ev.getActionIndex(); @@ -1925,6 +1913,18 @@ public class Workspace extends PagedView } public void onDragStartedWithItem(PendingAddItemInfo info, Bitmap b, boolean clipAlpha) { + // Find a page that has enough space to place this widget (after rearranging/resizing). + // Start at the current page and search right (on LTR) until finding a page with enough + // space. Since an empty screen is the furthest right, a page must be found. + int currentPageInOverview = getPageNearestToCenterOfScreen(); + for (int pageIndex = currentPageInOverview; pageIndex < getPageCount(); pageIndex++) { + CellLayout page = (CellLayout) getPageAt(pageIndex); + if (page.hasReorderSolution(info)) { + setCurrentPage(pageIndex); + break; + } + } + int[] size = estimateItemSize(info, false); // The outline is used to visualize where the item will land if dropped @@ -1980,6 +1980,10 @@ public class Workspace extends PagedView return mState == State.OVERVIEW; } + public void snapToPageFromOverView(int whichPage) { + mStateTransitionAnimation.snapToPageFromOverView(whichPage); + } + int getOverviewModeTranslationY() { DeviceProfile grid = mLauncher.getDeviceProfile(); Rect workspacePadding = grid.getWorkspacePadding(Utilities.isRtl(getResources())); @@ -1995,19 +1999,28 @@ public class Workspace extends PagedView return -workspaceOffsetTopEdge + overviewOffsetTopEdge; } + int getSpringLoadedTranslationY() { + return getOverviewModeTranslationY(); + } + /** * Sets the current workspace {@link State}, returning an animation transitioning the workspace * to that new state. */ - public Animator setStateWithAnimation(State toState, int toPage, boolean animated, + public Animator setStateWithAnimation(State toState, boolean animated, HashMap<View, Integer> layerViews) { // Create the animation to the new state Animator workspaceAnim = mStateTransitionAnimation.getAnimationToState(mState, - toState, toPage, animated, layerViews); + toState, animated, layerViews); // Update the current state mState = toState; updateAccessibilityFlags(); + if (mState == State.OVERVIEW || mState == State.SPRING_LOADED) { + // Redraw pages, as we might want to draw pages which were not visible. + mForceDrawAdjacentPages = true; + invalidate(); // This will call dispatchDraw(), which calls getVisiblePages(). + } return workspaceAnim; } @@ -2080,6 +2093,7 @@ public class Workspace extends PagedView mIsSwitchingState = false; updateChildrenLayersEnabled(false); showCustomContentIfNecessary(); + mForceDrawAdjacentPages = false; } void updateCustomContentVisibility() { @@ -2126,19 +2140,17 @@ public class Workspace extends PagedView * @param padding the horizontal and vertical padding to use when drawing */ private static void drawDragView(View v, Canvas destCanvas, int padding) { - final Rect clipRect = sTempRect; - v.getDrawingRect(clipRect); - - boolean textVisible = false; - destCanvas.save(); if (v instanceof TextView) { Drawable d = getTextViewIcon((TextView) v); Rect bounds = getDrawableBounds(d); - clipRect.set(0, 0, bounds.width() + padding, bounds.height() + padding); destCanvas.translate(padding / 2 - bounds.left, padding / 2 - bounds.top); d.draw(destCanvas); } else { + final Rect clipRect = sTempRect; + v.getDrawingRect(clipRect); + + boolean textVisible = false; if (v instanceof FolderIcon) { // For FolderIcons the text can bleed into the icon area, and so we need to // hide the text completely (which can't be achieved by clipping). @@ -2316,7 +2328,8 @@ public class Workspace extends PagedView icon.clearPressedBackground(); } - if (child.getTag() == null || !(child.getTag() instanceof ItemInfo)) { + Object dragObject = child.getTag(); + if (!(dragObject instanceof ItemInfo)) { String msg = "Drag started with a view that has no tag set. This " + "will cause a crash (issue 11627249) down the line. " + "View: " + child + " tag: " + child.getTag(); @@ -2327,11 +2340,14 @@ public class Workspace extends PagedView mDragSourceInternal = (ShortcutAndWidgetContainer) child.getParent(); } - DragView dv = mDragController.startDrag(b, dragLayerX, dragLayerY, source, child.getTag(), - DragController.DRAG_ACTION_MOVE, dragVisualizeOffset, dragRect, scale, accessible); + DragView dv = mDragController.startDrag(b, dragLayerX, dragLayerY, source, + (ItemInfo) dragObject, DragController.DRAG_ACTION_MOVE, dragVisualizeOffset, + dragRect, scale, accessible); dv.setIntrinsicIconScaleFactor(source.getIntrinsicIconScaleFactor()); b.recycle(); + + mLauncher.enterSpringLoadedDragMode(); } public void beginExternalDragShared(View child, DragSource source) { @@ -2364,7 +2380,8 @@ public class Workspace extends PagedView Point dragVisualizeOffset = new Point(-padding.get() / 2, padding.get() / 2); Rect dragRect = new Rect(0, 0, iconSize, iconSize); - if (child.getTag() == null || !(child.getTag() instanceof ItemInfo)) { + Object dragObject = child.getTag(); + if (!(dragObject instanceof ItemInfo)) { String msg = "Drag started with a view that has no tag set. This " + "will cause a crash (issue 11627249) down the line. " + "View: " + child + " tag: " + child.getTag(); @@ -2372,12 +2389,15 @@ public class Workspace extends PagedView } // Start the drag - DragView dv = mDragController.startDrag(b, dragLayerX, dragLayerY, source, child.getTag(), - DragController.DRAG_ACTION_MOVE, dragVisualizeOffset, dragRect, scale, false); + DragView dv = mDragController.startDrag(b, dragLayerX, dragLayerY, source, + (ItemInfo) dragObject, DragController.DRAG_ACTION_MOVE, dragVisualizeOffset, + dragRect, scale, false); dv.setIntrinsicIconScaleFactor(source.getIntrinsicIconScaleFactor()); // Recycle temporary bitmaps tmpB.recycle(); + + mLauncher.enterSpringLoadedDragMode(); } public boolean transitionStateShouldAllowDrop() { @@ -2404,7 +2424,7 @@ public class Workspace extends PagedView if (mLauncher.isHotseatLayout(dropTargetLayout)) { mapPointFromSelfToHotseatLayout(mLauncher.getHotseat(), mDragViewVisualCenter); } else { - mapPointFromSelfToChild(dropTargetLayout, mDragViewVisualCenter, null); + mapPointFromSelfToChild(dropTargetLayout, mDragViewVisualCenter); } int spanX = 1; @@ -2414,9 +2434,8 @@ public class Workspace extends PagedView spanX = dragCellInfo.spanX; spanY = dragCellInfo.spanY; } else { - final ItemInfo dragInfo = (ItemInfo) d.dragInfo; - spanX = dragInfo.spanX; - spanY = dragInfo.spanY; + spanX = d.dragInfo.spanX; + spanY = d.dragInfo.spanY; } int minSpanX = spanX; @@ -2431,12 +2450,12 @@ public class Workspace extends PagedView mTargetCell); float distance = dropTargetLayout.getDistanceFromCell(mDragViewVisualCenter[0], mDragViewVisualCenter[1], mTargetCell); - if (mCreateUserFolderOnDrop && willCreateUserFolder((ItemInfo) d.dragInfo, + if (mCreateUserFolderOnDrop && willCreateUserFolder(d.dragInfo, dropTargetLayout, mTargetCell, distance, true)) { return true; } - if (mAddToExistingFolderOnDrop && willAddToExistingUserFolder((ItemInfo) d.dragInfo, + if (mAddToExistingFolderOnDrop && willAddToExistingUserFolder(d.dragInfo, dropTargetLayout, mTargetCell, distance)) { return true; } @@ -2502,7 +2521,7 @@ public class Workspace extends PagedView return (aboveShortcut && willBecomeShortcut); } - boolean willAddToExistingUserFolder(Object dragInfo, CellLayout target, int[] targetCell, + boolean willAddToExistingUserFolder(ItemInfo dragInfo, CellLayout target, int[] targetCell, float distance) { if (distance > mMaxDistanceForFolderCreation) return false; View dropOverView = target.getChildAt(targetCell[0], targetCell[1]); @@ -2611,11 +2630,11 @@ public class Workspace extends PagedView if (mLauncher.isHotseatLayout(dropTargetLayout)) { mapPointFromSelfToHotseatLayout(mLauncher.getHotseat(), mDragViewVisualCenter); } else { - mapPointFromSelfToChild(dropTargetLayout, mDragViewVisualCenter, null); + mapPointFromSelfToChild(dropTargetLayout, mDragViewVisualCenter); } } - int snapScreen = WorkspaceStateTransitionAnimation.SCROLL_TO_CURRENT_PAGE; + int snapScreen = -1; boolean resizeOnDrop = false; if (d.dragSource != this) { final int[] touchXY = new int[] { (int) mDragViewVisualCenter[0], @@ -2658,7 +2677,7 @@ public class Workspace extends PagedView // Aside from the special case where we're dropping a shortcut onto a shortcut, // we need to find the nearest cell location that is vacant - ItemInfo item = (ItemInfo) d.dragInfo; + ItemInfo item = d.dragInfo; int minSpanX = item.spanX; int minSpanY = item.spanY; if (item.minSpanX > 0 && item.minSpanY > 0) { @@ -2696,7 +2715,7 @@ public class Workspace extends PagedView CellLayout parentCell = getParentCellLayoutForView(cell); if (parentCell != null) { parentCell.removeView(cell); - } else if (LauncherAppState.isDogfoodBuild()) { + } else if (ProviderConfig.IS_DOGFOOD_BUILD) { throw new NullPointerException("mDragInfo.cell has null parent"); } addInScreen(cell, container, screenId, mTargetCell[0], mTargetCell[1], @@ -2776,9 +2795,7 @@ public class Workspace extends PagedView animateWidgetDrop(info, parent, d.dragView, onCompleteRunnable, animationType, cell, false); } else { - int duration = snapScreen < 0 ? - WorkspaceStateTransitionAnimation.SCROLL_TO_CURRENT_PAGE : - ADJACENT_SCREEN_DROP_DURATION; + int duration = snapScreen < 0 ? -1 : ADJACENT_SCREEN_DROP_DURATION; mLauncher.getDragLayer().animateViewIntoPosition(d.dragView, cell, duration, onCompleteRunnable, this); } @@ -2838,49 +2855,6 @@ public class Workspace extends PagedView CellLayout layout = getCurrentDropLayout(); setCurrentDropLayout(layout); setCurrentDragOverlappingLayout(layout); - - if (!workspaceInModalState()) { - mLauncher.getDragLayer().showPageHints(); - } - } - - /** Return a rect that has the cellWidth/cellHeight (left, top), and - * widthGap/heightGap (right, bottom) */ - static Rect getCellLayoutMetrics(Launcher launcher, int orientation) { - LauncherAppState app = LauncherAppState.getInstance(); - InvariantDeviceProfile inv = app.getInvariantDeviceProfile(); - - Display display = launcher.getWindowManager().getDefaultDisplay(); - Point smallestSize = new Point(); - Point largestSize = new Point(); - display.getCurrentSizeRange(smallestSize, largestSize); - int countX = (int) inv.numColumns; - int countY = (int) inv.numRows; - boolean isLayoutRtl = Utilities.isRtl(launcher.getResources()); - if (orientation == CellLayout.LANDSCAPE) { - if (mLandscapeCellLayoutMetrics == null) { - Rect padding = inv.landscapeProfile.getWorkspacePadding(isLayoutRtl); - int width = largestSize.x - padding.left - padding.right; - int height = smallestSize.y - padding.top - padding.bottom; - mLandscapeCellLayoutMetrics = new Rect(); - mLandscapeCellLayoutMetrics.set( - DeviceProfile.calculateCellWidth(width, countX), - DeviceProfile.calculateCellHeight(height, countY), 0, 0); - } - return mLandscapeCellLayoutMetrics; - } else if (orientation == CellLayout.PORTRAIT) { - if (mPortraitCellLayoutMetrics == null) { - Rect padding = inv.portraitProfile.getWorkspacePadding(isLayoutRtl); - int width = smallestSize.x - padding.left - padding.right; - int height = largestSize.y - padding.top - padding.bottom; - mPortraitCellLayoutMetrics = new Rect(); - mPortraitCellLayoutMetrics.set( - DeviceProfile.calculateCellWidth(width, countX), - DeviceProfile.calculateCellHeight(height, countY), 0, 0); - } - return mPortraitCellLayoutMetrics; - } - return null; } @Override @@ -2915,8 +2889,6 @@ public class Workspace extends PagedView setCurrentDragOverlappingLayout(null); mSpringLoadedDragController.cancel(); - - mLauncher.getDragLayer().hidePageHints(); } private void enfoceDragParity(String event, int update, int expectedValue) { @@ -3021,41 +2993,27 @@ public class Workspace extends PagedView * * Convert the 2D coordinate xy from the parent View's coordinate space to this CellLayout's * coordinate space. The argument xy is modified with the return result. - * - * if cachedInverseMatrix is not null, this method will just use that matrix instead of - * computing it itself; we use this to avoid redundant matrix inversions in - * findMatchingPageForDragOver - * */ - void mapPointFromSelfToChild(View v, float[] xy, Matrix cachedInverseMatrix) { + void mapPointFromSelfToChild(View v, float[] xy) { xy[0] = xy[0] - v.getLeft(); xy[1] = xy[1] - v.getTop(); } - boolean isPointInSelfOverHotseat(int x, int y, Rect r) { - if (r == null) { - r = new Rect(); - } - mTempPt[0] = x; - mTempPt[1] = y; - mLauncher.getDragLayer().getDescendantCoordRelativeToSelf(this, mTempPt, true); - - DeviceProfile grid = mLauncher.getDeviceProfile(); - r = grid.getHotseatRect(); - if (r.contains(mTempPt[0], mTempPt[1])) { - return true; - } - return false; + boolean isPointInSelfOverHotseat(int x, int y) { + mTempXY[0] = x; + mTempXY[1] = y; + mLauncher.getDragLayer().getDescendantCoordRelativeToSelf(this, mTempXY, true); + return mLauncher.getDeviceProfile().isInHotseatRect(mTempXY[0], mTempXY[1]); } void mapPointFromSelfToHotseatLayout(Hotseat hotseat, float[] xy) { - mTempPt[0] = (int) xy[0]; - mTempPt[1] = (int) xy[1]; - mLauncher.getDragLayer().getDescendantCoordRelativeToSelf(this, mTempPt, true); - mLauncher.getDragLayer().mapCoordInSelfToDescendent(hotseat.getLayout(), mTempPt); + mTempXY[0] = (int) xy[0]; + mTempXY[1] = (int) xy[1]; + mLauncher.getDragLayer().getDescendantCoordRelativeToSelf(this, mTempXY, true); + mLauncher.getDragLayer().mapCoordInSelfToDescendent(hotseat.getLayout(), mTempXY); - xy[0] = mTempPt[0]; - xy[1] = mTempPt[1]; + xy[0] = mTempXY[0]; + xy[1] = mTempXY[1]; } /* @@ -3101,10 +3059,7 @@ public class Workspace extends PagedView CellLayout cl = (CellLayout) getChildAt(i); final float[] touchXy = {originX, originY}; - // Transform the touch coordinates to the CellLayout's local coordinates - // If the touch point is within the bounds of the cell layout, we can return immediately - cl.getMatrix().invert(mTempInverseMatrix); - mapPointFromSelfToChild(cl, touchXy, mTempInverseMatrix); + mapPointFromSelfToChild(cl, touchXy); if (touchXy[0] >= 0 && touchXy[0] <= cl.getWidth() && touchXy[1] >= 0 && touchXy[1] <= cl.getHeight()) { @@ -3146,11 +3101,10 @@ public class Workspace extends PagedView // Skip drag over events while we are dragging over side pages if (mInScrollArea || !transitionStateShouldAllowDrop()) return; - Rect r = new Rect(); CellLayout layout = null; - ItemInfo item = (ItemInfo) d.dragInfo; + ItemInfo item = d.dragInfo; if (item == null) { - if (LauncherAppState.isDogfoodBuild()) { + if (ProviderConfig.IS_DOGFOOD_BUILD) { throw new NullPointerException("DragObject has null info"); } return; @@ -3164,7 +3118,7 @@ public class Workspace extends PagedView // Identify whether we have dragged over a side page if (workspaceInModalState()) { if (mLauncher.getHotseat() != null && !isExternalDragWidget(d)) { - if (isPointInSelfOverHotseat(d.x, d.y, r)) { + if (isPointInSelfOverHotseat(d.x, d.y)) { layout = mLauncher.getHotseat().getLayout(); } } @@ -3187,7 +3141,7 @@ public class Workspace extends PagedView } else { // Test to see if we are over the hotseat otherwise just use the current page if (mLauncher.getHotseat() != null && !isDragWidget(d)) { - if (isPointInSelfOverHotseat(d.x, d.y, r)) { + if (isPointInSelfOverHotseat(d.x, d.y)) { layout = mLauncher.getHotseat().getLayout(); } } @@ -3206,10 +3160,10 @@ public class Workspace extends PagedView if (mLauncher.isHotseatLayout(mDragTargetLayout)) { mapPointFromSelfToHotseatLayout(mLauncher.getHotseat(), mDragViewVisualCenter); } else { - mapPointFromSelfToChild(mDragTargetLayout, mDragViewVisualCenter, null); + mapPointFromSelfToChild(mDragTargetLayout, mDragViewVisualCenter); } - ItemInfo info = (ItemInfo) d.dragInfo; + ItemInfo info = d.dragInfo; int minSpanX = item.spanX; int minSpanY = item.spanY; @@ -3389,24 +3343,6 @@ public class Workspace extends PagedView } /** - * Add the item specified by dragInfo to the given layout. - * @return true if successful - */ - public boolean addExternalItemToScreen(ItemInfo dragInfo, CellLayout layout) { - if (layout.findCellForSpan(mTempEstimate, dragInfo.spanX, dragInfo.spanY)) { - onDropExternal(dragInfo.dropPos, (ItemInfo) dragInfo, (CellLayout) layout, false); - return true; - } - mLauncher.showOutOfSpaceMessage(mLauncher.isHotseatLayout(layout)); - return false; - } - - private void onDropExternal(int[] touchXY, Object dragInfo, - CellLayout cellLayout, boolean insertAtFirst) { - onDropExternal(touchXY, dragInfo, cellLayout, insertAtFirst, null); - } - - /** * Drop an item that didn't originate on one of the workspace screens. * It may have come from Launcher (e.g. from all apps or customize), or it may have * come from another app altogether. @@ -3414,7 +3350,7 @@ public class Workspace extends PagedView * NOTE: This can also be called when we are outside of a drag event, when we want * to add an item to one of the workspace screens. */ - private void onDropExternal(final int[] touchXY, final Object dragInfo, + private void onDropExternal(final int[] touchXY, final ItemInfo dragInfo, final CellLayout cellLayout, boolean insertAtFirst, DragObject d) { final Runnable exitSpringLoadedRunnable = new Runnable() { @Override @@ -3424,7 +3360,7 @@ public class Workspace extends PagedView } }; - ItemInfo info = (ItemInfo) dragInfo; + ItemInfo info = dragInfo; int spanX = info.spanX; int spanY = info.spanY; if (mDragInfo != null) { @@ -3451,14 +3387,14 @@ public class Workspace extends PagedView cellLayout, mTargetCell); float distance = cellLayout.getDistanceFromCell(mDragViewVisualCenter[0], mDragViewVisualCenter[1], mTargetCell); - if (willCreateUserFolder((ItemInfo) d.dragInfo, cellLayout, mTargetCell, - distance, true) || willAddToExistingUserFolder((ItemInfo) d.dragInfo, - cellLayout, mTargetCell, distance)) { + if (willCreateUserFolder(d.dragInfo, cellLayout, mTargetCell, distance, true) + || willAddToExistingUserFolder( + d.dragInfo, cellLayout, mTargetCell, distance)) { findNearestVacantCell = false; } } - final ItemInfo item = (ItemInfo) d.dragInfo; + final ItemInfo item = d.dragInfo; boolean updateWidgetSize = false; if (findNearestVacantCell) { int minSpanX = item.spanX; @@ -3776,7 +3712,7 @@ public class Workspace extends PagedView mDragInfo.container, mDragInfo.screenId); if (cellLayout != null) { cellLayout.onDropChild(mDragInfo.cell); - } else if (LauncherAppState.isDogfoodBuild()) { + } else if (ProviderConfig.IS_DOGFOOD_BUILD) { throw new RuntimeException("Invalid state: cellLayout == null in " + "Workspace#onDropCompleted. Please file a bug. "); }; @@ -3787,6 +3723,9 @@ public class Workspace extends PagedView } mDragOutline = null; mDragInfo = null; + + mLauncher.exitSpringLoadedDragModeDelayed(success, + Launcher.EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null); } /** @@ -3796,7 +3735,7 @@ public class Workspace extends PagedView CellLayout parentCell = getParentCellLayoutForView(v); if (parentCell != null) { parentCell.removeView(v); - } else if (LauncherAppState.isDogfoodBuild()) { + } else if (ProviderConfig.IS_DOGFOOD_BUILD) { // When an app is uninstalled using the drop target, we wait until resume to remove // the icon. We also remove all the corresponding items from the workspace at // {@link Launcher#bindComponentsRemoved}. That call can come before or after @@ -3823,29 +3762,6 @@ public class Workspace extends PagedView } } - void updateItemLocationsInDatabase(CellLayout cl) { - int count = cl.getShortcutsAndWidgets().getChildCount(); - - long screenId = getIdForScreen(cl); - int container = Favorites.CONTAINER_DESKTOP; - - if (mLauncher.isHotseatLayout(cl)) { - screenId = -1; - container = Favorites.CONTAINER_HOTSEAT; - } - - for (int i = 0; i < count; i++) { - View v = cl.getShortcutsAndWidgets().getChildAt(i); - ItemInfo info = (ItemInfo) v.getTag(); - // Null check required as the AllApps button doesn't have an item info - if (info != null && info.requiresDbUpdate) { - info.requiresDbUpdate = false; - LauncherModel.modifyItemInDatabase(mLauncher, info, container, screenId, info.cellX, - info.cellY, info.spanX, info.spanY); - } - } - } - void saveWorkspaceToDb() { saveWorkspaceScreenToDb((CellLayout) mLauncher.getHotseat().getLayout()); int count = getChildCount(); @@ -3899,7 +3815,7 @@ public class Workspace extends PagedView @Override public boolean supportsAppInfoDropTarget() { - return false; + return true; } @Override @@ -4472,7 +4388,7 @@ public class Workspace extends PagedView private String getPageDescription(int page) { int delta = numCustomPages(); - return String.format(getContext().getString(R.string.workspace_scroll_format), + return getContext().getString(R.string.workspace_scroll_format, page + 1 - delta, getChildCount() - delta); } |