Android 震动模式

震动类

public class VibratorUtil {

    private static final long DEFAULT_VIBRATOR = 100;

    private static Vibrator sVibrator;
    private static Vibrator getVibrator() {
        if (sVibrator == null) {
            sVibrator =
            (Vibrator) AppContext.getAppContext().getSystemService(Service.VIBRATOR_SERVICE);
        }
        return sVibrator;
    }

    public static void defaultVibrate() {
        vibrate(DEFAULT_VIBRATOR);
    }

    public static void fingerPrintVibrate() {
        defaultVibrate();
    }

    /**
     *@param milliseconds 震动的时长,单位是毫秒
     */
    public static void vibrate(long milliseconds) {
        Vibrator vib = getVibrator();
        if (vib != null)
            vib.vibrate(milliseconds);
    }

    /**
     * @param pattern 自定义震动模式
     *  数组中数字的含义依次是[静止时长,震动时长,静止时长,震动时长]
     *  时长的单位是毫秒
     * @param isRepeat 是否反复震动,如果是true,反复震动,如果是false,只震动一次
     */
    public static void vibrate(long[] pattern, boolean isRepeat) {
        Vibrator vib = getVibrator();
        if (vib != null)
            vib.vibrate(pattern, isRepeat ? 1 : -1);
    }

}
上一篇:ASP.NET生命周期详解 [转]


下一篇:# pc端个性化日历实现