Java Code Examples for android.support.v4.app.NotificationCompat.InboxStyle

The following are top voted examples for showing how to use android.support.v4.app.NotificationCompat.InboxStyle. 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: intellij-ce-playground   File: NotificationGenerator.java   View source code 5 votes vote down vote up
private static void generateStyle(NotificationCompat.Builder builder) {
    Integer styleValue = STYLE.getValueInt();

    if (STYLE_BIG_PICTURE.equals(styleValue)) {
        BigPictureStyle bigPicture = new NotificationCompat.BigPictureStyle();
        if (PICTURE.hasValue())
            bigPicture.bigPicture(PICTURE.getValueBitmap());
        if (BIG_CONTENT_TITLE.hasValue())
            bigPicture.setBigContentTitle(BIG_CONTENT_TITLE.getValueString());
        if (SUMMARY_TEXT.hasValue())
            bigPicture.setSummaryText(SUMMARY_TEXT.getValueString());
        builder.setStyle(bigPicture);
    } else if (STYLE_BIG_TEXT.equals(styleValue)) {
        BigTextStyle bigText = new NotificationCompat.BigTextStyle();
        if (BIG_TEXT.hasValue())
            bigText.bigText(BIG_TEXT.getValueString());
        if (BIG_CONTENT_TITLE.hasValue())
            bigText.setBigContentTitle(BIG_CONTENT_TITLE.getValueString());
        if (SUMMARY_TEXT.hasValue())
            bigText.setSummaryText(SUMMARY_TEXT.getValueString());
        builder.setStyle(bigText);
    } else if (STYLE_INBOX.equals(styleValue)) {
        InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
        if (LINES.hasValue()) {
            for (String line : LINES.getValueString().split("\\n")) {
                inboxStyle.addLine(line);
            }
        }
        if (BIG_CONTENT_TITLE.hasValue())
            inboxStyle.setBigContentTitle(BIG_CONTENT_TITLE.getValueString());
        if (SUMMARY_TEXT.hasValue())
            inboxStyle.setSummaryText(SUMMARY_TEXT.getValueString());
        builder.setStyle(inboxStyle);
    }
}
 
Example 2
Project: BioStar2Android   File: GcmBroadcastReceiver.java   View source code 5 votes vote down vote up
private void Notification(PushNotification noti, Context context) {
        NotificationDBProvider dbProvider = NotificationDBProvider.getInstance(context);
        PendingIntent pendingIntent = getPendingIntent(context, DummyActivity.class);

        ArrayList<String> messages = dbProvider.getUnReadMessageTitle6();
        int count = dbProvider.getUnReadMessageCount();
        Builder builder = new NotificationCompat.Builder(context);
        if (count > 1) {
            if (count > 9999) {
                builder.setContentTitle("9999+" + context.getString(R.string.new_notification));
            } else {
                builder.setContentTitle(String.valueOf(count) + context.getString(R.string.new_notification));
            }
            InboxStyle style = new InboxStyle(builder);
            if (count > messages.size()) {
                count = messages.size();
            }
            for (int i = 0; i < count; i++) {
                style.addLine(messages.get(i));
            }
//			style.setSummaryText("+ more");
            builder.setStyle(style);
        } else {
            builder.setContentTitle(noti.title);
            builder.setContentText(noti.message);
        }
        commonBuilder(builder, pendingIntent, noti.message);
        NotificationManager notifyManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        notifyManager.notify(0, builder.build());

        Intent intentBoradCast = new Intent(Setting.BROADCAST_ALARM_UPDATE);
        LocalBroadcastManager.getInstance(context).sendBroadcast(intentBoradCast);
    }
 
Example 3
Project: nevolution   File: StackDecorator.java   View source code 5 votes vote down vote up
private RemoteViews buildBigContentView(final String pkg, final CharSequence title, final List<CharSequence> lines) {
//		final Bitmap large_icon = evolved_extras.getParcelable(NotificationCompat.EXTRA_LARGE_ICON);
		Context context; try { context = createPackageContext(pkg, 0); }	// This ensure the correct display of the small icon
		catch (final PackageManager.NameNotFoundException e) { context = this; }
		final Builder builder = new Builder(context)/*.setSmallIcon(evolved_n.icon).setLargeIcon(large_icon)*/;
		final InboxStyle inbox = new NotificationCompat.InboxStyle(builder).setBigContentTitle(title);
		for (final CharSequence line : lines) inbox.addLine(line);

		return inbox.build().bigContentView;
	}
 
