From 408a54f2e7b3f0da2a64b1e00716eb67a87d2fb5 Mon Sep 17 00:00:00 2001 From: Andras Kloczl Date: Sat, 28 Aug 2021 00:59:08 +0100 Subject: [PATCH 1/6] Add two extra empty pages on two panel launcher home Add a new screen ID for the second extra empty page and add that new screen as well when the existing extra empty page is added so that users can put items on both sides of Workspace. Test: manual Bug: 196376162 Change-Id: I0b4f2e818407a10d8a7c032788a7bd7a61267779 --- src/com/android/launcher3/Launcher.java | 22 +- src/com/android/launcher3/Workspace.java | 223 ++++++++++++++---- .../launcher3/WorkspaceLayoutManager.java | 11 +- .../LauncherAccessibilityDelegate.java | 17 +- .../ShortcutMenuAccessibilityDelegate.java | 3 + .../launcher3/model/data/ItemInfo.java | 4 +- .../util/WallpaperOffsetInterpolator.java | 4 +- 7 files changed, 210 insertions(+), 74 deletions(-) diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java index 3754dc147b..192b8a7c6f 100644 --- a/src/com/android/launcher3/Launcher.java +++ b/src/com/android/launcher3/Launcher.java @@ -871,11 +871,11 @@ public class Launcher extends StatefulActivity implements Launche if (dropLayout == null) { // it's possible that the add screen was removed because it was // empty and a re-bind occurred - mWorkspace.addExtraEmptyScreen(); - return mWorkspace.commitExtraEmptyScreen(); - } else { - return screenId; + mWorkspace.addExtraEmptyScreens(); + IntSet emptyPagesAdded = mWorkspace.commitExtraEmptyScreens(); + return emptyPagesAdded.isEmpty() ? -1 : emptyPagesAdded.getArray().get(0); } + return screenId; } @Thunk @@ -2175,7 +2175,7 @@ public class Launcher extends StatefulActivity implements Launche orderedScreenIds.add(firstScreenPosition, Workspace.FIRST_SCREEN_ID); } else if (!FeatureFlags.QSB_ON_FIRST_SCREEN && orderedScreenIds.isEmpty()) { // If there are no screens, we need to have an empty screen - mWorkspace.addExtraEmptyScreen(); + mWorkspace.addExtraEmptyScreens(); } bindAddScreens(orderedScreenIds); @@ -2190,17 +2190,7 @@ public class Launcher extends StatefulActivity implements Launche // Some empty pages might have been removed while the phone was in a single panel // mode, so we want to add those empty pages back. IntSet screenIds = IntSet.wrap(orderedScreenIds); - for (int i = 0; i < orderedScreenIds.size(); i++) { - int screenId = orderedScreenIds.get(i); - // Don't add the page pair if the page is the last one and if the pair is on the - // right, because that would cause a bug when adding new pages. - // TODO: (b/196376162) remove this when the new screen id logic is fixed for two - // panel in Workspace::commitExtraEmptyScreen - if (i == orderedScreenIds.size() - 1 && screenId % 2 == 0) { - continue; - } - screenIds.add(mWorkspace.getPagePair(screenId)); - } + orderedScreenIds.forEach(screenId -> screenIds.add(mWorkspace.getPagePair(screenId))); orderedScreenIds = screenIds.getArray(); } diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java index 94ec903b86..c404d1a386 100644 --- a/src/com/android/launcher3/Workspace.java +++ b/src/com/android/launcher3/Workspace.java @@ -125,6 +125,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; import java.util.List; +import java.util.function.Consumer; import java.util.function.Predicate; import java.util.stream.Collectors; @@ -642,18 +643,35 @@ public class Workspace extends PagedView boolean childOnFinalScreen = false; if (mDragSourceInternal != null) { + int dragSourceChildCount = mDragSourceInternal.getChildCount(); + + if (isTwoPanelEnabled()) { + int pagePairScreenId = getPagePair(dragObject.dragInfo.screenId); + CellLayout pagePair = mWorkspaceScreens.get(pagePairScreenId); + if (pagePair == null) { + // TODO: after http://b/198820019 is fixed, remove this + throw new IllegalStateException("Page pair is null, " + + "dragScreenId: " + dragObject.dragInfo.screenId + + ", pagePairScreenId: " + pagePairScreenId + + ", mScreenOrder: " + mScreenOrder.toConcatString() + ); + } + dragSourceChildCount += pagePair.getShortcutsAndWidgets().getChildCount(); + } + // When the drag view content is a LauncherAppWidgetHostView, we should increment the // drag source child count by 1 because the widget in drag has been detached from its // original parent, ShortcutAndWidgetContainer, and reattached to the DragView. - int dragSourceChildCount = - dragObject.dragView.getContentView() instanceof LauncherAppWidgetHostView - ? mDragSourceInternal.getChildCount() + 1 - : mDragSourceInternal.getChildCount(); + if (dragObject.dragView.getContentView() instanceof LauncherAppWidgetHostView) { + dragSourceChildCount++; + } + if (dragSourceChildCount == 1) { lastChildOnScreen = true; } CellLayout cl = (CellLayout) mDragSourceInternal.getParent(); - if (indexOfChild(cl) == getChildCount() - 1) { + if (getLeftmostVisiblePageForIndex(indexOfChild(cl)) + == getLeftmostVisiblePageForIndex(getPageCount() - 1)) { childOnFinalScreen = true; } } @@ -662,40 +680,83 @@ public class Workspace extends PagedView if (lastChildOnScreen && childOnFinalScreen) { return; } - if (!mWorkspaceScreens.containsKey(EXTRA_EMPTY_SCREEN_ID)) { - insertNewWorkspaceScreen(EXTRA_EMPTY_SCREEN_ID); + + forEachExtraEmptyPageId(extraEmptyPageId -> { + if (!mWorkspaceScreens.containsKey(extraEmptyPageId)) { + insertNewWorkspaceScreen(extraEmptyPageId); + } + }); + } + + /** + * Inserts extra empty pages to the end of the existing workspaces. + * Usually we add one extra empty screen, but when two panel home is enabled we add + * two extra screens. + **/ + public void addExtraEmptyScreens() { + forEachExtraEmptyPageId(extraEmptyPageId -> { + if (!mWorkspaceScreens.containsKey(extraEmptyPageId)) { + insertNewWorkspaceScreen(extraEmptyPageId); + } + }); + } + + /** + * Calls the consumer with all the necessary extra empty page IDs. + * On a normal one panel Workspace that means only EXTRA_EMPTY_SCREEN_ID, + * but in a two panel scenario this also includes EXTRA_EMPTY_SCREEN_SECOND_ID. + */ + private void forEachExtraEmptyPageId(Consumer callback) { + callback.accept(EXTRA_EMPTY_SCREEN_ID); + if (isTwoPanelEnabled()) { + callback.accept(EXTRA_EMPTY_SCREEN_SECOND_ID); } } - public boolean addExtraEmptyScreen() { - if (!mWorkspaceScreens.containsKey(EXTRA_EMPTY_SCREEN_ID)) { - insertNewWorkspaceScreen(EXTRA_EMPTY_SCREEN_ID); - return true; - } - return false; - } - + /** + * If two panel home is enabled we convert the last two screens that are visible at the same + * time. In other cases we only convert the last page. + */ private void convertFinalScreenToEmptyScreenIfNecessary() { if (mLauncher.isWorkspaceLoading()) { // Invalid and dangerous operation if workspace is loading return; } - if (hasExtraEmptyScreen() || mScreenOrder.size() == 0) return; - int finalScreenId = mScreenOrder.get(mScreenOrder.size() - 1); + int panelCount = getPanelCount(); + if (hasExtraEmptyScreens() || mScreenOrder.size() < panelCount) { + return; + } - CellLayout finalScreen = mWorkspaceScreens.get(finalScreenId); + SparseArray finalScreens = new SparseArray<>(); - // If the final screen is empty, convert it to the extra empty screen - if (finalScreen != null - && finalScreen.getShortcutsAndWidgets().getChildCount() == 0 - && !finalScreen.isDropPending()) { - mWorkspaceScreens.remove(finalScreenId); - mScreenOrder.removeValue(finalScreenId); + int pageCount = mScreenOrder.size(); + // First we add the last page(s) to the finalScreens collection. The number of final pages + // depends on the panel count. + for (int pageIndex = pageCount - panelCount; pageIndex < pageCount; pageIndex++) { + int screenId = mScreenOrder.get(pageIndex); + CellLayout screen = mWorkspaceScreens.get(screenId); + if (screen == null || screen.getShortcutsAndWidgets().getChildCount() != 0 + || screen.isDropPending()) { + // Final screen doesn't exist or it isn't empty or there's a pending drop + return; + } + finalScreens.append(screenId, screen); + } - // if this is the last screen, convert it to the empty screen - mWorkspaceScreens.put(EXTRA_EMPTY_SCREEN_ID, finalScreen); - mScreenOrder.add(EXTRA_EMPTY_SCREEN_ID); + // Then we remove the final screens from the collections (but not from the view hierarchy) + // and we store them as extra empty screens. + for (int i = 0; i < finalScreens.size(); i++) { + int screenId = finalScreens.keyAt(i); + CellLayout screen = finalScreens.get(screenId); + + mWorkspaceScreens.remove(screenId); + mScreenOrder.removeValue(screenId); + + int newScreenId = mWorkspaceScreens.containsKey(EXTRA_EMPTY_SCREEN_ID) + ? EXTRA_EMPTY_SCREEN_SECOND_ID : EXTRA_EMPTY_SCREEN_ID; + mWorkspaceScreens.put(newScreenId, screen); + mScreenOrder.add(newScreenId); } } @@ -703,6 +764,23 @@ public class Workspace extends PagedView removeExtraEmptyScreenDelayed(0, stripEmptyScreens, null); } + /** + * The purpose of this method is to remove empty pages from Workspace. + * Empty page(s) from the end of mWorkspaceScreens will always be removed. The pages with + * ID = Workspace.EXTRA_EMPTY_SCREEN_IDS will be removed if there are other non-empty pages. + * If there are no more non-empty pages left, extra empty page(s) will either stay or get added. + * + * If stripEmptyScreens is true, all empty pages (not just the ones on the end) will be removed + * from the Workspace, and if there are no more pages left then extra empty page(s) will be + * added. + * + * The number of extra empty pages is equal to what getPanelCount() returns. + * + * After the method returns the possible pages are: + * stripEmptyScreens = true : [non-empty pages, extra empty page(s) alone] + * stripEmptyScreens = false : [non-empty pages, empty pages (not in the end), + * extra empty page(s) alone] + */ public void removeExtraEmptyScreenDelayed( int delay, boolean stripEmptyScreens, Runnable onComplete) { if (mLauncher.isWorkspaceLoading()) { @@ -716,18 +794,26 @@ public class Workspace extends PagedView return; } + // First we convert the last page to an extra page if the last page is empty + // and we don't already have an extra page. convertFinalScreenToEmptyScreenIfNecessary(); - if (hasExtraEmptyScreen()) { - removeView(mWorkspaceScreens.get(EXTRA_EMPTY_SCREEN_ID)); + // Then we remove the extra page(s) if they are not the only pages left in Workspace. + if (hasExtraEmptyScreens()) { + forEachExtraEmptyPageId(extraEmptyPageId -> { + removeView(mWorkspaceScreens.get(extraEmptyPageId)); + mWorkspaceScreens.remove(extraEmptyPageId); + mScreenOrder.removeValue(extraEmptyPageId); + }); + setCurrentPage(getNextPage()); - mWorkspaceScreens.remove(EXTRA_EMPTY_SCREEN_ID); - mScreenOrder.removeValue(EXTRA_EMPTY_SCREEN_ID); // Update the page indicator to reflect the removed page. showPageIndicatorAtCurrentScroll(); } if (stripEmptyScreens) { + // This will remove all empty pages from the Workspace. If there are no more pages left, + // it will add extra page(s) so that users can put items on at least one page. stripEmptyScreens(); } @@ -736,27 +822,56 @@ public class Workspace extends PagedView } } - public boolean hasExtraEmptyScreen() { - return mWorkspaceScreens.containsKey(EXTRA_EMPTY_SCREEN_ID) && getChildCount() > 1; + public boolean hasExtraEmptyScreens() { + return mWorkspaceScreens.containsKey(EXTRA_EMPTY_SCREEN_ID) + && getChildCount() > getPanelCount() + && (!isTwoPanelEnabled() + || mWorkspaceScreens.containsKey(EXTRA_EMPTY_SCREEN_SECOND_ID)); } - public int commitExtraEmptyScreen() { + /** + * Commits the extra empty pages then returns the screen ids of those new screens. + * Usually there's only one extra empty screen, but when two panel home is enabled we commit + * two extra screens. + * + * Returns an empty IntSet in case we cannot commit any new screens. + */ + public IntSet commitExtraEmptyScreens() { if (mLauncher.isWorkspaceLoading()) { // Invalid and dangerous operation if workspace is loading - return -1; + return new IntSet(); } - CellLayout cl = mWorkspaceScreens.get(EXTRA_EMPTY_SCREEN_ID); - mWorkspaceScreens.remove(EXTRA_EMPTY_SCREEN_ID); - mScreenOrder.removeValue(EXTRA_EMPTY_SCREEN_ID); + IntSet extraEmptyPageIds = new IntSet(); + forEachExtraEmptyPageId(extraEmptyPageId -> + extraEmptyPageIds.add(commitExtraEmptyScreen(extraEmptyPageId))); - int newId = LauncherSettings.Settings.call(getContext().getContentResolver(), + return extraEmptyPageIds; + } + + private int commitExtraEmptyScreen(int emptyScreenId) { + CellLayout cl = mWorkspaceScreens.get(emptyScreenId); + mWorkspaceScreens.remove(emptyScreenId); + mScreenOrder.removeValue(emptyScreenId); + + int newScreenId = LauncherSettings.Settings.call(getContext().getContentResolver(), LauncherSettings.Settings.METHOD_NEW_SCREEN_ID) .getInt(LauncherSettings.Settings.EXTRA_VALUE); - mWorkspaceScreens.put(newId, cl); - mScreenOrder.add(newId); - return newId; + + // When two panel home is enabled and the last page (the page on the right) doesn't + // have any items, then Launcher database doesn't know about this page because it was added + // by Launcher::bindAddScreens but wasn't inserted into the database. LauncherSettings's + // generate new screen ID method will return the ID for the left page, + // so we need to increment it. + if (isTwoPanelEnabled() && emptyScreenId == EXTRA_EMPTY_SCREEN_ID && newScreenId % 2 == 1) { + newScreenId++; + } + + mWorkspaceScreens.put(newScreenId, cl); + mScreenOrder.add(newScreenId); + + return newScreenId; } @Override @@ -857,9 +972,10 @@ public class Workspace extends PagedView } } - // We enforce at least one page to add new items to. In the case that we remove the last - // such screen, we convert the last screen to the empty screen - int minScreens = 1; + // We enforce at least one page (two pages on two panel home) to add new items to. + // In the case that we remove the last such screen(s), we convert the last screen(s) + // to the empty screen(s) + int minScreens = getPanelCount(); int pageShift = 0; for (int i = 0; i < removeScreens.size(); i++) { @@ -869,14 +985,21 @@ public class Workspace extends PagedView mScreenOrder.removeValue(id); if (getChildCount() > minScreens) { + // If this isn't the last page, just remove it if (indexOfChild(cl) < currentPage) { pageShift++; } removeView(cl); } else { - // if this is the last screen, convert it to the empty screen - mWorkspaceScreens.put(EXTRA_EMPTY_SCREEN_ID, cl); - mScreenOrder.add(EXTRA_EMPTY_SCREEN_ID); + // The last page(s) should be converted into extra empty page(s) + int extraScreenId = isTwoPanelEnabled() && id % 2 == 1 + // This is the right panel in a two panel scenario + ? EXTRA_EMPTY_SCREEN_SECOND_ID + // This is either the last screen in a one panel scenario, or the left panel + // in a two panel scenario when there are only two empty pages left + : EXTRA_EMPTY_SCREEN_ID; + mWorkspaceScreens.put(extraScreenId, cl); + mScreenOrder.add(extraScreenId); } } @@ -1646,8 +1769,8 @@ public class Workspace extends PagedView } int screenId = getIdForScreen(dropTargetLayout); - if (screenId == EXTRA_EMPTY_SCREEN_ID) { - commitExtraEmptyScreen(); + if (Workspace.EXTRA_EMPTY_SCREEN_IDS.contains(screenId)) { + commitExtraEmptyScreens(); } return true; diff --git a/src/com/android/launcher3/WorkspaceLayoutManager.java b/src/com/android/launcher3/WorkspaceLayoutManager.java index 44a5536c92..7e6e1b60de 100644 --- a/src/com/android/launcher3/WorkspaceLayoutManager.java +++ b/src/com/android/launcher3/WorkspaceLayoutManager.java @@ -23,6 +23,7 @@ import com.android.launcher3.folder.Folder; import com.android.launcher3.folder.FolderIcon; import com.android.launcher3.model.data.ItemInfo; import com.android.launcher3.touch.ItemLongClickListener; +import com.android.launcher3.util.IntSet; public interface WorkspaceLayoutManager { @@ -30,6 +31,12 @@ public interface WorkspaceLayoutManager { // The screen id used for the empty screen always present at the end. int EXTRA_EMPTY_SCREEN_ID = -201; + // The screen id used for the second empty screen always present at the end for two panel home. + int EXTRA_EMPTY_SCREEN_SECOND_ID = -200; + // The screen ids used for the empty screens at the end of the workspaces. + IntSet EXTRA_EMPTY_SCREEN_IDS = + IntSet.wrap(EXTRA_EMPTY_SCREEN_ID, EXTRA_EMPTY_SCREEN_SECOND_ID); + // The is the first screen. It is always present, even if its empty. int FIRST_SCREEN_ID = 0; // This is the second page. On two panel home it is always present, even if its empty. @@ -81,9 +88,9 @@ public interface WorkspaceLayoutManager { return; } } - if (screenId == EXTRA_EMPTY_SCREEN_ID) { + if (EXTRA_EMPTY_SCREEN_IDS.contains(screenId)) { // This should never happen - throw new RuntimeException("Screen id should not be EXTRA_EMPTY_SCREEN_ID"); + throw new RuntimeException("Screen id should not be extra empty screen: " + screenId); } final CellLayout layout; diff --git a/src/com/android/launcher3/accessibility/LauncherAccessibilityDelegate.java b/src/com/android/launcher3/accessibility/LauncherAccessibilityDelegate.java index 9faac5b7ef..2032b26992 100644 --- a/src/com/android/launcher3/accessibility/LauncherAccessibilityDelegate.java +++ b/src/com/android/launcher3/accessibility/LauncherAccessibilityDelegate.java @@ -45,6 +45,7 @@ import com.android.launcher3.popup.ArrowPopup; import com.android.launcher3.popup.PopupContainerWithArrow; import com.android.launcher3.touch.ItemLongClickListener; import com.android.launcher3.util.IntArray; +import com.android.launcher3.util.IntSet; import com.android.launcher3.util.ShortcutUtil; import com.android.launcher3.util.Thunk; import com.android.launcher3.views.OptionsPopupView; @@ -221,6 +222,9 @@ public class LauncherAccessibilityDelegate extends AccessibilityDelegate impleme } else if (action == ADD_TO_WORKSPACE) { final int[] coordinates = new int[2]; final int screenId = findSpaceOnWorkspace(item, coordinates); + if (screenId == -1) { + return false; + } mLauncher.getStateManager().goToState(NORMAL, true, forSuccessCallback(() -> { if (item instanceof AppInfo) { WorkspaceItemInfo info = ((AppInfo) item).makeWorkspaceItem(); @@ -250,6 +254,9 @@ public class LauncherAccessibilityDelegate extends AccessibilityDelegate impleme final int[] coordinates = new int[2]; final int screenId = findSpaceOnWorkspace(item, coordinates); + if (screenId == -1) { + return false; + } mLauncher.getModelWriter().moveItemInDatabase(info, Favorites.CONTAINER_DESKTOP, screenId, coordinates[0], coordinates[1]); @@ -489,8 +496,14 @@ public class LauncherAccessibilityDelegate extends AccessibilityDelegate impleme return screenId; } - workspace.addExtraEmptyScreen(); - screenId = workspace.commitExtraEmptyScreen(); + workspace.addExtraEmptyScreens(); + IntSet emptyScreenIds = workspace.commitExtraEmptyScreens(); + if (emptyScreenIds.isEmpty()) { + // Couldn't create extra empty screens for some reason (e.g. Workspace is loading) + return -1; + } + + screenId = emptyScreenIds.getArray().get(0); layout = workspace.getScreenWithId(screenId); found = layout.findCellForSpan(outCoordinates, info.spanX, info.spanY); diff --git a/src/com/android/launcher3/accessibility/ShortcutMenuAccessibilityDelegate.java b/src/com/android/launcher3/accessibility/ShortcutMenuAccessibilityDelegate.java index f96afa856b..bf5a24b65b 100644 --- a/src/com/android/launcher3/accessibility/ShortcutMenuAccessibilityDelegate.java +++ b/src/com/android/launcher3/accessibility/ShortcutMenuAccessibilityDelegate.java @@ -68,6 +68,9 @@ public class ShortcutMenuAccessibilityDelegate extends LauncherAccessibilityDele final WorkspaceItemInfo info = ((DeepShortcutView) host.getParent()).getFinalInfo(); final int[] coordinates = new int[2]; final int screenId = findSpaceOnWorkspace(item, coordinates); + if (screenId == -1) { + return false; + } mLauncher.getStateManager().goToState(NORMAL, true, forSuccessCallback(() -> { mLauncher.getModelWriter().addItemToDatabase(info, LauncherSettings.Favorites.CONTAINER_DESKTOP, diff --git a/src/com/android/launcher3/model/data/ItemInfo.java b/src/com/android/launcher3/model/data/ItemInfo.java index 7091d2b143..4fdc412459 100644 --- a/src/com/android/launcher3/model/data/ItemInfo.java +++ b/src/com/android/launcher3/model/data/ItemInfo.java @@ -232,9 +232,9 @@ public class ItemInfo { * Write the fields of this item to the DB */ public void onAddToDatabase(ContentWriter writer) { - if (screenId == Workspace.EXTRA_EMPTY_SCREEN_ID) { + if (Workspace.EXTRA_EMPTY_SCREEN_IDS.contains(screenId)) { // We should never persist an item on the extra empty screen. - throw new RuntimeException("Screen id should not be EXTRA_EMPTY_SCREEN_ID"); + throw new RuntimeException("Screen id should not be extra empty screen: " + screenId); } writeToValues(writer); diff --git a/src/com/android/launcher3/util/WallpaperOffsetInterpolator.java b/src/com/android/launcher3/util/WallpaperOffsetInterpolator.java index c51f66f407..8a7cae90bc 100644 --- a/src/com/android/launcher3/util/WallpaperOffsetInterpolator.java +++ b/src/com/android/launcher3/util/WallpaperOffsetInterpolator.java @@ -150,8 +150,8 @@ public class WallpaperOffsetInterpolator extends BroadcastReceiver { */ private int getNumPagesExcludingEmpty() { int numOfPages = mWorkspace.getChildCount(); - if (numOfPages >= MIN_PARALLAX_PAGE_SPAN && mWorkspace.hasExtraEmptyScreen()) { - return numOfPages - 1; + if (numOfPages >= MIN_PARALLAX_PAGE_SPAN && mWorkspace.hasExtraEmptyScreens()) { + return numOfPages - mWorkspace.getPanelCount(); } else { return numOfPages; } From 62f129b878598a2f4673a1cdbbae7225f6128fc9 Mon Sep 17 00:00:00 2001 From: Alex Chau Date: Fri, 3 Sep 2021 16:54:27 +0100 Subject: [PATCH 2/6] Fix getPagesToBindSynchronously returning wrong page pairs - Use WorkSpace.getPagePair instead for accurate value Bug: 191657065 Test: manual Change-Id: I584f1705fb5ed2f0d2bd776eb6cf4f60c69238ac --- src/com/android/launcher3/Launcher.java | 20 ++++++++++---------- src/com/android/launcher3/Workspace.java | 4 ---- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java index 5be93b2f66..1354a7ab37 100644 --- a/src/com/android/launcher3/Launcher.java +++ b/src/com/android/launcher3/Launcher.java @@ -2112,19 +2112,19 @@ public class Launcher extends StatefulActivity implements Launche actualIds.add(id); } int firstId = visibleIds.getArray().get(0); + int pairId = mWorkspace.getPagePair(firstId); + // Double check that actual screenIds contains the visibleId, as empty screens are hidden + // in single panel. if (actualIds.contains(firstId)) { result.add(firstId); - - if (mDeviceProfile.isTwoPanels) { - int index = actualIds.indexOf(firstId); - int nextIndex = (index / 2) * 2; - if (nextIndex == index) { - nextIndex++; - } - if (nextIndex < actualIds.size()) { - result.add(actualIds.get(nextIndex)); - } + if (mDeviceProfile.isTwoPanels && actualIds.contains(pairId)) { + result.add(pairId); } + } else if (LauncherAppState.getIDP(this).supportedProfiles.stream().anyMatch( + deviceProfile -> deviceProfile.isTwoPanels) && actualIds.contains(pairId)) { + // Add the right panel if left panel is hidden when switching display, due to empty + // pages being hidden in single panel. + result.add(pairId); } return result; } diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java index b1a9b76f6d..6ec48e5278 100644 --- a/src/com/android/launcher3/Workspace.java +++ b/src/com/android/launcher3/Workspace.java @@ -920,12 +920,8 @@ public class Workspace extends PagedView /** * Returns the page that is shown together with the given page when two panel is enabled. - * @throws IllegalStateException if called while two panel home isn't enabled. */ public int getPagePair(int page) { - if (!isTwoPanelEnabled()) { - throw new IllegalStateException("Two panel home isn't enabled."); - } if (page % 2 == 0) { return page + 1; } else { From 929e3a2742671d7501d448bc9a11e5b82be4c61f Mon Sep 17 00:00:00 2001 From: Andras Kloczl Date: Mon, 6 Sep 2021 03:30:30 +0100 Subject: [PATCH 3/6] Remove widget panel related leftover workspace items Upgrade launcher DB version and remove items with widget panel IDs from the database. Test: follow test instructions (in CL comment) Bug: 198254728 Change-Id: I077a5f70ee93b7eca738b38f6b0e788d49f7ce70 --- res/raw/downgrade_schema.json | 3 ++- src/com/android/launcher3/LauncherProvider.java | 7 ++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/res/raw/downgrade_schema.json b/res/raw/downgrade_schema.json index bc25cece2d..14eac9f6ed 100644 --- a/res/raw/downgrade_schema.json +++ b/res/raw/downgrade_schema.json @@ -2,8 +2,9 @@ // Note: Comments are not supported in JSON schema, but android parser is lenient. // Maximum DB version supported by this schema - "version" : 29, + "version" : 30, + "downgrade_to_29" : [], "downgrade_to_28" : [ "ALTER TABLE favorites RENAME TO temp_favorites;", "CREATE TABLE favorites(_id INTEGER PRIMARY KEY, title TEXT, intent TEXT, container INTEGER, screen INTEGER, cellX INTEGER, cellY INTEGER, spanX INTEGER, spanY INTEGER, itemType INTEGER, appWidgetId INTEGER NOT NULL DEFAULT - 1, iconPackage TEXT, iconResource TEXT, icon BLOB, appWidgetProvider TEXT, modified INTEGER NOT NULL DEFAULT 0, restored INTEGER NOT NULL DEFAULT 0, profileId INTEGER DEFAULT 0, rank INTEGER NOT NULL DEFAULT 0, options INTEGER NOT NULL DEFAULT 0);", diff --git a/src/com/android/launcher3/LauncherProvider.java b/src/com/android/launcher3/LauncherProvider.java index 49f20c6272..df09f29241 100644 --- a/src/com/android/launcher3/LauncherProvider.java +++ b/src/com/android/launcher3/LauncherProvider.java @@ -97,7 +97,7 @@ public class LauncherProvider extends ContentProvider { * Represents the schema of the database. Changes in scheme need not be backwards compatible. * When increasing the scheme version, ensure that downgrade_schema.json is updated */ - public static final int SCHEMA_VERSION = 29; + public static final int SCHEMA_VERSION = 30; public static final String AUTHORITY = BuildConfig.APPLICATION_ID + ".settings"; public static final String KEY_LAYOUT_PROVIDER_AUTHORITY = "KEY_LAYOUT_PROVIDER_AUTHORITY"; @@ -864,6 +864,11 @@ public class LauncherProvider extends ContentProvider { } } case 29: { + // Remove widget panel related leftover workspace items + db.delete(Favorites.TABLE_NAME, Utilities.createDbSelectionQuery( + Favorites.SCREEN, IntArray.wrap(-777, -778)), null); + } + case 30: { // DB Upgraded successfully return; } From 61cb7c0310d0cfc00593a75407f5c5f620cb7abf Mon Sep 17 00:00:00 2001 From: Alex Chau Date: Mon, 6 Sep 2021 12:35:31 +0100 Subject: [PATCH 4/6] Hide overview actions when focused task is not snapped - Overview actions is still click able when focused task is slightly off snap position and the alpha is between 0 and 1 - This is not desired and we should simply hide the actions when focused task is not snapped Bug: 199040817 Test: manual non grid and non-grid Change-Id: Ifda800fc4169a05c8128e7b3802d2ab4a5af4ae8 --- .../quickstep/views/OverviewActionsView.java | 9 ++---- .../android/quickstep/views/RecentsView.java | 29 +++++++++---------- 2 files changed, 17 insertions(+), 21 deletions(-) diff --git a/quickstep/src/com/android/quickstep/views/OverviewActionsView.java b/quickstep/src/com/android/quickstep/views/OverviewActionsView.java index 1b28c53cad..ac779b1eaf 100644 --- a/quickstep/src/com/android/quickstep/views/OverviewActionsView.java +++ b/quickstep/src/com/android/quickstep/views/OverviewActionsView.java @@ -53,13 +53,15 @@ public class OverviewActionsView extends FrameLayo @IntDef(flag = true, value = { HIDDEN_NON_ZERO_ROTATION, HIDDEN_NO_TASKS, - HIDDEN_NO_RECENTS}) + HIDDEN_NO_RECENTS, + HIDDEN_FOCUSED_SCROLL}) @Retention(RetentionPolicy.SOURCE) public @interface ActionsHiddenFlags { } public static final int HIDDEN_NON_ZERO_ROTATION = 1 << 0; public static final int HIDDEN_NO_TASKS = 1 << 1; public static final int HIDDEN_NO_RECENTS = 1 << 2; + public static final int HIDDEN_FOCUSED_SCROLL = 1 << 3; @IntDef(flag = true, value = { DISABLED_SCROLLING, @@ -76,7 +78,6 @@ public class OverviewActionsView extends FrameLayo private static final int INDEX_VISIBILITY_ALPHA = 1; private static final int INDEX_FULLSCREEN_ALPHA = 2; private static final int INDEX_HIDDEN_FLAGS_ALPHA = 3; - private static final int INDEX_SCROLL_ALPHA = 4; private final MultiValueAlpha mMultiValueAlpha; private View mSplitButton; @@ -196,10 +197,6 @@ public class OverviewActionsView extends FrameLayo return mMultiValueAlpha.getProperty(INDEX_FULLSCREEN_ALPHA); } - public AlphaProperty getScrollAlpha() { - return mMultiValueAlpha.getProperty(INDEX_SCROLL_ALPHA); - } - private void updateHorizontalPadding() { setPadding(mInsets.left, 0, mInsets.right, 0); } diff --git a/quickstep/src/com/android/quickstep/views/RecentsView.java b/quickstep/src/com/android/quickstep/views/RecentsView.java index 8c376440f7..8699d04317 100644 --- a/quickstep/src/com/android/quickstep/views/RecentsView.java +++ b/quickstep/src/com/android/quickstep/views/RecentsView.java @@ -29,7 +29,6 @@ import static com.android.launcher3.LauncherAnimUtils.VIEW_ALPHA; import static com.android.launcher3.LauncherState.BACKGROUND_APP; import static com.android.launcher3.QuickstepTransitionManager.RECENTS_LAUNCH_DURATION; import static com.android.launcher3.Utilities.EDGE_NAV_BAR; -import static com.android.launcher3.Utilities.boundToRange; import static com.android.launcher3.Utilities.mapToRange; import static com.android.launcher3.Utilities.squaredHypot; import static com.android.launcher3.Utilities.squaredTouchSlop; @@ -1691,28 +1690,28 @@ public abstract class RecentsView Date: Mon, 6 Sep 2021 14:46:18 +0000 Subject: [PATCH 5/6] Snap to task from other grid row if dismissing non-snapped focused task and not enough tasks remain in current grid row to snap to. Test: manual Fix: 196200215 Change-Id: I611ffc457769d57ac0d13657fafa73a4a741f877 --- quickstep/src/com/android/quickstep/views/RecentsView.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/quickstep/src/com/android/quickstep/views/RecentsView.java b/quickstep/src/com/android/quickstep/views/RecentsView.java index 8c376440f7..73173f3313 100644 --- a/quickstep/src/com/android/quickstep/views/RecentsView.java +++ b/quickstep/src/com/android/quickstep/views/RecentsView.java @@ -29,7 +29,6 @@ import static com.android.launcher3.LauncherAnimUtils.VIEW_ALPHA; import static com.android.launcher3.LauncherState.BACKGROUND_APP; import static com.android.launcher3.QuickstepTransitionManager.RECENTS_LAUNCH_DURATION; import static com.android.launcher3.Utilities.EDGE_NAV_BAR; -import static com.android.launcher3.Utilities.boundToRange; import static com.android.launcher3.Utilities.mapToRange; import static com.android.launcher3.Utilities.squaredHypot; import static com.android.launcher3.Utilities.squaredTouchSlop; @@ -3001,6 +3000,10 @@ public abstract class RecentsView Date: Mon, 6 Sep 2021 16:43:01 +0100 Subject: [PATCH 6/6] Fix crash when hotseat icon is dragged onto Workspace Test: manual Bug: 198820019 Change-Id: I53bb858feb7aad45472803b133ef3d026dd9f319 --- src/com/android/launcher3/Workspace.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java index 6ec48e5278..a21c8e30f1 100644 --- a/src/com/android/launcher3/Workspace.java +++ b/src/com/android/launcher3/Workspace.java @@ -647,7 +647,8 @@ public class Workspace extends PagedView if (mDragSourceInternal != null) { int dragSourceChildCount = mDragSourceInternal.getChildCount(); - if (isTwoPanelEnabled()) { + // If the icon was dragged from Hotseat, there is no page pair + if (isTwoPanelEnabled() && !(mDragSourceInternal.getParent() instanceof Hotseat)) { int pagePairScreenId = getPagePair(dragObject.dragInfo.screenId); CellLayout pagePair = mWorkspaceScreens.get(pagePairScreenId); if (pagePair == null) {