From e445774ab5d76b35e527bfc873da6b9b1185b058 Mon Sep 17 00:00:00 2001 From: Thales Lima Date: Tue, 20 Jul 2021 16:46:38 +0100 Subject: [PATCH] launcher: correct page spacing for multiple panels This fixes 2 things: - adding the correct space between pages as insets (eg camera) were being discarded - adding the space between pages instead of between panels as was before This solution should work with more panels and don't create problems for phones, where panels = 1. Fixes 193194192 Test: manual testing in unfolded state in portrait and landscape, both rotations Change-Id: Ia3b148ceb773c6d5b6f8848ced07d7f9c1459e92 --- src/com/android/launcher3/PagedView.java | 9 ++++++-- src/com/android/launcher3/Workspace.java | 26 +++++++++++------------- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/src/com/android/launcher3/PagedView.java b/src/com/android/launcher3/PagedView.java index 20f5f9bb60..74b0d9c93e 100644 --- a/src/com/android/launcher3/PagedView.java +++ b/src/com/android/launcher3/PagedView.java @@ -709,6 +709,7 @@ public abstract class PagedView extends ViewGrou final int scrollOffsetStart = mOrientationHandler.getScrollOffsetStart(this, mInsets); final int scrollOffsetEnd = mOrientationHandler.getScrollOffsetEnd(this, mInsets); boolean pageScrollChanged = false; + int panelCount = getPanelCount(); for (int i = startIndex, childStart = scrollOffsetStart; i != endIndex; i += delta) { final View child = getPageAt(i); @@ -726,11 +727,15 @@ public abstract class PagedView extends ViewGrou pageScrollChanged = true; outPageScrolls[i] = pageScroll; } - childStart += primaryDimension + mPageSpacing + getChildGap(); + childStart += primaryDimension + getChildGap(); + + // This makes sure that the space is added after the page, not after each panel + if (i % panelCount == panelCount - 1) { + childStart += mPageSpacing; + } } } - int panelCount = getPanelCount(); if (panelCount > 1) { for (int i = 0; i < childCount; i++) { // In case we have multiple panels, always use left panel's page scroll for all diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java index a585be63a0..6c0e893ad8 100644 --- a/src/com/android/launcher3/Workspace.java +++ b/src/com/android/launcher3/Workspace.java @@ -315,9 +315,19 @@ public class Workspace extends PagedView // Increase our bottom insets so we don't overlap with the taskbar. mInsets.bottom += grid.nonOverlappingTaskbarInset; - if (grid.isTwoPanels) { - setPageSpacing(0); // we have two pages and we don't want any spacing + if (mWorkspaceFadeInAdjacentScreens) { + // In landscape mode the page spacing is set to the default. + setPageSpacing(grid.edgeMarginPx); + } else { + // In portrait, we want the pages spaced such that there is no + // overhang of the previous / next page into the current page viewport. + // We assume symmetrical padding in portrait mode. + int maxInsets = Math.max(insets.left, insets.right); + int maxPadding = Math.max(grid.edgeMarginPx, padding.left + 1); + setPageSpacing(Math.max(maxInsets, maxPadding)); + } + if (grid.isTwoPanels) { // Add left widget panel if it isn't already there if (!mWorkspaceScreens.containsKey(LEFT_PANEL_ID)) { int newCurrentPage = mCurrentPage + 1; @@ -325,18 +335,6 @@ public class Workspace extends PagedView setCurrentPage(newCurrentPage); } } else { - if (mWorkspaceFadeInAdjacentScreens) { - // In landscape mode the page spacing is set to the default. - setPageSpacing(grid.edgeMarginPx); - } else { - // In portrait, we want the pages spaced such that there is no - // overhang of the previous / next page into the current page viewport. - // We assume symmetrical padding in portrait mode. - int maxInsets = Math.max(insets.left, insets.right); - int maxPadding = Math.max(grid.edgeMarginPx, padding.left + 1); - setPageSpacing(Math.max(maxInsets, maxPadding)); - } - // Remove left widget panel if it is present if (mWorkspaceScreens.containsKey(LEFT_PANEL_ID)) { int newCurrentPage = mCurrentPage - 1;