use of androidx.core.app.NotificationCompat.Builder 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.NotificationCompat.Builder in project Conversations by siacs.
the class NotificationService method buildMultipleConversation.
private Builder buildMultipleConversation(final boolean notify, final boolean quietHours) {
final Builder mBuilder = new NotificationCompat.Builder(mXmppConnectionService, quietHours ? "quiet_hours" : (notify ? "messages" : "silent_messages"));
final NotificationCompat.InboxStyle style = new NotificationCompat.InboxStyle();
style.setBigContentTitle(mXmppConnectionService.getResources().getQuantityString(R.plurals.x_unread_conversations, notifications.size(), notifications.size()));
final StringBuilder names = new StringBuilder();
Conversation conversation = null;
for (final ArrayList<Message> messages : notifications.values()) {
if (messages.size() > 0) {
conversation = (Conversation) messages.get(0).getConversation();
final String name = conversation.getName().toString();
SpannableString styledString;
if (Config.HIDE_MESSAGE_TEXT_IN_NOTIFICATION) {
int count = messages.size();
styledString = new SpannableString(name + ": " + mXmppConnectionService.getResources().getQuantityString(R.plurals.x_messages, count, count));
styledString.setSpan(new StyleSpan(Typeface.BOLD), 0, name.length(), 0);
style.addLine(styledString);
} else {
styledString = new SpannableString(name + ": " + UIHelper.getMessagePreview(mXmppConnectionService, messages.get(0)).first);
styledString.setSpan(new StyleSpan(Typeface.BOLD), 0, name.length(), 0);
style.addLine(styledString);
}
names.append(name);
names.append(", ");
}
}
if (names.length() >= 2) {
names.delete(names.length() - 2, names.length());
}
final String contentTitle = mXmppConnectionService.getResources().getQuantityString(R.plurals.x_unread_conversations, notifications.size(), notifications.size());
mBuilder.setContentTitle(contentTitle);
mBuilder.setTicker(contentTitle);
mBuilder.setContentText(names.toString());
mBuilder.setStyle(style);
if (conversation != null) {
mBuilder.setContentIntent(createContentIntent(conversation));
}
mBuilder.setGroupSummary(true);
mBuilder.setGroup(CONVERSATIONS_GROUP);
mBuilder.setDeleteIntent(createDeleteIntent(null));
mBuilder.setSmallIcon(R.drawable.ic_notification);
return mBuilder;
}
use of androidx.core.app.NotificationCompat.Builder in project Conversations by siacs.
the class NotificationService method pushFailedDelivery.
public void pushFailedDelivery(final Message message) {
final Conversation conversation = (Conversation) message.getConversation();
final boolean isScreenLocked = !mXmppConnectionService.isScreenLocked();
if (this.mIsInForeground && isScreenLocked && this.mOpenConversation == message.getConversation()) {
Log.d(Config.LOGTAG, message.getConversation().getAccount().getJid().asBareJid() + ": suppressing failed delivery notification because conversation is open");
return;
}
final PendingIntent pendingIntent = createContentIntent(conversation);
final int notificationId = generateRequestCode(conversation, 0) + DELIVERY_FAILED_NOTIFICATION_ID;
final int failedDeliveries = conversation.countFailedDeliveries();
final Notification notification = new Builder(mXmppConnectionService, "delivery_failed").setContentTitle(conversation.getName()).setAutoCancel(true).setSmallIcon(R.drawable.ic_error_white_24dp).setContentText(mXmppConnectionService.getResources().getQuantityText(R.plurals.some_messages_could_not_be_delivered, failedDeliveries)).setGroup("delivery_failed").setContentIntent(pendingIntent).build();
final Notification summaryNotification = new Builder(mXmppConnectionService, "delivery_failed").setContentTitle(mXmppConnectionService.getString(R.string.failed_deliveries)).setContentText(mXmppConnectionService.getResources().getQuantityText(R.plurals.some_messages_could_not_be_delivered, 1024)).setSmallIcon(R.drawable.ic_error_white_24dp).setGroup("delivery_failed").setGroupSummary(true).setAutoCancel(true).build();
notify(notificationId, notification);
notify(DELIVERY_FAILED_NOTIFICATION_ID, summaryNotification);
}
use of androidx.core.app.NotificationCompat.Builder in project Conversations by siacs.
the class NotificationService method showIncomingCallNotification.
private void showIncomingCallNotification(final AbstractJingleConnection.Id id, final Set<Media> media) {
final Intent fullScreenIntent = new Intent(mXmppConnectionService, RtpSessionActivity.class);
fullScreenIntent.putExtra(RtpSessionActivity.EXTRA_ACCOUNT, id.account.getJid().asBareJid().toEscapedString());
fullScreenIntent.putExtra(RtpSessionActivity.EXTRA_WITH, id.with.toEscapedString());
fullScreenIntent.putExtra(RtpSessionActivity.EXTRA_SESSION_ID, id.sessionId);
fullScreenIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
fullScreenIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
final NotificationCompat.Builder builder = new NotificationCompat.Builder(mXmppConnectionService, INCOMING_CALLS_NOTIFICATION_CHANNEL);
if (media.contains(Media.VIDEO)) {
builder.setSmallIcon(R.drawable.ic_videocam_white_24dp);
builder.setContentTitle(mXmppConnectionService.getString(R.string.rtp_state_incoming_video_call));
} else {
builder.setSmallIcon(R.drawable.ic_call_white_24dp);
builder.setContentTitle(mXmppConnectionService.getString(R.string.rtp_state_incoming_call));
}
final Contact contact = id.getContact();
builder.setLargeIcon(mXmppConnectionService.getAvatarService().get(contact, AvatarService.getSystemUiAvatarSize(mXmppConnectionService)));
final Uri systemAccount = contact.getSystemAccount();
if (systemAccount != null) {
builder.addPerson(systemAccount.toString());
}
builder.setContentText(id.account.getRoster().getContact(id.with).getDisplayName());
builder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC);
builder.setPriority(NotificationCompat.PRIORITY_HIGH);
builder.setCategory(NotificationCompat.CATEGORY_CALL);
PendingIntent pendingIntent = createPendingRtpSession(id, Intent.ACTION_VIEW, 101);
builder.setFullScreenIntent(pendingIntent, true);
// old androids need this?
builder.setContentIntent(pendingIntent);
builder.setOngoing(true);
builder.addAction(new NotificationCompat.Action.Builder(R.drawable.ic_call_end_white_48dp, mXmppConnectionService.getString(R.string.dismiss_call), createCallAction(id.sessionId, XmppConnectionService.ACTION_DISMISS_CALL, 102)).build());
builder.addAction(new NotificationCompat.Action.Builder(R.drawable.ic_call_white_24dp, mXmppConnectionService.getString(R.string.answer_call), createPendingRtpSession(id, RtpSessionActivity.ACTION_ACCEPT_CALL, 103)).build());
modifyIncomingCall(builder);
final Notification notification = builder.build();
notification.flags = notification.flags | Notification.FLAG_INSISTENT;
notify(INCOMING_CALL_NOTIFICATION_ID, notification);
}
use of androidx.core.app.NotificationCompat.Builder in project Conversations by siacs.
the class NotificationService method buildSingleConversations.
private Builder buildSingleConversations(final ArrayList<Message> messages, final boolean notify, final boolean quietHours) {
final Builder mBuilder = new NotificationCompat.Builder(mXmppConnectionService, quietHours ? "quiet_hours" : (notify ? "messages" : "silent_messages"));
if (messages.size() >= 1) {
final Conversation conversation = (Conversation) messages.get(0).getConversation();
mBuilder.setLargeIcon(mXmppConnectionService.getAvatarService().get(conversation, AvatarService.getSystemUiAvatarSize(mXmppConnectionService)));
mBuilder.setContentTitle(conversation.getName());
if (Config.HIDE_MESSAGE_TEXT_IN_NOTIFICATION) {
int count = messages.size();
mBuilder.setContentText(mXmppConnectionService.getResources().getQuantityString(R.plurals.x_messages, count, count));
} else {
Message message;
// TODO starting with Android 9 we might want to put images in MessageStyle
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P && (message = getImage(messages)) != null) {
modifyForImage(mBuilder, message, messages);
} else {
modifyForTextOnly(mBuilder, messages);
}
RemoteInput remoteInput = new RemoteInput.Builder("text_reply").setLabel(UIHelper.getMessageHint(mXmppConnectionService, conversation)).build();
PendingIntent markAsReadPendingIntent = createReadPendingIntent(conversation);
NotificationCompat.Action markReadAction = new NotificationCompat.Action.Builder(R.drawable.ic_drafts_white_24dp, mXmppConnectionService.getString(R.string.mark_as_read), markAsReadPendingIntent).setSemanticAction(NotificationCompat.Action.SEMANTIC_ACTION_MARK_AS_READ).setShowsUserInterface(false).build();
final String replyLabel = mXmppConnectionService.getString(R.string.reply);
final String lastMessageUuid = Iterables.getLast(messages).getUuid();
final NotificationCompat.Action replyAction = new NotificationCompat.Action.Builder(R.drawable.ic_send_text_offline, replyLabel, createReplyIntent(conversation, lastMessageUuid, false)).setSemanticAction(NotificationCompat.Action.SEMANTIC_ACTION_REPLY).setShowsUserInterface(false).addRemoteInput(remoteInput).build();
final NotificationCompat.Action wearReplyAction = new NotificationCompat.Action.Builder(R.drawable.ic_wear_reply, replyLabel, createReplyIntent(conversation, lastMessageUuid, true)).addRemoteInput(remoteInput).build();
mBuilder.extend(new NotificationCompat.WearableExtender().addAction(wearReplyAction));
int addedActionsCount = 1;
mBuilder.addAction(markReadAction);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
mBuilder.addAction(replyAction);
++addedActionsCount;
}
if (displaySnoozeAction(messages)) {
String label = mXmppConnectionService.getString(R.string.snooze);
PendingIntent pendingSnoozeIntent = createSnoozeIntent(conversation);
NotificationCompat.Action snoozeAction = new NotificationCompat.Action.Builder(R.drawable.ic_notifications_paused_white_24dp, label, pendingSnoozeIntent).build();
mBuilder.addAction(snoozeAction);
++addedActionsCount;
}
if (addedActionsCount < 3) {
final Message firstLocationMessage = getFirstLocationMessage(messages);
if (firstLocationMessage != null) {
final PendingIntent pendingShowLocationIntent = createShowLocationIntent(firstLocationMessage);
if (pendingShowLocationIntent != null) {
final String label = mXmppConnectionService.getResources().getString(R.string.show_location);
NotificationCompat.Action locationAction = new NotificationCompat.Action.Builder(R.drawable.ic_room_white_24dp, label, pendingShowLocationIntent).build();
mBuilder.addAction(locationAction);
++addedActionsCount;
}
}
}
if (addedActionsCount < 3) {
Message firstDownloadableMessage = getFirstDownloadableMessage(messages);
if (firstDownloadableMessage != null) {
String label = mXmppConnectionService.getResources().getString(R.string.download_x_file, UIHelper.getFileDescriptionString(mXmppConnectionService, firstDownloadableMessage));
PendingIntent pendingDownloadIntent = createDownloadIntent(firstDownloadableMessage);
NotificationCompat.Action downloadAction = new NotificationCompat.Action.Builder(R.drawable.ic_file_download_white_24dp, label, pendingDownloadIntent).build();
mBuilder.addAction(downloadAction);
++addedActionsCount;
}
}
}
if (conversation.getMode() == Conversation.MODE_SINGLE) {
Contact contact = conversation.getContact();
Uri systemAccount = contact.getSystemAccount();
if (systemAccount != null) {
mBuilder.addPerson(systemAccount.toString());
}
}
mBuilder.setWhen(conversation.getLatestMessage().getTimeSent());
mBuilder.setSmallIcon(R.drawable.ic_notification);
mBuilder.setDeleteIntent(createDeleteIntent(conversation));
mBuilder.setContentIntent(createContentIntent(conversation));
}
return mBuilder;
}
Aggregations