Exemplo n.º 1
0
        /// <summary>
        /// Stops the vibration of the phone.
        /// </summary>
        public void Cancel()
        {
#if __ANDROID__
            _vibrator.Cancel();
#elif __IOS__
            SystemSound.Vibrate.Close();
#elif TIZEN
            _vibrator.Stop();
#elif WINDOWS_UWP || WINDOWS_PHONE_APP || WINDOWS_PHONE
            _device.Cancel();
#elif WINDOWS_PHONE
            Microsoft.Devices.VibrateController.Default.Stop();
#endif
        }
        /// <summary>
        /// Method for haptic operation
        /// </summary>
        /// <param name="time">Duration of vibraation</param>
        private async void HapticOperation(int time)
        {
            try
            {
                // Gets the number of the available vibrators
                var numofvib = Vibrator.NumberOfVibrators;
                // Gets the control of the specific vibrator
                Vibrator vib = Vibrator.Vibrators[0];
                int      wait_time;

                // Maximum vibration duration is 9999
                if (time < 9999)
                {
                    wait_time = time;
                }
                else
                {
                    wait_time = 9999;
                }

                // Show waiting page during vibration
                await this.Navigation.PushAsync(new SimpleResult("Testing... " + wait_time + "ms"));

                // Wait until vibration is over
                var t = Task.Run(async delegate
                {
                    await Task.Delay(wait_time);
                    return;
                });

                // Vibrates during the user input time with a constant intensity
                vib.Vibrate(time, 100);
                t.Wait();
                // Stops the vibration
                vib.Stop();

                // Operations are succeed
                await this.Navigation.PushAsync(new SimpleResult("Succeed: Haptic(" + wait_time + "ms)"));
            }
            catch (Exception e)
            {
                // Operations are failed
                await this.Navigation.PushAsync(new SimpleResult("Failed: Haptic\n" + e.Message));
            }
        }