From dbd45ee3045659e791340a84af48dbc47cd0295b Mon Sep 17 00:00:00 2001 From: camsim99 Date: Tue, 15 Mar 2022 15:21:17 -0700 Subject: [PATCH 1/8] Part one of fixing brightness --- .../plugin/platform/PlatformPlugin.java | 53 ++++++++++++++++--- tools/androidx/files.json | 4 +- 2 files changed, 47 insertions(+), 10 deletions(-) diff --git a/shell/platform/android/io/flutter/plugin/platform/PlatformPlugin.java b/shell/platform/android/io/flutter/plugin/platform/PlatformPlugin.java index a1d38ba0720db..92eb3cb7f4465 100644 --- a/shell/platform/android/io/flutter/plugin/platform/PlatformPlugin.java +++ b/shell/platform/android/io/flutter/plugin/platform/PlatformPlugin.java @@ -296,11 +296,13 @@ private void setSystemChromeEnabledSystemUIMode(PlatformChannel.SystemUiMode sys // SDK 29 and up will apply a translucent body scrim behind 2/3 button navigation bars // to ensure contrast with buttons on the nav and status bars, unless the contrast is not // enforced in the overlay styling. + System.out.println("Edge to edge mode being applied"); enabledOverlays = View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN; } else { + System.out.println("No system ui modes found to apply, returning"); // When none of the conditions are matched, return without updating the system UI overlays. return; } @@ -311,6 +313,7 @@ private void setSystemChromeEnabledSystemUIMode(PlatformChannel.SystemUiMode sys private void setSystemChromeEnabledSystemUIOverlays( List overlaysToShow) { + System.out.println("Applying overlays for some reason"); // Start by assuming we want to hide all system overlays (like an immersive // game). int enabledOverlays = @@ -353,8 +356,10 @@ private void setSystemChromeEnabledSystemUIOverlays( * PlatformPlugin}. */ public void updateSystemUiOverlays() { + System.out.println("Update being called"); activity.getWindow().getDecorView().setSystemUiVisibility(mEnabledOverlays); if (currentTheme != null) { + System.out.println("currentTheme being updated"); setSystemChromeSystemUIOverlayStyle(currentTheme); } } @@ -365,6 +370,7 @@ private void restoreSystemChromeSystemUIOverlays() { private void setSystemChromeSystemUIOverlayStyle( PlatformChannel.SystemChromeStyle systemChromeStyle) { + System.out.println("Call to update current theme made"); Window window = activity.getWindow(); View view = window.getDecorView(); WindowInsetsControllerCompat windowInsetsControllerCompat = @@ -377,23 +383,27 @@ private void setSystemChromeSystemUIOverlayStyle( // If transparent, SDK 29 and higher may apply a translucent scrim behind the bar to ensure // proper contrast. This can be overridden with // SystemChromeStyle.systemStatusBarContrastEnforced. + //TODO(camillesimon): Fix status bars if (Build.VERSION.SDK_INT >= 23) { if (systemChromeStyle.statusBarIconBrightness != null) { switch (systemChromeStyle.statusBarIconBrightness) { case DARK: // Dark status bar icon brightness. // Light status bar appearance. + System.out.println("Status bar icons set to dark"); windowInsetsControllerCompat.setAppearanceLightStatusBars(true); break; case LIGHT: // Light status bar icon brightness. // Dark status bar appearance. + System.out.println("Status bar icons set to light"); windowInsetsControllerCompat.setAppearanceLightStatusBars(false); break; } } if (systemChromeStyle.statusBarColor != null) { + System.out.println("Status bar color being set"); window.setStatusBarColor(systemChromeStyle.statusBarColor); } } @@ -401,6 +411,7 @@ private void setSystemChromeSystemUIOverlayStyle( // This overrides the translucent scrim that may be placed behind the bar on SDK 29+ to ensure // contrast is appropriate when using full screen layout modes like Edge to Edge. if (systemChromeStyle.systemStatusBarContrastEnforced != null && Build.VERSION.SDK_INT >= 29) { + System.out.println("Status bar contrast being enforced"); window.setStatusBarContrastEnforced(systemChromeStyle.systemStatusBarContrastEnforced); } @@ -411,32 +422,57 @@ private void setSystemChromeSystemUIOverlayStyle( // If transparent, SDK 29 and higher may apply a translucent scrim behind 2/3 button navigation // bars to ensure proper contrast. This can be overridden with // SystemChromeStyle.systemNavigationBarContrastEnforced. + + // You can't change the color of the navigation bar divider color until SDK 28. + if (systemChromeStyle.systemNavigationBarDividerColor != null && Build.VERSION.SDK_INT >= 28) { + System.out.println("Divider color being set"); + window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); + //TODO(camillesimon):https://developer.android.com/reference/android/view/WindowManager.LayoutParams#FLAG_TRANSLUCENT_NAVIGATION + window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); + window.setNavigationBarDividerColor(systemChromeStyle.systemNavigationBarDividerColor); + } + if (Build.VERSION.SDK_INT >= 26) { if (systemChromeStyle.systemNavigationBarIconBrightness != null) { switch (systemChromeStyle.systemNavigationBarIconBrightness) { case DARK: // Dark navigation bar icon brightness. // Light navigation bar appearance. - windowInsetsControllerCompat.setAppearanceLightNavigationBars(true); + System.out.println("Navigation icons set to dark"); + if (Build.VERSION.SDK_INT == 30) { + System.out.println("Made it to 30"); + // mEnabledOverlays = mEnabledOverlays &~ View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; + // view.setSystemUiVisibility(mEnabledOverlays); + windowInsetsControllerCompat.setAppearanceLightNavigationBars(true); + } else { + windowInsetsControllerCompat.setAppearanceLightNavigationBars(true); + } break; case LIGHT: // Light navigation bar icon brightness. // Dark navigation bar appearance. - windowInsetsControllerCompat.setAppearanceLightNavigationBars(false); + System.out.println("Navigation icons set to light"); + if (Build.VERSION.SDK_INT == 30) { + System.out.println("Made it to 30"); + // mEnabledOverlays = mEnabledOverlays | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; + // view.setSystemUiVisibility(mEnabledOverlays); + windowInsetsControllerCompat.setAppearanceLightNavigationBars(false); + } else { + windowInsetsControllerCompat.setAppearanceLightNavigationBars(false); + } + break; } } if (systemChromeStyle.systemNavigationBarColor != null) { + //TODO(camillesimon): Test clear flag fix for API 28. Seems to cause problems on 30 :/ + System.out.println("Navigation bar color being set"); + // window.clearFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); window.setNavigationBarColor(systemChromeStyle.systemNavigationBarColor); } } - // You can't change the color of the navigation bar divider color until SDK 28. - if (systemChromeStyle.systemNavigationBarDividerColor != null && Build.VERSION.SDK_INT >= 28) { - window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); - window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); - window.setNavigationBarDividerColor(systemChromeStyle.systemNavigationBarDividerColor); - } + // You can't override the enforced contrast for a transparent navigation bar until SDK 29. // This overrides the translucent scrim that may be placed behind 2/3 button navigation bars on @@ -444,6 +480,7 @@ private void setSystemChromeSystemUIOverlayStyle( // Edge to Edge. if (systemChromeStyle.systemNavigationBarContrastEnforced != null && Build.VERSION.SDK_INT >= 29) { + System.out.println("Nav bar contrast being enforced"); window.setNavigationBarContrastEnforced( systemChromeStyle.systemNavigationBarContrastEnforced); } diff --git a/tools/androidx/files.json b/tools/androidx/files.json index 2c055ebbb42e2..ac771d8a1e368 100644 --- a/tools/androidx/files.json +++ b/tools/androidx/files.json @@ -59,9 +59,9 @@ ] }, { - "url": "https://dl.google.com/android/maven2/androidx/core/core/1.6.0/core-1.6.0.aar", + "url": "https://dl.google.com/android/maven2/androidx/core/core/1.8.0-alpha04/core-1.8.0-alpha04.aar", "out_file_name": "androidx_core.aar", - "maven_dependency": "androidx.core:core:1.6.0", + "maven_dependency": "androidx.core:core:1.8.0-alpha04", "provides": [ "androidx.core.view.WindowInsetsControllerCompat" ] From 32b20d46077ee08c663016566ba66ba743c039b0 Mon Sep 17 00:00:00 2001 From: camsim99 Date: Wed, 16 Mar 2022 09:02:25 -0700 Subject: [PATCH 2/8] Fix status bar --- .../plugin/platform/PlatformPlugin.java | 76 ++++++++++--------- tools/androidx/files.json | 4 +- 2 files changed, 42 insertions(+), 38 deletions(-) diff --git a/shell/platform/android/io/flutter/plugin/platform/PlatformPlugin.java b/shell/platform/android/io/flutter/plugin/platform/PlatformPlugin.java index 92eb3cb7f4465..d4cdb2bf38a08 100644 --- a/shell/platform/android/io/flutter/plugin/platform/PlatformPlugin.java +++ b/shell/platform/android/io/flutter/plugin/platform/PlatformPlugin.java @@ -313,7 +313,7 @@ private void setSystemChromeEnabledSystemUIMode(PlatformChannel.SystemUiMode sys private void setSystemChromeEnabledSystemUIOverlays( List overlaysToShow) { - System.out.println("Applying overlays for some reason"); + System.out.println("Applying overlays for some reason"); // Start by assuming we want to hide all system overlays (like an immersive // game). int enabledOverlays = @@ -383,7 +383,16 @@ private void setSystemChromeSystemUIOverlayStyle( // If transparent, SDK 29 and higher may apply a translucent scrim behind the bar to ensure // proper contrast. This can be overridden with // SystemChromeStyle.systemStatusBarContrastEnforced. - //TODO(camillesimon): Fix status bars + // TODO(camillesimon): Fix status bars + System.out.println(Build.VERSION.SDK_INT); + System.out.println(systemChromeStyle.systemNavigationBarDividerColor); + if (systemChromeStyle.systemNavigationBarDividerColor != null && Build.VERSION.SDK_INT >= 28) { + System.out.println("Divider color being set"); + window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); + window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); + window.setNavigationBarDividerColor(systemChromeStyle.systemNavigationBarDividerColor); + } + if (Build.VERSION.SDK_INT >= 23) { if (systemChromeStyle.statusBarIconBrightness != null) { switch (systemChromeStyle.statusBarIconBrightness) { @@ -401,35 +410,6 @@ private void setSystemChromeSystemUIOverlayStyle( break; } } - - if (systemChromeStyle.statusBarColor != null) { - System.out.println("Status bar color being set"); - window.setStatusBarColor(systemChromeStyle.statusBarColor); - } - } - // You can't override the enforced contrast for a transparent status bar until SDK 29. - // This overrides the translucent scrim that may be placed behind the bar on SDK 29+ to ensure - // contrast is appropriate when using full screen layout modes like Edge to Edge. - if (systemChromeStyle.systemStatusBarContrastEnforced != null && Build.VERSION.SDK_INT >= 29) { - System.out.println("Status bar contrast being enforced"); - window.setStatusBarContrastEnforced(systemChromeStyle.systemStatusBarContrastEnforced); - } - - // SYSTEM NAVIGATION BAR -------------------------------------------------------------- - // You can't change the color of the system navigation bar until SDK 21, and you can't change - // the color of the navigation buttons until SDK 26. We only allow both starting at 26 to - // ensure buttons can be visible when changing the background color. - // If transparent, SDK 29 and higher may apply a translucent scrim behind 2/3 button navigation - // bars to ensure proper contrast. This can be overridden with - // SystemChromeStyle.systemNavigationBarContrastEnforced. - - // You can't change the color of the navigation bar divider color until SDK 28. - if (systemChromeStyle.systemNavigationBarDividerColor != null && Build.VERSION.SDK_INT >= 28) { - System.out.println("Divider color being set"); - window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); - //TODO(camillesimon):https://developer.android.com/reference/android/view/WindowManager.LayoutParams#FLAG_TRANSLUCENT_NAVIGATION - window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); - window.setNavigationBarDividerColor(systemChromeStyle.systemNavigationBarDividerColor); } if (Build.VERSION.SDK_INT >= 26) { @@ -464,15 +444,39 @@ private void setSystemChromeSystemUIOverlayStyle( break; } } + } - if (systemChromeStyle.systemNavigationBarColor != null) { - //TODO(camillesimon): Test clear flag fix for API 28. Seems to cause problems on 30 :/ - System.out.println("Navigation bar color being set"); + if (Build.VERSION.SDK_INT >= 23) { + if (systemChromeStyle.statusBarColor != null) { + System.out.println("Status bar color being set"); // window.clearFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); - window.setNavigationBarColor(systemChromeStyle.systemNavigationBarColor); + window.setStatusBarColor(systemChromeStyle.statusBarColor); } } + // You can't override the enforced contrast for a transparent status bar until SDK 29. + // This overrides the translucent scrim that may be placed behind the bar on SDK 29+ to ensure + // contrast is appropriate when using full screen layout modes like Edge to Edge. + if (systemChromeStyle.systemStatusBarContrastEnforced != null && Build.VERSION.SDK_INT >= 29) { + System.out.println("Status bar contrast being enforced"); + window.setStatusBarContrastEnforced(systemChromeStyle.systemStatusBarContrastEnforced); + } + + // SYSTEM NAVIGATION BAR -------------------------------------------------------------- + // You can't change the color of the system navigation bar until SDK 21, and you can't change + // the color of the navigation buttons until SDK 26. We only allow both starting at 26 to + // ensure buttons can be visible when changing the background color. + // If transparent, SDK 29 and higher may apply a translucent scrim behind 2/3 button navigation + // bars to ensure proper contrast. This can be overridden with + // SystemChromeStyle.systemNavigationBarContrastEnforced. + // You can't change the color of the navigation bar divider color until SDK 28. + + if (systemChromeStyle.systemNavigationBarColor != null) { + // TODO(camillesimon): Test clear flag fix for API 28. Seems to cause problems on 30 :/ + System.out.println("Navigation bar color being set"); + // window.clearFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); + window.setNavigationBarColor(systemChromeStyle.systemNavigationBarColor); + } // You can't override the enforced contrast for a transparent navigation bar until SDK 29. // This overrides the translucent scrim that may be placed behind 2/3 button navigation bars on @@ -480,7 +484,7 @@ private void setSystemChromeSystemUIOverlayStyle( // Edge to Edge. if (systemChromeStyle.systemNavigationBarContrastEnforced != null && Build.VERSION.SDK_INT >= 29) { - System.out.println("Nav bar contrast being enforced"); + System.out.println("Nav bar contrast being enforced"); window.setNavigationBarContrastEnforced( systemChromeStyle.systemNavigationBarContrastEnforced); } diff --git a/tools/androidx/files.json b/tools/androidx/files.json index ac771d8a1e368..2c055ebbb42e2 100644 --- a/tools/androidx/files.json +++ b/tools/androidx/files.json @@ -59,9 +59,9 @@ ] }, { - "url": "https://dl.google.com/android/maven2/androidx/core/core/1.8.0-alpha04/core-1.8.0-alpha04.aar", + "url": "https://dl.google.com/android/maven2/androidx/core/core/1.6.0/core-1.6.0.aar", "out_file_name": "androidx_core.aar", - "maven_dependency": "androidx.core:core:1.8.0-alpha04", + "maven_dependency": "androidx.core:core:1.6.0", "provides": [ "androidx.core.view.WindowInsetsControllerCompat" ] From 338a255efc32cb2cf450b501e1262681c7d54477 Mon Sep 17 00:00:00 2001 From: camsim99 Date: Mon, 21 Mar 2022 16:18:50 -0700 Subject: [PATCH 3/8] Fix system bar icon brightness on API 30 --- .../plugin/platform/PlatformPlugin.java | 98 +++++++------------ 1 file changed, 33 insertions(+), 65 deletions(-) diff --git a/shell/platform/android/io/flutter/plugin/platform/PlatformPlugin.java b/shell/platform/android/io/flutter/plugin/platform/PlatformPlugin.java index d4cdb2bf38a08..589a7dc97471f 100644 --- a/shell/platform/android/io/flutter/plugin/platform/PlatformPlugin.java +++ b/shell/platform/android/io/flutter/plugin/platform/PlatformPlugin.java @@ -296,13 +296,11 @@ private void setSystemChromeEnabledSystemUIMode(PlatformChannel.SystemUiMode sys // SDK 29 and up will apply a translucent body scrim behind 2/3 button navigation bars // to ensure contrast with buttons on the nav and status bars, unless the contrast is not // enforced in the overlay styling. - System.out.println("Edge to edge mode being applied"); enabledOverlays = View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN; } else { - System.out.println("No system ui modes found to apply, returning"); // When none of the conditions are matched, return without updating the system UI overlays. return; } @@ -313,7 +311,6 @@ private void setSystemChromeEnabledSystemUIMode(PlatformChannel.SystemUiMode sys private void setSystemChromeEnabledSystemUIOverlays( List overlaysToShow) { - System.out.println("Applying overlays for some reason"); // Start by assuming we want to hide all system overlays (like an immersive // game). int enabledOverlays = @@ -356,10 +353,8 @@ private void setSystemChromeEnabledSystemUIOverlays( * PlatformPlugin}. */ public void updateSystemUiOverlays() { - System.out.println("Update being called"); activity.getWindow().getDecorView().setSystemUiVisibility(mEnabledOverlays); if (currentTheme != null) { - System.out.println("currentTheme being updated"); setSystemChromeSystemUIOverlayStyle(currentTheme); } } @@ -370,86 +365,45 @@ private void restoreSystemChromeSystemUIOverlays() { private void setSystemChromeSystemUIOverlayStyle( PlatformChannel.SystemChromeStyle systemChromeStyle) { - System.out.println("Call to update current theme made"); Window window = activity.getWindow(); View view = window.getDecorView(); WindowInsetsControllerCompat windowInsetsControllerCompat = new WindowInsetsControllerCompat(window, view); + // Flag set to specify that this window is responsible for drawing the background for the system + // bars. + window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); + + // Flag set to dismiss any requests for translucent system bars to be provided in lieu of what + // is specified by systemChromeStyle. + window.clearFlags( + WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS + | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); + // SYSTEM STATUS BAR ------------------------------------------------------------------- // You can't change the color of the system status bar until SDK 21, and you can't change the // color of the status icons until SDK 23. We only allow both starting at 23 to ensure buttons - // and icons can be visible when changing the background color. + // and icons can bse visible when changing the background color. // If transparent, SDK 29 and higher may apply a translucent scrim behind the bar to ensure // proper contrast. This can be overridden with // SystemChromeStyle.systemStatusBarContrastEnforced. - // TODO(camillesimon): Fix status bars - System.out.println(Build.VERSION.SDK_INT); - System.out.println(systemChromeStyle.systemNavigationBarDividerColor); - if (systemChromeStyle.systemNavigationBarDividerColor != null && Build.VERSION.SDK_INT >= 28) { - System.out.println("Divider color being set"); - window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); - window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); - window.setNavigationBarDividerColor(systemChromeStyle.systemNavigationBarDividerColor); - } - if (Build.VERSION.SDK_INT >= 23) { if (systemChromeStyle.statusBarIconBrightness != null) { switch (systemChromeStyle.statusBarIconBrightness) { case DARK: // Dark status bar icon brightness. // Light status bar appearance. - System.out.println("Status bar icons set to dark"); windowInsetsControllerCompat.setAppearanceLightStatusBars(true); break; case LIGHT: // Light status bar icon brightness. // Dark status bar appearance. - System.out.println("Status bar icons set to light"); windowInsetsControllerCompat.setAppearanceLightStatusBars(false); break; } } - } - if (Build.VERSION.SDK_INT >= 26) { - if (systemChromeStyle.systemNavigationBarIconBrightness != null) { - switch (systemChromeStyle.systemNavigationBarIconBrightness) { - case DARK: - // Dark navigation bar icon brightness. - // Light navigation bar appearance. - System.out.println("Navigation icons set to dark"); - if (Build.VERSION.SDK_INT == 30) { - System.out.println("Made it to 30"); - // mEnabledOverlays = mEnabledOverlays &~ View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; - // view.setSystemUiVisibility(mEnabledOverlays); - windowInsetsControllerCompat.setAppearanceLightNavigationBars(true); - } else { - windowInsetsControllerCompat.setAppearanceLightNavigationBars(true); - } - break; - case LIGHT: - // Light navigation bar icon brightness. - // Dark navigation bar appearance. - System.out.println("Navigation icons set to light"); - if (Build.VERSION.SDK_INT == 30) { - System.out.println("Made it to 30"); - // mEnabledOverlays = mEnabledOverlays | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; - // view.setSystemUiVisibility(mEnabledOverlays); - windowInsetsControllerCompat.setAppearanceLightNavigationBars(false); - } else { - windowInsetsControllerCompat.setAppearanceLightNavigationBars(false); - } - - break; - } - } - } - - if (Build.VERSION.SDK_INT >= 23) { if (systemChromeStyle.statusBarColor != null) { - System.out.println("Status bar color being set"); - // window.clearFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); window.setStatusBarColor(systemChromeStyle.statusBarColor); } } @@ -457,7 +411,6 @@ private void setSystemChromeSystemUIOverlayStyle( // This overrides the translucent scrim that may be placed behind the bar on SDK 29+ to ensure // contrast is appropriate when using full screen layout modes like Edge to Edge. if (systemChromeStyle.systemStatusBarContrastEnforced != null && Build.VERSION.SDK_INT >= 29) { - System.out.println("Status bar contrast being enforced"); window.setStatusBarContrastEnforced(systemChromeStyle.systemStatusBarContrastEnforced); } @@ -468,23 +421,38 @@ private void setSystemChromeSystemUIOverlayStyle( // If transparent, SDK 29 and higher may apply a translucent scrim behind 2/3 button navigation // bars to ensure proper contrast. This can be overridden with // SystemChromeStyle.systemNavigationBarContrastEnforced. + if (Build.VERSION.SDK_INT >= 26) { + if (systemChromeStyle.systemNavigationBarIconBrightness != null) { + switch (systemChromeStyle.systemNavigationBarIconBrightness) { + case DARK: + // Dark navigation bar icon brightness. + // Light navigation bar appearance. + windowInsetsControllerCompat.setAppearanceLightNavigationBars(true); + break; + case LIGHT: + // Light navigation bar icon brightness. + // Dark navigation bar appearance. + windowInsetsControllerCompat.setAppearanceLightNavigationBars(false); + break; + } + } + } - // You can't change the color of the navigation bar divider color until SDK 28. - - if (systemChromeStyle.systemNavigationBarColor != null) { - // TODO(camillesimon): Test clear flag fix for API 28. Seems to cause problems on 30 :/ - System.out.println("Navigation bar color being set"); - // window.clearFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); + if (systemChromeStyle.systemNavigationBarColor != null && Build.VERSION.SDK_INT >= 21) { window.setNavigationBarColor(systemChromeStyle.systemNavigationBarColor); } + // You can't change the color of the navigation bar divider color until SDK 28. + if (systemChromeStyle.systemNavigationBarDividerColor != null && Build.VERSION.SDK_INT >= 28) { + window.setNavigationBarDividerColor(systemChromeStyle.systemNavigationBarDividerColor); + } + // You can't override the enforced contrast for a transparent navigation bar until SDK 29. // This overrides the translucent scrim that may be placed behind 2/3 button navigation bars on // SDK 29+ to ensure contrast is appropriate when using full screen layout modes like // Edge to Edge. if (systemChromeStyle.systemNavigationBarContrastEnforced != null && Build.VERSION.SDK_INT >= 29) { - System.out.println("Nav bar contrast being enforced"); window.setNavigationBarContrastEnforced( systemChromeStyle.systemNavigationBarContrastEnforced); } From 0f6c4a6ceea9b477e74ea75405173caaeedfa850 Mon Sep 17 00:00:00 2001 From: camsim99 Date: Mon, 21 Mar 2022 16:24:19 -0700 Subject: [PATCH 4/8] Undo change to navbar color --- .../android/io/flutter/plugin/platform/PlatformPlugin.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/shell/platform/android/io/flutter/plugin/platform/PlatformPlugin.java b/shell/platform/android/io/flutter/plugin/platform/PlatformPlugin.java index 589a7dc97471f..ebd589a75fa9e 100644 --- a/shell/platform/android/io/flutter/plugin/platform/PlatformPlugin.java +++ b/shell/platform/android/io/flutter/plugin/platform/PlatformPlugin.java @@ -436,10 +436,10 @@ private void setSystemChromeSystemUIOverlayStyle( break; } } - } - if (systemChromeStyle.systemNavigationBarColor != null && Build.VERSION.SDK_INT >= 21) { - window.setNavigationBarColor(systemChromeStyle.systemNavigationBarColor); + if (systemChromeStyle.systemNavigationBarColor != null) { + window.setNavigationBarColor(systemChromeStyle.systemNavigationBarColor); + } } // You can't change the color of the navigation bar divider color until SDK 28. From aa9d35085a39ed32758e050af804ca1bf2a4e6f0 Mon Sep 17 00:00:00 2001 From: camsim99 Date: Mon, 21 Mar 2022 16:25:30 -0700 Subject: [PATCH 5/8] Formatting --- .../android/io/flutter/plugin/platform/PlatformPlugin.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/shell/platform/android/io/flutter/plugin/platform/PlatformPlugin.java b/shell/platform/android/io/flutter/plugin/platform/PlatformPlugin.java index ebd589a75fa9e..be997e32fcfd4 100644 --- a/shell/platform/android/io/flutter/plugin/platform/PlatformPlugin.java +++ b/shell/platform/android/io/flutter/plugin/platform/PlatformPlugin.java @@ -383,7 +383,7 @@ private void setSystemChromeSystemUIOverlayStyle( // SYSTEM STATUS BAR ------------------------------------------------------------------- // You can't change the color of the system status bar until SDK 21, and you can't change the // color of the status icons until SDK 23. We only allow both starting at 23 to ensure buttons - // and icons can bse visible when changing the background color. + // and icons can be visible when changing the background color. // If transparent, SDK 29 and higher may apply a translucent scrim behind the bar to ensure // proper contrast. This can be overridden with // SystemChromeStyle.systemStatusBarContrastEnforced. @@ -441,7 +441,6 @@ private void setSystemChromeSystemUIOverlayStyle( window.setNavigationBarColor(systemChromeStyle.systemNavigationBarColor); } } - // You can't change the color of the navigation bar divider color until SDK 28. if (systemChromeStyle.systemNavigationBarDividerColor != null && Build.VERSION.SDK_INT >= 28) { window.setNavigationBarDividerColor(systemChromeStyle.systemNavigationBarDividerColor); From d9e9c9f0e32150f59554159b182c7e41d5d27930 Mon Sep 17 00:00:00 2001 From: camsim99 Date: Thu, 24 Mar 2022 13:27:03 -0700 Subject: [PATCH 6/8] Add test --- .../plugin/platform/PlatformPluginTest.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/shell/platform/android/test/io/flutter/plugin/platform/PlatformPluginTest.java b/shell/platform/android/test/io/flutter/plugin/platform/PlatformPluginTest.java index 2a04684aa6ab2..f6c005660b89c 100644 --- a/shell/platform/android/test/io/flutter/plugin/platform/PlatformPluginTest.java +++ b/shell/platform/android/test/io/flutter/plugin/platform/PlatformPluginTest.java @@ -23,6 +23,7 @@ import android.view.View; import android.view.Window; import android.view.WindowInsetsController; +import android.view.WindowManager; import androidx.activity.OnBackPressedCallback; import androidx.fragment.app.FragmentActivity; import androidx.test.ext.junit.runners.AndroidJUnit4; @@ -387,6 +388,29 @@ public void doNotEnableEdgeToEdgeOnOlderSdk() { | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN); } + @Config(sdk = 29) + @Test + public void verifyWindowFlagsSetToStyleOverlays() { + View fakeDecorView = mock(View.class); + Window fakeWindow = mock(Window.class); + when(fakeWindow.getDecorView()).thenReturn(fakeDecorView); + Activity fakeActivity = mock(Activity.class); + when(fakeActivity.getWindow()).thenReturn(fakeWindow); + PlatformChannel fakePlatformChannel = mock(PlatformChannel.class); + PlatformPlugin platformPlugin = new PlatformPlugin(fakeActivity, fakePlatformChannel); + + SystemChromeStyle style = + new SystemChromeStyle( + 0XFF000000, Brightness.LIGHT, true, 0XFFC70039, Brightness.LIGHT, 0XFF006DB3, true); + + platformPlugin.mPlatformMessageHandler.setSystemUiOverlayStyle(style); + verify(fakeWindow).addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); + verify(fakeWindow) + .clearFlags( + WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS + | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); + } + @Test public void popSystemNavigatorFlutterActivity() { Activity mockActivity = mock(Activity.class); From 699a6fceb5b09193fcb326dc8d364328f449747e Mon Sep 17 00:00:00 2001 From: camsim99 Date: Thu, 7 Apr 2022 11:27:07 -0700 Subject: [PATCH 7/8] Add version check --- .../plugin/platform/PlatformPlugin.java | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/shell/platform/android/io/flutter/plugin/platform/PlatformPlugin.java b/shell/platform/android/io/flutter/plugin/platform/PlatformPlugin.java index be997e32fcfd4..1bbbd83a223ea 100644 --- a/shell/platform/android/io/flutter/plugin/platform/PlatformPlugin.java +++ b/shell/platform/android/io/flutter/plugin/platform/PlatformPlugin.java @@ -370,15 +370,19 @@ private void setSystemChromeSystemUIOverlayStyle( WindowInsetsControllerCompat windowInsetsControllerCompat = new WindowInsetsControllerCompat(window, view); - // Flag set to specify that this window is responsible for drawing the background for the system - // bars. - window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); - - // Flag set to dismiss any requests for translucent system bars to be provided in lieu of what - // is specified by systemChromeStyle. - window.clearFlags( - WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS - | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); + if (Build.VERSION.SDK_INT < 30) { + // Flag set to specify that this window is responsible for drawing the background for the + // system + // bars. Must be set for all operations on API < 30 excluding enforcing system bar contrasts. + window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); + + // Flag set to dismiss any requests for translucent system bars to be provided in lieu of what + // is specified by systemChromeStyle. Must be set for all operations on API < 30 operations + // excluding enforcing system bar contrasts. + window.clearFlags( + WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS + | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION); + } // SYSTEM STATUS BAR ------------------------------------------------------------------- // You can't change the color of the system status bar until SDK 21, and you can't change the From d9015a6cbea385a49e5d2f9015aeb1dd2e5a5960 Mon Sep 17 00:00:00 2001 From: camsim99 Date: Fri, 8 Apr 2022 10:01:39 -0700 Subject: [PATCH 8/8] Update comment --- .../android/io/flutter/plugin/platform/PlatformPlugin.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/shell/platform/android/io/flutter/plugin/platform/PlatformPlugin.java b/shell/platform/android/io/flutter/plugin/platform/PlatformPlugin.java index 1bbbd83a223ea..a7d1c628b3c26 100644 --- a/shell/platform/android/io/flutter/plugin/platform/PlatformPlugin.java +++ b/shell/platform/android/io/flutter/plugin/platform/PlatformPlugin.java @@ -363,6 +363,7 @@ private void restoreSystemChromeSystemUIOverlays() { updateSystemUiOverlays(); } + @SuppressWarnings("deprecation") private void setSystemChromeSystemUIOverlayStyle( PlatformChannel.SystemChromeStyle systemChromeStyle) { Window window = activity.getWindow(); @@ -372,13 +373,13 @@ private void setSystemChromeSystemUIOverlayStyle( if (Build.VERSION.SDK_INT < 30) { // Flag set to specify that this window is responsible for drawing the background for the - // system - // bars. Must be set for all operations on API < 30 excluding enforcing system bar contrasts. + // system bars. Must be set for all operations on API < 30 excluding enforcing system + // bar contrasts. Deprecated in API 30. window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS); // Flag set to dismiss any requests for translucent system bars to be provided in lieu of what // is specified by systemChromeStyle. Must be set for all operations on API < 30 operations - // excluding enforcing system bar contrasts. + // excluding enforcing system bar contrasts. Deprecated in API 30. window.clearFlags( WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);