List of usage examples for android.content Context VIBRATOR_SERVICE
String VIBRATOR_SERVICE
To view the source code for android.content Context VIBRATOR_SERVICE.
Click Source Link
From source file:com.glennbech.trafikkinfo.fragments.DashboardFragment.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //To change body of overridden methods use File | Settings | File Templates. myVib = (Vibrator) getActivity().getSystemService(Context.VIBRATOR_SERVICE); }
From source file:il.ac.shenkar.todos.notifications.NotificationService.java
@Override public void onHandleIntent(Intent intent) { taskListModel = TaskList.getSingletonObject(this); // Vibrate the mobile phone Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); //vibrator.vibrate(vibrationTime); vibrator.vibrate(vibrationTime);//from ww w . j a v a 2s .c o m taskListModel.getDataBase().open(); String[] tokens = intent.getStringExtra("description").split(","); taskId = Integer.parseInt(tokens[0]); String title = tokens[1]; String windowTitle = null; String toSend = null; Task triggeredTask = null; boolean alarmRepeating = true; // check if alert was triggered by the location alert if (title.equals("GPS location nearby !")) { alarmType = "GPS"; alarmRepeating = false; taskId = intent.getIntExtra("Id", 0); windowTitle = "GPS location nearby !"; toSend = "Title: " + tokens[3] + "\n\nLocation: " + tokens[2]; triggeredTask = Utils.findTaskById(this, taskId); if (triggeredTask != null) { // remove the alarm new TaskAlarms(this).cancelProximityAlert(taskId, triggeredTask.getTaskTitle()); taskListModel.getDataBase().disableTaskLocationAlert(taskId); } } else // triggered by time alert { alarmType = "Time"; windowTitle = "Notification"; toSend = "Title: " + title + "\n\nDescription: " + tokens[2]; triggeredTask = Utils.findTaskById(this, taskId); if (triggeredTask != null) { String taskNotification = triggeredTask.getDate(); // checks if the alarm has an interval if (!taskNotification.contains("(")) { alarmRepeating = false; new TaskAlarms(this).cancelAlarm(taskId, triggeredTask.getTaskTitle()); taskListModel.getDataBase().disableTaskNotification(taskId); } } } // Prepare intent which is triggered if the // notification is selected Intent myIntent = new Intent(this, NotificationReceiverActivity.class); myIntent.putExtra("windowTitle", windowTitle); myIntent.putExtra("taskContent", toSend); PendingIntent pIntent = PendingIntent.getActivity(this, taskId, myIntent, PendingIntent.FLAG_UPDATE_CURRENT); // Build notification Notification noti = new Notification.Builder(this).setContentTitle(title).setContentText(tokens[2]) .setSmallIcon(R.drawable.app_icon).setContentIntent(pIntent).build(); NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); // Hide the notification after its selected noti.flags |= Notification.FLAG_AUTO_CANCEL; noti.flags |= Notification.FLAG_SHOW_LIGHTS; noti.ledARGB = 0xff00ffff; noti.ledOnMS = 300; noti.ledOffMS = 1000; if (Utils.IS_DEFAULT_SOUND) { //To play the default sound with your notification: noti.defaults |= Notification.DEFAULT_SOUND; } else { new MediaPlayerHandler(this).playAudio(Utils.LOUD_NOTIFICATION__SOUND); } notificationManager.notify(taskId, noti); if (!alarmRepeating) { // brodcast a message to main activity messageToActivity(); } }
From source file:com.vibrationapps.Vibration.java
/** * Executes the request and returns PluginResult. * * @param action The action to execute. * @param args JSONArray of arguments for the plugin. * @param callbackContext The callback context used when calling back into JavaScript. * @return True when the action was valid, false otherwise. *//* w w w. j av a 2 s . c o m*/ public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { Vibrator vibra = (Vibrator) cordova.getActivity().getSystemService(Context.VIBRATOR_SERVICE); if (action.equals("vibrate")) { vibra.vibrate(args.getLong(0)); } else if (action.equals("vibrateArr")) { JSONArray jsonArray = (JSONArray) args.getJSONArray(0); long[] list = new long[jsonArray.length()]; if (jsonArray != null) { int len = jsonArray.length(); for (int i = 0; i < len; i++) { list[i] = jsonArray.getLong(i); } } vibra.vibrate(list, args.getInt(1)); } else if (action.equals("cancel")) { vibra.cancel(); } else if (action.equals("hasVibrator")) { } else { return false; } // Only alert and confirm are async. callbackContext.success(); return true; }
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);// w ww .j a va 2s .c om Intent intent = new Intent(this, MainActivity.class).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) .putExtra(MainActivity.ACTION_REMOVE_TIMER, 1); startActivity(intent); NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this); Notification notification = NotificationCenter.getNotificationCenter(this) .buildFinishNotification(category); notificationManager.notify(MainActivity.END_NOTIFICATION_ID, notification); }
From source file:com.cybrosys.basic.EventListener.java
public void vibrate() { SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(PalmCalcActivity.ctx); Boolean isVibe = sharedPrefs.getBoolean("prefVibe", false); Vibrator vibe = (Vibrator) PalmCalcActivity.ctx.getSystemService(Context.VIBRATOR_SERVICE); if (isVibe) { vibe.vibrate(100);/*w ww. java 2 s . c o m*/ } }
From source file:org.ohmage.appwidget.StressButtonService.java
@Override protected void onHandleIntent(Intent intent) { Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); vibrator.vibrate(100);// w ww . j a v a 2 s .com SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); Calendar now = Calendar.getInstance(); String launchTime = dateFormat.format(now.getTime()); final SharedPreferencesHelper preferencesHelper = new SharedPreferencesHelper(this); if (preferencesHelper.isUserDisabled()) { ((OhmageApplication) getApplication()).resetAll(); } if (!preferencesHelper.isAuthenticated()) { Log.i(TAG, "no credentials saved, so launch Login"); startActivity(new Intent(this, LoginActivity.class).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)); return; } List<Prompt> prompts = null; String surveyId = "stressButton"; String surveyTitle = "Stress"; try { prompts = PromptXmlParser.parsePrompts(CampaignXmlHelper.loadDefaultCampaign(this), surveyId); } catch (NotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (XmlPullParserException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (prompts != null && prompts.size() > 0) { startService(new Intent(this, SurveyGeotagService.class)); if (((AbstractPrompt) prompts.get(0)).getResponseObject() == null) { Toast.makeText(this, "There is a bug: default value not being set!", Toast.LENGTH_SHORT).show(); } else { ((AbstractPrompt) prompts.get(0)).setDisplayed(true); ((AbstractPrompt) prompts.get(0)).setSkipped(false); Log.i(TAG, prompts.get(0).getResponseJson()); storeResponse(surveyId, surveyTitle, launchTime, prompts); //Toast.makeText(this, "Registered stressful event.", Toast.LENGTH_SHORT).show(); mHandler.post(new DisplayToast("Registered stressful event!")); } } }
From source file:io.github.hidroh.materialistic.widget.NavFloatingActionButton.java
public NavFloatingActionButton(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); bindNavigationPad();/*from w w w . j a v a 2 s. com*/ if (!isInEditMode()) { mVibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE); } else { mVibrator = null; } }
From source file:edu.tjhsst.ion.gcmFrame.MyGcmListenerService.java
/** * Create and show a simple notification containing the received GCM message. * * @param data GCM data received./*from w w w . j a v a 2 s . c o m*/ * title * text * url * sound * ongoing * wakeup */ private void sendNotification(Bundle data) { Vibrator vib = (Vibrator) this.getSystemService(Context.VIBRATOR_SERVICE); int vibrate = Integer.parseInt(data.getString("vibrate", "0")); if (vibrate > 0) { vib.vibrate(vibrate); } String[] vibratepattern = data.getString("vibrate", "").split(","); long[] vibpattern = new long[vibratepattern.length]; int i = 0; for (String p : vibratepattern) { vibpattern[i++] = Long.parseLong(p); } if (vibratepattern.length > 0) { vib.vibrate(vibpattern, -1); } String notif_title = data.getString("title", ""); String notif_text = data.getString("text", ""); String notif_url = data.getString("url", ""); String notif_strsound = data.getString("sound", ""); String notif_strongoing = data.getString("ongoing", ""); String notif_strwakeup = data.getString("wakeup", ""); boolean notif_sound = notif_strsound.equals("true"); boolean notif_ongoing = notif_strongoing.equals("true"); boolean notif_wakeup = notif_strwakeup.equals("true"); Intent intent; if (notif_url.length() > 0) { intent = new Intent(this, MainActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); } else { intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse(notif_url)); } PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, 0); PowerManager.WakeLock wl = null; if (notif_wakeup) { Log.d("showNotification", "Wakeup enabled"); PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); // FIXME: FULL_WAKE_LOCK is deprecated wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK, "My Tag"); wl.acquire(500); } // NotificationCompat supports API level 12 NotificationCompat.Builder n = new NotificationCompat.Builder(this).setContentTitle(notif_title) .setContentText(notif_text).setSmallIcon(R.drawable.ic_stat_ic_notification) .setLargeIcon(BitmapFactory.decodeResource(this.getResources(), R.drawable.ic_stat_ic_notification)) .setContentIntent(pIntent).setAutoCancel(true).setOngoing(notif_ongoing) .setTicker(notif_title + ": " + notif_text); if (notif_sound) { n.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)); } NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); Notification notif = n.build(); notificationManager.notify(0, notif); if (notif_wakeup) { wl.release(); } }
From source file:ca.mudar.snoozy.receiver.PowerConnectionReceiver.java
@Override public void onReceive(Context context, Intent intent) { final Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE); // Get user preferences final SharedPreferences sharedPrefs = context.getSharedPreferences(Const.APP_PREFS_NAME, Context.MODE_PRIVATE); final SharedPreferences.Editor sharedPrefsEditor = sharedPrefs.edit(); final boolean hasNotifications = sharedPrefs.getBoolean(Const.PrefsNames.HAS_NOTIFICATIONS, false); final boolean hasVibration = (sharedPrefs.getBoolean(Const.PrefsNames.HAS_VIBRATION, false) && vibrator.hasVibrator()); final boolean hasSound = sharedPrefs.getBoolean(Const.PrefsNames.HAS_SOUND, false); final boolean onScreenLock = sharedPrefs.getBoolean(Const.PrefsNames.ON_SCREEN_LOCK, true); final boolean onPowerLoss = sharedPrefs.getBoolean(Const.PrefsNames.ON_POWER_LOSS, false); final int delayToLock = Integer.parseInt( sharedPrefs.getString(Const.PrefsNames.DELAY_TO_LOCK, Const.PrefsValues.DELAY_FAST)) * 1000; final int notifyCount = sharedPrefs.getInt(Const.PrefsNames.NOTIFY_COUNT, 1); final int notifyGroup = sharedPrefs.getInt(Const.PrefsNames.NOTIFY_GROUP, 1); final String action = intent.getAction(); if (action == null) return;/*w ww. ja va2s . c om*/ if (action.equals(Const.IntentActions.NOTIFY_DELETE)) { if (hasNotifications) { // Reset the notification counter (and group) on NOTIFY_DELETE sharedPrefsEditor.putInt(Const.PrefsNames.NOTIFY_COUNT, 1); sharedPrefsEditor.putInt(Const.PrefsNames.NOTIFY_GROUP, notifyGroup + 1); sharedPrefsEditor.apply(); } } else if (action.equals(Intent.ACTION_POWER_CONNECTED) || action.equals(Intent.ACTION_POWER_DISCONNECTED)) { final boolean isConnectedPower = action.equals(Intent.ACTION_POWER_CONNECTED); // Lock the screen, following the user preferences if (delayToLock == 0) { LockScreenHelper.lockScreen(context, onScreenLock, onPowerLoss, isConnectedPower); } else { Intent intentService = new Intent(Intent.ACTION_SYNC, null, context, DelayedLockService.class); Bundle extras = new Bundle(); extras.putBoolean(Const.IntentExtras.ON_SCREEN_LOCK, onScreenLock); extras.putBoolean(Const.IntentExtras.ON_POWER_LOSS, onPowerLoss); extras.putBoolean(Const.IntentExtras.IS_CONNECTED, isConnectedPower); extras.putInt(Const.IntentExtras.DELAY_TO_LOCK, delayToLock); intentService.putExtras(extras); context.startService(intentService); } // Save in database saveHistoryItem(context.getApplicationContext(), isConnectedPower, notifyGroup); if (hasNotifications) { // Send notification, with sound and vibration notify(context, isConnectedPower, hasVibration, hasSound, notifyCount); // Increment the notification counter sharedPrefsEditor.putInt(Const.PrefsNames.NOTIFY_COUNT, notifyCount + 1); sharedPrefsEditor.apply(); } else { // Native Vibration or Sound, without Notifications nativeVibrate(context, hasVibration); nativeRingtone(context, hasSound); } } }
From source file:com.apps.howard.vicissitude.services.NotificationService.java
@Override public void onCreate() { notificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE); vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); notificationManager.cancelAll();//ww w. j ava 2s . c o m prefs = PreferenceManager.getDefaultSharedPreferences(this); }