refactor(android): execute - convert if condition to switch case (#251)

This commit is contained in:
エリス 2022-10-05 16:29:28 +09:00 committed by GitHub
parent 21847d0b78
commit f45cf99a3a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -97,14 +97,14 @@ public class StatusBar extends CordovaPlugin {
final Activity activity = this.cordova.getActivity(); final Activity activity = this.cordova.getActivity();
final Window window = activity.getWindow(); final Window window = activity.getWindow();
if (ACTION_READY.equals(action)) { switch (action) {
case ACTION_READY:
boolean statusBarVisible = (window.getAttributes().flags & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0; boolean statusBarVisible = (window.getAttributes().flags & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0;
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, statusBarVisible)); callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, statusBarVisible));
return true; return true;
}
if (ACTION_SHOW.equals(action)) { case ACTION_SHOW:
this.cordova.getActivity().runOnUiThread(() -> { activity.runOnUiThread(() -> {
int uiOptions = window.getDecorView().getSystemUiVisibility(); int uiOptions = window.getDecorView().getSystemUiVisibility();
uiOptions &= ~View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN; uiOptions &= ~View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
uiOptions &= ~View.SYSTEM_UI_FLAG_FULLSCREEN; uiOptions &= ~View.SYSTEM_UI_FLAG_FULLSCREEN;
@ -116,10 +116,9 @@ public class StatusBar extends CordovaPlugin {
window.clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); window.clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
}); });
return true; return true;
}
if (ACTION_HIDE.equals(action)) { case ACTION_HIDE:
this.cordova.getActivity().runOnUiThread(() -> { activity.runOnUiThread(() -> {
int uiOptions = window.getDecorView().getSystemUiVisibility() int uiOptions = window.getDecorView().getSystemUiVisibility()
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_FULLSCREEN; | View.SYSTEM_UI_FLAG_FULLSCREEN;
@ -131,10 +130,9 @@ public class StatusBar extends CordovaPlugin {
window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
}); });
return true; return true;
}
if (ACTION_BACKGROUND_COLOR_BY_HEX_STRING.equals(action)) { case ACTION_BACKGROUND_COLOR_BY_HEX_STRING:
this.cordova.getActivity().runOnUiThread(() -> { activity.runOnUiThread(() -> {
try { try {
setStatusBarBackgroundColor(args.getString(0)); setStatusBarBackgroundColor(args.getString(0));
} catch (JSONException ignore) { } catch (JSONException ignore) {
@ -142,10 +140,9 @@ public class StatusBar extends CordovaPlugin {
} }
}); });
return true; return true;
}
if (ACTION_OVERLAYS_WEB_VIEW.equals(action)) { case ACTION_OVERLAYS_WEB_VIEW:
this.cordova.getActivity().runOnUiThread(() -> { activity.runOnUiThread(() -> {
try { try {
setStatusBarTransparent(args.getBoolean(0)); setStatusBarTransparent(args.getBoolean(0));
} catch (JSONException ignore) { } catch (JSONException ignore) {
@ -153,20 +150,19 @@ public class StatusBar extends CordovaPlugin {
} }
}); });
return true; return true;
}
if (ACTION_STYLE_DEFAULT.equals(action)) { case ACTION_STYLE_DEFAULT:
this.cordova.getActivity().runOnUiThread(() -> setStatusBarStyle(STYLE_DEFAULT)); activity.runOnUiThread(() -> setStatusBarStyle(STYLE_DEFAULT));
return true; return true;
}
if (ACTION_STYLE_LIGHT_CONTENT.equals(action)) { case ACTION_STYLE_LIGHT_CONTENT:
this.cordova.getActivity().runOnUiThread(() -> setStatusBarStyle(STYLE_LIGHT_CONTENT)); activity.runOnUiThread(() -> setStatusBarStyle(STYLE_LIGHT_CONTENT));
return true; return true;
}
default:
return false; return false;
} }
}
private void setStatusBarBackgroundColor(final String colorPref) { private void setStatusBarBackgroundColor(final String colorPref) {
if (colorPref.isEmpty()) return; if (colorPref.isEmpty()) return;