From 7a6752da511df4fc43e4d39ce971035017835371 Mon Sep 17 00:00:00 2001 From: Thales Lima Date: Thu, 23 Sep 2021 14:31:00 +0100 Subject: [PATCH] launcher: create paddings for foldables This creates a new padding file that bring some foldables up to spec with VisD. For 2 panel layouts it now uses workspace margin instead of cell layout padding. Bug: 191879424 Fixes: 200035429 Test: checking paddings in HSV Change-Id: I11b8e1afd76f535368d4c26e31630ce496171e13 --- src/com/android/launcher3/DeviceProfile.java | 38 +++++-------------- src/com/android/launcher3/PagedView.java | 5 ++- src/com/android/launcher3/Workspace.java | 11 +++--- .../graphics/LauncherPreviewRenderer.java | 9 +++-- 4 files changed, 25 insertions(+), 38 deletions(-) diff --git a/src/com/android/launcher3/DeviceProfile.java b/src/com/android/launcher3/DeviceProfile.java index c7ae37384f..e739c37f22 100644 --- a/src/com/android/launcher3/DeviceProfile.java +++ b/src/com/android/launcher3/DeviceProfile.java @@ -293,10 +293,7 @@ public class DeviceProfile { : res.getDimensionPixelSize(R.dimen.dynamic_grid_cell_layout_padding); if (isTwoPanels) { - cellLayoutPaddingLeftRightPx = res.getDimensionPixelSize( - isLandscape - ? R.dimen.two_panels_home_side_padding_landscape - : R.dimen.two_panels_home_side_padding_portrait); + cellLayoutPaddingLeftRightPx = 0; cellLayoutBottomPaddingPx = 0; } else if (isLandscape) { cellLayoutPaddingLeftRightPx = 0; @@ -802,7 +799,9 @@ public class DeviceProfile { Point padding = getTotalWorkspacePadding(); int numColumns = isTwoPanels ? inv.numColumns * 2 : inv.numColumns; - int screenWidthPx = availableWidthPx - padding.x - 2 * cellLayoutPaddingLeftRightPx; + int cellLayoutTotalPadding = + isTwoPanels ? 4 * cellLayoutPaddingLeftRightPx : 2 * cellLayoutPaddingLeftRightPx; + int screenWidthPx = availableWidthPx - padding.x - cellLayoutTotalPadding; result.x = calculateCellWidth(screenWidthPx, cellLayoutBorderSpacingPx, numColumns); result.y = calculateCellHeight(availableHeightPx - padding.y - cellLayoutBottomPaddingPx, cellLayoutBorderSpacingPx, inv.numRows); @@ -832,33 +831,15 @@ public class DeviceProfile { padding.right = hotseatBarSizePx; } } else { + // Pad the bottom of the workspace with search/hotseat bar sizes int hotseatTop = hotseatBarSizePx; int paddingBottom = hotseatTop + workspacePageIndicatorHeight + workspaceBottomPadding - mWorkspacePageIndicatorOverlapWorkspace; - if (isTablet) { - // Pad the left and right of the workspace to ensure consistent spacing - // between all icons - // The amount of screen space available for left/right padding. - int availablePaddingX = Math.max(0, widthPx - ((inv.numColumns * cellWidthPx) + - ((inv.numColumns - 1) * cellWidthPx))); - availablePaddingX = (int) Math.min(availablePaddingX, - widthPx * MAX_HORIZONTAL_PADDING_PERCENT); - int hotseatVerticalPadding = hotseatBarTopPaddingPx + hotseatBarBottomPaddingPx; - int availablePaddingY = Math.max(0, heightPx - edgeMarginPx - paddingBottom - - (2 * inv.numRows * cellHeightPx) - hotseatVerticalPadding); - padding.set(availablePaddingX / 2, edgeMarginPx + availablePaddingY / 2, - availablePaddingX / 2, paddingBottom + availablePaddingY / 2); - if (isTwoPanels) { - padding.set(0, padding.top, 0, padding.bottom); - } - } else { - // Pad the top and bottom of the workspace with search/hotseat bar sizes - padding.set(desiredWorkspaceLeftRightMarginPx, - workspaceTopPadding + (isScalableGrid ? 0 : edgeMarginPx), - desiredWorkspaceLeftRightMarginPx, - paddingBottom); - } + padding.set(desiredWorkspaceLeftRightMarginPx, + (isScalableGrid ? workspaceTopPadding : edgeMarginPx), + desiredWorkspaceLeftRightMarginPx, + paddingBottom); } } @@ -1117,6 +1098,7 @@ public class DeviceProfile { writer.println(prefix + pxToDpStr("iconScale", iconScale)); writer.println(prefix + pxToDpStr("cellScaleToFit ", cellScaleToFit)); writer.println(prefix + pxToDpStr("extraSpace", extraSpace)); + writer.println(prefix + pxToDpStr("unscaled extraSpace", extraSpace / iconScale)); if (inv.devicePaddings != null) { int unscaledExtraSpace = (int) (extraSpace / iconScale); diff --git a/src/com/android/launcher3/PagedView.java b/src/com/android/launcher3/PagedView.java index d534c5d85d..523ac726f9 100644 --- a/src/com/android/launcher3/PagedView.java +++ b/src/com/android/launcher3/PagedView.java @@ -638,7 +638,10 @@ public abstract class PagedView extends ViewGrou } private int getPageWidthSize(int widthSize) { - return (widthSize - mInsets.left - mInsets.right) / getPanelCount(); + // It's necessary to add the padding back because it is remove when measuring children, + // like when MeasureSpec.getSize in CellLayout. + return (widthSize - mInsets.left - mInsets.right - getPaddingLeft() - getPaddingRight()) + / getPanelCount() + getPaddingLeft() + getPaddingRight(); } @Override diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java index c5e9dd2e45..6ce2930532 100644 --- a/src/com/android/launcher3/Workspace.java +++ b/src/com/android/launcher3/Workspace.java @@ -342,16 +342,15 @@ public class Workspace extends PagedView for (int i = 0; i < numberOfScreens; i++) { int paddingLeft = paddingLeftRight; int paddingRight = paddingLeftRight; + // Add missing cellLayout border in-between panels. if (panelCount > 1) { if (i % panelCount == leftPanelModulus) { - paddingLeft = paddingLeftRight; - paddingRight = grid.cellLayoutBorderSpacingPx / 2; + paddingRight += grid.cellLayoutBorderSpacingPx / 2; } else if (i % panelCount == rightPanelModulus) { // right side panel - paddingLeft = grid.cellLayoutBorderSpacingPx / 2; - paddingRight = paddingLeftRight; + paddingLeft += grid.cellLayoutBorderSpacingPx / 2; } else { // middle panel - paddingLeft = grid.cellLayoutBorderSpacingPx / 2; - paddingRight = grid.cellLayoutBorderSpacingPx / 2; + paddingLeft += grid.cellLayoutBorderSpacingPx / 2; + paddingRight += grid.cellLayoutBorderSpacingPx / 2; } } // SparseArrayMap doesn't keep the order diff --git a/src/com/android/launcher3/graphics/LauncherPreviewRenderer.java b/src/com/android/launcher3/graphics/LauncherPreviewRenderer.java index b4907e8772..e09b38b668 100644 --- a/src/com/android/launcher3/graphics/LauncherPreviewRenderer.java +++ b/src/com/android/launcher3/graphics/LauncherPreviewRenderer.java @@ -230,16 +230,19 @@ public class LauncherPreviewRenderer extends ContextWrapper CellLayout firstScreen = mRootView.findViewById(R.id.workspace); firstScreen.setPadding(mDp.workspacePadding.left + mDp.cellLayoutPaddingLeftRightPx, mDp.workspacePadding.top, - mDp.workspacePadding.right + mDp.cellLayoutBorderSpacingPx / 2, + (mDp.isTwoPanels ? mDp.cellLayoutBorderSpacingPx / 2 : mDp.workspacePadding.right) + + mDp.cellLayoutPaddingLeftRightPx, mDp.workspacePadding.bottom); mWorkspaceScreens.put(FIRST_SCREEN_ID, firstScreen); if (mDp.isTwoPanels) { CellLayout rightPanel = mRootView.findViewById(R.id.workspace_right); - rightPanel.setPadding(mDp.workspacePadding.left + mDp.cellLayoutBorderSpacingPx / 2, + rightPanel.setPadding( + mDp.cellLayoutBorderSpacingPx / 2 + mDp.cellLayoutPaddingLeftRightPx, mDp.workspacePadding.top, mDp.workspacePadding.right + mDp.cellLayoutPaddingLeftRightPx, - mDp.workspacePadding.bottom); + mDp.workspacePadding.bottom + ); mWorkspaceScreens.put(Workspace.SECOND_SCREEN_ID, rightPanel); }