diff options
author | Tony Wickham <twickham@google.com> | 2015-09-10 00:31:18 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2015-09-10 00:31:18 +0000 |
commit | 82ac82fb17919ec0ed8affdf92795d66dacb93f1 (patch) | |
tree | 666e552e97484f5e9e3bdcb99c4bd37e9e7a1f2c | |
parent | 3d3f90b2f064bfb531811ac66f69fc7c14f0dbca (diff) | |
parent | 869306140d3bb8782040ed65d3ae0ba498c2de6c (diff) | |
download | android_packages_apps_Trebuchet-82ac82fb17919ec0ed8affdf92795d66dacb93f1.tar.gz android_packages_apps_Trebuchet-82ac82fb17919ec0ed8affdf92795d66dacb93f1.tar.bz2 android_packages_apps_Trebuchet-82ac82fb17919ec0ed8affdf92795d66dacb93f1.zip |
Merge "When placing a widget, go to a page with enough space." into ub-launcher3-master
-rw-r--r-- | src/com/android/launcher3/CellLayout.java | 20 | ||||
-rw-r--r-- | src/com/android/launcher3/PagedView.java | 2 | ||||
-rw-r--r-- | src/com/android/launcher3/Workspace.java | 11 | ||||
-rw-r--r-- | src/com/android/launcher3/widget/WidgetsContainerView.java | 4 |
4 files changed, 35 insertions, 2 deletions
diff --git a/src/com/android/launcher3/CellLayout.java b/src/com/android/launcher3/CellLayout.java index 653ee7ec6..700bf9ee6 100644 --- a/src/com/android/launcher3/CellLayout.java +++ b/src/com/android/launcher3/CellLayout.java @@ -2966,6 +2966,26 @@ public class CellLayout extends ViewGroup implements BubbleTextShadowHandler { return Utilities.findVacantCell(outXY, spanX, spanY, mCountX, mCountY, mOccupied); } + /** + * Returns whether an item can be placed in this CellLayout (after rearranging and/or resizing + * if necessary). + */ + public boolean hasReorderSolution(ItemInfo itemInfo) { + int[] cellPoint = new int[2]; + // Check for a solution starting at every cell. + for (int cellX = 0; cellX < getCountX(); cellX++) { + for (int cellY = 0; cellY < getCountY(); cellY++) { + cellToPoint(cellX, cellY, cellPoint); + if (findReorderSolution(cellPoint[0], cellPoint[1], itemInfo.minSpanX, + itemInfo.minSpanY, itemInfo.spanX, itemInfo.spanY, mDirectionVector, null, + true, new ItemConfiguration()).isSolution) { + return true; + } + } + } + return false; + } + public boolean isRegionVacant(int x, int y, int spanX, int spanY) { int x2 = x + spanX - 1; int y2 = y + spanY - 1; diff --git a/src/com/android/launcher3/PagedView.java b/src/com/android/launcher3/PagedView.java index 5f54e1d14..e4d644884 100644 --- a/src/com/android/launcher3/PagedView.java +++ b/src/com/android/launcher3/PagedView.java @@ -441,7 +441,7 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc Math.min(newPage, mTempVisiblePagesRange[1])); } // Ensure that it is clamped by the actual set of children in all cases - validatedPage = Math.max(0, Math.min(validatedPage, getPageCount() - 1)); + validatedPage = Utilities.boundInRange(validatedPage, 0, getPageCount() - 1); return validatedPage; } diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java index 5c8c402ca..58209c317 100644 --- a/src/com/android/launcher3/Workspace.java +++ b/src/com/android/launcher3/Workspace.java @@ -1927,6 +1927,17 @@ 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. + for (int pageIndex = getCurrentPage(); 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 diff --git a/src/com/android/launcher3/widget/WidgetsContainerView.java b/src/com/android/launcher3/widget/WidgetsContainerView.java index e6059d5c7..81a8465d8 100644 --- a/src/com/android/launcher3/widget/WidgetsContainerView.java +++ b/src/com/android/launcher3/widget/WidgetsContainerView.java @@ -253,9 +253,11 @@ public class WidgetsContainerView extends BaseContainerView // Start the drag mLauncher.lockScreenOrientation(); - mLauncher.getWorkspace().onDragStartedWithItem(createItemInfo, preview, clipAlpha); mDragController.startDrag(image, preview, this, createItemInfo, bounds, DragController.DRAG_ACTION_COPY, scale); + // This call expects the extra empty screen to already be created, which is why we call it + // after mDragController.startDrag(). + mLauncher.getWorkspace().onDragStartedWithItem(createItemInfo, preview, clipAlpha); preview.recycle(); return true; |