refactor(android): Remove unused code (#242)

This commit is contained in:
jcesarmobile 2022-09-07 22:10:39 +02:00 committed by GitHub
parent 1672883a7f
commit 53ead01614
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -54,9 +54,7 @@ public class StatusBar extends CordovaPlugin {
LOG.v(TAG, "StatusBar: initialization"); LOG.v(TAG, "StatusBar: initialization");
super.initialize(cordova, webView); super.initialize(cordova, webView);
this.cordova.getActivity().runOnUiThread(new Runnable() { this.cordova.getActivity().runOnUiThread(() -> {
@Override
public void run() {
// Clear flag FLAG_FORCE_NOT_FULLSCREEN which is set initially // Clear flag FLAG_FORCE_NOT_FULLSCREEN which is set initially
// by the Cordova. // by the Cordova.
Window window = cordova.getActivity().getWindow(); Window window = cordova.getActivity().getWindow();
@ -71,7 +69,6 @@ public class StatusBar extends CordovaPlugin {
// Read 'StatusBarStyle' from config.xml, default is 'lightcontent'. // Read 'StatusBarStyle' from config.xml, default is 'lightcontent'.
String styleSetting = preferences.getString("StatusBarStyle", "lightcontent"); String styleSetting = preferences.getString("StatusBarStyle", "lightcontent");
setStatusBarStyle(styleSetting); setStatusBarStyle(styleSetting);
}
}); });
} }
@ -84,7 +81,7 @@ public class StatusBar extends CordovaPlugin {
* @return True if the action was valid, false otherwise. * @return True if the action was valid, false otherwise.
*/ */
@Override @Override
public boolean execute(final String action, final CordovaArgs args, final CallbackContext callbackContext) throws JSONException { public boolean execute(final String action, final CordovaArgs args, final CallbackContext callbackContext) {
LOG.v(TAG, "Executing action: " + action); LOG.v(TAG, "Executing action: " + action);
final Activity activity = this.cordova.getActivity(); final Activity activity = this.cordova.getActivity();
final Window window = activity.getWindow(); final Window window = activity.getWindow();
@ -96,97 +93,64 @@ public class StatusBar extends CordovaPlugin {
} }
if ("show".equals(action)) { if ("show".equals(action)) {
this.cordova.getActivity().runOnUiThread(new Runnable() { this.cordova.getActivity().runOnUiThread(() -> {
@Override
public void run() {
// SYSTEM_UI_FLAG_FULLSCREEN is available since JellyBean, but we
// use KitKat here to be aligned with "Fullscreen" preference
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
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;
window.getDecorView().setSystemUiVisibility(uiOptions); window.getDecorView().setSystemUiVisibility(uiOptions);
}
// CB-11197 We still need to update LayoutParams to force status bar // CB-11197 We still need to update LayoutParams to force status bar
// to be hidden when entering e.g. text fields // to be hidden when entering e.g. text fields
window.clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); window.clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
}); });
return true; return true;
} }
if ("hide".equals(action)) { if ("hide".equals(action)) {
this.cordova.getActivity().runOnUiThread(new Runnable() { this.cordova.getActivity().runOnUiThread(() -> {
@Override
public void run() {
// SYSTEM_UI_FLAG_FULLSCREEN is available since JellyBean, but we
// use KitKat here to be aligned with "Fullscreen" preference
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
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;
window.getDecorView().setSystemUiVisibility(uiOptions); window.getDecorView().setSystemUiVisibility(uiOptions);
}
// CB-11197 We still need to update LayoutParams to force status bar // CB-11197 We still need to update LayoutParams to force status bar
// to be hidden when entering e.g. text fields // to be hidden when entering e.g. text fields
window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
}); });
return true; return true;
} }
if ("backgroundColorByHexString".equals(action)) { if ("backgroundColorByHexString".equals(action)) {
this.cordova.getActivity().runOnUiThread(new Runnable() { this.cordova.getActivity().runOnUiThread(() -> {
@Override
public void run() {
try { try {
setStatusBarBackgroundColor(args.getString(0)); setStatusBarBackgroundColor(args.getString(0));
} catch (JSONException ignore) { } catch (JSONException ignore) {
LOG.e(TAG, "Invalid hexString argument, use f.i. '#777777'"); LOG.e(TAG, "Invalid hexString argument, use f.i. '#777777'");
} }
}
}); });
return true; return true;
} }
if ("overlaysWebView".equals(action)) { if ("overlaysWebView".equals(action)) {
if (Build.VERSION.SDK_INT >= 21) { this.cordova.getActivity().runOnUiThread(() -> {
this.cordova.getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
try { try {
setStatusBarTransparent(args.getBoolean(0)); setStatusBarTransparent(args.getBoolean(0));
} catch (JSONException ignore) { } catch (JSONException ignore) {
LOG.e(TAG, "Invalid boolean argument"); LOG.e(TAG, "Invalid boolean argument");
} }
}
}); });
return true; return true;
} }
else return args.getBoolean(0) == false;
}
if ("styleDefault".equals(action)) { if ("styleDefault".equals(action)) {
this.cordova.getActivity().runOnUiThread(new Runnable() { this.cordova.getActivity().runOnUiThread(() -> setStatusBarStyle("default"));
@Override
public void run() {
setStatusBarStyle("default");
}
});
return true; return true;
} }
if ("styleLightContent".equals(action)) { if ("styleLightContent".equals(action)) {
this.cordova.getActivity().runOnUiThread(new Runnable() { this.cordova.getActivity().runOnUiThread(() -> setStatusBarStyle("lightcontent"));
@Override
public void run() {
setStatusBarStyle("lightcontent");
}
});
return true; return true;
} }
@ -194,7 +158,6 @@ public class StatusBar extends CordovaPlugin {
} }
private void setStatusBarBackgroundColor(final String colorPref) { private void setStatusBarBackgroundColor(final String colorPref) {
if (Build.VERSION.SDK_INT >= 21) {
if (colorPref != null && !colorPref.isEmpty()) { if (colorPref != null && !colorPref.isEmpty()) {
final Window window = cordova.getActivity().getWindow(); final Window window = cordova.getActivity().getWindow();
// Method and constants not available on all SDKs but we want to be able to compile this code with any SDK // Method and constants not available on all SDKs but we want to be able to compile this code with any SDK
@ -211,10 +174,8 @@ public class StatusBar extends CordovaPlugin {
} }
} }
} }
}
private void setStatusBarTransparent(final boolean transparent) { private void setStatusBarTransparent(final boolean transparent) {
if (Build.VERSION.SDK_INT >= 21) {
final Window window = cordova.getActivity().getWindow(); final Window window = cordova.getActivity().getWindow();
if (transparent) { if (transparent) {
window.getDecorView().setSystemUiVisibility( window.getDecorView().setSystemUiVisibility(
@ -228,7 +189,6 @@ public class StatusBar extends CordovaPlugin {
| View.SYSTEM_UI_FLAG_VISIBLE); | View.SYSTEM_UI_FLAG_VISIBLE);
} }
} }
}
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) {