cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From purplecabb...@apache.org
Subject [2/4] cordova-plugin-statusbar git commit: - Add support for StatusBar.backgroundColorByHexString (and StatusBar.backgroundColorByName) on Android 5 and up
Date Wed, 04 Mar 2015 01:29:10 GMT
- 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 <eddyverbruggen@gmail.com>
Authored: Fri Feb 27 22:35:30 2015 +0100
Committer: EddyVerbruggen <eddyverbruggen@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


Mime
View raw message