diff --git a/flexera/src/app/flexera/home/FullScreenFolders.kt b/flexera/src/app/flexera/home/FullScreenFolders.kt index 9ccd65400d..45547164e1 100644 --- a/flexera/src/app/flexera/home/FullScreenFolders.kt +++ b/flexera/src/app/flexera/home/FullScreenFolders.kt @@ -26,9 +26,10 @@ import kotlin.math.roundToInt * darkened as behind the app drawer ([FolderBlur], [dim]), with light status bar icons over it * ([setLightBarIcons]), and the folder's apps sit at the bottom of the screen, within the * thumb's reach, with the folder's name below them. They are laid out like the home screen's - * icons: in its columns, in cells of the same size + * icons: across its grid, in its columns or in as many as the owner chose ([columns]), in rows + * as high as its rows * ([cellSize], [com.android.launcher3.folder.FolderGridOrganizer.createFullScreenFolderGridOrganizer]), - * in no more rows than fit on the screen ([maxHeight]). + * and in no more rows than fit on the screen ([maxHeight]). * Where the folder's icon is makes no difference to where its apps appear. * * What is seen of the folder is its apps, its name and its page dots; everywhere else is the @@ -58,16 +59,35 @@ object FullScreenFolders { fun isOn(context: Context): Boolean = PreferenceManager2.getInstance(context).fullScreenFolders.firstCached() + /** The fewest and the most columns offered for full-screen folders (Settings, Folders). */ + const val MIN_COLUMNS = 2 + const val MAX_COLUMNS = 6 + /** - * The size of a cell in a full-screen folder: that of the home screen's cells as they are - * laid out on a page (stretched to fill it, so larger than the device profile's own cell - * size), less the difference between the folder's and the home screen's spacing between - * cells. The folder's apps are then as far apart as the home screen's, both ways, and a - * folder centred on the screen has its columns where the home screen has them. A row is - * never lower than one app with its label needs, should the home screen's rows be lower. + * How many columns a full-screen folder has: as many as the owner chose under Settings, + * Folders, or the home screen's when they chose none (the default). Never more than fit + * across the home screen's grid with a whole icon in each, which the home screen's own + * count always does. */ @JvmStatic - fun cellSize(launcher: Launcher): Point { + fun columns(launcher: Launcher): Int { + val dp = launcher.deviceProfile + val home = homeColumns(dp) + val chosen = PreferenceManager2.getInstance(launcher).fullScreenFolderColumns.firstCached() + if (chosen <= 0) return home + val gap = dp.folderCellLayoutBorderSpacePx.x + val fit = home * homeCell(launcher).x / (dp.folderChildIconSizePx + gap) + return chosen.coerceIn(1, max(home, fit)) + } + + private fun homeColumns(dp: DeviceProfile): Int = max(1, dp.inv.numColumns) + + /** + * A cell of the home screen as it is laid out on a page (stretched to fill it, so larger + * than the device profile's own cell size), with the space between two cells added: the + * distance from one icon to the next, across and down. + */ + private fun homeCell(launcher: Launcher): Point { val dp = launcher.deviceProfile val workspace = launcher.workspace val page = workspace?.getPageAt(workspace.currentPage) as? CellLayout @@ -75,20 +95,35 @@ object FullScreenFolders { var height = page?.cellHeight ?: 0 if (width <= 0 || height <= 0) { // No page laid out yet: the width as a page would lay it out. - val columns = max(1, dp.inv.numColumns) + val columns = homeColumns(dp) val pageWidth = dp.deviceProperties.widthPx - dp.workspacePadding.left - dp.workspacePadding.right - dp.cellLayoutPaddingPx.left - dp.cellLayoutPaddingPx.right width = (pageWidth - (columns - 1) * dp.cellLayoutBorderSpacePx.x) / columns height = dp.cellHeightPx } + return Point(width + dp.cellLayoutBorderSpacePx.x, height + dp.cellLayoutBorderSpacePx.y) + } + + /** + * The size of a cell in a full-screen folder. Across, the home screen's grid is shared out + * among the folder's [columns], less the folder's spacing between cells: with as many + * columns as the home screen, that is the home screen's own cells, and a folder centred on + * the screen has its columns where the home screen has them; with fewer, the apps spread + * wider apart over the same width, with more they move closer together. Down, a row is as + * high as the home screen's, less the same difference in spacing, but never lower than one + * app with its label needs. + */ + @JvmStatic + fun cellSize(launcher: Launcher): Point { + val dp = launcher.deviceProfile + val home = homeCell(launcher) + val across = home.x * homeColumns(dp) / columns(launcher) val appHeight = dp.folderChildIconSizePx + dp.folderChildDrawablePaddingPx + Utilities.calculateTextHeight(dp.folderChildTextSizePx.toFloat()) return Point( - max(width + dp.cellLayoutBorderSpacePx.x - dp.folderCellLayoutBorderSpacePx.x, - dp.folderChildIconSizePx), - max(height + dp.cellLayoutBorderSpacePx.y - dp.folderCellLayoutBorderSpacePx.y, - appHeight), + max(across - dp.folderCellLayoutBorderSpacePx.x, dp.folderChildIconSizePx), + max(home.y - dp.folderCellLayoutBorderSpacePx.y, appHeight), ) } diff --git a/lawnchair/src/app/lawnchair/preferences2/PreferenceManager2.kt b/lawnchair/src/app/lawnchair/preferences2/PreferenceManager2.kt index 8172e1fa50..c798d70134 100644 --- a/lawnchair/src/app/lawnchair/preferences2/PreferenceManager2.kt +++ b/lawnchair/src/app/lawnchair/preferences2/PreferenceManager2.kt @@ -909,6 +909,14 @@ class PreferenceManager2 @Inject constructor( defaultValue = true, ) + // Flexera Launcher: how many columns a full-screen folder has + // (app.flexera.home.FullScreenFolders.columns); 0, the default, is as many as the home + // screen has. Read when a folder opens, so nothing has to be reloaded. + val fullScreenFolderColumns = preference( + key = intPreferencesKey(name = "flexera_full_screen_folder_columns"), + defaultValue = 0, + ) + val autoUpdaterNightly = preference( key = booleanPreferencesKey(name = "enable_nightly_auto_updater"), defaultValue = if (BuildConfig.APPLICATION_ID.contains("nightly")) { diff --git a/lawnchair/src/app/lawnchair/ui/preferences/destinations/FolderPreferences.kt b/lawnchair/src/app/lawnchair/ui/preferences/destinations/FolderPreferences.kt index 67167ccafc..e49784a09e 100644 --- a/lawnchair/src/app/lawnchair/ui/preferences/destinations/FolderPreferences.kt +++ b/lawnchair/src/app/lawnchair/ui/preferences/destinations/FolderPreferences.kt @@ -20,8 +20,10 @@ import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.stringResource +import app.flexera.home.FullScreenFolders import app.lawnchair.preferences.getAdapter import app.lawnchair.preferences.preferenceManager +import app.lawnchair.preferences.rememberTransformAdapter import app.lawnchair.preferences2.preferenceManager2 import app.lawnchair.ui.preferences.LocalIsExpandedScreen import app.lawnchair.ui.preferences.components.NavigationActionPreference @@ -32,6 +34,7 @@ import app.lawnchair.ui.preferences.components.layout.ExpandAndShrink import app.lawnchair.ui.preferences.components.layout.PreferenceGroup import app.lawnchair.ui.preferences.components.layout.PreferenceLayout import app.lawnchair.ui.preferences.navigation.GeneralIconShape +import com.android.launcher3.InvariantDeviceProfile import com.android.launcher3.R import com.android.launcher3.Utilities @@ -52,8 +55,8 @@ fun FolderPreferences( .firstOrNull { it.value == folderIconShapeAdapter.state.value } ?.label?.invoke() ?: stringResource(id = R.string.custom) - // Flexera Launcher: full-screen folders have no panel, and their columns are the home - // screen's, so the panel's opacity and the column count are hidden while they are on. + // Flexera Launcher: full-screen folders have no panel, and columns of their own, so the + // panel's opacity and the floating folder's column count are hidden while they are on. val fullScreenFoldersAdapter = prefs2.fullScreenFolders.getAdapter() PreferenceGroup(heading = stringResource(id = R.string.general_label)) { // Flexera Launcher: full-screen folders (app.flexera.home.FullScreenFolders). @@ -98,7 +101,22 @@ fun FolderPreferences( } } PreferenceGroup(heading = stringResource(id = R.string.grid)) { - // Flexera Launcher: hidden for full-screen folders; see fullScreenFoldersAdapter. + // Flexera Launcher: a full-screen folder has columns of its own + // (app.flexera.home.FullScreenFolders.columns), as many as the home screen's until + // the owner picks a number; the floating folder's slider is hidden meanwhile. + ExpandAndShrink(visible = fullScreenFoldersAdapter.state.value) { + val homeColumns = InvariantDeviceProfile.INSTANCE.get(context).numColumns + SliderPreference( + label = stringResource(id = R.string.columns), + adapter = rememberTransformAdapter( + adapter = prefs2.fullScreenFolderColumns.getAdapter(), + transformGet = { if (it > 0) it else homeColumns }, + transformSet = { it }, + ), + step = 1, + valueRange = FullScreenFolders.MIN_COLUMNS..maxOf(FullScreenFolders.MAX_COLUMNS, homeColumns), + ) + } ExpandAndShrink(visible = !fullScreenFoldersAdapter.state.value) { SliderPreference( label = stringResource(id = R.string.max_folder_columns), diff --git a/src/com/android/launcher3/folder/FolderGridOrganizer.java b/src/com/android/launcher3/folder/FolderGridOrganizer.java index df43ae2a62..4644839904 100644 --- a/src/com/android/launcher3/folder/FolderGridOrganizer.java +++ b/src/com/android/launcher3/folder/FolderGridOrganizer.java @@ -75,14 +75,15 @@ public class FolderGridOrganizer { /** * Flexera Launcher: the grid of an open full-screen folder (app.flexera.home.FullScreenFolders): - * the home screen's columns, filled row by row, and as many rows as a folder may have, or as - * fit on the screen ({@code rowsThatFit}) where that is fewer, so that no row is cut off and - * the other apps go to the next pages. Only the open folder is laid out with it; its icon's - * preview keeps the folder grid. + * {@code columns} columns (FullScreenFolders.columns: the home screen's, or as many as the + * owner chose), filled row by row, and as many rows as a folder may have, or as fit on the + * screen ({@code rowsThatFit}) where that is fewer, so that no row is cut off and the other + * apps go to the next pages. Only the open folder is laid out with it; its icon's preview + * keeps the folder grid. */ public static FolderGridOrganizer createFullScreenFolderGridOrganizer( - DeviceProfile profile, int rowsThatFit) { - return new FolderGridOrganizer(Math.max(1, profile.inv.numColumns), + DeviceProfile profile, int columns, int rowsThatFit) { + return new FolderGridOrganizer(Math.max(1, columns), Math.max(1, Math.min(profile.numFolderRows, rowsThatFit)), true); } diff --git a/src/com/android/launcher3/folder/FolderPagedView.java b/src/com/android/launcher3/folder/FolderPagedView.java index d7daf4aeb8..37bc36728f 100644 --- a/src/com/android/launcher3/folder/FolderPagedView.java +++ b/src/com/android/launcher3/folder/FolderPagedView.java @@ -148,8 +148,8 @@ public class FolderPagedView extends PagedView implements Cli /** * Flexera Launcher: a full-screen folder (app.flexera.home.FullScreenFolders) lays its apps out - * in the home screen's columns, each as wide as on the home screen; a floating one in its own - * grid. Called as the folder opens, before its items are bound. {@code maxHeight} is the most + * across the home screen's grid, in the home screen's columns or in as many as the owner + * chose; a floating one in its own grid. Called as the folder opens, before its items are bound. {@code maxHeight} is the most * this view can be high in the folder, its padding included. */ void setFullScreen(boolean fullScreen, int maxHeight) { @@ -161,7 +161,8 @@ public class FolderPagedView extends PagedView implements Cli int gap = grid.folderCellLayoutBorderSpacePx.y; int room = maxHeight - getPaddingTop() - getPaddingBottom(); int rowsThatFit = (room + gap) / (FullScreenFolders.cellSize(launcher).y + gap); - mOrganizer = FolderGridOrganizer.createFullScreenFolderGridOrganizer(grid, rowsThatFit); + mOrganizer = FolderGridOrganizer.createFullScreenFolderGridOrganizer( + grid, FullScreenFolders.columns(launcher), rowsThatFit); } else { mOrganizer = mFloatingOrganizer; } @@ -432,7 +433,8 @@ public class FolderPagedView extends PagedView implements Cli if (mFolder.isInAppDrawer()) { page.setCellDimensions(grid.getAllAppsProfile().getCellWidthPx(), grid.getAllAppsProfile().getCellHeightPx()); } else if (mFullScreen && mFolder.mActivityContext instanceof Launcher launcher) { - // Flexera Launcher: cells as large as the home screen's, so that the apps line up. + // Flexera Launcher: cells that share the home screen grid's width out among the + // folder's columns; with as many columns as the home screen, its cells exactly. Point cell = FullScreenFolders.cellSize(launcher); page.setCellDimensions(cell.x, cell.y); } else {