aszmyd closed pull request #96: Persistent transparency + getStatusBarHeight 
method
URL: https://github.com/apache/cordova-plugin-statusbar/pull/96
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/README.md b/README.md
index d6bf29c..4de091e 100644
--- a/README.md
+++ b/README.md
@@ -111,6 +111,7 @@ Although in the global scope, it is not available until 
after the `deviceready`
 - StatusBar.backgroundColorByHexString
 - StatusBar.hide
 - StatusBar.show
+- StatusBar.getStatusBarHeight (Android only)
 
 Properties
 --------
@@ -286,6 +287,18 @@ Shows the statusbar.
     StatusBar.show();
 
 
+StatusBar.getStatusBarHeight
+=================
+
+Gets the current height (in CSS pixels) of system statusbar.
+
+**Note that this is implemented currently only on Android**
+
+    StatusBar.getStatusBarHeight(function(height) {
+        // height in CSS pixels, i.e. 25
+    });
+
+
 Supported Platforms
 -------------------
 
diff --git a/src/android/StatusBar.java b/src/android/StatusBar.java
index 714c30e..2125c91 100644
--- a/src/android/StatusBar.java
+++ b/src/android/StatusBar.java
@@ -25,6 +25,8 @@
 import android.view.View;
 import android.view.Window;
 import android.view.WindowManager;
+import android.graphics.Rect;
+import android.content.res.Resources;
 
 import org.apache.cordova.CallbackContext;
 import org.apache.cordova.CordovaArgs;
@@ -39,6 +41,8 @@
 public class StatusBar extends CordovaPlugin {
     private static final String TAG = "StatusBar";
 
+    private boolean transparent = false;
+
     /**
      * Sets the context of the Command. This can then be used to do things like
      * get file paths associated with the Activity.
@@ -62,6 +66,9 @@ public void run() {
                 // Read 'StatusBarBackgroundColor' from config.xml, default is 
#000000.
                 
setStatusBarBackgroundColor(preferences.getString("StatusBarBackgroundColor", 
"#000000"));
 
+                // Read 'StatusBarOverlaysWebView' from config.xml, default is 
false.
+                
setStatusBarTransparent(preferences.getBoolean("StatusBarOverlaysWebView", 
false));
+
                 // Read 'StatusBarStyle' from config.xml, default is 
'lightcontent'.
                 setStatusBarStyle(preferences.getString("StatusBarStyle", 
"lightcontent"));
             }
@@ -96,7 +103,11 @@ public void run() {
                     // use KitKat here to be aligned with "Fullscreen"  
preference
                     if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
                         int uiOptions = 
window.getDecorView().getSystemUiVisibility();
-                        uiOptions &= ~View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
+                        if (transparent) {
+                            uiOptions |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
+                        } else {
+                            uiOptions &= 
~View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
+                        }
                         uiOptions &= ~View.SYSTEM_UI_FLAG_FULLSCREEN;
 
                         window.getDecorView().setSystemUiVisibility(uiOptions);
@@ -203,6 +214,17 @@ public void run() {
             return true;
         }
 
+        if ("getStatusBarHeight".equals(action)) {
+            this.cordova.getActivity().runOnUiThread(new Runnable() {
+                @Override
+                public void run() {
+                    callbackContext.sendPluginResult(new 
PluginResult(PluginResult.Status.OK, getStatusBarHeight()));
+                }
+            });
+            return true;
+        }
+
+
         return false;
     }
 
@@ -227,20 +249,22 @@ private void setStatusBarBackgroundColor(final String 
colorPref) {
     }
 
     private void setStatusBarTransparent(final boolean transparent) {
-        if (Build.VERSION.SDK_INT >= 21) {
+        this.transparent = transparent;
             final Window window = cordova.getActivity().getWindow();
             if (transparent) {
                 window.getDecorView().setSystemUiVisibility(
                         View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                                 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
-                window.setStatusBarColor(Color.TRANSPARENT);
+
+                if (Build.VERSION.SDK_INT >= 21) {
+                    window.setStatusBarColor(Color.TRANSPARENT);
+                }
             }
             else {
                 window.getDecorView().setSystemUiVisibility(
                         View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                                 | View.SYSTEM_UI_FLAG_VISIBLE);
             }
-        }
     }
 
     private void setStatusBarStyle(final String style) {
@@ -273,4 +297,14 @@ private void setStatusBarStyle(final String style) {
             }
         }
     }
+
+    private int getStatusBarHeight() {
+
+        Rect rectangle = new Rect();
+        Window window = cordova.getActivity().getWindow();
+        window.getDecorView().getWindowVisibleDisplayFrame(rectangle);
+        int statusBarHeight = Math.round(rectangle.top / 
Resources.getSystem().getDisplayMetrics().density);
+        return statusBarHeight;
+
+    }
 }
diff --git a/www/statusbar.js b/www/statusbar.js
index d9d0ea5..85fdfea 100644
--- a/www/statusbar.js
+++ b/www/statusbar.js
@@ -93,6 +93,13 @@ var StatusBar = {
     show: function () {
         exec(null, null, "StatusBar", "show", []);
         StatusBar.isVisible = true;
+    },
+
+    getStatusBarHeight: function (successCallback, errorCallback) {
+        exec(function (result) {
+            successCallback(result);
+        }, errorCallback, "StatusBar", "getStatusBarHeight", []);
+        StatusBar.isVisible = true;
     }
 
 };


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

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

Reply via email to