From 12fae110b77e3fdc5a3e3bdc993b44e578ef0290 Mon Sep 17 00:00:00 2001 From: Jordan Silva Date: Mon, 26 Jun 2023 12:51:01 +0100 Subject: [PATCH] Decrease icon size by steps for folders Resize the icon so that it fits within the cell. This will stop the icon from being cut off if it is larger than the cell. Fix: 288075868 Test: DeviceProfileAlternativeDisplaysDumpTest Test: DeviceProfileResponsiveAlternativeDisplaysDumpTest Flag: ENABLE_RESPONSIVE_WORKSPACE Change-Id: I67c703d89bb7f54a457793490b8251584363dedc --- src/com/android/launcher3/DeviceProfile.java | 31 ++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/src/com/android/launcher3/DeviceProfile.java b/src/com/android/launcher3/DeviceProfile.java index 463a243f6c..814a0f9324 100644 --- a/src/com/android/launcher3/DeviceProfile.java +++ b/src/com/android/launcher3/DeviceProfile.java @@ -1258,6 +1258,32 @@ public class DeviceProfile { mResponsiveHeightSpec.getGutterPx()); folderContentPaddingLeftRight = mResponsiveFolderWidthSpec.getStartPaddingPx(); + + // Reduce icon width if it's wider than the expected folder cell width + if (folderCellWidthPx < folderChildIconSizePx) { + folderChildIconSizePx = mIconSizeSteps.getIconSmallerThan(folderCellWidthPx); + } + + // Recalculating padding and cell height + folderChildDrawablePaddingPx = getNormalizedFolderChildDrawablePaddingPx(textHeight); + int folderCellContentHeight = folderChildIconSizePx + folderChildDrawablePaddingPx + + textHeight; + + // Reduce the icon in height when it's taller than the expected cell height + while (folderChildIconSizePx > mIconSizeSteps.minimumIconSize() + && folderCellContentHeight > folderCellHeightPx) { + folderChildDrawablePaddingPx -= folderCellContentHeight - folderCellHeightPx; + if (folderChildDrawablePaddingPx < 0) { + // get a smaller icon size + folderChildIconSizePx = mIconSizeSteps.getNextLowerIconSize( + folderChildIconSizePx); + folderChildDrawablePaddingPx = + getNormalizedFolderChildDrawablePaddingPx(textHeight); + } + // calculate new cellContentHeight + folderCellContentHeight = folderChildIconSizePx + folderChildDrawablePaddingPx + + textHeight; + } } else if (mIsScalableGrid) { if (inv.folderStyle == INVALID_RESOURCE_HANDLE) { folderCellWidthPx = roundPxValueFromFloat(getCellSize().x * scale); @@ -1275,6 +1301,8 @@ public class DeviceProfile { folderFooterHeightPx = roundPxValueFromFloat(folderFooterHeightPx * scale); folderContentPaddingLeftRight = folderCellLayoutBorderSpacePx.x; + + folderChildDrawablePaddingPx = getNormalizedFolderChildDrawablePaddingPx(textHeight); } else { int cellPaddingX = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_x_padding) * scale); @@ -1291,9 +1319,8 @@ public class DeviceProfile { res.getDimensionPixelSize(R.dimen.folder_footer_height_default) * scale); + folderChildDrawablePaddingPx = getNormalizedFolderChildDrawablePaddingPx(textHeight); } - - folderChildDrawablePaddingPx = getNormalizedFolderChildDrawablePaddingPx(textHeight); } public void updateInsets(Rect insets) {