Touchgui/plugins/org.apache.cordova.vibration/doc/index.md

Thu, 04 Jun 2015 14:50:33 +0200

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 04 Jun 2015 14:50:33 +0200
changeset 0
e8ccd40d0ef6
permissions
-rw-r--r--

Genesis of lecture sources for Droidcon Berlin 2015 in Postbahnhof.

michael@0 1 <!---
michael@0 2 Licensed to the Apache Software Foundation (ASF) under one
michael@0 3 or more contributor license agreements. See the NOTICE file
michael@0 4 distributed with this work for additional information
michael@0 5 regarding copyright ownership. The ASF licenses this file
michael@0 6 to you under the Apache License, Version 2.0 (the
michael@0 7 "License"); you may not use this file except in compliance
michael@0 8 with the License. You may obtain a copy of the License at
michael@0 9
michael@0 10 http://www.apache.org/licenses/LICENSE-2.0
michael@0 11
michael@0 12 Unless required by applicable law or agreed to in writing,
michael@0 13 software distributed under the License is distributed on an
michael@0 14 "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
michael@0 15 KIND, either express or implied. See the License for the
michael@0 16 specific language governing permissions and limitations
michael@0 17 under the License.
michael@0 18 -->
michael@0 19
michael@0 20 # org.apache.cordova.vibration
michael@0 21
michael@0 22 This plugin aligns with the W3C vibration specification http://www.w3.org/TR/vibration/
michael@0 23
michael@0 24 This plugin provides a way to vibrate the device.
michael@0 25
michael@0 26 This plugin defines global objects including `navigator.vibrate`.
michael@0 27
michael@0 28 Although in the global scope, they are not available until after the `deviceready` event.
michael@0 29
michael@0 30 document.addEventListener("deviceready", onDeviceReady, false);
michael@0 31 function onDeviceReady() {
michael@0 32 console.log(navigator.vibrate);
michael@0 33 }
michael@0 34
michael@0 35 ## Installation
michael@0 36
michael@0 37 cordova plugin add org.apache.cordova.vibration
michael@0 38
michael@0 39 ## Supported Platforms
michael@0 40
michael@0 41 navigator.vibrate,<br />
michael@0 42 navigator.notification.vibrate
michael@0 43 - Amazon Fire OS
michael@0 44 - Android
michael@0 45 - BlackBerry 10
michael@0 46 - Firefox OS
michael@0 47 - iOS
michael@0 48 - Windows Phone 7 and 8
michael@0 49
michael@0 50 navigator.notification.vibrateWithPattern,<br />navigator.notification.cancelVibration
michael@0 51 - Android
michael@0 52 - Windows Phone 8
michael@0 53
michael@0 54 ## vibrate (recommended)
michael@0 55
michael@0 56 This function has three different functionalities based on parameters passed to it.
michael@0 57
michael@0 58 ###Standard vibrate
michael@0 59
michael@0 60 Vibrates the device for a given amount of time.
michael@0 61
michael@0 62 navigator.vibrate(time)
michael@0 63
michael@0 64 or
michael@0 65
michael@0 66 navigator.vibrate([time])
michael@0 67
michael@0 68
michael@0 69 -__time__: Milliseconds to vibrate the device. _(Number)_
michael@0 70
michael@0 71 ####Example
michael@0 72
michael@0 73 // Vibrate for 3 seconds
michael@0 74 navigator.vibrate(3000);
michael@0 75
michael@0 76 // Vibrate for 3 seconds
michael@0 77 navigator.vibrate([3000]);
michael@0 78
michael@0 79 ####iOS Quirks
michael@0 80
michael@0 81 - __time__: Ignores the specified time and vibrates for a pre-set amount of time.
michael@0 82
michael@0 83 navigator.vibrate(3000); // 3000 is ignored
michael@0 84
michael@0 85 ####Windows and Blackberry Quirks
michael@0 86
michael@0 87 - __time__: Max time is 5000ms (5s) and min time is 1ms
michael@0 88
michael@0 89 navigator.vibrate(8000); // will be truncated to 5000
michael@0 90
michael@0 91 ###Vibrate with a pattern (Android and Windows only)
michael@0 92 Vibrates the device with a given pattern
michael@0 93
michael@0 94 navigator.vibrate(pattern);
michael@0 95
michael@0 96 - __pattern__: Sequence of durations (in milliseconds) for which to turn on or off the vibrator. _(Array of Numbers)_
michael@0 97
michael@0 98 ####Example
michael@0 99
michael@0 100 // Vibrate for 1 second
michael@0 101 // Wait for 1 second
michael@0 102 // Vibrate for 3 seconds
michael@0 103 // Wait for 1 second
michael@0 104 // Vibrate for 5 seconds
michael@0 105 navigator.vibrate([1000, 1000, 3000, 1000, 5000]);
michael@0 106
michael@0 107 ####Windows Phone 8 Quirks
michael@0 108
michael@0 109 - vibrate(pattern) falls back on vibrate with default duration
michael@0 110
michael@0 111 ###Cancel vibration (not supported in iOS)
michael@0 112
michael@0 113 Immediately cancels any currently running vibration.
michael@0 114
michael@0 115 navigator.vibrate(0)
michael@0 116
michael@0 117 or
michael@0 118
michael@0 119 navigator.vibrate([])
michael@0 120
michael@0 121 or
michael@0 122
michael@0 123 navigator.vibrate([0])
michael@0 124
michael@0 125 Passing in a parameter of 0, an empty array, or an array with one element of value 0 will cancel any vibrations.
michael@0 126
michael@0 127 ## *notification.vibrate (deprecated)
michael@0 128
michael@0 129 Vibrates the device for a given amount of time.
michael@0 130
michael@0 131 navigator.notification.vibrate(time)
michael@0 132
michael@0 133 - __time__: Milliseconds to vibrate the device. _(Number)_
michael@0 134
michael@0 135 ### Example
michael@0 136
michael@0 137 // Vibrate for 2.5 seconds
michael@0 138 navigator.notification.vibrate(2500);
michael@0 139
michael@0 140 ### iOS Quirks
michael@0 141
michael@0 142 - __time__: Ignores the specified time and vibrates for a pre-set amount of time.
michael@0 143
michael@0 144 navigator.notification.vibrate();
michael@0 145 navigator.notification.vibrate(2500); // 2500 is ignored
michael@0 146
michael@0 147 ## *notification.vibrateWithPattern (deprecated)
michael@0 148
michael@0 149 Vibrates the device with a given pattern.
michael@0 150
michael@0 151 navigator.notification.vibrateWithPattern(pattern, repeat)
michael@0 152
michael@0 153 - __pattern__: Sequence of durations (in milliseconds) for which to turn on or off the vibrator. _(Array of Numbers)_
michael@0 154 - __repeat__: Optional index into the pattern array at which to start repeating (will repeat until canceled), or -1 for no repetition (default). _(Number)_
michael@0 155
michael@0 156 ### Example
michael@0 157
michael@0 158 // Immediately start vibrating
michael@0 159 // vibrate for 100ms,
michael@0 160 // wait for 100ms,
michael@0 161 // vibrate for 200ms,
michael@0 162 // wait for 100ms,
michael@0 163 // vibrate for 400ms,
michael@0 164 // wait for 100ms,
michael@0 165 // vibrate for 800ms,
michael@0 166 // (do not repeat)
michael@0 167 navigator.notification.vibrateWithPattern([0, 100, 100, 200, 100, 400, 100, 800]);
michael@0 168
michael@0 169 ## *notification.cancelVibration (deprecated)
michael@0 170
michael@0 171 Immediately cancels any currently running vibration.
michael@0 172
michael@0 173 navigator.notification.cancelVibration()
michael@0 174
michael@0 175 *Note - due to alignment with w3c spec, the starred methods will be phased out

mercurial