From 5cd22f6bcd70e3235da50b8242b25c2e27047f8f Mon Sep 17 00:00:00 2001 From: Evan Debenham Date: Sun, 31 Aug 2025 15:04:55 -0400 Subject: [PATCH] v3.2.3: various further Android-specific UI/layout improvements --- android/src/main/AndroidManifest.xml | 7 +-- .../android/AndroidPlatformSupport.java | 43 +++++++++++-------- android/src/main/res/values-v28/style.xml | 9 ++++ android/src/main/res/values/style.xml | 8 ++-- 4 files changed, 38 insertions(+), 29 deletions(-) create mode 100644 android/src/main/res/values-v28/style.xml diff --git a/android/src/main/AndroidManifest.xml b/android/src/main/AndroidManifest.xml index 3a9e0b556..cdbcc0c82 100644 --- a/android/src/main/AndroidManifest.xml +++ b/android/src/main/AndroidManifest.xml @@ -1,11 +1,8 @@ + android:targetSandboxVersion="2"> - @@ -22,7 +19,7 @@ = Build.VERSION_CODES.M) { + //getting insets technically works down to 6.0 Marshmallow, but we let the device handle all of that prior to 9.0 Pie + //TODO test on Android P emulator! + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P && !AndroidLauncher.instance.isInMultiWindowMode()) { WindowInsets rootInsets = AndroidLauncher.instance.getApplicationWindow().getDecorView().getRootWindowInsets(); if (rootInsets != null) { @@ -82,21 +84,25 @@ public class AndroidPlatformSupport extends PlatformSupport { } //display cutout - if (level > INSET_BLK && Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { + if (level > INSET_BLK) { DisplayCutout cutout = rootInsets.getDisplayCutout(); - //TODO determine if a cutout is large or not based on its size in pixels: - // on my OP7P, dev mode not simulations are: - //top-left cutout is 0,0,136,136 (136x136 = 18.5k total) - //center is 552,0,888,168 (336*168 = 56k total) - //top-right corner is 1272,0,1440,168 (x168 = 28k total) - //overall screen is 1440x3120 = 4400k pixels - // 0.5% of 4400k is 22k - //maybe judge a cutout to be large if it's bigger than 0.5% of the display? + if (cutout != null) { - insets.left = Math.max(insets.left, cutout.getSafeInsetLeft()); - insets.top = Math.max(insets.top, cutout.getSafeInsetTop()); - insets.right = Math.max(insets.right, cutout.getSafeInsetRight()); - insets.bottom = Math.max(insets.bottom, cutout.getSafeInsetBottom()); + boolean largeCutout = false; + int screenSize = Game.width * Game.height; + for (Rect r : cutout.getBoundingRects()){ + int cutoutSize = Math.abs(r.height() * r.width()); + //display cutouts are considered large if they take up more than 0.5% of the screen + if (cutoutSize*200 >= screenSize){ + largeCutout = true; + } + } + if (largeCutout || level == INSET_ALL) { + insets.left = Math.max(insets.left, cutout.getSafeInsetLeft()); + insets.top = Math.max(insets.top, cutout.getSafeInsetTop()); + insets.right = Math.max(insets.right, cutout.getSafeInsetRight()); + insets.bottom = Math.max(insets.bottom, cutout.getSafeInsetBottom()); + } } } } @@ -107,7 +113,6 @@ public class AndroidPlatformSupport extends PlatformSupport { public void updateSystemUI() { AndroidLauncher.instance.runOnUiThread(new Runnable() { - @SuppressLint("NewApi") @Override public void run() { boolean fullscreen = Build.VERSION.SDK_INT < Build.VERSION_CODES.N diff --git a/android/src/main/res/values-v28/style.xml b/android/src/main/res/values-v28/style.xml new file mode 100644 index 000000000..01e8bb7f8 --- /dev/null +++ b/android/src/main/res/values-v28/style.xml @@ -0,0 +1,9 @@ + + + + + \ No newline at end of file diff --git a/android/src/main/res/values/style.xml b/android/src/main/res/values/style.xml index 195bf28c8..249a143f0 100644 --- a/android/src/main/res/values/style.xml +++ b/android/src/main/res/values/style.xml @@ -1,9 +1,7 @@ - + + +