List of usage examples for java.util HashMap remove
public V remove(Object key)
From source file:ir.besteveryeverapp.telegram.NotificationsController.java
@SuppressLint("InlinedApi") private void showExtraNotifications(NotificationCompat.Builder notificationBuilder, boolean notifyAboutLast) { if (Build.VERSION.SDK_INT < 18) { return;/* w w w . j a v a 2s . co m*/ } ArrayList<Long> sortedDialogs = new ArrayList<>(); HashMap<Long, ArrayList<MessageObject>> messagesByDialogs = new HashMap<>(); for (int a = 0; a < pushMessages.size(); a++) { MessageObject messageObject = pushMessages.get(a); long dialog_id = messageObject.getDialogId(); if ((int) dialog_id == 0) { continue; } ArrayList<MessageObject> arrayList = messagesByDialogs.get(dialog_id); if (arrayList == null) { arrayList = new ArrayList<>(); messagesByDialogs.put(dialog_id, arrayList); sortedDialogs.add(0, dialog_id); } arrayList.add(messageObject); } HashMap<Long, Integer> oldIdsWear = new HashMap<>(); oldIdsWear.putAll(wearNotificationsIds); wearNotificationsIds.clear(); HashMap<Long, Integer> oldIdsAuto = new HashMap<>(); oldIdsAuto.putAll(autoNotificationsIds); autoNotificationsIds.clear(); for (int b = 0; b < sortedDialogs.size(); b++) { long dialog_id = sortedDialogs.get(b); ArrayList<MessageObject> messageObjects = messagesByDialogs.get(dialog_id); int max_id = messageObjects.get(0).getId(); int max_date = messageObjects.get(0).messageOwner.date; TLRPC.Chat chat = null; TLRPC.User user = null; String name; if (dialog_id > 0) { user = MessagesController.getInstance().getUser((int) dialog_id); if (user == null) { continue; } } else { chat = MessagesController.getInstance().getChat(-(int) dialog_id); if (chat == null) { continue; } } TLRPC.FileLocation photoPath = null; if (AndroidUtilities.needShowPasscode(false) || UserConfig.isWaitingForPasscodeEnter) { name = LocaleController.getString("AppName", R.string.AppName); } else { if (chat != null) { name = chat.title; } else { name = UserObject.getUserName(user); } 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; } } } Integer notificationIdWear = oldIdsWear.get(dialog_id); if (notificationIdWear == null) { notificationIdWear = wearNotificationId++; } else { oldIdsWear.remove(dialog_id); } Integer notificationIdAuto = oldIdsAuto.get(dialog_id); if (notificationIdAuto == null) { notificationIdAuto = autoNotificationId++; } else { oldIdsAuto.remove(dialog_id); } NotificationCompat.CarExtender.UnreadConversation.Builder unreadConvBuilder = new NotificationCompat.CarExtender.UnreadConversation.Builder( name).setLatestTimestamp((long) max_date * 1000); Intent msgHeardIntent = new Intent(); msgHeardIntent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); msgHeardIntent.setAction("ir.besteveryeverapp.telegram.ACTION_MESSAGE_HEARD"); msgHeardIntent.putExtra("dialog_id", dialog_id); msgHeardIntent.putExtra("max_id", max_id); PendingIntent msgHeardPendingIntent = PendingIntent.getBroadcast(ApplicationLoader.applicationContext, notificationIdAuto, msgHeardIntent, PendingIntent.FLAG_UPDATE_CURRENT); unreadConvBuilder.setReadPendingIntent(msgHeardPendingIntent); NotificationCompat.Action wearReplyAction = null; if (!ChatObject.isChannel(chat) && !AndroidUtilities.needShowPasscode(false) && !UserConfig.isWaitingForPasscodeEnter) { Intent msgReplyIntent = new Intent(); msgReplyIntent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); msgReplyIntent.setAction("ir.besteveryeverapp.telegram.ACTION_MESSAGE_REPLY"); msgReplyIntent.putExtra("dialog_id", dialog_id); msgReplyIntent.putExtra("max_id", max_id); PendingIntent msgReplyPendingIntent = PendingIntent.getBroadcast( ApplicationLoader.applicationContext, notificationIdAuto, msgReplyIntent, PendingIntent.FLAG_UPDATE_CURRENT); RemoteInput remoteInputAuto = new RemoteInput.Builder(NotificationsController.EXTRA_VOICE_REPLY) .setLabel(LocaleController.getString("Reply", R.string.Reply)).build(); unreadConvBuilder.setReplyAction(msgReplyPendingIntent, remoteInputAuto); Intent replyIntent = new Intent(ApplicationLoader.applicationContext, WearReplyReceiver.class); replyIntent.putExtra("dialog_id", dialog_id); replyIntent.putExtra("max_id", max_id); PendingIntent replyPendingIntent = PendingIntent.getBroadcast(ApplicationLoader.applicationContext, notificationIdWear, replyIntent, PendingIntent.FLAG_UPDATE_CURRENT); RemoteInput remoteInputWear = new RemoteInput.Builder(EXTRA_VOICE_REPLY) .setLabel(LocaleController.getString("Reply", R.string.Reply)).build(); String replyToString; if (chat != null) { replyToString = LocaleController.formatString("ReplyToGroup", R.string.ReplyToGroup, name); } else { replyToString = LocaleController.formatString("ReplyToUser", R.string.ReplyToUser, name); } wearReplyAction = new NotificationCompat.Action.Builder(R.drawable.ic_reply_icon, replyToString, replyPendingIntent).addRemoteInput(remoteInputWear).build(); } String text = ""; for (int a = messageObjects.size() - 1; a >= 0; a--) { MessageObject messageObject = messageObjects.get(a); String message = getStringForMessage(messageObject, false); if (message == null) { continue; } if (chat != null) { message = message.replace(" @ " + name, ""); } else { message = message.replace(name + ": ", "").replace(name + " ", ""); } if (text.length() > 0) { text += "\n\n"; } text += message; unreadConvBuilder.addMessage(message); } Intent intent = new Intent(ApplicationLoader.applicationContext, LaunchActivity.class); intent.setAction("com.tmessages.openchat" + Math.random() + Integer.MAX_VALUE); intent.setFlags(32768); if (chat != null) { intent.putExtra("chatId", chat.id); } else if (user != null) { intent.putExtra("userId", user.id); } PendingIntent contentIntent = PendingIntent.getActivity(ApplicationLoader.applicationContext, 0, intent, PendingIntent.FLAG_ONE_SHOT); NotificationCompat.WearableExtender wearableExtender = new NotificationCompat.WearableExtender(); if (wearReplyAction != null) { wearableExtender.addAction(wearReplyAction); } NotificationCompat.Builder builder = new NotificationCompat.Builder( ApplicationLoader.applicationContext).setContentTitle(name) .setSmallIcon(R.drawable.notification).setGroup("messages").setContentText(text) .setAutoCancel(true).setColor(0xff2ca5e0).setGroupSummary(false) .setContentIntent(contentIntent).extend(wearableExtender) .extend(new NotificationCompat.CarExtender() .setUnreadConversation(unreadConvBuilder.build())) .setCategory(NotificationCompat.CATEGORY_MESSAGE); if (photoPath != null) { BitmapDrawable img = ImageLoader.getInstance().getImageFromMemory(photoPath, null, "50_50"); if (img != null) { builder.setLargeIcon(img.getBitmap()); } } if (chat == null && user != null && user.phone != null && user.phone.length() > 0) { builder.addPerson("tel:+" + user.phone); } notificationManager.notify(notificationIdWear, builder.build()); wearNotificationsIds.put(dialog_id, notificationIdWear); } for (HashMap.Entry<Long, Integer> entry : oldIdsWear.entrySet()) { notificationManager.cancel(entry.getValue()); } }
From source file:org.giffftalk.messenger.NotificationsController.java
@SuppressLint("InlinedApi") private void showExtraNotifications(NotificationCompat.Builder notificationBuilder, boolean notifyAboutLast) { if (Build.VERSION.SDK_INT < 18) { return;// ww w. j a va2s . c o m } ArrayList<Long> sortedDialogs = new ArrayList<>(); HashMap<Long, ArrayList<MessageObject>> messagesByDialogs = new HashMap<>(); for (int a = 0; a < pushMessages.size(); a++) { MessageObject messageObject = pushMessages.get(a); long dialog_id = messageObject.getDialogId(); if ((int) dialog_id == 0) { continue; } ArrayList<MessageObject> arrayList = messagesByDialogs.get(dialog_id); if (arrayList == null) { arrayList = new ArrayList<>(); messagesByDialogs.put(dialog_id, arrayList); sortedDialogs.add(0, dialog_id); } arrayList.add(messageObject); } HashMap<Long, Integer> oldIdsWear = new HashMap<>(); oldIdsWear.putAll(wearNotificationsIds); wearNotificationsIds.clear(); HashMap<Long, Integer> oldIdsAuto = new HashMap<>(); oldIdsAuto.putAll(autoNotificationsIds); autoNotificationsIds.clear(); for (int b = 0; b < sortedDialogs.size(); b++) { long dialog_id = sortedDialogs.get(b); ArrayList<MessageObject> messageObjects = messagesByDialogs.get(dialog_id); int max_id = messageObjects.get(0).getId(); int max_date = messageObjects.get(0).messageOwner.date; TLRPC.Chat chat = null; TLRPC.User user = null; String name; if (dialog_id > 0) { user = MessagesController.getInstance().getUser((int) dialog_id); if (user == null) { continue; } } else { chat = MessagesController.getInstance().getChat(-(int) dialog_id); if (chat == null) { continue; } } TLRPC.FileLocation photoPath = null; if (AndroidUtilities.needShowPasscode(false) || UserConfig.isWaitingForPasscodeEnter) { name = LocaleController.getString("AppName", R.string.AppName); } else { if (chat != null) { name = chat.title; } else { name = UserObject.getUserName(user); } 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; } } } Integer notificationIdWear = oldIdsWear.get(dialog_id); if (notificationIdWear == null) { notificationIdWear = wearNotificationId++; } else { oldIdsWear.remove(dialog_id); } Integer notificationIdAuto = oldIdsAuto.get(dialog_id); if (notificationIdAuto == null) { notificationIdAuto = autoNotificationId++; } else { oldIdsAuto.remove(dialog_id); } NotificationCompat.CarExtender.UnreadConversation.Builder unreadConvBuilder = new NotificationCompat.CarExtender.UnreadConversation.Builder( name).setLatestTimestamp((long) max_date * 1000); Intent msgHeardIntent = new Intent(); msgHeardIntent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); msgHeardIntent.setAction("org.giffftalk.messenger.ACTION_MESSAGE_HEARD"); msgHeardIntent.putExtra("dialog_id", dialog_id); msgHeardIntent.putExtra("max_id", max_id); PendingIntent msgHeardPendingIntent = PendingIntent.getBroadcast(ApplicationLoader.applicationContext, notificationIdAuto, msgHeardIntent, PendingIntent.FLAG_UPDATE_CURRENT); unreadConvBuilder.setReadPendingIntent(msgHeardPendingIntent); NotificationCompat.Action wearReplyAction = null; if (!ChatObject.isChannel(chat) && !AndroidUtilities.needShowPasscode(false) && !UserConfig.isWaitingForPasscodeEnter) { Intent msgReplyIntent = new Intent(); msgReplyIntent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); msgReplyIntent.setAction("org.giffftalk.messenger.ACTION_MESSAGE_REPLY"); msgReplyIntent.putExtra("dialog_id", dialog_id); msgReplyIntent.putExtra("max_id", max_id); PendingIntent msgReplyPendingIntent = PendingIntent.getBroadcast( ApplicationLoader.applicationContext, notificationIdAuto, msgReplyIntent, PendingIntent.FLAG_UPDATE_CURRENT); RemoteInput remoteInputAuto = new RemoteInput.Builder(NotificationsController.EXTRA_VOICE_REPLY) .setLabel(LocaleController.getString("Reply", R.string.Reply)).build(); unreadConvBuilder.setReplyAction(msgReplyPendingIntent, remoteInputAuto); Intent replyIntent = new Intent(ApplicationLoader.applicationContext, WearReplyReceiver.class); replyIntent.putExtra("dialog_id", dialog_id); replyIntent.putExtra("max_id", max_id); PendingIntent replyPendingIntent = PendingIntent.getBroadcast(ApplicationLoader.applicationContext, notificationIdWear, replyIntent, PendingIntent.FLAG_UPDATE_CURRENT); RemoteInput remoteInputWear = new RemoteInput.Builder(EXTRA_VOICE_REPLY) .setLabel(LocaleController.getString("Reply", R.string.Reply)).build(); String replyToString; if (chat != null) { replyToString = LocaleController.formatString("ReplyToGroup", R.string.ReplyToGroup, name); } else { replyToString = LocaleController.formatString("ReplyToUser", R.string.ReplyToUser, name); } wearReplyAction = new NotificationCompat.Action.Builder(R.drawable.ic_reply_icon, replyToString, replyPendingIntent).addRemoteInput(remoteInputWear).build(); } String text = ""; for (int a = messageObjects.size() - 1; a >= 0; a--) { MessageObject messageObject = messageObjects.get(a); String message = getStringForMessage(messageObject, false); if (message == null) { continue; } if (chat != null) { message = message.replace(" @ " + name, ""); } else { message = message.replace(name + ": ", "").replace(name + " ", ""); } if (text.length() > 0) { text += "\n\n"; } text += message; unreadConvBuilder.addMessage(message); } Intent intent = new Intent(ApplicationLoader.applicationContext, LaunchActivity.class); intent.setAction("com.tmessages.openchat" + Math.random() + Integer.MAX_VALUE); intent.setFlags(32768); if (chat != null) { intent.putExtra("chatId", chat.id); } else if (user != null) { intent.putExtra("userId", user.id); } PendingIntent contentIntent = PendingIntent.getActivity(ApplicationLoader.applicationContext, 0, intent, PendingIntent.FLAG_ONE_SHOT); NotificationCompat.WearableExtender wearableExtender = new NotificationCompat.WearableExtender(); if (wearReplyAction != null) { wearableExtender.addAction(wearReplyAction); } NotificationCompat.Builder builder = new NotificationCompat.Builder( ApplicationLoader.applicationContext).setContentTitle(name) .setSmallIcon(R.drawable.notification).setGroup("messages").setContentText(text) .setAutoCancel(true) // Customized by Digant // .setColor(0xff2ca5e0) .setColor(Theme.PRIMARY_COLOR).setGroupSummary(false).setContentIntent(contentIntent) .extend(wearableExtender) .extend(new NotificationCompat.CarExtender() .setUnreadConversation(unreadConvBuilder.build())) .setCategory(NotificationCompat.CATEGORY_MESSAGE); if (photoPath != null) { BitmapDrawable img = ImageLoader.getInstance().getImageFromMemory(photoPath, null, "50_50"); if (img != null) { builder.setLargeIcon(img.getBitmap()); } } if (chat == null && user != null && user.phone != null && user.phone.length() > 0) { builder.addPerson("tel:+" + user.phone); } notificationManager.notify(notificationIdWear, builder.build()); wearNotificationsIds.put(dialog_id, notificationIdWear); } for (HashMap.Entry<Long, Integer> entry : oldIdsWear.entrySet()) { notificationManager.cancel(entry.getValue()); } }
From source file:ir.irani.telecam.messenger.NotificationsController.java
@SuppressLint("InlinedApi") private void showExtraNotifications(NotificationCompat.Builder notificationBuilder, boolean notifyAboutLast) { if (Build.VERSION.SDK_INT < 18) { return;// ww w. j a v a2 s .c om } ArrayList<Long> sortedDialogs = new ArrayList<>(); HashMap<Long, ArrayList<MessageObject>> messagesByDialogs = new HashMap<>(); for (int a = 0; a < pushMessages.size(); a++) { MessageObject messageObject = pushMessages.get(a); long dialog_id = messageObject.getDialogId(); if ((int) dialog_id == 0) { continue; } ArrayList<MessageObject> arrayList = messagesByDialogs.get(dialog_id); if (arrayList == null) { arrayList = new ArrayList<>(); messagesByDialogs.put(dialog_id, arrayList); sortedDialogs.add(0, dialog_id); } arrayList.add(messageObject); } HashMap<Long, Integer> oldIdsWear = new HashMap<>(); oldIdsWear.putAll(wearNotificationsIds); wearNotificationsIds.clear(); HashMap<Long, Integer> oldIdsAuto = new HashMap<>(); oldIdsAuto.putAll(autoNotificationsIds); autoNotificationsIds.clear(); for (int b = 0; b < sortedDialogs.size(); b++) { long dialog_id = sortedDialogs.get(b); ArrayList<MessageObject> messageObjects = messagesByDialogs.get(dialog_id); int max_id = messageObjects.get(0).getId(); int max_date = messageObjects.get(0).messageOwner.date; TLRPC.Chat chat = null; TLRPC.User user = null; String name; if (dialog_id > 0) { user = MessagesController.getInstance().getUser((int) dialog_id); if (user == null) { continue; } } else { chat = MessagesController.getInstance().getChat(-(int) dialog_id); if (chat == null) { continue; } } TLRPC.FileLocation photoPath = null; if (AndroidUtilities.needShowPasscode(false) || UserConfig.isWaitingForPasscodeEnter || HiddenController.IsHidden(dialog_id)) { name = LocaleController.getString("AppName", R.string.AppName); } else { if (chat != null) { name = chat.title; } else { name = UserObject.getUserName(user); } 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; } } } Integer notificationIdWear = oldIdsWear.get(dialog_id); if (notificationIdWear == null) { notificationIdWear = wearNotificationId++; } else { oldIdsWear.remove(dialog_id); } Integer notificationIdAuto = oldIdsAuto.get(dialog_id); if (notificationIdAuto == null) { notificationIdAuto = autoNotificationId++; } else { oldIdsAuto.remove(dialog_id); } NotificationCompat.CarExtender.UnreadConversation.Builder unreadConvBuilder = new NotificationCompat.CarExtender.UnreadConversation.Builder( name).setLatestTimestamp((long) max_date * 1000); Intent msgHeardIntent = new Intent(); msgHeardIntent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); msgHeardIntent.setAction("org.telegram.messenger.ACTION_MESSAGE_HEARD"); msgHeardIntent.putExtra("dialog_id", dialog_id); msgHeardIntent.putExtra("max_id", max_id); PendingIntent msgHeardPendingIntent = PendingIntent.getBroadcast(ApplicationLoader.applicationContext, notificationIdAuto, msgHeardIntent, PendingIntent.FLAG_UPDATE_CURRENT); unreadConvBuilder.setReadPendingIntent(msgHeardPendingIntent); NotificationCompat.Action wearReplyAction = null; if (!ChatObject.isChannel(chat) && !AndroidUtilities.needShowPasscode(false) && !UserConfig.isWaitingForPasscodeEnter && !HiddenController.IsHidden(dialog_id)) { Intent msgReplyIntent = new Intent(); msgReplyIntent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); msgReplyIntent.setAction("ir.irani.telecam.messenger.ACTION_MESSAGE_REPLY"); msgReplyIntent.putExtra("dialog_id", dialog_id); msgReplyIntent.putExtra("max_id", max_id); PendingIntent msgReplyPendingIntent = PendingIntent.getBroadcast( ApplicationLoader.applicationContext, notificationIdAuto, msgReplyIntent, PendingIntent.FLAG_UPDATE_CURRENT); RemoteInput remoteInputAuto = new RemoteInput.Builder(NotificationsController.EXTRA_VOICE_REPLY) .setLabel(LocaleController.getString("Reply", R.string.Reply)).build(); unreadConvBuilder.setReplyAction(msgReplyPendingIntent, remoteInputAuto); Intent replyIntent = new Intent(ApplicationLoader.applicationContext, WearReplyReceiver.class); replyIntent.putExtra("dialog_id", dialog_id); replyIntent.putExtra("max_id", max_id); PendingIntent replyPendingIntent = PendingIntent.getBroadcast(ApplicationLoader.applicationContext, notificationIdWear, replyIntent, PendingIntent.FLAG_UPDATE_CURRENT); RemoteInput remoteInputWear = new RemoteInput.Builder(EXTRA_VOICE_REPLY) .setLabel(LocaleController.getString("Reply", R.string.Reply)).build(); String replyToString; if (chat != null) { replyToString = LocaleController.formatString("ReplyToGroup", R.string.ReplyToGroup, name); } else { replyToString = LocaleController.formatString("ReplyToUser", R.string.ReplyToUser, name); } wearReplyAction = new NotificationCompat.Action.Builder(R.drawable.ic_reply_icon, replyToString, replyPendingIntent).addRemoteInput(remoteInputWear).build(); } String text = ""; for (int a = messageObjects.size() - 1; a >= 0; a--) { MessageObject messageObject = messageObjects.get(a); String message = getStringForMessage(messageObject, false); if (message == null) { continue; } if (chat != null) { message = message.replace(" @ " + name, ""); } else { message = message.replace(name + ": ", "").replace(name + " ", ""); } if (text.length() > 0) { text += "\n\n"; } text += message; unreadConvBuilder.addMessage(message); } Intent intent = new Intent(ApplicationLoader.applicationContext, LaunchActivity.class); intent.setAction("com.tmessages.openchat" + Math.random() + Integer.MAX_VALUE); intent.setFlags(32768); if (chat != null) { intent.putExtra("chatId", chat.id); } else if (user != null) { intent.putExtra("userId", user.id); } PendingIntent contentIntent = PendingIntent.getActivity(ApplicationLoader.applicationContext, 0, intent, PendingIntent.FLAG_ONE_SHOT); NotificationCompat.WearableExtender wearableExtender = new NotificationCompat.WearableExtender(); if (wearReplyAction != null) { wearableExtender.addAction(wearReplyAction); } NotificationCompat.Builder builder = new NotificationCompat.Builder( ApplicationLoader.applicationContext).setContentTitle(name) .setSmallIcon(R.drawable.notification).setGroup("messages").setContentText(text) .setAutoCancel(true).setColor(0xff2ca5e0).setGroupSummary(false) .setContentIntent(contentIntent).extend(wearableExtender) .extend(new NotificationCompat.CarExtender() .setUnreadConversation(unreadConvBuilder.build())) .setCategory(NotificationCompat.CATEGORY_MESSAGE); if (photoPath != null) { BitmapDrawable img = ImageLoader.getInstance().getImageFromMemory(photoPath, null, "50_50"); if (img != null) { builder.setLargeIcon(img.getBitmap()); } } if (chat == null && user != null && user.phone != null && user.phone.length() > 0) { builder.addPerson("tel:+" + user.phone); } notificationManager.notify(notificationIdWear, builder.build()); wearNotificationsIds.put(dialog_id, notificationIdWear); } for (HashMap.Entry<Long, Integer> entry : oldIdsWear.entrySet()) { notificationManager.cancel(entry.getValue()); } }
From source file:org.pouyadr.messenger.NotificationsController.java
@SuppressLint("InlinedApi") private void showExtraNotifications(NotificationCompat.Builder notificationBuilder, boolean notifyAboutLast) { if (Build.VERSION.SDK_INT < 18) { return;/*from w ww . ja v a 2 s. com*/ } ArrayList<Long> sortedDialogs = new ArrayList<>(); HashMap<Long, ArrayList<MessageObject>> messagesByDialogs = new HashMap<>(); for (int a = 0; a < pushMessages.size(); a++) { MessageObject messageObject = pushMessages.get(a); long dialog_id = messageObject.getDialogId(); if ((int) dialog_id == 0) { continue; } ArrayList<MessageObject> arrayList = messagesByDialogs.get(dialog_id); if (arrayList == null) { arrayList = new ArrayList<>(); messagesByDialogs.put(dialog_id, arrayList); sortedDialogs.add(0, dialog_id); } arrayList.add(messageObject); } HashMap<Long, Integer> oldIdsWear = new HashMap<>(); oldIdsWear.putAll(wearNotificationsIds); wearNotificationsIds.clear(); HashMap<Long, Integer> oldIdsAuto = new HashMap<>(); oldIdsAuto.putAll(autoNotificationsIds); autoNotificationsIds.clear(); for (int b = 0; b < sortedDialogs.size(); b++) { long dialog_id = sortedDialogs.get(b); ArrayList<MessageObject> messageObjects = messagesByDialogs.get(dialog_id); int max_id = messageObjects.get(0).getId(); int max_date = messageObjects.get(0).messageOwner.date; TLRPC.Chat chat = null; TLRPC.User user = null; String name; if (dialog_id > 0) { user = MessagesController.getInstance().getUser((int) dialog_id); if (user == null) { continue; } } else { chat = MessagesController.getInstance().getChat(-(int) dialog_id); if (chat == null) { continue; } } TLRPC.FileLocation photoPath = null; if (AndroidUtilities.needShowPasscode(false) || UserConfig.isWaitingForPasscodeEnter || HiddenController.IsHidden(dialog_id)) { name = LocaleController.getString("AppName", R.string.AppName); } else { if (chat != null) { name = chat.title; } else { name = UserObject.getUserName(user); } 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; } } } Integer notificationIdWear = oldIdsWear.get(dialog_id); if (notificationIdWear == null) { notificationIdWear = wearNotificationId++; } else { oldIdsWear.remove(dialog_id); } Integer notificationIdAuto = oldIdsAuto.get(dialog_id); if (notificationIdAuto == null) { notificationIdAuto = autoNotificationId++; } else { oldIdsAuto.remove(dialog_id); } NotificationCompat.CarExtender.UnreadConversation.Builder unreadConvBuilder = new NotificationCompat.CarExtender.UnreadConversation.Builder( name).setLatestTimestamp((long) max_date * 1000); Intent msgHeardIntent = new Intent(); msgHeardIntent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); msgHeardIntent.setAction("org.telegram.messenger.ACTION_MESSAGE_HEARD"); msgHeardIntent.putExtra("dialog_id", dialog_id); msgHeardIntent.putExtra("max_id", max_id); PendingIntent msgHeardPendingIntent = PendingIntent.getBroadcast(ApplicationLoader.applicationContext, notificationIdAuto, msgHeardIntent, PendingIntent.FLAG_UPDATE_CURRENT); unreadConvBuilder.setReadPendingIntent(msgHeardPendingIntent); NotificationCompat.Action wearReplyAction = null; if (!ChatObject.isChannel(chat) && !AndroidUtilities.needShowPasscode(false) && !UserConfig.isWaitingForPasscodeEnter && !HiddenController.IsHidden(dialog_id)) { Intent msgReplyIntent = new Intent(); msgReplyIntent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); msgReplyIntent.setAction("org.pouyadr.messenger.ACTION_MESSAGE_REPLY"); msgReplyIntent.putExtra("dialog_id", dialog_id); msgReplyIntent.putExtra("max_id", max_id); PendingIntent msgReplyPendingIntent = PendingIntent.getBroadcast( ApplicationLoader.applicationContext, notificationIdAuto, msgReplyIntent, PendingIntent.FLAG_UPDATE_CURRENT); RemoteInput remoteInputAuto = new RemoteInput.Builder(NotificationsController.EXTRA_VOICE_REPLY) .setLabel(LocaleController.getString("Reply", R.string.Reply)).build(); unreadConvBuilder.setReplyAction(msgReplyPendingIntent, remoteInputAuto); Intent replyIntent = new Intent(ApplicationLoader.applicationContext, WearReplyReceiver.class); replyIntent.putExtra("dialog_id", dialog_id); replyIntent.putExtra("max_id", max_id); PendingIntent replyPendingIntent = PendingIntent.getBroadcast(ApplicationLoader.applicationContext, notificationIdWear, replyIntent, PendingIntent.FLAG_UPDATE_CURRENT); RemoteInput remoteInputWear = new RemoteInput.Builder(EXTRA_VOICE_REPLY) .setLabel(LocaleController.getString("Reply", R.string.Reply)).build(); String replyToString; if (chat != null) { replyToString = LocaleController.formatString("ReplyToGroup", R.string.ReplyToGroup, name); } else { replyToString = LocaleController.formatString("ReplyToUser", R.string.ReplyToUser, name); } wearReplyAction = new NotificationCompat.Action.Builder(R.drawable.ic_reply_icon, replyToString, replyPendingIntent).addRemoteInput(remoteInputWear).build(); } String text = ""; for (int a = messageObjects.size() - 1; a >= 0; a--) { MessageObject messageObject = messageObjects.get(a); String message = getStringForMessage(messageObject, false); if (message == null) { continue; } if (chat != null) { message = message.replace(" @ " + name, ""); } else { message = message.replace(name + ": ", "").replace(name + " ", ""); } if (text.length() > 0) { text += "\n\n"; } text += message; unreadConvBuilder.addMessage(message); } Intent intent = new Intent(ApplicationLoader.applicationContext, LaunchActivity.class); intent.setAction("com.tmessages.openchat" + Math.random() + Integer.MAX_VALUE); intent.setFlags(32768); if (chat != null) { intent.putExtra("chatId", chat.id); } else if (user != null) { intent.putExtra("userId", user.id); } PendingIntent contentIntent = PendingIntent.getActivity(ApplicationLoader.applicationContext, 0, intent, PendingIntent.FLAG_ONE_SHOT); NotificationCompat.WearableExtender wearableExtender = new NotificationCompat.WearableExtender(); if (wearReplyAction != null) { wearableExtender.addAction(wearReplyAction); } NotificationCompat.Builder builder = new NotificationCompat.Builder( ApplicationLoader.applicationContext).setContentTitle(name) .setSmallIcon(R.drawable.notification).setGroup("messages").setContentText(text) .setAutoCancel(true).setColor(0xff2ca5e0).setGroupSummary(false) .setContentIntent(contentIntent).extend(wearableExtender) .extend(new NotificationCompat.CarExtender() .setUnreadConversation(unreadConvBuilder.build())) .setCategory(NotificationCompat.CATEGORY_MESSAGE); if (photoPath != null) { BitmapDrawable img = ImageLoader.getInstance().getImageFromMemory(photoPath, null, "50_50"); if (img != null) { builder.setLargeIcon(img.getBitmap()); } } if (chat == null && user != null && user.phone != null && user.phone.length() > 0) { builder.addPerson("tel:+" + user.phone); } notificationManager.notify(notificationIdWear, builder.build()); wearNotificationsIds.put(dialog_id, notificationIdWear); } for (HashMap.Entry<Long, Integer> entry : oldIdsWear.entrySet()) { notificationManager.cancel(entry.getValue()); } }
From source file:kr.wdream.storyshop.NotificationsController.java
@SuppressLint("InlinedApi") private void showExtraNotifications(NotificationCompat.Builder notificationBuilder, boolean notifyAboutLast) { if (Build.VERSION.SDK_INT < 18) { return;//from w w w .ja v a 2s. c om } ArrayList<Long> sortedDialogs = new ArrayList<>(); HashMap<Long, ArrayList<MessageObject>> messagesByDialogs = new HashMap<>(); for (int a = 0; a < pushMessages.size(); a++) { MessageObject messageObject = pushMessages.get(a); long dialog_id = messageObject.getDialogId(); if ((int) dialog_id == 0) { continue; } ArrayList<MessageObject> arrayList = messagesByDialogs.get(dialog_id); if (arrayList == null) { arrayList = new ArrayList<>(); messagesByDialogs.put(dialog_id, arrayList); sortedDialogs.add(0, dialog_id); } arrayList.add(messageObject); } HashMap<Long, Integer> oldIdsWear = new HashMap<>(); oldIdsWear.putAll(wearNotificationsIds); wearNotificationsIds.clear(); for (int b = 0; b < sortedDialogs.size(); b++) { long dialog_id = sortedDialogs.get(b); ArrayList<MessageObject> messageObjects = messagesByDialogs.get(dialog_id); int max_id = messageObjects.get(0).getId(); int max_date = messageObjects.get(0).messageOwner.date; TLRPC.Chat chat = null; TLRPC.User user = null; String name; if (dialog_id > 0) { user = MessagesController.getInstance().getUser((int) dialog_id); if (user == null) { continue; } } else { chat = MessagesController.getInstance().getChat(-(int) dialog_id); if (chat == null) { continue; } } TLRPC.FileLocation photoPath = null; if (AndroidUtilities.needShowPasscode(false) || UserConfig.isWaitingForPasscodeEnter) { name = LocaleController.getString("AppName", R.string.AppName); } else { if (chat != null) { name = chat.title; } else { name = UserObject.getUserName(user); } 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; } } } Integer notificationId = oldIdsWear.get(dialog_id); if (notificationId == null) { notificationId = (int) dialog_id; } else { oldIdsWear.remove(dialog_id); } NotificationCompat.CarExtender.UnreadConversation.Builder unreadConvBuilder = new NotificationCompat.CarExtender.UnreadConversation.Builder( name).setLatestTimestamp((long) max_date * 1000); Intent msgHeardIntent = new Intent(); msgHeardIntent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); msgHeardIntent.setAction("kr.toptalk.messenger.ACTION_MESSAGE_HEARD"); msgHeardIntent.putExtra("dialog_id", dialog_id); msgHeardIntent.putExtra("max_id", max_id); PendingIntent msgHeardPendingIntent = PendingIntent.getBroadcast(ApplicationLoader.applicationContext, notificationId, msgHeardIntent, PendingIntent.FLAG_UPDATE_CURRENT); unreadConvBuilder.setReadPendingIntent(msgHeardPendingIntent); NotificationCompat.Action wearReplyAction = null; if (!ChatObject.isChannel(chat) && !AndroidUtilities.needShowPasscode(false) && !UserConfig.isWaitingForPasscodeEnter) { Intent msgReplyIntent = new Intent(); msgReplyIntent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); msgReplyIntent.setAction("kr.toptalk.messenger.ACTION_MESSAGE_REPLY"); msgReplyIntent.putExtra("dialog_id", dialog_id); msgReplyIntent.putExtra("max_id", max_id); PendingIntent msgReplyPendingIntent = PendingIntent.getBroadcast( ApplicationLoader.applicationContext, notificationId, msgReplyIntent, PendingIntent.FLAG_UPDATE_CURRENT); RemoteInput remoteInputAuto = new RemoteInput.Builder(NotificationsController.EXTRA_VOICE_REPLY) .setLabel(LocaleController.getString("Reply", R.string.Reply)).build(); unreadConvBuilder.setReplyAction(msgReplyPendingIntent, remoteInputAuto); Intent replyIntent = new Intent(ApplicationLoader.applicationContext, WearReplyReceiver.class); replyIntent.putExtra("dialog_id", dialog_id); replyIntent.putExtra("max_id", max_id); PendingIntent replyPendingIntent = PendingIntent.getBroadcast(ApplicationLoader.applicationContext, notificationId, replyIntent, PendingIntent.FLAG_UPDATE_CURRENT); RemoteInput remoteInputWear = new RemoteInput.Builder(EXTRA_VOICE_REPLY) .setLabel(LocaleController.getString("Reply", R.string.Reply)).build(); String replyToString; if (chat != null) { replyToString = LocaleController.formatString("ReplyToGroup", R.string.ReplyToGroup, name); } else { replyToString = LocaleController.formatString("ReplyToUser", R.string.ReplyToUser, name); } wearReplyAction = new NotificationCompat.Action.Builder(R.drawable.ic_reply_icon, replyToString, replyPendingIntent).addRemoteInput(remoteInputWear).build(); } Integer count = pushDialogs.get(dialog_id); if (count == null) { count = 0; } NotificationCompat.MessagingStyle messagingStyle = new NotificationCompat.MessagingStyle(null) .setConversationTitle(String.format("%1$s (%2$s)", name, LocaleController .formatPluralString("NewMessages", Math.max(count, messageObjects.size())))); String text = ""; for (int a = messageObjects.size() - 1; a >= 0; a--) { MessageObject messageObject = messageObjects.get(a); String message = getStringForMessage(messageObject, false); if (message == null) { continue; } if (chat != null) { message = message.replace(" @ " + name, ""); } else { message = message.replace(name + ": ", "").replace(name + " ", ""); } if (text.length() > 0) { text += "\n\n"; } text += message; unreadConvBuilder.addMessage(message); messagingStyle.addMessage(message, ((long) messageObject.messageOwner.date) * 1000, null); } Intent intent = new Intent(ApplicationLoader.applicationContext, LaunchActivity.class); intent.setAction("com.tmessages.openchat" + Math.random() + Integer.MAX_VALUE); intent.setFlags(32768); if (chat != null) { intent.putExtra("chatId", chat.id); } else if (user != null) { intent.putExtra("userId", user.id); } PendingIntent contentIntent = PendingIntent.getActivity(ApplicationLoader.applicationContext, 0, intent, PendingIntent.FLAG_ONE_SHOT); NotificationCompat.WearableExtender wearableExtender = new NotificationCompat.WearableExtender(); if (wearReplyAction != null) { wearableExtender.addAction(wearReplyAction); } NotificationCompat.Builder builder = new NotificationCompat.Builder( ApplicationLoader.applicationContext).setContentTitle(name) .setSmallIcon(R.drawable.notification).setGroup("messages").setContentText(text) .setAutoCancel(true).setNumber(messageObjects.size()).setColor(0xff2ca5e0) .setGroupSummary(false).setWhen(((long) messageObjects.get(0).messageOwner.date) * 1000) .setStyle(messagingStyle).setContentIntent(contentIntent).extend(wearableExtender) .extend(new NotificationCompat.CarExtender() .setUnreadConversation(unreadConvBuilder.build())) .setCategory(NotificationCompat.CATEGORY_MESSAGE); if (photoPath != null) { BitmapDrawable img = ImageLoader.getInstance().getImageFromMemory(photoPath, null, "50_50"); if (img != null) { builder.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) { builder.setLargeIcon(bitmap); } } catch (Throwable e) { //ignore } } } if (chat == null && user != null && user.phone != null && user.phone.length() > 0) { builder.addPerson("tel:+" + user.phone); } notificationManager.notify(notificationId, builder.build()); wearNotificationsIds.put(dialog_id, notificationId); } for (HashMap.Entry<Long, Integer> entry : oldIdsWear.entrySet()) { notificationManager.cancel(entry.getValue()); } }
From source file:net.bluehack.messenger.NotificationsController.java
@SuppressLint("InlinedApi") private void showExtraNotifications(NotificationCompat.Builder notificationBuilder, boolean notifyAboutLast) { if (Build.VERSION.SDK_INT < 18) { return;/*from w w w . j a v a 2s . co m*/ } ArrayList<Long> sortedDialogs = new ArrayList<>(); HashMap<Long, ArrayList<MessageObject>> messagesByDialogs = new HashMap<>(); for (int a = 0; a < pushMessages.size(); a++) { MessageObject messageObject = pushMessages.get(a); long dialog_id = messageObject.getDialogId(); if ((int) dialog_id == 0) { continue; } ArrayList<MessageObject> arrayList = messagesByDialogs.get(dialog_id); if (arrayList == null) { arrayList = new ArrayList<>(); messagesByDialogs.put(dialog_id, arrayList); sortedDialogs.add(0, dialog_id); } arrayList.add(messageObject); } HashMap<Long, Integer> oldIdsWear = new HashMap<>(); oldIdsWear.putAll(wearNotificationsIds); wearNotificationsIds.clear(); for (int b = 0; b < sortedDialogs.size(); b++) { long dialog_id = sortedDialogs.get(b); ArrayList<MessageObject> messageObjects = messagesByDialogs.get(dialog_id); int max_id = messageObjects.get(0).getId(); int max_date = messageObjects.get(0).messageOwner.date; TLRPC.Chat chat = null; TLRPC.User user = null; String name; if (dialog_id > 0) { user = MessagesController.getInstance().getUser((int) dialog_id); if (user == null) { continue; } } else { chat = MessagesController.getInstance().getChat(-(int) dialog_id); if (chat == null) { continue; } } TLRPC.FileLocation photoPath = null; if (AndroidUtilities.needShowPasscode(false) || UserConfig.isWaitingForPasscodeEnter) { name = LocaleController.getString("AppName", R.string.AppName); } else { if (chat != null) { name = chat.title; } else { name = UserObject.getUserName(user); } 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; } } } Integer notificationId = oldIdsWear.get(dialog_id); if (notificationId == null) { notificationId = (int) dialog_id; } else { oldIdsWear.remove(dialog_id); } NotificationCompat.CarExtender.UnreadConversation.Builder unreadConvBuilder = new NotificationCompat.CarExtender.UnreadConversation.Builder( name).setLatestTimestamp((long) max_date * 1000); Intent msgHeardIntent = new Intent(); msgHeardIntent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); msgHeardIntent.setAction("net.bluehack.messenger.ACTION_MESSAGE_HEARD"); msgHeardIntent.putExtra("dialog_id", dialog_id); msgHeardIntent.putExtra("max_id", max_id); PendingIntent msgHeardPendingIntent = PendingIntent.getBroadcast(ApplicationLoader.applicationContext, notificationId, msgHeardIntent, PendingIntent.FLAG_UPDATE_CURRENT); unreadConvBuilder.setReadPendingIntent(msgHeardPendingIntent); NotificationCompat.Action wearReplyAction = null; if (!ChatObject.isChannel(chat) && !AndroidUtilities.needShowPasscode(false) && !UserConfig.isWaitingForPasscodeEnter) { Intent msgReplyIntent = new Intent(); msgReplyIntent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); msgReplyIntent.setAction("net.bluehack.messenger.ACTION_MESSAGE_REPLY"); msgReplyIntent.putExtra("dialog_id", dialog_id); msgReplyIntent.putExtra("max_id", max_id); PendingIntent msgReplyPendingIntent = PendingIntent.getBroadcast( ApplicationLoader.applicationContext, notificationId, msgReplyIntent, PendingIntent.FLAG_UPDATE_CURRENT); RemoteInput remoteInputAuto = new RemoteInput.Builder(NotificationsController.EXTRA_VOICE_REPLY) .setLabel(LocaleController.getString("Reply", R.string.Reply)).build(); unreadConvBuilder.setReplyAction(msgReplyPendingIntent, remoteInputAuto); Intent replyIntent = new Intent(ApplicationLoader.applicationContext, WearReplyReceiver.class); replyIntent.putExtra("dialog_id", dialog_id); replyIntent.putExtra("max_id", max_id); PendingIntent replyPendingIntent = PendingIntent.getBroadcast(ApplicationLoader.applicationContext, notificationId, replyIntent, PendingIntent.FLAG_UPDATE_CURRENT); RemoteInput remoteInputWear = new RemoteInput.Builder(EXTRA_VOICE_REPLY) .setLabel(LocaleController.getString("Reply", R.string.Reply)).build(); String replyToString; if (chat != null) { replyToString = LocaleController.formatString("ReplyToGroup", R.string.ReplyToGroup, name); } else { replyToString = LocaleController.formatString("ReplyToUser", R.string.ReplyToUser, name); } wearReplyAction = new NotificationCompat.Action.Builder(R.drawable.ic_reply_icon, replyToString, replyPendingIntent).addRemoteInput(remoteInputWear).build(); } Integer count = pushDialogs.get(dialog_id); if (count == null) { count = 0; } NotificationCompat.MessagingStyle messagingStyle = new NotificationCompat.MessagingStyle(null) .setConversationTitle(String.format("%1$s (%2$s)", name, LocaleController .formatPluralString("NewMessages", Math.max(count, messageObjects.size())))); String text = ""; for (int a = messageObjects.size() - 1; a >= 0; a--) { MessageObject messageObject = messageObjects.get(a); String message = getStringForMessage(messageObject, false); if (message == null) { continue; } if (chat != null) { message = message.replace(" @ " + name, ""); } else { message = message.replace(name + ": ", "").replace(name + " ", ""); } if (text.length() > 0) { text += "\n\n"; } text += message; unreadConvBuilder.addMessage(message); messagingStyle.addMessage(message, ((long) messageObject.messageOwner.date) * 1000, null); } Intent intent = new Intent(ApplicationLoader.applicationContext, LaunchActivity.class); intent.setAction("com.tmessages.openchat" + Math.random() + Integer.MAX_VALUE); intent.setFlags(32768); if (chat != null) { intent.putExtra("chatId", chat.id); } else if (user != null) { intent.putExtra("userId", user.id); } PendingIntent contentIntent = PendingIntent.getActivity(ApplicationLoader.applicationContext, 0, intent, PendingIntent.FLAG_ONE_SHOT); NotificationCompat.WearableExtender wearableExtender = new NotificationCompat.WearableExtender(); if (wearReplyAction != null) { wearableExtender.addAction(wearReplyAction); } NotificationCompat.Builder builder = new NotificationCompat.Builder( ApplicationLoader.applicationContext).setContentTitle(name) .setSmallIcon(R.drawable.notification).setGroup("messages").setContentText(text) .setAutoCancel(true).setNumber(messageObjects.size()).setColor(0xff2ca5e0) .setGroupSummary(false).setWhen(((long) messageObjects.get(0).messageOwner.date) * 1000) .setStyle(messagingStyle).setContentIntent(contentIntent).extend(wearableExtender) .extend(new NotificationCompat.CarExtender() .setUnreadConversation(unreadConvBuilder.build())) .setCategory(NotificationCompat.CATEGORY_MESSAGE); if (photoPath != null) { BitmapDrawable img = ImageLoader.getInstance().getImageFromMemory(photoPath, null, "50_50"); if (img != null) { builder.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) { builder.setLargeIcon(bitmap); } } catch (Throwable e) { //ignore } } } if (chat == null && user != null && user.phone != null && user.phone.length() > 0) { builder.addPerson("tel:+" + user.phone); } notificationManager.notify(notificationId, builder.build()); wearNotificationsIds.put(dialog_id, notificationId); } for (HashMap.Entry<Long, Integer> entry : oldIdsWear.entrySet()) { notificationManager.cancel(entry.getValue()); } }
From source file:org.fornax.cartridges.sculptor.smartclient.server.ScServlet.java
private void mapRequestToObj(HashMap<String, Object> data, Class expectedClass, Object obj) throws Exception { if (obj == null) { throw new ApplicationException("mapRequestToObj called on NULL obj", "ERR9001"); }//w w w.j a va2 s .c om try { Method versionMethod = expectedClass.getMethod("getVersion", (Class<?>[]) null); Long objVersion = (Long) versionMethod.invoke(obj, (Object[]) null); String clientVersion = (String) data.get("version"); if (objVersion != null && clientVersion != null) { try { long clientVersionLong = Long.parseLong(clientVersion); if (!objVersion.equals(clientVersionLong)) { throw makeApplicationException("Can't save object", "ERR9016", (Serializable[]) null); } } catch (NumberFormatException nfe) { // Version from client isn't number - ignore } } } catch (NoSuchMethodException nme) { // No version control } Method[] methods = expectedClass.getMethods(); for (Method m : methods) { Class<?>[] paramTypes = m.getParameterTypes(); Class persistentClass = null; if (paramTypes.length == 1) { if (paramTypes[0].getAnnotation(Entity.class) != null) { persistentClass = paramTypes[0]; } else if (paramTypes[0].getAnnotation(Embeddable.class) != null) { persistentClass = paramTypes[0]; } } ServiceDescription srvParam = paramTypes.length == 1 ? findServiceByClassName(paramTypes[0].getName()) : null; if ((m.getName().startsWith(SET_PREFIX) && paramTypes.length == 1 && (paramTypes[0].isAssignableFrom(String.class) || paramTypes[0].equals(Integer.class) || paramTypes[0].equals(Integer.TYPE) || paramTypes[0].equals(Long.class) || paramTypes[0].equals(Long.TYPE) || paramTypes[0].equals(Float.class) || paramTypes[0].equals(Float.TYPE) || paramTypes[0].equals(Boolean.class) || paramTypes[0].equals(Boolean.TYPE) || paramTypes[0].equals(Double.class) || paramTypes[0].equals(Double.TYPE) || paramTypes[0].equals(Date.class) || Enum.class.isAssignableFrom(paramTypes[0]) || (srvParam != null && srvParam.getFindById() != null) || persistentClass != null)) || (m.getName().startsWith(GET_PREFIX) && paramTypes.length == 0 && (Set.class.isAssignableFrom(m.getReturnType()) || List.class.isAssignableFrom(m.getReturnType())))) { String fldName; if (m.getName().startsWith(GET_TRANSLATE)) { fldName = m.getName().substring(GET_TRANSLATE_LENGTH, GET_TRANSLATE_LENGTH + 1).toLowerCase() + m.getName().substring(GET_TRANSLATE_LENGTH + 1); } else { fldName = m.getName().substring(3, 4).toLowerCase() + m.getName().substring(4); } Object value = data.get(fldName); if (value == null) { fldName = m.getName().substring(3); value = data.get(fldName); } if (value != null) { Object typedVal; String val = null; if (value instanceof String) { val = (String) value; } log.log(Level.FINER, " value = " + value); if (m.getName().startsWith(GET_PREFIX) && paramTypes.length == 0 && (Set.class.isAssignableFrom(m.getReturnType()) || List.class.isAssignableFrom(m.getReturnType()))) { log.log(Level.FINER, "GET"); String attrName = m.getName().substring(3, 4).toLowerCase() + m.getName().substring(4); Type[] actualTypeArguments = null; Class iterClass = expectedClass; while (iterClass != null) { try { Field field = iterClass.getDeclaredField(attrName); ParameterizedType genericType = (ParameterizedType) field.getGenericType(); actualTypeArguments = genericType.getActualTypeArguments(); break; } catch (NoSuchFieldException nsfe) { // do nothing iterate again } iterClass = iterClass.getSuperclass(); iterClass = iterClass.equals(Object.class) ? null : iterClass; } if (actualTypeArguments != null && actualTypeArguments.length == 1 && actualTypeArguments[0] instanceof Class) { Class assocClass = (Class) actualTypeArguments[0]; ServiceDescription assocService = findServiceByClassName(assocClass.getName()); Collection dbValueSet = (Collection) m.invoke(obj, (Object[]) null); if (value == null || !(value instanceof HashMap)) { log.log(Level.FINE, "No data for db property {0}", attrName); } else if (assocService != null) { HashMap<String, Object> guiValueMap = (HashMap<String, Object>) value; ArrayList<Object> removeIt = new ArrayList<Object>(); Iterator dbIterator = dbValueSet.iterator(); while (dbIterator.hasNext()) { Object dbVal = dbIterator.next(); String dbValId = getIdFromObj(dbVal); if (dbValId != null) { boolean wasMatchingGuiVal = false; ArrayList<String> removeKeys = new ArrayList<String>(); for (String key : guiValueMap.keySet()) { Object object = guiValueMap.get(key); if (object instanceof HashMap) { Object guiValue = ((HashMap<String, Object>) object).get("id"); if (guiValue.equals(dbValId)) { removeKeys.add(key); wasMatchingGuiVal = true; mapRequestToObj((HashMap<String, Object>) guiValue, assocClass, dbVal); break; } } else if (object instanceof String) { // Association if (dbValId.equals(object)) { removeKeys.add(key); wasMatchingGuiVal = true; } } else { log.log(Level.WARNING, "Wrong object type from GUI under key {0}", key); } } // Remove processed elements // Direct remove is firing concurrent modification exception for (String removeKey : removeKeys) { guiValueMap.remove(removeKey); } if (!wasMatchingGuiVal) { // Is not in list comming from GUI - delete removeIt.add(dbVal); } } else { log.log(Level.WARNING, "No ID in object {0}", dbVal); } } dbValueSet.removeAll(removeIt); // Rest are new records for (String key : guiValueMap.keySet()) { Object object = guiValueMap.get(key); if (object instanceof HashMap) { Object subObj = makeNewInstance(assocClass, (HashMap<String, Object>) object); mapRequestToObj((HashMap<String, Object>) object, assocClass, subObj); dbValueSet.add(subObj); } else if (object instanceof String) { // Association try { Long id = new Long((String) object); Object assocObj = assocService.getFindById().invoke( assocService.getInstance(), ServiceContextStore.get(), id); if (assocObj != null) { dbValueSet.add(assocObj); } else { log.log(Level.WARNING, "Object with ID {0} not availabla via service {1}", new Object[] { id, assocService.getName() }); } } catch (Exception ex) { log.log(Level.WARNING, "No ID parsable from value {0} under key {1}", new Object[] { object, key }); } } else { log.log(Level.WARNING, "Wrong sub type {0}", attrName); } } } else if (assocClass != null) { HashMap<String, Object> guiValueMap = (HashMap<String, Object>) value; ArrayList<Object> removeIt = new ArrayList<Object>(); Iterator dbIterator = dbValueSet.iterator(); while (dbIterator.hasNext()) { Object dbVal = dbIterator.next(); String dbValId = getIdFromObj(dbVal); if (dbValId != null) { Object matchingGuiVal = null; for (String key : guiValueMap.keySet()) { Object object = guiValueMap.get(key); if (object instanceof HashMap) { HashMap<String, Object> guiVal = (HashMap<String, Object>) object; if (dbValId.equals(guiVal.get("id"))) { guiValueMap.remove(key); matchingGuiVal = guiVal; break; } } else { log.log(Level.WARNING, "Wrong object type from GUI under key {0}", key); } } if (matchingGuiVal != null) { // Coming from GUI - update mapRequestToObj((HashMap<String, Object>) matchingGuiVal, assocClass, dbVal); } else { // Not in GUI - delete removeIt.add(dbVal); } } else { log.log(Level.WARNING, "No ID in object {0}", dbVal); } } dbValueSet.removeAll(removeIt); // Rest are new records for (String key : guiValueMap.keySet()) { Object object = guiValueMap.get(key); if (object instanceof HashMap) { Object subObj = makeNewInstance(assocClass, (HashMap<String, Object>) object); mapRequestToObj((HashMap<String, Object>) object, assocClass, subObj); dbValueSet.add(subObj); } else { log.log(Level.WARNING, "Wrong sub type {0}", attrName); } } } } else { log.log(Level.WARNING, "No DB mapping or not of collection type: {0}", attrName); } typedVal = null; } else if (paramTypes[0].isAssignableFrom(String.class)) { typedVal = val; } else if (paramTypes[0].equals(Integer.class) || paramTypes[0].equals(Integer.TYPE)) { typedVal = Integer.parseInt(val); } else if (paramTypes[0].equals(Long.class) || paramTypes[0].equals(Long.TYPE)) { typedVal = Long.parseLong(val); } else if (paramTypes[0].equals(Double.class) || paramTypes[0].equals(Double.TYPE)) { typedVal = Double.parseDouble(val); } else if (paramTypes[0].equals(Float.class) || paramTypes[0].equals(Float.TYPE)) { typedVal = Float.parseFloat(val); } else if (paramTypes[0].equals(Boolean.class) || paramTypes[0].equals(Boolean.TYPE)) { typedVal = "true".equalsIgnoreCase(val) || "t".equalsIgnoreCase(val) || "y".equalsIgnoreCase(val); } else if (paramTypes[0].isAssignableFrom(Date.class)) { typedVal = dateFormat.parse(val); } else if (Enum.class.isAssignableFrom(paramTypes[0])) { try { Method fromValueMethod = paramTypes[0].getMethod("fromValue", String.class); typedVal = fromValueMethod.invoke(null, val); } catch (Exception ex) { typedVal = null; } try { if (typedVal == null) { Method valueOfMethod = paramTypes[0].getMethod("valueOf", String.class); typedVal = valueOfMethod.invoke(null, val); } } catch (Exception ex) { typedVal = null; } } else if (persistentClass != null && persistentClass.equals(FileUpload.class)) { FileItem fileItem = uploadServlet.getFileItem(sessionId.get(), fldName, val); if (fileItem != null) { typedVal = fileUploadService.uploadFile(ServiceContextStore.get(), fileItem.getName(), fileItem.getContentType(), fileItem.getInputStream()); } else { typedVal = null; } } else if (srvParam != null && srvParam.getFindById() != null) { if (value instanceof HashMap) { HashMap<String, Object> embeddedObj = (HashMap<String, Object>) value; typedVal = srvParam.getFindById().invoke(srvParam.getInstance(), ServiceContextStore.get(), new Long((String) embeddedObj.get("id"))); mapRequestToObj(embeddedObj, srvParam.getExpectedClass(), typedVal); } else { try { Long parsedId = new Long(val); typedVal = srvParam.getFindById().invoke(srvParam.getInstance(), ServiceContextStore.get(), parsedId); } catch (NumberFormatException nfe) { // wrong value typedVal = null; } } } else if (persistentClass != null) { String getMethodName = "g" + m.getName().substring(1); try { Method getMethod = obj.getClass().getMethod(getMethodName, (Class[]) null); typedVal = getMethod.invoke(obj, (Object[]) null); } catch (NoSuchMethodException nsme) { typedVal = null; } if (typedVal == null) { typedVal = makeNewInstance(persistentClass, (HashMap<String, Object>) value); } mapRequestToObj((HashMap<String, Object>) value, typedVal.getClass(), typedVal); } else { log.log(Level.WARNING, "Can't convert value for: {0}.{1} ({2})", new Object[] { expectedClass.getName(), m.getName(), (paramTypes.length == 1 ? paramTypes[0].getName() : paramTypes.toString()) }); typedVal = null; } if (typedVal != null) { m.invoke(obj, typedVal); } } } else if (m.getName().startsWith(SET_PREFIX)) { log.log(Level.WARNING, "Unusable setter method: {0}.{1} ({2})", new Object[] { expectedClass.getName(), m.getName(), (paramTypes.length == 1 ? paramTypes[0].getName() : paramTypes.toString()) }); } } }
From source file:org.opencms.test.OpenCmsTestCase.java
/** * Compares two lists of permission sets.<p> * @param source the source list to compare * @param target the destination list to compare * @param exclude the exclude list/* ww w . j av a2 s . c o m*/ * @return list of non matching permission sets */ private List compareList(CmsAccessControlList source, CmsAccessControlList target, List exclude) { boolean isOverwriteAll = false; Iterator itTargets = target.getPermissionMap().keySet().iterator(); while (itTargets.hasNext()) { CmsUUID principalId = (CmsUUID) itTargets.next(); if (principalId.equals(CmsAccessControlEntry.PRINCIPAL_OVERWRITE_ALL_ID)) { isOverwriteAll = true; } } HashMap result = new HashMap(); Map destinationMap = target.getPermissionMap(); Map sourceMap = source.getPermissionMap(); Iterator i = sourceMap.entrySet().iterator(); while (i.hasNext()) { Map.Entry entry = (Map.Entry) i.next(); CmsUUID key = (CmsUUID) entry.getKey(); CmsPermissionSet value = (CmsPermissionSet) entry.getValue(); if (destinationMap.containsKey(key)) { CmsPermissionSet destValue = (CmsPermissionSet) destinationMap.get(key); if (!destValue.equals(value)) { result.put(key, key + " " + value + " != " + destValue); } } else if (!isOverwriteAll) { // here would be best to check the path of the overwrite all entry // but since we have just the resource id, instead of the structure id // we are not able to do that here :( result.put(key, "missing " + key); } } // finally match the result list with the exclude list if (exclude != null) { Iterator l = exclude.iterator(); while (l.hasNext()) { CmsUUID excludeUUID = (CmsUUID) l.next(); if (result.containsKey(excludeUUID)) { result.remove(excludeUUID); } } } return new ArrayList(result.values()); }
From source file:com.ferdi2005.secondgram.NotificationsController.java
@SuppressLint("InlinedApi") private void showExtraNotifications(NotificationCompat.Builder notificationBuilder, boolean notifyAboutLast) { if (Build.VERSION.SDK_INT < 18) { return;// ww w . j a va2s . co m } ArrayList<Long> sortedDialogs = new ArrayList<>(); HashMap<Long, ArrayList<MessageObject>> messagesByDialogs = new HashMap<>(); for (int a = 0; a < pushMessages.size(); a++) { MessageObject messageObject = pushMessages.get(a); long dialog_id = messageObject.getDialogId(); if ((int) dialog_id == 0) { continue; } ArrayList<MessageObject> arrayList = messagesByDialogs.get(dialog_id); if (arrayList == null) { arrayList = new ArrayList<>(); messagesByDialogs.put(dialog_id, arrayList); sortedDialogs.add(0, dialog_id); } arrayList.add(messageObject); } HashMap<Long, Integer> oldIdsWear = new HashMap<>(); oldIdsWear.putAll(wearNotificationsIds); wearNotificationsIds.clear(); for (int b = 0; b < sortedDialogs.size(); b++) { long dialog_id = sortedDialogs.get(b); ArrayList<MessageObject> messageObjects = messagesByDialogs.get(dialog_id); int max_id = messageObjects.get(0).getId(); int max_date = messageObjects.get(0).messageOwner.date; TLRPC.Chat chat = null; TLRPC.User user = null; String name; if (dialog_id > 0) { user = MessagesController.getInstance().getUser((int) dialog_id); if (user == null) { continue; } } else { chat = MessagesController.getInstance().getChat(-(int) dialog_id); if (chat == null) { continue; } } TLRPC.FileLocation photoPath = null; if (AndroidUtilities.needShowPasscode(false) || UserConfig.isWaitingForPasscodeEnter) { name = LocaleController.getString("AppName", R.string.AppName); } else { if (chat != null) { name = chat.title; } else { name = UserObject.getUserName(user); } 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; } } } Integer notificationId = oldIdsWear.get(dialog_id); if (notificationId == null) { notificationId = (int) dialog_id; } else { oldIdsWear.remove(dialog_id); } NotificationCompat.CarExtender.UnreadConversation.Builder unreadConvBuilder = new NotificationCompat.CarExtender.UnreadConversation.Builder( name).setLatestTimestamp((long) max_date * 1000); Intent msgHeardIntent = new Intent(); msgHeardIntent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); msgHeardIntent.setAction("com.ferdi2005.secondgram.ACTION_MESSAGE_HEARD"); msgHeardIntent.putExtra("dialog_id", dialog_id); msgHeardIntent.putExtra("max_id", max_id); PendingIntent msgHeardPendingIntent = PendingIntent.getBroadcast(ApplicationLoader.applicationContext, notificationId, msgHeardIntent, PendingIntent.FLAG_UPDATE_CURRENT); unreadConvBuilder.setReadPendingIntent(msgHeardPendingIntent); NotificationCompat.Action wearReplyAction = null; if ((!ChatObject.isChannel(chat) || chat != null && chat.megagroup) && !AndroidUtilities.needShowPasscode(false) && !UserConfig.isWaitingForPasscodeEnter) { Intent msgReplyIntent = new Intent(); msgReplyIntent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); msgReplyIntent.setAction("com.ferdi2005.secondgram.ACTION_MESSAGE_REPLY"); msgReplyIntent.putExtra("dialog_id", dialog_id); msgReplyIntent.putExtra("max_id", max_id); PendingIntent msgReplyPendingIntent = PendingIntent.getBroadcast( ApplicationLoader.applicationContext, notificationId, msgReplyIntent, PendingIntent.FLAG_UPDATE_CURRENT); RemoteInput remoteInputAuto = new RemoteInput.Builder(NotificationsController.EXTRA_VOICE_REPLY) .setLabel(LocaleController.getString("Reply", R.string.Reply)).build(); unreadConvBuilder.setReplyAction(msgReplyPendingIntent, remoteInputAuto); Intent replyIntent = new Intent(ApplicationLoader.applicationContext, WearReplyReceiver.class); replyIntent.putExtra("dialog_id", dialog_id); replyIntent.putExtra("max_id", max_id); PendingIntent replyPendingIntent = PendingIntent.getBroadcast(ApplicationLoader.applicationContext, notificationId, replyIntent, PendingIntent.FLAG_UPDATE_CURRENT); RemoteInput remoteInputWear = new RemoteInput.Builder(EXTRA_VOICE_REPLY) .setLabel(LocaleController.getString("Reply", R.string.Reply)).build(); String replyToString; if (chat != null) { replyToString = LocaleController.formatString("ReplyToGroup", R.string.ReplyToGroup, name); } else { replyToString = LocaleController.formatString("ReplyToUser", R.string.ReplyToUser, name); } wearReplyAction = new NotificationCompat.Action.Builder(R.drawable.ic_reply_icon, replyToString, replyPendingIntent).setAllowGeneratedReplies(true).addRemoteInput(remoteInputWear).build(); } Integer count = pushDialogs.get(dialog_id); if (count == null) { count = 0; } NotificationCompat.MessagingStyle messagingStyle = new NotificationCompat.MessagingStyle(null) .setConversationTitle(String.format("%1$s (%2$s)", name, LocaleController .formatPluralString("NewMessages", Math.max(count, messageObjects.size())))); String text = ""; for (int a = messageObjects.size() - 1; a >= 0; a--) { MessageObject messageObject = messageObjects.get(a); String message = getStringForMessage(messageObject, false); if (message == null) { continue; } if (chat != null) { message = message.replace(" @ " + name, ""); } else { message = message.replace(name + ": ", "").replace(name + " ", ""); } if (text.length() > 0) { text += "\n\n"; } text += message; unreadConvBuilder.addMessage(message); messagingStyle.addMessage(message, ((long) messageObject.messageOwner.date) * 1000, null); } Intent intent = new Intent(ApplicationLoader.applicationContext, LaunchActivity.class); intent.setAction("com.tmessages.openchat" + Math.random() + Integer.MAX_VALUE); intent.setFlags(32768); if (chat != null) { intent.putExtra("chatId", chat.id); } else if (user != null) { intent.putExtra("userId", user.id); } PendingIntent contentIntent = PendingIntent.getActivity(ApplicationLoader.applicationContext, 0, intent, PendingIntent.FLAG_ONE_SHOT); NotificationCompat.WearableExtender wearableExtender = new NotificationCompat.WearableExtender(); if (wearReplyAction != null) { wearableExtender.addAction(wearReplyAction); } String dismissalID = null; if (chat != null) dismissalID = "tgchat" + chat.id + "_" + max_id; else if (user != null) dismissalID = "tguser" + user.id + "_" + max_id; wearableExtender.setDismissalId(dismissalID); NotificationCompat.WearableExtender summaryExtender = new NotificationCompat.WearableExtender(); summaryExtender.setDismissalId("summary_" + dismissalID); notificationBuilder.extend(summaryExtender); NotificationCompat.Builder builder = new NotificationCompat.Builder( ApplicationLoader.applicationContext).setContentTitle(name) .setSmallIcon(R.drawable.notification).setGroup("messages").setContentText(text) .setAutoCancel(true).setNumber(messageObjects.size()).setColor(0xff2ca5e0) .setGroupSummary(false).setWhen(((long) messageObjects.get(0).messageOwner.date) * 1000) .setStyle(messagingStyle).setContentIntent(contentIntent).extend(wearableExtender) .extend(new NotificationCompat.CarExtender() .setUnreadConversation(unreadConvBuilder.build())) .setCategory(NotificationCompat.CATEGORY_MESSAGE); if (photoPath != null) { BitmapDrawable img = ImageLoader.getInstance().getImageFromMemory(photoPath, null, "50_50"); if (img != null) { builder.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) { builder.setLargeIcon(bitmap); } } catch (Throwable e) { //ignore } } } if (chat == null && user != null && user.phone != null && user.phone.length() > 0) { builder.addPerson("tel:+" + user.phone); } notificationManager.notify(notificationId, builder.build()); wearNotificationsIds.put(dialog_id, notificationId); } for (HashMap.Entry<Long, Integer> entry : oldIdsWear.entrySet()) { notificationManager.cancel(entry.getValue()); } }
From source file:org.aselect.server.request.handler.xsaml20.sp.Xsaml20_AssertionConsumer.java
/** * Handle sso response.//from ww w. j a va 2 s. co m * * @param htRemoteAttributes * the ht remote attributes * @param servletRequest * the servlet request * @param servletResponse * the servlet response * @throws ASelectException * the a select exception */ private void handleSSOResponse(HashMap htSessionContext, HashMap htRemoteAttributes, HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws ASelectException { String sMethod = "handleSSOResponse"; _systemLogger.log(Level.INFO, MODULE, sMethod, "<--"); try { // 20120712, Bauke: Stores TGT in class variable to save on reads: HashMap htServiceRequest = createServiceRequest(servletRequest); _systemLogger.log(Level.INFO, MODULE, sMethod, "htServiceRequest=" + htServiceRequest); String sLocalRid = (String) htRemoteAttributes.get("local_rid"); if (sLocalRid == null) { _systemLogger.log(Level.INFO, MODULE, sMethod, "Missing remote attribute: 'local_rid'"); throw new ASelectCommunicationException(Errors.ERROR_ASELECT_SERVER_INVALID_REQUEST); } // for authentication logging String sRemoteOrg = (String) htSessionContext.get("remote_organization"); String sOrg = (String) htRemoteAttributes.get("organization"); if (sRemoteOrg != null && sOrg != null && !sRemoteOrg.equals(sOrg)) sRemoteOrg = sOrg + "@" + sRemoteOrg; String sResultCode = (String) htRemoteAttributes.get("result_code"); String sUID = (String) htRemoteAttributes.get("uid"); String sFederationId = (String) htSessionContext.get("federation_url"); if (sResultCode != null) { if (sResultCode.equals(Errors.ERROR_ASELECT_SERVER_CANCEL) || sResultCode.equals(Errors.ERROR_ASELECT_AUTHSP_COULD_NOT_AUTHENTICATE_USER)) { _systemLogger.log(Level.WARNING, MODULE, sMethod, "Cancel"); _authenticationLogger.log( new Object[] { "Saml", sUID, (String) htServiceRequest.get("client_ip"), sRemoteOrg, htSessionContext.get("app_id"), "denied", sFederationId, sResultCode }); // Issue 'CANCEL' TGT TGTIssuer tgtIssuer = new TGTIssuer(_sMyServerId); tgtIssuer.issueErrorTGTandRedirect(sLocalRid, htSessionContext, sResultCode, servletResponse); } else { // remote server returned error _systemLogger.log(Level.WARNING, MODULE, sMethod, "Error"); _authenticationLogger.log( new Object[] { "Saml", sUID, (String) htServiceRequest.get("client_ip"), sRemoteOrg, htSessionContext.get("app_id"), "denied", sFederationId, sResultCode }); throw new ASelectException(Errors.ERROR_ASELECT_AUTHSP_ACCESS_DENIED); } } else { // No result_code set, log successful authentication _authenticationLogger.log(new Object[] { "Saml", sUID, (String) htServiceRequest.get("client_ip"), sRemoteOrg, htSessionContext.get("app_id"), "granted", sFederationId }); if (isLogAuthProof()) { // Log auth_proof here if enabled ASelectAuthProofLogger.getHandle().log(sUID, (String) htRemoteAttributes.get("client_ip"), (String) htSessionContext.get("app_id"), (String) null, (String) htRemoteAttributes.get("auth_proof")); // _systemLogger.log(Level.FINEST, MODULE, sMethod, "auth_proof logged after successful authentication=" + // htRemoteAttributes.get("auth_proof")); if (!isCarryAuthProof()) { // We do not want to carry the auth_proof any further Object removed_auth_proof = htRemoteAttributes.remove("auth_proof"); if (removed_auth_proof != null) { _systemLogger.log(Level.FINEST, MODULE, sMethod, "Successfully removed auth_proof from htRemoteAttributes"); } else { _systemLogger.log(Level.FINEST, MODULE, sMethod, "Could not remove auth_proof from htRemoteAttributes"); } } } HandlerTools.setRequestorFriendlyCookie(servletResponse, htSessionContext, _systemLogger); // 20130825 // Issue a cross TGT since we do not know the AuthSP // and we might have received remote attributes. TGTIssuer oTGTIssuer = new TGTIssuer(_sMyServerId); String sOldTGT = (String) htServiceRequest.get("aselect_credentials_tgt"); // Will also redirect the user, this call can update/delete the session in the local cache // Final session updates will be done by finalSessionProcessing() oTGTIssuer.issueTGTandRedirect(sLocalRid, htSessionContext, null, htRemoteAttributes, servletRequest, servletResponse, sOldTGT, true); // 20090909: oTGTIssuer.issueCrossTGT(sLocalRid, null, htRemoteAttributes, servletResponse, sOldTGT); } } catch (ASelectException ae) { throw ae; } catch (Exception e) { _systemLogger.log(Level.WARNING, MODULE, sMethod, "Internal error", e); throw new ASelectException(Errors.ERROR_ASELECT_INTERNAL_ERROR, e); } }