diff --git a/quickstep/tests/src/com/android/quickstep/HotseatWidthCalculationTest.kt b/quickstep/tests/src/com/android/quickstep/HotseatWidthCalculationTest.kt index a347156769..b1ba4c697f 100644 --- a/quickstep/tests/src/com/android/quickstep/HotseatWidthCalculationTest.kt +++ b/quickstep/tests/src/com/android/quickstep/HotseatWidthCalculationTest.kt @@ -47,7 +47,7 @@ class HotseatWidthCalculationTest : FakeInvariantDeviceProfileTest() { assertThat(dp.getHotseatLayoutPadding(context).right).isEqualTo(580) assertThat(dp.isQsbInline).isFalse() - assertThat(dp.hotseatQsbWidth).isEqualTo(1445) + assertThat(dp.hotseatQsbWidth).isEqualTo(1435) } /** @@ -69,7 +69,7 @@ class HotseatWidthCalculationTest : FakeInvariantDeviceProfileTest() { assertThat(dp.getHotseatLayoutPadding(context).right).isEqualTo(550) assertThat(dp.isQsbInline).isFalse() - assertThat(dp.hotseatQsbWidth).isEqualTo(1080) + assertThat(dp.hotseatQsbWidth).isEqualTo(1070) } /** @@ -90,7 +90,7 @@ class HotseatWidthCalculationTest : FakeInvariantDeviceProfileTest() { assertThat(dp.getHotseatLayoutPadding(context).right).isEqualTo(759) assertThat(dp.isQsbInline).isFalse() - assertThat(dp.hotseatQsbWidth).isEqualTo(1468) + assertThat(dp.hotseatQsbWidth).isEqualTo(1455) } /** @@ -115,7 +115,7 @@ class HotseatWidthCalculationTest : FakeInvariantDeviceProfileTest() { assertThat(dp.getHotseatLayoutPadding(context).right).isEqualTo(1040) assertThat(dp.isQsbInline).isFalse() - assertThat(dp.hotseatQsbWidth).isEqualTo(1233) + assertThat(dp.hotseatQsbWidth).isEqualTo(1223) } /** This is a case when after setting the hotseat, the QSB width needs to be changed to fit */ diff --git a/src/com/android/launcher3/DeviceProfile.java b/src/com/android/launcher3/DeviceProfile.java index 1ca7da9d44..53297f260c 100644 --- a/src/com/android/launcher3/DeviceProfile.java +++ b/src/com/android/launcher3/DeviceProfile.java @@ -789,14 +789,16 @@ public class DeviceProfile { * width of the hotseat. */ private int calculateQsbWidth(int hotseatBorderSpace) { + int iconExtraSpacePx = iconSizePx - getIconVisibleSizePx(iconSizePx); if (isQsbInline) { int columns = getPanelCount() * inv.numColumns; return getIconToIconWidthForColumns(columns) - iconSizePx * numShownHotseatIcons - - hotseatBorderSpace * numShownHotseatIcons; + - hotseatBorderSpace * numShownHotseatIcons + - iconExtraSpacePx; } else { int columns = inv.hotseatColumnSpan[mTypeIndex]; - return getIconToIconWidthForColumns(columns); + return getIconToIconWidthForColumns(columns) - iconExtraSpacePx; } } @@ -1074,11 +1076,8 @@ public class DeviceProfile { } 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 = Math.round(ICON_VISIBLE_AREA_FACTOR * iconSizePx); - return Math.max(0, iconDrawablePadding - ((iconSizePx - iconVisibleSizePx) / 2)); + return Math.max(0, iconDrawablePadding + - ((iconSizePx - getIconVisibleSizePx(iconSizePx)) / 2)); } private int getNormalizedIconDrawablePadding() { @@ -1091,8 +1090,7 @@ public class DeviceProfile { // so remove that extra space to get labels closer to the correct padding int drawablePadding = (folderCellHeightPx - folderChildIconSizePx - textHeight) / 3; - int iconVisibleSizePx = Math.round(ICON_VISIBLE_AREA_FACTOR * folderChildIconSizePx); - int iconSizeDiff = folderChildIconSizePx - iconVisibleSizePx; + int iconSizeDiff = folderChildIconSizePx - getIconVisibleSizePx(folderChildIconSizePx); return Math.max(0, drawablePadding - iconSizeDiff / 2); } @@ -1788,7 +1786,8 @@ public class DeviceProfile { } } else if (mIsScalableGrid) { - int sideSpacing = (availableWidthPx - hotseatQsbWidth) / 2; + int iconExtraSpacePx = iconSizePx - getIconVisibleSizePx(iconSizePx); + int sideSpacing = (availableWidthPx - (hotseatQsbWidth + iconExtraSpacePx)) / 2; hotseatBarPadding.set(sideSpacing, 0, sideSpacing, @@ -1827,13 +1826,24 @@ public class DeviceProfile { availableWidthPx - allAppsSpacing, 0 /* borderSpace */, numShownAllAppsColumns); - int iconVisibleSize = Math.round(ICON_VISIBLE_AREA_FACTOR * allAppsIconSizePx); - int iconAlignmentMargin = (cellWidth - iconVisibleSize) / 2; + int iconAlignmentMargin = (cellWidth - getIconVisibleSizePx(allAppsIconSizePx)) / 2; return (Utilities.isRtl(context.getResources()) ? allAppsPadding.right : allAppsPadding.left) + iconAlignmentMargin; } + /** + * 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 + * some dimensions correct. + * + * When this bug is resolved this method will no longer be needed and we would be able to + * replace all instances where this method is called with iconSizePx. + */ + private int getIconVisibleSizePx(int iconSizePx) { + return Math.round(ICON_VISIBLE_AREA_FACTOR * iconSizePx); + } + private int getAdditionalQsbSpace() { return isQsbInline ? hotseatQsbWidth + hotseatBorderSpace : 0; } diff --git a/tests/assets/dumpTests/DeviceProfileDumpTest/tabletLandscape.txt b/tests/assets/dumpTests/DeviceProfileDumpTest/tabletLandscape.txt index 1781673128..0f27893f7a 100644 --- a/tests/assets/dumpTests/DeviceProfileDumpTest/tabletLandscape.txt +++ b/tests/assets/dumpTests/DeviceProfileDumpTest/tabletLandscape.txt @@ -87,7 +87,7 @@ DeviceProfile: numShownHotseatIcons: 6 hotseatBorderSpace: 100.0px (50.0dp) isQsbInline: false - hotseatQsbWidth: 1224.0px (612.0dp) + hotseatQsbWidth: 1214.0px (607.0dp) isTaskbarPresent:false isTaskbarPresentInApps:true taskbarHeight: 0.0px (0.0dp) diff --git a/tests/assets/dumpTests/DeviceProfileDumpTest/tabletLandscape3Button.txt b/tests/assets/dumpTests/DeviceProfileDumpTest/tabletLandscape3Button.txt index bd9e2675a4..85f7ca1040 100644 --- a/tests/assets/dumpTests/DeviceProfileDumpTest/tabletLandscape3Button.txt +++ b/tests/assets/dumpTests/DeviceProfileDumpTest/tabletLandscape3Button.txt @@ -87,7 +87,7 @@ DeviceProfile: numShownHotseatIcons: 6 hotseatBorderSpace: 100.0px (50.0dp) isQsbInline: false - hotseatQsbWidth: 1224.0px (612.0dp) + hotseatQsbWidth: 1214.0px (607.0dp) isTaskbarPresent:false isTaskbarPresentInApps:true taskbarHeight: 0.0px (0.0dp) diff --git a/tests/assets/dumpTests/DeviceProfileDumpTest/tabletPortrait.txt b/tests/assets/dumpTests/DeviceProfileDumpTest/tabletPortrait.txt index e983ef76fc..bd47777343 100644 --- a/tests/assets/dumpTests/DeviceProfileDumpTest/tabletPortrait.txt +++ b/tests/assets/dumpTests/DeviceProfileDumpTest/tabletPortrait.txt @@ -87,7 +87,7 @@ DeviceProfile: numShownHotseatIcons: 6 hotseatBorderSpace: 116.0px (58.0dp) isQsbInline: false - hotseatQsbWidth: 1300.0px (650.0dp) + hotseatQsbWidth: 1290.0px (645.0dp) isTaskbarPresent:false isTaskbarPresentInApps:true taskbarHeight: 0.0px (0.0dp) diff --git a/tests/assets/dumpTests/DeviceProfileDumpTest/tabletPortrait3Button.txt b/tests/assets/dumpTests/DeviceProfileDumpTest/tabletPortrait3Button.txt index aa92838ff9..902885abb5 100644 --- a/tests/assets/dumpTests/DeviceProfileDumpTest/tabletPortrait3Button.txt +++ b/tests/assets/dumpTests/DeviceProfileDumpTest/tabletPortrait3Button.txt @@ -87,7 +87,7 @@ DeviceProfile: numShownHotseatIcons: 6 hotseatBorderSpace: 116.0px (58.0dp) isQsbInline: false - hotseatQsbWidth: 1300.0px (650.0dp) + hotseatQsbWidth: 1290.0px (645.0dp) isTaskbarPresent:false isTaskbarPresentInApps:true taskbarHeight: 0.0px (0.0dp) diff --git a/tests/src/com/android/launcher3/nonquickstep/HotseatWidthCalculationTest.kt b/tests/src/com/android/launcher3/nonquickstep/HotseatWidthCalculationTest.kt index d10239762b..9912a34a08 100644 --- a/tests/src/com/android/launcher3/nonquickstep/HotseatWidthCalculationTest.kt +++ b/tests/src/com/android/launcher3/nonquickstep/HotseatWidthCalculationTest.kt @@ -47,7 +47,7 @@ class HotseatWidthCalculationTest : FakeInvariantDeviceProfileTest() { assertThat(dp.getHotseatLayoutPadding(context).right).isEqualTo(177) assertThat(dp.isQsbInline).isFalse() - assertThat(dp.hotseatQsbWidth).isEqualTo(1445) + assertThat(dp.hotseatQsbWidth).isEqualTo(1435) } /** @@ -69,7 +69,7 @@ class HotseatWidthCalculationTest : FakeInvariantDeviceProfileTest() { assertThat(dp.getHotseatLayoutPadding(context).right).isEqualTo(110) assertThat(dp.isQsbInline).isFalse() - assertThat(dp.hotseatQsbWidth).isEqualTo(1080) + assertThat(dp.hotseatQsbWidth).isEqualTo(1070) } /** @@ -90,7 +90,7 @@ class HotseatWidthCalculationTest : FakeInvariantDeviceProfileTest() { assertThat(dp.getHotseatLayoutPadding(context).right).isEqualTo(370) assertThat(dp.isQsbInline).isFalse() - assertThat(dp.hotseatQsbWidth).isEqualTo(1468) + assertThat(dp.hotseatQsbWidth).isEqualTo(1455) } /** @@ -115,7 +115,7 @@ class HotseatWidthCalculationTest : FakeInvariantDeviceProfileTest() { assertThat(dp.getHotseatLayoutPadding(context).right).isEqualTo(668) assertThat(dp.isQsbInline).isFalse() - assertThat(dp.hotseatQsbWidth).isEqualTo(1224) + assertThat(dp.hotseatQsbWidth).isEqualTo(1214) } /** This is a case when after setting the hotseat, the QSB width needs to be changed to fit */ @@ -134,7 +134,7 @@ class HotseatWidthCalculationTest : FakeInvariantDeviceProfileTest() { assertThat(dp.getHotseatLayoutPadding(context).right).isEqualTo(640) assertThat(dp.isQsbInline).isFalse() - assertThat(dp.hotseatQsbWidth).isEqualTo(1179) + assertThat(dp.hotseatQsbWidth).isEqualTo(1169) } /** @@ -156,7 +156,7 @@ class HotseatWidthCalculationTest : FakeInvariantDeviceProfileTest() { assertThat(dp.getHotseatLayoutPadding(context).right).isEqualTo(582) assertThat(dp.isQsbInline).isFalse() - assertThat(dp.hotseatQsbWidth).isEqualTo(1095) + assertThat(dp.hotseatQsbWidth).isEqualTo(1085) } @Test @@ -176,7 +176,7 @@ class HotseatWidthCalculationTest : FakeInvariantDeviceProfileTest() { assertThat(dp.getHotseatLayoutPadding(context).left).isEqualTo(177) assertThat(dp.getHotseatLayoutPadding(context).right).isEqualTo(177) - assertThat(dp.hotseatQsbWidth).isEqualTo(1445) + assertThat(dp.hotseatQsbWidth).isEqualTo(1435) } } }