You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by pu...@apache.org on 2015/03/04 02:29:09 UTC

[1/4] cordova-plugin-statusbar git commit: Allow setting the statusbar backgroundcolor on Android

Repository: cordova-plugin-statusbar
Updated Branches:
  refs/heads/master 29b42dd93 -> bf17f4397


Allow setting the statusbar backgroundcolor on Android


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-statusbar/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-statusbar/commit/43c8c15b
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-statusbar/tree/43c8c15b
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-statusbar/diff/43c8c15b

Branch: refs/heads/master
Commit: 43c8c15bf48d058fec9e91a6d2bcad17880b2b78
Parents: dff669e
Author: EddyVerbruggen <ed...@gmail.com>
Authored: Fri Feb 27 10:29:39 2015 +0100
Committer: EddyVerbruggen <ed...@gmail.com>
Committed: Fri Feb 27 10:29:39 2015 +0100

----------------------------------------------------------------------
 doc/index.md               |  4 ++++
 src/android/StatusBar.java | 25 +++++++++++++++++++++++++
 2 files changed, 29 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-statusbar/blob/43c8c15b/doc/index.md
----------------------------------------------------------------------
diff --git a/doc/index.md b/doc/index.md
index 9955857..bd5bd1e 100644
--- a/doc/index.md
+++ b/doc/index.md
@@ -41,6 +41,10 @@ Preferences
 
         <preference name="StatusBarBackgroundColor" value="#000000" />
 
+- __AndroidStatusBarBackgroundColor__ (color hex string, defaults to the Android theme default). On Android 5 and up, the background color can be set by a hex string (#RRGGBB) at startup. We don't use the same property as for iOS because on iOS you typically want the statusbar to have the same color as the app background, but the Android 5+ guidelines specify using a different color than you apps main color, so the value of this property is typically different than the one specified by StatusBarBackgroundColor.
+
+        <preference name="AndroidStatusBarBackgroundColor" value="#000000" />
+
 - __StatusBarStyle__ (status bar style, defaults to lightcontent). On iOS 7, set the status bar style. Available options default, lightcontent, blacktranslucent, blackopaque.
 
         <preference name="StatusBarStyle" value="lightcontent" />

http://git-wip-us.apache.org/repos/asf/cordova-plugin-statusbar/blob/43c8c15b/src/android/StatusBar.java
----------------------------------------------------------------------
diff --git a/src/android/StatusBar.java b/src/android/StatusBar.java
index e4f748f..2cbb19e 100644
--- a/src/android/StatusBar.java
+++ b/src/android/StatusBar.java
@@ -20,6 +20,8 @@
 package org.apache.cordova.statusbar;
 
 import android.app.Activity;
+import android.graphics.Color;
+import android.os.Build;
 import android.util.Log;
 import android.view.Window;
 import android.view.WindowManager;
@@ -54,6 +56,7 @@ public class StatusBar extends CordovaPlugin {
                 // by the Cordova.
                 Window window = cordova.getActivity().getWindow();
                 window.clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
+                setStatusBarBackgroundColor();
             }
         });
     }
@@ -98,4 +101,26 @@ public class StatusBar extends CordovaPlugin {
 
         return false;
     }
+
+    /**
+     * Read 'AndroidStatusBarBackgroundColor' from config.xml. We expect a hex #RRGGBB string.
+     */
+    private void setStatusBarBackgroundColor() {
+        if (Build.VERSION.SDK_INT >= 21) {
+            final String colorPref = preferences.getString("AndroidStatusBarBackgroundColor", null);
+            if (colorPref != null) {
+                final Window window = cordova.getActivity().getWindow();
+                // Method and constants not available on all SDKs but we want to be able to compile this code with any SDK
+                window.clearFlags(0x04000000); // SDK 19: WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
+                window.addFlags(0x80000000); // SDK 21: WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
+                try {
+                    // Using reflection makes sure any 5.0+ device will work without having to compile with SDK level 21
+                    window.getClass().getDeclaredMethod("setStatusBarColor", int.class).invoke(window, Color.parseColor(colorPref));
+                } catch (Exception ignore) {
+                    // this should not happen, only in case Android removes this method in a version > 21
+                    Log.w(TAG, "Method window.setStatusBarColor not found for SDK level " + Build.VERSION.SDK_INT);
+                }
+            }
+        }
+    }
 }


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


