summaryrefslogtreecommitdiff
path: root/core/java/android/util
diff options
context:
space:
mode:
authorShawn Lin <shawnlin@google.com>2022-05-24 02:30:28 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2022-05-24 02:30:28 +0000
commit15cb562bcd7427c4ec8565d2d022db4e6c252264 (patch)
tree2587bac0394034486b522f8ae54c7893a9ef616b /core/java/android/util
parentc45a6dd61c18b15478e6df1bf4aeefc64de1828a (diff)
parent0f7cc0128b9cf341eb3e0e657d4e6a416440ee53 (diff)
Merge "Replace DisplayManager.getStableDisplaySize with max Display.Mode" into tm-dev
Diffstat (limited to 'core/java/android/util')
-rw-r--r--core/java/android/util/DisplayUtils.java29
1 files changed, 24 insertions, 5 deletions
diff --git a/core/java/android/util/DisplayUtils.java b/core/java/android/util/DisplayUtils.java
index 9b76fc2ff028..cbb38a4ada31 100644
--- a/core/java/android/util/DisplayUtils.java
+++ b/core/java/android/util/DisplayUtils.java
@@ -17,6 +17,7 @@
package android.util;
import android.content.res.Resources;
+import android.view.Display;
import com.android.internal.R;
@@ -53,15 +54,33 @@ public class DisplayUtils {
}
/**
- * Get the display size ratio based on the stable display size.
+ * Returns the Display.Mode with maximum resolution.
+ */
+ public static Display.Mode getMaximumResolutionDisplayMode(Display.Mode[] modes) {
+ if (modes == null || modes.length == 0) {
+ return null;
+ }
+ int maxWidth = 0;
+ Display.Mode target = null;
+ for (Display.Mode mode : modes) {
+ if (mode.getPhysicalWidth() > maxWidth) {
+ maxWidth = mode.getPhysicalWidth();
+ target = mode;
+ }
+ }
+ return target;
+ }
+
+ /**
+ * Get the display size ratio based on the physical display size.
*/
public static float getPhysicalPixelDisplaySizeRatio(
- int stableWidth, int stableHeight, int currentWidth, int currentHeight) {
- if (stableWidth == currentWidth && stableHeight == currentHeight) {
+ int physicalWidth, int physicalHeight, int currentWidth, int currentHeight) {
+ if (physicalWidth == currentWidth && physicalHeight == currentHeight) {
return 1f;
}
- final float widthRatio = (float) currentWidth / stableWidth;
- final float heightRatio = (float) currentHeight / stableHeight;
+ final float widthRatio = (float) currentWidth / physicalWidth;
+ final float heightRatio = (float) currentHeight / physicalHeight;
return Math.min(widthRatio, heightRatio);
}
}