@Override protected void onDestroy() { super.onDestroy(); if (soundPool != null) soundPool.release(); if (ringtone != null && ringtone.isPlaying()) ringtone.stop(); audioManager.setMode(AudioManager.MODE_NORMAL); audioManager.setMicrophoneMute(false); if (callStateListener != null) EMChatManager.getInstance().removeCallStateChangeListener(callStateListener); }
/** * @return true if the ringtone is playing * @see isVibrating * @see isRinging */ private boolean isRingtonePlaying() { synchronized (this) { return (mRingtone != null && mRingtone.isPlaying()) || (mRingHandler != null && mRingHandler.hasMessages(PLAY_RING_ONCE)); } }
/** 手机震动和声音提示 */ public void viberateAndPlayTone(EMMessage message) { if (message != null) { if (EMChatManager.getInstance().isSlientMessage(message)) { return; } } com.easemob.applib.model.HXSDKModel model = HXSDKHelper.getInstance().getModel(); if (!model.getSettingMsgNotification()) { return; } if (System.currentTimeMillis() - lastNotifiyTime < 1000) { // received new messages within 2 seconds, skip play ringtone return; } try { lastNotifiyTime = System.currentTimeMillis(); // 判断是否处于静音模式 if (audioManager.getRingerMode() == AudioManager.RINGER_MODE_SILENT) { EMLog.e(TAG, "in slient mode now"); return; } if (model.getSettingMsgVibrate()) { long[] pattern = new long[] {0, 180, 80, 120}; vibrator.vibrate(pattern, -1); } if (model.getSettingMsgSound()) { if (ringtone == null) { Uri notificationUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); ringtone = RingtoneManager.getRingtone(appContext, notificationUri); if (ringtone == null) { EMLog.d(TAG, "cant find ringtone at:" + notificationUri.getPath()); return; } } if (!ringtone.isPlaying()) { String vendor = Build.MANUFACTURER; ringtone.play(); // for samsung S3, we meet a bug that the phone will // continue ringtone without stop // so add below special handler to stop it after 3s if // needed if (vendor != null && vendor.toLowerCase().contains("samsung")) { Thread ctlThread = new Thread() { public void run() { try { Thread.sleep(3000); if (ringtone.isPlaying()) { ringtone.stop(); } } catch (Exception e) { } } }; ctlThread.run(); } } } } catch (Exception e) { e.printStackTrace(); } }
protected final void notifyClient$1c42781f( String fromJid, String fromUserName, String message, boolean showNotification, boolean silent_notification) { Object obj; UserProvider userProvider; String str; String threadId = Utils.getUserIdFromXmppUserId(this.mConfig.jabberID) + "-" + Utils.getUserIdFromXmppUserId(fromJid); if (currentOpenedThreadId == null || !currentOpenedThreadId.equalsIgnoreCase(threadId)) { if (fromJid.equals("rabtcdn.com")) { Context context = SHAMChatApplication.getMyApplicationContext(); Intent intent = new Intent(context, BroadcastMessageActivity.class); intent.putExtra("Message", message); intent.setFlags(ClientDefaults.MAX_MSG_SIZE); context.startActivity(intent); } else if (showNotification) { int intValue; Notification notification; int notifyId; this.mWakeLock.acquire(); if (silent_notification && !this.notificationCount.containsKey(fromJid)) { silent_notification = false; } if (this.notificationCount.containsKey(fromJid)) { intValue = ((Integer) this.notificationCount.get(fromJid)).intValue(); } else { intValue = 0; } try { ((NotificationManager) getSystemService("notification")).cancelAll(); } catch (Exception e) { } String userIdFromXmppUserId = Utils.getUserIdFromXmppUserId(fromJid); String str2 = Utils.getUserIdFromXmppUserId(this.mConfig.jabberID) + "-" + userIdFromXmppUserId; if (currentOpenedThreadId == null || !currentOpenedThreadId.equalsIgnoreCase(str2)) { CharSequence charSequence; Object obj2; Cursor query; CharSequence charSequence2; PendingIntent activity; if (message.contains("http://")) { message = "New Media file"; } int i = intValue + 1; this.notificationCount.put(fromJid, Integer.valueOf(i)); if (fromUserName == null || fromUserName.length() == 0) { charSequence = "New message"; obj2 = null; } else { if (fromUserName.contains("_")) { int i2; String str3 = "New message "; query = getContentResolver() .query( UserProvider.CONTENT_URI_GROUP, new String[] {FriendGroup.DB_NAME}, FriendGroup.CHAT_ROOM_NAME + "=?", new String[] {fromJid}, null); if (query.getCount() > 0) { query.moveToFirst(); String string = query.getString(query.getColumnIndex(FriendGroup.DB_NAME)); if (!(string == null || string.isEmpty())) { charSequence = str3 + "from " + string; i2 = 1; } } obj = str3; i2 = 1; } else { try { Cursor query2 = getContentResolver() .query( Uri.parse( UserProvider.CONTENT_URI_USER.toString() + MqttTopic.TOPIC_LEVEL_SEPARATOR + Utils.getUserIdFromXmppUserId(fromJid)), null, null, null, null); query2.moveToFirst(); charSequence = query2.getString(query2.getColumnIndex("mobileNo")); if (charSequence != null) { ContactDetails conactExists = Utils.getConactExists(getApplicationContext(), charSequence); if (conactExists.isExist) { charSequence = conactExists.displayName; obj2 = null; } else { obj2 = null; } } else { try { charSequence = query2.getString(query2.getColumnIndex("name")); obj2 = null; } catch (Exception e2) { userProvider = new UserProvider(); str = UserProvider.getUserDetailsFromServer( Utils.getUserIdFromXmppUserId(fromJid)) .username; e2.printStackTrace(); obj = str; obj2 = null; } } } catch (Exception e22) { userProvider = new UserProvider(); str = UserProvider.getUserDetailsFromServer(Utils.getUserIdFromXmppUserId(fromJid)) .username; e22.printStackTrace(); obj = str; obj2 = null; } } } if (obj2 == null) { charSequence = getString(2131493237, new Object[] {charSequence}); } if (this.mConfig.ticker) { intValue = message.indexOf(10); if (intValue < 0) { intValue = 0; } if (intValue > 45 || message.length() > 45) { intValue = 45; } if (intValue > 0) { str = message.substring(0, intValue) + " [...]"; } else { str = message; } charSequence2 = charSequence + ":\n" + str; } else { charSequence2 = getString(2131493235); } SharedPreferences sharedPreferences = getApplicationContext().getSharedPreferences("setting", 0); sp = sharedPreferences; switch (sharedPreferences.getInt("notif_icon", 1)) { case Logger.SEVERE /*1*/: this.mNotification = new Notification(2130837905, charSequence2, System.currentTimeMillis()); break; case Logger.WARNING /*2*/: this.mNotification = new Notification(2130837906, charSequence2, System.currentTimeMillis()); break; case Logger.INFO /*3*/: this.mNotification = new Notification(2130837907, charSequence2, System.currentTimeMillis()); break; case Logger.CONFIG /*4*/: this.mNotification = new Notification(2130837908, charSequence2, System.currentTimeMillis()); break; case Logger.FINE /*5*/: this.mNotification = new Notification(2130837909, charSequence2, System.currentTimeMillis()); break; case Logger.FINER /*6*/: this.mNotification = new Notification(2130837910, charSequence2, System.currentTimeMillis()); break; case Logger.FINEST /*7*/: this.mNotification = new Notification(2130837911, charSequence2, System.currentTimeMillis()); break; case C0473R.styleable.SwitchButton_thumb_width /*8*/: this.mNotification = new Notification(2130837912, charSequence2, System.currentTimeMillis()); break; case C0473R.styleable.SwitchButton_thumb_height /*9*/: this.mNotification = new Notification(2130837913, charSequence2, System.currentTimeMillis()); break; default: this.mNotification = new Notification(2130837905, charSequence2, System.currentTimeMillis()); break; } this.mNotification.defaults = 0; Uri parse = Uri.parse(fromJid); this.mNotificationIntent.setData(parse); this.mNotificationGroupIntent.setData(parse); if (obj2 == null) { this.mNotificationIntent.putExtra( ChatActivity.INTENT_EXTRA_USER_ID, userIdFromXmppUserId); this.mNotificationIntent.putExtra( ChatInitialForGroupChatActivity.INTENT_EXTRA_THREAD_ID, str2); this.mNotificationIntent.setFlags(536870912); activity = PendingIntent.getActivity(this, 0, this.mNotificationIntent, 134217728); } else { this.mNotificationGroupIntent.putExtra( ChatInitialForGroupChatActivity.INTENT_EXTRA_GROUP_ID, userIdFromXmppUserId); this.mNotificationGroupIntent.putExtra( ChatInitialForGroupChatActivity.INTENT_EXTRA_THREAD_ID, str2); this.mNotificationGroupIntent.setFlags(536870912); activity = PendingIntent.getActivity(this, 0, this.mNotificationGroupIntent, 134217728); } long currentTimeMillis = System.currentTimeMillis(); Intent intent2 = new Intent(this, MainWindow.class); intent2.setFlags(67108864); PendingIntent.getActivity(this, 0, intent2, 134217728); Builder builder = new Builder(this); builder .setAutoCancel(true) .setContentTitle(charSequence) .setContentIntent(activity) .setContentText(message) .setTicker(charSequence2) .setWhen(currentTimeMillis) .setSmallIcon(2130837905); Notification build = builder.build(); build.flags = 8; ((NotificationManager) getSystemService("notification")).notify(1, build); if (i > 1) { this.mNotification.number = i; } this.mNotification.flags = 16; query = getContentResolver() .query( UserProvider.CONTENT_URI_NOTIFICATION, null, "user_id=?", new String[] {this.mConfig.userId}, null); query.moveToFirst(); UserProvider.userNotificationFromCursor(query); SharedPreferences defaultSharedPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); Editor edit = defaultSharedPreferences.edit(); try { Uri parse2; int i3 = sp.getInt("sound", 1); Log.i("Notify", "Sound " + i3); switch (i3) { case Logger.SEVERE /*1*/: parse2 = Uri.parse( "android.resource://" + SHAMChatApplication.getMyApplicationContext().getPackageName() + "/2131034112"); break; case Logger.WARNING /*2*/: parse2 = Uri.parse( "android.resource://" + SHAMChatApplication.getMyApplicationContext().getPackageName() + "/2131034113"); break; case Logger.INFO /*3*/: parse2 = Uri.parse( "android.resource://" + SHAMChatApplication.getMyApplicationContext().getPackageName() + "/2131034114"); break; case Logger.CONFIG /*4*/: parse2 = Uri.parse( "android.resource://" + SHAMChatApplication.getMyApplicationContext().getPackageName() + "/2131034116"); break; case Logger.FINE /*5*/: parse2 = Uri.parse( "android.resource://" + SHAMChatApplication.getMyApplicationContext().getPackageName() + "/2131034118"); break; default: parse2 = Uri.parse( "android.resource://" + SHAMChatApplication.getMyApplicationContext().getPackageName() + "/2131034112"); break; } Ringtone ringtone = RingtoneManager.getRingtone(getApplicationContext(), parse2); if (System.currentTimeMillis() - Long.valueOf(defaultSharedPreferences.getLong("Notification", 3100)) .longValue() > 2000 && !ringtone.isPlaying()) { ringtone.play(); edit.putLong("Notification", System.currentTimeMillis()); edit.commit(); } } catch (Exception e3) { } } if (this.mConfig.isLEDNotify) { this.mNotification.ledARGB = -65281; this.mNotification.ledOnMS = 300; this.mNotification.ledOffMS = 1000; notification = this.mNotification; notification.flags |= 1; } if (!silent_notification) { this.mNotification.sound = this.mConfig.notifySound; } if (this.notificationId.containsKey(fromJid)) { notifyId = ((Integer) this.notificationId.get(fromJid)).intValue(); } else { this.lastNotificationId++; notifyId = this.lastNotificationId; this.notificationId.put(fromJid, Integer.valueOf(notifyId)); } if (!silent_notification && "SYSTEM".equals(this.mConfig.vibraNotify)) { notification = this.mNotification; notification.defaults |= 2; } SharedPreferences sharedPreferences2 = SHAMChatApplication.getMyApplicationContext().getSharedPreferences("setting", 0); sp = sharedPreferences2; int shakes = sharedPreferences2.getInt("shakee", 1); Log.i("Notify", "Vibrate " + shakes); if (shakes != 0) { this.mNotificationMGR.notify(notifyId, this.mNotification); this.mVibrator.vibrate(400); } this.mWakeLock.release(); } else if (!silent_notification) { try { if (!Uri.EMPTY.equals(this.mConfig.notifySound)) { RingtoneManager.getRingtone(getApplicationContext(), this.mConfig.notifySound).play(); } } catch (NullPointerException e4) { } } } }
private boolean isSamplePlaying() { return mRingtone != null && mRingtone.isPlaying(); }