|
1 | 1 | package com.foxdebug.system; |
2 | 2 |
|
| 3 | +import static android.os.Build.VERSION.SDK_INT; |
3 | 4 |
|
4 | 5 | import java.nio.file.Files; |
5 | 6 | import java.nio.file.Paths; |
|
57 | 58 | import java.nio.file.Path; |
58 | 59 | import android.content.Context; |
59 | 60 | import android.net.Uri; |
| 61 | +import android.util.Log; |
60 | 62 |
|
61 | 63 | import java.io.File; |
62 | 64 | import java.io.FileInputStream; |
@@ -1038,11 +1040,11 @@ private void removeShortcut(String id, CallbackContext callback) { |
1038 | 1040 |
|
1039 | 1041 | private void setUiTheme( |
1040 | 1042 | final String systemBarColor, |
1041 | | - final JSONObject schema, |
| 1043 | + final JSONObject scheme, |
1042 | 1044 | final CallbackContext callback |
1043 | 1045 | ) { |
1044 | 1046 | this.systemBarColor = Color.parseColor(systemBarColor); |
1045 | | - this.theme = new Theme(schema); |
| 1047 | + this.theme = new Theme(scheme); |
1046 | 1048 |
|
1047 | 1049 | final Window window = activity.getWindow(); |
1048 | 1050 | // Method and constants not available on all SDKs but we want to be able to compile this code with any SDK |
@@ -1088,34 +1090,73 @@ private void setUiTheme( |
1088 | 1090 | } |
1089 | 1091 |
|
1090 | 1092 | private void setStatusBarStyle(final Window window) { |
1091 | | - View decorView = window.getDecorView(); |
1092 | | - int uiOptions = decorView.getSystemUiVisibility(); |
1093 | 1093 | String themeType = theme.getType(); |
| 1094 | + View decorView = window.getDecorView(); |
| 1095 | + int uiOptions; |
| 1096 | + int lightStatusBar; |
| 1097 | + |
| 1098 | + if (SDK_INT <= 30) { |
| 1099 | + uiOptions = getDeprecatedSystemUiVisibility(decorView); |
| 1100 | + lightStatusBar = deprecatedFlagUiLightStatusBar(); |
| 1101 | + |
| 1102 | + if (themeType.equals("light")) { |
| 1103 | + setDeprecatedSystemUiVisibility(decorView, uiOptions | lightStatusBar); |
| 1104 | + return; |
| 1105 | + } |
| 1106 | + setDeprecatedSystemUiVisibility(decorView, uiOptions & ~lightStatusBar); |
| 1107 | + return; |
| 1108 | + } |
| 1109 | + |
| 1110 | + uiOptions = Objects.requireNonNull(decorView.getWindowInsetsController()).getSystemBarsAppearance(); |
| 1111 | + lightStatusBar = WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS; |
1094 | 1112 |
|
1095 | 1113 | if (themeType.equals("light")) { |
1096 | | - decorView.setSystemUiVisibility( |
1097 | | - uiOptions | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR |
1098 | | - ); |
| 1114 | + decorView.getWindowInsetsController().setSystemBarsAppearance(uiOptions | lightStatusBar, lightStatusBar); |
1099 | 1115 | return; |
1100 | 1116 | } |
1101 | | - decorView.setSystemUiVisibility( |
1102 | | - uiOptions & ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR |
1103 | | - ); |
| 1117 | + |
| 1118 | + decorView.getWindowInsetsController().setSystemBarsAppearance(uiOptions & ~lightStatusBar, lightStatusBar); |
1104 | 1119 | } |
1105 | 1120 |
|
1106 | 1121 | private void setNavigationBarStyle(final Window window) { |
1107 | | - View decorView = window.getDecorView(); |
1108 | | - int uiOptions = decorView.getSystemUiVisibility(); |
1109 | 1122 | String themeType = theme.getType(); |
| 1123 | + View decorView = window.getDecorView(); |
| 1124 | + int uiOptions; |
1110 | 1125 |
|
1111 | | - // 0x80000000 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS |
1112 | | - // 0x00000010 SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR |
| 1126 | + if (SDK_INT <= 30) { |
| 1127 | + uiOptions = getDeprecatedSystemUiVisibility(decorView); |
| 1128 | + // 0x80000000 FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS |
| 1129 | + // 0x00000010 SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR |
| 1130 | + |
| 1131 | + if (themeType.equals("light")) { |
| 1132 | + setDeprecatedSystemUiVisibility(decorView, uiOptions | 0x80000000 | 0x00000010); |
| 1133 | + return; |
| 1134 | + } |
| 1135 | + setDeprecatedSystemUiVisibility(decorView, uiOptions | (0x80000000 & ~0x00000010)); |
| 1136 | + return; |
| 1137 | + } |
| 1138 | + |
| 1139 | + uiOptions = Objects.requireNonNull(decorView.getWindowInsetsController()).getSystemBarsAppearance(); |
| 1140 | + int lightNavigationBar = WindowInsetsController.APPEARANCE_LIGHT_NAVIGATION_BARS; |
1113 | 1141 |
|
1114 | 1142 | if (themeType.equals("light")) { |
1115 | | - decorView.setSystemUiVisibility(uiOptions | 0x80000000 | 0x00000010); |
| 1143 | + decorView.getWindowInsetsController().setSystemBarsAppearance(uiOptions | lightNavigationBar, lightNavigationBar); |
1116 | 1144 | return; |
1117 | 1145 | } |
1118 | | - decorView.setSystemUiVisibility(uiOptions | (0x80000000 & ~0x00000010)); |
| 1146 | + |
| 1147 | + decorView.getWindowInsetsController().setSystemBarsAppearance(uiOptions & ~lightNavigationBar, lightNavigationBar); |
| 1148 | + } |
| 1149 | + |
| 1150 | + private int deprecatedFlagUiLightStatusBar() { |
| 1151 | + return View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; |
| 1152 | + } |
| 1153 | + |
| 1154 | + private int getDeprecatedSystemUiVisibility(View decorView) { |
| 1155 | + return decorView.getSystemUiVisibility(); |
| 1156 | + } |
| 1157 | + |
| 1158 | + private void setDeprecatedSystemUiVisibility(View decorView, int visibility) { |
| 1159 | + decorView.setSystemUiVisibility(visibility); |
1119 | 1160 | } |
1120 | 1161 |
|
1121 | 1162 | private void getCordovaIntent(CallbackContext callback) { |
|
0 commit comments