Update responsive grid spec cell size remainderSpace logic

Refactoring the cellSize spec of responsive grid to divide the remainder space in code instead of dividing by cols/rows in the spec definition. For example, instead of using 0.2 in the spec for 5x5 grid (1 / number of rows), it is going to use 1 (100% of the remainder space) and divide the percentage by the number of cols or rows in code.

Fix: 313621277
Flag: ACONFIG com.android.launcher3.enable_responsive_workspace TEAMFOOD
Test: NexusLauncherImageTests
Test: CalculatedWorkspaceSpecTest
Test: DeviceProfileDumpTest
Test: DeviceProfileAlternativeDisplaysDumpTest
Change-Id: Ifaec838ac9751562ecedc1fe39b966ee3d092de3
This commit is contained in:
Jordan Silva
2024-01-04 14:44:20 -03:00
parent d4d4eaaf31
commit 2de6a277b7
12 changed files with 60 additions and 41 deletions

View File

@@ -189,6 +189,10 @@
defaults to 2 * numAllAppsColumns -->
<attr name="numExtendedAllAppsColumns" format="integer" />
<!-- Number of rows to calculate the cell height for all apps when it's necessary.
Defaults to numRows. Requires FeatureFlags.ENABLE_RESPONSIVE_WORKSPACE to be enabled. -->
<attr name="numAllAppsRowsForCellHeightCalculation" format="integer" />
<!-- numHotseatIcons defaults to numColumns, if not specified -->
<attr name="numHotseatIcons" format="integer" />
<!-- Number of icons to use when extending the hotseat size,

View File

