Find page for widget starting at current page from overview.
Previously the search began with the page that the user
long-pressed to enter the overview, even if they then free-
scrolled to another page before selecting "Widgets."
Change-Id: Ie286f6864c78b573c05dd9d02c1346e17db711a6
diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java
index 58209c3..14fb3fc 100644
--- a/src/com/android/launcher3/Workspace.java
+++ b/src/com/android/launcher3/Workspace.java
@@ -1930,7 +1930,8 @@
// 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++) {
+ int currentPageInOverview = getPageNearestToCenterOfScreen();
+ for (int pageIndex = currentPageInOverview; pageIndex < getPageCount(); pageIndex++) {
CellLayout page = (CellLayout) getPageAt(pageIndex);
if (page.hasReorderSolution(info)) {
setCurrentPage(pageIndex);