From a6907dc8c90ebf3f488301f8388f00a7c6371702 Mon Sep 17 00:00:00 2001 From: Alex Chau Date: Fri, 18 Mar 2022 15:24:07 +0000 Subject: [PATCH] Use correct config.smallestScreenWidthDp when creating Resource in DeviceProfile - This is a regression from ag/17070486 when tested, likely because DeviceProfiles are no longer re-created when changing display sizes, so correct values need to be calculated on the starting state Bug: 221961069 Test: verify smallestWidth specific resource on changing display sizes Change-Id: I1539bad4b35b36f0056d59307ab5fbec23a71f49 --- src/com/android/launcher3/DeviceProfile.java | 6 ++++-- .../android/launcher3/util/DisplayController.java | 13 +++++++++---- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/com/android/launcher3/DeviceProfile.java b/src/com/android/launcher3/DeviceProfile.java index 622d750c83..0e9b5da569 100644 --- a/src/com/android/launcher3/DeviceProfile.java +++ b/src/com/android/launcher3/DeviceProfile.java @@ -257,7 +257,8 @@ public class DeviceProfile { // Some more constants. context = getContext(context, info, isVerticalBarLayout() || (isTablet && isLandscape) ? Configuration.ORIENTATION_LANDSCAPE - : Configuration.ORIENTATION_PORTRAIT); + : Configuration.ORIENTATION_PORTRAIT, + windowBounds); final Resources res = context.getResources(); mMetrics = res.getDisplayMetrics(); @@ -1231,10 +1232,11 @@ public class DeviceProfile { writer.println(prefix + pxToDpStr("overviewGridSideMargin", overviewGridSideMargin)); } - private static Context getContext(Context c, Info info, int orientation) { + private static Context getContext(Context c, Info info, int orientation, WindowBounds bounds) { Configuration config = new Configuration(c.getResources().getConfiguration()); config.orientation = orientation; config.densityDpi = info.densityDpi; + config.smallestScreenWidthDp = (int) info.smallestSizeDp(bounds); return c.createConfigurationContext(config); } diff --git a/src/com/android/launcher3/util/DisplayController.java b/src/com/android/launcher3/util/DisplayController.java index 22e3de8f76..8b4ff85f90 100644 --- a/src/com/android/launcher3/util/DisplayController.java +++ b/src/com/android/launcher3/util/DisplayController.java @@ -345,16 +345,21 @@ public class DisplayController implements ComponentCallbacks, SafeCloseable { * Returns {@code true} if the bounds represent a tablet. */ public boolean isTablet(WindowBounds bounds) { - return dpiFromPx(Math.min(bounds.bounds.width(), bounds.bounds.height()), - densityDpi) >= MIN_TABLET_WIDTH; + return smallestSizeDp(bounds) >= MIN_TABLET_WIDTH; } /** * Returns {@code true} if the bounds represent a large tablet. */ public boolean isLargeTablet(WindowBounds bounds) { - return dpiFromPx(Math.min(bounds.bounds.width(), bounds.bounds.height()), - densityDpi) >= MIN_LARGE_TABLET_WIDTH; + return smallestSizeDp(bounds) >= MIN_LARGE_TABLET_WIDTH; + } + + /** + * Returns smallest size in dp for given bounds. + */ + public float smallestSizeDp(WindowBounds bounds) { + return dpiFromPx(Math.min(bounds.bounds.width(), bounds.bounds.height()), densityDpi); } }