List of usage examples for java.util HashMap putAll
public void putAll(Map<? extends K, ? extends V> m)
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 ww w . j ava 2 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(); 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;/* w w w. j a v a 2 s . 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(); 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:com.ferdi2005.secondgram.NotificationsController.java
@SuppressLint("InlinedApi") private void showExtraNotifications(NotificationCompat.Builder notificationBuilder, boolean notifyAboutLast) { if (Build.VERSION.SDK_INT < 18) { return;//from w w w .j av a 2 s .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(); 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.apache.ddlutils.platform.PlatformImplBase.java
/** * Creates the SQL for updating an object of the given type. If a concrete bean is given, * then a concrete update statement is created, otherwise an update statement usable in a * prepared statement is build./*from w w w .j av a 2 s . c o m*/ * * @param model The database model * @param dynaClass The type * @param primaryKeys The primary keys * @param properties The properties to write * @param bean Optionally the concrete bean to update * @return The SQL required to update the instance */ protected String createUpdateSql(Database model, SqlDynaClass dynaClass, SqlDynaProperty[] primaryKeys, SqlDynaProperty[] properties, DynaBean bean) { Table table = model.findTable(dynaClass.getTableName()); HashMap columnValues = toColumnValues(properties, bean); columnValues.putAll(toColumnValues(primaryKeys, bean)); return _builder.getUpdateSql(table, columnValues, bean == null); }
From source file:org.apache.ambari.server.controller.KerberosHelper.java
/** * Builds a composite Kerberos descriptor using the default Kerberos descriptor and a user-specified * Kerberos descriptor, if it exists.// ww w. j a va 2 s. c o m * <p/> * The default Kerberos descriptor is built from the kerberos.json files in the stack. It can be * retrieved via the <code>stacks/:stackName/versions/:version/artifacts/kerberos_descriptor</code> * endpoint * <p/> * The user-specified Kerberos descriptor was registered to the * <code>cluster/:clusterName/artifacts/kerberos_descriptor</code> endpoint. * <p/> * If the user-specified Kerberos descriptor exists, it is used to update the default Kerberos * descriptor and the composite is returned. If not, the default cluster descriptor is returned * as-is. * * @param cluster cluster instance * @return the kerberos descriptor associated with the specified cluster * @throws AmbariException if unable to obtain the descriptor */ private KerberosDescriptor getKerberosDescriptor(Cluster cluster) throws AmbariException { StackId stackId = cluster.getCurrentStackVersion(); // ------------------------------- // Get the default Kerberos descriptor from the stack, which is the same as the value from // stacks/:stackName/versions/:version/artifacts/kerberos_descriptor KerberosDescriptor defaultDescriptor = ambariMetaInfo.getKerberosDescriptor(stackId.getStackName(), stackId.getStackVersion()); // ------------------------------- // Get the user-supplied Kerberos descriptor from cluster/:clusterName/artifacts/kerberos_descriptor KerberosDescriptor descriptor = null; PredicateBuilder pb = new PredicateBuilder(); Predicate predicate = pb.begin().property("Artifacts/cluster_name").equals(cluster.getClusterName()).and() .property(ArtifactResourceProvider.ARTIFACT_NAME_PROPERTY).equals("kerberos_descriptor").end() .toPredicate(); synchronized (KerberosHelper.class) { if (clusterController == null) { clusterController = ClusterControllerHelper.getClusterController(); } } ResourceProvider artifactProvider = clusterController.ensureResourceProvider(Resource.Type.Artifact); Request request = new RequestImpl(Collections.<String>emptySet(), Collections.<Map<String, Object>>emptySet(), Collections.<String, String>emptyMap(), null); Set<Resource> response = null; try { response = artifactProvider.getResources(request, predicate); } catch (SystemException e) { e.printStackTrace(); throw new AmbariException( "An unknown error occurred while trying to obtain the cluster kerberos descriptor", e); } catch (UnsupportedPropertyException e) { e.printStackTrace(); throw new AmbariException( "An unknown error occurred while trying to obtain the cluster kerberos descriptor", e); } catch (NoSuchParentResourceException e) { // parent cluster doesn't exist. shouldn't happen since we have the cluster instance e.printStackTrace(); throw new AmbariException( "An unknown error occurred while trying to obtain the cluster kerberos descriptor", e); } catch (NoSuchResourceException e) { // no descriptor registered, use the default from the stack } if (response != null && !response.isEmpty()) { Resource descriptorResource = response.iterator().next(); Map<String, Map<String, Object>> propertyMap = descriptorResource.getPropertiesMap(); if (propertyMap != null) { Map<String, Object> artifactData = propertyMap.get(ArtifactResourceProvider.ARTIFACT_DATA_PROPERTY); Map<String, Object> artifactDataProperties = propertyMap .get(ArtifactResourceProvider.ARTIFACT_DATA_PROPERTY + "/properties"); HashMap<String, Object> data = new HashMap<String, Object>(); if (artifactData != null) { data.putAll(artifactData); } if (artifactDataProperties != null) { data.put("properties", artifactDataProperties); } descriptor = kerberosDescriptorFactory.createInstance(data); } } // ------------------------------- // ------------------------------- // Attempt to build and return a composite of the default Kerberos descriptor and the user-supplied // Kerberos descriptor. If the default descriptor exists, overlay the user-supplied Kerberos // descriptor on top of it (if it exists) and return the composite; else return the user-supplied // Kerberos descriptor. If both values are null, null may be returned. if (defaultDescriptor == null) { return descriptor; } else { if (descriptor != null) { defaultDescriptor.update(descriptor); } return defaultDescriptor; } // ------------------------------- }
From source file:oscar.oscarDemographic.pageUtil.DemographicExportAction4.java
private void fillContactInfo(Demographics.Contact contact, String contactId, String demoNo, int index) { org.oscarehr.common.model.Demographic relDemo = new DemographicData().getDemographic(contactId); HashMap<String, String> relDemoExt = new HashMap<String, String>(); relDemoExt.putAll(demographicExtDao.getAllValuesForDemo(contactId)); Util.writeNameSimple(contact.addNewName(), relDemo.getFirstName(), relDemo.getLastName()); if (StringUtils.empty(relDemo.getFirstName())) { exportError.add("Error! No First Name for contact (" + index + ") for Patient " + demoNo); }//from w w w. j ava 2 s . c o m if (StringUtils.empty(relDemo.getLastName())) { exportError.add("Error! No Last Name for contact (" + index + ") for Patient " + demoNo); } if (StringUtils.filled(relDemo.getEmail())) contact.setEmailAddress(relDemo.getEmail()); boolean phoneExtTooLong = false; if (phoneNoValid(relDemo.getPhone())) { phoneExtTooLong = addPhone(relDemo.getPhone(), relDemoExt.get("hPhoneExt"), cdsDt.PhoneNumberType.R, contact.addNewPhoneNumber()); if (phoneExtTooLong) { exportError.add("Home phone extension too long, export trimmed for contact (" + (index + 1) + ") of Patient " + demoNo); } } if (phoneNoValid(relDemo.getPhone2())) { phoneExtTooLong = addPhone(relDemo.getPhone2(), relDemoExt.get("wPhoneExt"), cdsDt.PhoneNumberType.W, contact.addNewPhoneNumber()); if (phoneExtTooLong) { exportError.add("Work phone extension too long, export trimmed for contact (" + (index + 1) + ") of Patient " + demoNo); } } if (phoneNoValid(relDemoExt.get("demo_cell"))) { addPhone(relDemoExt.get("demo_cell"), null, cdsDt.PhoneNumberType.C, contact.addNewPhoneNumber()); } }
From source file:org.kuali.kfs.module.tem.document.web.struts.TravelAuthorizationForm.java
/** * Creates a MAP for all the buttons to appear on the Travel Authorization Form, and sets the attributes of these buttons. * * @return the button map created./*from w w w . j av a 2 s. c o m*/ */ protected Map<String, ExtraButton> createButtonsMap() { HashMap<String, ExtraButton> result = new HashMap<String, ExtraButton>(); // Amend button ExtraButton amendButton = new ExtraButton(); amendButton.setExtraButtonProperty("methodToCall.amendTa"); amendButton .setExtraButtonSource("${" + KFSConstants.EXTERNALIZABLE_IMAGES_URL_KEY + "}buttonsmall_amend.gif"); amendButton.setExtraButtonAltText("Amend"); // Hold button ExtraButton holdButton = new ExtraButton(); holdButton.setExtraButtonProperty("methodToCall.holdTa"); holdButton .setExtraButtonSource("${" + KFSConstants.EXTERNALIZABLE_IMAGES_URL_KEY + "}buttonsmall_hold.gif"); holdButton.setExtraButtonAltText("Hold"); // Remove Hold button ExtraButton removeHoldButton = new ExtraButton(); removeHoldButton.setExtraButtonProperty("methodToCall.removeHoldTa"); removeHoldButton.setExtraButtonSource( "${" + KFSConstants.EXTERNALIZABLE_IMAGES_URL_KEY + "}buttonsmall_removehold.gif"); removeHoldButton.setExtraButtonAltText("Remove Hold"); // Cancel Travel button ExtraButton cancelTravelButton = new ExtraButton(); cancelTravelButton.setExtraButtonProperty("methodToCall.cancelTa"); cancelTravelButton.setExtraButtonSource( "${" + KFSConstants.EXTERNALIZABLE_IMAGES_URL_KEY + "}buttonsmall_cancelta.gif"); cancelTravelButton.setExtraButtonAltText("Cancel Travel Authorization"); // Close Travel button ExtraButton closeTAButton = new ExtraButton(); closeTAButton.setExtraButtonProperty("methodToCall.closeTa"); closeTAButton.setExtraButtonSource( "${" + KFSConstants.EXTERNALIZABLE_IMAGES_URL_KEY + "}buttonsmall_closeta.gif"); closeTAButton.setExtraButtonAltText("Close Travel Authorization"); result.put(amendButton.getExtraButtonProperty(), amendButton); result.put(holdButton.getExtraButtonProperty(), holdButton); result.put(removeHoldButton.getExtraButtonProperty(), removeHoldButton); result.put(cancelTravelButton.getExtraButtonProperty(), cancelTravelButton); result.put(closeTAButton.getExtraButtonProperty(), closeTAButton); result.putAll(createNewReimbursementButtonMap()); result.putAll(createPaymentExtraButtonMap()); return result; }
From source file:org.apache.lens.cube.metadata.CubeMetastoreClient.java
boolean partitionExists(String storageTableName, UpdatePeriod updatePeriod, Map<String, Date> partitionTimestamps, Map<String, String> nonTimePartSpec) throws HiveException, LensException { HashMap<String, String> partSpec = new HashMap<>(nonTimePartSpec); partSpec.putAll(getPartitionSpec(updatePeriod, partitionTimestamps)); return partitionExists(storageTableName, partSpec); }
From source file:org.apache.solr.handler.clustering.carrot2.CarrotClusteringEngine.java
@Override @SuppressWarnings("rawtypes") public String init(NamedList config, final SolrCore core) { this.core = core; String result = super.init(config, core); final SolrParams initParams = SolrParams.toSolrParams(config); // Initialization attributes for Carrot2 controller. HashMap<String, Object> initAttributes = new HashMap<>(); // Customize Carrot2's resource lookup to first look for resources // using Solr's resource loader. If that fails, try loading from the classpath. ResourceLookup resourceLookup = new ResourceLookup( // Solr-specific resource loading. new SolrResourceLocator(core, initParams), // Using the class loader directly because this time we want to omit the prefix new ClassLoaderLocator(core.getResourceLoader().getClassLoader())); DefaultLexicalDataFactoryDescriptor.attributeBuilder(initAttributes).resourceLookup(resourceLookup); // Make sure the requested Carrot2 clustering algorithm class is available String carrotAlgorithmClassName = initParams.get(CarrotParams.ALGORITHM); try {/* w ww . ja v a2 s.c o m*/ this.clusteringAlgorithmClass = core.getResourceLoader().findClass(carrotAlgorithmClassName, IClusteringAlgorithm.class); } catch (SolrException s) { if (!(s.getCause() instanceof ClassNotFoundException)) { throw s; } } // Load Carrot2-Workbench exported attribute XMLs based on the 'name' attribute // of this component. This by-name convention lookup is used to simplify configuring algorithms. String componentName = initParams.get(ClusteringEngine.ENGINE_NAME); log.info("Initializing Clustering Engine '" + MoreObjects.firstNonNull(componentName, "<no 'name' attribute>") + "'"); if (!Strings.isNullOrEmpty(componentName)) { IResource[] attributeXmls = resourceLookup.getAll(componentName + "-attributes.xml"); if (attributeXmls.length > 0) { if (attributeXmls.length > 1) { log.warn("More than one attribute file found, first one will be used: " + Arrays.toString(attributeXmls)); } Thread ct = Thread.currentThread(); ClassLoader prev = ct.getContextClassLoader(); try { ct.setContextClassLoader(core.getResourceLoader().getClassLoader()); AttributeValueSets avs = AttributeValueSets.deserialize(attributeXmls[0].open()); AttributeValueSet defaultSet = avs.getDefaultAttributeValueSet(); initAttributes.putAll(defaultSet.getAttributeValues()); } catch (Exception e) { throw new SolrException(ErrorCode.SERVER_ERROR, "Could not read attributes XML for clustering component: " + componentName, e); } finally { ct.setContextClassLoader(prev); } } } // Extract solrconfig attributes, they take precedence. extractCarrotAttributes(initParams, initAttributes); // Customize the stemmer and tokenizer factories. The implementations we provide here // are included in the code base of Solr, so that it's possible to refactor // the Lucene APIs the factories rely on if needed. // Additionally, we set a custom lexical resource factory for Carrot2 that // will use both Carrot2 default stop words as well as stop words from // the StopFilter defined on the field. final AttributeBuilder attributeBuilder = BasicPreprocessingPipelineDescriptor .attributeBuilder(initAttributes); attributeBuilder.lexicalDataFactory(SolrStopwordsCarrot2LexicalDataFactory.class); if (!initAttributes.containsKey(BasicPreprocessingPipelineDescriptor.Keys.TOKENIZER_FACTORY)) { attributeBuilder.tokenizerFactory(LuceneCarrot2TokenizerFactory.class); } if (!initAttributes.containsKey(BasicPreprocessingPipelineDescriptor.Keys.STEMMER_FACTORY)) { attributeBuilder.stemmerFactory(LuceneCarrot2StemmerFactory.class); } // Pass the schema (via the core) to SolrStopwordsCarrot2LexicalDataFactory. initAttributes.put("solrCore", core); // Carrot2 uses current thread's context class loader to get // certain classes (e.g. custom tokenizer/stemmer) at initialization time. // To make sure classes from contrib JARs are available, // we swap the context class loader for the time of clustering. Thread ct = Thread.currentThread(); ClassLoader prev = ct.getContextClassLoader(); try { ct.setContextClassLoader(core.getResourceLoader().getClassLoader()); this.controller.init(initAttributes); } finally { ct.setContextClassLoader(prev); } SchemaField uniqueField = core.getLatestSchema().getUniqueKeyField(); if (uniqueField == null) { throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, CarrotClusteringEngine.class.getSimpleName() + " requires the schema to have a uniqueKeyField"); } this.idFieldName = uniqueField.getName(); return result; }
From source file:pltag.corpus.StringTree.java
/** * Creates a lexicon entry from the tree except (removing unary nodes which * may have been introduced through modification. * *//*from ww w .j av a 2s .co m*/ public HashMap<Integer, Integer> removeUnaryNodes(int nodeid) { HashMap<Integer, Integer> mapping = new HashMap<Integer, Integer>(); //int nodeid = Integer.parseInt(nodeid); String cat = categories[nodeid]; String matchcat = cat; if (cat.contains("-")) { matchcat = cat.substring(0, cat.indexOf("-")); } ArrayList<Integer> childlist = children.get(nodeid); if (childlist == null) { return mapping; } else if (childlist.size() == 1) { int child = childlist.get(0); //int child = Integer.parseInt(child); if (categories[child].equals(matchcat) && ((originUp != null && originDown != null && this.getLowestOrigin(child, originUp) .equals(this.getLowestOrigin(child, originDown))) || (this.getLowerIndex(child) != -1 && this.getUpperIndex(child) != -1 && this.getLowerIndex(child) == this.getUpperIndex(child))) && (nodeTypes[child] == TagNodeType.internal || nodeTypes[child] == TagNodeType.predicted)) { children.put(nodeid, children.get(child)); // children.put(Integer.toString(nodeid), children.get(child)); mapping.put(nodeid, child); mapping.put(child, nodeid); if (children.get(child) != null) { for (Integer newchild : children.get(child)) { removeNode(child); parent[newchild] = nodeid; // parent[Integer.parseInt(newchild)] = Integer.toString(nodeid); mapping.putAll(removeUnaryNodes(nodeid)); // mapping.putAll(removeUnaryNodes(Integer.toString(nodeid))); } } return mapping; } } for (Integer child : childlist) { mapping.putAll(removeUnaryNodes(child)); } return mapping; }