You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by st...@apache.org on 2014/06/05 00:14:28 UTC
[1/2] git commit: Extended vibrateWithPattern to allow for pattern
repetition,
implemented a complementary cancelVibration function and adapted
documentation.
Repository: cordova-plugin-vibration
Updated Branches:
refs/heads/master 0b08297f7 -> 78f95e158
Extended vibrateWithPattern to allow for pattern repetition, implemented a complementary cancelVibration function 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/78f95e15
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-vibration/tree/78f95e15
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-vibration/diff/78f95e15
Branch: refs/heads/master
Commit: 78f95e1584eb784c7092955dc1f80868ae72ef55
Parents: e731cbb
Author: Andreas Tietz <an...@gmail.com>
Authored: Wed Mar 5 01:02:52 2014 +0100
Committer: Steven Gill <st...@gmail.com>
Committed: Wed Jun 4 15:12:58 2014 -0700
----------------------------------------------------------------------
doc/index.md | 19 ++++++++++++++-----
src/android/Vibration.java | 24 ++++++++++++++++++++----
www/vibration.js | 16 ++++++++++++++--
3 files changed, 48 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-plugin-vibration/blob/78f95e15/doc/index.md
----------------------------------------------------------------------
diff --git a/doc/index.md b/doc/index.md
index 316e775..c517ce5 100644
--- a/doc/index.md
+++ b/doc/index.md
@@ -29,12 +29,13 @@ This plugin provides a way to vibrate the device.
navigator.notification.vibrate
- Amazon Fire OS
+- Android
- BlackBerry 10
- Firefox OS
- iOS
- Windows Phone 7 and 8
-navigator.notification.vibrate and navigator.notification.vibrateWithPattern
+navigator.notification.vibrateWithPattern,<br />navigator.notification.cancelVibration
- Android
## notification.vibrate
@@ -61,18 +62,26 @@ Vibrates the device for a given amount of time.
Vibrates the device with a given pattern.
- navigator.notification.vibrateWithPattern(pattern)
+ navigator.notification.vibrateWithPattern(pattern, repeat)
- __pattern__: Sequence of durations (in milliseconds) for which to turn on or off the vibrator. _(Array of Numbers)_
+- __repeat__: Optional index into the pattern array at which to start repeating (will repeat until canceled), or -1 for no repetition (default). _(Number)_
### Example
// Immediately start vibrating
- // vibrate for 200ms,
+ // vibrate for 100ms,
// 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]);
+ // vibrate for 800ms,
+ // (do not repeat)
+ navigator.notification.vibrateWithPattern([0, 100, 100, 200, 100, 400, 100, 800]);
+
+## notification.cancelVibration
+
+Immediately cancels any currently running vibration.
+
+ navigator.notification.cancelVibration()
http://git-wip-us.apache.org/repos/asf/cordova-plugin-vibration/blob/78f95e15/src/android/Vibration.java
----------------------------------------------------------------------
diff --git a/src/android/Vibration.java b/src/android/Vibration.java
index 756cf38..9e82315 100755
--- a/src/android/Vibration.java
+++ b/src/android/Vibration.java
@@ -49,12 +49,16 @@ public class Vibration extends CordovaPlugin {
this.vibrate(args.getLong(0));
}
else if (action.equals("vibrateWithPattern")) {
- JSONArray pattern = args;
+ JSONArray pattern = args.getJSONArray(0);
+ int repeat = args.getInt(1);
long[] patternArray = new long[pattern.length()];
for (int i = 0; i < pattern.length(); i++) {
patternArray[i] = pattern.getLong(i);
}
- this.vibrateWithPattern(patternArray);
+ this.vibrateWithPattern(patternArray, repeat);
+ }
+ else if (action.equals("cancelVibration")) {
+ this.cancelVibration();
}
else {
return false;
@@ -62,6 +66,7 @@ public class Vibration extends CordovaPlugin {
// Only alert and confirm are async.
callbackContext.success();
+
return true;
}
@@ -100,9 +105,20 @@ public class Vibration extends CordovaPlugin {
* alternate between durations in
* milliseconds to turn the vibrator
* off or to turn the vibrator on.
+ *
+ * @param repeat Optional index into the pattern array at which
+ * to start repeating, or -1 for no repetition (default).
+ */
+ public void vibrateWithPattern(long[] pattern, int repeat) {
+ Vibrator vibrator = (Vibrator) this.cordova.getActivity().getSystemService(Context.VIBRATOR_SERVICE);
+ vibrator.vibrate(pattern, repeat);
+ }
+
+ /**
+ * Immediately cancels any currently running vibration.
*/
- public void vibrateWithPattern(long[] pattern) {
+ public void cancelVibration() {
Vibrator vibrator = (Vibrator) this.cordova.getActivity().getSystemService(Context.VIBRATOR_SERVICE);
- vibrator.vibrate(pattern, -1);
+ vibrator.cancel();
}
}
http://git-wip-us.apache.org/repos/asf/cordova-plugin-vibration/blob/78f95e15/www/vibration.js
----------------------------------------------------------------------
diff --git a/www/vibration.js b/www/vibration.js
index 4d4f392..34b16fb 100644
--- a/www/vibration.js
+++ b/www/vibration.js
@@ -53,8 +53,20 @@ module.exports = {
* alternate between durations in
* milliseconds to turn the vibrator
* off or to turn the vibrator on.
+ *
+ * @param {Integer} repeat Optional index into the pattern array at which
+ * to start repeating (will repeat until canceled),
+ * or -1 for no repetition (default).
+ */
+ vibrateWithPattern: function(pattern, repeat) {
+ repeat = (typeof repeat !== "undefined") ? repeat : -1;
+ exec(null, null, "Vibration", "vibrateWithPattern", [pattern, repeat]);
+ },
+
+ /**
+ * Immediately cancels any currently running vibration.
*/
- vibrateWithPattern: function(pattern) {
- exec(null, null, "Vibration", "vibrateWithPattern", pattern);
+ cancelVibration: function() {
+ exec(null, null, "Vibration", "cancelVibration", []);
},
};
[2/2] git commit: Implemented vibrateWithPattern (for android) and
adapted documentation.
Posted by st...@apache.org.
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 <an...@gmail.com>
Authored: Tue Mar 4 03:27:07 2014 +0100
Committer: Steven Gill <st...@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);
+ },
};