Align QSB with hotseat and workspace icons
The QSB was a bit wider becuase icons visible size is a bit smaller than their actual size due to b/235886078 so we add a workaround to adjust QSB size based on the visible icon size
Bug: 281587788
Test: atest HomeScreenImageTest
Flag: NONE
Change-Id: I593ca2d588f08b830be0b2ac389c747b6f558b91
diff --git a/quickstep/tests/src/com/android/quickstep/HotseatWidthCalculationTest.kt b/quickstep/tests/src/com/android/quickstep/HotseatWidthCalculationTest.kt
index a347156..b1ba4c6 100644
--- a/quickstep/tests/src/com/android/quickstep/HotseatWidthCalculationTest.kt
+++ b/quickstep/tests/src/com/android/quickstep/HotseatWidthCalculationTest.kt
@@ -47,7 +47,7 @@
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 @@
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 @@
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 @@
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 1ca7da9..53297f2 100644
--- a/src/com/android/launcher3/DeviceProfile.java
+++ b/src/com/android/launcher3/DeviceProfile.java
@@ -789,14 +789,16 @@
* 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 @@
}
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 @@
// 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 @@
}
} 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 @@
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 1781673..0f27893 100644
--- a/tests/assets/dumpTests/DeviceProfileDumpTest/tabletLandscape.txt
+++ b/tests/assets/dumpTests/DeviceProfileDumpTest/tabletLandscape.txt
@@ -87,7 +87,7 @@
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 bd9e267..85f7ca1 100644
--- a/tests/assets/dumpTests/DeviceProfileDumpTest/tabletLandscape3Button.txt
+++ b/tests/assets/dumpTests/DeviceProfileDumpTest/tabletLandscape3Button.txt
@@ -87,7 +87,7 @@
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 e983ef7..bd47777 100644
--- a/tests/assets/dumpTests/DeviceProfileDumpTest/tabletPortrait.txt
+++ b/tests/assets/dumpTests/DeviceProfileDumpTest/tabletPortrait.txt
@@ -87,7 +87,7 @@
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 aa92838..902885a 100644
--- a/tests/assets/dumpTests/DeviceProfileDumpTest/tabletPortrait3Button.txt
+++ b/tests/assets/dumpTests/DeviceProfileDumpTest/tabletPortrait3Button.txt
@@ -87,7 +87,7 @@
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 d102397..9912a34 100644
--- a/tests/src/com/android/launcher3/nonquickstep/HotseatWidthCalculationTest.kt
+++ b/tests/src/com/android/launcher3/nonquickstep/HotseatWidthCalculationTest.kt
@@ -47,7 +47,7 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
assertThat(dp.getHotseatLayoutPadding(context).left).isEqualTo(177)
assertThat(dp.getHotseatLayoutPadding(context).right).isEqualTo(177)
- assertThat(dp.hotseatQsbWidth).isEqualTo(1445)
+ assertThat(dp.hotseatQsbWidth).isEqualTo(1435)
}
}
}