Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 11 additions & 43 deletions src/plugins/system/android/com/foxdebug/system/System.java
Original file line number Diff line number Diff line change
Expand Up @@ -1686,53 +1686,21 @@ private void removeShortcut(String id, CallbackContext callback) {
}

private void setUiTheme(
final String systemBarColor,
final JSONObject scheme,
final CallbackContext callback
final String systemBarColor,
final JSONObject scheme,
final CallbackContext callback
) {
this.systemBarColor = Color.parseColor(systemBarColor);
this.theme = new Theme(scheme);

final Window window = activity.getWindow();
// Method and constants not available on all SDKs but we want to be able to compile this code with any SDK
window.clearFlags(0x04000000); // SDK 19: WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
window.addFlags(0x80000000); // SDK 21: WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
try {
// Using reflection makes sure any 5.0+ device will work without having to compile with SDK level 21

window
.getClass()
.getMethod("setNavigationBarColor", int.class)
.invoke(window, this.systemBarColor);
this.systemBarColor = Color.parseColor(systemBarColor);
this.theme = new Theme(scheme);

preferences.set("BackgroundColor", this.systemBarColor);

window
.getClass()
.getMethod("setStatusBarColor", int.class)
.invoke(window, this.systemBarColor);

window.getDecorView().setBackgroundColor(this.systemBarColor);
webView.getPluginManager().postMessage("updateSystemBars", null);

if (Build.VERSION.SDK_INT < 30) {
setStatusBarStyle(window);
setNavigationBarStyle(window);
} else {
String themeType = theme.getType();
WindowInsetsController controller = window.getInsetsController();
int appearance =
WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS |
WindowInsetsController.APPEARANCE_LIGHT_NAVIGATION_BARS;

if (themeType.equals("light")) {
controller.setSystemBarsAppearance(appearance, appearance);
} else {
controller.setSystemBarsAppearance(0, appearance);
}
}
callback.success("OK");
} catch (IllegalArgumentException error) {
callback.error(error.toString());
} catch (Exception error) {
callback.error(error.toString());
callback.success();
} catch (IllegalArgumentException e) {
callback.error("Invalid color: " + systemBarColor);
}
}

Expand Down
93 changes: 53 additions & 40 deletions src/plugins/system/www/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,19 @@ module.exports = {
cordova.exec(success, error, 'System', 'getNativeLibraryPath', []);
},

getFilesDir: function (success, error) {
cordova.exec(success, error, 'System', 'getFilesDir', []);
},
getRewardStatus: function (success, error) {
cordova.exec(success, error, 'System', 'getRewardStatus', []);
},
redeemReward: function (offerId, success, error) {
cordova.exec(success, error, 'System', 'redeemReward', [offerId]);
},

getParentPath: function (path, success, error) {
cordova.exec(success, error, 'System', 'getParentPath', [path]);
},
getFilesDir: function (success, error) {
cordova.exec(success, error, 'System', 'getFilesDir', []);
},
getRewardStatus: function (success, error) {
cordova.exec(success, error, 'System', 'getRewardStatus', []);
},
redeemReward: function (offerId, success, error) {
cordova.exec(success, error, 'System', 'redeemReward', [offerId]);
},
getParentPath: function (path, success, error) {
cordova.exec(success, error, 'System', 'getParentPath', [path]);
},

listChildren: function (path, success, error) {
cordova.exec(success, error, 'System', 'listChildren', [path]);
Expand Down Expand Up @@ -135,36 +135,49 @@ module.exports = {
onError: null,
};

cordova.exec(function (data) {
if (typeof data !== 'string') {
console.warn('System.inAppBrowser: invalid callback payload', data);
return;
}
var separatorIndex = data.indexOf(':');
if (separatorIndex < 0) {
console.warn('System.inAppBrowser: malformed callback payload', data);
return;
}
var dataTag = data.slice(0, separatorIndex);
var dataUrl = data.slice(separatorIndex + 1);
if (dataTag === 'onOpenExternalBrowser') {
if (typeof myInAppBrowser.onOpenExternalBrowser === 'function') {
myInAppBrowser.onOpenExternalBrowser(dataUrl);
} else {
console.warn('System.inAppBrowser: onOpenExternalBrowser handler is not set');
}
}
}, function (err) {
if (typeof myInAppBrowser.onError === 'function') {
myInAppBrowser.onError(err);
return;
}
console.warn('System.inAppBrowser error callback not handled', err);
}, 'System', 'in-app-browser', [url, title, !!showButtons, disableCache]);
cordova.exec(function (data) {
if (typeof data !== 'string') {
console.warn('System.inAppBrowser: invalid callback payload', data);
return;
}
var separatorIndex = data.indexOf(':');
if (separatorIndex < 0) {
console.warn('System.inAppBrowser: malformed callback payload', data);
return;
}
var dataTag = data.slice(0, separatorIndex);
var dataUrl = data.slice(separatorIndex + 1);
if (dataTag === 'onOpenExternalBrowser') {
if (typeof myInAppBrowser.onOpenExternalBrowser === 'function') {
myInAppBrowser.onOpenExternalBrowser(dataUrl);
} else {
console.warn('System.inAppBrowser: onOpenExternalBrowser handler is not set');
}
}
}, function (err) {
if (typeof myInAppBrowser.onError === 'function') {
myInAppBrowser.onError(err);
return;
}
console.warn('System.inAppBrowser error callback not handled', err);
}, 'System', 'in-app-browser', [url, title, !!showButtons, disableCache]);
return myInAppBrowser;
},
setUiTheme: function (systemBarColor, theme, onSuccess, onFail) {
cordova.exec(onSuccess, onFail, 'System', 'set-ui-theme', [systemBarColor, theme]);
const color = systemBarColor.toLowerCase();

if (color === '#ffffff' || color === '#ffffffff') {
systemBarColor = '#fffffe';
}

cordova.exec((out) => {
window.statusbar.setBackgroundColor(systemBarColor);

if (typeof onSuccess === "function") {
onSuccess(out);
}

}, onFail, 'System', 'set-ui-theme', [systemBarColor, theme]);
},
setIntentHandler: function (handler, onerror) {
cordova.exec(handler, onerror, 'System', 'set-intent-handler', []);
Expand Down