cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From purplecabb...@apache.org
Subject [3/4] cordova-plugin-statusbar git commit: - Use StatusBarBackgroundColor instead of AndroidStatusBarBackgroundColor, and added a quirk to the readme.
Date Wed, 04 Mar 2015 01:29:11 GMT
- 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 <eddyverbruggen@gmail.com>
Authored: Sat Feb 28 08:59:47 2015 +0100
Committer: EddyVerbruggen <eddyverbruggen@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


Mime
View raw message