From c1b2399540fb2d9c4830da7ac73cc2fb18c52cdf Mon Sep 17 00:00:00 2001 From: Jon Miranda Date: Tue, 13 Dec 2016 08:57:36 -0800 Subject: Scale folders to fit within the available height and width. * In the previous implementation, the folder icon size would not get updated if the cell height/width was set to the minimum value not including the folderChildIconSizePx AND the usedLength was less than the maxLength. * The bug is only really noticeable in an unlikely multi-window landscape mode, which is why it was not noticed before. Change-Id: I776c6f710e081645cff891487022cf787869ee3f --- src/com/android/launcher3/DeviceProfile.java | 34 ++++++++++++++++------------ 1 file changed, 20 insertions(+), 14 deletions(-) (limited to 'src/com/android/launcher3/DeviceProfile.java') diff --git a/src/com/android/launcher3/DeviceProfile.java b/src/com/android/launcher3/DeviceProfile.java index fbff4eb3b..f79d66659 100644 --- a/src/com/android/launcher3/DeviceProfile.java +++ b/src/com/android/launcher3/DeviceProfile.java @@ -315,19 +315,28 @@ public class DeviceProfile { + res.getDimensionPixelSize(R.dimen.folder_label_padding_bottom) + Utilities.calculateTextHeight(res.getDimension(R.dimen.folder_label_text_size)); - updateFolderCellSize(1f, dm, res, folderBottomPanelSize); + updateFolderCellSize(1f, dm, res); - // Check to see if the icons fit within the available height. If not, then scale down. - float usedHeight = (folderCellHeightPx * inv.numFolderRows) + folderBottomPanelSize; - int maxHeight = availableHeightPx - getTotalWorkspacePadding().y - (2 * edgeMarginPx); - if (usedHeight > maxHeight) { - float scale = maxHeight / usedHeight; - updateFolderCellSize(scale, dm, res, folderBottomPanelSize); + // Don't let the folder get too close to the edges of the screen. + int folderMargin = 4 * edgeMarginPx; + + // Check if the icons fit within the available height. + float usedHeight = folderCellHeightPx * inv.numFolderRows + folderBottomPanelSize; + int maxHeight = availableHeightPx - getTotalWorkspacePadding().y - folderMargin; + float scaleY = maxHeight / usedHeight; + + // Check if the icons fit within the available width. + float usedWidth = folderCellWidthPx * inv.numFolderColumns; + int maxWidth = availableWidthPx - getTotalWorkspacePadding().x - folderMargin; + float scaleX = maxWidth / usedWidth; + + float scale = Math.min(scaleX, scaleY); + if (scale < 1f) { + updateFolderCellSize(scale, dm, res); } } - private void updateFolderCellSize(float scale, DisplayMetrics dm, Resources res, - int folderBottomPanelSize) { + private void updateFolderCellSize(float scale, DisplayMetrics dm, Resources res) { folderChildIconSizePx = (int) (Utilities.pxFromDp(inv.iconSize, dm) * scale); folderChildTextSizePx = (int) (res.getDimensionPixelSize(R.dimen.folder_child_text_size) * scale); @@ -336,11 +345,8 @@ public class DeviceProfile { int cellPaddingX = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_x_padding) * scale); int cellPaddingY = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_y_padding) * scale); - // Don't let the folder get too close to the edges of the screen. - folderCellWidthPx = Math.min(folderChildIconSizePx + 2 * cellPaddingX, - (availableWidthPx - 4 * edgeMarginPx) / inv.numFolderColumns); - folderCellHeightPx = Math.min(folderChildIconSizePx + 2 * cellPaddingY + textHeight, - (availableHeightPx - 4 * edgeMarginPx - folderBottomPanelSize) / inv.numFolderRows); + folderCellWidthPx = folderChildIconSizePx + 2 * cellPaddingX; + folderCellHeightPx = folderChildIconSizePx + 2 * cellPaddingY + textHeight; folderChildDrawablePaddingPx = Math.max(0, (folderCellHeightPx - folderChildIconSizePx - textHeight) / 3); } -- cgit v1.2.3