summaryrefslogtreecommitdiff
path: root/src/com/android/launcher3/InvariantDeviceProfile.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android/launcher3/InvariantDeviceProfile.java')
-rw-r--r--src/com/android/launcher3/InvariantDeviceProfile.java102
1 files changed, 84 insertions, 18 deletions
diff --git a/src/com/android/launcher3/InvariantDeviceProfile.java b/src/com/android/launcher3/InvariantDeviceProfile.java
index c619bc58de..5721ed3493 100644
--- a/src/com/android/launcher3/InvariantDeviceProfile.java
+++ b/src/com/android/launcher3/InvariantDeviceProfile.java
@@ -22,16 +22,17 @@ import static com.android.launcher3.testing.shared.ResourceUtils.INVALID_RESOURC
import static com.android.launcher3.util.DisplayController.CHANGE_DENSITY;
import static com.android.launcher3.util.DisplayController.CHANGE_NAVIGATION_MODE;
import static com.android.launcher3.util.DisplayController.CHANGE_SUPPORTED_BOUNDS;
+import static com.android.launcher3.util.DisplayController.CHANGE_TASKBAR_PINNING;
import static com.android.launcher3.util.Executors.MAIN_EXECUTOR;
import android.annotation.TargetApi;
import android.content.Context;
-import android.content.res.Configuration;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.content.res.XmlResourceParser;
import android.graphics.Point;
import android.graphics.PointF;
+import android.graphics.Rect;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
@@ -121,8 +122,8 @@ public class InvariantDeviceProfile {
/**
* 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;
@@ -190,8 +191,18 @@ public class InvariantDeviceProfile {
public int folderSpecsId = INVALID_RESOURCE_HANDLE;
@XmlRes
public int folderSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
+ @XmlRes
public int hotseatSpecsId = INVALID_RESOURCE_HANDLE;
+ @XmlRes
public int hotseatSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
+ @XmlRes
+ public int workspaceCellSpecsId = INVALID_RESOURCE_HANDLE;
+ @XmlRes
+ public int workspaceCellSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
+ @XmlRes
+ public int allAppsCellSpecsId = INVALID_RESOURCE_HANDLE;
+ @XmlRes
+ public int allAppsCellSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
public String dbFile;
public int defaultLayoutId;
@@ -224,7 +235,7 @@ public class InvariantDeviceProfile {
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)) != 0) {
onConfigChanged(displayContext);
}
});
@@ -287,11 +298,15 @@ public class InvariantDeviceProfile {
* Reinitialize the current grid after a restore, where some grids might now be disabled.
*/
public void reinitializeAfterRestore(Context context) {
- FileLog.d(TAG, "Reinitializing grid after restore");
String currentGridName = getCurrentGridName(context);
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)) {
FileLog.d(TAG, "Restored grid is disabled : " + currentGridName
+ ", migrating to: " + newGridName
@@ -374,6 +389,10 @@ public class InvariantDeviceProfile {
folderSpecsTwoPanelId = closestProfile.mFolderSpecsTwoPanelId;
hotseatSpecsId = closestProfile.mHotseatSpecsId;
hotseatSpecsTwoPanelId = closestProfile.mHotseatSpecsTwoPanelId;
+ workspaceCellSpecsId = closestProfile.mWorkspaceCellSpecsId;
+ workspaceCellSpecsTwoPanelId = closestProfile.mWorkspaceCellSpecsTwoPanelId;
+ allAppsCellSpecsId = closestProfile.mAllAppsCellSpecsId;
+ allAppsCellSpecsTwoPanelId = closestProfile.mAllAppsCellSpecsTwoPanelId;
this.deviceType = deviceType;
inlineNavButtonsEndSpacing = closestProfile.inlineNavButtonsEndSpacing;
@@ -485,7 +504,9 @@ public class InvariantDeviceProfile {
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
@@ -697,14 +718,11 @@ public class InvariantDeviceProfile {
}
public DeviceProfile getDeviceProfile(Context context) {
- Resources res = context.getResources();
- Configuration config = context.getResources().getConfiguration();
-
- float screenWidth = config.screenWidthDp * res.getDisplayMetrics().density;
- float screenHeight = config.screenHeightDp * res.getDisplayMetrics().density;
- int rotation = WindowManagerProxy.INSTANCE.get(context).getRotation(context);
+ WindowManagerProxy windowManagerProxy = WindowManagerProxy.INSTANCE.get(context);
+ Rect bounds = windowManagerProxy.getCurrentBounds(context);
+ int rotation = windowManagerProxy.getRotation(context);
- return getBestMatch(screenWidth, screenHeight, rotation);
+ return getBestMatch(bounds.width(), bounds.height(), rotation);
}
/**
@@ -796,8 +814,8 @@ public class InvariantDeviceProfile {
public final int numSearchContainerColumns;
public final int deviceCategory;
- private final int numFolderRows;
- private 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;
@@ -827,6 +845,10 @@ public class InvariantDeviceProfile {
private final int mFolderSpecsTwoPanelId;
private final int mHotseatSpecsId;
private final int mHotseatSpecsTwoPanelId;
+ private final int mWorkspaceCellSpecsId;
+ private final int mWorkspaceCellSpecsTwoPanelId;
+ private final int mAllAppsCellSpecsId;
+ private final int mAllAppsCellSpecsTwoPanelId;
public GridOption(Context context, AttributeSet attrs) {
TypedArray a = context.obtainStyledAttributes(
@@ -870,11 +892,39 @@ public class InvariantDeviceProfile {
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);
@@ -888,7 +938,7 @@ public class InvariantDeviceProfile {
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(
@@ -909,6 +959,18 @@ public class InvariantDeviceProfile {
mHotseatSpecsTwoPanelId = a.getResourceId(
R.styleable.GridDisplayOption_hotseatSpecsTwoPanelId,
INVALID_RESOURCE_HANDLE);
+ mWorkspaceCellSpecsId = a.getResourceId(
+ R.styleable.GridDisplayOption_workspaceCellSpecsId,
+ INVALID_RESOURCE_HANDLE);
+ mWorkspaceCellSpecsTwoPanelId = a.getResourceId(
+ R.styleable.GridDisplayOption_workspaceCellSpecsTwoPanelId,
+ INVALID_RESOURCE_HANDLE);
+ mAllAppsCellSpecsId = a.getResourceId(
+ R.styleable.GridDisplayOption_allAppsCellSpecsId,
+ INVALID_RESOURCE_HANDLE);
+ mAllAppsCellSpecsTwoPanelId = a.getResourceId(
+ R.styleable.GridDisplayOption_allAppsCellSpecsTwoPanelId,
+ INVALID_RESOURCE_HANDLE);
} else {
mWorkspaceSpecsId = INVALID_RESOURCE_HANDLE;
mWorkspaceSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
@@ -918,6 +980,10 @@ public class InvariantDeviceProfile {
mFolderSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
mHotseatSpecsId = INVALID_RESOURCE_HANDLE;
mHotseatSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
+ mWorkspaceCellSpecsId = INVALID_RESOURCE_HANDLE;
+ mWorkspaceCellSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
+ mAllAppsCellSpecsId = INVALID_RESOURCE_HANDLE;
+ mAllAppsCellSpecsTwoPanelId = INVALID_RESOURCE_HANDLE;
}
int inlineForRotation = a.getInt(R.styleable.GridDisplayOption_inlineQsb,