summaryrefslogtreecommitdiffstats
path: root/src/com/android/launcher3/InvariantDeviceProfile.java
diff options
context:
space:
mode:
authorLuca Stefani <luca.stefani.ge1@gmail.com>2020-03-07 13:43:59 +0100
committerLuca Stefani <luca.stefani.ge1@gmail.com>2020-03-07 13:43:59 +0100
commit0007a046cf4f4bfed563aa52ffab9ec5e94ee6f0 (patch)
tree2bc4acf2f54df560a34dcc7b7844d9d18cc58131 /src/com/android/launcher3/InvariantDeviceProfile.java
parent744d192669a148bde24d36bef02deb05c2f7a1fa (diff)
parent02826bbe04d9dc1e6111f5d6ffd8706ac1f8f908 (diff)
downloadandroid_packages_apps_Trebuchet-0007a046cf4f4bfed563aa52ffab9ec5e94ee6f0.tar.gz
android_packages_apps_Trebuchet-0007a046cf4f4bfed563aa52ffab9ec5e94ee6f0.tar.bz2
android_packages_apps_Trebuchet-0007a046cf4f4bfed563aa52ffab9ec5e94ee6f0.zip
Merge tag 'android-10.0.0_r31' into HEAD
Android 10.0.0 release 31 * tag 'android-10.0.0_r31': (218 commits) Increase drag distance threshold when drag starts from deep press Fix shortcut componentname in workspace layout logging Fix shortcut componentname in workspace layout logging perform accessbility focus when the recyclerview doesn't gain focus after fragment replacement in SettingsActivity Persist predicted items when dragged to workspace Import translations. DO NOT MERGE Import translations. DO NOT MERGE Align badging logic with platform IconDrawableFactory. Fix bug where icon remains invisible after returning home. Fix quick switch from home biased towards returning home Fix recents scale sometimes lagging behind window scale Fix folder open/close animation when grid size is small. fix custom shortcut test Improve quick switch from home by tracking both x and y motion Move shelf peeking anim code to ShelfPeekAnim class Fix folder available height calculation Tapl: AllApps: ensuring a minimal vertical size of an icon Enable a11y scrolling with item drag disable custom shortcut test in oop include predicted_rank in app launch logging ... Change-Id: Id824c350cd133c4c8fa91de0f8793faed9003393
Diffstat (limited to 'src/com/android/launcher3/InvariantDeviceProfile.java')
-rw-r--r--src/com/android/launcher3/InvariantDeviceProfile.java195
1 files changed, 127 insertions, 68 deletions
diff --git a/src/com/android/launcher3/InvariantDeviceProfile.java b/src/com/android/launcher3/InvariantDeviceProfile.java
index 70ace0ff1..eda679f11 100644
--- a/src/com/android/launcher3/InvariantDeviceProfile.java
+++ b/src/com/android/launcher3/InvariantDeviceProfile.java
@@ -18,6 +18,7 @@ package com.android.launcher3;
import static com.android.launcher3.Utilities.getDevicePrefs;
import static com.android.launcher3.config.FeatureFlags.APPLY_CONFIG_AT_RUNTIME;
+import static com.android.launcher3.util.Executors.MAIN_EXECUTOR;
import static com.android.launcher3.util.PackageManagerHelper.getPackageFilter;
import android.annotation.TargetApi;
@@ -41,11 +42,13 @@ import android.util.Log;
import android.util.SparseArray;
import android.util.TypedValue;
import android.util.Xml;
-import android.view.Display;
-import android.view.WindowManager;
+
+import androidx.annotation.Nullable;
+import androidx.annotation.VisibleForTesting;
import com.android.launcher3.graphics.IconShape;
import com.android.launcher3.util.ConfigMonitor;
+import com.android.launcher3.util.DefaultDisplay;
import com.android.launcher3.util.IntArray;
import com.android.launcher3.util.MainThreadInitializedObject;
import com.android.launcher3.util.Themes;
@@ -56,9 +59,7 @@ import org.xmlpull.v1.XmlPullParserException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
-
-import androidx.annotation.Nullable;
-import androidx.annotation.VisibleForTesting;
+import java.util.Comparator;
public class InvariantDeviceProfile implements OnSharedPreferenceChangeListener {
@@ -107,6 +108,8 @@ public class InvariantDeviceProfile implements OnSharedPreferenceChangeListener
public int iconBitmapSize;
public int fillResIconDpi;
public float iconTextSize;
+ public float allAppsIconSize;
+ public float allAppsIconTextSize;
private SparseArray<TypedValue> mExtraAttrs;
@@ -115,6 +118,11 @@ public class InvariantDeviceProfile implements OnSharedPreferenceChangeListener
*/
public int numHotseatIcons;
+ /**
+ * Number of columns in the all apps list.
+ */
+ public int numAllAppsColumns;
+
public int defaultLayoutId;
int demoModeLayoutId;
@@ -143,6 +151,9 @@ public class InvariantDeviceProfile implements OnSharedPreferenceChangeListener
landscapeIconSize = p.landscapeIconSize;
iconTextSize = p.iconTextSize;
numHotseatIcons = p.numHotseatIcons;
+ numAllAppsColumns = p.numAllAppsColumns;
+ allAppsIconSize = p.allAppsIconSize;
+ allAppsIconTextSize = p.allAppsIconTextSize;
defaultLayoutId = p.defaultLayoutId;
demoModeLayoutId = p.demoModeLayoutId;
mExtraAttrs = p.mExtraAttrs;
@@ -156,7 +167,8 @@ public class InvariantDeviceProfile implements OnSharedPreferenceChangeListener
SharedPreferences prefs = Utilities.getPrefs(context);
prefs.registerOnSharedPreferenceChangeListener(this);
- initGrid(context, prefs.getString(KEY_IDP_GRID_NAME, null));
+ String gridName = prefs.getString(KEY_IDP_GRID_NAME, null);
+ initGrid(context, gridName);
mConfigMonitor = new ConfigMonitor(context,
APPLY_CONFIG_AT_RUNTIME.get() ? this::onConfigChanged : this::killProcess);
mOverlayMonitor = new OverlayMonitor(context);
@@ -191,64 +203,82 @@ public class InvariantDeviceProfile implements OnSharedPreferenceChangeListener
}
private String initGrid(Context context, String gridName) {
- WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
- Display display = wm.getDefaultDisplay();
- DisplayMetrics dm = new DisplayMetrics();
- display.getMetrics(dm);
+ DefaultDisplay.Info displayInfo = DefaultDisplay.INSTANCE.get(context).getInfo();
- Point smallestSize = new Point();
- Point largestSize = new Point();
- display.getCurrentSizeRange(smallestSize, largestSize);
+ Point smallestSize = new Point(displayInfo.smallestSize);
+ Point largestSize = new Point(displayInfo.largestSize);
- ArrayList<DisplayOption> allOptions = getPredefinedDeviceProfiles(context, gridName);
// This guarantees that width < height
- float minWidthDps = Utilities.dpiFromPx(Math.min(smallestSize.x, smallestSize.y), dm);
- float minHeightDps = Utilities.dpiFromPx(Math.min(largestSize.x, largestSize.y), dm);
+ float minWidthDps = Utilities.dpiFromPx(Math.min(smallestSize.x, smallestSize.y),
+ displayInfo.metrics);
+ float minHeightDps = Utilities.dpiFromPx(Math.min(largestSize.x, largestSize.y),
+ displayInfo.metrics);
+
+ Point realSize = new Point(displayInfo.realSize);
+ // The real size never changes. smallSide and largeSide will remain the
+ // same in any orientation.
+ int smallSide = Math.min(realSize.x, realSize.y);
+ int largeSide = Math.max(realSize.x, realSize.y);
+
+ // We want a list of all options as well as the list of filtered options. This allows us
+ // to have a consistent UI for areas that the grid size change should not affect
+ // ie. All Apps should be consistent between grid sizes.
+ ArrayList<DisplayOption> allOptions = new ArrayList<>();
+ ArrayList<DisplayOption> filteredOptions = new ArrayList<>();
+ getPredefinedDeviceProfiles(context, gridName, filteredOptions, allOptions);
+
+ if (allOptions.isEmpty() && filteredOptions.isEmpty()) {
+ throw new RuntimeException("No display option with canBeDefault=true");
+ }
+
// Sort the profiles based on the closeness to the device size
- Collections.sort(allOptions, (a, b) ->
- Float.compare(dist(minWidthDps, minHeightDps, a.minWidthDps, a.minHeightDps),
- dist(minWidthDps, minHeightDps, b.minWidthDps, b.minHeightDps)));
+ Comparator<DisplayOption> comparator = (a, b) -> Float.compare(dist(minWidthDps,
+ minHeightDps, a.minWidthDps, a.minHeightDps),
+ dist(minWidthDps, minHeightDps, b.minWidthDps, b.minHeightDps));
+
+ // Calculate the device profiles as if there is no grid override.
+ Collections.sort(allOptions, comparator);
DisplayOption interpolatedDisplayOption =
invDistWeightedInterpolate(minWidthDps, minHeightDps, allOptions);
+ initGridOption(context, allOptions, interpolatedDisplayOption, displayInfo.metrics);
+
+ // Create IDP with no grid override values.
+ InvariantDeviceProfile originalIDP = new InvariantDeviceProfile(this);
+ originalIDP.landscapeProfile = new DeviceProfile(context, this, null, smallestSize,
+ largestSize, largeSide, smallSide, true /* isLandscape */,
+ false /* isMultiWindowMode */);
+ originalIDP.portraitProfile = new DeviceProfile(context, this, null, smallestSize,
+ largestSize, smallSide, largeSide, false /* isLandscape */,
+ false /* isMultiWindowMode */);
+
+ if (filteredOptions.isEmpty()) {
+ filteredOptions = allOptions;
+
+ landscapeProfile = originalIDP.landscapeProfile;
+ portraitProfile = originalIDP.portraitProfile;
+ } else {
+ Collections.sort(filteredOptions, comparator);
+ interpolatedDisplayOption =
+ invDistWeightedInterpolate(minWidthDps, minHeightDps, filteredOptions);
+
+ initGridOption(context, filteredOptions, interpolatedDisplayOption,
+ displayInfo.metrics);
+ numAllAppsColumns = originalIDP.numAllAppsColumns;
+
+ landscapeProfile = new DeviceProfile(context, this, originalIDP, smallestSize,
+ largestSize, largeSide, smallSide, true /* isLandscape */,
+ false /* isMultiWindowMode */);
+ portraitProfile = new DeviceProfile(context, this, originalIDP, smallestSize,
+ largestSize, smallSide, largeSide, false /* isLandscape */,
+ false /* isMultiWindowMode */);
+ }
- GridOption closestProfile = allOptions.get(0).grid;
- numRows = closestProfile.numRows;
- numColumns = closestProfile.numColumns;
- numHotseatIcons = closestProfile.numHotseatIcons;
- defaultLayoutId = closestProfile.defaultLayoutId;
- demoModeLayoutId = closestProfile.demoModeLayoutId;
- numFolderRows = closestProfile.numFolderRows;
- numFolderColumns = closestProfile.numFolderColumns;
- mExtraAttrs = closestProfile.extraAttrs;
-
+ GridOption closestProfile = filteredOptions.get(0).grid;
if (!closestProfile.name.equals(gridName)) {
Utilities.getPrefs(context).edit()
.putString(KEY_IDP_GRID_NAME, closestProfile.name).apply();
}
- iconSize = interpolatedDisplayOption.iconSize;
- iconShapePath = getIconShapePath(context);
- landscapeIconSize = interpolatedDisplayOption.landscapeIconSize;
- iconBitmapSize = ResourceUtils.pxFromDp(iconSize, dm);
- iconTextSize = interpolatedDisplayOption.iconTextSize;
- fillResIconDpi = getLauncherIconDensity(iconBitmapSize);
-
- // If the partner customization apk contains any grid overrides, apply them
- // Supported overrides: numRows, numColumns, iconSize
- applyPartnerDeviceProfileOverrides(context, dm);
-
- Point realSize = new Point();
- display.getRealSize(realSize);
- // The real size never changes. smallSide and largeSide will remain the
- // same in any orientation.
- int smallSide = Math.min(realSize.x, realSize.y);
- int largeSide = Math.max(realSize.x, realSize.y);
-
- landscapeProfile = new DeviceProfile(context, this, smallestSize, largestSize,
- largeSide, smallSide, true /* isLandscape */, false /* isMultiWindowMode */);
- portraitProfile = new DeviceProfile(context, this, smallestSize, largestSize,
- smallSide, largeSide, false /* isLandscape */, false /* isMultiWindowMode */);
-
// We need to ensure that there is enough extra space in the wallpaper
// for the intended parallax effects
if (context.getResources().getConfiguration().smallestScreenWidthDp >= 720) {
@@ -265,6 +295,33 @@ public class InvariantDeviceProfile implements OnSharedPreferenceChangeListener
return closestProfile.name;
}
+ private void initGridOption(Context context, ArrayList<DisplayOption> options,
+ DisplayOption displayOption, DisplayMetrics metrics) {
+ GridOption closestProfile = options.get(0).grid;
+ numRows = closestProfile.numRows;
+ numColumns = closestProfile.numColumns;
+ numHotseatIcons = closestProfile.numHotseatIcons;
+ defaultLayoutId = closestProfile.defaultLayoutId;
+ demoModeLayoutId = closestProfile.demoModeLayoutId;
+ numFolderRows = closestProfile.numFolderRows;
+ numFolderColumns = closestProfile.numFolderColumns;
+ numAllAppsColumns = numColumns;
+
+ mExtraAttrs = closestProfile.extraAttrs;
+
+ iconSize = displayOption.iconSize;
+ iconShapePath = getIconShapePath(context);
+ landscapeIconSize = displayOption.landscapeIconSize;
+ iconBitmapSize = ResourceUtils.pxFromDp(iconSize, metrics);
+ iconTextSize = displayOption.iconTextSize;
+ fillResIconDpi = getLauncherIconDensity(iconBitmapSize);
+
+ // If the partner customization apk contains any grid overrides, apply them
+ // Supported overrides: numRows, numColumns, iconSize
+ applyPartnerDeviceProfileOverrides(context, metrics);
+ }
+
+
@Nullable
public TypedValue getAttrValue(int attr) {
return mExtraAttrs == null ? null : mExtraAttrs.get(attr);
@@ -299,7 +356,7 @@ public class InvariantDeviceProfile implements OnSharedPreferenceChangeListener
public void setCurrentGrid(Context context, String gridName) {
Context appContext = context.getApplicationContext();
Utilities.getPrefs(appContext).edit().putString(KEY_IDP_GRID_NAME, gridName).apply();
- new MainThreadExecutor().execute(() -> onConfigChanged(appContext));
+ MAIN_EXECUTOR.execute(() -> onConfigChanged(appContext));
}
private void onConfigChanged(Context context) {
@@ -307,7 +364,8 @@ public class InvariantDeviceProfile implements OnSharedPreferenceChangeListener
InvariantDeviceProfile oldProfile = new InvariantDeviceProfile(this);
// Re-init grid
- initGrid(context, Utilities.getPrefs(context).getString(KEY_IDP_GRID_NAME, null));
+ String gridName = Utilities.getPrefs(context).getString(KEY_IDP_GRID_NAME, null);
+ initGrid(context, gridName);
int changeFlags = 0;
if (numRows != oldProfile.numRows ||
@@ -339,7 +397,13 @@ public class InvariantDeviceProfile implements OnSharedPreferenceChangeListener
}
}
- static ArrayList<DisplayOption> getPredefinedDeviceProfiles(Context context, String gridName) {
+ /**
+ * @param gridName The current grid name.
+ * @param filteredOptionsOut List filled with all the filtered options based on gridName.
+ * @param allOptionsOut List filled with all the options that can be the default option.
+ */
+ static void getPredefinedDeviceProfiles(Context context, String gridName,
+ ArrayList<DisplayOption> filteredOptionsOut, ArrayList<DisplayOption> allOptionsOut) {
ArrayList<DisplayOption> profiles = new ArrayList<>();
try (XmlResourceParser parser = context.getResources().getXml(R.xml.device_profiles)) {
final int depth = parser.getDepth();
@@ -366,26 +430,19 @@ public class InvariantDeviceProfile implements OnSharedPreferenceChangeListener
throw new RuntimeException(e);
}
- ArrayList<DisplayOption> filteredProfiles = new ArrayList<>();
if (!TextUtils.isEmpty(gridName)) {
for (DisplayOption option : profiles) {
if (gridName.equals(option.grid.name)) {
- filteredProfiles.add(option);
+ filteredOptionsOut.add(option);
}
}
}
- if (filteredProfiles.isEmpty()) {
- // No grid found, use the default options
- for (DisplayOption option : profiles) {
- if (option.canBeDefault) {
- filteredProfiles.add(option);
- }
+
+ for (DisplayOption option : profiles) {
+ if (option.canBeDefault) {
+ allOptionsOut.add(option);
}
}
- if (filteredProfiles.isEmpty()) {
- throw new RuntimeException("No display option with canBeDefault=true");
- }
- return filteredProfiles;
}
private int getLauncherIconDensity(int requiredSize) {
@@ -531,6 +588,7 @@ public class InvariantDeviceProfile implements OnSharedPreferenceChangeListener
R.styleable.GridDisplayOption_numFolderRows, numRows);
numFolderColumns = a.getInt(
R.styleable.GridDisplayOption_numFolderColumns, numColumns);
+
a.recycle();
extraAttrs = Themes.createValueMap(context, attrs,
@@ -547,8 +605,8 @@ public class InvariantDeviceProfile implements OnSharedPreferenceChangeListener
private final boolean canBeDefault;
private float iconSize;
- private float landscapeIconSize;
private float iconTextSize;
+ private float landscapeIconSize;
DisplayOption(GridOption grid, Context context, AttributeSet attrs) {
this.grid = grid;
@@ -566,6 +624,7 @@ public class InvariantDeviceProfile implements OnSharedPreferenceChangeListener
landscapeIconSize = a.getFloat(R.styleable.ProfileDisplayOption_landscapeIconSize,
iconSize);
iconTextSize = a.getFloat(R.styleable.ProfileDisplayOption_iconTextSize, 0);
+
a.recycle();
}