@@ -27,7 +27,7 @@ public class StatusBar {
2727 public StatusBar (AppCompatActivity activity , StatusBarConfig config , ChangeListener listener ) {
2828 // save initial color of the status bar
2929 this .activity = activity ;
30- this .currentStatusBarColor = activity .getWindow (). getStatusBarColor ( );
30+ this .currentStatusBarColor = getStatusBarColorDeprecated ( activity .getWindow ());
3131 this .listener = listener ;
3232 setBackgroundColor (config .getBackgroundColor ());
3333 setStyle (config .getStyle ());
@@ -61,12 +61,11 @@ public void updateStyle() {
6161 setStyle (this .currentStyle );
6262 }
6363
64- @ SuppressWarnings ("deprecation" )
6564 public void setBackgroundColor (int color ) {
6665 Window window = activity .getWindow ();
67- window . clearFlags ( WindowManager . LayoutParams . FLAG_TRANSLUCENT_STATUS );
66+ clearTranslucentStatusFlagDeprecated ( window );
6867 window .addFlags (WindowManager .LayoutParams .FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS );
69- window . setStatusBarColor ( color );
68+ setStatusBarColorDeprecated ( window , color );
7069 // update the local color field as well
7170 currentStatusBarColor = color ;
7271 }
@@ -89,31 +88,29 @@ public void show() {
8988 listener .onChange (statusBarVisibilityChanged , info );
9089 }
9190
92- @ SuppressWarnings ("deprecation" )
9391 public void setOverlaysWebView (Boolean overlays ) {
9492 View decorView = activity .getWindow ().getDecorView ();
95- int uiOptions = decorView . getSystemUiVisibility ( );
93+ int uiOptions = getSystemUiVisibilityDeprecated ( decorView );
9694 if (overlays ) {
9795 // Sets the layout to a fullscreen one that does not hide the actual status bar, so the WebView is displayed behind it.
98- uiOptions = uiOptions | View . SYSTEM_UI_FLAG_LAYOUT_STABLE | View . SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN ;
99- decorView . setSystemUiVisibility ( uiOptions );
100- currentStatusBarColor = activity .getWindow (). getStatusBarColor ( );
101- activity .getWindow (). setStatusBarColor ( Color .TRANSPARENT );
96+ uiOptions = uiOptions | getSystemUiFlagLayoutStableDeprecated () | getSystemUiFlagLayoutFullscreenDeprecated () ;
97+ setSystemUiVisibilityDeprecated ( decorView , uiOptions );
98+ currentStatusBarColor = getStatusBarColorDeprecated ( activity .getWindow ());
99+ setStatusBarColorDeprecated ( activity .getWindow (), Color .TRANSPARENT );
102100 } else {
103101 // Sets the layout to a normal one that displays the WebView below the status bar.
104- uiOptions = uiOptions & ~View . SYSTEM_UI_FLAG_LAYOUT_STABLE & ~View . SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN ;
105- decorView . setSystemUiVisibility ( uiOptions );
102+ uiOptions = uiOptions & ~getSystemUiFlagLayoutStableDeprecated () & ~getSystemUiFlagLayoutFullscreenDeprecated () ;
103+ setSystemUiVisibilityDeprecated ( decorView , uiOptions );
106104 // recover the previous color of the status bar
107- activity .getWindow (). setStatusBarColor ( currentStatusBarColor );
105+ setStatusBarColorDeprecated ( activity .getWindow (), currentStatusBarColor );
108106 }
109107 listener .onChange (statusBarOverlayChanged , getInfo ());
110108 }
111109
112- @ SuppressWarnings ("deprecation" )
113110 private boolean getIsOverlaid () {
114111 return (
115- (activity .getWindow ().getDecorView (). getSystemUiVisibility () & View . SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN ) ==
116- View . SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
112+ (getSystemUiVisibilityDeprecated ( activity .getWindow ().getDecorView ())
113+ & getSystemUiFlagLayoutFullscreenDeprecated ()) == getSystemUiFlagLayoutFullscreenDeprecated ()
117114 );
118115 }
119116
@@ -125,7 +122,7 @@ public StatusBarInfo getInfo() {
125122 info .setStyle (getStyle ());
126123 info .setOverlays (getIsOverlaid ());
127124 info .setVisible (isVisible );
128- info .setColor (String .format ("#%06X" , (0xFFFFFF & window . getStatusBarColor ( ))));
125+ info .setColor (String .format ("#%06X" , (0xFFFFFF & getStatusBarColorDeprecated ( window ))));
129126 info .setHeight (getStatusBarHeight ());
130127 return info ;
131128 }
@@ -150,7 +147,7 @@ private int getStatusBarHeight() {
150147
151148 WindowInsets insets = activity .getWindow ().getDecorView ().getRootWindowInsets ();
152149 if (insets != null ) {
153- return ( int ) ( insets . getSystemWindowInsetTop () / metrics . density );
150+ return getSystemWindowInsetTopDeprecated ( insets , metrics );
154151 }
155152
156153 // Fallback if the insets are not available
@@ -160,4 +157,44 @@ private int getStatusBarHeight() {
160157 public interface ChangeListener {
161158 void onChange (String eventName , StatusBarInfo info );
162159 }
160+
161+ @ SuppressWarnings ("deprecation" )
162+ private int getStatusBarColorDeprecated (Window window ) {
163+ return window .getStatusBarColor ();
164+ }
165+
166+ @ SuppressWarnings ("deprecation" )
167+ private void setStatusBarColorDeprecated (Window window , int color ) {
168+ window .setStatusBarColor (color );
169+ }
170+
171+ @ SuppressWarnings ("deprecation" )
172+ private void clearTranslucentStatusFlagDeprecated (Window window ) {
173+ window .clearFlags (WindowManager .LayoutParams .FLAG_TRANSLUCENT_STATUS );
174+ }
175+
176+ @ SuppressWarnings ("deprecation" )
177+ private int getSystemUiVisibilityDeprecated (View decorView ) {
178+ return decorView .getSystemUiVisibility ();
179+ }
180+
181+ @ SuppressWarnings ("deprecation" )
182+ private void setSystemUiVisibilityDeprecated (View decorView , int uiOptions ) {
183+ decorView .setSystemUiVisibility (uiOptions );
184+ }
185+
186+ @ SuppressWarnings ("deprecation" )
187+ private int getSystemUiFlagLayoutStableDeprecated () {
188+ return View .SYSTEM_UI_FLAG_LAYOUT_STABLE ;
189+ }
190+
191+ @ SuppressWarnings ("deprecation" )
192+ private int getSystemUiFlagLayoutFullscreenDeprecated () {
193+ return View .SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN ;
194+ }
195+
196+ @ SuppressWarnings ("deprecation" )
197+ private int getSystemWindowInsetTopDeprecated (WindowInsets insets , DisplayMetrics metrics ) {
198+ return (int ) (insets .getSystemWindowInsetTop () / metrics .density );
199+ }
163200}
0 commit comments