List of usage examples for android.os Vibrator vibrate
@RequiresPermission(android.Manifest.permission.VIBRATE) public void vibrate(VibrationEffect vibe, AudioAttributes attributes)
From source file:Main.java
/** * msg shake/*from w ww .ja v a 2s . co 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:nth.com.ares.utils.Utils.java
public static void vibrate(long[] pattern, Context context) { // Start without a delay // Vibrate for 100 milliseconds // Sleep for 1000 milliseconds // long[] pattern = {0, 100, 1000}; // The first value indicates the number of milliseconds to wait before turning the vibrator ON: 0=Start without a delay // Each element then alternates between vibrate, sleep, vibrate, sleep... // long[] pattern = {0, 100, 1000, 300, 200, 100, 500, 200, 100}; Vibrator v1 = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE); // The '-1' here means to vibrate once, as '-1' is out of bounds in the pattern array // '0' here means to repeat indefinitely // '0' is actually the index at which the pattern keeps repeating from (the start) // To repeat the pattern from any other point, you could increase the index, e.g. '1' v1.vibrate(pattern, -1); }
From source file:jorge.tolentino.empty.Empty.java
/** * Vibrates the device with a given pattern. * * @param pattern Pattern with which to vibrate the device. * Pass in an array of longs that * are the durations for which to * turn on or off the vibrator in * milliseconds. The first value * indicates the number of milliseconds * to wait before turning the vibrator * on. The next value indicates the * number of milliseconds for which * to keep the vibrator on before * turning it off. Subsequent values * alternate between durations in * milliseconds to turn the vibrator * off or to turn the vibrator on. * * @param repeat Optional index into the pattern array at which * to start repeating, or -1 for no repetition (default). *//*from w ww . ja v a2 s . c om*/ public void vibrateWithPattern(long[] pattern, int repeat) { Vibrator vibrator = (Vibrator) this.cordova.getActivity().getSystemService(Context.VIBRATOR_SERVICE); vibrator.vibrate(pattern, repeat); }
From source file:com.hodor.company.areminder.service.TimerService.java
private void showAlarm(int category) { final Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); long[] pattern = { 0, getResources().getInteger(R.integer.vibration_duration) }; v.vibrate(pattern, -1); Intent intent = new Intent(this, MainActivity.class).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) .putExtra(MainActivity.ACTION_REMOVE_TIMER, 1); startActivity(intent);/*from w w w .ja va2 s. c o m*/ NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this); Notification notification = NotificationCenter.getNotificationCenter(this) .buildFinishNotification(category); notificationManager.notify(MainActivity.END_NOTIFICATION_ID, notification); }
From source file:com.bufarini.reminders.AlarmReceiver.java
@Override public void onReceive(final Context context, final Intent intent) { final String action = intent.getAction(); if (Log.LOGV) Log.v("AlarmInitReceiver \"" + action + "\""); final PendingResult result = goAsync(); final WakeLock wakelock = AlarmAlertWakeLock.createPartialWakeLock(context); wakelock.acquire();//from w ww . j a v a2 s .c om AsyncHandler.post(new Runnable() { @Override public void run() { try { String alarmActionName = context.getResources().getString(R.string.intent_action_alarm); if (Intent.ACTION_BOOT_COMPLETED.equals(action)) { SharedPreferences prefs = context.getSharedPreferences(Reminders.class.getName(), Context.MODE_PRIVATE); String accountName = prefs.getString(ListManager.PREF_ACCOUNT_NAME, null); if (Log.LOGV) Log.v("AlarmInitReceiver accountName = \"" + accountName + "\""); if (accountName != null && !accountName.equals("")) setReminders(context, accountName); } else if (alarmActionName.equals(action)) { showNotification(context, intent); Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE); vibrator.vibrate(VIBRATE_PATTERN, 1); } result.finish(); if (Log.LOGV) Log.v("AlarmInitReceiver finished"); } finally { wakelock.release(); } } }); }
From source file:de.hshannover.f4.trust.ironcontrol.logic.ResultNotificationManager.java
private void vibrator() { Vibrator mVibratorService = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE); mVibratorService.vibrate(new long[] { 0, 250, 500, 500 }, -1); }
From source file:com.daiv.android.twitter.services.SendScheduledTweet.java
public void finishedTweetingNotification() { try {/* w w w.j a v a 2s.c om*/ NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(MainActivity.sContext) .setSmallIcon(R.drawable.ic_stat_icon) .setContentTitle(getResources().getString(R.string.tweet_success)).setOngoing(false) .setTicker(getResources().getString(R.string.tweet_success)); if (AppSettings.getInstance(this).vibrate) { Log.v(TAG + "Test_vibrate", "vibrate on compose"); Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); long[] pattern = { 0, 50, 500 }; v.vibrate(pattern, -1); } stopForeground(true); NotificationManager mNotificationManager = (NotificationManager) MainActivity.sContext .getSystemService(Context.NOTIFICATION_SERVICE); mNotificationManager.notify(6, mBuilder.build()); // cancel it immediately, the ticker will just go off mNotificationManager.cancel(6); } catch (Exception e) { // not attached to activity } }
From source file:com.mattprecious.prioritysms.receiver.AlarmReceiver.java
private void doNotify(Context context, BaseProfile profile) { AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); MediaPlayer mediaPlayer = new MediaPlayer(); try {//from www. ja va 2s .co m if (audioManager.getRingerMode() == AudioManager.RINGER_MODE_NORMAL || profile.isOverrideSilent()) { mediaPlayer.setWakeMode(context, PowerManager.PARTIAL_WAKE_LOCK); mediaPlayer.setAudioStreamType( profile.isOverrideSilent() ? AudioManager.STREAM_ALARM : AudioManager.STREAM_NOTIFICATION); mediaPlayer.setDataSource(context, profile.getRingtone()); mediaPlayer.prepare(); mediaPlayer.start(); if (profile.isVibrate()) { Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE); vibrator.vibrate(VIBRATE_PATTERN, -1); } } } catch (IllegalArgumentException e) { Log.e(TAG, "failed to play audio", e); } catch (IOException e) { Log.e(TAG, "failed to play audio", e); } }
From source file:com.daiv.android.twitter.services.SendQueue.java
public void finishedTweetingNotification() { try {//www.j a v a 2 s.c o m NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(MainActivity.sContext) .setSmallIcon(R.drawable.ic_stat_icon) .setContentTitle(getResources().getString(R.string.tweet_success)).setOngoing(false) .setTicker(getResources().getString(R.string.tweet_success)); if (AppSettings.getInstance(this).vibrate) { Log.v(TAG + "Test_vibrate", "vibrate on compose"); Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); long[] pattern = { 0, 50, 500 }; v.vibrate(pattern, -1); } stopForeground(true); NotificationManager mNotificationManager = (NotificationManager) MainActivity.sContext .getSystemService(Context.NOTIFICATION_SERVICE); mNotificationManager.notify(6, mBuilder.build()); // cancel it immediately, the ticker will just go off mNotificationManager.cancel(6); sendMessage(); } catch (Exception e) { // not attached to activity } }
From source file:com.klinker.android.twitter.services.SendQueue.java
public void finishedTweetingNotification() { try {/*from w w w.j av a 2s .c o m*/ NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(MainActivity.sContext) .setSmallIcon(R.drawable.ic_stat_icon) .setContentTitle(getResources().getString(R.string.tweet_success)).setOngoing(false) .setTicker(getResources().getString(R.string.tweet_success)); if (AppSettings.getInstance(this).vibrate) { Log.v("talon_vibrate", "vibrate on compose"); Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); long[] pattern = { 0, 50, 500 }; v.vibrate(pattern, -1); } stopForeground(true); NotificationManager mNotificationManager = (NotificationManager) MainActivity.sContext .getSystemService(Context.NOTIFICATION_SERVICE); mNotificationManager.notify(6, mBuilder.build()); // cancel it immediately, the ticker will just go off mNotificationManager.cancel(6); } catch (Exception e) { // not attached to activity } }