Search in sources :

Example 1 with Person

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();
}
Also used : Builder(androidx.core.app.NotificationCompat.Builder) Person(androidx.core.app.Person) Uri(android.net.Uri) Contact(eu.siacs.conversations.entities.Contact)

Example 2 with Person

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();
}
Also used : Recipient(org.thoughtcrime.securesms.recipients.Recipient) ComponentName(android.content.ComponentName) Person(androidx.core.app.Person) ShortcutInfoCompat(androidx.core.content.pm.ShortcutInfoCompat) LocusIdCompat(androidx.core.content.LocusIdCompat) WorkerThread(androidx.annotation.WorkerThread) NonNull(androidx.annotation.NonNull)

Example 3 with Person

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);
            }
        }
    }
}
Also used : Message(eu.siacs.conversations.entities.Message) Conversation(eu.siacs.conversations.entities.Conversation) SpannableString(android.text.SpannableString) Uri(android.net.Uri) SpannableString(android.text.SpannableString) StyleSpan(android.text.style.StyleSpan) NotificationCompat(androidx.core.app.NotificationCompat) Person(androidx.core.app.Person)

Example 4 with Person

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;
}
Also used : NotificationCompat(androidx.core.app.NotificationCompat) Person(androidx.core.app.Person)

Aggregations

Person (androidx.core.app.Person)4 Uri (android.net.Uri)2 NotificationCompat (androidx.core.app.NotificationCompat)2 ComponentName (android.content.ComponentName)1 SpannableString (android.text.SpannableString)1 StyleSpan (android.text.style.StyleSpan)1 NonNull (androidx.annotation.NonNull)1 WorkerThread (androidx.annotation.WorkerThread)1 Builder (androidx.core.app.NotificationCompat.Builder)1 LocusIdCompat (androidx.core.content.LocusIdCompat)1 ShortcutInfoCompat (androidx.core.content.pm.ShortcutInfoCompat)1 Contact (eu.siacs.conversations.entities.Contact)1 Conversation (eu.siacs.conversations.entities.Conversation)1 Message (eu.siacs.conversations.entities.Message)1 Recipient (org.thoughtcrime.securesms.recipients.Recipient)1