Java 类android.os.VibrationEffect 实例源码

项目:Metronome-Android    文件:MetronomeService.java   
@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);
    }
}
项目: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);
    }
}
项目:Metronome-Android    文件:MetronomeService.java   
@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);
    }
}
项目: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);
    }
}
项目:TumCampusApp    文件:ChatActivity.java   
@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);
    }
}
项目:android_Skeleton    文件:VibratorHelper.java   
@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)));
}