1515
1616public class StatusBar {
1717
18+ public static final String statusBarVisibilityChanged = "statusBarVisibilityChanged" ;
19+ public static final String statusBarOverlayChanged = "statusBarOverlayChanged" ;
20+
1821 private int currentStatusBarColor ;
22+ private final ChangeListener listener ;
1923 private final AppCompatActivity activity ;
2024 private final String defaultStyle ;
2125
22- public StatusBar (AppCompatActivity activity , StatusBarConfig config ) {
26+ public StatusBar (AppCompatActivity activity , StatusBarConfig config , ChangeListener listener ) {
2327 // save initial color of the status bar
2428 this .activity = activity ;
2529 this .currentStatusBarColor = activity .getWindow ().getStatusBarColor ();
30+ this .listener = listener ;
2631 this .defaultStyle = getStyle ();
2732
2833 setBackgroundColor (config .getBackgroundColor ());
2934 setStyle (config .getStyle ());
3035 setOverlaysWebView (config .isOverlaysWebView ());
36+ StatusBarInfo info = getInfo ();
37+ info .setVisible (true );
38+ listener .onChange (statusBarOverlayChanged , info );
3139 }
3240
3341 public void setStyle (String style ) {
@@ -56,12 +64,18 @@ public void hide() {
5664 View decorView = activity .getWindow ().getDecorView ();
5765 WindowInsetsControllerCompat windowInsetsControllerCompat = WindowCompat .getInsetsController (activity .getWindow (), decorView );
5866 windowInsetsControllerCompat .hide (WindowInsetsCompat .Type .statusBars ());
67+ StatusBarInfo info = getInfo ();
68+ info .setVisible (false );
69+ listener .onChange (statusBarVisibilityChanged , info );
5970 }
6071
6172 public void show () {
6273 View decorView = activity .getWindow ().getDecorView ();
6374 WindowInsetsControllerCompat windowInsetsControllerCompat = WindowCompat .getInsetsController (activity .getWindow (), decorView );
6475 windowInsetsControllerCompat .show (WindowInsetsCompat .Type .statusBars ());
76+ StatusBarInfo info = getInfo ();
77+ info .setVisible (true );
78+ listener .onChange (statusBarVisibilityChanged , info );
6579 }
6680
6781 @ SuppressWarnings ("deprecation" )
@@ -81,6 +95,7 @@ public void setOverlaysWebView(Boolean overlays) {
8195 // recover the previous color of the status bar
8296 activity .getWindow ().setStatusBarColor (currentStatusBarColor );
8397 }
98+ listener .onChange (statusBarOverlayChanged , getInfo ());
8499 }
85100
86101 @ SuppressWarnings ("deprecation" )
@@ -130,4 +145,8 @@ private int getStatusBarHeight() {
130145 // Fallback if the insets are not available
131146 return 0 ;
132147 }
148+
149+ public interface ChangeListener {
150+ void onChange (String eventName , StatusBarInfo info );
151+ }
133152}
0 commit comments