Add feature flag and attribute for responsive grid
This shouldn't change anything in the grids, only support the creation of responsive grids in the future. For now, to check that the flag works, turn it on and check the dumpsys. There is also a dump test created for this.
Fix: 277064696
Fix: 277064702
Test: DeviceProfileResponsiveDumpTest
Flag: ENABLE_RESPONSIVE_WORKSPACE
Change-Id: I1bef87043a100234bd661cd6ac00007fdc654116
diff --git a/res/values/attrs.xml b/res/values/attrs.xml
index ce8d901..8136534 100644
--- a/res/values/attrs.xml
+++ b/res/values/attrs.xml
@@ -199,6 +199,9 @@
<attr name="demoModeLayoutId" format="reference" />
<attr name="isScalable" format="boolean" />
<attr name="devicePaddingId" format="reference" />
+ <!-- File that contains the specs for the workspace.
+ Needs FeatureFlags.ENABLE_RESPONSIVE_WORKSPACE enabled -->
+ <attr name="workspaceSpecsId" format="reference" />
<!-- By default all categories are enabled -->
<attr name="deviceCategory" format="integer">
<!-- Enable on phone only -->
diff --git a/src/com/android/launcher3/DeviceProfile.java b/src/com/android/launcher3/DeviceProfile.java
index 8675226..0231090 100644
--- a/src/com/android/launcher3/DeviceProfile.java
+++ b/src/com/android/launcher3/DeviceProfile.java
@@ -101,6 +101,7 @@
public final float aspectRatio;
public final boolean isScalableGrid;
+ public final boolean isResponsiveGrid;
private final int mTypeIndex;
/**
@@ -293,6 +294,10 @@
this.rotationHint = windowBounds.rotationHint;
mInsets.set(windowBounds.insets);
+ // TODO(b/241386436):
+ // for testing that the flag works only, shouldn't change any launcher behaviour
+ isResponsiveGrid = inv.workspaceSpecsId != INVALID_RESOURCE_HANDLE;
+
isScalableGrid = inv.isScalable && !isVerticalBarLayout() && !isMultiWindowMode;
// Determine device posture.
mInfo = info;
@@ -1577,6 +1582,7 @@
writer.println(prefix + "\taspectRatio:" + aspectRatio);
+ writer.println(prefix + "\tisResponsiveGrid:" + isResponsiveGrid);
writer.println(prefix + "\tisScalableGrid:" + isScalableGrid);
writer.println(prefix + "\tinv.numRows: " + inv.numRows);
diff --git a/src/com/android/launcher3/InvariantDeviceProfile.java b/src/com/android/launcher3/InvariantDeviceProfile.java
index 3aa582d..376f54d 100644
--- a/src/com/android/launcher3/InvariantDeviceProfile.java
+++ b/src/com/android/launcher3/InvariantDeviceProfile.java
@@ -48,6 +48,7 @@
import androidx.annotation.XmlRes;
import androidx.core.content.res.ResourcesCompat;
+import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.icons.DotRenderer;
import com.android.launcher3.model.DeviceGridState;
import com.android.launcher3.provider.RestoreDbTask;
@@ -105,7 +106,7 @@
static final int INDEX_TWO_PANEL_PORTRAIT = 2;
static final int INDEX_TWO_PANEL_LANDSCAPE = 3;
- /** These resources are used to override the device profile */
+ /** These resources are used to override the device profile */
private static final String RES_GRID_NUM_ROWS = "grid_num_rows";
private static final String RES_GRID_NUM_COLUMNS = "grid_num_columns";
private static final String RES_GRID_ICON_SIZE_DP = "grid_icon_size_dp";
@@ -177,6 +178,8 @@
protected boolean isScalable;
@XmlRes
public int devicePaddingId = INVALID_RESOURCE_HANDLE;
+ @XmlRes
+ public int workspaceSpecsId = INVALID_RESOURCE_HANDLE;
public String dbFile;
public int defaultLayoutId;
@@ -350,6 +353,7 @@
isScalable = closestProfile.isScalable;
devicePaddingId = closestProfile.devicePaddingId;
+ workspaceSpecsId = closestProfile.mWorkspaceSpecsId;
this.deviceType = deviceType;
inlineNavButtonsEndSpacing = closestProfile.inlineNavButtonsEndSpacing;
@@ -795,6 +799,7 @@
private final boolean isScalable;
private final int devicePaddingId;
+ private final int mWorkspaceSpecsId;
public GridOption(Context context, AttributeSet attrs) {
TypedArray a = context.obtainStyledAttributes(
@@ -836,7 +841,7 @@
inlineNavButtonsEndSpacing =
a.getResourceId(R.styleable.GridDisplayOption_inlineNavButtonsEndSpacing,
- R.dimen.taskbar_button_margin_default);
+ R.dimen.taskbar_button_margin_default);
numFolderRows = a.getInt(
R.styleable.GridDisplayOption_numFolderRows, numRows);
@@ -856,6 +861,13 @@
deviceCategory = a.getInt(R.styleable.GridDisplayOption_deviceCategory,
DEVICE_CATEGORY_ALL);
+ if (FeatureFlags.ENABLE_RESPONSIVE_WORKSPACE.get()) {
+ mWorkspaceSpecsId = a.getResourceId(
+ R.styleable.GridDisplayOption_workspaceSpecsId, INVALID_RESOURCE_HANDLE);
+ } else {
+ mWorkspaceSpecsId = INVALID_RESOURCE_HANDLE;
+ }
+
int inlineForRotation = a.getInt(R.styleable.GridDisplayOption_inlineQsb,
DONT_INLINE_QSB);
inlineQsb[INDEX_DEFAULT] =
diff --git a/src/com/android/launcher3/config/FeatureFlags.java b/src/com/android/launcher3/config/FeatureFlags.java
index 065122a..ef57953 100644
--- a/src/com/android/launcher3/config/FeatureFlags.java
+++ b/src/com/android/launcher3/config/FeatureFlags.java
@@ -420,6 +420,10 @@
// TODO(Block 32): Empty block
+ public static final BooleanFlag ENABLE_RESPONSIVE_WORKSPACE = getDebugFlag(241386436,
+ "ENABLE_RESPONSIVE_WORKSPACE", DISABLED,
+ "Enables new workspace grid calculations method.");
+
public static class BooleanFlag {
private final boolean mCurrentValue;
diff --git a/tests/src/com/android/launcher3/AbstractDeviceProfileTest.kt b/tests/src/com/android/launcher3/AbstractDeviceProfileTest.kt
index 0fe8bee..01f494b 100644
--- a/tests/src/com/android/launcher3/AbstractDeviceProfileTest.kt
+++ b/tests/src/com/android/launcher3/AbstractDeviceProfileTest.kt
@@ -50,7 +50,7 @@
private lateinit var originalWindowManagerProxy: WindowManagerProxy
@Before
- fun setUp() {
+ open fun setUp() {
val appContext: Context = ApplicationProvider.getApplicationContext()
originalWindowManagerProxy = WindowManagerProxy.INSTANCE.get(appContext)
originalDisplayController = DisplayController.INSTANCE.get(appContext)
@@ -59,7 +59,7 @@
}
@After
- fun tearDown() {
+ open fun tearDown() {
WindowManagerProxy.INSTANCE.initializeForTesting(originalWindowManagerProxy)
DisplayController.INSTANCE.initializeForTesting(originalDisplayController)
}
diff --git a/tests/src/com/android/launcher3/nonquickstep/DeviceProfileDumpTest.kt b/tests/src/com/android/launcher3/nonquickstep/DeviceProfileDumpTest.kt
index 13db6c7..a81413e 100644
--- a/tests/src/com/android/launcher3/nonquickstep/DeviceProfileDumpTest.kt
+++ b/tests/src/com/android/launcher3/nonquickstep/DeviceProfileDumpTest.kt
@@ -58,6 +58,7 @@
"\tmInsets.right: 0.0px (0.0dp)\n" +
"\tmInsets.bottom: 126.0px (48.0dp)\n" +
"\taspectRatio:2.2222223\n" +
+ "\tisResponsiveGrid:false\n" +
"\tisScalableGrid:false\n" +
"\tinv.numRows: 5\n" +
"\tinv.numColumns: 5\n" +
@@ -193,6 +194,7 @@
"\tmInsets.right: 0.0px (0.0dp)\n" +
"\tmInsets.bottom: 63.0px (24.0dp)\n" +
"\taspectRatio:2.2222223\n" +
+ "\tisResponsiveGrid:false\n" +
"\tisScalableGrid:false\n" +
"\tinv.numRows: 5\n" +
"\tinv.numColumns: 5\n" +
@@ -328,6 +330,7 @@
"\tmInsets.right: 126.0px (48.0dp)\n" +
"\tmInsets.bottom: 0.0px (0.0dp)\n" +
"\taspectRatio:2.2222223\n" +
+ "\tisResponsiveGrid:false\n" +
"\tisScalableGrid:false\n" +
"\tinv.numRows: 5\n" +
"\tinv.numColumns: 5\n" +
@@ -463,6 +466,7 @@
"\tmInsets.right: 0.0px (0.0dp)\n" +
"\tmInsets.bottom: 63.0px (24.0dp)\n" +
"\taspectRatio:2.2222223\n" +
+ "\tisResponsiveGrid:false\n" +
"\tisScalableGrid:false\n" +
"\tinv.numRows: 5\n" +
"\tinv.numColumns: 5\n" +
@@ -599,6 +603,7 @@
"\tmInsets.right: 0.0px (0.0dp)\n" +
"\tmInsets.bottom: 0.0px (0.0dp)\n" +
"\taspectRatio:1.6\n" +
+ "\tisResponsiveGrid:false\n" +
"\tisScalableGrid:true\n" +
"\tinv.numRows: 5\n" +
"\tinv.numColumns: 6\n" +
@@ -735,6 +740,7 @@
"\tmInsets.right: 0.0px (0.0dp)\n" +
"\tmInsets.bottom: 0.0px (0.0dp)\n" +
"\taspectRatio:1.6\n" +
+ "\tisResponsiveGrid:false\n" +
"\tisScalableGrid:true\n" +
"\tinv.numRows: 5\n" +
"\tinv.numColumns: 6\n" +
@@ -871,6 +877,7 @@
"\tmInsets.right: 0.0px (0.0dp)\n" +
"\tmInsets.bottom: 0.0px (0.0dp)\n" +
"\taspectRatio:1.6\n" +
+ "\tisResponsiveGrid:false\n" +
"\tisScalableGrid:true\n" +
"\tinv.numRows: 5\n" +
"\tinv.numColumns: 6\n" +
@@ -1007,6 +1014,7 @@
"\tmInsets.right: 0.0px (0.0dp)\n" +
"\tmInsets.bottom: 0.0px (0.0dp)\n" +
"\taspectRatio:1.6\n" +
+ "\tisResponsiveGrid:false\n" +
"\tisScalableGrid:true\n" +
"\tinv.numRows: 5\n" +
"\tinv.numColumns: 6\n" +
@@ -1148,6 +1156,7 @@
"\tmInsets.right: 0.0px (0.0dp)\n" +
"\tmInsets.bottom: 0.0px (0.0dp)\n" +
"\taspectRatio:1.2\n" +
+ "\tisResponsiveGrid:false\n" +
"\tisScalableGrid:false\n" +
"\tinv.numRows: 4\n" +
"\tinv.numColumns: 4\n" +
@@ -1288,6 +1297,7 @@
"\tmInsets.right: 0.0px (0.0dp)\n" +
"\tmInsets.bottom: 0.0px (0.0dp)\n" +
"\taspectRatio:1.2\n" +
+ "\tisResponsiveGrid:false\n" +
"\tisScalableGrid:false\n" +
"\tinv.numRows: 4\n" +
"\tinv.numColumns: 4\n" +
@@ -1428,6 +1438,7 @@
"\tmInsets.right: 0.0px (0.0dp)\n" +
"\tmInsets.bottom: 0.0px (0.0dp)\n" +
"\taspectRatio:1.2\n" +
+ "\tisResponsiveGrid:false\n" +
"\tisScalableGrid:false\n" +
"\tinv.numRows: 4\n" +
"\tinv.numColumns: 4\n" +
@@ -1564,6 +1575,7 @@
"\tmInsets.right: 0.0px (0.0dp)\n" +
"\tmInsets.bottom: 0.0px (0.0dp)\n" +
"\taspectRatio:1.2\n" +
+ "\tisResponsiveGrid:false\n" +
"\tisScalableGrid:false\n" +
"\tinv.numRows: 4\n" +
"\tinv.numColumns: 4\n" +