@Override public void run() { if (isPlaying) { handler.postDelayed(this, interval); if (emphasisIndex >= emphasisList.size()) emphasisIndex = 0; boolean isEmphasis = emphasisList.get(emphasisIndex); if (listener != null) listener.onTick(isEmphasis, emphasisIndex); emphasisIndex++; if (soundId != -1) soundPool.play(soundId, isEmphasis ? 1.0f : 0.2f, isEmphasis ? 1.0f : 0.2f, 0, 0, 1.0f); else if (Build.VERSION.SDK_INT >= 26) vibrator.vibrate(VibrationEffect.createOneShot(isEmphasis ? 50 : 20, VibrationEffect.DEFAULT_AMPLITUDE)); else vibrator.vibrate(isEmphasis ? 50 : 20); } }
@Override public void onShake() { if (!isRecording) { Vibrator vibrate = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); getManager().cancel(Const.SCREEN_RECORDER_WAITING_FOR_SHAKE_NOTIFICATION_ID); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) vibrate.vibrate(500); else VibrationEffect.createOneShot(500, 255); startRecording(); Toast.makeText(this, "Rec start", Toast.LENGTH_SHORT).show(); } else { Intent recordStopIntent = new Intent(this, RecorderService.class); recordStopIntent.setAction(Const.SCREEN_RECORDING_STOP); startService(recordStopIntent); Toast.makeText(this, "Rec stop", Toast.LENGTH_SHORT).show(); mShakeDetector.stop(); } }
private void vibrate(long millis) { Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) { if (v != null) { v.vibrate(millis); } } else { VibrationEffect effect = VibrationEffect.createOneShot(millis, VibrationEffect.DEFAULT_AMPLITUDE); v.vibrate(effect); } }
@Override public void run() { if (isPlaying) { if (soundId != -1) soundPool.play(soundId, 1.0f, 1.0f, 0, 0, 1.0f); else if (Build.VERSION.SDK_INT >= 26) vibrator.vibrate(VibrationEffect.createOneShot(50, VibrationEffect.DEFAULT_AMPLITUDE)); else vibrator.vibrate(50); handler.postDelayed(this, interval); } }
public static void vibratorVibrate(Vibrator vibratorService, long[] pattern, int repeat) { if (Build.VERSION.SDK_INT >= 26) { vibratorService.vibrate(VibrationEffect.createWaveform(pattern, repeat)); } else { //noinspection deprecation vibratorService.vibrate(pattern, repeat); } }
public static void doVibrate(Vibrator v, int time) { if (Build.VERSION.SDK_INT >= 26) { v.vibrate(VibrationEffect.createOneShot(time, VibrationEffect.DEFAULT_AMPLITUDE)); } else { v.vibrate(time); } }
@SuppressWarnings("deprecation") @TargetApi(android.os.Build.VERSION_CODES.O) private static void vibrate(Vibrator v) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { v.vibrate(VibrationEffect.createOneShot(500, VibrationEffect.DEFAULT_AMPLITUDE)); } else { v.vibrate(500); } }
@TargetApi(AndroidHelper.API_26) @RequiresPermission(Manifest.permission.VIBRATE) public static void vibrate26(final long[] durations, final boolean repeat) { SystemServices.vibrator().vibrate(VibrationEffect.createWaveform(durations, (repeat ? DO_REPEAT : DO_NOT_REPEAT))); }