cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject [2/2] git commit: Implemented vibrateWithPattern (for android) and adapted documentation.
Date Wed, 04 Jun 2014 22:14:29 GMT
Implemented vibrateWithPattern (for android) and adapted documentation.


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-vibration/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-vibration/commit/e731cbbf
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-vibration/tree/e731cbbf
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-vibration/diff/e731cbbf

Branch: refs/heads/master
Commit: e731cbbf32f6e2c646be30169327ea028f38f0d4
Parents: 0b08297
Author: Andreas Tietz <andreas.tietz@gmail.com>
Authored: Tue Mar 4 03:27:07 2014 +0100
Committer: Steven Gill <stevengill97@gmail.com>
Committed: Wed Jun 4 15:12:58 2014 -0700

----------------------------------------------------------------------
 doc/index.md               | 33 +++++++++++++++++++++++++++------
 src/android/Vibration.java | 33 ++++++++++++++++++++++++++++++++-
 www/vibration.js           | 26 ++++++++++++++++++++++++--
 3 files changed, 83 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-vibration/blob/e731cbbf/doc/index.md
----------------------------------------------------------------------
diff --git a/doc/index.md b/doc/index.md
index fd557f9..316e775 100644
--- a/doc/index.md
+++ b/doc/index.md
@@ -27,31 +27,52 @@ This plugin provides a way to vibrate the device.
 
 ## Supported Platforms
 
+navigator.notification.vibrate
 - Amazon Fire OS
-- Android
 - BlackBerry 10
 - Firefox OS
 - iOS
 - Windows Phone 7 and 8
 
+navigator.notification.vibrate and navigator.notification.vibrateWithPattern
+- Android
+
 ## notification.vibrate
 
-Vibrates the device for the specified amount of time.
+Vibrates the device for a given amount of time.
 
     navigator.notification.vibrate(time)
 
 - __time__: Milliseconds to vibrate the device. _(Number)_
 
-
-## Example
+### Example
 
     // Vibrate for 2.5 seconds
     navigator.notification.vibrate(2500);
 
-
-## iOS Quirks
+### iOS Quirks
 
 - __time__: Ignores the specified time and vibrates for a pre-set amount of time.
 
         navigator.notification.vibrate();
         navigator.notification.vibrate(2500);   // 2500 is ignored
+
+## notification.vibrateWithPattern
+
+Vibrates the device with a given pattern.
+
+    navigator.notification.vibrateWithPattern(pattern)
+
+- __pattern__: Sequence of durations (in milliseconds) for which to turn on or off the vibrator.
_(Array of Numbers)_
+
+### Example
+
+    // Immediately start vibrating
+    // vibrate for 200ms,
+    // wait for 100ms,
+    // vibrate for 200ms,
+    // wait for 100ms,
+    // vibrate for 400ms,
+    // wait for 100ms,
+    // vibrate for 800ms
+    navigator.notification.vibrateWithPattern([0, 200, 100, 200, 100, 400, 100, 800]);

http://git-wip-us.apache.org/repos/asf/cordova-plugin-vibration/blob/e731cbbf/src/android/Vibration.java
----------------------------------------------------------------------
diff --git a/src/android/Vibration.java b/src/android/Vibration.java
index 0098619..756cf38 100755
--- a/src/android/Vibration.java
+++ b/src/android/Vibration.java
@@ -48,6 +48,14 @@ public class Vibration extends CordovaPlugin {
         if (action.equals("vibrate")) {
             this.vibrate(args.getLong(0));
         }
+        else if (action.equals("vibrateWithPattern")) {
+            JSONArray pattern = args;
+            long[] patternArray = new long[pattern.length()];
+            for (int i = 0; i < pattern.length(); i++) {
+                patternArray[i] = pattern.getLong(i);
+            }
+            this.vibrateWithPattern(patternArray);
+        }
         else {
             return false;
         }
@@ -62,7 +70,7 @@ public class Vibration extends CordovaPlugin {
     //--------------------------------------------------------------------------
 
     /**
-     * Vibrates the device for the specified amount of time.
+     * Vibrates the device for a given amount of time.
      *
      * @param time      Time to vibrate in ms.
      */
@@ -74,4 +82,27 @@ public class Vibration extends CordovaPlugin {
         Vibrator vibrator = (Vibrator) this.cordova.getActivity().getSystemService(Context.VIBRATOR_SERVICE);
         vibrator.vibrate(time);
     }
+
+    /**
+     * Vibrates the device with a given pattern.
+     *
+     * @param pattern     Pattern with which to vibrate the device.
+     *                    Pass in an array of longs that
+     *                    are the durations for which to
+     *                    turn on or off the vibrator in
+     *                    milliseconds. The first value
+     *                    indicates the number of milliseconds
+     *                    to wait before turning the vibrator
+     *                    on. The next value indicates the
+     *                    number of milliseconds for which
+     *                    to keep the vibrator on before
+     *                    turning it off. Subsequent values
+     *                    alternate between durations in
+     *                    milliseconds to turn the vibrator
+     *                    off or to turn the vibrator on.
+     */
+    public void vibrateWithPattern(long[] pattern) {
+        Vibrator vibrator = (Vibrator) this.cordova.getActivity().getSystemService(Context.VIBRATOR_SERVICE);
+        vibrator.vibrate(pattern, -1);
+    }
 }

http://git-wip-us.apache.org/repos/asf/cordova-plugin-vibration/blob/e731cbbf/www/vibration.js
----------------------------------------------------------------------
diff --git a/www/vibration.js b/www/vibration.js
index 62ef521..4d4f392 100644
--- a/www/vibration.js
+++ b/www/vibration.js
@@ -28,11 +28,33 @@ var exec = require('cordova/exec');
 module.exports = {
 
     /**
-     * Causes the device to vibrate.
+     * Vibrates the device for a given amount of time.
      *
-     * @param {Integer} mills       The number of milliseconds to vibrate for.
+     * @param {Integer} mills       The number of milliseconds to vibrate.
      */
     vibrate: function(mills) {
         exec(null, null, "Vibration", "vibrate", [mills]);
     },
+
+    /**
+     * Vibrates the device with a given pattern.
+     *
+     * @param {Array of Integer} pattern    Pattern with which to vibrate the device.
+     *                                      Pass in an array of integers that
+     *                                      are the durations for which to
+     *                                      turn on or off the vibrator in
+     *                                      milliseconds. The first value
+     *                                      indicates the number of milliseconds
+     *                                      to wait before turning the vibrator
+     *                                      on. The next value indicates the
+     *                                      number of milliseconds for which
+     *                                      to keep the vibrator on before
+     *                                      turning it off. Subsequent values
+     *                                      alternate between durations in
+     *                                      milliseconds to turn the vibrator
+     *                                      off or to turn the vibrator on.
+     */
+    vibrateWithPattern: function(pattern) {
+        exec(null, null, "Vibration", "vibrateWithPattern", pattern);
+    },
 };


Mime
View raw message