// Get instance of Vibrator from current Context Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); // Start without a delay // Vibrate for 100 milliseconds // Sleep for 1000 milliseconds long[] pattern = {0, 100, 1000}; // The '0' here means to repeat indefinitely // '0' is actually the index at which the pattern keeps repeating from (the start) // To repeat the pattern from any other point, you could increase the index, e.g. '1' v.vibrate(pattern, 0);
// Get instance of Vibrator from current Context Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); // Start without a delay // Each element then alternates between vibrate, sleep, vibrate, sleep... long[] pattern = {0, 100, 1000, 300, 200, 100, 500, 200, 100}; // The '-1' here means to vibrate once, as '-1' is out of bounds in the pattern array v.vibrate(pattern, -1);
// Get instance of Vibrator from current Context Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); // Vibrate for 400 milliseconds v.vibrate(400);
@Override public void vibrate (long[] pattern, int repeat) { vibrator.vibrate(pattern, repeat); }
@Override public void vibrate (int milliseconds) { vibrator.vibrate(milliseconds); }
@Override public void vibrate (int milliseconds) { vibrator.vibrate(milliseconds); }
@Override public void vibrate (long[] pattern, int repeat) { vibrator.vibrate(pattern, repeat); }
// Get instance of Vibrator from current Context Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); // Vibrate for 300 milliseconds v.vibrate(300);
Vibrator vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE); long[] vibrationPattern = {0, 500, 50, 300}; //-1 - don't repeat final int indexInPatternToRepeat = -1; vibrator.vibrate(vibrationPattern, indexInPatternToRepeat);
@SuppressLint("MissingPermission") @Override public void onClick(View v) { if (isVibrateOn) { mVibrator.vibrate(vibrateIntensity); } boolean isSlideChangingAllowed = handleBeforeSlideChanged(); // Check if changing to the next slide is allowed if (isSlideChangingAllowed) { // Changing slide is handled by permission result if (!checkAndRequestPermissions()) { changeSlide(false); } } else { handleIllegalSlideChangeAttempt(); } } }
@SuppressLint("MissingPermission") @Override public void onClick(@NonNull View v) { if (isVibrateOn) { mVibrator.vibrate(vibrateIntensity); } boolean isSlideChangingAllowed = handleBeforeSlideChanged(); if (isSlideChangingAllowed) { // Changing slide is handled by permission result if (!checkAndRequestPermissions()) { changeSlide(true); } } else { handleIllegalSlideChangeAttempt(); } } });
private void playBeepSoundAndVibrate() { if (playBeep && mediaPlayer != null) { mediaPlayer.start(); } if (vibrate) { Vibrator vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE); vibrator.vibrate(VIBRATE_DURATION); } }
private void playBeepSoundAndVibrate() { if (playBeep && mediaPlayer != null) { mediaPlayer.start(); } if (vibrate) { Vibrator vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE); vibrator.vibrate(VIBRATE_DURATION); } }
@SuppressLint("MissingPermission") public synchronized void playBeepSoundAndVibrate() { if (beepEnabled) { playBeepSound(); } if (vibrateEnabled) { Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE); if (vibrator != null) { vibrator.vibrate(VIBRATE_DURATION); } } }
private void vibrate(long duration) { Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); long[] pattern = { 0, duration }; vibrator.vibrate(pattern, -1); }
@SuppressLint("MissingPermission") @Override public void onClick(@NonNull View v) { if (isVibrateOn) { mVibrator.vibrate(vibrateIntensity); } onSkipPressed(mPagerAdapter.getItem(pager.getCurrentItem())); } });
private void playBeepSoundAndVibrate() { if (playBeep && mediaPlayer != null) { mediaPlayer.start(); } if (vibrate) { Vibrator vibrator = (Vibrator) getActivity().getSystemService(getActivity().VIBRATOR_SERVICE); vibrator.vibrate(VIBRATE_DURATION); } }
@Test public void vibratePattern() { long[] pattern = new long[] { 0, 200 }; vibrator.vibrate(pattern, 1); assertThat(shadowOf(vibrator).isVibrating()).isTrue(); assertThat(shadowOf(vibrator).getPattern()).isEqualTo(pattern); assertThat(shadowOf(vibrator).getRepeat()).isEqualTo(1); }
@Test public void cancelled() { vibrator.vibrate(5000); assertThat(shadowOf(vibrator).isVibrating()).isTrue(); assertThat(shadowOf(vibrator).isCancelled()).isFalse(); vibrator.cancel(); assertThat(shadowOf(vibrator).isVibrating()).isFalse(); assertThat(shadowOf(vibrator).isCancelled()).isTrue(); } }
@Test public void vibrateMilliseconds() { vibrator.vibrate(5000); assertThat(shadowOf(vibrator).isVibrating()).isTrue(); assertThat(shadowOf(vibrator).getMilliseconds()).isEqualTo(5000L); Robolectric.getForegroundThreadScheduler().advanceToNextPostedRunnable(); assertThat(shadowOf(vibrator).isVibrating()).isFalse(); }