erisu commented on code in PR #1817:
URL: https://github.com/apache/cordova-android/pull/1817#discussion_r2190547772


##########
framework/src/org/apache/cordova/SystemBarPlugin.java:
##########
@@ -0,0 +1,289 @@
+/*
+       Licensed to the Apache Software Foundation (ASF) under one
+       or more contributor license agreements.  See the NOTICE file
+       distributed with this work for additional information
+       regarding copyright ownership.  The ASF licenses this file
+       to you under the Apache License, Version 2.0 (the
+       "License"); you may not use this file except in compliance
+       with the License.  You may obtain a copy of the License at
+
+         http://www.apache.org/licenses/LICENSE-2.0
+
+       Unless required by applicable law or agreed to in writing,
+       software distributed under the License is distributed on an
+       "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+       KIND, either express or implied.  See the License for the
+       specific language governing permissions and limitations
+       under the License.
+*/
+
+package org.apache.cordova;
+
+import android.annotation.SuppressLint;
+import android.content.Context;
+import android.content.res.Configuration;
+import android.content.res.Resources;
+import android.graphics.Color;
+import android.os.Build;
+import android.view.View;
+import android.view.ViewParent;
+import android.view.Window;
+import android.view.WindowInsetsController;
+import android.view.WindowManager;
+import android.widget.FrameLayout;
+
+import androidx.core.content.ContextCompat;
+import androidx.core.view.ViewCompat;
+import androidx.core.view.WindowCompat;
+import androidx.core.view.WindowInsetsControllerCompat;
+
+import org.json.JSONArray;
+import org.json.JSONException;
+
+public class SystemBarPlugin extends CordovaPlugin {
+    static final String PLUGIN_NAME = "SystemBarPlugin";
+
+    static final int INVALID_COLOR = -1;
+
+    // Internal variables
+    private Context context;
+    private Resources resources;
+    private int overrideStatusBarBackgroundColor = INVALID_COLOR;
+
+
+    @Override
+    protected void pluginInitialize() {
+        context = cordova.getContext();
+        resources = context.getResources();
+    }
+
+    @Override
+    public void onConfigurationChanged(Configuration newConfig) {
+        super.onConfigurationChanged(newConfig);
+        cordova.getActivity().runOnUiThread(this::updateSystemBars);
+    }
+
+    @Override
+    public void onResume(boolean multitasking) {
+        super.onResume(multitasking);
+        cordova.getActivity().runOnUiThread(this::updateSystemBars);
+    }
+
+    @Override
+    public Object onMessage(String id, Object data) {
+        if (id.equals("updateSystemBars")) {
+            cordova.getActivity().runOnUiThread(this::updateSystemBars);
+        }
+        return null;
+    }
+
+    @Override
+    public boolean execute(String action, JSONArray args, CallbackContext 
callbackContext) throws JSONException {
+        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM
+                && preferences.getBoolean("AndroidEdgeToEdge", false)
+        ) {
+            // Disable JS API in E2E mode (SDK >= 35)
+            return false;
+        }
+
+        if ("setStatusBarVisible".equals(action)) {
+            boolean visible = args.getBoolean(0);
+            cordova.getActivity().runOnUiThread(() -> 
setStatusBarVisible(visible));
+        } else if ("setStatusBarBackgroundColor".equals(action)) {
+            String bgColor = args.getString(0);
+            cordova.getActivity().runOnUiThread(() -> 
setStatusBarBackgroundColor(bgColor));
+        } else {
+            return false;
+        }
+
+        callbackContext.success();
+        return true;
+    }
+
+    private void setStatusBarVisible(final boolean visible) {
+        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM) {
+            View statusBar = getStatusBarView(webView);
+            if (statusBar != null) {
+                statusBar.setVisibility(visible ? View.VISIBLE : View.GONE);
+
+                FrameLayout rootLayout = getRootLayout(webView);
+                if (rootLayout != null) {
+                    ViewCompat.requestApplyInsets(rootLayout);
+                }
+            }
+        } else {
+            Window window = cordova.getActivity().getWindow();
+            int uiOptions = window.getDecorView().getSystemUiVisibility();
+            int flags = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | 
View.SYSTEM_UI_FLAG_FULLSCREEN;
+            if (visible) {
+                uiOptions &= ~flags;
+                window.clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
+            } else {
+                uiOptions |= flags;
+                window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
+            }
+            window.getDecorView().setSystemUiVisibility(uiOptions);
+        }
+    }
+
+    private void setStatusBarBackgroundColor(final String colorPref) {

Review Comment:
   This should be fixed.



##########
cordova-js-src/plugin/android/statusbar.js:
##########
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+var exec = require('cordova/exec');
+
+var statusBarVisible = true;
+var statusBar = {};
+
+Object.defineProperty(statusBar, 'visible', {
+    configurable: false,
+    enumerable: true,
+    get: function () {
+        if (window.StatusBar) {
+            // try to let the StatusBar plugin handle it
+            return window.StatusBar.isVisible;
+        }
+
+        return statusBarVisible;
+    },
+    set: function (value) {
+        if (window.StatusBar) {
+            // try to let the StatusBar plugin handle it
+            if (value) {
+                window.StatusBar.show();
+            } else {
+                window.StatusBar.hide();
+            }
+        } else {
+            statusBarVisible = value;
+            exec(null, null, 'SystemBarPlugin', 'setStatusBarVisible', 
[!!value]);
+        }
+    }
+});
+
+Object.defineProperty(statusBar, 'setBackgroundColor', {
+    configurable: false,
+    enumerable: false,
+    writable: false,
+    value: function (value) {
+        // Confirm if value is a valid hex code is before passing to 
native-side
+        if (!(/^#(?:[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/.test(value))) {
+            console.error('Invalid color hex code. Valid format: #RRGGBB or 
#AARRGGBB');
+            return;
+        }

Review Comment:
   This should be fixed.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscr...@cordova.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@cordova.apache.org
For additional commands, e-mail: issues-h...@cordova.apache.org

Reply via email to