@@ -29,12 +29,17 @@ Licensed to the Apache Software Foundation (ASF) under one
29
29
import android .view .ViewParent ;
30
30
import android .view .Window ;
31
31
import android .view .WindowInsetsController ;
32
+ import android .view .WindowManager ;
32
33
import android .widget .FrameLayout ;
33
34
34
35
import androidx .core .content .ContextCompat ;
36
+ import androidx .core .view .ViewCompat ;
35
37
import androidx .core .view .WindowCompat ;
36
38
import androidx .core .view .WindowInsetsControllerCompat ;
37
39
40
+ import org .json .JSONArray ;
41
+ import org .json .JSONException ;
42
+
38
43
public class SystemBarPlugin extends CordovaPlugin {
39
44
static final String PLUGIN_NAME = "SystemBarPlugin" ;
40
45
@@ -72,6 +77,63 @@ public Object onMessage(String id, Object data) {
72
77
return null ;
73
78
}
74
79
80
+ @ Override
81
+ public boolean execute (String action , JSONArray args , CallbackContext callbackContext ) throws JSONException {
82
+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .VANILLA_ICE_CREAM
83
+ && preferences .getBoolean ("AndroidEdgeToEdge" , false )
84
+ ) {
85
+ // Disable JS API in E2E mode (SDK >= 35)
86
+ return false ;
87
+ }
88
+
89
+ if ("setStatusBarVisible" .equals (action )) {
90
+ boolean visible = args .getBoolean (0 );
91
+ cordova .getActivity ().runOnUiThread (() -> setStatusBarVisible (visible ));
92
+ } else if ("setStatusBarBackgroundColor" .equals (action )) {
93
+ String bgColor = args .getString (0 );
94
+ cordova .getActivity ().runOnUiThread (() -> setStatusBarBackgroundColor (bgColor ));
95
+ } else {
96
+ return false ;
97
+ }
98
+
99
+ callbackContext .success ();
100
+ return true ;
101
+ }
102
+
103
+ private void setStatusBarVisible (final boolean visible ) {
104
+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .VANILLA_ICE_CREAM ) {
105
+ View statusBar = getStatusBarView (webView );
106
+ if (statusBar != null ) {
107
+ statusBar .setVisibility (visible ? View .VISIBLE : View .GONE );
108
+
109
+ FrameLayout rootLayout = getRootLayout (webView );
110
+ if (rootLayout != null ) {
111
+ ViewCompat .requestApplyInsets (rootLayout );
112
+ }
113
+ }
114
+ } else {
115
+ Window window = cordova .getActivity ().getWindow ();
116
+ int uiOptions = window .getDecorView ().getSystemUiVisibility ();
117
+ int flags = View .SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View .SYSTEM_UI_FLAG_FULLSCREEN ;
118
+ if (visible ) {
119
+ uiOptions &= ~flags ;
120
+ window .clearFlags (WindowManager .LayoutParams .FLAG_FULLSCREEN );
121
+ } else {
122
+ uiOptions |= flags ;
123
+ window .addFlags (WindowManager .LayoutParams .FLAG_FULLSCREEN );
124
+ }
125
+ window .getDecorView ().setSystemUiVisibility (uiOptions );
126
+ }
127
+ }
128
+
129
+ private void setStatusBarBackgroundColor (final String colorPref ) {
130
+ int parsedColor = parseColorFromString (colorPref );
131
+ if (parsedColor == INVALID_COLOR ) return ;
132
+
133
+ overrideStatusBarBackgroundColor = Color .parseColor (colorPref );
134
+ updateStatusBar (overrideStatusBarBackgroundColor );
135
+ }
136
+
75
137
private void updateSystemBars () {
76
138
// Update Root View Background Color
77
139
int rootViewBackgroundColor = getPreferenceBackgroundColor ();
@@ -130,7 +192,9 @@ private void updateRootView(int bgColor) {
130
192
private void updateStatusBar (int bgColor ) {
131
193
Window window = cordova .getActivity ().getWindow ();
132
194
133
- if (!preferences .getBoolean ("AndroidEdgeToEdge" , false )) {
195
+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .VANILLA_ICE_CREAM
196
+ && !preferences .getBoolean ("AndroidEdgeToEdge" , false )
197
+ ) {
134
198
View statusBar = getStatusBarView (webView );
135
199
if (statusBar != null ) {
136
200
statusBar .setBackgroundColor (bgColor );
0 commit comments