Merge branch 'CB-11858' of github.com:urmx/cordova-plugin-statusbar

This closes #78
This commit is contained in:
Joe Bowser 2017-10-12 13:25:12 -07:00
commit b03a8313ef
2 changed files with 79 additions and 0 deletions

View File

@ -163,6 +163,7 @@ Supported Platforms
-------------------
- iOS
- Android 6+
- Windows Phone 7
- Windows Phone 8
- Windows Phone 8.1
@ -179,6 +180,7 @@ Supported Platforms
-------------------
- iOS
- Android 6+
- Windows Phone 7
- Windows Phone 8
- Windows Phone 8.1
@ -195,6 +197,7 @@ Supported Platforms
-------------------
- iOS
- Android 6+
- Windows Phone 7
- Windows Phone 8
- Windows Phone 8.1
@ -211,6 +214,7 @@ Supported Platforms
-------------------
- iOS
- Android 6+
- Windows Phone 7
- Windows Phone 8
- Windows Phone 8.1

View File

@ -34,6 +34,7 @@ import org.apache.cordova.CordovaWebView;
import org.apache.cordova.LOG;
import org.apache.cordova.PluginResult;
import org.json.JSONException;
import java.util.Arrays;
public class StatusBar extends CordovaPlugin {
private static final String TAG = "StatusBar";
@ -60,6 +61,9 @@ public class StatusBar extends CordovaPlugin {
// Read 'StatusBarBackgroundColor' from config.xml, default is #000000.
setStatusBarBackgroundColor(preferences.getString("StatusBarBackgroundColor", "#000000"));
// Read 'StatusBarStyle' from config.xml, default is 'lightcontent'.
setStatusBarStyle(preferences.getString("StatusBarStyle", "lightcontent"));
}
});
}
@ -159,6 +163,46 @@ public class StatusBar extends CordovaPlugin {
else return args.getBoolean(0) == false;
}
if ("styleDefault".equals(action)) {
this.cordova.getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
setStatusBarStyle("default");
}
});
return true;
}
if ("styleLightContent".equals(action)) {
this.cordova.getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
setStatusBarStyle("lightcontent");
}
});
return true;
}
if ("styleBlackTranslucent".equals(action)) {
this.cordova.getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
setStatusBarStyle("blacktranslucent");
}
});
return true;
}
if ("styleBlackOpaque".equals(action)) {
this.cordova.getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
setStatusBarStyle("blackopaque");
}
});
return true;
}
return false;
}
@ -198,4 +242,35 @@ public class StatusBar extends CordovaPlugin {
}
}
}
private void setStatusBarStyle(final String style) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (style != null && !style.isEmpty()) {
View decorView = cordova.getActivity().getWindow().getDecorView();
int uiOptions = decorView.getSystemUiVisibility();
String[] darkContentStyles = {
"default",
};
String[] lightContentStyles = {
"lightcontent",
"blacktranslucent",
"blackopaque",
};
if (Arrays.asList(darkContentStyles).contains(style.toLowerCase())) {
decorView.setSystemUiVisibility(uiOptions | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
return;
}
if (Arrays.asList(lightContentStyles).contains(style.toLowerCase())) {
decorView.setSystemUiVisibility(uiOptions & ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
return;
}
LOG.e(TAG, "Invalid style, must be either 'default', 'lightcontent' or the deprecated 'blacktranslucent' and 'blackopaque'");
}
}
}
}