From 7772fcde4792d623acbfd8222e8881d01e7db953 Mon Sep 17 00:00:00 2001 From: Jon Miranda Date: Mon, 1 Jun 2020 14:08:16 -0700 Subject: [PATCH] Fix bug where font size (etc.) doesn't change after changing display settings. The metrics we get from Display#getMetrics does not change regardless of what the new configuration is (we would expect the scaledDensity to change). Documentation shows that Display#getMetrics is deprecated in R. Using guidance from b/154665987#comment14 we get the metrics from the derived context. Bug: 156141463 Change-Id: I25e5f2c13f94e0471111f6c895694947998e3222 --- src/com/android/launcher3/InvariantDeviceProfile.java | 2 +- src/com/android/launcher3/util/DefaultDisplay.java | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/com/android/launcher3/InvariantDeviceProfile.java b/src/com/android/launcher3/InvariantDeviceProfile.java index 8951674879..60abc66b2b 100644 --- a/src/com/android/launcher3/InvariantDeviceProfile.java +++ b/src/com/android/launcher3/InvariantDeviceProfile.java @@ -200,7 +200,7 @@ public class InvariantDeviceProfile { DefaultDisplay.INSTANCE.get(context).getInfo(), getPredefinedDeviceProfiles(context, gridName)); - Info myInfo = new Info(display); + Info myInfo = new Info(context, display); DisplayOption myDisplayOption = invDistWeightedInterpolate( myInfo, getPredefinedDeviceProfiles(context, gridName)); diff --git a/src/com/android/launcher3/util/DefaultDisplay.java b/src/com/android/launcher3/util/DefaultDisplay.java index fabdb4e86c..150fb5b043 100644 --- a/src/com/android/launcher3/util/DefaultDisplay.java +++ b/src/com/android/launcher3/util/DefaultDisplay.java @@ -145,10 +145,11 @@ public class DefaultDisplay implements DisplayListener { } private Info(Context context) { - this(context.getSystemService(DisplayManager.class).getDisplay(DEFAULT_DISPLAY)); + this(context, context.getSystemService(DisplayManager.class) + .getDisplay(DEFAULT_DISPLAY)); } - public Info(Display display) { + public Info(Context context, Display display) { id = display.getDisplayId(); rotation = display.getRotation(); @@ -161,8 +162,8 @@ public class DefaultDisplay implements DisplayListener { display.getRealSize(realSize); display.getCurrentSizeRange(smallestSize, largestSize); - metrics = new DisplayMetrics(); - display.getMetrics(metrics); + Context defaultDisplayContext = context.createDisplayContext(display); + metrics = defaultDisplayContext.getResources().getDisplayMetrics(); } private boolean hasDifferentSize(Info info) {