List of usage examples for android.os Vibrator vibrate
@RequiresPermission(android.Manifest.permission.VIBRATE) public void vibrate(VibrationEffect vibe, AudioAttributes attributes)
From source file:org.ciasaboark.tacere.service.EventSilencerService.java
private void vibrate() { BetaPrefs betaPrefs = new BetaPrefs(this); if (betaPrefs.getDisableVibration()) { Log.d(TAG, "vibrations disabled"); } else {/*from ww w . j av a 2 s . c o m*/ Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); long[] pattern = { 0, 500, 200, 500 }; vibrator.vibrate(pattern, -1); } }
From source file:nl.johndekroon.dma.GCMIntentService.java
@Override protected void onMessage(Context context, Intent intent) { prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext()); prefs.getBoolean("muteAll", false); String data = intent.getStringExtra("message"); JSONObject datajson;/*w w w . j a v a 2s . c o m*/ try { datajson = new JSONObject(data); String message = datajson.get("message").toString(); String type = datajson.get("type").toString(); String monitor = datajson.get("monitor").toString(); DatabaseDAO datasource = new DatabaseDAO(this); datasource.open(); //On getting a warning or an OK if (type.equals("WARNING") || type.equals("OK")) { if (prefs.getBoolean("muteAll", false) != true) { Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); long[] pattern = { 0, 500, 200, 200 }; // Only perform this pattern one time (-1 means "do not repeat") v.vibrate(pattern, -1); Uri alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); if (alert == null) { // I can't see this ever being null (as always have a default notification) but just incase // alert backup is null, using 2nd backup alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM); } Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), alert); r.play(); } datasource.updateScenario(monitor, type); generateNotification(context, message); } //on receiving an error else if (type.equals("ERROR")) { System.out.println("bbbrrrrrrr brrrrrr"); Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); long[] pattern = { 0, 1000, 50, 200, 50, 200, 50, 1200 }; // Only perform this pattern one time (-1 means "do not repeat") v.vibrate(pattern, -1); if (prefs.getBoolean("muteAll", false) != true) { Uri alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); if (alert == null) { alert = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_ALARM); } Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), alert); r.play(); } datasource.updateScenario(monitor, type); generateNotification(context, message); } //on register, make a new scenario. else if (type.equals("REGISTER")) { datasource.createScenario(monitor); } System.out.println(intent.getStringExtra("message")); Log.i(TAG, "Received message"); //No idea why this part isn't working. It should. // if(type.equals("ERROR")) // { // displayMessage(context, message, "error"); // } // else // { displayMessage(context, message); // } } catch (JSONException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } }
From source file:com.daiv.android.twitter.services.SendTweet.java
public void finishedTweetingNotification() { // sometimes it just would keep making the notification for some reason... // so delay it to insure it clears everything correctly try {//w ww . jav a 2s . c o m Thread.sleep(500); } catch (Exception e) { } try { 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(getApplicationContext()).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.klinker.android.twitter.services.SendTweet.java
public void finishedTweetingNotification() { // sometimes it just would keep making the notification for some reason... // so delay it to insure it clears everything correctly try {//from w ww. ja va 2 s . c o m Thread.sleep(500); } catch (Exception e) { } try { 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(getApplicationContext()).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 } }
From source file:com.nxp.nfc_demo.activities.MainActivity.java
@Override protected void onNewIntent(Intent nfc_intent) { super.onNewIntent(nfc_intent); // Set the pattern for vibration long pattern[] = { 0, 100 }; // Set the initial auth parameters mAuthStatus = AuthStatus.Disabled.getValue(); mPassword = null;//from ww w .j a va 2 s .c o m // Vibrate on new Intent Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); vibrator.vibrate(pattern, -1); doProcess(nfc_intent); }
From source file:com.sir_m2x.messenger.activities.ChatWindowPager.java
@Override public void onSensorChanged(final SensorEvent event) { float x = event.values[0]; float y = event.values[1]; float z = event.values[2]; this.mAccelLast = this.mAccelCurrent; this.mAccelCurrent = (float) Math.sqrt((x * x + y * y + z * z)); float delta = this.mAccelCurrent - this.mAccelLast; this.mAccel = this.mAccel * 0.9f + delta; // perform low-cut filter if (this.mAccel > Preferences.shakeSensitivity) if (doBuzz()) { Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); v.vibrate(new long[] { 0, 100, 200, 100, 200, 100 }, -1); }/*from w ww . ja va 2 s . com*/ }
From source file:com.example.bluetooth_faster_connection.MainActivity.java
public void vibrate(long[] pattern, int repeat) { Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); v.vibrate(pattern, repeat); }
From source file:pro.dbro.bart.UsherService.java
private void makeLegCountdownTimer(long msUntilNext) { //make sure we don't leak any timers if (timer != null) timer.cancel();//from w w w. j a v a2s.co m // Make a new timer to expire EVENT_PADDING_MS before event timer = new CountDownTimer(msUntilNext - EVENT_PADDING_MS, UPDATE_INTERVAL_MS) { //new CountDownTimer(5000, 1000){ @Override public void onFinish() { // TODO Auto-generated method stub Vibrator v = (Vibrator) getSystemService(c.VIBRATOR_SERVICE); long[] vPattern = { 0, 400, 300, 400, 300, 400, 300, 400 }; v.vibrate(vPattern, -1); //if(didBoard) // if we've boarded, we're handling the last leg // currentLeg ++; didBoard = !didBoard; // Our next move is departing the final leg train if ((usherRoute.legs.size() == currentLeg + 1) && !didBoard) { NotificationCompat.Builder builder = new NotificationCompat.Builder(c); if (contentIntent == null) { Log.d("ContentIntent", "was null"); setContentIntent(); } builder.setContentIntent(contentIntent).setSmallIcon(R.drawable.ic_launcher_notification) //.setLargeIcon(BitmapFactory.decodeResource(res, R.drawable.some_big_img)) .setWhen(0).setTicker("This is your stop! Take care!"); notification = builder.getNotification(); mNM.notify(NOTIFICATION, notification); //TheActivity.removeStopServiceText(); stopSelf(); } // Our next move is departing the current leg's train else if (didBoard) { //Set timer for this leg's disembark time Date now = new Date(); long msUntilNext = ((((leg) usherRoute.legs.get(currentLeg)).disembarkTime.getTime() - now.getTime())); //Log.v("UsherState","leg: "+ String.valueOf(currentLeg)+ " / "+String.valueOf(usherRoute.legs.size())+" Boarded. Next: "+String.valueOf(msUntilNext)+"ms"); updateNotification(true); makeLegCountdownTimer(msUntilNext); // this cancels current timer } // Our next move is boarding the next leg's train else { currentLeg++; Date now = new Date(); long msUntilNext = ((((leg) usherRoute.legs.get(currentLeg)).boardTime.getTime() - now.getTime())); //Log.v("UsherState","leg: "+ String.valueOf(currentLeg)+ " / "+String.valueOf(usherRoute.legs.size())+" Waiting. Next: "+String.valueOf(msUntilNext)+"ms"); updateNotification(true); makeLegCountdownTimer(msUntilNext); } } @Override public void onTick(long arg0) { updateNotification(false); } }.start(); //timer.start(); // Set Reminder timer REMINDER_PADDING_MS ms before event if (msUntilNext > (REMINDER_PADDING_MS + 30 * 1000)) { // if next event is more than 30 seconds + REMINDER_PADDING_MS out, set reminder //avoid leaking timer if (reminderTimer != null) reminderTimer.cancel(); reminderTimer = new CountDownTimer(msUntilNext - REMINDER_PADDING_MS, msUntilNext - REMINDER_PADDING_MS) { @Override public void onFinish() { // TODO: Is this a good time for updating? //requestDataUpdate(); updateNotification(true); Vibrator v = (Vibrator) getSystemService(c.VIBRATOR_SERVICE); long[] vPattern = { 0, 400, 300, 400 }; v.vibrate(vPattern, -1); } @Override public void onTick(long millisUntilFinished) { // TODO Auto-generated method stub } }.start(); } }
From source file:com.googlecode.mindbell.accessors.ContextAccessor.java
/** * Vibrate with the requested vibration pattern. *//*ww w .ja v a2s.c o m*/ private void startVibration() { Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE); vibrator.vibrate(prefs.getVibrationPattern(), -1); }
From source file:com.sean.takeastand.alarmprocess.AlarmService.java
private void updateNotification() { /*if (!bRepeatingAlarmStepCheck) { mNotifTimePassed++;/*from www . ja v a2 s . co m*/ } Log.i(TAG, "time since first notification: " + mNotifTimePassed + setMinutes(mNotifTimePassed));*/ NotificationManager notificationManager = (NotificationManager) this .getSystemService(Context.NOTIFICATION_SERVICE); PendingIntent[] pendingIntents = makeNotificationIntents(); RemoteViews rvRibbon = new RemoteViews(getPackageName(), R.layout.stand_notification); rvRibbon.setOnClickPendingIntent(R.id.btnStood, pendingIntents[1]); rvRibbon.setTextViewText(R.id.notificationTimeStamp, notificationClockTime); /*rvRibbon.setTextViewText(R.id.stand_up_minutes, mNotifTimePassed + setMinutes(mNotifTimePassed)); rvRibbon.setTextViewText(R.id.topTextView, getString(R.string.stand_up_time_up));*/ NotificationCompat.Builder alarmNotificationBuilder = new NotificationCompat.Builder(this); alarmNotificationBuilder.setContent(rvRibbon); alarmNotificationBuilder.setContentIntent(pendingIntents[0]).setAutoCancel(false) .setTicker(getString(R.string.stand_up_time_low)).setSmallIcon(R.drawable.ic_notification_small) .setContentTitle("Take A Stand ") //.setContentText("Mark Stood\n" + mNotifTimePassed + setMinutes(mNotifTimePassed)) .extend(new NotificationCompat.WearableExtender().addAction( new NotificationCompat.Action.Builder(R.drawable.ic_action_done, "Stood", pendingIntents[1]) .build()) .setContentAction(0).setHintHideIcon(true) // .setBackground(BitmapFactory.decodeResource(getResources(), R.drawable.alarm_schedule_passed)) ); boolean[] alertType; if (mCurrentAlarmSchedule != null) { alertType = mCurrentAlarmSchedule.getAlertType(); } else { alertType = Utils.getDefaultAlertType(this); } if ((alertType[0])) { alarmNotificationBuilder.setLights(238154000, 1000, 4000); } if (Utils.getRepeatAlerts(this)) { if (alertType[1]) { boolean bUseLastStepCounters = false; if (!bRepeatingAlarmStepCheck) { bRepeatingAlarmStepCheck = true; bUseLastStepCounters = UseLastStepCounters(null); } if (!bUseLastStepCounters) { bRepeatingAlarmStepCheck = false; alarmNotificationBuilder.setVibrate(mVibrationPattern); AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); if (audioManager.getMode() == AudioManager.RINGER_MODE_SILENT && Utils.getVibrateOverride(this)) { Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); v.vibrate(mVibrationPattern, -1); } } } if (alertType[2]) { Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); alarmNotificationBuilder.setSound(soundUri); } } Notification alarmNotification = alarmNotificationBuilder.build(); notificationManager.notify(R.integer.AlarmNotificationID, alarmNotification); }