launcher: create a device profile for foldables
This creates a device_profiles_split.xml that will be used when the
device is a foldable. This makes the changes contained for specific
devices and make it possible to use different padding files in the
future if needed.
Bug: 191879424
Test: tested with NexusLauncher and Launcher3, in foldables and
handhelds
Test: check that 4x4 is not scalable anymore on handhelds by using HSV
Change-Id: If6ef14e3611c5252634c080643433545ce186f0d
diff --git a/src/com/android/launcher3/InvariantDeviceProfile.java b/src/com/android/launcher3/InvariantDeviceProfile.java
index 1b2f177..d844b87 100644
--- a/src/com/android/launcher3/InvariantDeviceProfile.java
+++ b/src/com/android/launcher3/InvariantDeviceProfile.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2015 The Android Open Source Project
+ * Copyright (C) 2021 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -70,11 +70,6 @@
public static final MainThreadInitializedObject<InvariantDeviceProfile> INSTANCE =
new MainThreadInitializedObject<>(InvariantDeviceProfile::new);
- private static final int DEFAULT_TRUE = -1;
- private static final int DEFAULT_SPLIT_DISPLAY = 2;
- private static final int GRID_ENABLED_ALL_DISPLAYS = 0;
- private static final int GRID_ENABLED_SINGLE_DISPLAY = 1;
-
private static final String KEY_IDP_GRID_NAME = "idp_grid_name";
private static final float ICON_SIZE_DEFINED_IN_APP_DP = 48;
@@ -393,7 +388,9 @@
private static ArrayList<DisplayOption> getPredefinedDeviceProfiles(
Context context, String gridName, boolean isSplitDisplay, boolean allowDisabledGrid) {
ArrayList<DisplayOption> profiles = new ArrayList<>();
- try (XmlResourceParser parser = context.getResources().getXml(R.xml.device_profiles)) {
+ int xmlResource = isSplitDisplay ? R.xml.device_profiles_split : R.xml.device_profiles;
+
+ try (XmlResourceParser parser = context.getResources().getXml(xmlResource)) {
final int depth = parser.getDepth();
int type;
while (((type = parser.next()) != XmlPullParser.END_TAG ||
@@ -411,8 +408,7 @@
if ((type == XmlPullParser.START_TAG) && "display-option".equals(
parser.getName())) {
profiles.add(new DisplayOption(gridOption, context,
- Xml.asAttributeSet(parser),
- isSplitDisplay ? DEFAULT_SPLIT_DISPLAY : DEFAULT_TRUE));
+ Xml.asAttributeSet(parser)));
}
}
}
@@ -450,7 +446,9 @@
*/
public List<GridOption> parseAllGridOptions(Context context) {
List<GridOption> result = new ArrayList<>();
- try (XmlResourceParser parser = context.getResources().getXml(R.xml.device_profiles)) {
+ int xmlResource = isSplitDisplay ? R.xml.device_profiles_split : R.xml.device_profiles;
+
+ try (XmlResourceParser parser = context.getResources().getXml(xmlResource)) {
final int depth = parser.getDepth();
int type;
while (((type = parser.next()) != XmlPullParser.END_TAG
@@ -702,11 +700,7 @@
devicePaddingId = a.getResourceId(
R.styleable.GridDisplayOption_devicePaddingId, 0);
- final int enabledInt =
- a.getInteger(R.styleable.GridDisplayOption_gridEnabled,
- GRID_ENABLED_ALL_DISPLAYS);
- isEnabled = enabledInt == GRID_ENABLED_ALL_DISPLAYS
- || enabledInt == GRID_ENABLED_SINGLE_DISPLAY && !isSplitDisplay;
+ isEnabled = a.getBoolean(R.styleable.GridDisplayOption_gridEnabled, true);
a.recycle();
extraAttrs = Themes.createValueMap(context, attrs,
@@ -732,17 +726,15 @@
private final float[] iconSizes = new float[COUNT_SIZES];
private final float[] textSizes = new float[COUNT_SIZES];
- DisplayOption(GridOption grid, Context context, AttributeSet attrs, int defaultFlagValue) {
+ DisplayOption(GridOption grid, Context context, AttributeSet attrs) {
this.grid = grid;
- TypedArray a = context.obtainStyledAttributes(
- attrs, R.styleable.ProfileDisplayOption);
+ TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ProfileDisplayOption);
minWidthDps = a.getFloat(R.styleable.ProfileDisplayOption_minWidthDps, 0);
minHeightDps = a.getFloat(R.styleable.ProfileDisplayOption_minHeightDps, 0);
- canBeDefault = a.getInt(R.styleable.ProfileDisplayOption_canBeDefault, 0)
- == defaultFlagValue;
+ canBeDefault = a.getBoolean(R.styleable.ProfileDisplayOption_canBeDefault, false);
float x;
float y;