This is an automated email from the ASF dual-hosted git repository. erisu pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/cordova-plugin-statusbar.git
The following commit(s) were added to refs/heads/master by this push: new f45cf99 refactor(android): execute - convert if condition to switch case (#251) f45cf99 is described below commit f45cf99a3a67b292baed721f55a30c24c24384e4 Author: エリス <er...@users.noreply.github.com> AuthorDate: Wed Oct 5 16:29:28 2022 +0900 refactor(android): execute - convert if condition to switch case (#251) --- src/android/StatusBar.java | 132 ++++++++++++++++++++++----------------------- 1 file changed, 64 insertions(+), 68 deletions(-) diff --git a/src/android/StatusBar.java b/src/android/StatusBar.java index 67680ab..52c5da3 100644 --- a/src/android/StatusBar.java +++ b/src/android/StatusBar.java @@ -97,75 +97,71 @@ public class StatusBar extends CordovaPlugin { final Activity activity = this.cordova.getActivity(); final Window window = activity.getWindow(); - if (ACTION_READY.equals(action)) { - boolean statusBarVisible = (window.getAttributes().flags & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0; - callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, statusBarVisible)); - return true; + switch (action) { + case ACTION_READY: + boolean statusBarVisible = (window.getAttributes().flags & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0; + callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, statusBarVisible)); + return true; + + case ACTION_SHOW: + activity.runOnUiThread(() -> { + int uiOptions = window.getDecorView().getSystemUiVisibility(); + uiOptions &= ~View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN; + uiOptions &= ~View.SYSTEM_UI_FLAG_FULLSCREEN; + + window.getDecorView().setSystemUiVisibility(uiOptions); + + // CB-11197 We still need to update LayoutParams to force status bar + // to be hidden when entering e.g. text fields + window.clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); + }); + return true; + + case ACTION_HIDE: + activity.runOnUiThread(() -> { + int uiOptions = window.getDecorView().getSystemUiVisibility() + | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN + | View.SYSTEM_UI_FLAG_FULLSCREEN; + + window.getDecorView().setSystemUiVisibility(uiOptions); + + // CB-11197 We still need to update LayoutParams to force status bar + // to be hidden when entering e.g. text fields + window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); + }); + return true; + + case ACTION_BACKGROUND_COLOR_BY_HEX_STRING: + activity.runOnUiThread(() -> { + try { + setStatusBarBackgroundColor(args.getString(0)); + } catch (JSONException ignore) { + LOG.e(TAG, "Invalid hexString argument, use f.i. '#777777'"); + } + }); + return true; + + case ACTION_OVERLAYS_WEB_VIEW: + activity.runOnUiThread(() -> { + try { + setStatusBarTransparent(args.getBoolean(0)); + } catch (JSONException ignore) { + LOG.e(TAG, "Invalid boolean argument"); + } + }); + return true; + + case ACTION_STYLE_DEFAULT: + activity.runOnUiThread(() -> setStatusBarStyle(STYLE_DEFAULT)); + return true; + + case ACTION_STYLE_LIGHT_CONTENT: + activity.runOnUiThread(() -> setStatusBarStyle(STYLE_LIGHT_CONTENT)); + return true; + + default: + return false; } - - if (ACTION_SHOW.equals(action)) { - this.cordova.getActivity().runOnUiThread(() -> { - int uiOptions = window.getDecorView().getSystemUiVisibility(); - uiOptions &= ~View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN; - uiOptions &= ~View.SYSTEM_UI_FLAG_FULLSCREEN; - - window.getDecorView().setSystemUiVisibility(uiOptions); - - // CB-11197 We still need to update LayoutParams to force status bar - // to be hidden when entering e.g. text fields - window.clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); - }); - return true; - } - - if (ACTION_HIDE.equals(action)) { - this.cordova.getActivity().runOnUiThread(() -> { - int uiOptions = window.getDecorView().getSystemUiVisibility() - | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN - | View.SYSTEM_UI_FLAG_FULLSCREEN; - - window.getDecorView().setSystemUiVisibility(uiOptions); - - // CB-11197 We still need to update LayoutParams to force status bar - // to be hidden when entering e.g. text fields - window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); - }); - return true; - } - - if (ACTION_BACKGROUND_COLOR_BY_HEX_STRING.equals(action)) { - this.cordova.getActivity().runOnUiThread(() -> { - try { - setStatusBarBackgroundColor(args.getString(0)); - } catch (JSONException ignore) { - LOG.e(TAG, "Invalid hexString argument, use f.i. '#777777'"); - } - }); - return true; - } - - if (ACTION_OVERLAYS_WEB_VIEW.equals(action)) { - this.cordova.getActivity().runOnUiThread(() -> { - try { - setStatusBarTransparent(args.getBoolean(0)); - } catch (JSONException ignore) { - LOG.e(TAG, "Invalid boolean argument"); - } - }); - return true; - } - - if (ACTION_STYLE_DEFAULT.equals(action)) { - this.cordova.getActivity().runOnUiThread(() -> setStatusBarStyle(STYLE_DEFAULT)); - return true; - } - - if (ACTION_STYLE_LIGHT_CONTENT.equals(action)) { - this.cordova.getActivity().runOnUiThread(() -> setStatusBarStyle(STYLE_LIGHT_CONTENT)); - return true; - } - - return false; } private void setStatusBarBackgroundColor(final String colorPref) { --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@cordova.apache.org For additional commands, e-mail: commits-h...@cordova.apache.org