Skip to content

Commit

Permalink
MOBILE-4331 app: Remove status bar color from local plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
crazyserver committed Sep 4, 2023
1 parent a09b301 commit 10b0cfa
Showing 1 changed file with 1 addition and 41 deletions.
42 changes: 1 addition & 41 deletions cordova-plugin-moodleapp/src/android/SystemUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,7 @@ public class SystemUI extends CordovaPlugin {
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) {
try {
switch (action) {
case "setNavigationBarColor":
this.setNavigationBarColor(args.getString(0));
callbackContext.success();

return true;
// No actions yet.
}
} catch (Throwable e) {
Log.e(TAG, "Failed executing action: " + action, e);
Expand All @@ -45,41 +41,5 @@ public boolean execute(String action, JSONArray args, CallbackContext callbackCo
return false;
}

private void setNavigationBarColor(String color) {
if (Build.VERSION.SDK_INT < 21) {
return;
}

if (color == null || color.isEmpty()) {
return;
}

Log.d(TAG, "Setting navigation bar color to " + color);

this.cordova.getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
final int FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS = 0x80000000;
final int SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR = 0x00000010;
final Window window = cordova.getActivity().getWindow();
int uiOptions = window.getDecorView().getSystemUiVisibility();

uiOptions = uiOptions | FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS;
uiOptions = uiOptions & ~SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR;

window.getDecorView().setSystemUiVisibility(uiOptions);

try {
// Using reflection makes sure any 5.0+ device will work without having to compile with SDK level 21
window.getClass().getDeclaredMethod("setNavigationBarColor", int.class).invoke(window, Color.parseColor(color));
} catch (IllegalArgumentException ignore) {
Log.e(TAG, "Invalid hexString argument, use f.i. '#999999'");
} catch (Exception ignore) {
// this should not happen, only in case Android removes this method in a version > 21
Log.w(TAG, "Method window.setNavigationBarColor not found for SDK level " + Build.VERSION.SDK_INT);
}
}
});
}

}

0 comments on commit 10b0cfa

Please sign in to comment.