incubator-callback-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From deedu...@apache.org
Subject [2/2] git commit: Add battery API support for Playbook.
Date Thu, 22 Mar 2012 19:16:29 GMT
Add battery API support for Playbook.


Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/commit/4d5d1afc
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/tree/4d5d1afc
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/diff/4d5d1afc

Branch: refs/heads/master
Commit: 4d5d1afc89cfcc02732b59d728b06f18978656f4
Parents: 2a56f4e
Author: Drew Walters <deedubbu@gmail.com>
Authored: Wed Mar 21 15:30:05 2012 -0500
Committer: Drew Walters <deedubbu@gmail.com>
Committed: Wed Mar 21 15:30:05 2012 -0500

----------------------------------------------------------------------
 lib/plugin/playbook/manager.js |   38 ++++++++++++++++++++++++++++++++++-
 1 files changed, 37 insertions(+), 1 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-js/blob/4d5d1afc/lib/plugin/playbook/manager.js
----------------------------------------------------------------------
diff --git a/lib/plugin/playbook/manager.js b/lib/plugin/playbook/manager.js
index 312a1d2..df19a9a 100644
--- a/lib/plugin/playbook/manager.js
+++ b/lib/plugin/playbook/manager.js
@@ -10,6 +10,41 @@ var webworks = require('cordova/plugin/webworks/manager'),
     retAsyncCall = function () {
         return { "status" : cordova.callbackStatus.NO_RESULT, "message" : "WebWorks Is On
It" };
     },
+    batteryAPI = {
+        execute: function (webWorksResult, action, args, win, fail) {
+            if (action === 'start') {
+                // Register one listener to each of level and state change
+                // events using WebWorks API.
+                blackberry.system.event.deviceBatteryStateChange(function(state) {
+                    var me = navigator.battery;
+                    // state is either CHARGING or UNPLUGGED
+                    if (state === 2 || state === 3) {
+                        var info = {
+                            "level" : me._level,
+                            "isPlugged" : state === 2
+                        };
+
+                        if (me._isPlugged !== info.isPlugged
+                                && typeof win === 'function') {
+                            win(info);
+                        }
+                    }
+                });
+                blackberry.system.event.deviceBatteryLevelChange(function(level) {
+                    var me = navigator.battery;
+                    if (level != me._level && typeof win === 'function') {
+                        win({'level' : level, 'isPlugged' : me._isPlugged});
+                    }
+                });
+            } else if (action === 'stop') {
+                // Unregister battery listeners.
+                blackberry.system.event.deviceBatteryStateChange(null);
+                blackberry.system.event.deviceBatteryLevelChange(null);
+            } else {
+                return retInvalidAction();
+            }
+        }
+    },
     cameraAPI = {
         execute: function (webWorksResult, action, args, win, fail) {
             if (action === 'takePicture') {
@@ -256,11 +291,12 @@ var webworks = require('cordova/plugin/webworks/manager'),
         }
     },
     plugins = {
+        'Battery' : batteryAPI,
         'Camera' : cameraAPI,
         'Device' : deviceAPI,
         'Logger' : loggerAPI,
         'Media' : mediaAPI,
-        'MediaCapture' : mediaCaptureAPI,
+        'Capture' : mediaCaptureAPI,
         'Network Status' : networkAPI,
         'Notification' : notificationAPI
     };


Mime
View raw message