use of androidx.core.app.Person in project Conversations by siacs.
the class NotificationService method getPerson.
private Person getPerson(Message message) {
final Contact contact = message.getContact();
final Person.Builder builder = new Person.Builder();
if (contact != null) {
builder.setName(contact.getDisplayName());
final Uri uri = contact.getSystemAccount();
if (uri != null) {
builder.setUri(uri.toString());
}
} else {
builder.setName(UIHelper.getMessageDisplayName(message));
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
builder.setIcon(IconCompat.createWithBitmap(mXmppConnectionService.getAvatarService().get(message, AvatarService.getSystemUiAvatarSize(mXmppConnectionService), false)));
}
return builder.build();
}
use of androidx.core.app.Person in project Signal-Android by WhisperSystems.
the class ConversationUtil method buildShortcutInfo.
/**
* Builds the shortcut info object for a given Recipient.
*
* @param context The Context under which we are operating
* @param recipient The Recipient to generate a ShortcutInfo for
* @param rank The rank that should be assigned to this recipient
* @return The new ShortcutInfo
*/
@WorkerThread
@NonNull
private static ShortcutInfoCompat buildShortcutInfo(@NonNull Context context, @NonNull Recipient recipient, int rank) {
Recipient resolved = recipient.resolve();
Person[] persons = buildPersons(context, resolved);
Long threadId = SignalDatabase.threads().getThreadIdFor(resolved.getId());
String shortName = resolved.isSelf() ? context.getString(R.string.note_to_self) : resolved.getShortDisplayName(context);
String longName = resolved.isSelf() ? context.getString(R.string.note_to_self) : resolved.getDisplayName(context);
String shortcutId = getShortcutId(resolved);
return new ShortcutInfoCompat.Builder(context, shortcutId).setLongLived(true).setIntent(ConversationIntents.createBuilder(context, resolved.getId(), threadId != null ? threadId : -1).build()).setShortLabel(shortName).setLongLabel(longName).setIcon(AvatarUtil.getIconCompatForShortcut(context, resolved)).setPersons(persons).setCategories(Collections.singleton(CATEGORY_SHARE_TARGET)).setActivity(new ComponentName(context, "org.thoughtcrime.securesms.RoutingActivity")).setRank(rank).setLocusId(new LocusIdCompat(shortcutId)).build();
}
use of androidx.core.app.Person in project Conversations by siacs.
the class NotificationService method modifyForTextOnly.
private void modifyForTextOnly(final Builder builder, final ArrayList<Message> messages) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
final Conversation conversation = (Conversation) messages.get(0).getConversation();
final Person.Builder meBuilder = new Person.Builder().setName(mXmppConnectionService.getString(R.string.me));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
meBuilder.setIcon(IconCompat.createWithBitmap(mXmppConnectionService.getAvatarService().get(conversation.getAccount(), AvatarService.getSystemUiAvatarSize(mXmppConnectionService))));
}
final Person me = meBuilder.build();
NotificationCompat.MessagingStyle messagingStyle = new NotificationCompat.MessagingStyle(me);
final boolean multiple = conversation.getMode() == Conversation.MODE_MULTI;
if (multiple) {
messagingStyle.setConversationTitle(conversation.getName());
}
for (Message message : messages) {
final Person sender = message.getStatus() == Message.STATUS_RECEIVED ? getPerson(message) : null;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P && isImageMessage(message)) {
final Uri dataUri = FileBackend.getMediaUri(mXmppConnectionService, mXmppConnectionService.getFileBackend().getFile(message));
NotificationCompat.MessagingStyle.Message imageMessage = new NotificationCompat.MessagingStyle.Message(UIHelper.getMessagePreview(mXmppConnectionService, message).first, message.getTimeSent(), sender);
if (dataUri != null) {
imageMessage.setData(message.getMimeType(), dataUri);
}
messagingStyle.addMessage(imageMessage);
} else {
messagingStyle.addMessage(UIHelper.getMessagePreview(mXmppConnectionService, message).first, message.getTimeSent(), sender);
}
}
messagingStyle.setGroupConversation(multiple);
builder.setStyle(messagingStyle);
} else {
if (messages.get(0).getConversation().getMode() == Conversation.MODE_SINGLE) {
builder.setStyle(new NotificationCompat.BigTextStyle().bigText(getMergedBodies(messages)));
final CharSequence preview = UIHelper.getMessagePreview(mXmppConnectionService, messages.get(messages.size() - 1)).first;
builder.setContentText(preview);
builder.setTicker(preview);
builder.setNumber(messages.size());
} else {
final NotificationCompat.InboxStyle style = new NotificationCompat.InboxStyle();
SpannableString styledString;
for (Message message : messages) {
final String name = UIHelper.getMessageDisplayName(message);
styledString = new SpannableString(name + ": " + message.getBody());
styledString.setSpan(new StyleSpan(Typeface.BOLD), 0, name.length(), 0);
style.addLine(styledString);
}
builder.setStyle(style);
int count = messages.size();
if (count == 1) {
final String name = UIHelper.getMessageDisplayName(messages.get(0));
styledString = new SpannableString(name + ": " + messages.get(0).getBody());
styledString.setSpan(new StyleSpan(Typeface.BOLD), 0, name.length(), 0);
builder.setContentText(styledString);
builder.setTicker(styledString);
} else {
final String text = mXmppConnectionService.getResources().getQuantityString(R.plurals.x_messages, count, count);
builder.setContentText(text);
builder.setTicker(text);
}
}
}
}
use of androidx.core.app.Person in project xabber-android by redsolution.
the class MessageNotificationCreator method createMessageStyle.
private NotificationCompat.Style createMessageStyle(MessageNotificationManager.Chat chat, boolean showText) {
NotificationCompat.MessagingStyle messageStyle = new NotificationCompat.MessagingStyle(new Person.Builder().setName(context.getString(R.string.sender_is_you)).build());
for (MessageNotificationManager.Message message : chat.getMessages()) {
Person person = null;
if (message.getAuthor() != null && message.getAuthor().length() > 0) {
person = new Person.Builder().setName(message.getAuthor()).setIcon(IconCompat.createWithBitmap(getLargeIcon(chat))).build();
}
messageStyle.addMessage(new NotificationCompat.MessagingStyle.Message(showText ? message.getMessageText() : messageHidden, message.getTimestamp(), person));
}
messageStyle.setConversationTitle(chat.getChatTitle());
messageStyle.setGroupConversation(chat.isGroupChat());
return messageStyle;
}
Aggregations