Android学习之工具类六:Vibrator震动功能工具类

权限:

import android.content.Context;
import android.os.Vibrator;

/**
 * 震动功能工具类
 *
 * @author linzhiyong
 * @time 2017-01-16 10:11:16
 */
public class VibratorPlayer {

    private Vibrator vibrator;

    public VibratorPlayer(Context context) {
        this.vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
    }

    /**
     * 开始震动
     *
     * @param delay 延时时间
     * @param interval 震动间隔
     * @param isRepeat 是否重复
     */
    public void play(long delay, long interval, boolean isRepeat) {
        long[] pattern = {delay, interval};
        this.vibrator.vibrate(pattern, isRepeat ? 0 : -1);
    }

    /**
     * 停止震动
     */
    public void stop() {
        this.vibrator.cancel();
    }

}


你可能感兴趣的:(android)