Update SDLActivity.java

Enabled immersive mode on Android devices during onCreate in the lifecycle.
This commit is contained in:
Patrick Babb
2025-05-04 23:53:45 -05:00
committed by GitHub
parent e6a99ca9ac
commit ccd421598e
@@ -1115,16 +1115,41 @@ public class SDLActivity extends Activity implements OnKeyListener {
} }
// Setup // Setup
private void enterImmersiveMode() {
final View decorView = getWindow().getDecorView();
decorView.setSystemUiVisibility(
View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE
);
}
@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if (hasFocus) {
enterImmersiveMode();
}
}
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
//Log.d(TAG, "onCreate()");
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll() StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
.build();
StrictMode.setThreadPolicy(policy); StrictMode.setThreadPolicy(policy);
setContentView(R.layout.main); setContentView(R.layout.main);
// Enable immersive mode
enterImmersiveMode();
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
// So we can call stuff from static callbacks // So we can call stuff from static callbacks
mSingleton = this; mSingleton = this;
mContext = this.getApplicationContext(); mContext = this.getApplicationContext();