From d780b0d9d68702ebef6081a36b0acf7c34eb3eb8 Mon Sep 17 00:00:00 2001 From: Daniel Stone Date: Sun, 3 Apr 2022 11:04:56 -0700 Subject: [PATCH] GH-180 (android): Fixes nav and title bars still appearing when app is fullscreen (#213) Co-authored-by: Daniel Stone Co-authored-by: distinctdan --- src/android/SplashScreen.java | 41 +++++++++++++++++++++++++++++++---- 1 file changed, 37 insertions(+), 4 deletions(-) diff --git a/src/android/SplashScreen.java b/src/android/SplashScreen.java index 6f2252c7..ea9e38dc 100644 --- a/src/android/SplashScreen.java +++ b/src/android/SplashScreen.java @@ -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; @@ -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(); }