Commit f2ddfb08 by olly Committed by Oliver Woodman

Expose getPhysicalDisplaySize for non-primary display

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=132856997
parent 7925342f
...@@ -911,9 +911,21 @@ public final class Util { ...@@ -911,9 +911,21 @@ public final class Util {
* @return The physical display size, in pixels. * @return The physical display size, in pixels.
*/ */
public static Point getPhysicalDisplaySize(Context context) { public static Point getPhysicalDisplaySize(Context context) {
// Before API 25 the platform Display object does not provide a working way to identify Android WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
// TVs that can show 4k resolution in a SurfaceView, so check for supported devices here. return getPhysicalDisplaySize(context, windowManager.getDefaultDisplay());
if (Util.SDK_INT < 25) { }
/**
* Gets the physical size of the specified display, in pixels.
*
* @param context Any context.
* @param display The display whose size is to be returned.
* @return The physical display size, in pixels.
*/
public static Point getPhysicalDisplaySize(Context context, Display display) {
if (Util.SDK_INT < 25 && display.getDisplayId() == Display.DEFAULT_DISPLAY) {
// Before API 25 the Display object does not provide a working way to identify Android TVs
// that can show 4k resolution in a SurfaceView, so check for supported devices here.
if ("Sony".equals(Util.MANUFACTURER) && Util.MODEL.startsWith("BRAVIA") if ("Sony".equals(Util.MANUFACTURER) && Util.MODEL.startsWith("BRAVIA")
&& context.getPackageManager().hasSystemFeature("com.sony.dtv.hardware.panel.qfhd")) { && context.getPackageManager().hasSystemFeature("com.sony.dtv.hardware.panel.qfhd")) {
return new Point(3840, 2160); return new Point(3840, 2160);
...@@ -947,8 +959,6 @@ public final class Util { ...@@ -947,8 +959,6 @@ public final class Util {
} }
} }
WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Display display = windowManager.getDefaultDisplay();
Point displaySize = new Point(); Point displaySize = new Point();
if (Util.SDK_INT >= 23) { if (Util.SDK_INT >= 23) {
getDisplaySizeV23(display, displaySize); getDisplaySizeV23(display, displaySize);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment