List of usage examples for android.os Vibrator vibrate
@RequiresPermission(android.Manifest.permission.VIBRATE) public void vibrate(VibrationEffect vibe)
From source file:fi.iki.murgo.irssinotifier.IrssiNotifierActivity.java
public void newMessage(IrcMessage msg) { if ((!preferences.isSpamFilterEnabled() || new Date().getTime() > IrcNotificationManager.getInstance().getLastSoundDate() + 60000L)) { Uri sound = preferences.getNotificationSound(); if (sound != null) { MediaPlayer mp = MediaPlayer.create(this, sound); if (mp != null) { mp.start();/*w w w. j av a 2 s . c o m*/ } } if (preferences.isVibrationEnabled()) { Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); if (v != null) { v.vibrate(500); } } IrcNotificationManager.getInstance().setLastSoundDate(new Date().getTime()); } if (preferences.isFeedViewDefault()) { channelToView = FEED; } else { channelToView = msg.getLogicalChannel(); } startMainApp(false); }
From source file:app.abhijit.iter.MainActivity.java
private void vibrate() { Vibrator vibrator = (Vibrator) mContext.getSystemService(Context.VIBRATOR_SERVICE); vibrator.vibrate(500); }
From source file:shetye.prathamesh.notifyme.Utilities.java
public void generateNotification(Context context, int ID, String title, String message, boolean isOngoing) { NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); Intent notificationIntent = new Intent(context, NotifyMe.class); notificationIntent.setData(Uri.parse(Integer.toString(ID))); notificationIntent.putExtra(Utilities.NOTIF_EXTRA_ID_KEY, ID); notificationIntent.putExtra(Utilities.NOTIF_EXTRA_KEY, message); notificationIntent.putExtra(Utilities.NOTIF_EXTRA_TITLE_KEY, title); Intent laterIntent = new Intent(context, NotificationDetail.class); laterIntent.setData(Uri.parse(Integer.toString(ID))); laterIntent.putExtra(Utilities.NOTIF_EXTRA_ID_KEY, ID); laterIntent.putExtra(Utilities.NOTIF_EXTRA_DONE_LATER_KEY, true); Intent doneIntent = new Intent(context, RecieveAndNotify.class); doneIntent.setData(Uri.parse(Integer.toString(ID))); doneIntent.setAction(NOTIF_SERVICE_DONE_ACTION); doneIntent.putExtra(Utilities.NOTIF_EXTRA_ID_KEY, ID); PendingIntent resultPendingIntent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); PendingIntent remindLaterIntent = PendingIntent.getActivity(context, 0, laterIntent, PendingIntent.FLAG_UPDATE_CURRENT); PendingIntent completedIntent = PendingIntent.getBroadcast(context, 0, doneIntent, PendingIntent.FLAG_UPDATE_CURRENT); NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(); String newTitle;/*from w w w . j ava2 s . co m*/ if (title == null || title.isEmpty()) newTitle = context.getResources().getString(R.string.app_name); else newTitle = title; inboxStyle.setBigContentTitle(newTitle); inboxStyle.addLine(message); NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context) .setSmallIcon(R.drawable.ic_notif).setContentTitle(newTitle).setContentText(message) .setPriority(NotificationCompat.PRIORITY_MAX).setContentIntent(resultPendingIntent) .addAction(R.drawable.ic_restore, "Later", remindLaterIntent) .addAction(R.drawable.ic_done, "Done", completedIntent).setStyle(inboxStyle); Log.d(LOG_TAG, "Notifying for ID : " + ID); notificationManager.notify(ID, mBuilder.build()); try { Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); Ringtone r = RingtoneManager.getRingtone(context, notification); Vibrator v = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE); // Vibrate for 300 milliseconds v.vibrate(200); r.play(); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.mk4droid.IMC_Activities.Fragment_NewIssueB.java
/** * OnMarker drag start vibrate//from www. j ava 2s . c o m */ @Override public void onMarkerDragStart(Marker arg0) { //Vibrate Vibrator vibrator = (Vibrator) getActivity().getSystemService(Context.VIBRATOR_SERVICE); vibrator.vibrate(500); }
From source file:org.yuttadhammo.BodhiTimer.TimerReceiver.java
@Override public void onReceive(Context context, Intent pintent) { Log.v(TAG, "ALARM: received alarm"); NotificationManager mNM = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); if (player != null) { Log.v(TAG, "Releasing media player..."); try {/*from w w w . jav a 2 s . co m*/ player.release(); player = null; } catch (Exception e) { e.printStackTrace(); player = null; } finally { // do nothing } } // Cancel notification and return... if (CANCEL_NOTIFICATION.equals(pintent.getAction())) { Log.v(TAG, "Cancelling notification..."); mNM.cancelAll(); return; } // ...or display a new one Log.v(TAG, "Showing notification..."); player = new MediaPlayer(); int setTime = pintent.getIntExtra("SetTime", 0); String setTimeStr = TimerUtils.time2humanStr(context, setTime); Log.v(TAG, "Time: " + setTime); CharSequence text = context.getText(R.string.Notification); CharSequence textLatest = String.format(context.getString(R.string.timer_for_x), setTimeStr); // Load the settings SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); boolean led = prefs.getBoolean("LED", true); boolean vibrate = prefs.getBoolean("Vibrate", true); String notificationUri = ""; boolean useAdvTime = prefs.getBoolean("useAdvTime", false); String advTimeString = prefs.getString("advTimeString", ""); String[] advTime = null; int advTimeIndex = 1; if (useAdvTime && advTimeString.length() > 0) { advTime = advTimeString.split("\\^"); advTimeIndex = prefs.getInt("advTimeIndex", 1); String[] thisAdvTime = advTime[advTimeIndex - 1].split("#"); // will be of format timeInMs#pathToSound if (thisAdvTime.length == 3) notificationUri = thisAdvTime[1]; if (notificationUri.equals("sys_def")) notificationUri = prefs.getString("NotificationUri", "android.resource://org.yuttadhammo.BodhiTimer/" + R.raw.bell); } else notificationUri = prefs.getString("NotificationUri", "android.resource://org.yuttadhammo.BodhiTimer/" + R.raw.bell); Log.v(TAG, "notification uri: " + notificationUri); if (notificationUri.equals("system")) notificationUri = prefs.getString("SystemUri", ""); else if (notificationUri.equals("file")) notificationUri = prefs.getString("FileUri", ""); else if (notificationUri.equals("tts")) { notificationUri = ""; final String ttsString = prefs.getString("tts_string", context.getString(R.string.timer_done)); Intent ttsIntent = new Intent(context, TTSService.class); ttsIntent.putExtra("spoken_text", ttsString); context.startService(ttsIntent); } NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context.getApplicationContext()) .setSmallIcon(R.drawable.notification).setContentTitle(text).setContentText(textLatest); Uri uri = null; // Play a sound! if (!notificationUri.equals("")) uri = Uri.parse(notificationUri); // Vibrate if (vibrate && uri == null) { mBuilder.setDefaults(Notification.DEFAULT_VIBRATE); } // Have a light if (led) { mBuilder.setLights(0xff00ff00, 300, 1000); } mBuilder.setAutoCancel(true); // Creates an explicit intent for an Activity in your app Intent resultIntent = new Intent(context, TimerActivity.class); // The stack builder object will contain an artificial back stack for the // started Activity. // This ensures that navigating backward from the Activity leads out of // your application to the Home screen. TaskStackBuilder stackBuilder = TaskStackBuilder.create(context); // Adds the back stack for the Intent (but not the Intent itself) stackBuilder.addParentStack(TimerActivity.class); // Adds the Intent that starts the Activity to the top of the stack stackBuilder.addNextIntent(resultIntent); PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); mBuilder.setContentIntent(resultPendingIntent); NotificationManager mNotificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); // Create intent for cancelling the notification Context appContext = context.getApplicationContext(); Intent intent = new Intent(appContext, TimerReceiver.class); intent.setAction(CANCEL_NOTIFICATION); // Cancel the pending cancellation and create a new one PendingIntent pendingCancelIntent = PendingIntent.getBroadcast(appContext, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); if (uri != null) { //remove notification sound mBuilder.setSound(null); try { if (player != null && player.isPlaying()) { player.release(); player = new MediaPlayer(); } int currVolume = prefs.getInt("tone_volume", 0); if (currVolume != 0) { float log1 = (float) (Math.log(100 - currVolume) / Math.log(100)); player.setVolume(1 - log1, 1 - log1); } player.setDataSource(context, uri); player.prepare(); player.setLooping(false); player.setOnCompletionListener(new OnCompletionListener() { @Override public void onCompletion(MediaPlayer mp) { // TODO Auto-generated method stub mp.release(); } }); player.start(); if (vibrate) { Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE); vibrator.vibrate(1000); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } if (prefs.getBoolean("AutoClear", false)) { // Determine duration of notification sound int duration = 5000; if (uri != null) { MediaPlayer cancelPlayer = new MediaPlayer(); try { cancelPlayer.setDataSource(context, uri); cancelPlayer.prepare(); duration = Math.max(duration, cancelPlayer.getDuration() + 2000); } catch (java.io.IOException ex) { Log.e(TAG, "Cannot get sound duration: " + ex); duration = 30000; // on error, default to 30 seconds } finally { cancelPlayer.release(); } cancelPlayer.release(); } Log.v(TAG, "Notification duration: " + duration + " ms"); // Schedule cancellation AlarmManager alarmMgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); alarmMgr.set(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + duration, pendingCancelIntent); } if (useAdvTime && advTimeString.length() > 0) { Intent broadcast = new Intent(); SharedPreferences.Editor editor = prefs.edit(); if (advTimeIndex < advTime.length) { editor.putInt("advTimeIndex", advTimeIndex + 1); String[] thisAdvTime = advTime[advTimeIndex].split("#"); // will be of format timeInMs#pathToSound int time = Integer.parseInt(thisAdvTime[0]); broadcast.putExtra("time", time); // Save new time editor.putLong("TimeStamp", new Date().getTime() + time); editor.putInt("LastTime", time); // editor.putString("NotificationUri", thisAdvTime[1]); mNM.cancelAll(); Log.v(TAG, "Starting next iteration of the timer service ..."); Intent rintent = new Intent(context, TimerReceiver.class); rintent.putExtra("SetTime", time); PendingIntent mPendingIntent = PendingIntent.getBroadcast(context, 0, rintent, PendingIntent.FLAG_UPDATE_CURRENT); AlarmManager mAlarmMgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); mAlarmMgr.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + time, mPendingIntent); } else { broadcast.putExtra("stop", true); editor.putInt("advTimeIndex", 1); } broadcast.setAction(BROADCAST_RESET); context.sendBroadcast(broadcast); editor.apply(); } else if (prefs.getBoolean("AutoRestart", false)) { int time = pintent.getIntExtra("SetTime", 0); if (time != 0) { mNM.cancel(0); Log.v(TAG, "Restarting the timer service ..."); Intent rintent = new Intent(context, TimerReceiver.class); rintent.putExtra("SetTime", time); PendingIntent mPendingIntent = PendingIntent.getBroadcast(context, 0, rintent, PendingIntent.FLAG_UPDATE_CURRENT); AlarmManager mAlarmMgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); mAlarmMgr.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + time, mPendingIntent); // Save new time SharedPreferences.Editor editor = prefs.edit(); editor.putLong("TimeStamp", new Date().getTime() + time); editor.putInt("LastTime", time); editor.apply(); Intent broadcast = new Intent(); broadcast.putExtra("time", time); broadcast.setAction(BROADCAST_RESET); context.sendBroadcast(broadcast); } } mNotificationManager.notify(0, mBuilder.build()); Log.d(TAG, "ALARM: alarm finished"); }
From source file:mx.klozz.xperience.tweaker.fragments.Advanced.java
public void openDialog(String title, final int min, final int max, final Preference pref, final String path, final String key) { Resources res = context.getResources(); String cancel = res.getString(R.string.cancel); String ok = res.getString(R.string.ok); final EditText settingText; LayoutInflater factory = LayoutInflater.from(context); final View alphaDialog = factory.inflate(R.layout.seekbar_dialog, null); final SeekBar seekbar = (SeekBar) alphaDialog.findViewById(R.id.seek_bar); seekbar.setMax(max - min);// www .java 2 s .co m int currentProgress = min; if (key.equals("pref_viber")) { currentProgress = Integer.parseInt(Helpers.LeerUnaLinea(path)); } else { currentProgress = Integer.parseInt(vib.get_val(path)); } if (currentProgress > max) currentProgress = max - min; else if (currentProgress < min) currentProgress = 0; else currentProgress = currentProgress - min; seekbar.setProgress(currentProgress); settingText = (EditText) alphaDialog.findViewById(R.id.setting_text); settingText.setText(Integer.toString(currentProgress + min)); settingText.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_DONE) { int val = Integer.parseInt(settingText.getText().toString()) - min; seekbar.setProgress(val); return true; } return false; } }); settingText.addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void afterTextChanged(Editable s) { try { int val = Integer.parseInt(s.toString()); if (val > max) { s.replace(0, s.length(), Integer.toString(max)); val = max; } seekbar.setProgress(val - min); } catch (NumberFormatException ex) { } } }); OnSeekBarChangeListener seekBarChangeListener = new OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekbar, int progress, boolean fromUser) { final int mSeekbarProgress = seekbar.getProgress(); if (fromUser) { settingText.setText(Integer.toString(mSeekbarProgress + min)); } } @Override public void onStopTrackingTouch(SeekBar seekbar) { } @Override public void onStartTrackingTouch(SeekBar seekbar) { } }; seekbar.setOnSeekBarChangeListener(seekBarChangeListener); new AlertDialog.Builder(context).setTitle(title).setView(alphaDialog) .setNegativeButton(cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // nothing } }).setPositiveButton(ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { int val = min; if (!settingText.getText().toString().equals("")) val = Integer.parseInt(settingText.getText().toString()); if (val < min) val = min; seekbar.setProgress(val - min); int newProgress = seekbar.getProgress() + min; new CMDProcessor().su .runWaitFor("busybox echo " + Integer.toString(newProgress) + " > " + path); String v; if (key.equals("pref_viber")) { v = vib.get_val(path); Vibrator vb = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE); vb.vibrate(1000); } else { v = Helpers.LeerUnaLinea(path); } final SharedPreferences.Editor editor = mPreferences.edit(); editor.putInt(key, Integer.parseInt(v)).commit(); pref.setSummary(v); } }).create().show(); }
From source file:com.brewcrewfoo.performance.fragments.Advanced.java
public void openDialog(String title, final int min, final int max, final Preference pref, final String path, final String key) { Resources res = context.getResources(); String cancel = res.getString(R.string.cancel); String ok = res.getString(R.string.ok); final EditText settingText; LayoutInflater factory = LayoutInflater.from(context); final View alphaDialog = factory.inflate(R.layout.seekbar_dialog, null); final SeekBar seekbar = (SeekBar) alphaDialog.findViewById(R.id.seek_bar); seekbar.setMax(max - min);// w w w . j ava 2 s . c om int currentProgress = min; if (key.equals("pref_viber")) { currentProgress = Integer.parseInt(vib.get_val(path)); } else { currentProgress = Integer.parseInt(Helpers.readOneLine(path)); } if (currentProgress > max) currentProgress = max - min; else if (currentProgress < min) currentProgress = 0; else currentProgress = currentProgress - min; seekbar.setProgress(currentProgress); settingText = (EditText) alphaDialog.findViewById(R.id.setting_text); settingText.setText(Integer.toString(currentProgress + min)); settingText.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_DONE) { int val = Integer.parseInt(settingText.getText().toString()) - min; seekbar.setProgress(val); return true; } return false; } }); settingText.addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void afterTextChanged(Editable s) { try { int val = Integer.parseInt(s.toString()); if (val > max) { s.replace(0, s.length(), Integer.toString(max)); val = max; } seekbar.setProgress(val - min); } catch (NumberFormatException ex) { } } }); OnSeekBarChangeListener seekBarChangeListener = new OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekbar, int progress, boolean fromUser) { final int mSeekbarProgress = seekbar.getProgress(); if (fromUser) { settingText.setText(Integer.toString(mSeekbarProgress + min)); } } @Override public void onStopTrackingTouch(SeekBar seekbar) { } @Override public void onStartTrackingTouch(SeekBar seekbar) { } }; seekbar.setOnSeekBarChangeListener(seekBarChangeListener); new AlertDialog.Builder(context).setTitle(title).setView(alphaDialog) .setNegativeButton(cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // nothing } }).setPositiveButton(ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { int val = min; if (!settingText.getText().toString().equals("")) val = Integer.parseInt(settingText.getText().toString()); if (val < min) val = min; seekbar.setProgress(val - min); int newProgress = seekbar.getProgress() + min; new CMDProcessor().su .runWaitFor("busybox echo " + Integer.toString(newProgress) + " > " + path); String v; if (key.equals("pref_viber")) { v = vib.get_val(path); Vibrator vb = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE); vb.vibrate(1000); } else { v = Helpers.readOneLine(path); } final SharedPreferences.Editor editor = mPreferences.edit(); editor.putInt(key, Integer.parseInt(v)).commit(); pref.setSummary(v); } }).create().show(); }
From source file:org.dalol.orthodoxmezmurmedia.utilities.widgets.AmharicKeyboardView.java
private void handleChild(View child, int columnCount, LinearLayout keyContainer, int keyHeight) { child.setBackgroundDrawable(ContextCompat.getDrawable(getContext(), R.drawable.amharic_key_bg)); child.setOnTouchListener(new OnTouchListener() { @Override//w w w . jav a2 s .c o m public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: if (shouldVibrate) { Vibrator vb = (Vibrator) getContext().getSystemService(Context.VIBRATOR_SERVICE); if (vb != null) { vb.vibrate(20); } } mPressedKeyView = v; mHandler.removeCallbacks(mKeyPressRunnable); mHandler.postAtTime(mKeyPressRunnable, mPressedKeyView, SystemClock.uptimeMillis() + INITIAL_INTERVAL); break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_OUTSIDE: mHandler.removeCallbacksAndMessages(mPressedKeyView); mPressedKeyView = null; mNormalInterval = 100; break; } return false; } }); child.setOnClickListener(mKeyClickListener); int margin = getCustomSize(1.5f); int tempKeyHeight = keyHeight - (margin * 2); LayoutParams params = new LayoutParams(0, tempKeyHeight, columnCount); params.setMargins(margin, margin, margin, margin); keyContainer.addView(child, params); }
From source file:com.example.bluetooth_faster_connection.MainActivity.java
public void vibrate(int duration) { Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); v.vibrate(duration); }
From source file:system.info.reader.java
public String refresh() { //wifi/*ww w .j av a 2s . c om*/ WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE); WifiInfo wifiInfo = wifiManager.getConnectionInfo(); if ((wifiInfo != null) && (wifiInfo.getMacAddress() != null)) Properties.setInfo((String) propertyItems[4], wifiInfo.getMacAddress()); else Properties.setInfo((String) propertyItems[4], "not avaiable"); //String tmpsdcard = runCmd("df", ""); //if (tmpsdcard != null) result += tmpsdcard + "\n\n"; //setMap("dpi", dpi); //location LocationManager lm = (LocationManager) getSystemService(LOCATION_SERVICE); List ll = lm.getProviders(true); Boolean foundLoc = false; for (int i = 0; i < ll.size(); i++) { Location lo = lm.getLastKnownLocation((String) ll.get(i)); if (lo != null) { Properties.setInfo((String) propertyItems[3], lo.getLatitude() + ":" + lo.getLongitude()); foundLoc = true; break; } } if (!foundLoc) Properties.setInfo((String) propertyItems[3], getString(R.string.locationHint)); ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE); List serviceList = am.getRunningServices(10000); serviceInfo = ""; for (int i = 0; i < serviceList.size(); i++) { RunningServiceInfo rs = (RunningServiceInfo) serviceList.get(i); serviceInfo += rs.service.flattenToShortString() + "\n"; } //result += getString(R.string.nService) + serviceList.size() + "\n";//service number psInfo = ""; List appList = am.getRunningAppProcesses(); for (int i = 0; i < appList.size(); i++) { RunningAppProcessInfo as = (RunningAppProcessInfo) appList.get(i); psInfo += as.processName + "\n"; } //result += getString(R.string.nProcess) + appList.size() + "\n";//process number taskInfo = ""; List taskList = am.getRunningTasks(10000); for (int i = 0; i < taskList.size(); i++) { RunningTaskInfo ts = (RunningTaskInfo) taskList.get(i); taskInfo += ts.baseActivity.flattenToShortString() + "\n"; } //result += getString(R.string.nTask) + taskList.size() + "\n\n";//task number //result += getString(R.string.nProcess) + runCmd("ps", "") + "\n";//process number //setMap(getString(R.string.nApk), nApk); //send message to let view redraw. Message msg = mRedrawHandler.obtainMessage(); mRedrawHandler.sendMessage(msg); //properListItemAdapter.notifyDataSetChanged();//no use? Vibrator vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); vibrator.vibrate(400); return ""; }