List of usage examples for android.os Vibrator vibrate
@RequiresPermission(android.Manifest.permission.VIBRATE) public void vibrate(VibrationEffect vibe)
From source file:net.ustyugov.jtalk.Notify.java
public static void subscribtionNotify(Context context, String account, String from) { String soundPath = ""; Intent i = new Intent(context, RosterActivity.class); i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); i.putExtra("subscribtion", true); i.putExtra("account", account); i.putExtra("jid", from); PendingIntent contentIntent = PendingIntent.getActivity(context, 0, i, PendingIntent.FLAG_UPDATE_CURRENT); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); String vibration = prefs.getString("vibrationMode", "1"); if (!prefs.getBoolean("soundDisabled", false)) { if (vibration.equals("1") || vibration.equals("2") || vibration.equals("3")) { Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE); vibrator.vibrate(200); }/*from w w w .j ava 2 s . c o m*/ soundPath = prefs.getString("ringtone", ""); } NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context); mBuilder.setAutoCancel(true); mBuilder.setOngoing(false); mBuilder.setSmallIcon(R.drawable.noface); mBuilder.setLights(0xFF0000FF, 2000, 3000); mBuilder.setContentTitle(from); mBuilder.setContentText("Subscription request"); mBuilder.setContentIntent(contentIntent); mBuilder.setTicker("Subscription request from " + from); if (!soundPath.isEmpty()) mBuilder.setSound(Uri.parse(soundPath)); NotificationManager mng = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); mng.notify(Integer.parseInt((System.currentTimeMillis() + "").substring(7)), mBuilder.build()); }
From source file:com.oo58.game.texaspoker.AppActivity.java
public static void Vibrate(final int times) { mAct.runOnUiThread(new Runnable() { @Override/*from w w w .j a v a2 s. com*/ public void run() { // TODO Auto-generated method stub try { Vibrator vibrator = (Vibrator) mContext.getSystemService(VIBRATOR_SERVICE); vibrator.vibrate(times); } catch (Exception ex) { ex.printStackTrace(); } } }); }
From source file:de.ub0r.android.websms.WebSMSReceiver.java
/** * Handle result of message sending./*from w ww .jav a 2 s. c om*/ * * @param context context * @param specs {@link de.ub0r.android.websms.connector.common.ConnectorSpec} * @param command {@link de.ub0r.android.websms.connector.common.ConnectorCommand} */ static void handleSendCommand(final Context context, final ConnectorSpec specs, final ConnectorCommand command) { boolean isHandled = false; final SharedPreferences p = PreferenceManager.getDefaultSharedPreferences(context); if (!specs.hasStatus(ConnectorSpec.STATUS_ERROR)) { // Sent successfully saveMessage(context, specs, command, MESSAGE_TYPE_SENT); if (p.getBoolean(WebSMS.PREFS_SEND_VIBRATE, false)) { final Vibrator v = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE); if (v != null) { v.vibrate(VIBRATOR_SEND); v.cancel(); } } isHandled = true; messageCompleted(context, command); } if (!isHandled) { // Resend if possible (network might be down temporarily or an odd // failure on the provider's web side) final int maxResendCount = de.ub0r.android.lib.Utils .parseInt(p.getString(WebSMS.PREFS_MAX_RESEND_COUNT, "0"), 0); if (maxResendCount > 0) { int wasResendCount = command.getResendCount(); if (wasResendCount < maxResendCount && !isResendCancelled(command.getMsgId())) { // schedule resend command.setResendCount(wasResendCount + 1); displayResendingNotification(context, command); scheduleMessageResend(context, specs, command); isHandled = true; } } } if (!isHandled) { // Display notification if sending failed displaySendingFailedNotification(context, specs, command); messageCompleted(context, command); } }
From source file:org.xbmc.kore.utils.UIUtils.java
public static void handleVibration(Context context) { if (context == null) return;/* w w w. ja v a2 s . c o m*/ Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE); if (!vibrator.hasVibrator()) return; //Check if we should vibrate boolean vibrateOnPress = PreferenceManager.getDefaultSharedPreferences(context) .getBoolean(Settings.KEY_PREF_VIBRATE_REMOTE_BUTTONS, Settings.DEFAULT_PREF_VIBRATE_REMOTE_BUTTONS); if (vibrateOnPress) { vibrator.vibrate(UIUtils.buttonVibrationDuration); } }
From source file:com.linkbubble.MainApplication.java
public static boolean handleBubbleAction(final Context context, BubbleAction action, final String urlAsString, long totalTrackedLoadTime) { Constant.ActionType actionType = Settings.get().getConsumeBubbleActionType(action); boolean result = false; if (actionType == Constant.ActionType.Share) { String consumePackageName = Settings.get().getConsumeBubblePackageName(action); CrashTracking.log("MainApplication.handleBubbleAction() action:" + action.toString() + ", consumePackageName:" + consumePackageName); String consumeName = Settings.get().getConsumeBubbleActivityClassName(action); if (consumePackageName.equals(BuildConfig.APPLICATION_ID) && consumeName.equals(Constant.SHARE_PICKER_NAME)) { AlertDialog alertDialog = ActionItem.getShareAlert(context, false, new ActionItem.OnActionItemSelectedListener() { @Override public void onSelected(ActionItem actionItem) { Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); intent.setClassName(actionItem.mPackageName, actionItem.mActivityClassName); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.putExtra(Intent.EXTRA_TEXT, urlAsString); String title = MainApplication.sTitleHashMap != null ? MainApplication.sTitleHashMap.get(urlAsString) : null; if (title != null) { intent.putExtra(Intent.EXTRA_SUBJECT, title); }/*w w w . j a va2 s .co m*/ context.startActivity(intent); } }); Util.showThemedDialog(alertDialog); return true; } // TODO: Retrieve the class name below from the app in case Twitter ever change it. Intent intent = Util.getSendIntent(consumePackageName, consumeName, urlAsString); try { context.startActivity(intent); if (totalTrackedLoadTime > -1) { Settings.get().trackLinkLoadTime(totalTrackedLoadTime, Settings.LinkLoadType.ShareToOtherApp, urlAsString); } result = true; } catch (ActivityNotFoundException ex) { Toast.makeText(context, R.string.consume_activity_not_found, Toast.LENGTH_LONG).show(); } catch (SecurityException ex) { Toast.makeText(context, R.string.consume_activity_security_exception, Toast.LENGTH_SHORT).show(); } } else if (actionType == Constant.ActionType.View) { String consumePackageName = Settings.get().getConsumeBubblePackageName(action); CrashTracking.log("MainApplication.handleBubbleAction() action:" + action.toString() + ", consumePackageName:" + consumePackageName); result = MainApplication.loadIntent(context, consumePackageName, Settings.get().getConsumeBubbleActivityClassName(action), urlAsString, -1, true); } else if (action == BubbleAction.Close || action == BubbleAction.BackButton) { CrashTracking.log("MainApplication.handleBubbleAction() action:" + action.toString()); result = true; } if (result) { boolean hapticFeedbackEnabled = android.provider.Settings.System.getInt(context.getContentResolver(), android.provider.Settings.System.HAPTIC_FEEDBACK_ENABLED, 0) != 0; if (hapticFeedbackEnabled && action != BubbleAction.BackButton) { Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE); if (vibrator.hasVibrator()) { vibrator.vibrate(10); } } } return result; }
From source file:ca.psiphon.ploggy.ActivitySendIdentityByNfc.java
@Override public void onNdefPushComplete(NfcEvent nfcEvent) { final Context finalContext = this; runOnUiThread(new Runnable() { @Override// ww w . j ava2 s . c o m public void run() { Vibrator vibe = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); vibe.vibrate(100); Toast.makeText(finalContext, R.string.prompt_nfc_push_complete, Toast.LENGTH_LONG).show(); } }); }
From source file:net.ustyugov.jtalk.Notify.java
public static void messageNotify(String account, String fullJid, Type type, String text) { JTalkService service = JTalkService.getInstance(); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(service); String currentJid = JTalkService.getInstance().getCurrentJid(); String from = fullJid;/*from w w w. j a v a2s. com*/ if (type == Type.Direct) from = StringUtils.parseBareAddress(fullJid); String ignored = prefs.getString("IgnoreJids", ""); if (ignored.toLowerCase().contains(from.toLowerCase())) return; int color = Color.GREEN; try { color = Integer.parseInt(prefs.getString("lightsColor", Color.GREEN + "")); } catch (NumberFormatException nfe) { } String nick = from; if (service.getConferencesHash(account).containsKey(from)) { nick = StringUtils.parseName(from); } else if (service.getConferencesHash(account).containsKey(StringUtils.parseBareAddress(from))) { nick = StringUtils.parseResource(from); } else { Roster roster = JTalkService.getInstance().getRoster(account); if (roster != null) { RosterEntry re = roster.getEntry(from); if (re != null && re.getName() != null) nick = re.getName(); } } String ticker = ""; boolean include = prefs.getBoolean("MessageInNotification", false); if (include) { int count = Integer.parseInt(prefs.getString("MessageInNotificationCount", "64")); if (count > 0 && count < text.length()) text = text.substring(0, count); } String vibration = prefs.getString("vibrationMode", "1"); Vibrator vibrator = (Vibrator) service.getSystemService(Context.VIBRATOR_SERVICE); boolean vibro = false; boolean sound = true; String soundPath = ""; if (type == Type.Conference) { if (!currentJid.equals(from) || currentJid.equals("me")) { if (!prefs.getBoolean("soundDisabled", false)) { if (vibration.equals("1") || vibration.equals("4")) vibrator.vibrate(200); new SoundTask().execute(""); } } return; } else if (type == Type.Direct) { text = StringUtils.parseResource(fullJid) + ": " + text; if (!prefs.getBoolean("soundDisabled", false)) { if (vibration.equals("1") || vibration.equals("3") || vibration.equals("4")) vibro = true; soundPath = prefs.getString("ringtone_direct", ""); } } else { if (!prefs.getBoolean("soundDisabled", false)) { if (vibration.equals("1") || vibration.equals("2") || vibration.equals("3")) vibro = true; soundPath = prefs.getString("ringtone", ""); } } if (soundPath.equals("")) sound = false; if (!currentJid.equals(from) || currentJid.equals("me")) { if (vibro) vibrator.vibrate(200); if (include) { ticker = service.getString(R.string.NewMessageFrom) + " " + nick + ": " + text; } else ticker = service.getString(R.string.NewMessageFrom) + " " + nick; Uri sound_file = Uri.parse(soundPath); String key = account + "/" + from; int id = 11 + ids.size(); if (ids.containsKey(key)) id = ids.get(key); else ids.put(key, id); Intent i = new Intent(service, Chat.class); i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); i.setAction(ids + ""); i.putExtra("jid", from); i.putExtra("account", account); PendingIntent contentIntent = PendingIntent.getActivity(service, 0, i, PendingIntent.FLAG_UPDATE_CURRENT); Bitmap largeIcon = BitmapFactory.decodeResource(service.getResources(), R.drawable.stat_msg); if (type == Type.Direct) largeIcon = BitmapFactory.decodeResource(service.getResources(), R.drawable.icon_muc); else { if (prefs.getBoolean("LoadNotifyAvatar", true)) { String filePath = Constants.PATH + fullJid.replaceAll("/", "%"); File a = new File(filePath); if (a.exists()) { largeIcon = BitmapFactory.decodeFile(filePath); int width = largeIcon.getWidth(); if (width > 96) { double k = (double) width / (double) 96; int h = (int) (largeIcon.getHeight() / k); largeIcon = Bitmap.createScaledBitmap(largeIcon, 96, h, true); } } } } NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(service); mBuilder.setLargeIcon(largeIcon); mBuilder.setSmallIcon(R.drawable.stat_msg); mBuilder.setLights(color, 2000, 3000); mBuilder.setContentTitle(nick); mBuilder.setContentText(text); mBuilder.setContentIntent(contentIntent); mBuilder.setTicker(ticker); mBuilder.setNumber(service.getMessagesCount(account, from)); mBuilder.setPriority(NotificationCompat.PRIORITY_MAX); if (sound) mBuilder.setSound(sound_file); NotificationCompat.BigTextStyle bts = new NotificationCompat.BigTextStyle(); bts.setBigContentTitle(nick); bts.bigText(text); mBuilder.setStyle(bts); NotificationManager mng = (NotificationManager) service.getSystemService(Context.NOTIFICATION_SERVICE); mng.notify(id, mBuilder.build()); } }
From source file:org.peterbaldwin.vlcremote.fragment.NavigationFragment.java
private void vibrate() { Vibrator v = getSystemService(Context.VIBRATOR_SERVICE); if (v != null) { v.vibrate(100); } }
From source file:com.measurence.sdk.android.gcm_push_notifications.PresenceSessionUpdatesNotificationService.java
private void notifySessionUpdateToUI(String presenceSessionUpdateJson) { Intent sessionUpdateNotificationIntent = new Intent(SESSION_UPDATE_INTENT_ID); sessionUpdateNotificationIntent.putExtra(SESSION_UPDATE_JSON_PARAMETER, presenceSessionUpdateJson); localBroadcastManager.sendBroadcast(sessionUpdateNotificationIntent); PresenceSessionUpdate update = PresenceSessionUpdate.fromJson(presenceSessionUpdateJson); sendNotification(update.getUserIdentities().get(0).getId(), update.getStoreKey(), update.getStatus()); Vibrator v = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); v.vibrate(2000); long pattern[] = { 0, 400, 200, 200, 800 }; // 2nd argument is for repetition pass -1 if you do not want to repeat the Vibrate v.vibrate(pattern, -1);//w ww . j ava 2 s.c o m }
From source file:com.belatrix.events.utils.fcm.EventsFirebaseMessagingService.java
private void sendNotification(String messageTitle, String messageBody) { Intent intent = MainActivity.makeIntent(this); intent.putExtra(MainActivity.PARAM_FROM_NOTIFICATION, true); intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_ONE_SHOT); NotificationCompat.BigTextStyle bigTextStyle = new NotificationCompat.BigTextStyle(); bigTextStyle.setBigContentTitle(messageTitle); bigTextStyle.bigText(messageBody);/*w ww.j a va 2 s. c o m*/ Bitmap icon = BitmapFactory.decodeResource(getApplicationContext().getResources(), R.drawable.ic_launcher); Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.bx_connect_white).setLargeIcon(icon).setStyle(bigTextStyle) .setContentText(messageBody).setContentTitle(messageTitle).setAutoCancel(true) .setContentIntent(pendingIntent).setSound(alarmSound).setLights(0xFF8F0300, 1000, 200) .setPriority(Notification.PRIORITY_MAX); //for vibration Vibrator v = (Vibrator) getApplicationContext().getSystemService(Context.VIBRATOR_SERVICE); v.vibrate(1000); NotificationManager notificationManager = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); long time = new Date().getTime(); String tmpStr = String.valueOf(time); String last4Str = tmpStr.substring(tmpStr.length() - 5); int notificationId = Integer.valueOf(last4Str); notificationManager.notify(notificationId, notificationBuilder.build()); }