Skip to content

Commit 29bd2fb

Browse files
fix: systembar colors (#1976)
* fix: system bar colors * feat: improvements * fix: white themes not working * fix: error
1 parent 2738169 commit 29bd2fb

File tree

2 files changed

+64
-83
lines changed

2 files changed

+64
-83
lines changed

src/plugins/system/android/com/foxdebug/system/System.java

Lines changed: 11 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1686,53 +1686,21 @@ private void removeShortcut(String id, CallbackContext callback) {
16861686
}
16871687

16881688
private void setUiTheme(
1689-
final String systemBarColor,
1690-
final JSONObject scheme,
1691-
final CallbackContext callback
1689+
final String systemBarColor,
1690+
final JSONObject scheme,
1691+
final CallbackContext callback
16921692
) {
1693-
this.systemBarColor = Color.parseColor(systemBarColor);
1694-
this.theme = new Theme(scheme);
1695-
1696-
final Window window = activity.getWindow();
1697-
// Method and constants not available on all SDKs but we want to be able to compile this code with any SDK
1698-
window.clearFlags(0x04000000); // SDK 19: WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
1699-
window.addFlags(0x80000000); // SDK 21: WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
17001693
try {
1701-
// Using reflection makes sure any 5.0+ device will work without having to compile with SDK level 21
1702-
1703-
window
1704-
.getClass()
1705-
.getMethod("setNavigationBarColor", int.class)
1706-
.invoke(window, this.systemBarColor);
1694+
this.systemBarColor = Color.parseColor(systemBarColor);
1695+
this.theme = new Theme(scheme);
1696+
1697+
preferences.set("BackgroundColor", this.systemBarColor);
17071698

1708-
window
1709-
.getClass()
1710-
.getMethod("setStatusBarColor", int.class)
1711-
.invoke(window, this.systemBarColor);
1712-
1713-
window.getDecorView().setBackgroundColor(this.systemBarColor);
1699+
webView.getPluginManager().postMessage("updateSystemBars", null);
17141700

1715-
if (Build.VERSION.SDK_INT < 30) {
1716-
setStatusBarStyle(window);
1717-
setNavigationBarStyle(window);
1718-
} else {
1719-
String themeType = theme.getType();
1720-
WindowInsetsController controller = window.getInsetsController();
1721-
int appearance =
1722-
WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS |
1723-
WindowInsetsController.APPEARANCE_LIGHT_NAVIGATION_BARS;
1724-
1725-
if (themeType.equals("light")) {
1726-
controller.setSystemBarsAppearance(appearance, appearance);
1727-
} else {
1728-
controller.setSystemBarsAppearance(0, appearance);
1729-
}
1730-
}
1731-
callback.success("OK");
1732-
} catch (IllegalArgumentException error) {
1733-
callback.error(error.toString());
1734-
} catch (Exception error) {
1735-
callback.error(error.toString());
1701+
callback.success();
1702+
} catch (IllegalArgumentException e) {
1703+
callback.error("Invalid color: " + systemBarColor);
17361704
}
17371705
}
17381706

src/plugins/system/www/plugin.js

Lines changed: 53 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,19 @@ module.exports = {
3333
cordova.exec(success, error, 'System', 'getNativeLibraryPath', []);
3434
},
3535

36-
getFilesDir: function (success, error) {
37-
cordova.exec(success, error, 'System', 'getFilesDir', []);
38-
},
39-
getRewardStatus: function (success, error) {
40-
cordova.exec(success, error, 'System', 'getRewardStatus', []);
41-
},
42-
redeemReward: function (offerId, success, error) {
43-
cordova.exec(success, error, 'System', 'redeemReward', [offerId]);
44-
},
45-
46-
getParentPath: function (path, success, error) {
47-
cordova.exec(success, error, 'System', 'getParentPath', [path]);
48-
},
36+
getFilesDir: function (success, error) {
37+
cordova.exec(success, error, 'System', 'getFilesDir', []);
38+
},
39+
getRewardStatus: function (success, error) {
40+
cordova.exec(success, error, 'System', 'getRewardStatus', []);
41+
},
42+
redeemReward: function (offerId, success, error) {
43+
cordova.exec(success, error, 'System', 'redeemReward', [offerId]);
44+
},
45+
46+
getParentPath: function (path, success, error) {
47+
cordova.exec(success, error, 'System', 'getParentPath', [path]);
48+
},
4949

5050
listChildren: function (path, success, error) {
5151
cordova.exec(success, error, 'System', 'listChildren', [path]);
@@ -135,36 +135,49 @@ module.exports = {
135135
onError: null,
136136
};
137137

138-
cordova.exec(function (data) {
139-
if (typeof data !== 'string') {
140-
console.warn('System.inAppBrowser: invalid callback payload', data);
141-
return;
142-
}
143-
var separatorIndex = data.indexOf(':');
144-
if (separatorIndex < 0) {
145-
console.warn('System.inAppBrowser: malformed callback payload', data);
146-
return;
147-
}
148-
var dataTag = data.slice(0, separatorIndex);
149-
var dataUrl = data.slice(separatorIndex + 1);
150-
if (dataTag === 'onOpenExternalBrowser') {
151-
if (typeof myInAppBrowser.onOpenExternalBrowser === 'function') {
152-
myInAppBrowser.onOpenExternalBrowser(dataUrl);
153-
} else {
154-
console.warn('System.inAppBrowser: onOpenExternalBrowser handler is not set');
155-
}
156-
}
157-
}, function (err) {
158-
if (typeof myInAppBrowser.onError === 'function') {
159-
myInAppBrowser.onError(err);
160-
return;
161-
}
162-
console.warn('System.inAppBrowser error callback not handled', err);
163-
}, 'System', 'in-app-browser', [url, title, !!showButtons, disableCache]);
138+
cordova.exec(function (data) {
139+
if (typeof data !== 'string') {
140+
console.warn('System.inAppBrowser: invalid callback payload', data);
141+
return;
142+
}
143+
var separatorIndex = data.indexOf(':');
144+
if (separatorIndex < 0) {
145+
console.warn('System.inAppBrowser: malformed callback payload', data);
146+
return;
147+
}
148+
var dataTag = data.slice(0, separatorIndex);
149+
var dataUrl = data.slice(separatorIndex + 1);
150+
if (dataTag === 'onOpenExternalBrowser') {
151+
if (typeof myInAppBrowser.onOpenExternalBrowser === 'function') {
152+
myInAppBrowser.onOpenExternalBrowser(dataUrl);
153+
} else {
154+
console.warn('System.inAppBrowser: onOpenExternalBrowser handler is not set');
155+
}
156+
}
157+
}, function (err) {
158+
if (typeof myInAppBrowser.onError === 'function') {
159+
myInAppBrowser.onError(err);
160+
return;
161+
}
162+
console.warn('System.inAppBrowser error callback not handled', err);
163+
}, 'System', 'in-app-browser', [url, title, !!showButtons, disableCache]);
164164
return myInAppBrowser;
165165
},
166166
setUiTheme: function (systemBarColor, theme, onSuccess, onFail) {
167-
cordova.exec(onSuccess, onFail, 'System', 'set-ui-theme', [systemBarColor, theme]);
167+
const color = systemBarColor.toLowerCase();
168+
169+
if (color === '#ffffff' || color === '#ffffffff') {
170+
systemBarColor = '#fffffe';
171+
}
172+
173+
cordova.exec((out) => {
174+
window.statusbar.setBackgroundColor(systemBarColor);
175+
176+
if (typeof onSuccess === "function") {
177+
onSuccess(out);
178+
}
179+
180+
}, onFail, 'System', 'set-ui-theme', [systemBarColor, theme]);
168181
},
169182
setIntentHandler: function (handler, onerror) {
170183
cordova.exec(handler, onerror, 'System', 'set-intent-handler', []);

0 commit comments

Comments
 (0)