Java Code Examples for android.support.v4.app.NotificationCompat.CarExtender.UnreadConversation

The following are top voted examples for showing how to use android.support.v4.app.NotificationCompat.CarExtender.UnreadConversation. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: TenguChat   File: NotificationService.java   View source code 5 votes vote down vote up
private void modifyForImage(final Builder builder, final UnreadConversation.Builder uBuilder,
							final Message message, final ArrayList<Message> messages) {
	try {
		final Bitmap bitmap = mXmppConnectionService.getFileBackend()
				.getThumbnail(message, getPixel(288), false);
		final ArrayList<Message> tmp = new ArrayList<>();
		for (final Message msg : messages) {
			if (msg.getType() == Message.TYPE_TEXT
					&& msg.getTransferable() == null) {
				tmp.add(msg);
			}
		}
		final BigPictureStyle bigPictureStyle = new NotificationCompat.BigPictureStyle();
		bigPictureStyle.bigPicture(bitmap);
		if (tmp.size() > 0) {
			CharSequence text = getMergedBodies(tmp);
			bigPictureStyle.setSummaryText(text);
			builder.setContentText(text);
		} else {
			builder.setContentText(mXmppConnectionService.getString(
					R.string.received_x_file,
					UIHelper.getFileDescriptionString(mXmppConnectionService, message)));
		}
		builder.setStyle(bigPictureStyle);
	} catch (final FileNotFoundException e) {
		modifyForTextOnly(builder, uBuilder, messages);
	}
}
 
Example 2
Project: Pix-Art-Messenger   File: NotificationService.java   View source code 5 votes vote down vote up
private void modifyForImage(final Builder builder, final UnreadConversation.Builder uBuilder,
                            final Message message, final ArrayList<Message> messages) {
    try {
        final Bitmap bitmap = mXmppConnectionService.getFileBackend()
                .getThumbnail(message, getPixel(288), false);
        final ArrayList<Message> tmp = new ArrayList<>();
        for (final Message msg : messages) {
            if (msg.getType() == Message.TYPE_TEXT
                    && msg.getTransferable() == null) {
                tmp.add(msg);
            }
        }
        final BigPictureStyle bigPictureStyle = new NotificationCompat.BigPictureStyle();
        bigPictureStyle.bigPicture(bitmap);
        if (tmp.size() > 0) {
            CharSequence text = getMergedBodies(tmp);
            bigPictureStyle.setSummaryText(text);
            builder.setContentText(text);
        } else {
            builder.setContentText(mXmppConnectionService.getString(
                    R.string.received_x_file,
                    UIHelper.getFileDescriptionString(mXmppConnectionService, message)));
        }
        builder.setStyle(bigPictureStyle);
    } catch (final FileNotFoundException e) {
        modifyForTextOnly(builder, uBuilder, messages);
    }
}
 
Example 3
Project: Conversations   File: NotificationService.java   View source code 5 votes vote down vote up
private void modifyForImage(final Builder builder, final UnreadConversation.Builder uBuilder,
							final Message message, final ArrayList<Message> messages) {
	try {
		final Bitmap bitmap = mXmppConnectionService.getFileBackend()
				.getThumbnail(message, getPixel(288), false);
		final ArrayList<Message> tmp = new ArrayList<>();
		for (final Message msg : messages) {
			if (msg.getType() == Message.TYPE_TEXT
					&& msg.getTransferable() == null) {
				tmp.add(msg);
			}
		}
		final BigPictureStyle bigPictureStyle = new NotificationCompat.BigPictureStyle();
		bigPictureStyle.bigPicture(bitmap);
		if (tmp.size() > 0) {
			CharSequence text = getMergedBodies(tmp);
			bigPictureStyle.setSummaryText(text);
			builder.setContentText(text);
		} else {
			builder.setContentText(mXmppConnectionService.getString(
					R.string.received_x_file,
					UIHelper.getFileDescriptionString(mXmppConnectionService, message)));
		}
		builder.setStyle(bigPictureStyle);
	} catch (final FileNotFoundException e) {
		modifyForTextOnly(builder, uBuilder, messages);
	}
}
 
