public void SendHapticFeedback(SimpleHapticsControllerFeedback feedback) { if (feedback is null) { throw new ArgumentNullException(nameof(feedback)); } if (ContextHelper.Current == null) { throw new InvalidOperationException($"Context must be initialized before {nameof(SendHapticFeedback)} is called."); } try { var activity = (Activity)ContextHelper.Current; var androidFeedback = FeedbackToAndroidFeedback(feedback); activity.Window?.DecorView.PerformHapticFeedback(androidFeedback); } catch (Exception ex) { if (this.Log().IsEnabled(LogLevel.Error)) { this.Log().LogError($"Could not send haptic feedback: {ex}"); } } }
public void SendHapticFeedback(SimpleHapticsControllerFeedback feedback) { if (feedback is null) { throw new ArgumentNullException(nameof(feedback)); } if (ContextHelper.Current == null) { throw new InvalidOperationException($"Context must be initialized before {nameof(SendHapticFeedback)} is called."); } try { var activity = (Activity)ContextHelper.Current; var androidFeedback = FeedbackToAndroidFeedback(feedback); bool hapticFeedbackEnabled = Settings.System.GetInt(activity.ContentResolver, Settings.System.HapticFeedbackEnabled, 0) != 0; if (hapticFeedbackEnabled) { var executed = activity.Window?.DecorView.PerformHapticFeedback(androidFeedback) ?? false; if (!executed && PhoneVibrationDevice.GetDefault() is { } vibrationDevice) { // Fall back to VibrationDevice vibrationDevice.Vibrate(feedback.Duration); } } } catch (Exception ex) { if (this.Log().IsEnabled(LogLevel.Error)) { this.Log().LogError($"Could not send haptic feedback: {ex}"); } } }
public void SendHapticFeedback(SimpleHapticsControllerFeedback feedback) { if (feedback is null) { throw new ArgumentNullException(nameof(feedback)); } _simpleHapticsControllerExtension.SendHapticFeedback(feedback); }
public void SendHapticFeedback(SimpleHapticsControllerFeedback feedback) { if (feedback is null) { throw new ArgumentNullException(nameof(feedback)); } var impactStyle = FeedbackToImpactStyle(feedback); using var impact = new UIImpactFeedbackGenerator(impactStyle); impact.Prepare(); impact.ImpactOccurred(); }
public void SendHapticFeedback(SimpleHapticsControllerFeedback feedback) { if (feedback is null) { throw new ArgumentNullException(nameof(feedback)); } if (_vibrationDevice == null) { throw new InvalidOperationException("Vibration is not supported"); } _vibrationDevice.Vibrate(feedback.Duration); }
private static FeedbackConstants FeedbackToAndroidFeedback(SimpleHapticsControllerFeedback feedback) { if (feedback.Waveform == KnownSimpleHapticsControllerWaveforms.Click) { return(FeedbackConstants.ContextClick); } else if (feedback.Waveform == KnownSimpleHapticsControllerWaveforms.Press) { return(FeedbackConstants.LongPress); } else { throw new NotSupportedException("Unsupported feedback waveform"); } }
private UIImpactFeedbackStyle FeedbackToImpactStyle(SimpleHapticsControllerFeedback feedback) { if (feedback.Waveform == KnownSimpleHapticsControllerWaveforms.Click) { return(UIImpactFeedbackStyle.Light); } else if (feedback.Waveform == KnownSimpleHapticsControllerWaveforms.Press) { return(UIImpactFeedbackStyle.Medium); } else { throw new NotSupportedException("Unsupported feedback waveform"); } }
public void SendHapticFeedback(SimpleHapticsControllerFeedback feedback) { if (feedback is null) { throw new ArgumentNullException(nameof(feedback)); } if (feedback.Waveform != KnownSimpleHapticsControllerWaveforms.Press) { throw new NotSupportedException("Unsupported feedback waveform"); } NSHapticFeedbackManager.DefaultPerformer.PerformFeedback( NSHapticFeedbackPattern.Generic, NSHapticFeedbackPerformanceTime.Default); }