You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by lo...@apache.org on 2013/05/07 17:14:09 UTC

[22/50] [abbrv] webworks commit: Add Accelerometer plugin

Add Accelerometer plugin

Reviewed by Bryan Higgins <bh...@blackberry.com>
Tested by Tracy Li <tl...@blackberry.com>


Project: http://git-wip-us.apache.org/repos/asf/cordova-blackberry/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-blackberry/commit/70152add
Tree: http://git-wip-us.apache.org/repos/asf/cordova-blackberry/tree/70152add
Diff: http://git-wip-us.apache.org/repos/asf/cordova-blackberry/diff/70152add

Branch: refs/heads/future
Commit: 70152adda6e020c41f0f56e7d7f133e1ec953cda
Parents: b3960ef
Author: Hasan Ahmad <ha...@blackberry.com>
Authored: Wed Mar 27 15:00:30 2013 -0400
Committer: Bryan Higgins <bh...@blackberry.com>
Committed: Fri May 3 10:13:30 2013 -0400

----------------------------------------------------------------------
 .../project/plugins/Accelerometer/index.js         |   45 ++++++++
 .../bin/test/plugins/Accelerometer/index.js        |   81 +++++++++++++++
 blackberry10/javascript/cordova.blackberry10.js    |   54 +++-------
 3 files changed, 144 insertions(+), 36 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/70152add/blackberry10/bin/templates/project/plugins/Accelerometer/index.js
----------------------------------------------------------------------
diff --git a/blackberry10/bin/templates/project/plugins/Accelerometer/index.js b/blackberry10/bin/templates/project/plugins/Accelerometer/index.js
new file mode 100644
index 0000000..47abe42
--- /dev/null
+++ b/blackberry10/bin/templates/project/plugins/Accelerometer/index.js
@@ -0,0 +1,45 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+*/
+
+var callback;
+
+module.exports = {
+    start: function (success, fail, args, env) {
+        var result = new PluginResult(args, env);
+        window.removeEventListener("devicemotion", callback);
+        callback = function (motion) {
+            var info = {
+                x: motion.accelerationIncludingGravity.x,
+                y: motion.accelerationIncludingGravity.y,
+                z: motion.accelerationIncludingGravity.z,
+                timestamp: motion.timestamp
+            };
+            result.callbackOk(info, true);
+        };
+        window.addEventListener("devicemotion", callback);
+        result.noResult(true);
+    },
+    stop: function (success, fail, args, env) {
+        var result = new PluginResult(args, env);
+        window.removeEventListener("devicemotion", callback);
+        result.ok("removed");
+    }
+};

