@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,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);
}
}
项目:screenrecorder
文件:RecorderService.java
@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();
}
}
项目:smart-asset-iot-android-demo
文件:MainActivity.java
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);
else if (Build.VERSION.SDK_INT >= 26)
vibrator.vibrate(VibrationEffect.createOneshot(50,VibrationEffect.DEFAULT_AMPLITUDE));
else vibrator.vibrate(50);
handler.postDelayed(this,interval);
}
}
项目:RespawnIRC-Android
文件:Undeprecator.java
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);
}
}
项目:kcanotify
文件:KcaUtils.java
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)));
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。