Skip to content

Commit

Permalink
CB-14238: Fixed transparency of statusbar
Browse files Browse the repository at this point in the history
  • Loading branch information
aszmyd committed Aug 1, 2018
1 parent ecf8ccd commit 515d683
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 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 (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);
Expand Down Expand Up @@ -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);
}
}

Expand Down

0 comments on commit 515d683

Please sign in to comment.