private static void VibrateWhenNotified() { if (Preferences.Get("IsVibrate", false)) { var vibrator = (Vibrator)Application.Context.GetSystemService(Context.VibratorService); vibrator.Vibrate(VibrationEffect.CreateWaveform(vibrationPattern, -1)); } }
public void Success() { if (!ShouldVibrate()) { return; } var pause = 50; var action = 80; s_vibrator?.Vibrate(VibrationEffect.CreateWaveform(new long[] { 0, action, pause, action }, -1)); }
private void SetVibrator() { if (IsVibrateOn) { _vibrator = Vibrator.FromContext(this); long[] mVibratePattern = new long[] { 0, 400, 1000, 600, 1000, 800, 1000, 1000 }; if (Build.VERSION.SdkInt >= BuildVersionCodes.O) { var effect = VibrationEffect.CreateWaveform(mVibratePattern, 0); _vibrator?.Vibrate(effect); } else { _vibrator?.Vibrate(mVibratePattern, 0); } } }
public void Feedback(HapticEffect effect, FeedbackMode mode = FeedbackMode.Default) { if (effect == HapticEffect.None || mode == FeedbackMode.Off || (mode == FeedbackMode.Default && Forms9Patch.Feedback.HapticMode == FeedbackMode.Off)) { return; } var hapticEnabled = true; if (mode == FeedbackMode.Default) { hapticEnabled = Android.Provider.Settings.System.GetInt(Android.App.Application.Context.ContentResolver, Android.Provider.Settings.System.HapticFeedbackEnabled) != 0; } if (hapticEnabled && AppEnabled) { if (effect == HapticEffect.Selection) { Settings.Activity.Window.DecorView.PerformHapticFeedback(Android.Views.FeedbackConstants.KeyboardTap); } else if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.O) { VibrationEffect droidEffect = null; switch (effect) { case HapticEffect.LightImpact: droidEffect = VibrationEffect.CreateOneShot(200, 128); break; case HapticEffect.MediumImpact: droidEffect = VibrationEffect.CreateOneShot(200, 196); break; case HapticEffect.HeavyImpact: droidEffect = VibrationEffect.CreateOneShot(200, 255); break; case HapticEffect.ErrorNotification: droidEffect = VibrationEffect.CreateWaveform(new long[] { 0, 200, 100, 200, 100, 200 }, new int[] { 0, 196, 0, 196, 0, 255 }, -1); break; case HapticEffect.WarningNotification: droidEffect = VibrationEffect.CreateWaveform(new long[] { 0, 200, 100, 200 }, new int[] { 0, 196, 0, 255 }, -1); break; case HapticEffect.SuccessNotification: droidEffect = VibrationEffect.CreateWaveform(new long[] { 0, 200, 100, 200 }, new int[] { 0, 255, 0, 196 }, -1); break; case HapticEffect.Long: droidEffect = VibrationEffect.CreateOneShot(800, 255); break; } if (droidEffect != null) { _vibrator.Vibrate(droidEffect); } } else { #pragma warning disable CS0618 // Type or member is obsolete long[] pattern = null; switch (effect) { case HapticEffect.LightImpact: _vibrator.Vibrate(200, Attributes); break; case HapticEffect.MediumImpact: _vibrator.Vibrate(300, Attributes); break; case HapticEffect.HeavyImpact: _vibrator.Vibrate(400, Attributes); break; case HapticEffect.ErrorNotification: pattern = new long[] { 0, 200, 100, 200, 100, 200 }; break; case HapticEffect.WarningNotification: pattern = new long[] { 0, 200, 100, 200 }; break; case HapticEffect.SuccessNotification: pattern = new long[] { 0, 200, 100, 200 }; break; case HapticEffect.Long: _vibrator.Vibrate(800, Attributes); break; } if (pattern != null) { _vibrator.Vibrate(pattern, -1, Attributes); } #pragma warning restore CS0618 // Type or member is obsolete } } }
protected override void OnCreate(Bundle savedInstanceState) { try { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.TwilioCommingVideoCallLayout); Window.AddFlags(WindowManagerFlags.KeepScreenOn); SensorManager = (SensorManager)GetSystemService(SensorService); Proximity = SensorManager.GetDefaultSensor(SensorType.Proximity); CallActivity = this; var dataCallId = Intent?.GetStringExtra("CallID") ?? ""; if (!string.IsNullOrEmpty(dataCallId)) { CallType = Intent?.GetStringExtra("type"); if (CallType == "Twilio_video_call" || CallType == "Twilio_audio_call") { CallId = dataCallId; UserId = Intent?.GetStringExtra("UserID"); Avatar = Intent?.GetStringExtra("avatar"); Name = Intent?.GetStringExtra("name"); FromId = Intent?.GetStringExtra("from_id"); Active = Intent?.GetStringExtra("active"); Time = Intent?.GetStringExtra("time"); Status = Intent?.GetStringExtra("status"); RoomName = Intent?.GetStringExtra("room_name"); TwilioAccessToken = Intent?.GetStringExtra("access_token"); TwilioAccessTokenUser2 = Intent?.GetStringExtra("access_token_2"); } else if (CallType == "Agora_video_call_recieve" || CallType == "Agora_audio_call_recieve") { CallId = dataCallId; UserId = Intent?.GetStringExtra("UserID"); Avatar = Intent?.GetStringExtra("avatar"); Name = Intent?.GetStringExtra("name"); FromId = Intent?.GetStringExtra("from_id"); Active = Intent?.GetStringExtra("active"); Time = Intent?.GetStringExtra("time"); Status = Intent?.GetStringExtra("status"); RoomName = Intent?.GetStringExtra("room_name"); } } UserNameTextView = FindViewById <TextView>(Resource.Id.UsernameTextView); TypeCallTextView = FindViewById <TextView>(Resource.Id.TypecallTextView); UserImageView = FindViewById <ImageView>(Resource.Id.UserImageView); GradientPreView = FindViewById <View>(Resource.Id.gradientPreloaderView); AcceptCallButton = FindViewById <CircleButton>(Resource.Id.accept_call_button); RejectCallButton = FindViewById <CircleButton>(Resource.Id.end_call_button); MessageCallButton = FindViewById <CircleButton>(Resource.Id.message_call_button); StartAnimatedBackground(); AcceptCallButton.Click += AcceptCallButton_Click; RejectCallButton.Click += RejectCallButton_Click; MessageCallButton.Click += MessageCallButton_Click; if (!string.IsNullOrEmpty(Name)) { UserNameTextView.Text = Name; } if (!string.IsNullOrEmpty(Avatar)) { GlideImageLoader.LoadImage(this, Avatar, UserImageView, ImageStyle.CircleCrop, ImagePlaceholders.Drawable); } if (CallType == "Twilio_video_call" || CallType == "Agora_video_call_recieve") { TypeCallTextView.Text = GetText(Resource.String.Lbl_Video_call); } else { TypeCallTextView.Text = GetText(Resource.String.Lbl_Voice_call); } Methods.AudioRecorderAndPlayer.PlayAudioFromAsset("mystic_call.mp3"); Vibrator = (Vibrator)GetSystemService(VibratorService); var vibrate = new long[] { 1000, 1000, 2000, 1000, 2000, 1000, 2000, 1000, 2000, 1000, 2000, 1000, 2000, 1000, 2000, 1000, 2000, 1000, 2000, 1000, 2000, 1000, 2000, 1000, 2000 }; // Vibrate for 500 milliseconds Vibrator.Vibrate(VibrationEffect.CreateWaveform(vibrate, 3)); } catch (Exception e) { Methods.DisplayReportResultTrack(e); } }