Skip to content

Commit 7a189f2

Browse files
Ajit KumarAjit Kumar
authored andcommitted
fix(status and navigation bar text color in light theme)
1 parent f620bad commit 7a189f2

File tree

5 files changed

+108
-87
lines changed

5 files changed

+108
-87
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
- New
66
- [x] **Ace editor** | 937
77
- Updated Ace editor to version 1.32.7
8+
- Fixes
9+
- [x] **UI** | 942
10+
- Fixed status and navigation text color not visible in light theme.
811

912
- Fixes
1013
- [x] **Text selection** | 937

config.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version='1.0' encoding='utf-8' ?>
2-
<widget id="com.foxdebug.acode" android-versionCode="941" version="1.10.0"
2+
<widget id="com.foxdebug.acode" android-versionCode="942" version="1.10.0"
33
xmlns="http://www.w3.org/ns/widgets"
44
xmlns:android="http://schemas.android.com/apk/res/android"
55
xmlns:cdv="http://cordova.apache.org/ns/1.0">

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
"cordova-plugin-iap": {},
3131
"cordova-plugin-ftp": {},
3232
"cordova-plugin-sdcard": {},
33-
"cordova-plugin-system": {},
34-
"cordova-plugin-browser": {}
33+
"cordova-plugin-browser": {},
34+
"cordova-plugin-system": {}
3535
},
3636
"platforms": [
3737
"android"

src/plugins/browser/android/com/foxdebug/browser/BrowserActivity.java

Lines changed: 48 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import android.util.Log;
99
import android.view.View;
1010
import android.view.Window;
11+
import android.view.WindowInsetsController;
1112
import android.webkit.WebChromeClient;
1213
import com.foxdebug.system.Ui;
1314
import org.json.JSONObject;
@@ -51,56 +52,64 @@ public void onBackPressed() {
5152
private void setSystemTheme(int systemBarColor) {
5253
try {
5354
Ui.Icons.setSize(Ui.dpToPixels(this, 18));
54-
if (Build.VERSION.SDK_INT >= 21) {
55-
final Window window = getWindow();
56-
// Method and constants not available on all SDKs but we want to be able to compile this code with any SDK
57-
window.clearFlags(0x04000000); // SDK 19: WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
58-
window.addFlags(0x80000000); // SDK 21: WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
59-
try {
60-
// Using reflection makes sure any 5.0+ device will work without having to compile with SDK level 21
61-
62-
window
63-
.getClass()
64-
.getMethod("setNavigationBarColor", int.class)
65-
.invoke(window, systemBarColor);
66-
67-
window
68-
.getClass()
69-
.getMethod("setStatusBarColor", int.class)
70-
.invoke(window, systemBarColor);
71-
55+
final Window window = getWindow();
56+
// Method and constants not available on all SDKs but we want to be able to compile this code with any SDK
57+
window.clearFlags(0x04000000); // SDK 19: WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
58+
window.addFlags(0x80000000); // SDK 21: WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
59+
try {
60+
// Using reflection makes sure any 5.0+ device will work without having to compile with SDK level 21
61+
62+
window
63+
.getClass()
64+
.getMethod("setNavigationBarColor", int.class)
65+
.invoke(window, systemBarColor);
66+
67+
window
68+
.getClass()
69+
.getMethod("setStatusBarColor", int.class)
70+
.invoke(window, systemBarColor);
71+
72+
if (Build.VERSION.SDK_INT < 30) {
7273
setStatusBarStyle(window);
7374
setNavigationBarStyle(window);
74-
} catch (IllegalArgumentException ignore) {} catch (Exception ignore) {}
75-
}
75+
} else {
76+
String themeType = theme.getType();
77+
WindowInsetsController controller = window.getInsetsController();
78+
int appearance =
79+
WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS |
80+
WindowInsetsController.APPEARANCE_LIGHT_NAVIGATION_BARS;
81+
82+
if (themeType.equals("light")) {
83+
controller.setSystemBarsAppearance(appearance, appearance);
84+
} else {
85+
controller.setSystemBarsAppearance(0, appearance);
86+
}
87+
}
88+
} catch (IllegalArgumentException ignore) {} catch (Exception ignore) {}
7689
} catch (Exception e) {}
7790
}
7891

7992
private void setStatusBarStyle(final Window window) {
80-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
81-
View decorView = window.getDecorView();
82-
int uiOptions = decorView.getSystemUiVisibility();
83-
String themeType = theme.getType();
84-
85-
if (themeType.equals("light")) {
86-
decorView.setSystemUiVisibility(
87-
uiOptions | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
88-
);
89-
return;
90-
}
93+
View decorView = window.getDecorView();
94+
int uiOptions = decorView.getSystemUiVisibility();
95+
String themeType = theme.getType();
96+
97+
if (themeType.equals("light")) {
98+
decorView.setSystemUiVisibility(
99+
uiOptions | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
100+
);
101+
return;
91102
}
92103
}
93104

94105
private void setNavigationBarStyle(final Window window) {
95-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
96-
View decorView = window.getDecorView();
97-
int uiOptions = decorView.getSystemUiVisibility();
98-
String themeType = theme.getType();
106+
View decorView = window.getDecorView();
107+
int uiOptions = decorView.getSystemUiVisibility();
108+
String themeType = theme.getType();
99109

100-
if (themeType.equals("light")) {
101-
decorView.setSystemUiVisibility(uiOptions | 0x80000000 | 0x00000010);
102-
return;
103-
}
110+
if (themeType.equals("light")) {
111+
decorView.setSystemUiVisibility(uiOptions | 0x80000000 | 0x00000010);
112+
return;
104113
}
105114
}
106115

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

Lines changed: 54 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import android.util.Base64;
2323
import android.view.View;
2424
import android.view.Window;
25+
import android.view.WindowInsetsController;
2526
import android.view.inputmethod.InputMethodManager;
2627
import android.webkit.WebView;
2728
import androidx.core.content.FileProvider;
@@ -643,74 +644,82 @@ private void removeShortcut(String id, CallbackContext callback) {
643644

644645
private void setUiTheme(
645646
final String systemBarColor,
646-
final JSONObject theme,
647+
final JSONObject schema,
647648
final CallbackContext callback
648649
) {
649650
this.systemBarColor = Color.parseColor(systemBarColor);
650-
this.theme = new Theme(theme);
651+
this.theme = new Theme(schema);
651652

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

660-
window
661-
.getClass()
662-
.getMethod("setNavigationBarColor", int.class)
663-
.invoke(window, this.systemBarColor);
660+
window
661+
.getClass()
662+
.getMethod("setNavigationBarColor", int.class)
663+
.invoke(window, this.systemBarColor);
664664

665-
window
666-
.getClass()
667-
.getMethod("setStatusBarColor", int.class)
668-
.invoke(window, this.systemBarColor);
665+
window
666+
.getClass()
667+
.getMethod("setStatusBarColor", int.class)
668+
.invoke(window, this.systemBarColor);
669669

670+
if (Build.VERSION.SDK_INT < 30) {
670671
setStatusBarStyle(window);
671672
setNavigationBarStyle(window);
672-
callback.success("OK");
673-
} catch (IllegalArgumentException error) {
674-
callback.error(error.toString());
675-
} catch (Exception error) {
676-
callback.error(error.toString());
673+
} else {
674+
String themeType = theme.getType();
675+
WindowInsetsController controller = window.getInsetsController();
676+
int appearance =
677+
WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS |
678+
WindowInsetsController.APPEARANCE_LIGHT_NAVIGATION_BARS;
679+
680+
if (themeType.equals("light")) {
681+
controller.setSystemBarsAppearance(appearance, appearance);
682+
} else {
683+
controller.setSystemBarsAppearance(0, appearance);
684+
}
677685
}
686+
callback.success("OK");
687+
} catch (IllegalArgumentException error) {
688+
callback.error(error.toString());
689+
} catch (Exception error) {
690+
callback.error(error.toString());
678691
}
679692
}
680693

681694
private void setStatusBarStyle(final Window window) {
682-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
683-
View decorView = window.getDecorView();
684-
int uiOptions = decorView.getSystemUiVisibility();
685-
String themeType = theme.getType();
686-
687-
if (themeType.equals("light")) {
688-
decorView.setSystemUiVisibility(
689-
uiOptions | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
690-
);
691-
return;
692-
}
695+
View decorView = window.getDecorView();
696+
int uiOptions = decorView.getSystemUiVisibility();
697+
String themeType = theme.getType();
698+
699+
if (themeType.equals("light")) {
693700
decorView.setSystemUiVisibility(
694-
uiOptions & ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
701+
uiOptions | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
695702
);
703+
return;
696704
}
705+
decorView.setSystemUiVisibility(
706+
uiOptions & ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
707+
);
697708
}
698709

699710
private void setNavigationBarStyle(final Window window) {
700-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
701-
View decorView = window.getDecorView();
702-
int uiOptions = decorView.getSystemUiVisibility();
703-
String themeType = theme.getType();
711+
View decorView = window.getDecorView();
712+
int uiOptions = decorView.getSystemUiVisibility();
713+
String themeType = theme.getType();
704714

705-
// 0x80000000 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS
706-
// 0x00000010 SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR
715+
// 0x80000000 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS
716+
// 0x00000010 SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR
707717

708-
if (themeType.equals("light")) {
709-
decorView.setSystemUiVisibility(uiOptions | 0x80000000 | 0x00000010);
710-
return;
711-
}
712-
decorView.setSystemUiVisibility(uiOptions | 0x80000000 & ~0x00000010);
718+
if (themeType.equals("light")) {
719+
decorView.setSystemUiVisibility(uiOptions | 0x80000000 | 0x00000010);
720+
return;
713721
}
722+
decorView.setSystemUiVisibility(uiOptions | 0x80000000 & ~0x00000010);
714723
}
715724

716725
private void getCordovaIntent(CallbackContext callback) {

0 commit comments

Comments
 (0)