|
20 | 20 | import android.os.Build; |
21 | 21 | import android.view.View; |
22 | 22 | import android.view.Window; |
| 23 | +import android.view.WindowInsetsControllerCompat; |
| 24 | +import android.view.WindowInsetsControllerCompat.APPEARANCE_LIGHT_NAVIGATION_BARS; |
| 25 | +import android.view.WindowInsetsControllerCompat.APPEARANCE_LIGHT_STATUS_BARS; |
23 | 26 | import androidx.activity.OnBackPressedCallback; |
24 | 27 | import androidx.fragment.app.FragmentActivity; |
25 | 28 | import io.flutter.embedding.engine.systemchannels.PlatformChannel; |
@@ -190,6 +193,97 @@ public void setNavigationBarDividerColor() { |
190 | 193 | } |
191 | 194 | } |
192 | 195 |
|
| 196 | + @Config(sdk = 30) |
| 197 | + @Test |
| 198 | + public void setNavigationBarIconBrightness() { |
| 199 | + View fakeDecorView = mock(View.class); |
| 200 | + WindowInsetsController fakeWindowInsetsController = mock(WindowInsetsController.class); |
| 201 | + Window fakeWindow = mock(Window.class); |
| 202 | + when(fakeWindow.getDecorView()).thenReturn(fakeDecorView); |
| 203 | + when(fakeWindow.getInsetsController()).thenReturn(fakeWindowInsetsController); |
| 204 | + Activity fakeActivity = mock(Activity.class); |
| 205 | + when(fakeActivity.getWindow()).thenReturn(fakeWindow); |
| 206 | + PlatformChannel fakePlatformChannel = mock(PlatformChannel.class); |
| 207 | + PlatformPlugin platformPlugin = new PlatformPlugin(fakeActivity, fakePlatformChannel); |
| 208 | + |
| 209 | + if (Build.VERSION.SDK_INT >= 30) { |
| 210 | + SystemChromeStyle style = |
| 211 | + new SystemChromeStyle( |
| 212 | + null, // statusBarColor |
| 213 | + Brightness.LIGHT, // statusBarIconBrightness |
| 214 | + null, // systemStatusBarContrastEnforced |
| 215 | + null, // systemNavigationBarColor |
| 216 | + null, // systemNavigationBarIconBrightness |
| 217 | + null, // systemNavigationBarDividerColor |
| 218 | + null); // systemNavigationBarContrastEnforced |
| 219 | + |
| 220 | + platformPlugin.mPlatformMessageHandler.setSystemUiOverlayStyle(style); |
| 221 | + |
| 222 | + verify(fakeWindowInsetsController).setSystemBarsAppearance( |
| 223 | + 0, APPEARANCE_LIGHT_NAVIGATION_BARS); |
| 224 | + |
| 225 | + SystemChromeStyle style = |
| 226 | + new SystemChromeStyle( |
| 227 | + null, // statusBarColor |
| 228 | + Brightness.DARK, // statusBarIconBrightness |
| 229 | + null, // systemStatusBarContrastEnforced |
| 230 | + null, // systemNavigationBarColor |
| 231 | + null, // systemNavigationBarIconBrightness |
| 232 | + null, // systemNavigationBarDividerColor |
| 233 | + null); // systemNavigationBarContrastEnforced |
| 234 | + |
| 235 | + platformPlugin.mPlatformMessageHandler.setSystemUiOverlayStyle(style); |
| 236 | + |
| 237 | + verify(fakeWindowInsetsController).setSystemBarsAppearance( |
| 238 | + APPEARANCE_LIGHT_NAVIGATION_BARS, APPEARANCE_LIGHT_NAVIGATION_BARS); |
| 239 | + } |
| 240 | + } |
| 241 | + |
| 242 | + @Config(sdk = 30) |
| 243 | + @Test |
| 244 | + public void setStatusBarIconBrightness() { |
| 245 | + View fakeDecorView = mock(View.class); |
| 246 | + WindowInsetsController fakeWindowInsetsController = mock(WindowInsetsController.class); |
| 247 | + Window fakeWindow = mock(Window.class); |
| 248 | + when(fakeWindow.getDecorView()).thenReturn(fakeDecorView); |
| 249 | + when(fakeWindow.getInsetsController()).thenReturn(fakeWindowInsetsController); |
| 250 | + Activity fakeActivity = mock(Activity.class); |
| 251 | + when(fakeActivity.getWindow()).thenReturn(fakeWindow); |
| 252 | + PlatformChannel fakePlatformChannel = mock(PlatformChannel.class); |
| 253 | + PlatformPlugin platformPlugin = new PlatformPlugin(fakeActivity, fakePlatformChannel); |
| 254 | + |
| 255 | + if (Build.VERSION.SDK_INT >= 30) { |
| 256 | + SystemChromeStyle style = |
| 257 | + new SystemChromeStyle( |
| 258 | + null, // statusBarColor |
| 259 | + null, // statusBarIconBrightness |
| 260 | + null, // systemStatusBarContrastEnforced |
| 261 | + null, // systemNavigationBarColor |
| 262 | + Brightness.LIGHT, // systemNavigationBarIconBrightness |
| 263 | + null, // systemNavigationBarDividerColor |
| 264 | + null); // systemNavigationBarContrastEnforced |
| 265 | + |
| 266 | + platformPlugin.mPlatformMessageHandler.setSystemUiOverlayStyle(style); |
| 267 | + |
| 268 | + verify(fakeWindowInsetsController).setSystemBarsAppearance(0, APPEARANCE_LIGHT_STATUS_BARS); |
| 269 | + |
| 270 | + SystemChromeStyle style = |
| 271 | + new SystemChromeStyle( |
| 272 | + null, // statusBarColor |
| 273 | + null, // statusBarIconBrightness |
| 274 | + null, // systemStatusBarContrastEnforced |
| 275 | + null, // systemNavigationBarColor |
| 276 | + Brightness.DARK, // systemNavigationBarIconBrightness |
| 277 | + null, // systemNavigationBarDividerColor |
| 278 | + null); // systemNavigationBarContrastEnforced |
| 279 | + |
| 280 | + platformPlugin.mPlatformMessageHandler.setSystemUiOverlayStyle(style); |
| 281 | + |
| 282 | + verify(fakeWindowInsetsController).setSystemBarsAppearance( |
| 283 | + APPEARANCE_LIGHT_STATUS_BARS, APPEARANCE_LIGHT_STATUS_BARS); |
| 284 | + } |
| 285 | + } |
| 286 | + |
193 | 287 | @Config(sdk = 29) |
194 | 288 | @Test |
195 | 289 | public void setSystemUiMode() { |
|
0 commit comments