Resize icon and text size for AllApps when it doesn't fit the cell
Bug: 287975993
Fix: 309489796
Flag: ACONFIG com.android.launcher3.enable_responsive_workspace TEAMFOOD
Test: DeviceProfileDumpTest
Test: DeviceProfileResponsiveDumpTest
Test: ResponsiveHomeScreenImageTest
Test: ResponsiveFolderImageTest
Test: ResponsiveAllAppsImageTest
Change-Id: I1dda073b558a7f4540d5fe5c438fa796a70b6ddd
diff --git a/src/com/android/launcher3/DeviceProfile.java b/src/com/android/launcher3/DeviceProfile.java
index 59f3f0d..a8266ec 100644
--- a/src/com/android/launcher3/DeviceProfile.java
+++ b/src/com/android/launcher3/DeviceProfile.java
@@ -591,7 +591,8 @@
if (mIsResponsiveGrid) {
int availableResponsiveWidth =
availableWidthPx - (isVerticalBarLayout() ? hotseatBarSizePx : 0);
- int numColumns = getPanelCount() * inv.numColumns;
+ int numWorkspaceColumns = getPanelCount() * inv.numColumns;
+ int numAllAppsColumns = getPanelCount() * inv.numAllAppsColumns;
// don't use availableHeightPx because it subtracts mInsets.bottom
int availableResponsiveHeight = heightPx - mInsets.top
- (isVerticalBarLayout() ? 0 : hotseatBarSizePx);
@@ -602,7 +603,7 @@
isTwoPanels ? inv.workspaceSpecsTwoPanelId : inv.workspaceSpecsId),
ResponsiveSpecType.Workspace);
mResponsiveWidthSpec = workspaceSpecs.getCalculatedSpec(responsiveAspectRatio,
- DimensionType.WIDTH, numColumns, availableResponsiveWidth);
+ DimensionType.WIDTH, numWorkspaceColumns, availableResponsiveWidth);
mResponsiveHeightSpec = workspaceSpecs.getCalculatedSpec(responsiveAspectRatio,
DimensionType.HEIGHT, inv.numRows, availableResponsiveHeight);
@@ -611,7 +612,7 @@
isTwoPanels ? inv.allAppsSpecsTwoPanelId : inv.allAppsSpecsId),
ResponsiveSpecType.AllApps);
mAllAppsResponsiveWidthSpec = allAppsSpecs.getCalculatedSpec(responsiveAspectRatio,
- DimensionType.WIDTH, numColumns, availableWidthPx,
+ DimensionType.WIDTH, numAllAppsColumns, availableWidthPx,
mResponsiveWidthSpec);
mAllAppsResponsiveHeightSpec = allAppsSpecs.getCalculatedSpec(responsiveAspectRatio,
DimensionType.HEIGHT, inv.numRows, heightPx - mInsets.top,
@@ -1017,12 +1018,16 @@
+ cellLayoutPaddingPx.left + cellLayoutPaddingPx.right;
}
- private int getNormalizedIconDrawablePadding() {
+ private int getNormalizedIconDrawablePadding(int iconSizePx, int iconDrawablePadding) {
// TODO(b/235886078): workaround needed because of this bug
// Icons are 10% larger on XML than their visual size,
// so remove that extra space to get labels closer to the correct padding
int iconVisibleSizePx = (int) Math.round(ICON_VISIBLE_AREA_FACTOR * iconSizePx);
- return Math.max(0, mIconDrawablePaddingOriginalPx - ((iconSizePx - iconVisibleSizePx) / 2));
+ return Math.max(0, iconDrawablePadding - ((iconSizePx - iconVisibleSizePx) / 2));
+ }
+
+ private int getNormalizedIconDrawablePadding() {
+ return getNormalizedIconDrawablePadding(iconSizePx, mIconDrawablePaddingOriginalPx);
}
private int getNormalizedFolderChildDrawablePaddingPx(int textHeight) {
@@ -1160,7 +1165,7 @@
// All apps
if (mIsResponsiveGrid) {
- updateAllAppsWithResponsiveMeasures();
+ updateAllAppsWithResponsiveMeasures(res);
} else {
updateAllAppsIconSize(scale, res);
}
@@ -1259,11 +1264,7 @@
}
}
- private void updateAllAppsWithResponsiveMeasures() {
- allAppsIconSizePx = iconSizePx;
- allAppsIconTextSizePx = iconTextSizePx;
- allAppsIconDrawablePaddingPx = iconDrawablePaddingPx;
-
+ private void updateAllAppsWithResponsiveMeasures(Resources res) {
allAppsBorderSpacePx = new Point(
mAllAppsResponsiveWidthSpec.getGutterPx(),
mAllAppsResponsiveHeightSpec.getGutterPx()
@@ -1277,6 +1278,47 @@
int halfBorder = allAppsBorderSpacePx.x / 2;
allAppsPadding.left = mAllAppsResponsiveWidthSpec.getStartPaddingPx() - halfBorder;
allAppsPadding.right = mAllAppsResponsiveWidthSpec.getEndPaddingPx() - halfBorder;
+
+ // TODO(b/287975993): Remove this after icon size is extracted to responsive grid
+ // Copy icon size from the workspace when spec is matchWorkspace or
+ // use the default all apps icon size
+ if (mAllAppsResponsiveHeightSpec.isCellSizeMatchWorkspace()
+ || mAllAppsResponsiveWidthSpec.isCellSizeMatchWorkspace()) {
+ allAppsIconSizePx = iconSizePx;
+ allAppsIconTextSizePx = iconTextSizePx;
+ allAppsIconDrawablePaddingPx = iconDrawablePaddingPx;
+ } else {
+ allAppsIconSizePx = pxFromDp(inv.allAppsIconSize[mTypeIndex], mMetrics);
+ allAppsIconTextSizePx = pxFromSp(inv.allAppsIconTextSize[mTypeIndex], mMetrics);
+ allAppsIconDrawablePaddingPx = res.getDimensionPixelSize(
+ R.dimen.all_apps_icon_drawable_padding);
+ allAppsIconDrawablePaddingPx = getNormalizedIconDrawablePadding(allAppsIconSizePx,
+ allAppsIconDrawablePaddingPx);
+ }
+
+ // Reduce the size of the app icon if it doesn't fit
+ if (allAppsCellWidthPx < allAppsIconSizePx) {
+ // get a smaller icon size
+ allAppsIconSizePx = mIconSizeSteps.getIconSmallerThan(allAppsCellWidthPx);
+ }
+
+ CellContentDimensions cellContentDimensions = new CellContentDimensions(
+ allAppsIconSizePx, allAppsIconDrawablePaddingPx, (int) allAppsIconTextSizePx);
+
+ if (allAppsCellHeightPx < cellContentDimensions.getCellContentHeight()) {
+ if (isVerticalBarLayout()) {
+ if (allAppsCellHeightPx < iconSizePx) {
+ cellContentDimensions.setIconSizePx(
+ mIconSizeSteps.getIconSmallerThan(allAppsCellHeightPx));
+ }
+ } else {
+ cellContentDimensions.resizeToFitCellHeight(allAppsCellHeightPx,
+ mIconSizeSteps);
+ }
+ allAppsIconSizePx = cellContentDimensions.getIconSizePx();
+ allAppsIconDrawablePaddingPx = cellContentDimensions.getIconDrawablePaddingPx();
+ allAppsIconTextSizePx = cellContentDimensions.getIconTextSizePx();
+ }
}
/**