From 823da2283337a43f238c7665364fa0abe14e8df4 Mon Sep 17 00:00:00 2001 From: Jon Miranda Date: Tue, 23 Mar 2021 08:08:45 -0400 Subject: [PATCH] Folder cell should match grid cell aspect ratio if isScalableGrid is true. Bug: 175329686 Test: inspected with go/web-hv Change-Id: I652c696d8ae58b7009b7310bb926b279b9477724 --- src/com/android/launcher3/CellLayout.java | 5 ++- src/com/android/launcher3/DeviceProfile.java | 38 +++++++++++++------- 2 files changed, 29 insertions(+), 14 deletions(-) diff --git a/src/com/android/launcher3/CellLayout.java b/src/com/android/launcher3/CellLayout.java index 9df8d44d58..de11eae825 100644 --- a/src/com/android/launcher3/CellLayout.java +++ b/src/com/android/launcher3/CellLayout.java @@ -213,7 +213,10 @@ public class CellLayout extends ViewGroup { mActivity = ActivityContext.lookupContext(context); DeviceProfile deviceProfile = mActivity.getDeviceProfile(); - mBorderSpacing = deviceProfile.cellLayoutBorderSpacingPx; + mBorderSpacing = mContainerType == FOLDER + ? deviceProfile.folderCellLayoutBorderSpacingPx + : deviceProfile.cellLayoutBorderSpacingPx; + mCellWidth = mCellHeight = -1; mFixedCellWidth = mFixedCellHeight = -1; diff --git a/src/com/android/launcher3/DeviceProfile.java b/src/com/android/launcher3/DeviceProfile.java index fa19ee6918..4c9c53330b 100644 --- a/src/com/android/launcher3/DeviceProfile.java +++ b/src/com/android/launcher3/DeviceProfile.java @@ -122,6 +122,7 @@ public class DeviceProfile { public int folderIconOffsetYPx; // Folder content + public int folderCellLayoutBorderSpacingPx; public int folderContentPaddingLeftRight; public int folderContentPaddingTop; @@ -248,6 +249,7 @@ public class DeviceProfile { setCellLayoutBorderSpacing(pxFromDp(inv.borderSpacing, mInfo.metrics, 1f)); cellLayoutBorderSpacingOriginalPx = cellLayoutBorderSpacingPx; + folderCellLayoutBorderSpacingPx = cellLayoutBorderSpacingPx; int cellLayoutPaddingLeftRightMultiplier = !isVerticalBarLayout() && isTablet ? PORTRAIT_TABLET_LEFT_RIGHT_PADDING_MULTIPLIER : 1; @@ -332,13 +334,7 @@ public class DeviceProfile { } private void setCellLayoutBorderSpacing(int borderSpacing) { - if (isScalableGrid) { - cellLayoutBorderSpacingPx = borderSpacing; - folderContentPaddingLeftRight = borderSpacing; - folderContentPaddingTop = borderSpacing; - } else { - cellLayoutBorderSpacingPx = 0; - } + cellLayoutBorderSpacingPx = isScalableGrid ? borderSpacing : 0; } /** @@ -565,14 +561,14 @@ public class DeviceProfile { // Check if the icons fit within the available height. float contentUsedHeight = folderCellHeightPx * inv.numFolderRows - + ((inv.numFolderRows - 1) * cellLayoutBorderSpacingPx); + + ((inv.numFolderRows - 1) * folderCellLayoutBorderSpacingPx); int contentMaxHeight = availableHeightPx - totalWorkspacePadding.y - folderBottomPanelSize - folderMargin - folderContentPaddingTop; float scaleY = contentMaxHeight / contentUsedHeight; // Check if the icons fit within the available width. float contentUsedWidth = folderCellWidthPx * inv.numFolderColumns - + ((inv.numFolderColumns - 1) * cellLayoutBorderSpacingPx); + + ((inv.numFolderColumns - 1) * folderCellLayoutBorderSpacingPx); int contentMaxWidth = availableWidthPx - totalWorkspacePadding.x - folderMargin - folderContentPaddingLeftRight * 2; float scaleX = contentMaxWidth / contentUsedWidth; @@ -590,11 +586,25 @@ public class DeviceProfile { folderLabelTextSizePx = (int) (folderChildTextSizePx * folderLabelTextScale); int textHeight = Utilities.calculateTextHeight(folderChildTextSizePx); - int cellPaddingX = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_x_padding) * scale); - int cellPaddingY = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_y_padding) * scale); - folderCellWidthPx = folderChildIconSizePx + 2 * cellPaddingX; - folderCellHeightPx = folderChildIconSizePx + 2 * cellPaddingY + textHeight; + if (isScalableGrid) { + folderCellWidthPx = (int) (cellWidthPx * scale); + folderCellHeightPx = (int) (cellHeightPx * scale); + + int borderSpacing = (int) (cellLayoutBorderSpacingOriginalPx * scale); + folderCellLayoutBorderSpacingPx = borderSpacing; + folderContentPaddingLeftRight = borderSpacing; + folderContentPaddingTop = borderSpacing; + } else { + int cellPaddingX = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_x_padding) + * scale); + int cellPaddingY = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_y_padding) + * scale); + + folderCellWidthPx = folderChildIconSizePx + 2 * cellPaddingX; + folderCellHeightPx = folderChildIconSizePx + 2 * cellPaddingY + textHeight; + } + folderChildDrawablePaddingPx = Math.max(0, (folderCellHeightPx - folderChildIconSizePx - textHeight) / 3); } @@ -846,6 +856,8 @@ public class DeviceProfile { writer.println(prefix + pxToDpStr("folderChildTextSizePx", folderChildTextSizePx)); writer.println(prefix + pxToDpStr("folderChildDrawablePaddingPx", folderChildDrawablePaddingPx)); + writer.println(prefix + pxToDpStr("folderCellLayoutBorderSpacingPx", + folderCellLayoutBorderSpacingPx)); writer.println(prefix + pxToDpStr("cellLayoutBorderSpacingPx", cellLayoutBorderSpacingPx));