|
1 | 1 | package io.flutter.plugin.platform;
|
2 | 2 |
|
| 3 | +import static android.view.WindowInsetsController.APPEARANCE_LIGHT_NAVIGATION_BARS; |
| 4 | +import static android.view.WindowInsetsController.APPEARANCE_LIGHT_STATUS_BARS; |
3 | 5 | import static org.junit.Assert.assertFalse;
|
4 | 6 | import static org.junit.Assert.assertNotNull;
|
5 | 7 | import static org.junit.Assert.assertNull;
|
|
20 | 22 | import android.os.Build;
|
21 | 23 | import android.view.View;
|
22 | 24 | import android.view.Window;
|
| 25 | +import android.view.WindowInsetsController; |
23 | 26 | import androidx.activity.OnBackPressedCallback;
|
24 | 27 | import androidx.fragment.app.FragmentActivity;
|
25 | 28 | import io.flutter.embedding.engine.systemchannels.PlatformChannel;
|
@@ -216,6 +219,98 @@ public void setNavigationBarDividerColor() {
|
216 | 219 | }
|
217 | 220 | }
|
218 | 221 |
|
| 222 | + @Config(sdk = 30) |
| 223 | + @Test |
| 224 | + public void setNavigationBarIconBrightness() { |
| 225 | + View fakeDecorView = mock(View.class); |
| 226 | + WindowInsetsController fakeWindowInsetsController = mock(WindowInsetsController.class); |
| 227 | + Window fakeWindow = mock(Window.class); |
| 228 | + when(fakeWindow.getDecorView()).thenReturn(fakeDecorView); |
| 229 | + when(fakeWindow.getInsetsController()).thenReturn(fakeWindowInsetsController); |
| 230 | + Activity fakeActivity = mock(Activity.class); |
| 231 | + when(fakeActivity.getWindow()).thenReturn(fakeWindow); |
| 232 | + PlatformChannel fakePlatformChannel = mock(PlatformChannel.class); |
| 233 | + PlatformPlugin platformPlugin = new PlatformPlugin(fakeActivity, fakePlatformChannel); |
| 234 | + |
| 235 | + if (Build.VERSION.SDK_INT >= 30) { |
| 236 | + SystemChromeStyle style = |
| 237 | + new SystemChromeStyle( |
| 238 | + null, // statusBarColor |
| 239 | + Brightness.LIGHT, // statusBarIconBrightness |
| 240 | + null, // systemStatusBarContrastEnforced |
| 241 | + null, // systemNavigationBarColor |
| 242 | + null, // systemNavigationBarIconBrightness |
| 243 | + null, // systemNavigationBarDividerColor |
| 244 | + null); // systemNavigationBarContrastEnforced |
| 245 | + |
| 246 | + platformPlugin.mPlatformMessageHandler.setSystemUiOverlayStyle(style); |
| 247 | + |
| 248 | + verify(fakeWindowInsetsController) |
| 249 | + .setSystemBarsAppearance(0, APPEARANCE_LIGHT_NAVIGATION_BARS); |
| 250 | + |
| 251 | + style = |
| 252 | + new SystemChromeStyle( |
| 253 | + null, // statusBarColor |
| 254 | + Brightness.DARK, // statusBarIconBrightness |
| 255 | + null, // systemStatusBarContrastEnforced |
| 256 | + null, // systemNavigationBarColor |
| 257 | + null, // systemNavigationBarIconBrightness |
| 258 | + null, // systemNavigationBarDividerColor |
| 259 | + null); // systemNavigationBarContrastEnforced |
| 260 | + |
| 261 | + platformPlugin.mPlatformMessageHandler.setSystemUiOverlayStyle(style); |
| 262 | + |
| 263 | + verify(fakeWindowInsetsController) |
| 264 | + .setSystemBarsAppearance( |
| 265 | + APPEARANCE_LIGHT_NAVIGATION_BARS, APPEARANCE_LIGHT_NAVIGATION_BARS); |
| 266 | + } |
| 267 | + } |
| 268 | + |
| 269 | + @Config(sdk = 30) |
| 270 | + @Test |
| 271 | + public void setStatusBarIconBrightness() { |
| 272 | + View fakeDecorView = mock(View.class); |
| 273 | + WindowInsetsController fakeWindowInsetsController = mock(WindowInsetsController.class); |
| 274 | + Window fakeWindow = mock(Window.class); |
| 275 | + when(fakeWindow.getDecorView()).thenReturn(fakeDecorView); |
| 276 | + when(fakeWindow.getInsetsController()).thenReturn(fakeWindowInsetsController); |
| 277 | + Activity fakeActivity = mock(Activity.class); |
| 278 | + when(fakeActivity.getWindow()).thenReturn(fakeWindow); |
| 279 | + PlatformChannel fakePlatformChannel = mock(PlatformChannel.class); |
| 280 | + PlatformPlugin platformPlugin = new PlatformPlugin(fakeActivity, fakePlatformChannel); |
| 281 | + |
| 282 | + if (Build.VERSION.SDK_INT >= 30) { |
| 283 | + SystemChromeStyle style = |
| 284 | + new SystemChromeStyle( |
| 285 | + null, // statusBarColor |
| 286 | + null, // statusBarIconBrightness |
| 287 | + null, // systemStatusBarContrastEnforced |
| 288 | + null, // systemNavigationBarColor |
| 289 | + Brightness.LIGHT, // systemNavigationBarIconBrightness |
| 290 | + null, // systemNavigationBarDividerColor |
| 291 | + null); // systemNavigationBarContrastEnforced |
| 292 | + |
| 293 | + platformPlugin.mPlatformMessageHandler.setSystemUiOverlayStyle(style); |
| 294 | + |
| 295 | + verify(fakeWindowInsetsController).setSystemBarsAppearance(0, APPEARANCE_LIGHT_STATUS_BARS); |
| 296 | + |
| 297 | + style = |
| 298 | + new SystemChromeStyle( |
| 299 | + null, // statusBarColor |
| 300 | + null, // statusBarIconBrightness |
| 301 | + null, // systemStatusBarContrastEnforced |
| 302 | + null, // systemNavigationBarColor |
| 303 | + Brightness.DARK, // systemNavigationBarIconBrightness |
| 304 | + null, // systemNavigationBarDividerColor |
| 305 | + null); // systemNavigationBarContrastEnforced |
| 306 | + |
| 307 | + platformPlugin.mPlatformMessageHandler.setSystemUiOverlayStyle(style); |
| 308 | + |
| 309 | + verify(fakeWindowInsetsController) |
| 310 | + .setSystemBarsAppearance(APPEARANCE_LIGHT_STATUS_BARS, APPEARANCE_LIGHT_STATUS_BARS); |
| 311 | + } |
| 312 | + } |
| 313 | + |
219 | 314 | @Config(sdk = 29)
|
220 | 315 | @Test
|
221 | 316 | public void setSystemUiMode() {
|
|
0 commit comments