List of usage examples for android.media AudioManager STREAM_NOTIFICATION
int STREAM_NOTIFICATION
To view the source code for android.media AudioManager STREAM_NOTIFICATION.
Click Source Link
From source file:com.transistorsoft.cordova.bggeo.CDVBackgroundGeolocation.java
private void playSound(int soundId) { int duration = 1000; toneGenerator = new ToneGenerator(AudioManager.STREAM_NOTIFICATION, 100); toneGenerator.startTone(soundId, duration); }
From source file:org.telegraph.messenger.NotificationsController.java
private void showOrUpdateNotification(boolean notifyAboutLast) { if (!UserConfig.isClientActivated() || pushMessages.isEmpty()) { dismissNotification();//w w w.j a v a2 s . com return; } try { ConnectionsManager.getInstance().resumeNetworkMaybe(); MessageObject lastMessageObject = pushMessages.get(0); long dialog_id = lastMessageObject.getDialogId(); long override_dialog_id = dialog_id; if ((lastMessageObject.messageOwner.flags & TLRPC.MESSAGE_FLAG_MENTION) != 0) { override_dialog_id = lastMessageObject.messageOwner.from_id; } int mid = lastMessageObject.getId(); int chat_id = lastMessageObject.messageOwner.to_id.chat_id != 0 ? lastMessageObject.messageOwner.to_id.chat_id : lastMessageObject.messageOwner.to_id.channel_id; int user_id = lastMessageObject.messageOwner.to_id.user_id; if (user_id == 0) { user_id = lastMessageObject.messageOwner.from_id; } else if (user_id == UserConfig.getClientUserId()) { user_id = lastMessageObject.messageOwner.from_id; } TLRPC.User user = MessagesController.getInstance().getUser(user_id); TLRPC.Chat chat = null; if (chat_id != 0) { chat = MessagesController.getInstance().getChat(chat_id); } TLRPC.FileLocation photoPath = null; boolean notifyDisabled = false; int needVibrate = 0; String choosenSoundPath = null; int ledColor = 0xff00ff00; boolean inAppSounds; boolean inAppVibrate; boolean inAppPreview = false; boolean inAppPriority; int priority = 0; int priorityOverride; int vibrateOverride; SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("Notifications", Context.MODE_PRIVATE); int notifyOverride = getNotifyOverride(preferences, override_dialog_id); if (!notifyAboutLast || notifyOverride == 2 || (!preferences.getBoolean("EnableAll", true) || chat_id != 0 && !preferences.getBoolean("EnableGroup", true)) && notifyOverride == 0) { notifyDisabled = true; } if (!notifyDisabled && dialog_id == override_dialog_id && chat != null) { int notifyMaxCount = preferences.getInt("smart_max_count_" + dialog_id, 2); int notifyDelay = preferences.getInt("smart_delay_" + dialog_id, 3 * 60); if (notifyMaxCount != 0) { Point dialogInfo = smartNotificationsDialogs.get(dialog_id); if (dialogInfo == null) { dialogInfo = new Point(1, (int) (System.currentTimeMillis() / 1000)); smartNotificationsDialogs.put(dialog_id, dialogInfo); } else { int lastTime = dialogInfo.y; if (lastTime + notifyDelay < System.currentTimeMillis() / 1000) { dialogInfo.set(1, (int) (System.currentTimeMillis() / 1000)); } else { int count = dialogInfo.x; if (count < notifyMaxCount) { dialogInfo.set(count + 1, (int) (System.currentTimeMillis() / 1000)); } else { notifyDisabled = true; } } } } } String defaultPath = Settings.System.DEFAULT_NOTIFICATION_URI.getPath(); if (!notifyDisabled) { inAppSounds = preferences.getBoolean("EnableInAppSounds", true); inAppVibrate = preferences.getBoolean("EnableInAppVibrate", true); inAppPreview = preferences.getBoolean("EnableInAppPreview", true); inAppPriority = preferences.getBoolean("EnableInAppPriority", false); vibrateOverride = preferences.getInt("vibrate_" + dialog_id, 0); priorityOverride = preferences.getInt("priority_" + dialog_id, 3); boolean vibrateOnlyIfSilent = false; choosenSoundPath = preferences.getString("sound_path_" + dialog_id, null); if (chat_id != 0) { if (choosenSoundPath != null && choosenSoundPath.equals(defaultPath)) { choosenSoundPath = null; } else if (choosenSoundPath == null) { choosenSoundPath = preferences.getString("GroupSoundPath", defaultPath); } needVibrate = preferences.getInt("vibrate_group", 0); priority = preferences.getInt("priority_group", 1); ledColor = preferences.getInt("GroupLed", 0xff00ff00); } else if (user_id != 0) { if (choosenSoundPath != null && choosenSoundPath.equals(defaultPath)) { choosenSoundPath = null; } else if (choosenSoundPath == null) { choosenSoundPath = preferences.getString("GlobalSoundPath", defaultPath); } needVibrate = preferences.getInt("vibrate_messages", 0); priority = preferences.getInt("priority_group", 1); ledColor = preferences.getInt("MessagesLed", 0xff00ff00); } if (preferences.contains("color_" + dialog_id)) { ledColor = preferences.getInt("color_" + dialog_id, 0); } if (priorityOverride != 3) { priority = priorityOverride; } if (needVibrate == 4) { vibrateOnlyIfSilent = true; needVibrate = 0; } if (needVibrate == 2 && (vibrateOverride == 1 || vibrateOverride == 3 || vibrateOverride == 5) || needVibrate != 2 && vibrateOverride == 2 || vibrateOverride != 0) { needVibrate = vibrateOverride; } if (!ApplicationLoader.mainInterfacePaused) { if (!inAppSounds) { choosenSoundPath = null; } if (!inAppVibrate) { needVibrate = 2; } if (!inAppPriority) { priority = 0; } else if (priority == 2) { priority = 1; } } if (vibrateOnlyIfSilent && needVibrate != 2) { try { int mode = audioManager.getRingerMode(); if (mode != AudioManager.RINGER_MODE_SILENT && mode != AudioManager.RINGER_MODE_VIBRATE) { needVibrate = 2; } } catch (Exception e) { FileLog.e("tmessages", e); } } } Intent intent = new Intent(ApplicationLoader.applicationContext, LaunchActivity.class); intent.setAction("com.tmessages.openchat" + Math.random() + Integer.MAX_VALUE); intent.setFlags(32768); if ((int) dialog_id != 0) { if (pushDialogs.size() == 1) { if (chat_id != 0) { intent.putExtra("chatId", chat_id); } else if (user_id != 0) { intent.putExtra("userId", user_id); } } if (AndroidUtilities.needShowPasscode(false) || UserConfig.isWaitingForPasscodeEnter) { photoPath = null; } else { if (pushDialogs.size() == 1) { if (chat != null) { if (chat.photo != null && chat.photo.photo_small != null && chat.photo.photo_small.volume_id != 0 && chat.photo.photo_small.local_id != 0) { photoPath = chat.photo.photo_small; } } else { if (user.photo != null && user.photo.photo_small != null && user.photo.photo_small.volume_id != 0 && user.photo.photo_small.local_id != 0) { photoPath = user.photo.photo_small; } } } } } else { if (pushDialogs.size() == 1) { intent.putExtra("encId", (int) (dialog_id >> 32)); } } PendingIntent contentIntent = PendingIntent.getActivity(ApplicationLoader.applicationContext, 0, intent, PendingIntent.FLAG_ONE_SHOT); String name; boolean replace = true; if ((int) dialog_id == 0 || pushDialogs.size() > 1 || AndroidUtilities.needShowPasscode(false) || UserConfig.isWaitingForPasscodeEnter) { name = LocaleController.getString("AppName", R.string.AppName); replace = false; } else { if (chat != null) { name = chat.title; } else { name = UserObject.getUserName(user); } } String detailText; if (pushDialogs.size() == 1) { detailText = LocaleController.formatPluralString("NewMessages", total_unread_count); } else { detailText = LocaleController.formatString("NotificationMessagesPeopleDisplayOrder", R.string.NotificationMessagesPeopleDisplayOrder, LocaleController.formatPluralString("NewMessages", total_unread_count), LocaleController.formatPluralString("FromChats", pushDialogs.size())); } NotificationCompat.Builder mBuilder = new NotificationCompat.Builder( ApplicationLoader.applicationContext).setContentTitle(name) .setSmallIcon(R.drawable.notification).setAutoCancel(true).setNumber(total_unread_count) .setContentIntent(contentIntent).setGroup("messages").setGroupSummary(true) .setColor(0xff2ca5e0); if (!notifyAboutLast) { mBuilder.setPriority(NotificationCompat.PRIORITY_LOW); } else { if (priority == 0) { mBuilder.setPriority(NotificationCompat.PRIORITY_DEFAULT); } else if (priority == 1) { mBuilder.setPriority(NotificationCompat.PRIORITY_HIGH); } else if (priority == 2) { mBuilder.setPriority(NotificationCompat.PRIORITY_MAX); } } mBuilder.setCategory(NotificationCompat.CATEGORY_MESSAGE); if (chat == null && user != null && user.phone != null && user.phone.length() > 0) { mBuilder.addPerson("tel:+" + user.phone); } String lastMessage = null; if (pushMessages.size() == 1) { String message = lastMessage = getStringForMessage(pushMessages.get(0), false); if (message == null) { return; } if (replace) { if (chat != null) { message = message.replace(" @ " + name, ""); } else { message = message.replace(name + ": ", "").replace(name + " ", ""); } } mBuilder.setContentText(message); mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(message)); } else { mBuilder.setContentText(detailText); NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(); inboxStyle.setBigContentTitle(name); int count = Math.min(10, pushMessages.size()); for (int i = 0; i < count; i++) { String message = getStringForMessage(pushMessages.get(i), false); if (message == null) { continue; } if (i == 0) { lastMessage = message; } if (pushDialogs.size() == 1) { if (replace) { if (chat != null) { message = message.replace(" @ " + name, ""); } else { message = message.replace(name + ": ", "").replace(name + " ", ""); } } } inboxStyle.addLine(message); } inboxStyle.setSummaryText(detailText); mBuilder.setStyle(inboxStyle); } if (photoPath != null) { BitmapDrawable img = ImageLoader.getInstance().getImageFromMemory(photoPath, null, "50_50"); if (img != null) { mBuilder.setLargeIcon(img.getBitmap()); } } if (!notifyDisabled) { if (ApplicationLoader.mainInterfacePaused || inAppPreview) { if (lastMessage.length() > 100) { lastMessage = lastMessage.substring(0, 100).replace("\n", " ").trim() + "..."; } mBuilder.setTicker(lastMessage); } if (choosenSoundPath != null && !choosenSoundPath.equals("NoSound")) { if (choosenSoundPath.equals(defaultPath)) { /*MediaPlayer mediaPlayer = new MediaPlayer(); mediaPlayer.setAudioStreamType(AudioManager.STREAM_ALARM); mediaPlayer.setDataSource(ApplicationLoader.applicationContext, Settings.System.DEFAULT_NOTIFICATION_URI); mediaPlayer.prepare(); mediaPlayer.start();*/ mBuilder.setSound(Settings.System.DEFAULT_NOTIFICATION_URI, AudioManager.STREAM_NOTIFICATION); } else { mBuilder.setSound(Uri.parse(choosenSoundPath), AudioManager.STREAM_NOTIFICATION); } } if (ledColor != 0) { mBuilder.setLights(ledColor, 1000, 1000); } if (needVibrate == 2) { mBuilder.setVibrate(new long[] { 0, 0 }); } else if (needVibrate == 1) { mBuilder.setVibrate(new long[] { 0, 100, 0, 100 }); } else if (needVibrate == 0 || needVibrate == 4) { mBuilder.setDefaults(NotificationCompat.DEFAULT_VIBRATE); } else if (needVibrate == 3) { mBuilder.setVibrate(new long[] { 0, 1000 }); } } else { mBuilder.setVibrate(new long[] { 0, 0 }); } showExtraNotifications(mBuilder, notifyAboutLast); notificationManager.notify(1, mBuilder.build()); scheduleNotificationRepeat(); } catch (Exception e) { FileLog.e("tmessages", e); } }
From source file:com.strathclyde.highlightingkeyboard.SoftKeyboardService.java
/** * Manages actual input into the editor. Here we: * implement our injection algorithm as required * store data relating to the key press/*w w w . ja v a 2 s .c o m*/ * initiate any spell checking as required */ public void onKey(int primaryCode, int[] keyCodes) { // touches all done, add the chars to the event and then the event to the session currentEvent.keyCode = primaryCode; if (errorInjection && primaryCode >= 32) { //give a n% chance of the key being modified Random r = new Random(); int res = r.nextInt(100); if (res <= errorInjectionThreshold) //%n chance of key being modified { //Log.i("OnKey", "Will modify"); try { //for each combination in the model, find the eucleidian distance and the replacement freq JSONObject targetObj = suspectReplacementDistribution .getJSONObject(Integer.toString(primaryCode)); Iterator<?> keys = targetObj.keys(); ArrayList<Character> list = new ArrayList(); while (keys.hasNext()) { String key = (String) keys.next(); int freq = targetObj.getInt(key); //if the frequency is 0, add the suspect as a replacement candidate double dist = keyModel.distance2(primaryCode, Integer.parseInt(key)); if (dist > 0) { if (dist > 2.0) //fix it so that only nearby keys have a chance of being elected dist = 100; //add to the list of candidates as many times as required if specific freq>0; int sfreq = (int) Math.round(freq / dist); //Log.i("Test", "Freq/Dist to "+key+": "+freq+"/"+dist+" final prob: "+sfreq); if (sfreq == 0) //add the suspect as a replacement candidate { list.add(Character.toChars(primaryCode)[0]); } else //add the other replacement candidates as required { for (int x = 0; x < targetObj.getInt(key); x++) { list.add(Character.toChars(Integer.parseInt(key))[0]); } } } } //Log.i("OnKey", "Replace list size: "+list.size()); Random x = new Random(); int sel = x.nextInt(list.size()); //if the replacement eventually happens if ((int) list.get(sel) != primaryCode) { if (errorInjectionSound) { final ToneGenerator tg = new ToneGenerator(AudioManager.STREAM_NOTIFICATION, 100); tg.startTone(ToneGenerator.TONE_CDMA_SOFT_ERROR_LITE); } //primaryCode = (int)list.get(sel); //Log.w("OnKey", "Replace "+Character.toChars(primaryCode)[0]+" with "+list.get(sel)); errorMap.put(mComposing.length(), (char) (int) list.get(sel)); //put in our current position and the replacement //nInjections++; } else Log.i("OnKey", "Replacement will not happen, same key selected"); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { //Log.i("OnKey", "Will not modify, r="+res); } } //switch adaptxt language if necessary if (coreEngine != null) { switch (mInputView.currentKeyboard) { case KeyboardViews.QWERTY_EL: coreEngine.activateLanguageKeymap(131092, null); coreEngine.setDictionaryPriority(131092, 0); break; case KeyboardViews.QWERTY_EN: coreEngine.activateLanguageKeymap(131081, null); coreEngine.setDictionaryPriority(131092, 1); break; } } //get the full inputted text extr = ic.getExtractedText(new ExtractedTextRequest(), 0); if (currentEvent != null && captureData == true) { //Log.i("OnKey", "OK to capture data!"); currentEvent.user = userid; if (primaryCode > 0) currentEvent.keyChar = (char) primaryCode; //handle the booleans if (currentSession.events.get(currentSession.events.size() - 1).keyChar == ' ') //space { currentEvent.followsSpace = true; } if (currentEvent.keyCode == Keyboard.KEYCODE_DELETE) { System.out.println("Backspace Pressed!"); //if a delete is pressed after another delete //and its cursor position is not -1 from the previous delete //we must commit the previous deletion as a suspect character. if (currentSession.events.get(currentSession.events.size() - 1).keyCode == Keyboard.KEYCODE_DELETE && extr.selectionStart != lastDeletedPos - 1) { currentSession.suspects.add(lastDeleted); //System.out.println("Suspect = "+lastDeleted); } //get all the text before the backspace press and the current cursor position if (extr.selectionStart > 0) { lastDeleted = extr.text.charAt(extr.selectionStart - 1); lastDeletedPos = extr.selectionStart; //System.out.println("Deleted = "+lastDeleted+"\nCursor Position = "+extr.selectionStart); } } //if the current key is NOT a backspace but the previous one was if (currentEvent.keyCode != Keyboard.KEYCODE_DELETE && currentSession.events .get(currentSession.events.size() - 1).keyCode == Keyboard.KEYCODE_DELETE) { currentSession.suspects.add(lastDeleted); //System.out.println("Suspect = "+lastDeleted); } } //do the handling if (isWordSeparator(primaryCode)) { // Handle separator //System.out.println("Detected a word separator \""+primaryCode+"\""); if (primaryCode != 32) { shouldInsertSpace = false; if (extr.text.length() > 0) { //Log.i("On Key ", "last letter after separator was ["+extr.text.charAt(extr.selectionStart-1)+"]"); //check if the previous char was a space, if so delete it. if (extr.text.charAt(extr.selectionStart - 1) == ' ' && !isSpecialSeparator(primaryCode)) //detecting if the current char is not part of a smiley face { onKey(-5, null); } } } //clear the touch history clearDots(); //ensure spell checker is using correct language SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); Editor ed = prefs.edit(); if (captureData) { if (mInputView.currentLang == 1) //english { ed.putString("available_dicts", "en"); ed.commit(); if (mScs != null) mScs.close(); String lang = prefs.getString("available_dicts", "jam"); Log.i("OnKey", "Spellcheck lang set to " + lang); Locale english = new Locale("en", "GB"); mScs = tsm.newSpellCheckerSession(null, english, this, false); if (mScs == null) Log.e("OnKey", "Failed to obtain spell-checker session"); } else { ed.putString("available_dicts", "el"); ed.commit(); if (mScs != null) mScs.close(); String lang = prefs.getString("available_dicts", "jam"); Log.i("OnKey", "Spellcheck lang set to " + lang); Locale greek = new Locale("el", "GR"); mScs = tsm.newSpellCheckerSession(null, greek, this, false); if (mScs == null) Log.e("OnKey", "Failed to obtain spell-checker session"); } } //handle space for Adaptxt if (Character.isSpaceChar(primaryCode)) { if (coreEngine != null) { //Log.i("Handle Character", "Space pressed"); coreEngine.resetCoreString(); //Log.i("Space Pressed", "Word is "+mComposing+" "); coreEngine.insertText(mComposing.toString() + " "); updateCandidates(); } } if (!firstWordSet && mComposing.length() > 1) { if (captureData) currentSession.firstWord = mComposing.toString(); else currentSession.firstWord = "$$$$"; firstWordSet = true; //System.out.println("First Word\""+mComposing.toString()+"\""); } //effect any injections as required if (mComposing.length() > 0) { //commitTyped(getCurrentInputConnection()); //check the errormap for any replacements if (errorMap.size() > 0) { //restrict the errormap to the 25% of word length cap int replacementstodelete = errorMap.size() - (int) Math.round(mComposing.length() * 0.25); //total replacements - those to keep if (replacementstodelete < 0) replacementstodelete = 0; //allow at least one if (errorMap.size() == replacementstodelete) replacementstodelete = errorMap.size() - 1; if (replacementstodelete > 0) { List<Integer> keys = new ArrayList<Integer>(errorMap.keySet()); for (int z = 0; z < replacementstodelete; z++) { Random random = new Random(); int listposition = random.nextInt(keys.size()); int randomKey = keys.get(listposition); //remove this from the error map and the list errorMap.remove(randomKey); keys.remove(listposition); } } //effect the injections String oldmComposing = mComposing.toString(); Iterator it = errorMap.entrySet().iterator(); while (it.hasNext()) { Map.Entry pair = (Map.Entry) it.next(); mComposing.replace((Integer) pair.getKey(), (Integer) pair.getKey() + 1, "" + (Character) pair.getValue()); //it.remove(); // avoids a ConcurrentModificationException } nInjections += errorMap.size(); currentSession.nInjections = nInjections; //Log.i("Injections", "Will replace "+oldmComposing+" with "+mComposing+", nInjections="+nInjections); errorMap.clear(); } wordSeparatorKeyCode = primaryCode; if (captureData) commitTyped(ic, isWordSeparator(primaryCode)); else { if (primaryCode != Keyboard.KEYCODE_DONE && primaryCode != 10) //done and go/enter handleCharacter(primaryCode, keyCodes); else sendKey(primaryCode); commitTyped(ic); } } else { sendKey(primaryCode); } updateShiftKeyState(getCurrentInputEditorInfo()); } else if (primaryCode == Keyboard.KEYCODE_DELETE) { if (errorMap.get(mComposing.length() - 1) != null) { //Log.i("Injection", "Delete from map pos="+(mComposing.length()-1)+", char="+errorMap.get(mComposing.length()-1)); errorMap.remove(mComposing.length() - 1); } handleBackspace(); } else if (primaryCode == Keyboard.KEYCODE_SHIFT) { handleShift(); } else if (primaryCode == Keyboard.KEYCODE_CANCEL) { //keyboard hiding button //override this for settings activity //handleClose(); Intent intent = new Intent(this, LoggingIMESettings.class); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); return; } else if (primaryCode == LatinKeyboardView.KEYCODE_OPTIONS) { // Show a menu or somethin' } else if (primaryCode == Keyboard.KEYCODE_MODE_CHANGE && mInputView != null) { //Keyboard current = mInputView.getKeyboard(); if (mInputView.currentKeyboard == KeyboardViews.SYMBOLS || mInputView.currentKeyboard == KeyboardViews.SYMBOLS_SHIFTED) { //mInputView.currentKeyboard = KeyboardViews.QWERTY_EN; mInputView.currentKeyboard = lastKeyboardView; } else { //about to change to symbols lastKeyboardView = mInputView.currentKeyboard; //keep track of where we came from mInputView.currentKeyboard = KeyboardViews.SYMBOLS; } mInputView.switchKeyboard(); if (mInputView.currentKeyboard == KeyboardViews.SYMBOLS) { mInputView.getKeyboard().setShifted(false); } } else { handleCharacter(primaryCode, keyCodes); } }
From source file:com.android.messaging.datamodel.BugleNotifications.java
/** * Play the observable conversation notification sound (it's the regular notification sound, but * played at half-volume)//from w w w .j a v a 2 s.co m */ private static void playObservableConversationNotificationSound(final Uri ringtoneUri) { final Context context = Factory.get().getApplicationContext(); final AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); final boolean silenced = audioManager.getRingerMode() != AudioManager.RINGER_MODE_NORMAL; if (silenced) { return; } final NotificationPlayer player = new NotificationPlayer(LogUtil.BUGLE_TAG); player.play(ringtoneUri, false, AudioManager.STREAM_NOTIFICATION, OBSERVABLE_CONVERSATION_NOTIFICATION_VOLUME); // Stop the sound after five seconds to handle continuous ringtones ThreadUtil.getMainThreadHandler().postDelayed(new Runnable() { @Override public void run() { player.stop(); } }, 5000); }
From source file:org.getlantern.firetweet.provider.FiretweetDataProvider.java
private void setNotificationPreferences(NotificationCompat.Builder builder, AccountPreferences pref, int defaultFlags) { int notificationDefaults = 0; if (AccountPreferences.isNotificationHasLight(defaultFlags)) { notificationDefaults |= NotificationCompat.DEFAULT_LIGHTS; }//from ww w . j ava2 s. c om if (isNotificationAudible()) { if (AccountPreferences.isNotificationHasVibration(defaultFlags)) { notificationDefaults |= NotificationCompat.DEFAULT_VIBRATE; } else { notificationDefaults &= ~NotificationCompat.DEFAULT_VIBRATE; } if (AccountPreferences.isNotificationHasRingtone(defaultFlags)) { notificationDefaults |= NotificationCompat.DEFAULT_SOUND; builder.setSound(pref.getNotificationRingtone(), AudioManager.STREAM_NOTIFICATION); } } else { notificationDefaults &= ~(NotificationCompat.DEFAULT_VIBRATE | NotificationCompat.DEFAULT_SOUND); } builder.setDefaults(notificationDefaults); }
From source file:com.b44t.messenger.NotificationsController.java
private void showOrUpdateNotification(boolean notifyAboutLast) { if (pushMessages.isEmpty()) { dismissNotification();// w ww. j av a 2 s . c o m return; } try { ConnectionsManager.getInstance().resumeNetworkMaybe(); MessageObject lastMessageObject = pushMessages.get(0); SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("Notifications", Context.MODE_PRIVATE); int dismissDate = preferences.getInt("dismissDate", 0); if (lastMessageObject.messageOwner.date <= dismissDate) { dismissNotification(); return; } final long dialog_id = lastMessageObject.getDialogId(); //int mid = lastMessageObject.getId(); final int user_id = lastMessageObject.messageOwner.from_id; //TLRPC.User user = MessagesController.getInstance().getUser(user_id); MrChat mrChat = MrMailbox.getChat((int) dialog_id); boolean isGroupChat = mrChat.getType() == MrChat.MR_CHAT_GROUP; //TLRPC.FileLocation photoPath = null; boolean notifyDisabled = false; int needVibrate = 0; String choosenSoundPath = null; int ledColor = 0xff00ff00; boolean inAppSounds; boolean inAppVibrate; //boolean inAppPreview = false; int priority = 0; int priorityOverride; int vibrateOverride; int notifyOverride = getNotifyOverride(preferences, dialog_id); if (!notifyAboutLast || notifyOverride == 2 || (!preferences.getBoolean("EnableAll", true) || isGroupChat && !preferences.getBoolean("EnableGroup", true)) && notifyOverride == 0) { notifyDisabled = true; } if (!notifyDisabled && isGroupChat) { int notifyMaxCount = preferences.getInt("smart_max_count_" + dialog_id, 0); int notifyDelay = preferences.getInt("smart_delay_" + dialog_id, 3 * 60); if (notifyMaxCount != 0) { Point dialogInfo = smartNotificationsDialogs.get(dialog_id); if (dialogInfo == null) { dialogInfo = new Point(1, (int) (System.currentTimeMillis() / 1000)); smartNotificationsDialogs.put(dialog_id, dialogInfo); } else { int lastTime = dialogInfo.y; if (lastTime + notifyDelay < System.currentTimeMillis() / 1000) { dialogInfo.set(1, (int) (System.currentTimeMillis() / 1000)); } else { int count = dialogInfo.x; if (count < notifyMaxCount) { dialogInfo.set(count + 1, (int) (System.currentTimeMillis() / 1000)); } else { notifyDisabled = true; } } } } } String defaultPath = Settings.System.DEFAULT_NOTIFICATION_URI.getPath(); if (!notifyDisabled) { inAppSounds = preferences.getBoolean("EnableInAppSounds", true); inAppVibrate = preferences.getBoolean("EnableInAppVibrate", true); vibrateOverride = preferences.getInt("vibrate_" + dialog_id, 0); priorityOverride = preferences.getInt("priority_" + dialog_id, 3); boolean vibrateOnlyIfSilent = false; choosenSoundPath = preferences.getString("sound_path_" + dialog_id, null); if (isGroupChat) { if (choosenSoundPath != null && choosenSoundPath.equals(defaultPath)) { choosenSoundPath = null; } else if (choosenSoundPath == null) { choosenSoundPath = preferences.getString("GroupSoundPath", defaultPath); } needVibrate = preferences.getInt("vibrate_group", 0); priority = preferences.getInt("priority_group", 1); ledColor = preferences.getInt("GroupLed", 0xff00ff00); } else { if (choosenSoundPath != null && choosenSoundPath.equals(defaultPath)) { choosenSoundPath = null; } else if (choosenSoundPath == null) { choosenSoundPath = preferences.getString("GlobalSoundPath", defaultPath); } needVibrate = preferences.getInt("vibrate_messages", 0); priority = preferences.getInt("priority_messages", 1); ledColor = preferences.getInt("MessagesLed", 0xff00ff00); } if (preferences.contains("color_" + dialog_id)) { ledColor = preferences.getInt("color_" + dialog_id, 0); } if (priorityOverride != 3) { priority = priorityOverride; } if (needVibrate == 4) { vibrateOnlyIfSilent = true; needVibrate = 0; } if (needVibrate == 2 && (vibrateOverride == 1 || vibrateOverride == 3 || vibrateOverride == 5) || needVibrate != 2 && vibrateOverride == 2 || vibrateOverride != 0) { needVibrate = vibrateOverride; } if (!ApplicationLoader.mainInterfacePaused) { if (!inAppSounds) { choosenSoundPath = null; } if (!inAppVibrate) { needVibrate = 2; } priority = preferences.getInt("priority_inapp", 0); } if (vibrateOnlyIfSilent && needVibrate != 2) { try { int mode = audioManager.getRingerMode(); if (mode != AudioManager.RINGER_MODE_SILENT && mode != AudioManager.RINGER_MODE_VIBRATE) { needVibrate = 2; } } catch (Exception e) { FileLog.e("messenger", e); } } } Intent intent = new Intent(ApplicationLoader.applicationContext, LaunchActivity.class); intent.setAction("com.b44t.messenger.openchat" + (pushDialogs.size() == 1 ? dialog_id : 0)); intent.setFlags(32768); PendingIntent contentIntent = PendingIntent.getActivity(ApplicationLoader.applicationContext, 0, intent, PendingIntent.FLAG_ONE_SHOT); boolean showPreview = preferences.getBoolean("EnablePreviewAll", true); if (AndroidUtilities.needShowPasscode(false) || UserConfig.isWaitingForPasscodeEnter) { showPreview = false; } String name; if (pushDialogs.size() > 1 || !showPreview) { name = mContext.getString(R.string.AppName); } else { if (isGroupChat) { name = mrChat.getName(); } else { name = MrMailbox.getContact(user_id).getDisplayName(); } } String detailText; if (pushDialogs.size() == 1) { detailText = mContext.getResources().getQuantityString(R.plurals.NewMessages, total_unread_count, total_unread_count); } else { String newMessages = mContext.getResources().getQuantityString(R.plurals.NewMessages, total_unread_count, total_unread_count); detailText = mContext.getResources().getQuantityString(R.plurals.NewMessagesInChats, pushDialogs.size(), newMessages, pushDialogs.size()); } NotificationCompat.Builder mBuilder = new NotificationCompat.Builder( ApplicationLoader.applicationContext).setContentTitle(name) .setSmallIcon(R.drawable.notification).setAutoCancel(true).setNumber(total_unread_count) .setContentIntent(contentIntent).setGroup("messages").setGroupSummary(true) .setColor(Theme.ACTION_BAR_COLOR); mBuilder.setCategory(NotificationCompat.CATEGORY_MESSAGE); int silent = 2; String lastMessage = null; boolean hasNewMessages = false; if (!showPreview) { mBuilder.setContentText(detailText); lastMessage = detailText; } else if (pushMessages.size() == 1) { MessageObject messageObject = pushMessages.get(0); String message = lastMessage = getStringForMessage(messageObject, isGroupChat ? ADD_USER : 0); silent = messageObject.messageOwner.silent ? 1 : 0; if (message == null) { return; } mBuilder.setContentText(message); mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(message)); } else { mBuilder.setContentText(detailText); NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(); inboxStyle.setBigContentTitle(name); int count = Math.min(10, pushMessages.size()); int string_flags = 0; if (pushDialogs.size() > 1) { string_flags |= ADD_GROUP; } for (int i = 1/*user_id is #0*/; i < pushMessages.size(); i++) { MessageObject messageObject = pushMessages.get(i); if (messageObject.messageOwner.from_id != user_id) { string_flags |= ADD_USER; break; } } for (int i = 0; i < count; i++) { MessageObject messageObject = pushMessages.get(i); String message = getStringForMessage(messageObject, string_flags); if (message == null || messageObject.messageOwner.date <= dismissDate) { continue; } if (silent == 2) { lastMessage = message; silent = messageObject.messageOwner.silent ? 1 : 0; } /*if (pushDialogs.size() == 1) { if (replace) { if (chat != null) { message = message.replace(" @ " + name, ""); } else { message = message.replace(name + ": ", "").replace(name + " ", ""); } } }*/ inboxStyle.addLine(message); } inboxStyle.setSummaryText(detailText); mBuilder.setStyle(inboxStyle); } Intent dismissIntent = new Intent(ApplicationLoader.applicationContext, NotificationDismissReceiver.class); dismissIntent.putExtra("messageDate", lastMessageObject.messageOwner.date); mBuilder.setDeleteIntent(PendingIntent.getBroadcast(ApplicationLoader.applicationContext, 1, dismissIntent, PendingIntent.FLAG_UPDATE_CURRENT)); /*if (photoPath != null) { BitmapDrawable img = ImageLoader.getInstance().getImageFromMemory(photoPath, null, "50_50"); if (img != null) { mBuilder.setLargeIcon(img.getBitmap()); } else { try { float scaleFactor = 160.0f / AndroidUtilities.dp(50); BitmapFactory.Options options = new BitmapFactory.Options(); options.inSampleSize = scaleFactor < 1 ? 1 : (int) scaleFactor; Bitmap bitmap = BitmapFactory.decodeFile(FileLoader.getPathToAttach(photoPath, true).toString(), options); if (bitmap != null) { mBuilder.setLargeIcon(bitmap); } } catch (Throwable e) { //ignore } } }*/ if (!notifyAboutLast || silent == 1) { mBuilder.setPriority(NotificationCompat.PRIORITY_LOW); } else { if (priority == 0) { mBuilder.setPriority(NotificationCompat.PRIORITY_DEFAULT); } else if (priority == 1) { mBuilder.setPriority(NotificationCompat.PRIORITY_HIGH); } else if (priority == 2) { mBuilder.setPriority(NotificationCompat.PRIORITY_MAX); } } if (silent != 1 && !notifyDisabled) { /*if (ApplicationLoader.mainInterfacePaused || inAppPreview)*/ { if (lastMessage.length() > 100) { lastMessage = lastMessage.substring(0, 100).replace('\n', ' ').trim() + "..."; } mBuilder.setTicker(lastMessage); } if (!MediaController.getInstance().isRecordingAudio()) { if (choosenSoundPath != null && !choosenSoundPath.equals("NoSound")) { if (choosenSoundPath.equals(defaultPath)) { mBuilder.setSound(Settings.System.DEFAULT_NOTIFICATION_URI, AudioManager.STREAM_NOTIFICATION); } else { mBuilder.setSound(Uri.parse(choosenSoundPath), AudioManager.STREAM_NOTIFICATION); } } } if (ledColor != 0) { mBuilder.setLights(ledColor, 1000, 1000); } if (needVibrate == 2 || MediaController.getInstance().isRecordingAudio()) { mBuilder.setVibrate(new long[] { 0, 0 }); } else if (needVibrate == 1) { mBuilder.setVibrate(new long[] { 0, 100, 0, 100 }); } else if (needVibrate == 0 || needVibrate == 4) { mBuilder.setDefaults(NotificationCompat.DEFAULT_VIBRATE); } else if (needVibrate == 3) { mBuilder.setVibrate(new long[] { 0, 1000 }); } } else { mBuilder.setVibrate(new long[] { 0, 0 }); } //showExtraNotifications(mBuilder, notifyAboutLast); notificationManager.notify(1, mBuilder.build()); scheduleNotificationRepeat(); if (preferences.getBoolean("badgeNumber", true)) { setBadge(total_unread_count); } } catch (Exception e) { FileLog.e("messenger", e); } }
From source file:org.telegram.messenger.NotificationsController.java
private void showOrUpdateNotification(boolean notifyAboutLast) { if (!UserConfig.isClientActivated() || pushMessages.isEmpty()) { dismissNotification();//w ww. j a v a 2s.c om return; } try { ConnectionsManager.getInstance().resumeNetworkMaybe(); MessageObject lastMessageObject = pushMessages.get(0); long dialog_id = lastMessageObject.getDialogId(); long override_dialog_id = dialog_id; if ((lastMessageObject.messageOwner.flags & TLRPC.MESSAGE_FLAG_MENTION) != 0) { override_dialog_id = lastMessageObject.messageOwner.from_id; } int mid = lastMessageObject.getId(); int chat_id = lastMessageObject.messageOwner.to_id.chat_id != 0 ? lastMessageObject.messageOwner.to_id.chat_id : lastMessageObject.messageOwner.to_id.channel_id; int user_id = lastMessageObject.messageOwner.to_id.user_id; if (user_id == 0) { user_id = lastMessageObject.messageOwner.from_id; } else if (user_id == UserConfig.getClientUserId()) { user_id = lastMessageObject.messageOwner.from_id; } TLRPC.User user = MessagesController.getInstance().getUser(user_id); TLRPC.Chat chat = null; if (chat_id != 0) { chat = MessagesController.getInstance().getChat(chat_id); } TLRPC.FileLocation photoPath = null; boolean notifyDisabled = false; int needVibrate = 0; String choosenSoundPath = null; int ledColor = 0xff00ff00; boolean inAppSounds; boolean inAppVibrate; boolean inAppPreview = false; boolean inAppPriority; int priority = 0; int priorityOverride; int vibrateOverride; SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("Notifications", Context.MODE_PRIVATE); int notifyOverride = getNotifyOverride(preferences, override_dialog_id); if (!notifyAboutLast || notifyOverride == 2 || (!preferences.getBoolean("EnableAll", true) || chat_id != 0 && !preferences.getBoolean("EnableGroup", true)) && notifyOverride == 0) { notifyDisabled = true; } if (!notifyDisabled && dialog_id == override_dialog_id && chat != null) { int notifyMaxCount = preferences.getInt("smart_max_count_" + dialog_id, 2); int notifyDelay = preferences.getInt("smart_delay_" + dialog_id, 3 * 60); if (notifyMaxCount != 0) { Point dialogInfo = smartNotificationsDialogs.get(dialog_id); if (dialogInfo == null) { dialogInfo = new Point(1, (int) (System.currentTimeMillis() / 1000)); smartNotificationsDialogs.put(dialog_id, dialogInfo); } else { int lastTime = dialogInfo.y; if (lastTime + notifyDelay < System.currentTimeMillis() / 1000) { dialogInfo.set(1, (int) (System.currentTimeMillis() / 1000)); } else { int count = dialogInfo.x; if (count < notifyMaxCount) { dialogInfo.set(count + 1, (int) (System.currentTimeMillis() / 1000)); } else { notifyDisabled = true; } } } } } String defaultPath = Settings.System.DEFAULT_NOTIFICATION_URI.getPath(); if (!notifyDisabled) { inAppSounds = preferences.getBoolean("EnableInAppSounds", true); inAppVibrate = preferences.getBoolean("EnableInAppVibrate", true); inAppPreview = preferences.getBoolean("EnableInAppPreview", true); inAppPriority = preferences.getBoolean("EnableInAppPriority", false); vibrateOverride = preferences.getInt("vibrate_" + dialog_id, 0); priorityOverride = preferences.getInt("priority_" + dialog_id, 3); boolean vibrateOnlyIfSilent = false; choosenSoundPath = preferences.getString("sound_path_" + dialog_id, null); if (chat_id != 0) { if (choosenSoundPath != null && choosenSoundPath.equals(defaultPath)) { choosenSoundPath = null; } else if (choosenSoundPath == null) { choosenSoundPath = preferences.getString("GroupSoundPath", defaultPath); } needVibrate = preferences.getInt("vibrate_group", 0); priority = preferences.getInt("priority_group", 1); ledColor = preferences.getInt("GroupLed", 0xff00ff00); } else if (user_id != 0) { if (choosenSoundPath != null && choosenSoundPath.equals(defaultPath)) { choosenSoundPath = null; } else if (choosenSoundPath == null) { choosenSoundPath = preferences.getString("GlobalSoundPath", defaultPath); } needVibrate = preferences.getInt("vibrate_messages", 0); priority = preferences.getInt("priority_group", 1); ledColor = preferences.getInt("MessagesLed", 0xff00ff00); } if (preferences.contains("color_" + dialog_id)) { ledColor = preferences.getInt("color_" + dialog_id, 0); } if (priorityOverride != 3) { priority = priorityOverride; } if (needVibrate == 4) { vibrateOnlyIfSilent = true; needVibrate = 0; } if (needVibrate == 2 && (vibrateOverride == 1 || vibrateOverride == 3 || vibrateOverride == 5) || needVibrate != 2 && vibrateOverride == 2 || vibrateOverride != 0) { needVibrate = vibrateOverride; } if (!ApplicationLoader.mainInterfacePaused) { if (!inAppSounds) { choosenSoundPath = null; } if (!inAppVibrate) { needVibrate = 2; } if (!inAppPriority) { priority = 0; } else if (priority == 2) { priority = 1; } } if (vibrateOnlyIfSilent && needVibrate != 2) { try { int mode = audioManager.getRingerMode(); if (mode != AudioManager.RINGER_MODE_SILENT && mode != AudioManager.RINGER_MODE_VIBRATE) { needVibrate = 2; } } catch (Exception e) { FileLog.e("tmessages", e); } } } Intent intent = new Intent(ApplicationLoader.applicationContext, LaunchActivity.class); intent.setAction("com.tmessages.openchat" + Math.random() + Integer.MAX_VALUE); intent.setFlags(32768); if ((int) dialog_id != 0) { if (pushDialogs.size() == 1) { if (chat_id != 0) { intent.putExtra("chatId", chat_id); } else if (user_id != 0) { intent.putExtra("userId", user_id); } } if (AndroidUtilities.needShowPasscode(false) || UserConfig.isWaitingForPasscodeEnter) { photoPath = null; } else { if (pushDialogs.size() == 1) { if (chat != null) { if (chat.photo != null && chat.photo.photo_small != null && chat.photo.photo_small.volume_id != 0 && chat.photo.photo_small.local_id != 0) { photoPath = chat.photo.photo_small; } } else if (user != null) { if (user.photo != null && user.photo.photo_small != null && user.photo.photo_small.volume_id != 0 && user.photo.photo_small.local_id != 0) { photoPath = user.photo.photo_small; } } } } } else { if (pushDialogs.size() == 1) { intent.putExtra("encId", (int) (dialog_id >> 32)); } } PendingIntent contentIntent = PendingIntent.getActivity(ApplicationLoader.applicationContext, 0, intent, PendingIntent.FLAG_ONE_SHOT); String name; boolean replace = true; if ((int) dialog_id == 0 || pushDialogs.size() > 1 || AndroidUtilities.needShowPasscode(false) || UserConfig.isWaitingForPasscodeEnter) { name = LocaleController.getString("AppName", R.string.AppName); replace = false; } else { if (chat != null) { name = chat.title; } else { name = UserObject.getUserName(user); } } String detailText; if (pushDialogs.size() == 1) { detailText = LocaleController.formatPluralString("NewMessages", total_unread_count); } else { detailText = LocaleController.formatString("NotificationMessagesPeopleDisplayOrder", R.string.NotificationMessagesPeopleDisplayOrder, LocaleController.formatPluralString("NewMessages", total_unread_count), LocaleController.formatPluralString("FromChats", pushDialogs.size())); } NotificationCompat.Builder mBuilder = new NotificationCompat.Builder( ApplicationLoader.applicationContext).setContentTitle(name) .setSmallIcon(R.drawable.notification).setAutoCancel(true).setNumber(total_unread_count) .setContentIntent(contentIntent).setGroup("messages").setGroupSummary(true) .setColor(0xff2ca5e0); if (!notifyAboutLast) { mBuilder.setPriority(NotificationCompat.PRIORITY_LOW); } else { if (priority == 0) { mBuilder.setPriority(NotificationCompat.PRIORITY_DEFAULT); } else if (priority == 1) { mBuilder.setPriority(NotificationCompat.PRIORITY_HIGH); } else if (priority == 2) { mBuilder.setPriority(NotificationCompat.PRIORITY_MAX); } } mBuilder.setCategory(NotificationCompat.CATEGORY_MESSAGE); if (chat == null && user != null && user.phone != null && user.phone.length() > 0) { mBuilder.addPerson("tel:+" + user.phone); } String lastMessage = null; if (pushMessages.size() == 1) { String message = lastMessage = getStringForMessage(pushMessages.get(0), false); if (message == null) { return; } if (replace) { if (chat != null) { message = message.replace(" @ " + name, ""); } else { message = message.replace(name + ": ", "").replace(name + " ", ""); } } mBuilder.setContentText(message); mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(message)); } else { mBuilder.setContentText(detailText); NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(); inboxStyle.setBigContentTitle(name); int count = Math.min(10, pushMessages.size()); for (int i = 0; i < count; i++) { String message = getStringForMessage(pushMessages.get(i), false); if (message == null) { continue; } if (i == 0) { lastMessage = message; } if (pushDialogs.size() == 1) { if (replace) { if (chat != null) { message = message.replace(" @ " + name, ""); } else { message = message.replace(name + ": ", "").replace(name + " ", ""); } } } inboxStyle.addLine(message); } inboxStyle.setSummaryText(detailText); mBuilder.setStyle(inboxStyle); } if (photoPath != null) { BitmapDrawable img = ImageLoader.getInstance().getImageFromMemory(photoPath, null, "50_50"); if (img != null) { mBuilder.setLargeIcon(img.getBitmap()); } } if (!notifyDisabled) { if (ApplicationLoader.mainInterfacePaused || inAppPreview) { if (lastMessage.length() > 100) { lastMessage = lastMessage.substring(0, 100).replace("\n", " ").trim() + "..."; } mBuilder.setTicker(lastMessage); } if (choosenSoundPath != null && !choosenSoundPath.equals("NoSound")) { if (choosenSoundPath.equals(defaultPath)) { /*MediaPlayer mediaPlayer = new MediaPlayer(); mediaPlayer.setAudioStreamType(AudioManager.STREAM_ALARM); mediaPlayer.setDataSource(ApplicationLoader.applicationContext, Settings.System.DEFAULT_NOTIFICATION_URI); mediaPlayer.prepare(); mediaPlayer.start();*/ mBuilder.setSound(Settings.System.DEFAULT_NOTIFICATION_URI, AudioManager.STREAM_NOTIFICATION); } else { mBuilder.setSound(Uri.parse(choosenSoundPath), AudioManager.STREAM_NOTIFICATION); } } if (ledColor != 0) { mBuilder.setLights(ledColor, 1000, 1000); } if (needVibrate == 2) { mBuilder.setVibrate(new long[] { 0, 0 }); } else if (needVibrate == 1) { mBuilder.setVibrate(new long[] { 0, 100, 0, 100 }); } else if (needVibrate == 0 || needVibrate == 4) { mBuilder.setDefaults(NotificationCompat.DEFAULT_VIBRATE); } else if (needVibrate == 3) { mBuilder.setVibrate(new long[] { 0, 1000 }); } } else { mBuilder.setVibrate(new long[] { 0, 0 }); } showExtraNotifications(mBuilder, notifyAboutLast); notificationManager.notify(1, mBuilder.build()); scheduleNotificationRepeat(); } catch (Exception e) { FileLog.e("tmessages", e); } }
From source file:com.almalence.plugins.capture.video.VideoCapturePlugin.java
protected void muteAllSounds() { ((AudioManager) ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE)) .setStreamMute(AudioManager.STREAM_ALARM, true); ((AudioManager) ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE)) .setStreamMute(AudioManager.STREAM_DTMF, true); ((AudioManager) ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE)) .setStreamMute(AudioManager.STREAM_MUSIC, true); ((AudioManager) ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE)) .setStreamMute(AudioManager.STREAM_NOTIFICATION, true); ((AudioManager) ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE)) .setStreamMute(AudioManager.STREAM_RING, true); ((AudioManager) ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE)) .setStreamMute(AudioManager.STREAM_SYSTEM, true); ((AudioManager) ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE)) .setStreamMute(AudioManager.STREAM_VOICE_CALL, true); // ((AudioManager)ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE)).setStreamVolume(AudioManager.STREAM_ALARM, 0, 0); // ((AudioManager)ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE)).setStreamVolume(AudioManager.STREAM_DTMF, 0, 0); // ((AudioManager)ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE)).setStreamVolume(AudioManager.STREAM_MUSIC, 0, 0); // ((AudioManager)ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE)).setStreamVolume(AudioManager.STREAM_RING, 0, 0); // ((AudioManager)ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE)).setStreamVolume(AudioManager.STREAM_SYSTEM, 0, 0); // ((AudioManager)ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE)).setStreamVolume(AudioManager.STREAM_VOICE_CALL, 0, 0); // ((AudioManager)ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE)).adjustStreamVolume(AudioManager.STREAM_ALARM, AudioManager.ADJUST_MUTE, 0); // ((AudioManager)ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE)).adjustStreamVolume(AudioManager.STREAM_DTMF, AudioManager.ADJUST_MUTE, 0); // ((AudioManager)ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE)).adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_MUTE, 0); // ((AudioManager)ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE)).adjustStreamVolume(AudioManager.STREAM_RING, AudioManager.ADJUST_MUTE, 0); // ((AudioManager)ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE)).adjustStreamVolume(AudioManager.STREAM_SYSTEM, AudioManager.ADJUST_MUTE, 0); // ((AudioManager)ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE)).adjustStreamVolume(AudioManager.STREAM_VOICE_CALL, AudioManager.ADJUST_MUTE, 0); }
From source file:com.almalence.plugins.capture.video.VideoCapturePlugin.java
protected void unmuteAllSounds() { ((AudioManager) ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE)) .setStreamMute(AudioManager.STREAM_ALARM, false); ((AudioManager) ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE)) .setStreamMute(AudioManager.STREAM_DTMF, false); ((AudioManager) ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE)) .setStreamMute(AudioManager.STREAM_MUSIC, false); ((AudioManager) ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE)) .setStreamMute(AudioManager.STREAM_NOTIFICATION, false); ((AudioManager) ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE)) .setStreamMute(AudioManager.STREAM_RING, false); ((AudioManager) ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE)) .setStreamMute(AudioManager.STREAM_SYSTEM, false); ((AudioManager) ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE)) .setStreamMute(AudioManager.STREAM_VOICE_CALL, false); // ((AudioManager)ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE)).setStreamVolume(AudioManager.STREAM_ALARM, 0, 0); // ((AudioManager)ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE)).setStreamVolume(AudioManager.STREAM_DTMF, 0, 0); // ((AudioManager)ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE)).setStreamVolume(AudioManager.STREAM_MUSIC, 0, 0); // ((AudioManager)ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE)).setStreamVolume(AudioManager.STREAM_RING, 0, 0); // ((AudioManager)ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE)).setStreamVolume(AudioManager.STREAM_SYSTEM, 0, 0); }
From source file:com.goftagram.telegram.messenger.NotificationsController.java
private void showOrUpdateNotification(boolean notifyAboutLast) { if (!UserConfig.isClientActivated() || pushMessages.isEmpty()) { dismissNotification();/*w w w.j a v a2 s .co m*/ return; } try { ConnectionsManager.getInstance().resumeNetworkMaybe(); MessageObject lastMessageObject = pushMessages.get(0); long dialog_id = lastMessageObject.getDialogId(); long override_dialog_id = dialog_id; if (lastMessageObject.messageOwner.mentioned) { override_dialog_id = lastMessageObject.messageOwner.from_id; } int mid = lastMessageObject.getId(); int chat_id = lastMessageObject.messageOwner.to_id.chat_id != 0 ? lastMessageObject.messageOwner.to_id.chat_id : lastMessageObject.messageOwner.to_id.channel_id; int user_id = lastMessageObject.messageOwner.to_id.user_id; if (user_id == 0) { user_id = lastMessageObject.messageOwner.from_id; } else if (user_id == UserConfig.getClientUserId()) { user_id = lastMessageObject.messageOwner.from_id; } TLRPC.User user = MessagesController.getInstance().getUser(user_id); TLRPC.Chat chat = null; if (chat_id != 0) { chat = MessagesController.getInstance().getChat(chat_id); } TLRPC.FileLocation photoPath = null; boolean notifyDisabled = false; int needVibrate = 0; String choosenSoundPath = null; int ledColor = 0xff00ff00; boolean inAppSounds; boolean inAppVibrate; boolean inAppPreview = false; boolean inAppPriority; int priority = 0; int priorityOverride; int vibrateOverride; SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("Notifications", Context.MODE_PRIVATE); int notifyOverride = getNotifyOverride(preferences, override_dialog_id); if (!notifyAboutLast || notifyOverride == 2 || (!preferences.getBoolean("EnableAll", true) || chat_id != 0 && !preferences.getBoolean("EnableGroup", true)) && notifyOverride == 0) { notifyDisabled = true; } if (!notifyDisabled && dialog_id == override_dialog_id && chat != null) { int notifyMaxCount = preferences.getInt("smart_max_count_" + dialog_id, 2); int notifyDelay = preferences.getInt("smart_delay_" + dialog_id, 3 * 60); if (notifyMaxCount != 0) { Point dialogInfo = smartNotificationsDialogs.get(dialog_id); if (dialogInfo == null) { dialogInfo = new Point(1, (int) (System.currentTimeMillis() / 1000)); smartNotificationsDialogs.put(dialog_id, dialogInfo); } else { int lastTime = dialogInfo.y; if (lastTime + notifyDelay < System.currentTimeMillis() / 1000) { dialogInfo.set(1, (int) (System.currentTimeMillis() / 1000)); } else { int count = dialogInfo.x; if (count < notifyMaxCount) { dialogInfo.set(count + 1, (int) (System.currentTimeMillis() / 1000)); } else { notifyDisabled = true; } } } } } String defaultPath = Settings.System.DEFAULT_NOTIFICATION_URI.getPath(); if (!notifyDisabled) { inAppSounds = preferences.getBoolean("EnableInAppSounds", true); inAppVibrate = preferences.getBoolean("EnableInAppVibrate", true); inAppPreview = preferences.getBoolean("EnableInAppPreview", true); inAppPriority = preferences.getBoolean("EnableInAppPriority", false); vibrateOverride = preferences.getInt("vibrate_" + dialog_id, 0); priorityOverride = preferences.getInt("priority_" + dialog_id, 3); boolean vibrateOnlyIfSilent = false; choosenSoundPath = preferences.getString("sound_path_" + dialog_id, null); if (chat_id != 0) { if (choosenSoundPath != null && choosenSoundPath.equals(defaultPath)) { choosenSoundPath = null; } else if (choosenSoundPath == null) { choosenSoundPath = preferences.getString("GroupSoundPath", defaultPath); } needVibrate = preferences.getInt("vibrate_group", 0); priority = preferences.getInt("priority_group", 1); ledColor = preferences.getInt("GroupLed", 0xff00ff00); } else if (user_id != 0) { if (choosenSoundPath != null && choosenSoundPath.equals(defaultPath)) { choosenSoundPath = null; } else if (choosenSoundPath == null) { choosenSoundPath = preferences.getString("GlobalSoundPath", defaultPath); } needVibrate = preferences.getInt("vibrate_messages", 0); priority = preferences.getInt("priority_group", 1); ledColor = preferences.getInt("MessagesLed", 0xff00ff00); } if (preferences.contains("color_" + dialog_id)) { ledColor = preferences.getInt("color_" + dialog_id, 0); } if (priorityOverride != 3) { priority = priorityOverride; } if (needVibrate == 4) { vibrateOnlyIfSilent = true; needVibrate = 0; } if (needVibrate == 2 && (vibrateOverride == 1 || vibrateOverride == 3 || vibrateOverride == 5) || needVibrate != 2 && vibrateOverride == 2 || vibrateOverride != 0) { needVibrate = vibrateOverride; } if (!ApplicationLoader.mainInterfacePaused) { if (!inAppSounds) { choosenSoundPath = null; } if (!inAppVibrate) { needVibrate = 2; } if (!inAppPriority) { priority = 0; } else if (priority == 2) { priority = 1; } } if (vibrateOnlyIfSilent && needVibrate != 2) { try { int mode = audioManager.getRingerMode(); if (mode != AudioManager.RINGER_MODE_SILENT && mode != AudioManager.RINGER_MODE_VIBRATE) { needVibrate = 2; } } catch (Exception e) { FileLog.e("tmessages", e); } } } Intent intent = new Intent(ApplicationLoader.applicationContext, LaunchActivity.class); intent.setAction("com.tmessages.openchat" + Math.random() + Integer.MAX_VALUE); intent.setFlags(32768); if ((int) dialog_id != 0) { if (pushDialogs.size() == 1) { if (chat_id != 0) { intent.putExtra("chatId", chat_id); } else if (user_id != 0) { intent.putExtra("userId", user_id); } } if (AndroidUtilities.needShowPasscode(false) || UserConfig.isWaitingForPasscodeEnter) { photoPath = null; } else { if (pushDialogs.size() == 1) { if (chat != null) { if (chat.photo != null && chat.photo.photo_small != null && chat.photo.photo_small.volume_id != 0 && chat.photo.photo_small.local_id != 0) { photoPath = chat.photo.photo_small; } } else if (user != null) { if (user.photo != null && user.photo.photo_small != null && user.photo.photo_small.volume_id != 0 && user.photo.photo_small.local_id != 0) { photoPath = user.photo.photo_small; } } } } } else { if (pushDialogs.size() == 1) { intent.putExtra("encId", (int) (dialog_id >> 32)); } } PendingIntent contentIntent = PendingIntent.getActivity(ApplicationLoader.applicationContext, 0, intent, PendingIntent.FLAG_ONE_SHOT); String name; boolean replace = true; if ((int) dialog_id == 0 || pushDialogs.size() > 1 || AndroidUtilities.needShowPasscode(false) || UserConfig.isWaitingForPasscodeEnter) { name = LocaleController.getString("AppName", R.string.AppName); replace = false; } else { if (chat != null) { name = chat.title; } else { name = UserObject.getUserName(user); } } String detailText; if (pushDialogs.size() == 1) { detailText = LocaleController.formatPluralString("NewMessages", total_unread_count); } else { detailText = LocaleController.formatString("NotificationMessagesPeopleDisplayOrder", R.string.NotificationMessagesPeopleDisplayOrder, LocaleController.formatPluralString("NewMessages", total_unread_count), LocaleController.formatPluralString("FromChats", pushDialogs.size())); } NotificationCompat.Builder mBuilder = new NotificationCompat.Builder( ApplicationLoader.applicationContext).setContentTitle(name) .setSmallIcon(R.drawable.notification).setAutoCancel(true).setNumber(total_unread_count) .setContentIntent(contentIntent).setGroup("messages").setGroupSummary(true) .setColor(0xff2ca5e0); if (!notifyAboutLast) { mBuilder.setPriority(NotificationCompat.PRIORITY_LOW); } else { if (priority == 0) { mBuilder.setPriority(NotificationCompat.PRIORITY_DEFAULT); } else if (priority == 1) { mBuilder.setPriority(NotificationCompat.PRIORITY_HIGH); } else if (priority == 2) { mBuilder.setPriority(NotificationCompat.PRIORITY_MAX); } } mBuilder.setCategory(NotificationCompat.CATEGORY_MESSAGE); if (chat == null && user != null && user.phone != null && user.phone.length() > 0) { mBuilder.addPerson("tel:+" + user.phone); } String lastMessage = null; if (pushMessages.size() == 1) { String message = lastMessage = getStringForMessage(pushMessages.get(0), false); if (message == null) { return; } if (replace) { if (chat != null) { message = message.replace(" @ " + name, ""); } else { message = message.replace(name + ": ", "").replace(name + " ", ""); } } mBuilder.setContentText(message); mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(message)); } else { mBuilder.setContentText(detailText); NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle(); inboxStyle.setBigContentTitle(name); int count = Math.min(10, pushMessages.size()); for (int i = 0; i < count; i++) { String message = getStringForMessage(pushMessages.get(i), false); if (message == null) { continue; } if (i == 0) { lastMessage = message; } if (pushDialogs.size() == 1) { if (replace) { if (chat != null) { message = message.replace(" @ " + name, ""); } else { message = message.replace(name + ": ", "").replace(name + " ", ""); } } } inboxStyle.addLine(message); } inboxStyle.setSummaryText(detailText); mBuilder.setStyle(inboxStyle); } if (photoPath != null) { BitmapDrawable img = ImageLoader.getInstance().getImageFromMemory(photoPath, null, "50_50"); if (img != null) { mBuilder.setLargeIcon(img.getBitmap()); } } if (!notifyDisabled) { if (ApplicationLoader.mainInterfacePaused || inAppPreview) { if (lastMessage.length() > 100) { lastMessage = lastMessage.substring(0, 100).replace("\n", " ").trim() + "..."; } mBuilder.setTicker(lastMessage); } if (choosenSoundPath != null && !choosenSoundPath.equals("NoSound")) { if (choosenSoundPath.equals(defaultPath)) { /*MediaPlayer mediaPlayer = new MediaPlayer(); mediaPlayer.setAudioStreamType(AudioManager.STREAM_ALARM); mediaPlayer.setDataSource(ApplicationLoader.applicationContext, Settings.System.DEFAULT_NOTIFICATION_URI); mediaPlayer.prepare(); mediaPlayer.start();*/ mBuilder.setSound(Settings.System.DEFAULT_NOTIFICATION_URI, AudioManager.STREAM_NOTIFICATION); } else { mBuilder.setSound(Uri.parse(choosenSoundPath), AudioManager.STREAM_NOTIFICATION); } } if (ledColor != 0) { mBuilder.setLights(ledColor, 1000, 1000); } if (needVibrate == 2) { mBuilder.setVibrate(new long[] { 0, 0 }); } else if (needVibrate == 1) { mBuilder.setVibrate(new long[] { 0, 100, 0, 100 }); } else if (needVibrate == 0 || needVibrate == 4) { mBuilder.setDefaults(NotificationCompat.DEFAULT_VIBRATE); } else if (needVibrate == 3) { mBuilder.setVibrate(new long[] { 0, 1000 }); } } else { mBuilder.setVibrate(new long[] { 0, 0 }); } showExtraNotifications(mBuilder, notifyAboutLast); notificationManager.notify(1, mBuilder.build()); scheduleNotificationRepeat(); } catch (Exception e) { FileLog.e("tmessages", e); } }