[2/4] cordova-plugin-statusbar git commit: - Add support for StatusBar.backgroundColorByHexString (and StatusBar.backgroundColorByName) on Android 5 and up

Posted by pu...@apache.org.
- Add support for StatusBar.backgroundColorByHexString (and StatusBar.backgroundColorByName) on Android 5 and up


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-statusbar/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-statusbar/commit/84ee94cb
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-statusbar/tree/84ee94cb
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-statusbar/diff/84ee94cb

Branch: refs/heads/master
Commit: 84ee94cb418de381baacc3135594dfbf263924f7
Parents: 43c8c15
Author: EddyVerbruggen <ed...@gmail.com>
Authored: Fri Feb 27 22:35:30 2015 +0100
Committer: EddyVerbruggen <ed...@gmail.com>
Committed: Fri Feb 27 22:35:30 2015 +0100

----------------------------------------------------------------------
 doc/index.md               |  2 ++
 src/android/StatusBar.java | 30 +++++++++++++++++++++---------
 2 files changed, 23 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-statusbar/blob/84ee94cb/doc/index.md
----------------------------------------------------------------------
diff --git a/doc/index.md b/doc/index.md
index bd5bd1e..4557320 100644
--- a/doc/index.md
+++ b/doc/index.md
@@ -203,6 +203,7 @@ Supported Platforms
 -------------------
 
 - iOS
+- Android 5+
 - Windows Phone 7
 - Windows Phone 8
 - Windows Phone 8.1
@@ -227,6 +228,7 @@ Supported Platforms
 -------------------
 
 - iOS
+- Android 5+
 - Windows Phone 7
 - Windows Phone 8
 - Windows Phone 8.1

http://git-wip-us.apache.org/repos/asf/cordova-plugin-statusbar/blob/84ee94cb/src/android/StatusBar.java
----------------------------------------------------------------------
diff --git a/src/android/StatusBar.java b/src/android/StatusBar.java
index 2cbb19e..07aee43 100644
--- a/src/android/StatusBar.java
+++ b/src/android/StatusBar.java
@@ -56,7 +56,9 @@ public class StatusBar extends CordovaPlugin {
                 // by the Cordova.
                 Window window = cordova.getActivity().getWindow();
                 window.clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
-                setStatusBarBackgroundColor();
+
+                // Read 'AndroidStatusBarBackgroundColor' from config.xml. We expect a hex string like #999999.
+                setStatusBarBackgroundColor(preferences.getString("AndroidStatusBarBackgroundColor", null));
             }
         });
     }
@@ -70,7 +72,7 @@ public class StatusBar extends CordovaPlugin {
      * @return                  True if the action was valid, false otherwise.
      */
     @Override
-    public boolean execute(String action, CordovaArgs args, final CallbackContext callbackContext) throws JSONException {
+    public boolean execute(final String action, final CordovaArgs args, final CallbackContext callbackContext) throws JSONException {
         Log.v(TAG, "Executing action: " + action);
         final Activity activity = this.cordova.getActivity();
         final Window window = activity.getWindow();
@@ -99,16 +101,26 @@ public class StatusBar extends CordovaPlugin {
             return true;
         }
 
+        if ("backgroundColorByHexString".equals(action)) {
+            this.cordova.getActivity().runOnUiThread(new Runnable() {
+                @Override
+                public void run() {
+                    try {
+                        setStatusBarBackgroundColor(args.getString(0));
+                    } catch (JSONException ignore) {
+                        callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, "Invalid hexString argument, use '#RRGGBB'"));
+                    }
+                }
+            });
+            return true;
+        }
+
         return false;
     }
 