Example 4
Project: Klyph   File: KlyphNotification.java   View source code 5 votes vote down vote up
public static void setInboxStyle(Builder builder, String title, List<String> lines)
{
	builder.setNumber(lines.size());
	InboxStyle inboxStyle = new InboxStyle();

	inboxStyle.setBigContentTitle(title);

	for (String line : lines)
	{
		inboxStyle.addLine(line);
	}

	builder.setStyle(inboxStyle);
}
 
Example 5
Project: KlyphMessenger   File: KlyphMessengerNotification.java   View source code 5 votes vote down vote up
public static void setInboxStyle(Builder builder, String title, List<String> lines)
{
	builder.setNumber(lines.size());
	InboxStyle inboxStyle = new InboxStyle();

	inboxStyle.setBigContentTitle(title);

	for (String line : lines)
	{
		inboxStyle.addLine(line);
	}

	builder.setStyle(inboxStyle);
}
 
Example 6
Project: moVirt   File: NotificationHelper.java   View source code 5 votes vote down vote up
public <E extends BaseEntity<?>> void showTriggersNotification(
        MovirtAccount account, List<Pair<E, Trigger>> entitiesAndTriggers, Context context, PendingIntent resultPendingIntent
) {
    Log.d(TAG, "Displaying notification " + notificationCount);
    if (entitiesAndTriggers.size() == 1) { // one entity displays in full format
        Pair<E, Trigger> entityAndTrigger = entitiesAndTriggers.get(0);
        showTriggerNotification(account, entityAndTrigger.second, entityAndTrigger.first, context, resultPendingIntent);
        return;
    }

    boolean critical = false;
    InboxStyle style = new NotificationCompat.InboxStyle();

    for (int i = 0; i < entitiesAndTriggers.size(); i++) {
        Pair<E, Trigger> pair = entitiesAndTriggers.get(i);

        if (!critical && pair.second.getNotificationType() == Trigger.NotificationType.CRITICAL) {
            critical = true;
        }

        if (i < maxDisplayedNotifications) {
            style.addLine(pair.second.getCondition().getMessage(context, pair.first));
        }
    }

    if (entitiesAndTriggers.size() > maxDisplayedNotifications) {
        style.addLine("."); // dummy line to show dots
        style.setSummaryText("+ " + (entitiesAndTriggers.size() - maxDisplayedNotifications) + " more");
    }

    Notification notification = prepareNotification(context, resultPendingIntent, System.currentTimeMillis(), getEventTitle(account, critical))
            .setStyle(style)
            .build();
    notificationManager.notify(notificationCount++, notification);
    if (critical) {
        vibrator.vibrate(vibrationDuration);
    }
}
 
Example 7
Project: Onosendai   File: Notifications.java   View source code 5 votes vote down vote up
private static Style makePreview (final List<Tweet> tweets, final int count) {
	if (tweets == null || tweets.size() < 1) return null;

	if (tweets.size() == 1) return new NotificationCompat.BigTextStyle()
			.bigText(tweetToSpanable(tweets.iterator().next()));

	final InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
	for (final Tweet tweet : tweets) {
		inboxStyle.addLine(tweetToSpanable(tweet));
	}
	if (tweets.size() < count) {
		inboxStyle.setSummaryText(String.format("+%s more", count - tweets.size()));
	}
	return inboxStyle;
}
 
Example 8
Project: q-mail   File: DeviceNotifications.java   View source code 4 votes vote down vote up
protected InboxStyle createInboxStyle(Builder builder) {
    return new InboxStyle(builder);
}
 
Example 9
Project: q-mail   File: DeviceNotificationsTest.java   View source code 4 votes vote down vote up
@Override
protected InboxStyle createInboxStyle(Builder builder) {
    return inboxStyle;
}
 
Example 10
Project: K9-MailClient   File: DeviceNotifications.java   View source code 4 votes vote down vote up
protected InboxStyle createInboxStyle(Builder builder) {
    return new InboxStyle(builder);
}
 