Example 4
Project: TenguChat   File: NotificationService.java   View source code 4 votes vote down vote up
private Builder buildSingleConversations(final ArrayList<Message> messages) {
	final Builder mBuilder = new NotificationCompat.Builder(mXmppConnectionService);
	if (messages.size() >= 1) {
		final Conversation conversation = messages.get(0).getConversation();
		final UnreadConversation.Builder mUnreadBuilder = new UnreadConversation.Builder(conversation.getName());
		mBuilder.setLargeIcon(mXmppConnectionService.getAvatarService()
				.get(conversation, getPixel(64)));
		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;
			if ((message = getImage(messages)) != null) {
				modifyForImage(mBuilder, mUnreadBuilder, message, messages);
			} else {
				modifyForTextOnly(mBuilder, mUnreadBuilder, messages);
			}
			RemoteInput remoteInput = new RemoteInput.Builder("text_reply").setLabel(UIHelper.getMessageHint(mXmppConnectionService, conversation)).build();
			NotificationCompat.Action markReadAction = new NotificationCompat.Action.Builder(R.drawable.ic_send_text_offline, "Mark As Read", createReadPendingIntent(conversation)).build();
			NotificationCompat.Action replyAction = new NotificationCompat.Action.Builder(R.drawable.ic_send_text_offline, "Reply", createReplyIntent(conversation, false)).addRemoteInput(remoteInput).build();
			NotificationCompat.Action wearReplyAction = new NotificationCompat.Action.Builder(R.drawable.ic_wear_reply, "Reply", createReplyIntent(conversation, true)).addRemoteInput(remoteInput).build();
			mBuilder.extend(new NotificationCompat.WearableExtender().addAction(wearReplyAction));
			mUnreadBuilder.setReplyAction(createReplyIntent(conversation, true), remoteInput);
			mUnreadBuilder.setReadPendingIntent(createReadPendingIntent(conversation));
			mBuilder.extend(new NotificationCompat.CarExtender().setUnreadConversation(mUnreadBuilder.build()));
			if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
				mBuilder.addAction(markReadAction);
				mBuilder.addAction(replyAction);
			}
			if ((message = getFirstDownloadableMessage(messages)) != null) {
				mBuilder.addAction(
						Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ?
								R.drawable.ic_file_download_white_24dp : R.drawable.ic_action_download,
						mXmppConnectionService.getResources().getString(R.string.download_x_file,
								UIHelper.getFileDescriptionString(mXmppConnectionService, message)),
						createDownloadIntent(message)
				);
			}
			if ((message = getFirstLocationMessage(messages)) != null) {
				mBuilder.addAction(R.drawable.ic_room_white_24dp,
						mXmppConnectionService.getString(R.string.show_location),
						createShowLocationIntent(message));
			}
		}
		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;
}
 
