Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CB-14238: Make transparency of statusbar persistent when hiding and showing statusbar #99

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code indentation of the code inside this removed if should be adapted to match the added this.transparent = transparent;, right?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. Fixes

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