Example 11
Project: K9-MailClient   File: DeviceNotificationsTest.java   View source code 4 votes vote down vote up
@Override
protected InboxStyle createInboxStyle(Builder builder) {
    return inboxStyle;
}
 
Example 12
Project: TextSecure   File: MessageNotifier.java   View source code 4 votes vote down vote up
private static void sendMultipleThreadNotification(Context context,
                                                   MasterSecret masterSecret,
                                                   NotificationState notificationState,
                                                   boolean signal)
{
  List<NotificationItem> notifications = notificationState.getNotifications();
  NotificationCompat.Builder builder   = new NotificationCompat.Builder(context);

  builder.setSmallIcon(R.drawable.icon_notification);
  builder.setLargeIcon(BitmapFactory.decodeResource(context.getResources(),
                                                    R.drawable.icon_notification));
  builder.setContentTitle(String.format(context.getString(R.string.MessageNotifier_d_new_messages),
                                        notificationState.getMessageCount()));
  builder.setContentText(String.format(context.getString(R.string.MessageNotifier_most_recent_from_s),
                                       notifications.get(0).getIndividualRecipientName()));
  builder.setContentIntent(PendingIntent.getActivity(context, 0, new Intent(context, RoutingActivity.class), 0));
  
  builder.setContentInfo(String.valueOf(notificationState.getMessageCount()));
  builder.setNumber(notificationState.getMessageCount());

  builder.setDeleteIntent(PendingIntent.getBroadcast(context, 0, new Intent(DeleteReceiver.DELETE_REMINDER_ACTION), 0));

  if (masterSecret != null) {
    builder.addAction(R.drawable.check, context.getString(R.string.MessageNotifier_mark_all_as_read),
                      notificationState.getMarkAsReadIntent(context, masterSecret));
  }

  InboxStyle style = new InboxStyle();

  ListIterator<NotificationItem> iterator = notifications.listIterator(notifications.size());
  while(iterator.hasPrevious()) {
    NotificationItem item = iterator.previous();
    style.addLine(item.getTickerText());
  }

  builder.setStyle(style);

  setNotificationAlarms(context, builder, signal);

  if (signal) {
    builder.setTicker(notifications.get(0).getTickerText());
  }

  ((NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE))
    .notify(NOTIFICATION_ID, builder.build());
}
 
Example 13
Project: TextSecureSMP   File: MessageNotifier.java   View source code 4 votes vote down vote up
private static void sendMultipleThreadNotification(Context context,
                                                   MasterSecret masterSecret,
                                                   NotificationState notificationState,
                                                   boolean signal)
{
  List<NotificationItem> notifications = notificationState.getNotifications();
  NotificationCompat.Builder builder   = new NotificationCompat.Builder(context);

  builder.setColor(context.getResources().getColor(R.color.textsecure_primary));
  builder.setSmallIcon(R.drawable.icon_notification);
  builder.setContentTitle(context.getString(R.string.app_name));
  builder.setSubText(context.getString(R.string.MessageNotifier_d_messages_in_d_conversations,
                                       notificationState.getMessageCount(),
                                       notificationState.getThreadCount()));
  builder.setContentText(context.getString(R.string.MessageNotifier_most_recent_from_s,
                                           notifications.get(0).getIndividualRecipientName()));
  builder.setContentIntent(PendingIntent.getActivity(context, 0, new Intent(context, ConversationListActivity.class), 0));
  
  builder.setContentInfo(String.valueOf(notificationState.getMessageCount()));
  builder.setNumber(notificationState.getMessageCount());
  builder.setCategory(NotificationCompat.CATEGORY_MESSAGE);

  long timestamp = notifications.get(0).getTimestamp();
  if (timestamp != 0) builder.setWhen(timestamp);

  builder.setDeleteIntent(PendingIntent.getBroadcast(context, 0, new Intent(DeleteReceiver.DELETE_REMINDER_ACTION), 0));

  if (masterSecret != null) {
     Action markAllAsReadAction = new Action(R.drawable.check,
                                             context.getString(R.string.MessageNotifier_mark_all_as_read),
                                             notificationState.getMarkAsReadIntent(context, masterSecret));
     builder.addAction(markAllAsReadAction);
     builder.extend(new NotificationCompat.WearableExtender().addAction(markAllAsReadAction));
  }

  InboxStyle style = new InboxStyle();

  ListIterator<NotificationItem> iterator = notifications.listIterator(notifications.size());
  while(iterator.hasPrevious()) {
    NotificationItem item = iterator.previous();
    style.addLine(item.getTickerText());
    if (item.getIndividualRecipient().getContactUri() != null) {
      builder.addPerson(item.getIndividualRecipient().getContactUri().toString());
    }
  }

  builder.setStyle(style);

  setNotificationAlarms(context, builder, signal,
                        notificationState.getRingtone(),
                        notificationState.getVibrate());

  if (signal) {
    builder.setTicker(notifications.get(0).getTickerText());
  }

  ((NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE))
    .notify(NOTIFICATION_ID, builder.build());
}
 
