cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From purplecabb...@apache.org
Subject [2/8] cordova-plugin-vibration git commit: CB-6916 added vibrateWithPattern for wp8
Date Mon, 18 May 2015 22:33:26 GMT
CB-6916 added vibrateWithPattern for wp8

Also change to cancelVibration to allow for canceling a pattern


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/7dd0e661
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-vibration/tree/7dd0e661
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-vibration/diff/7dd0e661

Branch: refs/heads/master
Commit: 7dd0e6610be372b076daf6f6c80f4ec3aa5e0df4
Parents: faa3d62
Author: Staci Cooper <smcooper@us.ibm.com>
Authored: Tue Jul 29 11:24:43 2014 -0400
Committer: Staci Cooper <smcooper@us.ibm.com>
Committed: Tue Jul 29 11:24:43 2014 -0400

----------------------------------------------------------------------
 src/wp/Vibration.cs | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-vibration/blob/7dd0e661/src/wp/Vibration.cs
----------------------------------------------------------------------
diff --git a/src/wp/Vibration.cs b/src/wp/Vibration.cs
index 8d54d94..2975b7a 100644
--- a/src/wp/Vibration.cs
+++ b/src/wp/Vibration.cs
@@ -21,12 +21,15 @@ using System.Threading;
 using System.Windows.Resources;
 using Microsoft.Phone.Controls;
 using System.Diagnostics;
+using System.Threading.Tasks;
 
 
 namespace WPCordovaClassLib.Cordova.Commands
 {
     public class Vibration : BaseCommand
     {
+        // bool used by vibrateWithPattern to stop when Cancel is pressed
+        private bool cancelPattern = false;
 
         public void vibrate(string vibrateDuration)
         {
@@ -54,9 +57,29 @@ namespace WPCordovaClassLib.Cordova.Commands
             DispatchCommandResult();
         }
 
+        public async Task vibrateWithPattern(string options)
+        {
+            // get options
+            string[] args = JSON.JsonHelper.Deserialize<string[]>(options);
+            long[] pattern = JSON.JsonHelper.Deserialize<long[]>(args[0]);
+
+            for (int i = 0; i < pattern.Length && !cancelPattern; i++)
+            {
+                long msecs = pattern[i];
+                if (i % 2 == 0)
+                {
+                    VibrateController.Default.Start(TimeSpan.FromMilliseconds(msecs));
+                }
+                await Task.Delay(TimeSpan.FromMilliseconds(msecs));
+            }
+            cancelPattern = false;
+            DispatchCommandResult();
+        }
+
         public void cancelVibration(string options)
         {
             VibrateController.Default.Stop();
+            cancelPattern = true;
             DispatchCommandResult();
         }
     }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org


Mime
View raw message