Skip to content

Commit

Permalink
GH-180 (android): Fixes nav and title bars still appearing when app i…
Browse files Browse the repository at this point in the history
…s fullscreen (#213)

Co-authored-by: Daniel Stone <daniel.stone@powerdms.com>
Co-authored-by: distinctdan <distinctdan@users.noreply.github.com>
  • Loading branch information
3 people authored Apr 3, 2022
1 parent 10be9d0 commit d780b0d
Showing 1 changed file with 37 additions and 4 deletions.
41 changes: 37 additions & 4 deletions src/android/SplashScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Licensed to the Apache Software Foundation (ASF) under one
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.view.Window;
import android.view.WindowManager;
import android.view.animation.Animation;
import android.view.animation.AlphaAnimation;
Expand Down Expand Up @@ -315,16 +316,48 @@ public void run() {

// Create and show the dialog
splashDialog = new Dialog(context, android.R.style.Theme_Translucent_NoTitleBar);
// check to see if the splash screen should be full screen
if ((cordova.getActivity().getWindow().getAttributes().flags & WindowManager.LayoutParams.FLAG_FULLSCREEN)
== WindowManager.LayoutParams.FLAG_FULLSCREEN) {
splashDialog.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,

// Check to see if the splash screen should be full screen.
// On first run, currently cordova hasn't set the window flags yet because it does it in
// onWindowFocusChanged instead of onCreate. If that's the case, we'll fall back to the
// Fullscreen preference. Hopefully it will get fixed so that cordova sets them in onCreate,
// so that this fallback can be removed.
boolean isFullscreen = false;
int mainWindowFlags = cordova.getActivity().getWindow().getAttributes().flags;
boolean flagFullscreen = (mainWindowFlags & WindowManager.LayoutParams.FLAG_FULLSCREEN)
== WindowManager.LayoutParams.FLAG_FULLSCREEN;
boolean flagForceNotFullscreen = (mainWindowFlags & WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN)
== WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN;

// If cordova has set flags, one of these must be true.
if (flagFullscreen || flagForceNotFullscreen) {
isFullscreen = flagFullscreen;
} else {
// Cordova hasn't set flags, fall back to reading preference.
isFullscreen = preferences.getBoolean("Fullscreen", false);
}

Window dialogWindow = splashDialog.getWindow();
if (isFullscreen) {
dialogWindow.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
splashDialog.setContentView(splashImageView);
splashDialog.setCancelable(false);
splashDialog.show();

if (isFullscreen) {
// These must be set after .show() is called because they only work on visible views.
// When the splashscreen hides, the app will revert to whatever was set in CordovaActivity
dialogWindow.getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
}

if (preferences.getBoolean("ShowSplashScreenSpinner", true)) {
spinnerStart();
}
Expand Down

0 comments on commit d780b0d

Please sign in to comment.