From bb82db9aa9d8acbeb44631caa7e99fce9fb35a26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=A8=E3=83=AA=E3=82=B9?= Date: Wed, 5 Oct 2022 16:28:59 +0900 Subject: [PATCH] refactor(android): refactor setStatusBarStyle (#248) --- src/android/StatusBar.java | 33 ++++++++++++--------------------- 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/src/android/StatusBar.java b/src/android/StatusBar.java index 89c2210..0337967 100644 --- a/src/android/StatusBar.java +++ b/src/android/StatusBar.java @@ -37,7 +37,6 @@ 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"; @@ -78,8 +77,9 @@ public class StatusBar extends CordovaPlugin { setStatusBarBackgroundColor(preferences.getString("StatusBarBackgroundColor", "#000000")); // Read 'StatusBarStyle' from config.xml, default is 'lightcontent'. - String styleSetting = preferences.getString("StatusBarStyle", STYLE_LIGHT_CONTENT); - setStatusBarStyle(styleSetting); + setStatusBarStyle( + preferences.getString("StatusBarStyle", STYLE_LIGHT_CONTENT).toLowerCase() + ); }); } @@ -202,25 +202,16 @@ 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()) { - Window window = cordova.getActivity().getWindow(); - View decorView = window.getDecorView(); - 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 (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !style.isEmpty()) { + Window window = cordova.getActivity().getWindow(); + View decorView = window.getDecorView(); + WindowInsetsControllerCompat windowInsetsControllerCompat = WindowCompat.getInsetsController(window, decorView); + 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'"); } }