mirror of
https://github.com/apache/cordova-plugin-statusbar.git
synced 2025-01-19 01:12:49 +08:00
refactor(android): refactor setStatusBarStyle (#248)
This commit is contained in:
parent
a86c3e6279
commit
bb82db9aa9
@ -37,7 +37,6 @@ import org.apache.cordova.CordovaWebView;
|
|||||||
import org.apache.cordova.LOG;
|
import org.apache.cordova.LOG;
|
||||||
import org.apache.cordova.PluginResult;
|
import org.apache.cordova.PluginResult;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
public class StatusBar extends CordovaPlugin {
|
public class StatusBar extends CordovaPlugin {
|
||||||
private static final String TAG = "StatusBar";
|
private static final String TAG = "StatusBar";
|
||||||
@ -78,8 +77,9 @@ public class StatusBar extends CordovaPlugin {
|
|||||||
setStatusBarBackgroundColor(preferences.getString("StatusBarBackgroundColor", "#000000"));
|
setStatusBarBackgroundColor(preferences.getString("StatusBarBackgroundColor", "#000000"));
|
||||||
|
|
||||||
// Read 'StatusBarStyle' from config.xml, default is 'lightcontent'.
|
// Read 'StatusBarStyle' from config.xml, default is 'lightcontent'.
|
||||||
String styleSetting = preferences.getString("StatusBarStyle", STYLE_LIGHT_CONTENT);
|
setStatusBarStyle(
|
||||||
setStatusBarStyle(styleSetting);
|
preferences.getString("StatusBarStyle", STYLE_LIGHT_CONTENT).toLowerCase()
|
||||||
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -202,25 +202,16 @@ public class StatusBar extends CordovaPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void setStatusBarStyle(final String style) {
|
private void setStatusBarStyle(final String style) {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !style.isEmpty()) {
|
||||||
if (style != null && !style.isEmpty()) {
|
Window window = cordova.getActivity().getWindow();
|
||||||
Window window = cordova.getActivity().getWindow();
|
View decorView = window.getDecorView();
|
||||||
View decorView = window.getDecorView();
|
WindowInsetsControllerCompat windowInsetsControllerCompat = WindowCompat.getInsetsController(window, decorView);
|
||||||
WindowInsetsControllerCompat windowInsetsControllerCompat = WindowCompat.getInsetsController(window, decorView);
|
|
||||||
|
|
||||||
String[] darkContentStyles = { STYLE_DEFAULT };
|
|
||||||
String[] lightContentStyles = { STYLE_LIGHT_CONTENT };
|
|
||||||
|
|
||||||
if (Arrays.asList(darkContentStyles).contains(style.toLowerCase())) {
|
|
||||||
windowInsetsControllerCompat.setAppearanceLightStatusBars(true);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Arrays.asList(lightContentStyles).contains(style.toLowerCase())) {
|
|
||||||
windowInsetsControllerCompat.setAppearanceLightStatusBars(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (style.equals(STYLE_DEFAULT)) {
|
||||||
|
windowInsetsControllerCompat.setAppearanceLightStatusBars(true);
|
||||||
|
} else if (style.equals(STYLE_LIGHT_CONTENT)) {
|
||||||
|
windowInsetsControllerCompat.setAppearanceLightStatusBars(false);
|
||||||
|
} else {
|
||||||
LOG.e(TAG, "Invalid style, must be either 'default' or 'lightcontent'");
|
LOG.e(TAG, "Invalid style, must be either 'default' or 'lightcontent'");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user