-    /**
-     * Read 'AndroidStatusBarBackgroundColor' from config.xml. We expect a hex #RRGGBB string.
-     */
-    private void setStatusBarBackgroundColor() {
-        if (Build.VERSION.SDK_INT >= 21) {
-            final String colorPref = preferences.getString("AndroidStatusBarBackgroundColor", null);
-            if (colorPref != null) {
+    private void setStatusBarBackgroundColor(final String colorPref) {
+        if (colorPref != null && !colorPref.isEmpty()) {
+            if (Build.VERSION.SDK_INT >= 21) {
                 final Window window = cordova.getActivity().getWindow();
                 // Method and constants not available on all SDKs but we want to be able to compile this code with any SDK
                 window.clearFlags(0x04000000); // SDK 19: WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);


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


[4/4] cordova-plugin-statusbar git commit: Merge branch 'master' of https://github.com/EddyVerbruggen/cordova-plugin-statusbar

Posted by pu...@apache.org.
Merge branch 'master' of https://github.com/EddyVerbruggen/cordova-plugin-statusbar


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-statusbar/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-statusbar/commit/bf17f439
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-statusbar/tree/bf17f439
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-statusbar/diff/bf17f439

Branch: refs/heads/master
Commit: bf17f43973f2c48e558106720b22c5b223dc66e4
Parents: 29b42dd 7f135a4
Author: Jesse MacFadyen <pu...@gmail.com>
Authored: Tue Mar 3 17:28:50 2015 -0800
Committer: Jesse MacFadyen <pu...@gmail.com>
Committed: Tue Mar 3 17:28:50 2015 -0800

----------------------------------------------------------------------
 doc/index.md               | 12 +++++++++++-
 src/android/StatusBar.java | 41 ++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 51 insertions(+), 2 deletions(-)
----------------------------------------------------------------------



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


[3/4] cordova-plugin-statusbar git commit: - Use StatusBarBackgroundColor instead of AndroidStatusBarBackgroundColor, and added a quirk to the readme.

Posted by pu...@apache.org.
- Use StatusBarBackgroundColor instead of AndroidStatusBarBackgroundColor, and added a quirk to the readme.


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-statusbar/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-statusbar/commit/7f135a46
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-statusbar/tree/7f135a46
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-statusbar/diff/7f135a46

Branch: refs/heads/master
Commit: 7f135a46e18d8c8fd2c868e3a194d63d72b97807
Parents: 84ee94c
Author: EddyVerbruggen <ed...@gmail.com>
Authored: Sat Feb 28 08:59:47 2015 +0100
Committer: EddyVerbruggen <ed...@gmail.com>
Committed: Sat Feb 28 08:59:47 2015 +0100

----------------------------------------------------------------------
 doc/index.md               | 14 +++++++++-----
 src/android/StatusBar.java | 12 +++++++-----
 2 files changed, 16 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-statusbar/blob/7f135a46/doc/index.md
----------------------------------------------------------------------
diff --git a/doc/index.md b/doc/index.md
index 4557320..d22662c 100644
--- a/doc/index.md
+++ b/doc/index.md
@@ -37,18 +37,22 @@ Preferences
 
         <preference name="StatusBarOverlaysWebView" value="true" />
 
-- __StatusBarBackgroundColor__ (color hex string, defaults to #000000). On iOS 7, set the background color of the statusbar by a hex string (#RRGGBB) at startup.
+- __StatusBarBackgroundColor__ (color hex string, defaults to #000000). On iOS 7 and Android 5, set the background color of the statusbar by a hex string (#RRGGBB) at startup.
 
         <preference name="StatusBarBackgroundColor" value="#000000" />
 
-- __AndroidStatusBarBackgroundColor__ (color hex string, defaults to the Android theme default). On Android 5 and up, the background color can be set by a hex string (#RRGGBB) at startup. We don't use the same property as for iOS because on iOS you typically want the statusbar to have the same color as the app background, but the Android 5+ guidelines specify using a different color than you apps main color, so the value of this property is typically different than the one specified by StatusBarBackgroundColor.
-
-        <preference name="AndroidStatusBarBackgroundColor" value="#000000" />
-
 - __StatusBarStyle__ (status bar style, defaults to lightcontent). On iOS 7, set the status bar style. Available options default, lightcontent, blacktranslucent, blackopaque.
 
         <preference name="StatusBarStyle" value="lightcontent" />
 
+### Android Quirks
+The Android 5+ guidelines specify using a different color for the statusbar than your main app color (unlike the uniform statusbar color of many iOS 7+ apps), so you may want to set the statusbar color at runtime instead via `StatusBar.backgroundColorByHexString` or `StatusBar.backgroundColorByName`. One way to do that would be:
+```js
+if (cordova.platformId == 'android') {
+    StatusBar.backgroundColorByHexString("#333");
+}
+```
+
 Hiding at startup
 -----------
 

http://git-wip-us.apache.org/repos/asf/cordova-plugin-statusbar/blob/7f135a46/src/android/StatusBar.java
----------------------------------------------------------------------
diff --git a/src/android/StatusBar.java b/src/android/StatusBar.java
index 07aee43..4d3b85b 100644
--- a/src/android/StatusBar.java
+++ b/src/android/StatusBar.java
@@ -57,8 +57,8 @@ public class StatusBar extends CordovaPlugin {
                 Window window = cordova.getActivity().getWindow();
                 window.clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
 
-                // Read 'AndroidStatusBarBackgroundColor' from config.xml. We expect a hex string like #999999.
-                setStatusBarBackgroundColor(preferences.getString("AndroidStatusBarBackgroundColor", null));
+                // Read 'StatusBarBackgroundColor' from config.xml, default is #000000.
+                setStatusBarBackgroundColor(preferences.getString("StatusBarBackgroundColor", "#000000"));
             }
         });
     }
@@ -108,7 +108,7 @@ public class StatusBar extends CordovaPlugin {
                     try {
                         setStatusBarBackgroundColor(args.getString(0));
                     } catch (JSONException ignore) {
-                        callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, "Invalid hexString argument, use '#RRGGBB'"));
+                        Log.e(TAG, "Invalid hexString argument, use f.i. '#777777'");
                     }
                 }
             });
@@ -119,8 +119,8 @@ public class StatusBar extends CordovaPlugin {
     }
 
     private void setStatusBarBackgroundColor(final String colorPref) {
-        if (colorPref != null && !colorPref.isEmpty()) {
-            if (Build.VERSION.SDK_INT >= 21) {
+        if (Build.VERSION.SDK_INT >= 21) {
+            if (colorPref != null && !colorPref.isEmpty()) {
                 final Window window = cordova.getActivity().getWindow();
                 // Method and constants not available on all SDKs but we want to be able to compile this code with any SDK
                 window.clearFlags(0x04000000); // SDK 19: WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
@@ -128,6 +128,8 @@ public class StatusBar extends CordovaPlugin {
                 try {
                     // Using reflection makes sure any 5.0+ device will work without having to compile with SDK level 21
                     window.getClass().getDeclaredMethod("setStatusBarColor", int.class).invoke(window, Color.parseColor(colorPref));
+                } catch (IllegalArgumentException ignore) {
+                    Log.e(TAG, "Invalid hexString argument, use f.i. '#999999'");
                 } catch (Exception ignore) {
                     // this should not happen, only in case Android removes this method in a version > 21
                     Log.w(TAG, "Method window.setStatusBarColor not found for SDK level " + Build.VERSION.SDK_INT);


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