Skip to content

Commit d780b0d

Browse files
distinctdanDaniel Stone
andauthored
GH-180 (android): Fixes nav and title bars still appearing when app is fullscreen (#213)
Co-authored-by: Daniel Stone <[email protected]> Co-authored-by: distinctdan <[email protected]>
1 parent 10be9d0 commit d780b0d

File tree

1 file changed

+37
-4
lines changed

1 file changed

+37
-4
lines changed

src/android/SplashScreen.java

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ Licensed to the Apache Software Foundation (ASF) under one
3232
import android.view.Gravity;
3333
import android.view.View;
3434
import android.view.ViewGroup.LayoutParams;
35+
import android.view.Window;
3536
import android.view.WindowManager;
3637
import android.view.animation.Animation;
3738
import android.view.animation.AlphaAnimation;
@@ -315,16 +316,48 @@ public void run() {
315316

316317
// Create and show the dialog
317318
splashDialog = new Dialog(context, android.R.style.Theme_Translucent_NoTitleBar);
318-
// check to see if the splash screen should be full screen
319-
if ((cordova.getActivity().getWindow().getAttributes().flags & WindowManager.LayoutParams.FLAG_FULLSCREEN)
320-
== WindowManager.LayoutParams.FLAG_FULLSCREEN) {
321-
splashDialog.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
319+
320+
// Check to see if the splash screen should be full screen.
321+
// On first run, currently cordova hasn't set the window flags yet because it does it in
322+
// onWindowFocusChanged instead of onCreate. If that's the case, we'll fall back to the
323+
// Fullscreen preference. Hopefully it will get fixed so that cordova sets them in onCreate,
324+
// so that this fallback can be removed.
325+
boolean isFullscreen = false;
326+
int mainWindowFlags = cordova.getActivity().getWindow().getAttributes().flags;
327+
boolean flagFullscreen = (mainWindowFlags & WindowManager.LayoutParams.FLAG_FULLSCREEN)
328+
== WindowManager.LayoutParams.FLAG_FULLSCREEN;
329+
boolean flagForceNotFullscreen = (mainWindowFlags & WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN)
330+
== WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN;
331+
332+
// If cordova has set flags, one of these must be true.
333+
if (flagFullscreen || flagForceNotFullscreen) {
334+
isFullscreen = flagFullscreen;
335+
} else {
336+
// Cordova hasn't set flags, fall back to reading preference.
337+
isFullscreen = preferences.getBoolean("Fullscreen", false);
338+
}
339+
340+
Window dialogWindow = splashDialog.getWindow();
341+
if (isFullscreen) {
342+
dialogWindow.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
322343
WindowManager.LayoutParams.FLAG_FULLSCREEN);
323344
}
324345
splashDialog.setContentView(splashImageView);
325346
splashDialog.setCancelable(false);
326347
splashDialog.show();
327348

349+
if (isFullscreen) {
350+
// These must be set after .show() is called because they only work on visible views.
351+
// When the splashscreen hides, the app will revert to whatever was set in CordovaActivity
352+
dialogWindow.getDecorView().setSystemUiVisibility(
353+
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
354+
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
355+
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
356+
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
357+
| View.SYSTEM_UI_FLAG_FULLSCREEN
358+
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
359+
}
360+
328361
if (preferences.getBoolean("ShowSplashScreenSpinner", true)) {
329362
spinnerStart();
330363
}

0 commit comments

Comments
 (0)