From ec5abba93b3f3c430da68071817d80ae0e79c201 Mon Sep 17 00:00:00 2001 From: Thales Lima Date: Wed, 5 Apr 2023 16:33:50 +0100 Subject: [PATCH] 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 --- res/values/attrs.xml | 3 +++ src/com/android/launcher3/DeviceProfile.java | 6 ++++++ .../launcher3/InvariantDeviceProfile.java | 16 ++++++++++++++-- .../android/launcher3/config/FeatureFlags.java | 4 ++++ .../launcher3/AbstractDeviceProfileTest.kt | 4 ++-- .../nonquickstep/DeviceProfileDumpTest.kt | 12 ++++++++++++ 6 files changed, 41 insertions(+), 4 deletions(-) diff --git a/res/values/attrs.xml b/res/values/attrs.xml index ce8d90166b..813653446d 100644 --- a/res/values/attrs.xml +++ b/res/values/attrs.xml @@ -199,6 +199,9 @@ + + diff --git a/src/com/android/launcher3/DeviceProfile.java b/src/com/android/launcher3/DeviceProfile.java index 867522699f..0231090d7e 100644 --- a/src/com/android/launcher3/DeviceProfile.java +++ b/src/com/android/launcher3/DeviceProfile.java @@ -101,6 +101,7 @@ public class DeviceProfile { public final float aspectRatio; public final boolean isScalableGrid; + public final boolean isResponsiveGrid; private final int mTypeIndex; /** @@ -293,6 +294,10 @@ public class DeviceProfile { 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 @@ public class DeviceProfile { 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 3aa582d074..376f54dc4c 100644 --- a/src/com/android/launcher3/InvariantDeviceProfile.java +++ b/src/com/android/launcher3/InvariantDeviceProfile.java @@ -48,6 +48,7 @@ import androidx.annotation.VisibleForTesting; 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 @@ public class InvariantDeviceProfile { 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 @@ public class InvariantDeviceProfile { 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 @@ public class InvariantDeviceProfile { isScalable = closestProfile.isScalable; devicePaddingId = closestProfile.devicePaddingId; + workspaceSpecsId = closestProfile.mWorkspaceSpecsId; this.deviceType = deviceType; inlineNavButtonsEndSpacing = closestProfile.inlineNavButtonsEndSpacing; @@ -795,6 +799,7 @@ public class InvariantDeviceProfile { 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 @@ public class InvariantDeviceProfile { 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 @@ public class InvariantDeviceProfile { 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 065122aa30..ef57953e9c 100644 --- a/src/com/android/launcher3/config/FeatureFlags.java +++ b/src/com/android/launcher3/config/FeatureFlags.java @@ -420,6 +420,10 @@ public final class FeatureFlags { // 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 0fe8bee230..01f494b202 100644 --- a/tests/src/com/android/launcher3/AbstractDeviceProfileTest.kt +++ b/tests/src/com/android/launcher3/AbstractDeviceProfileTest.kt @@ -50,7 +50,7 @@ abstract class AbstractDeviceProfileTest { 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 @@ abstract class AbstractDeviceProfileTest { } @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 13db6c76c8..a81413e1d3 100644 --- a/tests/src/com/android/launcher3/nonquickstep/DeviceProfileDumpTest.kt +++ b/tests/src/com/android/launcher3/nonquickstep/DeviceProfileDumpTest.kt @@ -58,6 +58,7 @@ class DeviceProfileDumpTest : AbstractDeviceProfileTest() { "\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 @@ class DeviceProfileDumpTest : AbstractDeviceProfileTest() { "\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 @@ class DeviceProfileDumpTest : AbstractDeviceProfileTest() { "\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 @@ class DeviceProfileDumpTest : AbstractDeviceProfileTest() { "\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 @@ class DeviceProfileDumpTest : AbstractDeviceProfileTest() { "\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 @@ class DeviceProfileDumpTest : AbstractDeviceProfileTest() { "\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 @@ class DeviceProfileDumpTest : AbstractDeviceProfileTest() { "\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 @@ class DeviceProfileDumpTest : AbstractDeviceProfileTest() { "\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 @@ class DeviceProfileDumpTest : AbstractDeviceProfileTest() { "\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 @@ class DeviceProfileDumpTest : AbstractDeviceProfileTest() { "\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 @@ class DeviceProfileDumpTest : AbstractDeviceProfileTest() { "\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 @@ class DeviceProfileDumpTest : AbstractDeviceProfileTest() { "\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" +