diff options
author | Jon Miranda <jonmiranda@google.com> | 2016-12-13 08:57:36 -0800 |
---|---|---|
committer | Jon Miranda <jonmiranda@google.com> | 2016-12-13 11:09:13 -0800 |
commit | c1b2399540fb2d9c4830da7ac73cc2fb18c52cdf (patch) | |
tree | 8850c86f63a4f439f0db710b9da16452191f1a49 /src/com/android/launcher3/DeviceProfile.java | |
parent | 824c540f1911101321ebe7f05cb0885a4922e363 (diff) | |
download | android_packages_apps_Trebuchet-c1b2399540fb2d9c4830da7ac73cc2fb18c52cdf.tar.gz android_packages_apps_Trebuchet-c1b2399540fb2d9c4830da7ac73cc2fb18c52cdf.tar.bz2 android_packages_apps_Trebuchet-c1b2399540fb2d9c4830da7ac73cc2fb18c52cdf.zip |
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
Diffstat (limited to 'src/com/android/launcher3/DeviceProfile.java')
-rw-r--r-- | src/com/android/launcher3/DeviceProfile.java | 34 |
1 files changed, 20 insertions, 14 deletions
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); } |