You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ripple.apache.org by gt...@apache.org on 2013/10/30 04:38:55 UTC

git commit: added emulation for vibrate plugin

Updated Branches:
  refs/heads/next ff0deaddd -> 65eab48da


added emulation for vibrate plugin


Project: http://git-wip-us.apache.org/repos/asf/incubator-ripple/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ripple/commit/65eab48d
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ripple/tree/65eab48d
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ripple/diff/65eab48d

Branch: refs/heads/next
Commit: 65eab48da1a69e79cc44271dd4b963a7caa87f2d
Parents: ff0dead
Author: Gord Tanner <gt...@gmail.com>
Authored: Tue Oct 29 23:38:42 2013 -0400
Committer: Gord Tanner <gt...@gmail.com>
Committed: Tue Oct 29 23:38:42 2013 -0400

----------------------------------------------------------------------
 .../platform/cordova/3.0.0/bridge/vibration.js  | 28 ++++++++++++++
 lib/client/platform/cordova/3.0.0/spec.js       | 10 +++++
 test/unit/client/cordova/vibration.js           | 39 ++++++++++++++++++++
 3 files changed, 77 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ripple/blob/65eab48d/lib/client/platform/cordova/3.0.0/bridge/vibration.js
----------------------------------------------------------------------
diff --git a/lib/client/platform/cordova/3.0.0/bridge/vibration.js b/lib/client/platform/cordova/3.0.0/bridge/vibration.js
new file mode 100644
index 0000000..f7bca79
--- /dev/null
+++ b/lib/client/platform/cordova/3.0.0/bridge/vibration.js
@@ -0,0 +1,28 @@
+/*
+ *
+ * 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 goodVibrations = ripple('ui/plugins/goodVibrations');
+
+module.exports = {
+    vibrate: function (win, fail, args) {
+        var ms = args[0] || 500;
+        goodVibrations.vibrateDevice(ms);
+    }
+};

http://git-wip-us.apache.org/repos/asf/incubator-ripple/blob/65eab48d/lib/client/platform/cordova/3.0.0/spec.js
----------------------------------------------------------------------
diff --git a/lib/client/platform/cordova/3.0.0/spec.js b/lib/client/platform/cordova/3.0.0/spec.js
index 4e9b051..ced8865 100644
--- a/lib/client/platform/cordova/3.0.0/spec.js
+++ b/lib/client/platform/cordova/3.0.0/spec.js
@@ -30,6 +30,8 @@ module.exports = {
 
     initialize: function (win) {
         var honeypot = ripple('honeypot'),
+            devices =ripple('devices'),
+            device = devices.getCurrentDevice(),
             bridge = ripple('platform/cordova/2.0.0/bridge'),
             cordova,
             get = function () {
@@ -49,7 +51,15 @@ module.exports = {
         bridge.add("PluginManager", ripple('platform/cordova/3.0.0/bridge/PluginManager'));
         bridge.add("SplashScreen", ripple('platform/cordova/3.0.0/bridge/splashscreen'));
         bridge.add("InAppBrowser", ripple('platform/cordova/3.0.0/bridge/inappbrowser'));
+        bridge.add("Vibration", ripple('platform/cordova/3.0.0/bridge/vibration'));
         honeypot.monitor(win, "cordova").andRun(get, set);
+
+        //HACK: BlackBerry does vibration different
+        if (device.manufacturer === "BlackBerry") {
+            navigator.vibrate = function (ms) {
+                ripple('platform/cordova/3.0.0/bridge/vibration').vibrate(null, null, [ms]);
+            };
+        }
     },
 
     objects: {

http://git-wip-us.apache.org/repos/asf/incubator-ripple/blob/65eab48d/test/unit/client/cordova/vibration.js
----------------------------------------------------------------------
diff --git a/test/unit/client/cordova/vibration.js b/test/unit/client/cordova/vibration.js
new file mode 100644
index 0000000..a74b8f1
--- /dev/null
+++ b/test/unit/client/cordova/vibration.js
@@ -0,0 +1,39 @@
+/*
+ *
+ * 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.
+ *
+ */
+describe("cordova vibrate bridge", function () {
+    var vibration = ripple('platform/cordova/3.0.0/bridge/vibration'),
+        goodVibrations = ripple('ui/plugins/goodVibrations');
+
+    beforeEach(function () {
+        spyOn(goodVibrations, "vibrateDevice");
+    });
+
+    it("can't be called with no args", function () {
+        expect(vibration.vibrate).toThrow();
+        expect(goodVibrations.vibrateDevice).not.toHaveBeenCalled();
+    });
+
+    it("can be called specifying milliseconds", function () {
+        var vibelength = 789;
+        vibration.vibrate(null, null, [vibelength]);
+        expect(goodVibrations.vibrateDevice).toHaveBeenCalledWith(vibelength);
+    });
+});