Example 5
Project: Pix-Art-Messenger   File: NotificationService.java   View source code 4 votes vote down vote up
private Builder buildSingleConversations(final ArrayList<Message> messages) {
    final Builder mBuilder = new NotificationCompat.Builder(mXmppConnectionService);
    if (messages.size() >= 1) {
        final Conversation conversation = messages.get(0).getConversation();
        final UnreadConversation.Builder mUnreadBuilder = new UnreadConversation.Builder(conversation.getName());
        mBuilder.setLargeIcon(mXmppConnectionService.getAvatarService()
                .get(conversation, getPixel(64)));
        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;
            if ((message = getImage(messages)) != null) {
                modifyForImage(mBuilder, mUnreadBuilder, message, messages);
            } else {
                modifyForTextOnly(mBuilder, mUnreadBuilder, messages);
            }
            RemoteInput remoteInput = new RemoteInput.Builder("text_reply").setLabel(UIHelper.getMessageHint(mXmppConnectionService, conversation)).build();
            NotificationCompat.Action markReadAction = new NotificationCompat.Action.Builder(R.drawable.ic_send_text_offline, mXmppConnectionService.getResources().getString(R.string.mark_as_read), createReadPendingIntent(conversation)).build();
            NotificationCompat.Action replyAction = new NotificationCompat.Action.Builder(R.drawable.ic_send_text_offline, mXmppConnectionService.getResources().getString(R.string.reply), createReplyIntent(conversation, false)).addRemoteInput(remoteInput).build();
            NotificationCompat.Action wearReplyAction = new NotificationCompat.Action.Builder(R.drawable.ic_wear_reply, "Reply", createReplyIntent(conversation, true)).addRemoteInput(remoteInput).build();
            mBuilder.extend(new NotificationCompat.WearableExtender().addAction(wearReplyAction));
            mUnreadBuilder.setReplyAction(createReplyIntent(conversation, true), remoteInput);
            mUnreadBuilder.setReadPendingIntent(createReadPendingIntent(conversation));
            mBuilder.extend(new NotificationCompat.CarExtender().setUnreadConversation(mUnreadBuilder.build()));
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
                mBuilder.addAction(markReadAction);
                mBuilder.addAction(replyAction);
            }
            if ((message = getFirstDownloadableMessage(messages)) != null) {
                mBuilder.addAction(
                        Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ?
                                R.drawable.ic_file_download_white_24dp : R.drawable.ic_action_download,
                        mXmppConnectionService.getResources().getString(R.string.download_x_file,
                                UIHelper.getFileDescriptionString(mXmppConnectionService, message)),
                        createDownloadIntent(message)
                );
            }
            if ((message = getFirstLocationMessage(messages)) != null) {
                mBuilder.addAction(R.drawable.ic_room_white_24dp,
                        mXmppConnectionService.getString(R.string.show_location),
                        createShowLocationIntent(message));
            }
        }
        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;
}
 
Example 6
Project: io2015-codelabs   File: MessagingService.java   View source code 4 votes vote down vote up
private void sendNotificationForConversation(int conversationId,
                                             String sender, String message, long timestamp) {
    // A pending Intent for reads
    PendingIntent readPendingIntent = PendingIntent.getBroadcast(getApplicationContext(),
            conversationId,
            getMessageReadIntent(conversationId),
            PendingIntent.FLAG_UPDATE_CURRENT);

    /// Add the code to create the UnreadConversation

    // Build a RemoteInput for receiving voice input in a Car Notification
    RemoteInput remoteInput = new RemoteInput.Builder(EXTRA_VOICE_REPLY).build();

    // Building a Pending Intent for the reply action to trigger
    PendingIntent replyIntent = PendingIntent.getBroadcast(getApplicationContext(),
            conversationId,
            getMessageReplyIntent(conversationId),
            PendingIntent.FLAG_UPDATE_CURRENT);

    // Create the UnreadConversation and populate it with the participant name,
    // read and reply intents.
    UnreadConversation.Builder unreadConversationBuilder =
            new UnreadConversation.Builder(sender)
                    .setLatestTimestamp(timestamp)
                    .setReadPendingIntent(readPendingIntent)
                    .setReplyAction(replyIntent, remoteInput);

    // Note: Add messages from oldest to newest to the UnreadConversation.Builder
    // Since we are sending a single message here we simply add the message.
    // In a real world application there could be multiple messages which should be ordered
    // and added from oldest to newest.
    unreadConversationBuilder.addMessage(message);

    /// End create UnreadConversation

    NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplicationContext())
            .setSmallIcon(R.drawable.notification_icon)
            .setLargeIcon(BitmapFactory.decodeResource(
                    getApplicationContext().getResources(), R.drawable.android_contact))
            .setContentText(message)
            .setWhen(timestamp)
            .setContentTitle(sender)
            .setContentIntent(readPendingIntent)
            /// Extend the notification with CarExtender.
            .extend(new CarExtender()
                    .setUnreadConversation(unreadConversationBuilder.build()))
                    .setColor(getResources().getColor(R.color.default_color_light));
            /// End
            ;


    Log.d(TAG, "Sending notification "
            + conversationId + " conversation: " + message);

    NotificationManagerCompat.from(this)
            .notify(conversationId, builder.build());
}