From 515d683053720fe0c5f958713624cfe59dfaf19e Mon Sep 17 00:00:00 2001 From: Adam Szmyd Date: Mon, 26 Mar 2018 14:08:05 +0200 Subject: [PATCH] CB-14238: Fixed transparency of statusbar --- src/android/StatusBar.java | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/src/android/StatusBar.java b/src/android/StatusBar.java index 714c30e8..4ee44651 100644 --- a/src/android/StatusBar.java +++ b/src/android/StatusBar.java @@ -39,6 +39,8 @@ public class StatusBar extends CordovaPlugin { private static final String TAG = "StatusBar"; + private boolean transparent = false; + /** * Sets the context of the Command. This can then be used to do things like * get file paths associated with the Activity. @@ -62,6 +64,9 @@ public void run() { // Read 'StatusBarBackgroundColor' from config.xml, default is #000000. setStatusBarBackgroundColor(preferences.getString("StatusBarBackgroundColor", "#000000")); + // Read 'StatusBarOverlaysWebView' from config.xml, default is false. + setStatusBarTransparent(preferences.getBoolean("StatusBarOverlaysWebView", false)); + // Read 'StatusBarStyle' from config.xml, default is 'lightcontent'. setStatusBarStyle(preferences.getString("StatusBarStyle", "lightcontent")); } @@ -96,7 +101,11 @@ public void run() { // use KitKat here to be aligned with "Fullscreen" preference if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { int uiOptions = window.getDecorView().getSystemUiVisibility(); - uiOptions &= ~View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN; + if (StatusBar.this.transparent) { + uiOptions |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN; + } else { + uiOptions &= ~View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN; + } uiOptions &= ~View.SYSTEM_UI_FLAG_FULLSCREEN; window.getDecorView().setSystemUiVisibility(uiOptions); @@ -227,19 +236,21 @@ private void setStatusBarBackgroundColor(final String colorPref) { } private void setStatusBarTransparent(final boolean transparent) { - if (Build.VERSION.SDK_INT >= 21) { - final Window window = cordova.getActivity().getWindow(); - if (transparent) { - window.getDecorView().setSystemUiVisibility( - View.SYSTEM_UI_FLAG_LAYOUT_STABLE - | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN); + this.transparent = transparent; + final Window window = cordova.getActivity().getWindow(); + if (transparent) { + window.getDecorView().setSystemUiVisibility( + View.SYSTEM_UI_FLAG_LAYOUT_STABLE + | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN); + + if (Build.VERSION.SDK_INT >= 21) { window.setStatusBarColor(Color.TRANSPARENT); } - else { - window.getDecorView().setSystemUiVisibility( - View.SYSTEM_UI_FLAG_LAYOUT_STABLE - | View.SYSTEM_UI_FLAG_VISIBLE); - } + } + else { + window.getDecorView().setSystemUiVisibility( + View.SYSTEM_UI_FLAG_LAYOUT_STABLE + | View.SYSTEM_UI_FLAG_VISIBLE); } }