Skip to content

Commit

Permalink
Android: Better fullscreen support.
Browse files Browse the repository at this point in the history
  • Loading branch information
MohammedKHC0 authored Jan 27, 2025
1 parent 2472690 commit f17338d
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions java/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

}
}
});
Expand Down Expand Up @@ -366,4 +370,3 @@ public void setClipboardText(String text) {
clipboard.setPrimaryClip(clip);
}
}

0 comments on commit f17338d

Please sign in to comment.