From 247269058f5764ae6d1fbfc6dc0951f5af927af2 Mon Sep 17 00:00:00 2001 From: MohammedKHC0 Date: Sun, 26 Jan 2025 16:27:00 +0200 Subject: [PATCH 1/2] Adding FULLSCREEN flag when window is fullscreen. This flag is needed to properly hide display cutout on Android devices, Without it a black space appears on the status bar. Refer to https://stackoverflow.com/questions/49190381/fullscreen-app-with-displaycutout --- java/MainActivity.java | 1 + 1 file changed, 1 insertion(+) diff --git a/java/MainActivity.java b/java/MainActivity.java index ea1a1fb0..edbfe96b 100644 --- a/java/MainActivity.java +++ b/java/MainActivity.java @@ -308,6 +308,7 @@ public void run() { if (fullscreen) { getWindow().setFlags(LayoutParams.FLAG_LAYOUT_NO_LIMITS, LayoutParams.FLAG_LAYOUT_NO_LIMITS); + getWindow().addFlags(LayoutParams.FLAG_FULLSCREEN); if (Build.VERSION.SDK_INT >= 28) { getWindow().getAttributes().layoutInDisplayCutoutMode = LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES; } From f17338d3dec30220d8b81ed0f61707dfcba9bbfa Mon Sep 17 00:00:00 2001 From: MohammedKHC0 Date: Mon, 27 Jan 2025 20:00:08 +0200 Subject: [PATCH 2/2] Android: Better fullscreen support. --- java/MainActivity.java | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/java/MainActivity.java b/java/MainActivity.java index edbfe96b..34679a9b 100644 --- a/java/MainActivity.java +++ b/java/MainActivity.java @@ -12,6 +12,7 @@ import android.view.Surface; import android.view.Window; import android.view.WindowInsets; +import android.view.WindowInsetsController; import android.view.WindowManager.LayoutParams; import android.view.SurfaceView; import android.view.SurfaceHolder; @@ -307,25 +308,28 @@ public void run() { View decorView = getWindow().getDecorView(); if (fullscreen) { - getWindow().setFlags(LayoutParams.FLAG_LAYOUT_NO_LIMITS, LayoutParams.FLAG_LAYOUT_NO_LIMITS); - getWindow().addFlags(LayoutParams.FLAG_FULLSCREEN); - if (Build.VERSION.SDK_INT >= 28) { - getWindow().getAttributes().layoutInDisplayCutoutMode = LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES; - } if (Build.VERSION.SDK_INT >= 30) { - getWindow().setDecorFitsSystemWindows(false); + WindowInsetsController controller = getWindow().getInsetsController(); + controller.setSystemBarsBehavior(WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE); + controller.hide(WindowInsets.Type.systemBars() | WindowInsets.Type.displayCutout()); } else { + if (Build.VERSION.SDK_INT >= 28) { + getWindow().getAttributes().layoutInDisplayCutoutMode = LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES; + } int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY; decorView.setSystemUiVisibility(uiOptions); } - } - else { + } else { if (Build.VERSION.SDK_INT >= 30) { - getWindow().setDecorFitsSystemWindows(true); + WindowInsetsController controller = getWindow().getInsetsController(); + controller.setSystemBarsBehavior(WindowInsetsController.BEHAVIOR_DEFAULT); + controller.show(WindowInsets.Type.systemBars() | WindowInsets.Type.displayCutout()); } else { - decorView.setSystemUiVisibility(0); + if (Build.VERSION.SDK_INT >= 28) { + getWindow().getAttributes().layoutInDisplayCutoutMode = LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_DEFAULT; + } + decorView.setSystemUiVisibility(0); } - } } }); @@ -366,4 +370,3 @@ public void setClipboardText(String text) { clipboard.setPrimaryClip(clip); } } -