Example usage for android.content Context VIBRATOR_SERVICE

List of usage examples for android.content Context VIBRATOR_SERVICE

Introduction

In this page you can find the example usage for android.content Context VIBRATOR_SERVICE.

Prototype

String VIBRATOR_SERVICE

To view the source code for android.content Context VIBRATOR_SERVICE.

Click Source Link

Document

Use with #getSystemService(String) to retrieve a android.os.Vibrator for interacting with the vibration hardware.

Usage

From source file:Main.java

public static void vibrateDevice(Context context, long time) {
    if (context == null)
        return;/*w w  w. java 2  s  . c  o  m*/

    if (time < 100)
        time = 100;
    if (time > 2000)
        time = 200;
    Vibrator v = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
    v.vibrate(time);
}

From source file:Main.java

public static void vibrate(Context context, int duration) {
    if (hasVibrationPermission(context)) {
        ((Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE)).vibrate(duration);
    }/*  ww  w . ja  v a 2s .c om*/
}

From source file:Main.java

public static void vibrate(Context context, long[] pattern, int repeat) {
    Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
    vibrator.vibrate(pattern, repeat);/*from   w  ww  .ja  v  a 2s.co  m*/
}

From source file:Main.java

/**
 * msg shake//from  www . ja v a  2 s .c  om
 * 
 * @param context
 * @param isShake
 */
public static void shake(Context context, boolean isShake) {
    Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
    if (vibrator == null) {
        return;
    }
    if (isShake) {
        vibrator.vibrate(SHAKE_PATTERN, -1);
        return;
    }
    vibrator.cancel();
}

From source file:Main.java

/**
 * msg shake//from   ww w  .  j av a 2 s  .  c o  m
 * 
 * @param context
 * @param isShake
 */
public static void shakeControlMic(Context context, boolean isShake) {
    Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
    if (vibrator == null) {
        return;
    }
    if (isShake) {
        vibrator.vibrate(SHAKE_MIC_PATTERN, -1);
        return;
    }
    vibrator.cancel();
}

From source file:Main.java

/**
 * Vibrates the phone for the desired number of milliseconds. Ensure that the vibration
 * permission is listed in the app's manifest file.
 *
 * @param context/*  w w w . jav  a2  s.  c  om*/
 * @param milliseconds The number of milliseconds to vibrate the phone for
 */
public static void vibratePhone(Context context, long milliseconds) {
    Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
    vibrator.vibrate(milliseconds);
}

From source file:Main.java

public static void setVibrator(Context context, long mms) {
    Vibrator vibe = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
    vibe.vibrate(mms);//ww w  .  j  a v  a2  s .  c o m
}

From source file:Main.java

public static void vibratePattern(Context context, long... pattern) {
    Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
    vibrator.vibrate(pattern, -1);//w ww. j av  a 2s .co  m
}

From source file:Main.java

/**
 * Causes device to vibrate for the given duration (in millis). If duration is set to 0, then it
 * will use the <code>DEFAULT_VIBRATION_DURATION_MS</code>.
 *//*  w  ww. j  a  va  2 s  .c o  m*/
public final static void vibrate(Context context, int duration) {
    if (duration == 0) {
        duration = DEFAULT_VIBRATION_DURATION_MS;
    }
    Vibrator v = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
    v.vibrate(duration);
}

From source file:Main.java

public static void silentAlarm(Context context) {
    if (player != null) {
        Log.i("AlarmHelper", "silented");
        try {// ww w. ja v a 2  s  . c  om
            if (player.isLooping()) {
                player.setLooping(false);
            }
            player.pause();
            player.stop();
            player.release();
        } catch (IllegalStateException e) {
            AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
            am.setStreamVolume(AudioManager.STREAM_ALARM, 0, 0);
        }

        // player.setVolume(0, 0);
        AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
        am.setStreamVolume(AudioManager.STREAM_ALARM, mUserVolume, 0);
    } else {
        Log.i("AlarmHelper", "ring zero");
        AudioManager am = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
        am.setStreamVolume(AudioManager.STREAM_ALARM, 0, 0);
    }

    if (vibrator != null) {
        vibrator.cancel();
    } else {
        vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
        vibrator.cancel();
    }
}