mirror of
https://github.com/LawnchairLauncher/lawnchair.git
synced 2026-03-04 01:46:49 +00:00
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
This commit is contained in:
@@ -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<DisplayOption> 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<GridDimension> rowCounts = new ArrayList<>();
|
||||
ArrayList<GridSize> 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<GridDimension> list, int minWidthDp,
|
||||
private static GridSize findBestGridSize(List<GridSize> 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();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user