Search in sources :

Example 86 with Builder

use of android.support.v4.app.NotificationCompat.Builder in project meatspace-android by RomainPiel.

the class ChatService method showForeground.

/**
 * place service in foreground or update its notification
 */
private void showForeground() {
    Intent openIntent = new Intent(this, MainActivity.class);
    openIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent pi = PendingIntent.getActivity(this, 0, openIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
    String description;
    if (appInBackground && missedMessageCount > 0) {
        description = getResources().getQuantityString(R.plurals.service_chat_running_description_missed_messages_, missedMessageCount, missedMessageCount);
        if (PreferencesHelper.areNotificationsEnabled(this)) {
            String lastMessage = chatList.get().last().getValue().getMessage();
            builder.setTicker(lastMessage);
        }
    } else {
        description = getString(R.string.service_chat_running_description);
    }
    RemoteViews notificationView = new RemoteViews(this.getPackageName(), R.layout.notification_template);
    notificationView.setTextViewText(R.id.notification_template_title, getString(R.string.service_chat_running));
    notificationView.setTextViewText(R.id.notification_template_text2, description);
    notificationView.setOnClickPendingIntent(R.id.notification_template_cancel, PendingIntent.getBroadcast(this, 0, new Intent(Constants.FILTER_CHAT_CLOSE), 0));
    Notification notification = builder.setContentIntent(pi).setSmallIcon(R.drawable.ic_stat_meatspace).setContent(notificationView).build();
    notification.flags |= Notification.FLAG_NO_CLEAR;
    startForeground(Constants.NOTIFICICATION_ID_CHAT, notification);
}
Also used : RemoteViews(android.widget.RemoteViews) NotificationCompat(android.support.v4.app.NotificationCompat) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent) Notification(android.app.Notification)

Example 87 with Builder

use of android.support.v4.app.NotificationCompat.Builder in project k-9 by k9mail.

the class AuthenticationErrorNotifications method showAuthenticationErrorNotification.

public void showAuthenticationErrorNotification(Account account, boolean incoming) {
    int notificationId = NotificationIds.getAuthenticationErrorNotificationId(account, incoming);
    Context context = controller.getContext();
    PendingIntent editServerSettingsPendingIntent = createContentIntent(context, account, incoming);
    String title = context.getString(R.string.notification_authentication_error_title);
    String text = context.getString(R.string.notification_authentication_error_text, account.getDescription());
    NotificationCompat.Builder builder = controller.createNotificationBuilder().setSmallIcon(R.drawable.notification_icon_warning).setWhen(System.currentTimeMillis()).setAutoCancel(true).setTicker(title).setContentTitle(title).setContentText(text).setContentIntent(editServerSettingsPendingIntent).setStyle(new BigTextStyle().bigText(text)).setVisibility(NotificationCompat.VISIBILITY_PUBLIC).setCategory(NotificationCompat.CATEGORY_ERROR);
    controller.configureNotification(builder, null, null, NOTIFICATION_LED_FAILURE_COLOR, NOTIFICATION_LED_BLINK_FAST, true);
    getNotificationManager().notify(notificationId, builder.build());
}
Also used : Context(android.content.Context) BigTextStyle(android.support.v4.app.NotificationCompat.BigTextStyle) NotificationCompat(android.support.v4.app.NotificationCompat) PendingIntent(android.app.PendingIntent)

Example 88 with Builder

use of android.support.v4.app.NotificationCompat.Builder in project k-9 by k9mail.

the class CertificateErrorNotifications method showCertificateErrorNotification.

public void showCertificateErrorNotification(Account account, boolean incoming) {
    int notificationId = NotificationIds.getCertificateErrorNotificationId(account, incoming);
    Context context = controller.getContext();
    PendingIntent editServerSettingsPendingIntent = createContentIntent(context, account, incoming);
    String title = context.getString(R.string.notification_certificate_error_title, account.getDescription());
    String text = context.getString(R.string.notification_certificate_error_text);
    NotificationCompat.Builder builder = controller.createNotificationBuilder().setSmallIcon(getCertificateErrorNotificationIcon()).setWhen(System.currentTimeMillis()).setAutoCancel(true).setTicker(title).setContentTitle(title).setContentText(text).setContentIntent(editServerSettingsPendingIntent).setVisibility(NotificationCompat.VISIBILITY_PUBLIC).setCategory(NotificationCompat.CATEGORY_ERROR);
    controller.configureNotification(builder, null, null, NOTIFICATION_LED_FAILURE_COLOR, NOTIFICATION_LED_BLINK_FAST, true);
    getNotificationManager().notify(notificationId, builder.build());
}
Also used : Context(android.content.Context) NotificationCompat(android.support.v4.app.NotificationCompat) PendingIntent(android.app.PendingIntent)

