Thu, 04 Jun 2015 14:50:33 +0200
Genesis of lecture sources for Droidcon Berlin 2015 in Postbahnhof.
michael@0 | 1 | /* |
michael@0 | 2 | Licensed under the Apache License, Version 2.0 (the "License"); |
michael@0 | 3 | you may not use this file except in compliance with the License. |
michael@0 | 4 | You may obtain a copy of the License at |
michael@0 | 5 | |
michael@0 | 6 | http://www.apache.org/licenses/LICENSE-2.0 |
michael@0 | 7 | |
michael@0 | 8 | Unless required by applicable law or agreed to in writing, software |
michael@0 | 9 | distributed under the License is distributed on an "AS IS" BASIS, |
michael@0 | 10 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
michael@0 | 11 | See the License for the specific language governing permissions and |
michael@0 | 12 | limitations under the License. |
michael@0 | 13 | */ |
michael@0 | 14 | |
michael@0 | 15 | using System; |
michael@0 | 16 | using System.Windows; |
michael@0 | 17 | using System.Windows.Controls; |
michael@0 | 18 | using Microsoft.Devices; |
michael@0 | 19 | using System.Runtime.Serialization; |
michael@0 | 20 | using System.Threading; |
michael@0 | 21 | using System.Windows.Resources; |
michael@0 | 22 | using Microsoft.Phone.Controls; |
michael@0 | 23 | using System.Diagnostics; |
michael@0 | 24 | |
michael@0 | 25 | |
michael@0 | 26 | namespace WPCordovaClassLib.Cordova.Commands |
michael@0 | 27 | { |
michael@0 | 28 | public class Vibration : BaseCommand |
michael@0 | 29 | { |
michael@0 | 30 | private static readonly int DEFAULT_DURATION = 200; |
michael@0 | 31 | |
michael@0 | 32 | public void vibrate(string vibrateDuration) |
michael@0 | 33 | { |
michael@0 | 34 | int msecs = DEFAULT_DURATION; // set default |
michael@0 | 35 | |
michael@0 | 36 | try |
michael@0 | 37 | { |
michael@0 | 38 | string[] args = JSON.JsonHelper.Deserialize<string[]>(vibrateDuration); |
michael@0 | 39 | |
michael@0 | 40 | msecs = int.Parse(args[0]); |
michael@0 | 41 | if (msecs < 1) |
michael@0 | 42 | { |
michael@0 | 43 | msecs = 1; |
michael@0 | 44 | } |
michael@0 | 45 | } |
michael@0 | 46 | catch (FormatException) |
michael@0 | 47 | { |
michael@0 | 48 | |
michael@0 | 49 | } |
michael@0 | 50 | |
michael@0 | 51 | vibrateMs(msecs); |
michael@0 | 52 | |
michael@0 | 53 | // TODO: may need to add listener to trigger DispatchCommandResult when the vibration ends... |
michael@0 | 54 | DispatchCommandResult(); |
michael@0 | 55 | } |
michael@0 | 56 | |
michael@0 | 57 | private static void vibrateMs(int msecs) |
michael@0 | 58 | { |
michael@0 | 59 | VibrateController.Default.Start(TimeSpan.FromMilliseconds(msecs)); |
michael@0 | 60 | } |
michael@0 | 61 | |
michael@0 | 62 | public void vibrateWithPattern(string options) |
michael@0 | 63 | { |
michael@0 | 64 | // falling back to vibrate |
michael@0 | 65 | vibrateMs(DEFAULT_DURATION); |
michael@0 | 66 | |
michael@0 | 67 | // TODO: may need to add listener to trigger DispatchCommandResult when the vibration ends... |
michael@0 | 68 | DispatchCommandResult(); |
michael@0 | 69 | } |
michael@0 | 70 | |
michael@0 | 71 | public void cancelVibration(string options) |
michael@0 | 72 | { |
michael@0 | 73 | VibrateController.Default.Stop(); |
michael@0 | 74 | DispatchCommandResult(); |
michael@0 | 75 | } |
michael@0 | 76 | } |
michael@0 | 77 | } |