@@ -640,8 +640,8 @@ public class DeviceProfile {
DimensionType.WIDTH, numShownAllAppsColumns, availableWidthPx,
mResponsiveWorkspaceWidthSpec);
mResponsiveAllAppsHeightSpec = allAppsSpecs.getCalculatedSpec(responsiveAspectRatio,
DimensionType.HEIGHT, inv.numRows, heightPx - mInsets.top,
mResponsiveWorkspaceHeightSpec);
DimensionType.HEIGHT, inv.numAllAppsRowsForCellHeightCalculation,
heightPx - mInsets.top, mResponsiveWorkspaceHeightSpec);
ResponsiveSpecsProvider folderSpecs = ResponsiveSpecsProvider.create(
new ResourceHelper(context,
@@ -1341,7 +1341,7 @@ public class DeviceProfile {
if (allAppsCellHeightPx < cellContentDimensions.getCellContentHeight()) {
if (isVerticalBarLayout()) {
if (allAppsCellHeightPx < iconSizePx) {
if (allAppsCellHeightPx < allAppsIconSizePx) {
cellContentDimensions.setIconSizePx(
mIconSizeSteps.getIconSmallerThan(allAppsCellHeightPx));
}

View File

@@ -170,6 +170,7 @@ public class InvariantDeviceProfile {
* Number of columns in the all apps list.
*/
public int numAllAppsColumns;
public int numAllAppsRowsForCellHeightCalculation;
public int numDatabaseAllAppsColumns;
public @StyleRes int allAppsStyle;
@@ -393,6 +394,8 @@ public class InvariantDeviceProfile {
workspaceCellSpecsTwoPanelId = closestProfile.mWorkspaceCellSpecsTwoPanelId;
allAppsCellSpecsId = closestProfile.mAllAppsCellSpecsId;
allAppsCellSpecsTwoPanelId = closestProfile.mAllAppsCellSpecsTwoPanelId;
numAllAppsRowsForCellHeightCalculation =
closestProfile.mNumAllAppsRowsForCellHeightCalculation;
this.deviceType = deviceType;
inlineNavButtonsEndSpacing = closestProfile.inlineNavButtonsEndSpacing;
@@ -423,6 +426,7 @@ public class InvariantDeviceProfile {
allAppsStyle = closestProfile.allAppsStyle;
numAllAppsColumns = closestProfile.numAllAppsColumns;
numDatabaseAllAppsColumns = deviceType == TYPE_MULTI_DISPLAY
? closestProfile.numDatabaseAllAppsColumns : closestProfile.numAllAppsColumns;
@@ -821,6 +825,7 @@ public class InvariantDeviceProfile {
private final @StyleRes int allAppsStyle;
private final int numAllAppsColumns;
private final int mNumAllAppsRowsForCellHeightCalculation;
private final int numDatabaseAllAppsColumns;
private final int numHotseatIcons;
private final int numDatabaseHotseatIcons;
@@ -971,6 +976,9 @@ public class InvariantDeviceProfile {
mAllAppsCellSpecsTwoPanelId = a.getResourceId(
R.styleable.GridDisplayOption_allAppsCellSpecsTwoPanelId,
INVALID_RESOURCE_HANDLE);
mNumAllAppsRowsForCellHeightCalculation = a.getInt(
R.styleable.GridDisplayOption_numAllAppsRowsForCellHeightCalculation,
numRows);
} else {
mWorkspaceSpecsId = INVALID_RESOURCE_HANDLE;
mWorkspaceSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
@@ -984,6 +992,7 @@ public class InvariantDeviceProfile {
mWorkspaceCellSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
mAllAppsCellSpecsId = INVALID_RESOURCE_HANDLE;
mAllAppsCellSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
mNumAllAppsRowsForCellHeightCalculation = numRows;
}
int inlineForRotation = a.getInt(R.styleable.GridDisplayOption_inlineQsb,

View File

@@ -59,7 +59,7 @@ data class ResponsiveSpec(
val cellSize: SizeSpec,
) : IResponsiveSpec {
init {
check(isValid()) { "Invalid ResponsiveSpec found." }
check(isValid()) { "Invalid ResponsiveSpec found. $this" }
}
constructor(
@@ -106,7 +106,7 @@ data class ResponsiveSpec(
}
if (!isValidRemainderSpace()) {
logError("The total Remainder Space used must be lower or equal to 100%.")
logError("The total Remainder Space used must be equal to 0 or 1.")
return false
}
@@ -131,11 +131,12 @@ data class ResponsiveSpec(
}
private fun isValidRemainderSpace(): Boolean {
// TODO(b/313621277): This validation must be update do accept only 0 or 1 instead of <= 1f.
return startPadding.ofRemainderSpace +
endPadding.ofRemainderSpace +
gutter.ofRemainderSpace +
cellSize.ofRemainderSpace <= 1f
val remainderSpaceUsed =
startPadding.ofRemainderSpace +
endPadding.ofRemainderSpace +
gutter.ofRemainderSpace +
cellSize.ofRemainderSpace
return remainderSpaceUsed == 0f || remainderSpaceUsed == 1f
}
private fun isValidAvailableSpace(): Boolean {
@@ -254,8 +255,8 @@ class CalculatedResponsiveSpec {
startPaddingPx = spec.startPadding.getRemainderSpaceValue(remainderSpace, startPaddingPx)
endPaddingPx = spec.endPadding.getRemainderSpaceValue(remainderSpace, endPaddingPx)
gutterPx = spec.gutter.getRemainderSpaceValue(remainderSpace, gutterPx)
cellSizePx = spec.cellSize.getRemainderSpaceValue(remainderSpace, cellSizePx)
gutterPx = spec.gutter.getRemainderSpaceValue(remainderSpace, gutterPx, gutters)
cellSizePx = spec.cellSize.getRemainderSpaceValue(remainderSpace, cellSizePx, cells)
}
override fun hashCode(): Int {

View File

@@ -57,11 +57,16 @@ data class SizeSpec(
/**
* Calculates the [SizeSpec] value when remainder space value is defined. If no remainderSpace
* is 0, returns a default value.
*
* @param remainderSpace The remainder space to be used for the calculation
* @param defaultValue The default value to be returned when no ofRemainderSpace is defined
* @param factor A number to divide the remainder space. The default value is 1. This property
* is used to split equally the remainder space by the number of cells and gutters.
*/
fun getRemainderSpaceValue(remainderSpace: Int, defaultValue: Int): Int {
fun getRemainderSpaceValue(remainderSpace: Int, defaultValue: Int, factor: Int = 1): Int {
val remainderSpaceValue =
if (ofRemainderSpace > 0) {
(ofRemainderSpace * remainderSpace).roundToInt()
(ofRemainderSpace * remainderSpace / factor).roundToInt()
} else {
defaultValue
}

View File

@@ -27,7 +27,7 @@
<workspaceSpec
launcher:maxAvailableSize="9999dp"
launcher:dimensionType="width">
<cellSize launcher:ofRemainderSpace="0.25" />
<cellSize launcher:ofRemainderSpace="1" />
<endPadding launcher:fixedSize="22dp" />
<gutter launcher:fixedSize="16dp" />
<startPadding launcher:fixedSize="22dp" />

View File

@@ -28,7 +28,7 @@
<workspaceSpec
launcher:maxAvailableSize="9999dp"
launcher:dimensionType="width">
<cellSize launcher:ofRemainderSpace="0.25" />
<cellSize launcher:ofRemainderSpace="1" />
<endPadding launcher:fixedSize="22dp" />
<gutter launcher:fixedSize="16dp" />
<startPadding launcher:fixedSize="22dp" />
@@ -38,7 +38,7 @@
<workspaceSpec
launcher:maxAvailableSize="9999dp"
launcher:dimensionType="width">
<cellSize launcher:ofRemainderSpace="0.25" />
<cellSize launcher:ofRemainderSpace="1" />
<endPadding launcher:fixedSize="22dp" />
<gutter launcher:fixedSize="16dp" />
<startPadding launcher:fixedSize="22dp" />

View File

@@ -22,7 +22,7 @@
<startPadding launcher:fixedSize="0dp" />
<endPadding launcher:fixedSize="34dp" />
<gutter launcher:fixedSize="12dp" />
<cellSize launcher:ofRemainderSpace="0.25" />
<cellSize launcher:ofRemainderSpace="1" />
</workspaceSpec>
<!-- Height spec -->
@@ -32,7 +32,7 @@
<startPadding launcher:fixedSize="0dp" />
<endPadding launcher:fixedSize="24dp" />
<gutter launcher:fixedSize="12dp" />
<cellSize launcher:ofRemainderSpace="0.25" />
<cellSize launcher:ofRemainderSpace="1" />
</workspaceSpec>
<!-- Width spec -->
@@ -42,7 +42,7 @@
<startPadding launcher:fixedSize="16dp" />
<endPadding launcher:fixedSize="64dp" />
<gutter launcher:fixedSize="12dp" />
<cellSize launcher:ofRemainderSpace="0.25" />
<cellSize launcher:ofRemainderSpace="1" />
</workspaceSpec>
<workspaceSpec
launcher:dimensionType="width"
@@ -50,7 +50,7 @@
<startPadding launcher:fixedSize="36dp" />
<endPadding launcher:fixedSize="80dp" />
<gutter launcher:fixedSize="12dp" />
<cellSize launcher:ofRemainderSpace="0.25" />
<cellSize launcher:ofRemainderSpace="1" />
</workspaceSpec>
<workspaceSpec
launcher:dimensionType="width"
@@ -58,7 +58,7 @@
<startPadding launcher:fixedSize="0dp" />
<endPadding launcher:fixedSize="36dp" />
<gutter launcher:fixedSize="12dp" />
<cellSize launcher:ofRemainderSpace="0.25" />
<cellSize launcher:ofRemainderSpace="1" />
</workspaceSpec>
</specs>
@@ -71,7 +71,7 @@
<startPadding launcher:fixedSize="2dp" />
<endPadding launcher:fixedSize="2dp" />
<gutter launcher:fixedSize="8dp" />
<cellSize launcher:ofRemainderSpace="0.25" />
<cellSize launcher:ofRemainderSpace="1" />
</workspaceSpec>
<!-- Width spec -->
@@ -81,7 +81,7 @@
<startPadding launcher:fixedSize="1dp" />
<endPadding launcher:fixedSize="1dp" />
<gutter launcher:fixedSize="8dp" />
<cellSize launcher:ofRemainderSpace="0.25" />
<cellSize launcher:ofRemainderSpace="1" />
</workspaceSpec>
</specs>
@@ -122,7 +122,7 @@
<startPadding launcher:fixedSize="22dp" />
<endPadding launcher:fixedSize="22dp" />
<gutter launcher:fixedSize="16dp" />
<cellSize launcher:ofRemainderSpace="0.25" />
<cellSize launcher:ofRemainderSpace="1" />
</workspaceSpec>
</specs>
</workspaceSpecs>

View File

@@ -54,7 +54,7 @@
<startPadding launcher:fixedSize="22dp" />
<endPadding launcher:fixedSize="22dp" />
<gutter launcher:fixedSize="16dp" />
<cellSize launcher:ofRemainderSpace="0.25" />
<cellSize launcher:ofRemainderSpace="1" />
</workspaceSpec>
</specs>
@@ -67,7 +67,7 @@
<startPadding launcher:fixedSize="0dp" />
<endPadding launcher:fixedSize="24dp" />
<gutter launcher:fixedSize="12dp" />
<cellSize launcher:ofRemainderSpace="0.25" />
<cellSize launcher:ofRemainderSpace="1" />
</workspaceSpec>
<workspaceSpec
launcher:dimensionType="height"
@@ -75,7 +75,7 @@
<startPadding launcher:fixedSize="0dp" />
<endPadding launcher:fixedSize="34dp" />
<gutter launcher:fixedSize="12dp" />
<cellSize launcher:ofRemainderSpace="0.25" />
<cellSize launcher:ofRemainderSpace="1" />
</workspaceSpec>
<!-- Width spec -->
@@ -85,7 +85,7 @@
<startPadding launcher:fixedSize="0dp" />
<endPadding launcher:fixedSize="36dp" />
<gutter launcher:fixedSize="12dp" />
<cellSize launcher:ofRemainderSpace="0.25" />
<cellSize launcher:ofRemainderSpace="1" />
</workspaceSpec>
<workspaceSpec
launcher:dimensionType="width"
@@ -93,7 +93,7 @@
<startPadding launcher:fixedSize="16dp" />
<endPadding launcher:fixedSize="64dp" />
<gutter launcher:fixedSize="12dp" />
<cellSize launcher:ofRemainderSpace="0.25" />
<cellSize launcher:ofRemainderSpace="1" />
</workspaceSpec>
<workspaceSpec
launcher:dimensionType="width"
@@ -101,7 +101,7 @@
<startPadding launcher:fixedSize="36dp" />
<endPadding launcher:fixedSize="80dp" />
<gutter launcher:fixedSize="12dp" />
<cellSize launcher:ofRemainderSpace="0.25" />
<cellSize launcher:ofRemainderSpace="1" />
</workspaceSpec>
</specs>
</workspaceSpecs>

View File

@@ -52,7 +52,7 @@
<startPadding launcher:fixedSize="22dp" />
<endPadding launcher:fixedSize="22dp" />
<gutter launcher:fixedSize="16dp" />
<cellSize launcher:ofRemainderSpace="0.25" />
<cellSize launcher:ofRemainderSpace="1" />
</workspaceSpec>
</specs>
</workspaceSpecs>

View File

@@ -84,7 +84,7 @@ class ResponsiveSpecsProviderTest : AbstractDeviceProfileTest() {
startPadding = SizeSpec(1f.dpToPx()),
endPadding = SizeSpec(1f.dpToPx()),
gutter = SizeSpec(8f.dpToPx()),
cellSize = SizeSpec(ofRemainderSpace = .25f)
cellSize = SizeSpec(ofRemainderSpace = 1f)
)
)
@@ -97,7 +97,7 @@ class ResponsiveSpecsProviderTest : AbstractDeviceProfileTest() {
startPadding = SizeSpec(2f.dpToPx()),
endPadding = SizeSpec(2f.dpToPx()),
gutter = SizeSpec(8f.dpToPx()),
cellSize = SizeSpec(ofRemainderSpace = .25f)
cellSize = SizeSpec(ofRemainderSpace = 1f)
),
)
@@ -182,7 +182,7 @@ class ResponsiveSpecsProviderTest : AbstractDeviceProfileTest() {
startPadding = SizeSpec(22f.dpToPx()),
endPadding = SizeSpec(22f.dpToPx()),
gutter = sizeSpec16,
cellSize = SizeSpec(ofRemainderSpace = .25f)
cellSize = SizeSpec(ofRemainderSpace = 1f)
)
)
@@ -231,7 +231,7 @@ class ResponsiveSpecsProviderTest : AbstractDeviceProfileTest() {
startPadding = SizeSpec(0f.dpToPx()),
endPadding = SizeSpec(36f.dpToPx()),
gutter = sizeSpec12,
cellSize = SizeSpec(ofRemainderSpace = .25f)
cellSize = SizeSpec(ofRemainderSpace = 1f)
),
ResponsiveSpec(
maxAvailableSize = 716.dpToPx(),
@@ -240,7 +240,7 @@ class ResponsiveSpecsProviderTest : AbstractDeviceProfileTest() {
startPadding = SizeSpec(16f.dpToPx()),
endPadding = SizeSpec(64f.dpToPx()),
gutter = sizeSpec12,
cellSize = SizeSpec(ofRemainderSpace = .25f)
cellSize = SizeSpec(ofRemainderSpace = 1f)
),
ResponsiveSpec(
maxAvailableSize = 9999.dpToPx(),
@@ -249,7 +249,7 @@ class ResponsiveSpecsProviderTest : AbstractDeviceProfileTest() {
startPadding = SizeSpec(36f.dpToPx()),
endPadding = SizeSpec(80f.dpToPx()),
gutter = sizeSpec12,
cellSize = SizeSpec(ofRemainderSpace = .25f)
cellSize = SizeSpec(ofRemainderSpace = 1f)
)
)
@@ -262,7 +262,7 @@ class ResponsiveSpecsProviderTest : AbstractDeviceProfileTest() {
startPadding = SizeSpec(0f),
endPadding = SizeSpec(24f.dpToPx()),
gutter = sizeSpec12,
cellSize = SizeSpec(ofRemainderSpace = .25f)
cellSize = SizeSpec(ofRemainderSpace = 1f)
),
ResponsiveSpec(
maxAvailableSize = 9999.dpToPx(),
@@ -271,7 +271,7 @@ class ResponsiveSpecsProviderTest : AbstractDeviceProfileTest() {
startPadding = SizeSpec(0f),
endPadding = SizeSpec(34f.dpToPx()),
gutter = sizeSpec12,
cellSize = SizeSpec(ofRemainderSpace = .25f)
cellSize = SizeSpec(ofRemainderSpace = 1f)
),
)

View File

@@ -159,7 +159,7 @@ class WorkspaceSpecsTest : AbstractDeviceProfileTest() {
"maxSize=2147483647), " +
"cellSize=SizeSpec(fixedSize=0.0, " +
"ofAvailableSpace=0.0, " +
"ofRemainderSpace=0.25, " +
"ofRemainderSpace=1.0, " +
"matchWorkspace=false, " +
"maxSize=2147483647)" +
")"