44
55package com .idlefish .flutterboost ;
66
7+ import android .app .Activity ;
8+ import android .os .Build ;
79import android .os .Bundle ;
810import android .view .View ;
911import android .view .ViewGroup ;
12+ import android .view .Window ;
13+ import android .view .WindowManager ;
1014
15+ import java .lang .reflect .Field ;
1116import java .util .HashMap ;
1217import java .util .Map ;
1318import java .util .Set ;
1419import java .util .UUID ;
1520
21+ import androidx .annotation .NonNull ;
22+ import androidx .annotation .Nullable ;
23+ import androidx .core .view .WindowInsetsControllerCompat ;
1624import io .flutter .embedding .android .FlutterView ;
1725import io .flutter .embedding .engine .FlutterEngine ;
1826import io .flutter .embedding .engine .plugins .FlutterPlugin ;
27+ import io .flutter .embedding .engine .systemchannels .PlatformChannel ;
28+ import io .flutter .plugin .platform .PlatformPlugin ;
1929
2030/**
2131 * Helper methods to deal with common tasks.
@@ -82,4 +92,79 @@ public static FlutterView findFlutterView(View view) {
8292 }
8393 return null ;
8494 }
95+
96+ @ Nullable
97+ public static PlatformChannel .SystemChromeStyle getCurrentSystemUiOverlayTheme (PlatformPlugin platformPlugin ) {
98+ if (platformPlugin != null ) {
99+ try {
100+ Field field = platformPlugin .getClass ().getDeclaredField ("currentTheme" );
101+ field .setAccessible (true );
102+ return (PlatformChannel .SystemChromeStyle ) field .get (platformPlugin );
103+ } catch (NoSuchFieldException e ) {
104+ e .printStackTrace ();
105+ } catch (IllegalAccessException e ) {
106+ e .printStackTrace ();
107+ }
108+ }
109+ return null ;
110+ }
111+
112+ public static void setSystemChromeSystemUIOverlayStyle (@ NonNull Activity activity ,
113+ PlatformChannel .SystemChromeStyle systemChromeStyle ) {
114+ Window window = activity .getWindow ();
115+ View view = window .getDecorView ();
116+ WindowInsetsControllerCompat windowInsetsControllerCompat =
117+ new WindowInsetsControllerCompat (window , view );
118+
119+ if (Build .VERSION .SDK_INT < 30 ) {
120+ window .addFlags (WindowManager .LayoutParams .FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS );
121+ window .clearFlags (
122+ WindowManager .LayoutParams .FLAG_TRANSLUCENT_STATUS
123+ | WindowManager .LayoutParams .FLAG_TRANSLUCENT_NAVIGATION );
124+ }
125+ if (Build .VERSION .SDK_INT >= 23 ) {
126+ if (systemChromeStyle .statusBarIconBrightness != null ) {
127+ switch (systemChromeStyle .statusBarIconBrightness ) {
128+ case DARK :
129+ windowInsetsControllerCompat .setAppearanceLightStatusBars (true );
130+ break ;
131+ case LIGHT :
132+ windowInsetsControllerCompat .setAppearanceLightStatusBars (false );
133+ break ;
134+ }
135+ }
136+
137+ if (systemChromeStyle .statusBarColor != null ) {
138+ window .setStatusBarColor (systemChromeStyle .statusBarColor );
139+ }
140+ }
141+ if (systemChromeStyle .systemStatusBarContrastEnforced != null && Build .VERSION .SDK_INT >= 29 ) {
142+ window .setStatusBarContrastEnforced (systemChromeStyle .systemStatusBarContrastEnforced );
143+ }
144+
145+ if (Build .VERSION .SDK_INT >= 26 ) {
146+ if (systemChromeStyle .systemNavigationBarIconBrightness != null ) {
147+ switch (systemChromeStyle .systemNavigationBarIconBrightness ) {
148+ case DARK :
149+ windowInsetsControllerCompat .setAppearanceLightNavigationBars (true );
150+ break ;
151+ case LIGHT :
152+ windowInsetsControllerCompat .setAppearanceLightNavigationBars (false );
153+ break ;
154+ }
155+ }
156+
157+ if (systemChromeStyle .systemNavigationBarColor != null ) {
158+ window .setNavigationBarColor (systemChromeStyle .systemNavigationBarColor );
159+ }
160+ }
161+ if (systemChromeStyle .systemNavigationBarDividerColor != null && Build .VERSION .SDK_INT >= 28 ) {
162+ window .setNavigationBarDividerColor (systemChromeStyle .systemNavigationBarDividerColor );
163+ }
164+ if (systemChromeStyle .systemNavigationBarContrastEnforced != null
165+ && Build .VERSION .SDK_INT >= 29 ) {
166+ window .setNavigationBarContrastEnforced (
167+ systemChromeStyle .systemNavigationBarContrastEnforced );
168+ }
169+ }
85170}
0 commit comments