From 941375eda4bb4ae06a85306b7fed24f1b4d9fd82 Mon Sep 17 00:00:00 2001 From: Jon Miranda Date: Wed, 31 Mar 2021 13:10:45 -0400 Subject: [PATCH] Only hide workspace labels if there is not enough space for it in the cell. - Also increases the spacing in all apps to reduce visual clitter. Bug: 175329686 Test: manual, change grid to mw, smaller grid, and verify labels Change-Id: I75c7fa9c69b8446ce0e48f4353fb225004e2a2fc --- src/com/android/launcher3/DeviceProfile.java | 42 ++++++++++---------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/src/com/android/launcher3/DeviceProfile.java b/src/com/android/launcher3/DeviceProfile.java index 1ce5f4dba6..a207731472 100644 --- a/src/com/android/launcher3/DeviceProfile.java +++ b/src/com/android/launcher3/DeviceProfile.java @@ -404,12 +404,7 @@ public class DeviceProfile { .setMultiWindowMode(true) .build(); - // If there isn't enough vertical cell padding with the labels displayed, hide the labels. - float workspaceCellPaddingY = profile.getCellSize().y - profile.iconSizePx - - iconDrawablePaddingPx - profile.iconTextSizePx; - if (workspaceCellPaddingY < profile.iconDrawablePaddingPx * 2) { - profile.adjustToHideWorkspaceLabels(); - } + profile.hideWorkspaceLabelsIfNotEnoughSpace(); // We use these scales to measure and layout the widgets using their full invariant profile // sizes and then draw them scaled and centered to fit in their multi-window mode cellspans. @@ -430,24 +425,32 @@ public class DeviceProfile { } /** - * Adjusts the profile so that the labels on the Workspace are hidden. + * Checks if there is enough space for labels on the workspace. + * If there is not, labels on the Workspace are hidden. * It is important to call this method after the All Apps variables have been set. */ - private void adjustToHideWorkspaceLabels() { - iconTextSizePx = 0; - iconDrawablePaddingPx = 0; - cellHeightPx = iconSizePx; - autoResizeAllAppsCells(); + private void hideWorkspaceLabelsIfNotEnoughSpace() { + float iconTextHeight = Utilities.calculateTextHeight(iconTextSizePx); + float workspaceCellPaddingY = getCellSize().y - iconSizePx - iconDrawablePaddingPx + - iconTextHeight; + + // We want enough space so that the text is closer to its corresponding icon. + if (workspaceCellPaddingY < iconTextHeight) { + iconTextSizePx = 0; + iconDrawablePaddingPx = 0; + cellHeightPx = iconSizePx; + autoResizeAllAppsCells(); + } } /** * Re-computes the all-apps cell size to be independent of workspace */ public void autoResizeAllAppsCells() { - int topBottomPadding = allAppsIconDrawablePaddingPx * (isVerticalBarLayout() ? 2 : 1); + int textHeight = Utilities.calculateTextHeight(allAppsIconTextSizePx); + int topBottomPadding = textHeight; allAppsCellHeightPx = allAppsIconSizePx + allAppsIconDrawablePaddingPx - + Utilities.calculateTextHeight(allAppsIconTextSizePx) - + topBottomPadding * 2; + + textHeight + (topBottomPadding * 2); } /** @@ -536,9 +539,7 @@ public class DeviceProfile { allAppsIconSizePx = pxFromDp(inv.allAppsIconSize, mInfo.metrics); allAppsIconTextSizePx = Utilities.pxFromSp(inv.allAppsIconTextSize, mInfo.metrics); allAppsIconDrawablePaddingPx = iconDrawablePaddingOriginalPx; - // We use 4 below to ensure labels are closer to their corresponding icon. - allAppsCellHeightPx = Math.round(allAppsIconSizePx + allAppsIconTextSizePx - + (4 * allAppsIconDrawablePaddingPx)); + autoResizeAllAppsCells(); } else { allAppsIconSizePx = iconSizePx; allAppsIconTextSizePx = iconTextSizePx; @@ -547,9 +548,8 @@ public class DeviceProfile { } allAppsCellWidthPx = allAppsIconSizePx + allAppsIconDrawablePaddingPx; - if (isVerticalBarLayout()) { - // Always hide the Workspace text with vertical bar layout. - adjustToHideWorkspaceLabels(); + if (isVerticalLayout) { + hideWorkspaceLabelsIfNotEnoughSpace(); } // Hotseat