Scale folder if it doesn't fit the screen
Scale folder attrs if a full folder doesn't fit the screen width. This will make icons and text smaller than the workspace. As a follow-up, another bug will be created to only scale full folders instead of all folders. Bug: 271554689 Test: manually create a full folder, change the display size to large+ Change-Id: I47dc4bd4fe0c9eae989095fc1d179b81d350ef77
This commit is contained in:
parent
b4af207224
commit
7eee74b3f8
|
@ -28,6 +28,7 @@ import static com.android.launcher3.folder.ClippedFolderIconLayoutRule.ICON_OVER
|
|||
import static com.android.launcher3.icons.GraphicsUtils.getShapePath;
|
||||
import static com.android.launcher3.testing.shared.ResourceUtils.INVALID_RESOURCE_HANDLE;
|
||||
import static com.android.launcher3.testing.shared.ResourceUtils.pxFromDp;
|
||||
import static com.android.launcher3.testing.shared.ResourceUtils.roundPxValueFromFloat;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
|
@ -377,7 +378,7 @@ public class DeviceProfile {
|
|||
|
||||
folderLabelTextScale = res.getFloat(R.dimen.folder_label_text_scale);
|
||||
|
||||
if (inv.folderStyle != INVALID_RESOURCE_HANDLE) {
|
||||
if (isScalableGrid && inv.folderStyle != INVALID_RESOURCE_HANDLE) {
|
||||
TypedArray folderStyle = context.obtainStyledAttributes(inv.folderStyle,
|
||||
R.styleable.FolderStyle);
|
||||
// These are re-set in #updateFolderCellSize if the grid is not scalable
|
||||
|
@ -395,7 +396,7 @@ public class DeviceProfile {
|
|||
folderStyle.recycle();
|
||||
} else {
|
||||
folderCellLayoutBorderSpacePx = 0;
|
||||
folderFooterHeightPx = 0;
|
||||
folderFooterHeightPx = res.getDimensionPixelSize(R.dimen.folder_footer_height_default);
|
||||
folderContentPaddingTop = res.getDimensionPixelSize(R.dimen.folder_top_padding_default);
|
||||
}
|
||||
|
||||
|
@ -548,6 +549,9 @@ public class DeviceProfile {
|
|||
cellLayoutPadding);
|
||||
updateWorkspacePadding();
|
||||
|
||||
// Folder scaling requires correct workspace paddings
|
||||
updateAvailableFolderCellDimensions(res);
|
||||
|
||||
mMinHotseatIconSpacePx = res.getDimensionPixelSize(R.dimen.min_hotseat_icon_space);
|
||||
mMinHotseatQsbWidthPx = res.getDimensionPixelSize(R.dimen.min_hotseat_qsb_width);
|
||||
mMaxHotseatIconSpacePx = areNavButtonsInline
|
||||
|
@ -875,7 +879,6 @@ public class DeviceProfile {
|
|||
extraHeight = Math.max(0, maxHeight - getCellLayoutHeightSpecification());
|
||||
}
|
||||
|
||||
updateAvailableFolderCellDimensions(res);
|
||||
return Math.round(extraHeight);
|
||||
}
|
||||
|
||||
|
@ -1064,22 +1067,22 @@ public class DeviceProfile {
|
|||
private void updateAvailableFolderCellDimensions(Resources res) {
|
||||
updateFolderCellSize(1f, res);
|
||||
|
||||
// Don't let the folder get too close to the edges of the screen.
|
||||
int folderMargin = edgeMarginPx * 2;
|
||||
// For usability we can't have the folder use the whole width of the screen
|
||||
Point totalWorkspacePadding = getTotalWorkspacePadding();
|
||||
|
||||
// Check if the icons fit within the available height.
|
||||
// Check if the folder fit within the available height.
|
||||
float contentUsedHeight = folderCellHeightPx * inv.numFolderRows
|
||||
+ ((inv.numFolderRows - 1) * folderCellLayoutBorderSpacePx);
|
||||
int contentMaxHeight = availableHeightPx - totalWorkspacePadding.y - folderFooterHeightPx
|
||||
- folderMargin - folderContentPaddingTop;
|
||||
+ ((inv.numFolderRows - 1) * folderCellLayoutBorderSpacePx)
|
||||
+ folderFooterHeightPx
|
||||
+ folderContentPaddingTop;
|
||||
int contentMaxHeight = availableHeightPx - totalWorkspacePadding.y;
|
||||
float scaleY = contentMaxHeight / contentUsedHeight;
|
||||
|
||||
// Check if the icons fit within the available width.
|
||||
// Check if the folder fit within the available width.
|
||||
float contentUsedWidth = folderCellWidthPx * inv.numFolderColumns
|
||||
+ ((inv.numFolderColumns - 1) * folderCellLayoutBorderSpacePx);
|
||||
int contentMaxWidth = availableWidthPx - totalWorkspacePadding.x - folderMargin
|
||||
- folderContentPaddingLeftRight * 2;
|
||||
+ ((inv.numFolderColumns - 1) * folderCellLayoutBorderSpacePx)
|
||||
+ folderContentPaddingLeftRight * 2;
|
||||
int contentMaxWidth = availableWidthPx - totalWorkspacePadding.x;
|
||||
float scaleX = contentMaxWidth / contentUsedWidth;
|
||||
|
||||
float scale = Math.min(scaleX, scaleY);
|
||||
|
@ -1092,17 +1095,25 @@ public class DeviceProfile {
|
|||
float invIconSizeDp = inv.iconSize[mTypeIndex];
|
||||
folderChildIconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics, scale));
|
||||
folderChildTextSizePx = pxFromSp(inv.iconTextSize[mTypeIndex], mMetrics, scale);
|
||||
folderLabelTextSizePx = Math.max(pxFromSp(MIN_FOLDER_TEXT_SIZE_SP, mMetrics),
|
||||
folderLabelTextSizePx = Math.max(pxFromSp(MIN_FOLDER_TEXT_SIZE_SP, mMetrics, scale),
|
||||
(int) (folderChildTextSizePx * folderLabelTextScale));
|
||||
|
||||
int textHeight = Utilities.calculateTextHeight(folderChildTextSizePx);
|
||||
|
||||
if (isScalableGrid) {
|
||||
if (inv.folderStyle == INVALID_RESOURCE_HANDLE) {
|
||||
folderCellWidthPx = pxFromDp(getCellSize().x, mMetrics, scale);
|
||||
folderCellHeightPx = pxFromDp(getCellSize().y, mMetrics, scale);
|
||||
folderCellWidthPx = roundPxValueFromFloat(getCellSize().x * scale);
|
||||
folderCellHeightPx = roundPxValueFromFloat(getCellSize().y * scale);
|
||||
} else {
|
||||
folderCellWidthPx = roundPxValueFromFloat(folderCellWidthPx * scale);
|
||||
folderCellHeightPx = roundPxValueFromFloat(folderCellHeightPx * scale);
|
||||
}
|
||||
|
||||
folderContentPaddingTop = roundPxValueFromFloat(folderContentPaddingTop * scale);
|
||||
folderCellLayoutBorderSpacePx = roundPxValueFromFloat(
|
||||
folderCellLayoutBorderSpacePx * scale);
|
||||
folderFooterHeightPx = roundPxValueFromFloat(folderFooterHeightPx * scale);
|
||||
|
||||
folderContentPaddingLeftRight = folderCellLayoutBorderSpacePx;
|
||||
} else {
|
||||
int cellPaddingX = (int) (res.getDimensionPixelSize(R.dimen.folder_cell_x_padding)
|
||||
|
@ -1112,10 +1123,14 @@ public class DeviceProfile {
|
|||
|
||||
folderCellWidthPx = folderChildIconSizePx + 2 * cellPaddingX;
|
||||
folderCellHeightPx = folderChildIconSizePx + 2 * cellPaddingY + textHeight;
|
||||
folderContentPaddingTop = roundPxValueFromFloat(folderContentPaddingTop * scale);
|
||||
folderContentPaddingLeftRight =
|
||||
res.getDimensionPixelSize(R.dimen.folder_content_padding_left_right);
|
||||
folderFooterHeightPx =
|
||||
res.getDimensionPixelSize(R.dimen.folder_footer_height_default);
|
||||
roundPxValueFromFloat(
|
||||
res.getDimensionPixelSize(R.dimen.folder_footer_height_default)
|
||||
* scale);
|
||||
|
||||
}
|
||||
|
||||
folderChildDrawablePaddingPx = Math.max(0,
|
||||
|
|
|
@ -342,15 +342,15 @@ class DeviceProfileDumpTest : AbstractDeviceProfileTest() {
|
|||
"\ticonDrawablePaddingPx: 0.0px (0.0dp)\n" +
|
||||
"\tinv.numFolderRows: 4\n" +
|
||||
"\tinv.numFolderColumns: 4\n" +
|
||||
"\tfolderCellWidthPx: 142.0px (54.095238dp)\n" +
|
||||
"\tfolderCellHeightPx: 168.0px (64.0dp)\n" +
|
||||
"\tfolderChildIconSizePx: 108.0px (41.142857dp)\n" +
|
||||
"\tfolderChildTextSizePx: 28.0px (10.666667dp)\n" +
|
||||
"\tfolderChildDrawablePaddingPx: 7.0px (2.6666667dp)\n" +
|
||||
"\tfolderCellWidthPx: 173.0px (65.90476dp)\n" +
|
||||
"\tfolderCellHeightPx: 205.0px (78.09524dp)\n" +
|
||||
"\tfolderChildIconSizePx: 131.0px (49.904762dp)\n" +
|
||||
"\tfolderChildTextSizePx: 34.0px (12.952381dp)\n" +
|
||||
"\tfolderChildDrawablePaddingPx: 9.0px (3.4285715dp)\n" +
|
||||
"\tfolderCellLayoutBorderSpacePx: 0.0px (0.0dp)\n" +
|
||||
"\tfolderContentPaddingLeftRight: 21.0px (8.0dp)\n" +
|
||||
"\tfolderTopPadding: 63.0px (24.0dp)\n" +
|
||||
"\tfolderFooterHeight: 147.0px (56.0dp)\n" +
|
||||
"\tfolderTopPadding: 56.0px (21.333334dp)\n" +
|
||||
"\tfolderFooterHeight: 131.0px (49.904762dp)\n" +
|
||||
"\tbottomSheetTopPadding: 114.0px (43.42857dp)\n" +
|
||||
"\tbottomSheetOpenDuration: 267\n" +
|
||||
"\tbottomSheetCloseDuration: 267\n" +
|
||||
|
@ -474,15 +474,15 @@ class DeviceProfileDumpTest : AbstractDeviceProfileTest() {
|
|||
"\ticonDrawablePaddingPx: 0.0px (0.0dp)\n" +
|
||||
"\tinv.numFolderRows: 4\n" +
|
||||
"\tinv.numFolderColumns: 4\n" +
|
||||
"\tfolderCellWidthPx: 128.0px (48.761906dp)\n" +
|
||||
"\tfolderCellHeightPx: 152.0px (57.904762dp)\n" +
|
||||
"\tfolderChildIconSizePx: 98.0px (37.333332dp)\n" +
|
||||
"\tfolderChildTextSizePx: 25.0px (9.523809dp)\n" +
|
||||
"\tfolderChildDrawablePaddingPx: 6.0px (2.2857144dp)\n" +
|
||||
"\tfolderCellWidthPx: 163.0px (62.095238dp)\n" +
|
||||
"\tfolderCellHeightPx: 192.0px (73.14286dp)\n" +
|
||||
"\tfolderChildIconSizePx: 123.0px (46.857143dp)\n" +
|
||||
"\tfolderChildTextSizePx: 32.0px (12.190476dp)\n" +
|
||||
"\tfolderChildDrawablePaddingPx: 8.0px (3.047619dp)\n" +
|
||||
"\tfolderCellLayoutBorderSpacePx: 0.0px (0.0dp)\n" +
|
||||
"\tfolderContentPaddingLeftRight: 21.0px (8.0dp)\n" +
|
||||
"\tfolderTopPadding: 63.0px (24.0dp)\n" +
|
||||
"\tfolderFooterHeight: 147.0px (56.0dp)\n" +
|
||||
"\tfolderTopPadding: 53.0px (20.190475dp)\n" +
|
||||
"\tfolderFooterHeight: 123.0px (46.857143dp)\n" +
|
||||
"\tbottomSheetTopPadding: 114.0px (43.42857dp)\n" +
|
||||
"\tbottomSheetOpenDuration: 267\n" +
|
||||
"\tbottomSheetCloseDuration: 267\n" +
|
||||
|
@ -607,15 +607,15 @@ class DeviceProfileDumpTest : AbstractDeviceProfileTest() {
|
|||
"\ticonDrawablePaddingPx: 14.0px (7.0dp)\n" +
|
||||
"\tinv.numFolderRows: 3\n" +
|
||||
"\tinv.numFolderColumns: 3\n" +
|
||||
"\tfolderCellWidthPx: 397.0px (198.5dp)\n" +
|
||||
"\tfolderCellHeightPx: 371.0px (185.5dp)\n" +
|
||||
"\tfolderChildIconSizePx: 99.0px (49.5dp)\n" +
|
||||
"\tfolderChildTextSizePx: 23.0px (11.5dp)\n" +
|
||||
"\tfolderChildDrawablePaddingPx: 80.0px (40.0dp)\n" +
|
||||
"\tfolderCellWidthPx: 240.0px (120.0dp)\n" +
|
||||
"\tfolderCellHeightPx: 208.0px (104.0dp)\n" +
|
||||
"\tfolderChildIconSizePx: 120.0px (60.0dp)\n" +
|
||||
"\tfolderChildTextSizePx: 28.0px (14.0dp)\n" +
|
||||
"\tfolderChildDrawablePaddingPx: 16.0px (8.0dp)\n" +
|
||||
"\tfolderCellLayoutBorderSpacePx: 0.0px (0.0dp)\n" +
|
||||
"\tfolderContentPaddingLeftRight: 0.0px (0.0dp)\n" +
|
||||
"\tfolderTopPadding: 48.0px (24.0dp)\n" +
|
||||
"\tfolderFooterHeight: 0.0px (0.0dp)\n" +
|
||||
"\tfolderFooterHeight: 112.0px (56.0dp)\n" +
|
||||
"\tbottomSheetTopPadding: 104.0px (52.0dp)\n" +
|
||||
"\tbottomSheetOpenDuration: 500\n" +
|
||||
"\tbottomSheetCloseDuration: 500\n" +
|
||||
|
@ -740,15 +740,15 @@ class DeviceProfileDumpTest : AbstractDeviceProfileTest() {
|
|||
"\ticonDrawablePaddingPx: 14.0px (7.0dp)\n" +
|
||||
"\tinv.numFolderRows: 3\n" +
|
||||
"\tinv.numFolderColumns: 3\n" +
|
||||
"\tfolderCellWidthPx: 397.0px (198.5dp)\n" +
|
||||
"\tfolderCellHeightPx: 371.0px (185.5dp)\n" +
|
||||
"\tfolderChildIconSizePx: 99.0px (49.5dp)\n" +
|
||||
"\tfolderChildTextSizePx: 23.0px (11.5dp)\n" +
|
||||
"\tfolderChildDrawablePaddingPx: 80.0px (40.0dp)\n" +
|
||||
"\tfolderCellWidthPx: 240.0px (120.0dp)\n" +
|
||||
"\tfolderCellHeightPx: 208.0px (104.0dp)\n" +
|
||||
"\tfolderChildIconSizePx: 120.0px (60.0dp)\n" +
|
||||
"\tfolderChildTextSizePx: 28.0px (14.0dp)\n" +
|
||||
"\tfolderChildDrawablePaddingPx: 16.0px (8.0dp)\n" +
|
||||
"\tfolderCellLayoutBorderSpacePx: 0.0px (0.0dp)\n" +
|
||||
"\tfolderContentPaddingLeftRight: 0.0px (0.0dp)\n" +
|
||||
"\tfolderTopPadding: 48.0px (24.0dp)\n" +
|
||||
"\tfolderFooterHeight: 0.0px (0.0dp)\n" +
|
||||
"\tfolderFooterHeight: 112.0px (56.0dp)\n" +
|
||||
"\tbottomSheetTopPadding: 104.0px (52.0dp)\n" +
|
||||
"\tbottomSheetOpenDuration: 500\n" +
|
||||
"\tbottomSheetCloseDuration: 500\n" +
|
||||
|
@ -873,15 +873,15 @@ class DeviceProfileDumpTest : AbstractDeviceProfileTest() {
|
|||
"\ticonDrawablePaddingPx: 14.0px (7.0dp)\n" +
|
||||
"\tinv.numFolderRows: 3\n" +
|
||||
"\tinv.numFolderColumns: 3\n" +
|
||||
"\tfolderCellWidthPx: 408.0px (204.0dp)\n" +
|
||||
"\tfolderCellHeightPx: 648.0px (324.0dp)\n" +
|
||||
"\tfolderCellWidthPx: 204.0px (102.0dp)\n" +
|
||||
"\tfolderCellHeightPx: 240.0px (120.0dp)\n" +
|
||||
"\tfolderChildIconSizePx: 120.0px (60.0dp)\n" +
|
||||
"\tfolderChildTextSizePx: 28.0px (14.0dp)\n" +
|
||||
"\tfolderChildDrawablePaddingPx: 163.0px (81.5dp)\n" +
|
||||
"\tfolderChildDrawablePaddingPx: 27.0px (13.5dp)\n" +
|
||||
"\tfolderCellLayoutBorderSpacePx: 0.0px (0.0dp)\n" +
|
||||
"\tfolderContentPaddingLeftRight: 0.0px (0.0dp)\n" +
|
||||
"\tfolderTopPadding: 48.0px (24.0dp)\n" +
|
||||
"\tfolderFooterHeight: 0.0px (0.0dp)\n" +
|
||||
"\tfolderFooterHeight: 112.0px (56.0dp)\n" +
|
||||
"\tbottomSheetTopPadding: 704.0px (352.0dp)\n" +
|
||||
"\tbottomSheetOpenDuration: 500\n" +
|
||||
"\tbottomSheetCloseDuration: 500\n" +
|
||||
|
@ -1006,15 +1006,15 @@ class DeviceProfileDumpTest : AbstractDeviceProfileTest() {
|
|||
"\ticonDrawablePaddingPx: 14.0px (7.0dp)\n" +
|
||||
"\tinv.numFolderRows: 3\n" +
|
||||
"\tinv.numFolderColumns: 3\n" +
|
||||
"\tfolderCellWidthPx: 408.0px (204.0dp)\n" +
|
||||
"\tfolderCellHeightPx: 648.0px (324.0dp)\n" +
|
||||
"\tfolderCellWidthPx: 204.0px (102.0dp)\n" +
|
||||
"\tfolderCellHeightPx: 240.0px (120.0dp)\n" +
|
||||
"\tfolderChildIconSizePx: 120.0px (60.0dp)\n" +
|
||||
"\tfolderChildTextSizePx: 28.0px (14.0dp)\n" +
|
||||
"\tfolderChildDrawablePaddingPx: 163.0px (81.5dp)\n" +
|
||||
"\tfolderChildDrawablePaddingPx: 27.0px (13.5dp)\n" +
|
||||
"\tfolderCellLayoutBorderSpacePx: 0.0px (0.0dp)\n" +
|
||||
"\tfolderContentPaddingLeftRight: 0.0px (0.0dp)\n" +
|
||||
"\tfolderTopPadding: 48.0px (24.0dp)\n" +
|
||||
"\tfolderFooterHeight: 0.0px (0.0dp)\n" +
|
||||
"\tfolderFooterHeight: 112.0px (56.0dp)\n" +
|
||||
"\tbottomSheetTopPadding: 704.0px (352.0dp)\n" +
|
||||
"\tbottomSheetOpenDuration: 500\n" +
|
||||
"\tbottomSheetCloseDuration: 500\n" +
|
||||
|
|
Loading…
Reference in New Issue