http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/70152add/blackberry10/bin/test/plugins/Accelerometer/index.js
----------------------------------------------------------------------
diff --git a/blackberry10/bin/test/plugins/Accelerometer/index.js b/blackberry10/bin/test/plugins/Accelerometer/index.js
new file mode 100644
index 0000000..a016219
--- /dev/null
+++ b/blackberry10/bin/test/plugins/Accelerometer/index.js
@@ -0,0 +1,81 @@
+/*
+* Copyright 2013 Research In Motion Limited.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+describe("Accelerometer", function () {
+    var _apiDir = __dirname + "./../../../templates/project/plugins/Accelerometer/",
+        index,
+        callback,
+        result = {
+            ok: jasmine.createSpy(),
+            error: jasmine.createSpy(),
+            noResult: jasmine.createSpy(),
+            callbackOk: jasmine.createSpy()
+        },
+        motion = {
+            timestamp: 0,
+            accelerationIncludingGravity: {
+                x: 0,
+                y: 0,
+                z: 0
+            }
+        };
+
+    beforeEach(function () {
+        index = require(_apiDir + "index");
+        GLOBAL.window = {
+            removeEventListener: jasmine.createSpy("removeEventListener spy"),
+            addEventListener: jasmine.createSpy("addEventListener spy").andCallFake(function (evt, cb) {
+                callback = cb;
+            })
+        };
+        GLOBAL.PluginResult = function () {
+            return result;
+        };
+    });
+
+    afterEach(function () {
+        index = null;
+        delete GLOBAL.window;
+        delete GLOBAL.PluginResult;
+    });
+
+    describe("start", function () {
+        it("calls noResult and keeps callbacks", function () {
+            index.start();
+            expect(window.addEventListener).toHaveBeenCalled();
+            expect(result.noResult).toHaveBeenCalledWith(true);
+        });
+
+        it("callback calls ok and keeps callbacks", function () {
+            callback(motion);
+            expect(result.callbackOk).toHaveBeenCalled();
+        });
+
+        it("does not call error if already started", function () {
+            index.start();
+            expect(window.removeEventListener).toHaveBeenCalled();
+            expect(window.addEventListener).toHaveBeenCalled();
+            expect(result.error).not.toHaveBeenCalled();
+        });
+    });
+
+    describe("stop", function () {
+        it("calls result ok", function () {
+            index.stop();
+            expect(window.removeEventListener).toHaveBeenCalled();
+            expect(result.ok).toHaveBeenCalledWith("removed");
+        });
+    });
+});

http://git-wip-us.apache.org/repos/asf/cordova-blackberry/blob/70152add/blackberry10/javascript/cordova.blackberry10.js
----------------------------------------------------------------------
diff --git a/blackberry10/javascript/cordova.blackberry10.js b/blackberry10/javascript/cordova.blackberry10.js
index b730b08..45f9aff 100644
--- a/blackberry10/javascript/cordova.blackberry10.js
+++ b/blackberry10/javascript/cordova.blackberry10.js
@@ -1,8 +1,8 @@
 // Platform: blackberry10
 
-// commit f9ac2930aa892422deff2be5a3b3b8f5e8f7edc0
+// commit c8e2a018e93036393bcf5e0edd855187e5c587c5
 
-// File generated at :: Mon Apr 08 2013 15:58:16 GMT-0400 (EDT)
+// File generated at :: Thu Apr 11 2013 16:14:07 GMT-0400 (EDT)
 
 /*
  Licensed to the Apache Software Foundation (ASF) under one
@@ -31,17 +31,28 @@ var require,
     define;
 
 (function () {
-    var modules = {};
+    var modules = {},
     // Stack of moduleIds currently being built.
-    var requireStack = [];
+        requireStack = [],
     // Map of module ID -> index into requireStack of modules currently being built.
-    var inProgressModules = {};
+        inProgressModules = {},
+        SEPERATOR = ".";
+
+
 
     function build(module) {
-        var factory = module.factory;
+        var factory = module.factory,
+            localRequire = function (id) {
+                var resultantId = id;
+                //Its a relative path, so lop off the last portion and add the id (minus "./")
+                if (id.charAt(0) === ".") {
+                    resultantId = module.id.slice(0, module.id.lastIndexOf(SEPERATOR)) + SEPERATOR + id.slice(2);
+                }
+                return require(resultantId);
+            };
         module.exports = {};
         delete module.factory;
-        factory(require, module.exports, module);
+        factory(localRequire, module.exports, module);
         return module.exports;
     }
 
@@ -949,7 +960,6 @@ define("cordova/exec", function(require, exports, module) {
 
 var cordova = require('cordova'),
     plugins = {
-        'Accelerometer' : require('cordova/plugin/blackberry10/accelerometer'),
         'Compass' : require('cordova/plugin/blackberry10/magnetometer'),
         'Capture' : require('cordova/plugin/blackberry10/capture'),
         'Media': require('cordova/plugin/blackberry10/media'),
@@ -3841,34 +3851,6 @@ module.exports = {
 
 });
 
-// file: lib/blackberry10/plugin/blackberry10/accelerometer.js
-define("cordova/plugin/blackberry10/accelerometer", function(require, exports, module) {
-
-var cordova = require('cordova'),
-    callback;
-
-module.exports = {
-    start: function (args, win, fail) {
-        window.removeEventListener("devicemotion", callback);
-        callback = function (motion) {
-            win({
-                x: motion.accelerationIncludingGravity.x,
-                y: motion.accelerationIncludingGravity.y,
-                z: motion.accelerationIncludingGravity.z,
-                timestamp: motion.timestamp
-            });
-        };
-        window.addEventListener("devicemotion", callback);
-        return { "status" : cordova.callbackStatus.NO_RESULT, "message" : "WebWorks Is On It" };
-    },
-    stop: function (args, win, fail) {
-        window.removeEventListener("devicemotion", callback);
-        return { "status" : cordova.callbackStatus.OK, "message" : "removed" };
-    }
-};
-
-});
-
 // file: lib/blackberry10/plugin/blackberry10/capture.js
 define("cordova/plugin/blackberry10/capture", function(require, exports, module) {