diff --git a/build.gradle b/build.gradle index 40a308abde..17f43692f2 100644 --- a/build.gradle +++ b/build.gradle @@ -408,6 +408,9 @@ dependencies { implementation "androidx.room:room-ktx:$roomVersion" ksp "androidx.room:room-compiler:$roomVersion" + def core_version = "1.13.1" + implementation "androidx.core:core:$core_version" + implementation "com.github.topjohnwu.libsu:service:6.0.0" // Persian Date diff --git a/lawnchair/res/xml/device_profiles.xml b/lawnchair/res/xml/device_profiles.xml index 7c48a86b8e..54f66c26f7 100644 --- a/lawnchair/res/xml/device_profiles.xml +++ b/lawnchair/res/xml/device_profiles.xml @@ -168,7 +168,6 @@ launcher:numFolderRows="3" launcher:numFolderColumns="3" launcher:numHotseatIcons="6" - launcher:hotseatColumnSpanLandscape="4" launcher:numAllAppsColumns="6" launcher:isScalable="true" launcher:inlineNavButtonsEndSpacing="@dimen/taskbar_button_margin_6_5" diff --git a/prebuilts/libs/framework-15.jar b/prebuilts/libs/framework-15.jar new file mode 100644 index 0000000000..265de0f75c Binary files /dev/null and b/prebuilts/libs/framework-15.jar differ diff --git a/res/xml/split_configuration.xml b/res/xml/split_configuration.xml index 531fef893b..60aedb3c60 100644 --- a/res/xml/split_configuration.xml +++ b/res/xml/split_configuration.xml @@ -5,10 +5,6 @@ INSTANCE = new MainThreadInitializedObject<>(InvariantDeviceProfile::new); - @Override - public void close() { - - } - @Retention(RetentionPolicy.SOURCE) @IntDef({TYPE_PHONE, TYPE_MULTI_DISPLAY, TYPE_TABLET}) public @interface DeviceType {} @@ -110,17 +105,15 @@ public class InvariantDeviceProfile implements SafeCloseable { // Used for arrays to specify different sizes (e.g. border spaces, width/height) in different // constraints static final int COUNT_SIZES = 4; - public static final int INDEX_DEFAULT = 0; - public static final int INDEX_LANDSCAPE = 1; - public static final int INDEX_TWO_PANEL_PORTRAIT = 2; - public static final int INDEX_TWO_PANEL_LANDSCAPE = 3; + static final int INDEX_DEFAULT = 0; + static final int INDEX_LANDSCAPE = 1; + 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 */ - public static final String RES_GRID_NUM_ROWS = "grid_num_rows"; - public static final String RES_GRID_NUM_COLUMNS = "grid_num_columns"; - public static final String RES_GRID_ICON_SIZE_DP = "grid_icon_size_dp"; - - private static final String KEY_IDP_GRID_NAME = "idp_grid_name"; + /** 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"; /** * Number of icons per row and column in the workspace. @@ -129,21 +122,16 @@ public class InvariantDeviceProfile implements SafeCloseable { public int numColumns; public int numSearchContainerColumns; - /** - * Original profile before preference overrides - */ - public GridOption closestProfile; - /** * Number of icons per row and column in the folder. */ - public int numFolderRows; - public int numFolderColumns; + public int[] numFolderRows; + public int[] numFolderColumns; public float[] iconSize; public float[] iconTextSize; public int iconBitmapSize; public int fillResIconDpi; - public static @DeviceType int deviceType; + public @DeviceType int deviceType; public PointF[] minCellSize; @@ -177,7 +165,6 @@ public class InvariantDeviceProfile implements SafeCloseable { */ public int numDatabaseHotseatIcons; - public int[] hotseatColumnSpan; public float[] hotseatBarBottomSpace; public float[] hotseatQsbSpace; @@ -185,6 +172,7 @@ public class InvariantDeviceProfile implements SafeCloseable { * Number of columns in the all apps list. */ public int numAllAppsColumns; + public int numAllAppsRowsForCellHeightCalculation; public int numDatabaseAllAppsColumns; public @StyleRes int allAppsStyle; @@ -194,16 +182,10 @@ public class InvariantDeviceProfile implements SafeCloseable { protected boolean isScalable; @XmlRes public int devicePaddingId = INVALID_RESOURCE_HANDLE; - - public String dbFile; - public int defaultLayoutId; - @XmlRes public int workspaceSpecsId = INVALID_RESOURCE_HANDLE; - @XmlRes public int workspaceSpecsTwoPanelId = INVALID_RESOURCE_HANDLE; - @XmlRes public int allAppsSpecsId = INVALID_RESOURCE_HANDLE; @XmlRes @@ -216,7 +198,6 @@ public class InvariantDeviceProfile implements SafeCloseable { public int hotseatSpecsId = INVALID_RESOURCE_HANDLE; @XmlRes public int hotseatSpecsTwoPanelId = INVALID_RESOURCE_HANDLE; - @XmlRes public int workspaceCellSpecsId = INVALID_RESOURCE_HANDLE; @XmlRes @@ -225,6 +206,9 @@ public class InvariantDeviceProfile implements SafeCloseable { public int allAppsCellSpecsId = INVALID_RESOURCE_HANDLE; @XmlRes public int allAppsCellSpecsTwoPanelId = INVALID_RESOURCE_HANDLE; + + public String dbFile; + public int defaultLayoutId; public int demoModeLayoutId; public boolean[] inlineQsb = new boolean[COUNT_SIZES]; @@ -234,7 +218,6 @@ public class InvariantDeviceProfile implements SafeCloseable { public List supportedProfiles = Collections.EMPTY_LIST; public Point defaultWallpaperSize; - public Rect defaultWidgetPadding; private final ArrayList mChangeListeners = new ArrayList<>(); @@ -246,16 +229,16 @@ public class InvariantDeviceProfile implements SafeCloseable { String gridName = getCurrentGridName(context); String newGridName = initGrid(context, gridName); if (!newGridName.equals(gridName)) { - Utilities.getPrefs(context).edit().putString(KEY_IDP_GRID_NAME, newGridName).apply(); + LauncherPrefs.get(context).put(GRID_NAME, newGridName); } - LockedUserState.get(context).runOnUserUnlocked(() -> { - new DeviceGridState(this).writeToPrefs(context); - }); + LockedUserState.get(context).runOnUserUnlocked(() -> + new DeviceGridState(this).writeToPrefs(context)); DisplayController.INSTANCE.get(context).setPriorityListener( (displayContext, info, flags) -> { if ((flags & (CHANGE_DENSITY | CHANGE_SUPPORTED_BOUNDS - | CHANGE_NAVIGATION_MODE)) != 0) { + | CHANGE_NAVIGATION_MODE | CHANGE_TASKBAR_PINNING + | CHANGE_DESKTOP_MODE)) != 0) { onConfigChanged(displayContext); } }); @@ -265,12 +248,10 @@ public class InvariantDeviceProfile implements SafeCloseable { * This constructor should NOT have any monitors by design. */ public InvariantDeviceProfile(Context context, String gridName) { - this(context, DeviceProfileOverrides.INSTANCE.get(context).getGridInfo(gridName)); - } - - public InvariantDeviceProfile(Context context, DeviceProfileOverrides.DBGridInfo dbGridInfo) { - String gridName = DeviceProfileOverrides.INSTANCE.get(context).getGridName(dbGridInfo); - initGrid(context, gridName, dbGridInfo); + String newName = initGrid(context, gridName); + if (newName == null || !newName.equals(gridName)) { + throw new IllegalArgumentException("Unknown grid name: " + gridName); + } } /** @@ -283,7 +264,7 @@ public class InvariantDeviceProfile implements SafeCloseable { // Get the display info based on default display and interpolate it to existing display Info defaultInfo = DisplayController.INSTANCE.get(context).getInfo(); - @DeviceType int defaultDeviceType = getDeviceType(defaultInfo); + @DeviceType int defaultDeviceType = defaultInfo.getDeviceType(); DisplayOption defaultDisplayOption = invDistWeightedInterpolate( defaultInfo, getPredefinedDeviceProfiles(context, gridName, defaultDeviceType, @@ -292,7 +273,7 @@ public class InvariantDeviceProfile implements SafeCloseable { Context displayContext = context.createDisplayContext(display); Info myInfo = new Info(displayContext); - @DeviceType int deviceType = getDeviceType(myInfo); + @DeviceType int deviceType = myInfo.getDeviceType(); DisplayOption myDisplayOption = invDistWeightedInterpolate( myInfo, getPredefinedDeviceProfiles(context, gridName, deviceType, @@ -316,6 +297,11 @@ public class InvariantDeviceProfile implements SafeCloseable { initGrid(context, myInfo, result, deviceType); } + @Override + public void close() { + DisplayController.INSTANCE.executeIfCreated(dc -> dc.setPriorityListener(null)); + } + /** * Reinitialize the current grid after a restore, where some grids might now be disabled. */ @@ -324,8 +310,13 @@ public class InvariantDeviceProfile implements SafeCloseable { String currentDbFile = dbFile; String newGridName = initGrid(context, currentGridName); String newDbFile = dbFile; + FileLog.d(TAG, "Reinitializing grid after restore." + + " currentGridName=" + currentGridName + + ", currentDbFile=" + currentDbFile + + ", newGridName=" + newGridName + + ", newDbFile=" + newDbFile); if (!newDbFile.equals(currentDbFile)) { - Log.d(TAG, "Restored grid is disabled : " + currentGridName + FileLog.d(TAG, "Restored grid is disabled : " + currentGridName + ", migrating to: " + newGridName + ", removing all other grid db files"); for (String gridDbFile : LauncherFiles.GRID_DB_FILES) { @@ -333,58 +324,37 @@ public class InvariantDeviceProfile implements SafeCloseable { continue; } if (context.getDatabasePath(gridDbFile).delete()) { - Log.d(TAG, "Removed old grid db file: " + gridDbFile); + FileLog.d(TAG, "Removed old grid db file: " + gridDbFile); } } setCurrentGrid(context, newGridName); } } - public static @DeviceType int getDeviceType(Info displayInfo) { - int flagPhone = 1 << 0; - int flagTablet = 1 << 1; - - int type = displayInfo.supportedBounds.stream() - .mapToInt(bounds -> displayInfo.isTablet(bounds) ? flagTablet : flagPhone) - .reduce(0, (a, b) -> a | b); - if ((type == (flagPhone | flagTablet))) { - // device has profiles supporting both phone and table modes - return TYPE_MULTI_DISPLAY; - } else if (type == flagTablet) { - return TYPE_TABLET; - } else { - return TYPE_PHONE; - } - } - public static String getCurrentGridName(Context context) { - return DeviceProfileOverrides.INSTANCE.get(context).getCurrentGridName(); + return LauncherPrefs.get(context).get(GRID_NAME); } - private String initGrid(Context context, String gridName, DeviceProfileOverrides.DBGridInfo dbGridInfo) { + private String initGrid(Context context, String gridName) { Info displayInfo = DisplayController.INSTANCE.get(context).getInfo(); - @DeviceType int deviceType = getDeviceType(displayInfo); + @DeviceType int deviceType = displayInfo.getDeviceType(); ArrayList allOptions = getPredefinedDeviceProfiles(context, gridName, deviceType, RestoreDbTask.isPending(context)); DisplayOption displayOption = invDistWeightedInterpolate(displayInfo, allOptions, deviceType); - initGrid(context, displayInfo, displayOption, deviceType, dbGridInfo); + initGrid(context, displayInfo, displayOption, deviceType); return displayOption.grid.name; } - private void initGrid(Context context, Info displayInfo, DisplayOption displayOption, - @DeviceType int deviceType) { - DeviceProfileOverrides.DBGridInfo dbGridInfo = DeviceProfileOverrides.INSTANCE.get(context) - .getGridInfo(); - initGrid(context, displayInfo, displayOption, deviceType, dbGridInfo); - } - - private String initGrid(Context context, String gridName) { - DeviceProfileOverrides.DBGridInfo dbGridInfo = DeviceProfileOverrides.INSTANCE.get(context) - .getGridInfo(); - return initGrid(context, gridName, dbGridInfo); + /** + * @deprecated This is a temporary solution because on the backup and restore case we modify the + * IDP, this resets it. b/332974074 + */ + @Deprecated + public void reset(Context context) { + initGrid(context, getCurrentGridName(context)); } @VisibleForTesting @@ -393,15 +363,13 @@ public class InvariantDeviceProfile implements SafeCloseable { } private void initGrid(Context context, Info displayInfo, DisplayOption displayOption, - @DeviceType int deviceType, DeviceProfileOverrides.DBGridInfo dbGridInfo) { - DeviceProfileOverrides.Options overrideOptions = DeviceProfileOverrides.INSTANCE.get(context) - .getOverrides(displayOption.grid); + @DeviceType int deviceType) { DisplayMetrics metrics = context.getResources().getDisplayMetrics(); - closestProfile = displayOption.grid; - numRows = dbGridInfo.getNumRows(); - numColumns = dbGridInfo.getNumColumns(); + GridOption closestProfile = displayOption.grid; + numRows = closestProfile.numRows; + numColumns = closestProfile.numColumns; numSearchContainerColumns = closestProfile.numSearchContainerColumns; - dbFile = dbGridInfo.getDbFile(); + dbFile = closestProfile.dbFile; defaultLayoutId = closestProfile.defaultLayoutId; demoModeLayoutId = closestProfile.demoModeLayoutId; @@ -425,7 +393,8 @@ public class InvariantDeviceProfile implements SafeCloseable { workspaceCellSpecsTwoPanelId = closestProfile.mWorkspaceCellSpecsTwoPanelId; allAppsCellSpecsId = closestProfile.mAllAppsCellSpecsId; allAppsCellSpecsTwoPanelId = closestProfile.mAllAppsCellSpecsTwoPanelId; - + numAllAppsRowsForCellHeightCalculation = + closestProfile.mNumAllAppsRowsForCellHeightCalculation; this.deviceType = deviceType; inlineNavButtonsEndSpacing = closestProfile.inlineNavButtonsEndSpacing; @@ -446,17 +415,16 @@ public class InvariantDeviceProfile implements SafeCloseable { horizontalMargin = displayOption.horizontalMargin; - numShownHotseatIcons = deviceType == TYPE_MULTI_DISPLAY - ? closestProfile.numHotseatIcons : dbGridInfo.getNumHotseatColumns(); + numShownHotseatIcons = closestProfile.numHotseatIcons; numDatabaseHotseatIcons = deviceType == TYPE_MULTI_DISPLAY - ? closestProfile.numDatabaseHotseatIcons : numShownHotseatIcons; - hotseatColumnSpan = closestProfile.hotseatColumnSpan; + ? closestProfile.numDatabaseHotseatIcons : closestProfile.numHotseatIcons; hotseatBarBottomSpace = displayOption.hotseatBarBottomSpace; hotseatQsbSpace = displayOption.hotseatQsbSpace; allAppsStyle = closestProfile.allAppsStyle; numAllAppsColumns = closestProfile.numAllAppsColumns; + numDatabaseAllAppsColumns = deviceType == TYPE_MULTI_DISPLAY ? closestProfile.numDatabaseAllAppsColumns : closestProfile.numAllAppsColumns; @@ -475,9 +443,6 @@ public class InvariantDeviceProfile implements SafeCloseable { // Supported overrides: numRows, numColumns, iconSize applyPartnerDeviceProfileOverrides(context, metrics); - // Lawnchair ignores partner overrides and allows the user to customize the grid themselves - overrideOptions.applyUi(this); - final List localSupportedProfiles = new ArrayList<>(); defaultWallpaperSize = new Point(displayInfo.currentSize); SparseArray dotRendererCache = new SparseArray<>(); @@ -529,15 +494,10 @@ public class InvariantDeviceProfile implements SafeCloseable { mChangeListeners.remove(listener); } - public void onPreferencesChanged(Context context) { - Context appContext = context.getApplicationContext(); - MAIN_EXECUTOR.execute(() -> onConfigChanged(appContext)); - } public void setCurrentGrid(Context context, String gridName) { - DeviceProfileOverrides.INSTANCE.get(context).setCurrentGrid(gridName); - Context appContext = context.getApplicationContext(); - MAIN_EXECUTOR.execute(() -> onConfigChanged(appContext)); + LauncherPrefs.get(context).put(GRID_NAME, gridName); + MAIN_EXECUTOR.execute(() -> onConfigChanged(context.getApplicationContext())); } private Object[] toModelState() { @@ -546,7 +506,9 @@ public class InvariantDeviceProfile implements SafeCloseable { iconBitmapSize, fillResIconDpi, numDatabaseAllAppsColumns, dbFile}; } - private void onConfigChanged(Context context) { + /** Updates IDP using the provided context. Notifies listeners of change. */ + @VisibleForTesting + public void onConfigChanged(Context context) { Object[] oldState = toModelState(); // Re-init grid @@ -613,10 +575,49 @@ public class InvariantDeviceProfile implements SafeCloseable { return filteredProfiles; } + /** + * Returns the GridOption associated to the given file name or null if the fileName is not + * supported. + * Ej, launcher.db -> "normal grid", launcher_4_by_4.db -> "practical grid" + */ + public GridOption getGridOptionFromFileName(Context context, String fileName) { + return parseAllGridOptions(context).stream() + .filter(gridOption -> Objects.equals(gridOption.dbFile, fileName)) + .findFirst() + .orElse(null); + } + + /** + * Returns the name of the given size on the current device or empty string if the size is not + * supported. Ej. 4x4 -> normal, 5x4 -> practical, etc. + * (Note: the name of the grid can be different for the same grid size depending of + * the values of the InvariantDeviceProfile) + * + */ + public String getGridNameFromSize(Context context, Point size) { + return parseAllGridOptions(context).stream() + .filter(gridOption -> gridOption.numColumns == size.x + && gridOption.numRows == size.y) + .map(gridOption -> gridOption.name) + .findFirst() + .orElse(""); + } + + /** + * Returns the grid option for the given gridName on the current device (Note: the gridOption + * be different for the same gridName depending on the values of the InvariantDeviceProfile). + */ + public GridOption getGridOptionFromName(Context context, String gridName) { + return parseAllGridOptions(context).stream() + .filter(gridOption -> Objects.equals(gridOption.name, gridName)) + .findFirst() + .orElse(null); + } + /** * @return all the grid options that can be shown on the device */ - public static List parseAllGridOptions(Context context) { + public List parseAllGridOptions(Context context) { return parseAllDefinedGridOptions(context) .stream() .filter(go -> go.isEnabled(deviceType)) @@ -758,14 +759,11 @@ public class InvariantDeviceProfile implements SafeCloseable { } public DeviceProfile getDeviceProfile(Context context) { - Resources res = context.getResources(); - Configuration config = context.getResources().getConfiguration(); + WindowManagerProxy windowManagerProxy = WindowManagerProxy.INSTANCE.get(context); + Rect bounds = windowManagerProxy.getCurrentBounds(context); + int rotation = windowManagerProxy.getRotation(context); - float screenWidth = config.screenWidthDp * res.getDisplayMetrics().density; - float screenHeight = config.screenHeightDp * res.getDisplayMetrics().density; - int rotation = WindowManagerProxy.INSTANCE.get(context).getRotation(context); - - return getBestMatch(screenWidth, screenHeight, rotation); + return getBestMatch(bounds.width(), bounds.height(), rotation); } /** @@ -857,28 +855,29 @@ public class InvariantDeviceProfile implements SafeCloseable { public final int numSearchContainerColumns; public final int deviceCategory; - public final int numFolderRows; - public final int numFolderColumns; + private final int[] numFolderRows = new int[COUNT_SIZES]; + private final int[] numFolderColumns = new int[COUNT_SIZES]; private final @StyleRes int folderStyle; private final @StyleRes int cellStyle; private final @StyleRes int allAppsStyle; - public final int numAllAppsColumns; - public final int numDatabaseAllAppsColumns; - public final int numHotseatIcons; - public final int numDatabaseHotseatIcons; - - private final int[] hotseatColumnSpan = new int[COUNT_SIZES]; + private final int numAllAppsColumns; + private final int mNumAllAppsRowsForCellHeightCalculation; + private final int numDatabaseAllAppsColumns; + private final int numHotseatIcons; + private final int numDatabaseHotseatIcons; private final boolean[] inlineQsb = new boolean[COUNT_SIZES]; private @DimenRes int inlineNavButtonsEndSpacing; - public final String dbFile; + private final String dbFile; private final int defaultLayoutId; private final int demoModeLayoutId; - private final int mWorkspaceSpecsId; + private final boolean isScalable; + private final int devicePaddingId; + private final int mWorkspaceSpecsId; private final int mWorkspaceSpecsTwoPanelId; private final int mAllAppsSpecsId; private final int mAllAppsSpecsTwoPanelId; @@ -891,15 +890,12 @@ public class InvariantDeviceProfile implements SafeCloseable { private final int mAllAppsCellSpecsId; private final int mAllAppsCellSpecsTwoPanelId; - private final boolean isScalable; - private final int devicePaddingId; - public GridOption(Context context, AttributeSet attrs) { TypedArray a = context.obtainStyledAttributes( attrs, R.styleable.GridDisplayOption); name = a.getString(R.styleable.GridDisplayOption_name); numRows = a.getInt(R.styleable.GridDisplayOption_numRows, 0); - numColumns = a.getInt(R.styleable.GridDisplayOption_numColumns, 4); + numColumns = a.getInt(R.styleable.GridDisplayOption_numColumns, 0); numSearchContainerColumns = a.getInt( R.styleable.GridDisplayOption_numSearchContainerColumns, numColumns); @@ -914,33 +910,50 @@ public class InvariantDeviceProfile implements SafeCloseable { numAllAppsColumns = a.getInt( R.styleable.GridDisplayOption_numAllAppsColumns, numColumns); numDatabaseAllAppsColumns = a.getInt( - R.styleable.GridDisplayOption_numExtendedAllAppsColumns, numAllAppsColumns); + R.styleable.GridDisplayOption_numExtendedAllAppsColumns, 2 * numAllAppsColumns); numHotseatIcons = a.getInt( R.styleable.GridDisplayOption_numHotseatIcons, numColumns); numDatabaseHotseatIcons = a.getInt( R.styleable.GridDisplayOption_numExtendedHotseatIcons, 2 * numHotseatIcons); - hotseatColumnSpan[INDEX_DEFAULT] = a.getInt( - R.styleable.GridDisplayOption_hotseatColumnSpan, numColumns); - hotseatColumnSpan[INDEX_LANDSCAPE] = a.getInt( - R.styleable.GridDisplayOption_hotseatColumnSpanLandscape, numColumns); - hotseatColumnSpan[INDEX_TWO_PANEL_LANDSCAPE] = a.getInt( - R.styleable.GridDisplayOption_hotseatColumnSpanTwoPanelLandscape, - numColumns); - hotseatColumnSpan[INDEX_TWO_PANEL_PORTRAIT] = a.getInt( - R.styleable.GridDisplayOption_hotseatColumnSpanTwoPanelPortrait, - numColumns); - inlineNavButtonsEndSpacing = a.getResourceId(R.styleable.GridDisplayOption_inlineNavButtonsEndSpacing, R.dimen.taskbar_button_margin_default); - numFolderRows = a.getInt( + numFolderRows[INDEX_DEFAULT] = a.getInt( R.styleable.GridDisplayOption_numFolderRows, numRows); - numFolderColumns = a.getInt( + numFolderColumns[INDEX_DEFAULT] = a.getInt( R.styleable.GridDisplayOption_numFolderColumns, numColumns); + if (FeatureFlags.enableResponsiveWorkspace()) { + numFolderRows[INDEX_LANDSCAPE] = a.getInt( + R.styleable.GridDisplayOption_numFolderRowsLandscape, + numFolderRows[INDEX_DEFAULT]); + numFolderColumns[INDEX_LANDSCAPE] = a.getInt( + R.styleable.GridDisplayOption_numFolderColumnsLandscape, + numFolderColumns[INDEX_DEFAULT]); + numFolderRows[INDEX_TWO_PANEL_PORTRAIT] = a.getInt( + R.styleable.GridDisplayOption_numFolderRowsTwoPanelPortrait, + numFolderRows[INDEX_DEFAULT]); + numFolderColumns[INDEX_TWO_PANEL_PORTRAIT] = a.getInt( + R.styleable.GridDisplayOption_numFolderColumnsTwoPanelPortrait, + numFolderColumns[INDEX_DEFAULT]); + numFolderRows[INDEX_TWO_PANEL_LANDSCAPE] = a.getInt( + R.styleable.GridDisplayOption_numFolderRowsTwoPanelLandscape, + numFolderRows[INDEX_DEFAULT]); + numFolderColumns[INDEX_TWO_PANEL_LANDSCAPE] = a.getInt( + R.styleable.GridDisplayOption_numFolderColumnsTwoPanelLandscape, + numFolderColumns[INDEX_DEFAULT]); + } else { + numFolderRows[INDEX_LANDSCAPE] = numFolderRows[INDEX_DEFAULT]; + numFolderColumns[INDEX_LANDSCAPE] = numFolderColumns[INDEX_DEFAULT]; + numFolderRows[INDEX_TWO_PANEL_PORTRAIT] = numFolderRows[INDEX_DEFAULT]; + numFolderColumns[INDEX_TWO_PANEL_PORTRAIT] = numFolderColumns[INDEX_DEFAULT]; + numFolderRows[INDEX_TWO_PANEL_LANDSCAPE] = numFolderRows[INDEX_DEFAULT]; + numFolderColumns[INDEX_TWO_PANEL_LANDSCAPE] = numFolderColumns[INDEX_DEFAULT]; + } + folderStyle = a.getResourceId(R.styleable.GridDisplayOption_folderStyle, INVALID_RESOURCE_HANDLE); @@ -954,39 +967,42 @@ public class InvariantDeviceProfile implements SafeCloseable { deviceCategory = a.getInt(R.styleable.GridDisplayOption_deviceCategory, DEVICE_CATEGORY_ALL); - if (FeatureFlags.ENABLE_RESPONSIVE_WORKSPACE.get()) { + if (FeatureFlags.enableResponsiveWorkspace()) { mWorkspaceSpecsId = a.getResourceId( R.styleable.GridDisplayOption_workspaceSpecsId, INVALID_RESOURCE_HANDLE); mWorkspaceSpecsTwoPanelId = a.getResourceId( R.styleable.GridDisplayOption_workspaceSpecsTwoPanelId, - INVALID_RESOURCE_HANDLE); + mWorkspaceSpecsId); mAllAppsSpecsId = a.getResourceId( R.styleable.GridDisplayOption_allAppsSpecsId, INVALID_RESOURCE_HANDLE); mAllAppsSpecsTwoPanelId = a.getResourceId( R.styleable.GridDisplayOption_allAppsSpecsTwoPanelId, - INVALID_RESOURCE_HANDLE); + mAllAppsSpecsId); mFolderSpecsId = a.getResourceId( R.styleable.GridDisplayOption_folderSpecsId, INVALID_RESOURCE_HANDLE); mFolderSpecsTwoPanelId = a.getResourceId( R.styleable.GridDisplayOption_folderSpecsTwoPanelId, - INVALID_RESOURCE_HANDLE); + mFolderSpecsId); mHotseatSpecsId = a.getResourceId( R.styleable.GridDisplayOption_hotseatSpecsId, INVALID_RESOURCE_HANDLE); mHotseatSpecsTwoPanelId = a.getResourceId( R.styleable.GridDisplayOption_hotseatSpecsTwoPanelId, - INVALID_RESOURCE_HANDLE); + mHotseatSpecsId); mWorkspaceCellSpecsId = a.getResourceId( R.styleable.GridDisplayOption_workspaceCellSpecsId, INVALID_RESOURCE_HANDLE); mWorkspaceCellSpecsTwoPanelId = a.getResourceId( R.styleable.GridDisplayOption_workspaceCellSpecsTwoPanelId, - INVALID_RESOURCE_HANDLE); + mWorkspaceCellSpecsId); mAllAppsCellSpecsId = a.getResourceId( R.styleable.GridDisplayOption_allAppsCellSpecsId, INVALID_RESOURCE_HANDLE); mAllAppsCellSpecsTwoPanelId = a.getResourceId( R.styleable.GridDisplayOption_allAppsCellSpecsTwoPanelId, - INVALID_RESOURCE_HANDLE); + mAllAppsCellSpecsId); + mNumAllAppsRowsForCellHeightCalculation = a.getInt( + R.styleable.GridDisplayOption_numAllAppsRowsForCellHeightCalculation, + numRows); } else { mWorkspaceSpecsId = INVALID_RESOURCE_HANDLE; mWorkspaceSpecsTwoPanelId = INVALID_RESOURCE_HANDLE; @@ -1000,6 +1016,7 @@ public class InvariantDeviceProfile implements SafeCloseable { mWorkspaceCellSpecsTwoPanelId = INVALID_RESOURCE_HANDLE; mAllAppsCellSpecsId = INVALID_RESOURCE_HANDLE; mAllAppsCellSpecsTwoPanelId = INVALID_RESOURCE_HANDLE; + mNumAllAppsRowsForCellHeightCalculation = numRows; } int inlineForRotation = a.getInt(R.styleable.GridDisplayOption_inlineQsb, @@ -1014,6 +1031,7 @@ public class InvariantDeviceProfile implements SafeCloseable { inlineQsb[INDEX_TWO_PANEL_LANDSCAPE] = (inlineForRotation & INLINE_QSB_FOR_TWO_PANEL_LANDSCAPE) == INLINE_QSB_FOR_TWO_PANEL_LANDSCAPE; + a.recycle(); } diff --git a/src/com/android/launcher3/Utilities.java b/src/com/android/launcher3/Utilities.java index 8cf9ee0285..a0cd6de6f7 100644 --- a/src/com/android/launcher3/Utilities.java +++ b/src/com/android/launcher3/Utilities.java @@ -136,6 +136,9 @@ public final class Utilities { public static final boolean ATLEAST_O_MR1 = Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1; + @ChecksSdkIntAtLeast(api = VERSION_CODES.R) + public static final boolean ATLEAST_R = Build.VERSION.SDK_INT >= Build.VERSION_CODES.R; + @ChecksSdkIntAtLeast(api = VERSION_CODES.S) public static final boolean ATLEAST_S = Build.VERSION.SDK_INT >= Build.VERSION_CODES.S; diff --git a/src/com/android/launcher3/util/window/WindowManagerProxy.java b/src/com/android/launcher3/util/window/WindowManagerProxy.java index c05958c8e1..e699dba792 100644 --- a/src/com/android/launcher3/util/window/WindowManagerProxy.java +++ b/src/com/android/launcher3/util/window/WindowManagerProxy.java @@ -452,21 +452,6 @@ public class WindowManagerProxy implements ResourceBasedOverride, SafeCloseable return new Rect(0, 0, (int) screenWidth, (int) screenHeight); } - /** - * Returns bounds of the display associated with the context, or bounds of - * DEFAULT_DISPLAY - * if the context isn't associated with a display. - */ - public Rect getCurrentBounds(Context displayInfoContext) { - Resources res = displayInfoContext.getResources(); - Configuration config = res.getConfiguration(); - - float screenWidth = config.screenWidthDp * res.getDisplayMetrics().density; - float screenHeight = config.screenHeightDp * res.getDisplayMetrics().density; - - return new Rect(0, 0, (int) screenWidth, (int) screenHeight); - } - /** * Returns rotation of the display associated with the context, or rotation of * DEFAULT_DISPLAY