From d1cd8c2ea6d5e168257db82a67723677e075bde0 Mon Sep 17 00:00:00 2001 From: fbaron Date: Tue, 26 Nov 2024 10:13:36 -0800 Subject: [PATCH] Add GridDimensionSpecs to fixed landscape and make grid dimension generalized so we can use it to determine row count or col count Bug: 364711064 Flag: com.android.launcher3.one_grid_specs Test: HomeScreenImageTest Change-Id: If1dafedc710ebc483fc7b6b5cd6cae6f70dc3cfc --- res/values/attrs.xml | 11 +- res/xml/backupscheme.xml | 1 + src/com/android/launcher3/DeviceProfile.java | 10 +- .../launcher3/InvariantDeviceProfile.java | 132 ++++++++---------- src/com/android/launcher3/Launcher.java | 2 +- src/com/android/launcher3/LauncherFiles.java | 2 + .../launcher3/settings/SettingsActivity.java | 5 +- 7 files changed, 77 insertions(+), 86 deletions(-) diff --git a/res/values/attrs.xml b/res/values/attrs.xml index c477633ddf..698877ac19 100644 --- a/res/values/attrs.xml +++ b/res/values/attrs.xml @@ -162,10 +162,11 @@ - - - - + + + + + @@ -261,7 +262,7 @@ - + diff --git a/res/xml/backupscheme.xml b/res/xml/backupscheme.xml index 34b80b150c..083af5cf11 100644 --- a/res/xml/backupscheme.xml +++ b/res/xml/backupscheme.xml @@ -11,6 +11,7 @@ + diff --git a/src/com/android/launcher3/DeviceProfile.java b/src/com/android/launcher3/DeviceProfile.java index 9b6fe4e826..16d9525b38 100644 --- a/src/com/android/launcher3/DeviceProfile.java +++ b/src/com/android/launcher3/DeviceProfile.java @@ -865,7 +865,7 @@ public class DeviceProfile { canQsbInline = canQsbInline && hotseatQsbHeight > 0; return (mIsScalableGrid && inv.inlineQsb[mTypeIndex] && canQsbInline) - || inv.isFixedLandscapeMode; + || inv.isFixedLandscape; } private static DotRenderer createDotRenderer( @@ -1834,7 +1834,7 @@ public class DeviceProfile { } int paddingTop = workspaceTopPadding + (mIsScalableGrid ? 0 : edgeMarginPx); // On isFixedLandscapeMode on phones we already have padding because of the camera hole - int paddingSide = inv.isFixedLandscapeMode ? 0 : desiredWorkspaceHorizontalMarginPx; + int paddingSide = inv.isFixedLandscape ? 0 : desiredWorkspaceHorizontalMarginPx; padding.set(paddingSide, paddingTop, paddingSide, paddingBottom); } @@ -1934,7 +1934,7 @@ public class DeviceProfile { hotseatBarPadding.set(mHotseatBarWorkspaceSpacePx, paddingTop, mInsets.right + mHotseatBarEdgePaddingPx, paddingBottom); } - } else if (isTaskbarPresent || inv.isFixedLandscapeMode) { + } else if (isTaskbarPresent || inv.isFixedLandscape) { // Center the QSB vertically with hotseat int hotseatBarBottomPadding = getHotseatBarBottomPadding(); int hotseatBarTopPadding = @@ -1953,7 +1953,7 @@ public class DeviceProfile { } startSpacing += getAdditionalQsbSpace(); - if (inv.isFixedLandscapeMode) { + if (inv.isFixedLandscape) { endSpacing += mInsets.right; startSpacing += mInsets.left; } @@ -2568,7 +2568,7 @@ public class DeviceProfile { } if (mTransposeLayoutWithOrientation == null) { mTransposeLayoutWithOrientation = - !(mInfo.isTablet(mWindowBounds) || mInv.isFixedLandscapeMode); + !(mInfo.isTablet(mWindowBounds) || mInv.isFixedLandscape); } if (mIsGestureMode == null) { mIsGestureMode = mInfo.getNavigationMode().hasGestures; diff --git a/src/com/android/launcher3/InvariantDeviceProfile.java b/src/com/android/launcher3/InvariantDeviceProfile.java index c044c52e3e..dfbcf5c439 100644 --- a/src/com/android/launcher3/InvariantDeviceProfile.java +++ b/src/com/android/launcher3/InvariantDeviceProfile.java @@ -188,7 +188,7 @@ public class InvariantDeviceProfile implements SafeCloseable { @XmlRes public int workspaceSpecsId = INVALID_RESOURCE_HANDLE; @XmlRes - public int rowCountSpecsId = INVALID_RESOURCE_HANDLE;; + public int gridSizeSpecsId = INVALID_RESOURCE_HANDLE;; @XmlRes public int workspaceSpecsTwoPanelId = INVALID_RESOURCE_HANDLE; @XmlRes @@ -216,7 +216,7 @@ public class InvariantDeviceProfile implements SafeCloseable { /** * Fixed landscape mode is the landscape on the phones. */ - public boolean isFixedLandscapeMode = false; + public boolean isFixedLandscape = false; private LauncherPrefChangeListener mLandscapeModePreferenceListener; public String dbFile; @@ -255,9 +255,12 @@ public class InvariantDeviceProfile implements SafeCloseable { }); if (Flags.oneGridSpecs()) { mLandscapeModePreferenceListener = (String s) -> { - boolean newFixedLandscapeValue = FIXED_LANDSCAPE_MODE.get(context); - if (isFixedLandscapeMode != newFixedLandscapeValue) { - setFixedLandscape(context, newFixedLandscapeValue); + if (isFixedLandscape != FIXED_LANDSCAPE_MODE.get(context)) { + MAIN_EXECUTOR.execute(() -> { + Trace.beginSection("InvariantDeviceProfile#setFixedLandscape"); + onConfigChanged(context.getApplicationContext()); + Trace.endSection(); + }); } }; LauncherPrefs.INSTANCE.get(context).addListener( @@ -295,7 +298,7 @@ public class InvariantDeviceProfile implements SafeCloseable { gridName, defaultInfo, /*allowDisabledGrid=*/false, - isFixedLandscapeMode + FIXED_LANDSCAPE_MODE.get(context) ), defaultDeviceType); @@ -309,7 +312,7 @@ public class InvariantDeviceProfile implements SafeCloseable { gridName, myInfo, /*allowDisabledGrid=*/false, - isFixedLandscapeMode + FIXED_LANDSCAPE_MODE.get(context) ), deviceType); @@ -345,13 +348,7 @@ public class InvariantDeviceProfile implements SafeCloseable { } private String initGrid(Context context, String gridName) { - if (!Flags.oneGridSpecs() && (isFixedLandscapeMode || FIXED_LANDSCAPE_MODE.get(context))) { - LauncherPrefs.get(context).put(FIXED_LANDSCAPE_MODE, false); - isFixedLandscapeMode = false; - } - Info displayInfo = DisplayController.INSTANCE.get(context).getInfo(); - List allOptions = getPredefinedDeviceProfiles( context, gridName, @@ -413,7 +410,7 @@ public class InvariantDeviceProfile implements SafeCloseable { isScalable = closestProfile.isScalable; devicePaddingId = closestProfile.devicePaddingId; workspaceSpecsId = closestProfile.mWorkspaceSpecsId; - rowCountSpecsId = closestProfile.mRowCountSpecsId; + gridSizeSpecsId = closestProfile.mGridSizeSpecsId; workspaceSpecsTwoPanelId = closestProfile.mWorkspaceSpecsTwoPanelId; allAppsSpecsId = closestProfile.mAllAppsSpecsId; allAppsSpecsTwoPanelId = closestProfile.mAllAppsSpecsTwoPanelId; @@ -473,7 +470,7 @@ public class InvariantDeviceProfile implements SafeCloseable { startAlignTaskbar = displayOption.startAlignTaskbar; // Fixed Landscape mode - isFixedLandscapeMode = FIXED_LANDSCAPE_MODE.get(context) && Flags.oneGridSpecs(); + isFixedLandscape = closestProfile.mIsFixedLandscape; // If the partner customization apk contains any grid overrides, apply them // Supported overrides: numRows, numColumns, iconSize @@ -543,24 +540,6 @@ public class InvariantDeviceProfile implements SafeCloseable { }); } - /** - * Updates the fixed landscape mode, this triggers a new IDP, reloads the database and triggers - * a grid migration. - */ - public void setFixedLandscape(Context context, boolean isFixedLandscape) { - this.isFixedLandscapeMode = isFixedLandscape; - if (isFixedLandscape) { - // When in isFixedLandscape there should only be one default grid to choose from - MAIN_EXECUTOR.execute(() -> { - Trace.beginSection("InvariantDeviceProfile#setFixedLandscape"); - onConfigChanged(context.getApplicationContext()); - Trace.endSection(); - }); - } else { - setCurrentGrid(context, LauncherPrefs.get(context).get(GRID_NAME)); - } - } - private Object[] toModelState() { return new Object[]{ numColumns, numRows, numSearchContainerColumns, numDatabaseHotseatIcons, @@ -651,14 +630,14 @@ public class InvariantDeviceProfile implements SafeCloseable { } /** - * Parses through the xml to find GridDimension specs. Then calls findBestRowCount to get the - * correct row count for this GridOption. + * Parses through the xml to find GridSize specs. Then calls findBestGridSize to get the + * correct grid size for this GridOption. * - * @return the result of {@link #findBestRowCount(List, int, int)}. + * @return the result of {@link #findBestGridSize(List, int, int)}. */ - private static GridDimension getRowCount(ResourceHelper resourceHelper, Context context, + private static GridSize getGridSize(ResourceHelper resourceHelper, Context context, Info displayInfo) { - ArrayList rowCounts = new ArrayList<>(); + ArrayList gridSizes = new ArrayList<>(); try (XmlResourceParser parser = resourceHelper.getXml()) { final int depth = parser.getDepth(); @@ -666,8 +645,8 @@ public class InvariantDeviceProfile implements SafeCloseable { while (((type = parser.next()) != XmlPullParser.END_TAG || parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) { if ((type == XmlPullParser.START_TAG) - && "GridDimension".equals(parser.getName())) { - rowCounts.add(new GridDimension(context, Xml.asAttributeSet(parser))); + && "GridSize".equals(parser.getName())) { + gridSizes.add(new GridSize(context, Xml.asAttributeSet(parser))); } } } catch (IOException | XmlPullParserException e) { @@ -677,24 +656,26 @@ public class InvariantDeviceProfile implements SafeCloseable { // Finds the min width and height in dp for all displays. int[] dimens = findMinWidthAndHeightDpForDevice(displayInfo); - return findBestRowCount(rowCounts, dimens[0], dimens[1]); + return findBestGridSize(gridSizes, dimens[0], dimens[1]); } /** - * @return the biggest row count that fits the display dimensions spec using GridDimension to - * determine that. If no best row count is found, return null. + * @return the biggest grid size that fits the display dimensions. + * If no best grid size is found, return null. */ - private static GridDimension findBestRowCount(List list, int minWidthDp, + private static GridSize findBestGridSize(List list, int minWidthDp, int minHeightDp) { - GridDimension selectedRow = null; - for (GridDimension item: list) { + GridSize selectedGridSize = null; + for (GridSize item: list) { if (minWidthDp >= item.mMinDeviceWidthDp && minHeightDp >= item.mMinDeviceHeightDp) { - if (selectedRow == null || selectedRow.mNumGridDimension < item.mNumGridDimension) { - selectedRow = item; + if (selectedGridSize == null + || (selectedGridSize.mNumColumns <= item.mNumColumns + && selectedGridSize.mNumRows <= item.mNumRows)) { + selectedGridSize = item; } } } - return selectedRow; + return selectedGridSize; } private static int[] findMinWidthAndHeightDpForDevice(Info displayInfo) { @@ -767,7 +748,7 @@ public class InvariantDeviceProfile implements SafeCloseable { return parseAllDefinedGridOptions(context, displayInfo) .stream() .filter(go -> go.isEnabled(deviceType)) - .filter(go -> go.filterByFlag(deviceType, isFixedLandscapeMode)) + .filter(go -> go.filterByFlag(deviceType, isFixedLandscape)) .collect(Collectors.toList()); } @@ -1037,7 +1018,7 @@ public class InvariantDeviceProfile implements SafeCloseable { private final int mWorkspaceCellSpecsTwoPanelId; private final int mAllAppsCellSpecsId; private final int mAllAppsCellSpecsTwoPanelId; - private final int mRowCountSpecsId; + private final int mGridSizeSpecsId; private final boolean mIsFixedLandscape; private final boolean mIsOldGrid; @@ -1048,18 +1029,20 @@ public class InvariantDeviceProfile implements SafeCloseable { title = a.getString(R.styleable.GridDisplayOption_title); deviceCategory = a.getInt(R.styleable.GridDisplayOption_deviceCategory, DEVICE_CATEGORY_ALL); - mRowCountSpecsId = a.getResourceId( - R.styleable.GridDisplayOption_rowCountSpecsId, INVALID_RESOURCE_HANDLE); + mGridSizeSpecsId = a.getResourceId( + R.styleable.GridDisplayOption_gridSizeSpecsId, INVALID_RESOURCE_HANDLE); mIsDualGrid = a.getBoolean(R.styleable.GridDisplayOption_isDualGrid, false); - if (mRowCountSpecsId != INVALID_RESOURCE_HANDLE) { - ResourceHelper resourceHelper = new ResourceHelper(context, mRowCountSpecsId); - GridDimension numR = getRowCount(resourceHelper, context, displayInfo); - numRows = numR.mNumGridDimension; - dbFile = numR.mDbFile; - defaultLayoutId = numR.mDefaultLayoutId; - demoModeLayoutId = numR.mDemoModeLayoutId; + if (mGridSizeSpecsId != INVALID_RESOURCE_HANDLE) { + ResourceHelper resourceHelper = new ResourceHelper(context, mGridSizeSpecsId); + GridSize gridSize = getGridSize(resourceHelper, context, displayInfo); + numColumns = gridSize.mNumColumns; + numRows = gridSize.mNumRows; + dbFile = gridSize.mDbFile; + defaultLayoutId = gridSize.mDefaultLayoutId; + demoModeLayoutId = gridSize.mDemoModeLayoutId; } else { numRows = a.getInt(R.styleable.GridDisplayOption_numRows, 0); + numColumns = a.getInt(R.styleable.GridDisplayOption_numColumns, 0); dbFile = a.getString(R.styleable.GridDisplayOption_dbFile); defaultLayoutId = a.getResourceId( R.styleable.GridDisplayOption_defaultLayoutId, 0); @@ -1067,7 +1050,6 @@ public class InvariantDeviceProfile implements SafeCloseable { R.styleable.GridDisplayOption_demoModeLayoutId, defaultLayoutId); } - numColumns = a.getInt(R.styleable.GridDisplayOption_numColumns, 0); numSearchContainerColumns = a.getInt( R.styleable.GridDisplayOption_numSearchContainerColumns, numColumns); @@ -1230,7 +1212,7 @@ public class InvariantDeviceProfile implements SafeCloseable { } // Here we return true if we want to show the new grids. - if (mRowCountSpecsId != INVALID_RESOURCE_HANDLE) { + if (mGridSizeSpecsId != INVALID_RESOURCE_HANDLE) { return Flags.oneGridSpecs(); } @@ -1243,26 +1225,28 @@ public class InvariantDeviceProfile implements SafeCloseable { } } - public static final class GridDimension { - final int mNumGridDimension; - final int mMinDeviceWidthDp; - final int mMinDeviceHeightDp; + public static final class GridSize { + final int mNumRows; + final int mNumColumns; + final float mMinDeviceWidthDp; + final float mMinDeviceHeightDp; final String mDbFile; final int mDefaultLayoutId; final int mDemoModeLayoutId; - GridDimension(Context context, AttributeSet attrs) { - TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.GridDimension); + GridSize(Context context, AttributeSet attrs) { + TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.GridSize); - mNumGridDimension = (int) a.getFloat(R.styleable.GridDimension_numGridDimension, 0); - mMinDeviceWidthDp = a.getInt(R.styleable.GridDimension_minDeviceWidthDp, 0); - mMinDeviceHeightDp = a.getInt(R.styleable.GridDimension_minDeviceHeightDp, 0); - mDbFile = a.getString(R.styleable.GridDimension_dbFile); + mNumRows = (int) a.getFloat(R.styleable.GridSize_numGridRows, 0); + mNumColumns = (int) a.getFloat(R.styleable.GridSize_numGridColumns, 0); + mMinDeviceWidthDp = a.getFloat(R.styleable.GridSize_minDeviceWidthDp, 0); + mMinDeviceHeightDp = a.getFloat(R.styleable.GridSize_minDeviceHeightDp, 0); + mDbFile = a.getString(R.styleable.GridSize_dbFile); mDefaultLayoutId = a.getResourceId( - R.styleable.GridDimension_defaultLayoutId, 0); + R.styleable.GridSize_defaultLayoutId, 0); mDemoModeLayoutId = a.getResourceId( - R.styleable.GridDimension_demoModeLayoutId, mDefaultLayoutId); + R.styleable.GridSize_demoModeLayoutId, mDefaultLayoutId); a.recycle(); } diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java index 898102429e..aaa0c41d55 100644 --- a/src/com/android/launcher3/Launcher.java +++ b/src/com/android/launcher3/Launcher.java @@ -789,7 +789,7 @@ public class Launcher extends StatefulActivity LauncherPrefs.get(this).put(LauncherPrefs.ALLOW_ROTATION, false); } getRotationHelper().setFixedLandscape( - Objects.requireNonNull(mDeviceProfile.inv).isFixedLandscapeMode + Objects.requireNonNull(mDeviceProfile.inv).isFixedLandscape ); } diff --git a/src/com/android/launcher3/LauncherFiles.java b/src/com/android/launcher3/LauncherFiles.java index a5b8168c5f..c702414d1c 100644 --- a/src/com/android/launcher3/LauncherFiles.java +++ b/src/com/android/launcher3/LauncherFiles.java @@ -24,6 +24,7 @@ public class LauncherFiles { public static final String LAUNCHER_4_BY_4_DB = "launcher_4_by_4.db"; public static final String LAUNCHER_3_BY_3_DB = "launcher_3_by_3.db"; public static final String LAUNCHER_2_BY_2_DB = "launcher_2_by_2.db"; + public static final String LAUNCHER_7_BY_3_DB = "launcher_7_by_3.db"; public static final String LAUNCHER_8_BY_3_DB = "launcher_8_by_3.db"; public static final String BACKUP_DB = "backup.db"; public static final String SHARED_PREFERENCES_KEY = "com.android.launcher3.prefs"; @@ -45,6 +46,7 @@ public class LauncherFiles { LAUNCHER_4_BY_4_DB, LAUNCHER_3_BY_3_DB, LAUNCHER_2_BY_2_DB, + LAUNCHER_7_BY_3_DB, LAUNCHER_8_BY_3_DB)); public static final List OTHER_FILES = Collections.unmodifiableList(Arrays.asList( diff --git a/src/com/android/launcher3/settings/SettingsActivity.java b/src/com/android/launcher3/settings/SettingsActivity.java index 5068b48fc8..6008287492 100644 --- a/src/com/android/launcher3/settings/SettingsActivity.java +++ b/src/com/android/launcher3/settings/SettingsActivity.java @@ -23,6 +23,7 @@ import static androidx.preference.PreferenceFragmentCompat.ARG_PREFERENCE_ROOT; import static com.android.launcher3.BuildConfig.IS_DEBUG_DEVICE; import static com.android.launcher3.BuildConfig.IS_STUDIO_BUILD; import static com.android.launcher3.InvariantDeviceProfile.TYPE_MULTI_DISPLAY; +import static com.android.launcher3.InvariantDeviceProfile.TYPE_TABLET; import static com.android.launcher3.states.RotationHelper.ALLOW_ROTATION_PREFERENCE_KEY; import android.app.Activity; @@ -315,7 +316,9 @@ public class SettingsActivity extends FragmentActivity if (!Flags.oneGridSpecs() // adding this condition until fixing b/378972567 || InvariantDeviceProfile.INSTANCE.get(getContext()).deviceType - == TYPE_MULTI_DISPLAY) { + == TYPE_MULTI_DISPLAY + || InvariantDeviceProfile.INSTANCE.get(getContext()).deviceType + == TYPE_TABLET) { return false; } // When the setting changes rotate the screen accordingly to showcase the result