diff --git a/app/GioView.java b/app/GioView.java index d67503bb..adc32377 100644 --- a/app/GioView.java +++ b/app/GioView.java @@ -165,19 +165,40 @@ public final class GioView extends SurfaceView { } private void setFullscreen(boolean enabled) { - int flags = this.getSystemUiVisibility(); + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) { + int flags = this.getSystemUiVisibility(); + if (enabled) { + flags |= SYSTEM_UI_FLAG_IMMERSIVE_STICKY; + flags |= SYSTEM_UI_FLAG_HIDE_NAVIGATION; + flags |= SYSTEM_UI_FLAG_FULLSCREEN; + flags |= SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN; + } else { + flags &= ~SYSTEM_UI_FLAG_IMMERSIVE_STICKY; + flags &= ~SYSTEM_UI_FLAG_HIDE_NAVIGATION; + flags &= ~SYSTEM_UI_FLAG_FULLSCREEN; + flags &= ~SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN; + } + this.setSystemUiVisibility(flags); + return; + } + + Window window = ((Activity) this.getContext()).getWindow(); + WindowInsetsController insetsController = window.getInsetsController(); + if (insetsController == null) { + // return; + } + // Configure the behavior of the hidden system bars + insetsController.setSystemBarsBehavior( + WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE + ); if (enabled) { - flags |= SYSTEM_UI_FLAG_IMMERSIVE_STICKY; - flags |= SYSTEM_UI_FLAG_HIDE_NAVIGATION; - flags |= SYSTEM_UI_FLAG_FULLSCREEN; - flags |= SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN; + // Hide both the status bar and the navigation bar + insetsController.hide(WindowInsets.Type.systemBars()); } else { - flags &= ~SYSTEM_UI_FLAG_IMMERSIVE_STICKY; - flags &= ~SYSTEM_UI_FLAG_HIDE_NAVIGATION; - flags &= ~SYSTEM_UI_FLAG_FULLSCREEN; - flags &= ~SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN; + insetsController.show(WindowInsets.Type.systemBars()); } - this.setSystemUiVisibility(flags); + + // window.setDecorFitsSystemWindows(false); } private enum Bar { @@ -217,9 +238,9 @@ public final class GioView extends SurfaceView { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.R) { int flags = this.getSystemUiVisibility(); if (luminance > 128) { - flags |= viewMask; + flags |= viewMask; } else { - flags &= ~viewMask; + flags &= ~viewMask; } this.setSystemUiVisibility(flags); return;