Example 89 with Builder

use of android.support.v4.app.NotificationCompat.Builder in project k-9 by k9mail.

the class DeviceNotifications method buildSummaryNotification.

public Notification buildSummaryNotification(Account account, NotificationData notificationData, boolean silent) {
    int unreadMessageCount = notificationData.getUnreadMessageCount();
    NotificationCompat.Builder builder;
    if (isPrivacyModeActive() || !platformSupportsExtendedNotifications()) {
        builder = createSimpleSummaryNotification(account, unreadMessageCount);
    } else if (notificationData.isSingleMessageNotification()) {
        NotificationHolder holder = notificationData.getHolderForLatestNotification();
        builder = createBigTextStyleSummaryNotification(account, holder);
    } else {
        builder = createInboxStyleSummaryNotification(account, notificationData, unreadMessageCount);
    }
    if (notificationData.containsStarredMessages()) {
        builder.setPriority(NotificationCompat.PRIORITY_HIGH);
    }
    int notificationId = NotificationIds.getNewMailSummaryNotificationId(account);
    PendingIntent deletePendingIntent = actionCreator.createDismissAllMessagesPendingIntent(account, notificationId);
    builder.setDeleteIntent(deletePendingIntent);
    lockScreenNotification.configureLockScreenNotification(builder, notificationData);
    boolean ringAndVibrate = false;
    if (!silent && !account.isRingNotified()) {
        account.setRingNotified(true);
        ringAndVibrate = true;
    }
    NotificationSetting notificationSetting = account.getNotificationSetting();
    controller.configureNotification(builder, (notificationSetting.shouldRing()) ? notificationSetting.getRingtone() : null, (notificationSetting.shouldVibrate()) ? notificationSetting.getVibration() : null, (notificationSetting.isLed()) ? notificationSetting.getLedColor() : null, NOTIFICATION_LED_BLINK_SLOW, ringAndVibrate);
    return builder.build();
}
Also used : Builder(android.support.v4.app.NotificationCompat.Builder) NotificationCompat(android.support.v4.app.NotificationCompat) NotificationSetting(com.fsck.k9.NotificationSetting) PendingIntent(android.app.PendingIntent)

Example 90 with Builder

use of android.support.v4.app.NotificationCompat.Builder in project k-9 by k9mail.

the class LockScreenNotification method createPublicNotificationWithSenderList.

private Notification createPublicNotificationWithSenderList(NotificationData notificationData) {
    Builder builder = createPublicNotification(notificationData);
    int newMessages = notificationData.getNewMessagesCount();
    if (newMessages == 1) {
        NotificationHolder holder = notificationData.getHolderForLatestNotification();
        builder.setContentText(holder.content.sender);
    } else {
        List<NotificationContent> contents = notificationData.getContentForSummaryNotification();
        String senderList = createCommaSeparatedListOfSenders(contents);
        builder.setContentText(senderList);
    }
    return builder.build();
}
Also used : Builder(android.support.v4.app.NotificationCompat.Builder)

Aggregations

NotificationCompat (android.support.v4.app.NotificationCompat)109 PendingIntent (android.app.PendingIntent)89 Intent (android.content.Intent)82 NotificationManager (android.app.NotificationManager)36 Notification (android.app.Notification)31 Builder (android.support.v4.app.NotificationCompat.Builder)19 Context (android.content.Context)18 TaskStackBuilder (android.support.v4.app.TaskStackBuilder)15 Uri (android.net.Uri)14 Bundle (android.os.Bundle)13 View (android.view.View)13 TextView (android.widget.TextView)11 Bitmap (android.graphics.Bitmap)10 IOException (java.io.IOException)10 RemoteViews (android.widget.RemoteViews)9 ArrayList (java.util.ArrayList)9 AlertDialog (android.app.AlertDialog)8 DialogInterface (android.content.DialogInterface)7 Dialog (android.app.Dialog)6 Paint (android.graphics.Paint)6