Exemplo n.º 1
0
        public void TriggerHapticFeedback(HapticFeedbackType hapticFeedback)
        {
            switch (hapticFeedback)
            {
            case HapticFeedbackType.ImpactLight:
                TriggerImpactFeedback(ImpactFeedbackStyle.Light);
                break;

            case HapticFeedbackType.ImpactMedium:
                TriggerImpactFeedback(ImpactFeedbackStyle.Medium);
                break;

            case HapticFeedbackType.ImpactHeavy:
                TriggerImpactFeedback(ImpactFeedbackStyle.Heavy);
                break;

            case HapticFeedbackType.NotificationError:
                TriggerNotificationFeedback(NotificationFeedbackType.Error);
                break;

            case HapticFeedbackType.NotificationSuccess:
                TriggerNotificationFeedback(NotificationFeedbackType.Success);
                break;

            case HapticFeedbackType.NotificationWarning:
                TriggerNotificationFeedback(NotificationFeedbackType.Warning);
                break;

            case HapticFeedbackType.Selection:
                TriggerSelectionFeedback();
                break;
            }
        }
Exemplo n.º 2
0
 static void PlatformPerform(HapticFeedbackType type)
 {
     if (type == HapticFeedbackType.LongPress)
     {
         NSHapticFeedbackManager.DefaultPerformer.PerformFeedback(NSHapticFeedbackPattern.Generic, NSHapticFeedbackPerformanceTime.Default);
     }
 }
Exemplo n.º 3
0
 public static void Perform(HapticFeedbackType type = HapticFeedbackType.Click)
 {
     if (!IsSupported)
     {
         throw new FeatureNotSupportedException();
     }
     PlatformPerform(type);
 }
Exemplo n.º 4
0
        static void PlatformPerform(HapticFeedbackType type)
        {
            switch (type)
            {
            case HapticFeedbackType.LongPress:
                PlatformLongPress();
                break;

            default:
                PlatformClick();
                break;
            }
        }
Exemplo n.º 5
0
        public void Perform(HapticFeedbackType type)
        {
            switch (type)
            {
            case HapticFeedbackType.LongPress:
                LongPress();
                break;

            default:
                Click();
                break;
            }
        }
Exemplo n.º 6
0
        static void PlatformPerform(HapticFeedbackType type)
        {
            Permissions.EnsureDeclared <Permissions.Vibrate>();

            try
            {
                Platform.CurrentActivity?.Window?.DecorView?.PerformHapticFeedback(ConvertType(type));
            }
            catch (Exception ex)
            {
                Debug.WriteLine($"HapticFeedback Exception: {ex.Message}");
            }
        }
Exemplo n.º 7
0
        public void Perform(HapticFeedbackType type)
        {
            Permissions.EnsureDeclared <Permissions.Vibrate>();

            try
            {
                ActivityStateManager.Default.GetCurrentActivity()?.Window?.DecorView?.PerformHapticFeedback(ConvertType(type));
            }
            catch (Exception ex)
            {
                Debug.WriteLine($"HapticFeedback Exception: {ex.Message}");
            }
        }
Exemplo n.º 8
0
 public void Perform(HapticFeedbackType type)
 {
     Permissions.EnsureDeclared <Permissions.Vibrate>();
     try
     {
         var feedback = new Feedback();
         var pattern  = ConvertType(type);
         if (feedback.IsSupportedPattern(FeedbackType.Vibration, pattern))
         {
             feedback.Play(FeedbackType.Vibration, pattern);
         }
     }
     catch (Exception ex)
     {
         Debug.WriteLine($"HapticFeedback Exception: {ex.Message}");
     }
 }
Exemplo n.º 9
0
        public void Run(HapticFeedbackType hapticFeedbackType)
        {
            switch (hapticFeedbackType)
            {
            case HapticFeedbackType.Softy:
                activity.Window.DecorView.RootView.PerformHapticFeedback(FeedbackConstants.ContextClick);
                break;

            case HapticFeedbackType.Medium:
                activity.Window.DecorView.RootView.PerformHapticFeedback(FeedbackConstants.KeyboardPress);
                break;

            case HapticFeedbackType.Heavy:
                activity.Window.DecorView.RootView.PerformHapticFeedback(FeedbackConstants.KeyboardPress);
                break;
            }
        }
Exemplo n.º 10
0
 internal static void DoHaptic(HapticFeedbackType type)
 {
     try
     {
         // Perform click feedback
         // Use default vibration length
         Vibration.Vibrate(TimeSpan.FromMilliseconds(50));
         // Xamarin.Essentials.HapticFeedback.Perform(type);
     }
     catch (FeatureNotSupportedException ex)
     {
         // Feature not supported on device
     }
     catch (Exception ex)
     {
         // Other error has occurred.
     }
 }
Exemplo n.º 11
0
        public void Run(HapticFeedbackType hapticFeedbackType)
        {
            UIImpactFeedbackGenerator impact = null;

            switch (hapticFeedbackType)
            {
            case HapticFeedbackType.Softy:
                impact = new UIImpactFeedbackGenerator(UIImpactFeedbackStyle.Light);
                break;

            case HapticFeedbackType.Medium:
                impact = new UIImpactFeedbackGenerator(UIImpactFeedbackStyle.Medium);
                break;

            case HapticFeedbackType.Heavy:
                impact = new UIImpactFeedbackGenerator(UIImpactFeedbackStyle.Heavy);
                break;
            }

            impact.Prepare();
            impact.ImpactOccurred();
        }
Exemplo n.º 12
0
        public async void Perform(HapticFeedbackType type)
        {
            try
            {
                if (ApiInformation.IsTypePresent(vibrationDeviceApiType) &&
                    await VibrationDevice.RequestAccessAsync() == VibrationAccessStatus.Allowed)
                {
                    var controller = (await VibrationDevice.GetDefaultAsync())?.SimpleHapticsController;

                    if (controller != null)
                    {
                        var feedback = FindFeedback(controller, ConvertType(type));
                        if (feedback != null)
                        {
                            controller.SendHapticFeedback(feedback);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine($"HapticFeedback Exception: {ex.Message}");
            }
        }
Exemplo n.º 13
0
 static FeedbackConstants ConvertType(HapticFeedbackType type) =>
 type switch
 {
Exemplo n.º 14
0
 static ushort ConvertType(HapticFeedbackType type) =>
 type switch
 {
Exemplo n.º 15
0
 static void PlatformPerform(HapticFeedbackType type)
 => throw ExceptionUtils.NotSupportedOrImplementedException;
Exemplo n.º 16
0
 public static void Perform(HapticFeedbackType type = HapticFeedbackType.Click) =>
 Current.Perform(type);
Exemplo n.º 17
0
 public void Run(HapticFeedbackType hapticFeedbackType)
 {
     //This is a default thing should not be used;
     //throw new System.Exception("Not initialized in device platforms isbrubles");
 }
Exemplo n.º 18
0
 static string ConvertType(HapticFeedbackType type) =>
 type switch
 {
Exemplo n.º 19
0
 public static void Perform(HapticFeedbackType type = HapticFeedbackType.Click) =>
 Default.Perform(type);