Example 14
Project: Securecom-Messaging   File: MessageNotifier.java   View source code 4 votes vote down vote up
private static void sendMultipleThreadNotification(Context context,
                                                   MasterSecret masterSecret,
                                                   NotificationState notificationState,
                                                   boolean signal)
{
  List<NotificationItem> notifications = notificationState.getNotifications();
  NotificationCompat.Builder builder   = new NotificationCompat.Builder(context);

  builder.setSmallIcon(R.drawable.icon_notification);
  builder.setLargeIcon(BitmapFactory.decodeResource(context.getResources(),
                                                    R.drawable.icon_notification));
  builder.setContentTitle(String.format(context.getString(R.string.MessageNotifier_d_new_messages),
                                        notificationState.getMessageCount()));
  builder.setContentText(String.format(context.getString(R.string.MessageNotifier_most_recent_from_s),
                                       notifications.get(0).getIndividualRecipientName()));
  builder.setContentIntent(PendingIntent.getActivity(context, 0, new Intent(context, RoutingActivity.class), 0));
  
  builder.setContentInfo(String.valueOf(notificationState.getMessageCount()));
  builder.setNumber(notificationState.getMessageCount());

  if (masterSecret != null) {
    builder.addAction(R.drawable.check, context.getString(R.string.MessageNotifier_mark_all_as_read),
                      notificationState.getMarkAsReadIntent(context, masterSecret));
  }

  InboxStyle style = new InboxStyle();

  for (NotificationItem item : notifications) {
    style.addLine(item.getTickerText());
  }

  builder.setStyle(style);

  setNotificationAlarms(context, builder, signal);

  if (signal) {
    builder.setTicker(notifications.get(0).getTickerText());
  }

  ((NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE))
    .notify(NOTIFICATION_ID, builder.build());
}
 
Example 15
Project: Securecom-Text   File: MessageNotifier.java   View source code 4 votes vote down vote up
private static void sendMultipleThreadNotification(Context context,
                                                   MasterSecret masterSecret,
                                                   NotificationState notificationState,
                                                   boolean signal)
{
  List<NotificationItem> notifications = notificationState.getNotifications();
  NotificationCompat.Builder builder   = new NotificationCompat.Builder(context);

  builder.setSmallIcon(R.drawable.icon_notification);
  builder.setLargeIcon(BitmapFactory.decodeResource(context.getResources(),
                                                    R.drawable.icon_notification));
  builder.setContentTitle(String.format(context.getString(R.string.MessageNotifier_d_new_messages),
                                        notificationState.getMessageCount()));
  builder.setContentText(String.format(context.getString(R.string.MessageNotifier_most_recent_from_s),
                                       notifications.get(0).getIndividualRecipientName()));
  builder.setContentIntent(PendingIntent.getActivity(context, 0, new Intent(context, RoutingActivity.class), 0));
  
  builder.setContentInfo(String.valueOf(notificationState.getMessageCount()));
  builder.setNumber(notificationState.getMessageCount());

  if (masterSecret != null) {
    builder.addAction(R.drawable.check, context.getString(R.string.MessageNotifier_mark_all_as_read),
                      notificationState.getMarkAsReadIntent(context, masterSecret));
  }

  InboxStyle style = new InboxStyle();

  for (NotificationItem item : notifications) {
    style.addLine(item.getTickerText());
  }

  builder.setStyle(style);

  setNotificationAlarms(context, builder, signal);

  if (signal) {
    builder.setTicker(notifications.get(0).getTickerText());
  }

  ((NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE))
    .notify(NOTIFICATION_ID, builder.build());
}