Skip to content

Commit

Permalink
Make transparency of statusbar persistent when hiding and showing sta…
Browse files Browse the repository at this point in the history
…tus bar again + support pre-configured `StatusBarOverlaysWebView` parameter from `config.xml`
  • Loading branch information
aszmyd committed Mar 26, 2018
1 parent 4c1507b commit 75d0d81
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/android/StatusBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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"));
}
Expand Down Expand Up @@ -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 (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);
Expand Down Expand Up @@ -227,20 +236,22 @@ private void setStatusBarBackgroundColor(final String colorPref) {
}

private void setStatusBarTransparent(final boolean transparent) {
if (Build.VERSION.SDK_INT >= 21) {
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);
window.setStatusBarColor(Color.TRANSPARENT);

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);
}
}
}

private void setStatusBarStyle(final String style) {
Expand Down

0 comments on commit 75d0d81

Please sign in to comment.