Search in sources :

Example 6 with Builder

use of androidx.core.app.NotificationCompat.Builder in project Conversations by siacs.

the class NotificationService method getOngoingCallNotification.

public Notification getOngoingCallNotification(final XmppConnectionService.OngoingCall ongoingCall) {
    final AbstractJingleConnection.Id id = ongoingCall.id;
    final NotificationCompat.Builder builder = new NotificationCompat.Builder(mXmppConnectionService, "ongoing_calls");
    if (ongoingCall.media.contains(Media.VIDEO)) {
        builder.setSmallIcon(R.drawable.ic_videocam_white_24dp);
        if (ongoingCall.reconnecting) {
            builder.setContentTitle(mXmppConnectionService.getString(R.string.reconnecting_video_call));
        } else {
            builder.setContentTitle(mXmppConnectionService.getString(R.string.ongoing_video_call));
        }
    } else {
        builder.setSmallIcon(R.drawable.ic_call_white_24dp);
        if (ongoingCall.reconnecting) {
            builder.setContentTitle(mXmppConnectionService.getString(R.string.reconnecting_call));
        } else {
            builder.setContentTitle(mXmppConnectionService.getString(R.string.ongoing_call));
        }
    }
    builder.setContentText(id.account.getRoster().getContact(id.with).getDisplayName());
    builder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC);
    builder.setPriority(NotificationCompat.PRIORITY_HIGH);
    builder.setCategory(NotificationCompat.CATEGORY_CALL);
    builder.setContentIntent(createPendingRtpSession(id, Intent.ACTION_VIEW, 101));
    builder.setOngoing(true);
    builder.addAction(new NotificationCompat.Action.Builder(R.drawable.ic_call_end_white_48dp, mXmppConnectionService.getString(R.string.hang_up), createCallAction(id.sessionId, XmppConnectionService.ACTION_END_CALL, 104)).build());
    return builder.build();
}
Also used : AbstractJingleConnection(eu.siacs.conversations.xmpp.jingle.AbstractJingleConnection) Builder(androidx.core.app.NotificationCompat.Builder) Builder(androidx.core.app.NotificationCompat.Builder) NotificationCompat(androidx.core.app.NotificationCompat)

Example 7 with Builder

use of androidx.core.app.NotificationCompat.Builder in project Conversations by siacs.

the class NotificationService method updateNotification.

private void updateNotification(final boolean notify, final List<String> conversations, final boolean summaryOnly) {
    final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(mXmppConnectionService);
    final boolean quiteHours = isQuietHours();
    // if this check is changed to > 0 catchup messages will create one notification per conversation
    final boolean notifyOnlyOneChild = notify && conversations != null && conversations.size() == 1;
    if (notifications.size() == 0) {
        cancel(NOTIFICATION_ID);
    } else {
        if (notify) {
            this.markLastNotification();
        }
        final Builder mBuilder;
        if (notifications.size() == 1 && Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
            mBuilder = buildSingleConversations(notifications.values().iterator().next(), notify, quiteHours);
            modifyForSoundVibrationAndLight(mBuilder, notify, quiteHours, preferences);
            notify(NOTIFICATION_ID, mBuilder.build());
        } else {
            mBuilder = buildMultipleConversation(notify, quiteHours);
            if (notifyOnlyOneChild) {
                mBuilder.setGroupAlertBehavior(NotificationCompat.GROUP_ALERT_CHILDREN);
            }
            modifyForSoundVibrationAndLight(mBuilder, notify, quiteHours, preferences);
            if (!summaryOnly) {
                for (Map.Entry<String, ArrayList<Message>> entry : notifications.entrySet()) {
                    String uuid = entry.getKey();
                    final boolean notifyThis = notifyOnlyOneChild ? conversations.contains(uuid) : notify;
                    Builder singleBuilder = buildSingleConversations(entry.getValue(), notifyThis, quiteHours);
                    if (!notifyOnlyOneChild) {
                        singleBuilder.setGroupAlertBehavior(NotificationCompat.GROUP_ALERT_SUMMARY);
                    }
                    modifyForSoundVibrationAndLight(singleBuilder, notifyThis, quiteHours, preferences);
                    singleBuilder.setGroup(CONVERSATIONS_GROUP);
                    setNotificationColor(singleBuilder);
                    notify(entry.getKey(), NOTIFICATION_ID, singleBuilder.build());
                }
            }
            notify(NOTIFICATION_ID, mBuilder.build());
        }
    }
}
Also used : SharedPreferences(android.content.SharedPreferences) Builder(androidx.core.app.NotificationCompat.Builder) ArrayList(java.util.ArrayList) SpannableString(android.text.SpannableString) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

Builder (androidx.core.app.NotificationCompat.Builder)7 NotificationCompat (androidx.core.app.NotificationCompat)4 PendingIntent (android.app.PendingIntent)3 Uri (android.net.Uri)3 SpannableString (android.text.SpannableString)3 Contact (eu.siacs.conversations.entities.Contact)3 Conversation (eu.siacs.conversations.entities.Conversation)3 Notification (android.app.Notification)2 Message (eu.siacs.conversations.entities.Message)2 Intent (android.content.Intent)1 SharedPreferences (android.content.SharedPreferences)1 StyleSpan (android.text.style.StyleSpan)1 Person (androidx.core.app.Person)1 RemoteInput (androidx.core.app.RemoteInput)1 AbstractJingleConnection (eu.siacs.conversations.xmpp.jingle.AbstractJingleConnection)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1