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

The following examples show how to use android.support.v4.app.NotificationCompat#InboxStyle . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NotificationUtils.java    From LNMOnlineAndroidSample with Apache License 2.0 6 votes vote down vote up
private void showSmallNotification(NotificationCompat.Builder mBuilder, int icon, String title, String message, String timeStamp, PendingIntent resultPendingIntent, Uri alarmSound) {

        NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();

        inboxStyle.addLine(message);

        Notification notification;
        notification = mBuilder.setSmallIcon(icon).setTicker(title).setWhen(0)
                .setAutoCancel(true)
                .setContentTitle(title)
                .setContentIntent(resultPendingIntent)
                .setSound(alarmSound)
                .setStyle(inboxStyle)
                .setWhen(getTimeMilliSec(timeStamp))
                .setSmallIcon(R.mipmap.ic_launcher)
                .setLargeIcon(BitmapFactory.decodeResource(mContext.getResources(), icon))
                .setContentText(message)
                .build();

        NotificationManager notificationManager = (NotificationManager) mContext.getSystemService(NOTIFICATION_SERVICE);
        notificationManager.notify(NOTIFICATION_ID, notification);
    }
 
Example 2
Source File: AbstractNotificationCheckReceiver.java    From SteamGifts with MIT License 6 votes vote down vote up
/**
 * Display a notification for multiple items.
 *
 * @param context        receiver context
 * @param notificationId the notification id to replace (should be unique per class)
 * @param iconResource   icon to display along with the notification
 * @param title          title
 * @param content        texts to display in the notification
 * @param viewIntent     what happens when clicking the notification
 * @param deleteIntent   what happens when dismissing the notification
 */

protected static void showNotification(Context context, NotificationId notificationId, @DrawableRes int iconResource, String title, List<CharSequence> content, PendingIntent viewIntent, PendingIntent deleteIntent) {
    NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
    for (CharSequence c : content)
        inboxStyle.addLine(c);

    Notification notification = new NotificationCompat.Builder(context)
            .setSmallIcon(iconResource)
            .setPriority(NotificationCompat.PRIORITY_LOW)
            .setCategory(NotificationCompat.CATEGORY_SOCIAL)
            .setContentTitle(title)
            .setContentText(content.get(0))
            .setStyle(inboxStyle) /* 4.1+ */
            .setNumber(SteamGiftsUserData.getCurrent(context).getMessageNotification())
            .setContentIntent(viewIntent)
            .setDeleteIntent(deleteIntent)
            .setAutoCancel(true)
            .build();

    showNotification(context, notificationId, notification);
}
 
Example 3
Source File: TabsTrackerService.java    From Overchan-Android with GNU General Public License v3.0 6 votes vote down vote up
private Notification getSubscriptionsNotification() {
    if (!subscriptions) return null;
    subscriptions = false;
    List<Triple<String, String, String>> list = subscriptionsData;
    if (list == null || list.size() == 0) return null;
    String url = list.get(0).getMiddle();
    Intent activityIntent = new Intent(TabsTrackerService.this, MainActivity.class).putExtra(EXTRA_CLEAR_SUBSCRIPTIONS, true);
    if (url != null) activityIntent.setData(Uri.parse(url));
    NotificationCompat.InboxStyle style = list.size() == 1 ? null : new NotificationCompat.InboxStyle().
            addLine(getString(R.string.subscriptions_notification_text_format, list.get(0).getRight())).
            addLine(getString(R.string.subscriptions_notification_text_format, list.get(1).getRight()));
    if (list.size() > 2) style.setSummaryText(getString(R.string.subscriptions_notification_text_more, list.size() - 2));
    
    return notifSubscription.
            setContentText(list.size() > 1 ?
                    getString(R.string.subscriptions_notification_text_multiple) :
                        getString(R.string.subscriptions_notification_text_format, list.get(0).getRight())).
            setStyle(style).
            setContentIntent(PendingIntent.getActivity(TabsTrackerService.this, 0, activityIntent, PendingIntent.FLAG_CANCEL_CURRENT)).
            build();
}
 
Example 4
Source File: NotificationPresets.java    From AndroidWearable-Samples with Apache License 2.0 6 votes vote down vote up
@Override
public Notification[] buildNotifications(Context context, BuildOptions options) {
    NotificationCompat.InboxStyle style = new NotificationCompat.InboxStyle();
    style.addLine(context.getString(R.string.inbox_style_example_line1));
    style.addLine(context.getString(R.string.inbox_style_example_line2));
    style.addLine(context.getString(R.string.inbox_style_example_line3));
    style.setBigContentTitle(context.getString(R.string.inbox_style_example_title));
    style.setSummaryText(context.getString(R.string.inbox_style_example_summary_text));

    NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
            .setStyle(style);
    NotificationCompat.WearableExtender wearableOptions =
            new NotificationCompat.WearableExtender();
    applyBasicOptions(context, builder, wearableOptions, options);
    builder.extend(wearableOptions);
    return new Notification[] { builder.build() };
}
 
Example 5
Source File: NotificationHelper.java    From moVirt with Apache License 2.0 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 6
Source File: NearbyBackgroundService.java    From Android-nRF-Beacon-for-Eddystone with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void createNotification() {
    //mNearbyDevicesMessageList = loadNearbyMessageListForNotification();
    NotificationManager notificationManager =
            (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    if(mNearbyDevicesMessageList.size() == 0){
        notificationManager.cancelAll();
        return;

    }
    Intent intent = new Intent(getApplicationContext(), MainActivity.class);
    intent.putExtra(Utils.NEARBY_DEVICE_DATA, mNearbyDevicesMessageList);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    PendingIntent pendingIntent = PendingIntent.getActivities(getApplicationContext(), OPEN_ACTIVITY_REQ, new Intent[]{intent}, PendingIntent.FLAG_UPDATE_CURRENT);

    NotificationCompat.Builder mBuilder =
            new NotificationCompat.Builder(getApplicationContext())
                    .setSmallIcon(R.drawable.ic_eddystone)
                    .setColor(ContextCompat.getColor(getApplicationContext(), R.color.actionBarColor))
                    .setContentTitle(getString(R.string.app_name))
                    .setContentIntent(pendingIntent);

    if(mNearbyDevicesMessageList.size() == 1) {
        mBuilder.setContentText(new String(mNearbyDevicesMessageList.get(0).getContent(), Charset.forName("UTF-8")));
    } else {
        NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
        inboxStyle.setBigContentTitle(getString(R.string.app_name));
        inboxStyle.setSummaryText(mNearbyDevicesMessageList.size() + " beacons found");
        mBuilder.setContentText(mNearbyDevicesMessageList.size() + " beacons found");
        for (int i = 0; i < mNearbyDevicesMessageList.size(); i++) {
            inboxStyle.addLine(new String(mNearbyDevicesMessageList.get(i).getContent(), Charset.forName("UTF-8")));
        }
        mBuilder.setStyle(inboxStyle);
    }

    notificationManager.notify(NOTIFICATION_ID, mBuilder.build());
}
 
Example 7
Source File: BeaconsFragment.java    From Android-nRF-Beacon-for-Eddystone with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void createNotification() {

        if(mNearbyDevicesMessageList.size() == 0){
            mNotificationManager.cancelAll();
            return;
        }

        final ArrayList<Message> nearbyMessageList = loadNearbyMessageListForNotification();
        mParentIntent.putExtra(NEARBY_DEVICE_DATA, nearbyMessageList);
        mParentIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        mPendingIntent = PendingIntent.getActivities(getActivity(), OPEN_ACTIVITY_REQ, new Intent[]{mParentIntent}, PendingIntent.FLAG_UPDATE_CURRENT);

        NotificationCompat.Builder mBuilder =
                new NotificationCompat.Builder(getActivity())
                        .setSmallIcon(R.drawable.ic_eddystone)
                        .setColor(ContextCompat.getColor(getActivity(), R.color.actionBarColor))
                        .setContentTitle(getString(R.string.app_name))
                        .setContentIntent(mPendingIntent);

        if(mNearbyDevicesMessageList.size() == 1) {
            mBuilder.setContentText(new String(mNearbyDevicesMessageList.get(0).getContent(), Charset.forName("UTF-8")));
        } else {
            NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
            inboxStyle.setBigContentTitle(getString(R.string.app_name));
            inboxStyle.setSummaryText(mNearbyDevicesMessageList.size() + " beacons found");
            mBuilder.setContentText(mNearbyDevicesMessageList.size() + " beacons found");
            for (int i = 0; i < mNearbyDevicesMessageList.size(); i++) {
                inboxStyle.addLine(new String(mNearbyDevicesMessageList.get(i).getContent(), Charset.forName("UTF-8")));
            }
            mBuilder.setStyle(inboxStyle);
        }
        mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
    }
 
Example 8
Source File: PlumbleMessageNotification.java    From Plumble with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Shows the notification with the provided message.
 * If the notification is already shown, append the message to the existing notification.
 * @param message The message to notify the user about.
 */
public void show(IMessage message) {
    mUnreadMessages.add(message);

    NotificationCompat.InboxStyle style = new NotificationCompat.InboxStyle();
    style.setBigContentTitle(mContext.getString(R.string.notification_unread_many, mUnreadMessages.size()));
    for (IMessage m : mUnreadMessages) {
        String line = mContext.getString(R.string.notification_message, m.getActorName(), m.getMessage());
        style.addLine(line);
    }

    Intent channelListIntent = new Intent(mContext, PlumbleActivity.class);
    channelListIntent.putExtra(PlumbleActivity.EXTRA_DRAWER_FRAGMENT, DrawerAdapter.ITEM_SERVER);
    // FLAG_CANCEL_CURRENT ensures that the extra always gets sent.
    PendingIntent pendingIntent = PendingIntent.getActivity(mContext, 0, channelListIntent, PendingIntent.FLAG_CANCEL_CURRENT);

    NotificationCompat.Builder builder = new NotificationCompat.Builder(mContext)
            .setPriority(NotificationCompat.PRIORITY_HIGH)
            .setSmallIcon(R.drawable.ic_stat_notify)
            .setContentIntent(pendingIntent)
            .setAutoCancel(true)
            .setTicker(message.getActorName())
            .setContentTitle(message.getActorName())
            .setContentText(message.getMessage())
            .setVibrate(VIBRATION_PATTERN)
            .setStyle(style);

    if (mUnreadMessages.size() > 0)
        builder.setNumber(mUnreadMessages.size());

    final NotificationManagerCompat manager = NotificationManagerCompat.from(mContext);
    Notification notification = builder.build();
    manager.notify(NOTIFICATION_ID, notification);
}
 
Example 9
Source File: NotificationFactory.java    From RxGpsService with Apache License 2.0 5 votes vote down vote up
Notification getNotificationServiceStarted(long seconds, long distance) {
  boolean showGroup = false;
  NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
  String timeFormatted = utilities.getTimeFormatted(seconds);
  String distanceFormatted = utilities.getDistanceFormatted(distance);

  if (!TextUtils.isEmpty(rxGpsServiceExtras.bigContentTitle())) {
    inboxStyle.setBigContentTitle(rxGpsServiceExtras.bigContentTitle());
  }

  if (rxGpsServiceExtras.showTime()) {
    showGroup = true;
    timeFormatted = TextUtils.isEmpty(rxGpsServiceExtras.timeText()) ? timeFormatted
        : rxGpsServiceExtras.timeText().replace("%1$s", timeFormatted);
    inboxStyle.addLine(timeFormatted);
  }

  if (rxGpsServiceExtras.showDistance()) {
    showGroup = true;
    distanceFormatted = TextUtils.isEmpty(rxGpsServiceExtras.distanceText()) ? distanceFormatted
        : rxGpsServiceExtras.distanceText().replace("%1$s", distanceFormatted);
    inboxStyle.addLine(distanceFormatted);
  }

  if (showGroup) {
    builderServiceStarted.setPriority(NotificationCompat.PRIORITY_MAX);
    builderServiceStarted.setOngoing(true);
    builderServiceStarted.setAutoCancel(false);
    builderServiceStarted.setStyle(inboxStyle);
    builderServiceStarted.setGroupSummary(true);
    builderServiceStarted.setGroup(rxGpsServiceExtras.notificationGroupServiceStarted());
  }

  return builderServiceStarted.build();
}
 
Example 10
Source File: NotificationFactory.java    From sana.mobile with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private NotificationFactory(Context context) {
    mContext = context;
    mBuilder = new NotificationCompat.Builder(mContext)
            .setSmallIcon(R.drawable.ic_notification);
    NotificationCompat.InboxStyle style =
            new NotificationCompat.InboxStyle();
    mBuilder.setStyle(style);
    mNotificationManager =
            (NotificationManager) mContext.getSystemService(Context.NOTIFICATION_SERVICE);
}
 
Example 11
Source File: Notifications.java    From Onosendai with Apache License 2.0 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 12
Source File: MultipleRecipientNotificationBuilder.java    From Silence with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Notification build() {
  if (privacy.isDisplayMessage() || privacy.isDisplayContact()) {
    NotificationCompat.InboxStyle style = new NotificationCompat.InboxStyle();

    for (CharSequence body : messageBodies) {
      style.addLine(body);
    }

    setStyle(style);
  }

  return super.build();
}
 
Example 13
Source File: AndroidNotifications.java    From actor-platform with GNU Affero General Public License v3.0 5 votes vote down vote up
private android.app.Notification buildSingleConversationNotification(NotificationCompat.Builder builder, NotificationCompat.InboxStyle inboxStyle, Drawable avatarDrawable, Notification topNotification) {

        android.app.Notification notification = builder
                .setLargeIcon(drawableToBitmap(avatarDrawable))
                .setContentIntent(PendingIntent.getActivity(context, 0,
                        Intents.openDialog(topNotification.getPeer(), false, context),
                        PendingIntent.FLAG_UPDATE_CURRENT))
                .setStyle(inboxStyle)
                .build();
        addCustomLedAndSound(topNotification, notification);
        return notification;
    }
 
Example 14
Source File: DownloadManager.java    From Android-Remote with GNU General Public License v3.0 5 votes vote down vote up
private void setNotificationMultipleDownloads(NotificationCompat.Builder notificationBuilder) {
    NotificationCompat.InboxStyle downloadItems =
            new NotificationCompat.InboxStyle();

    // Title
    String title = mContext.getResources().getQuantityString(R.plurals.download_noti_n_downloads,
            mActiveDownloads.size(),
            mActiveDownloads.size());
    notificationBuilder.setContentTitle(title);

    // Total progress in subtitle
    int progress = 0;
    for (int i = 0; i < mActiveDownloads.size(); ++i) {
        ClementineSongDownloader downloader = mActiveDownloads.valueAt(i);
        DownloadStatus status = downloader.getDownloadStatus();
        progress += status.getProgress();

        downloadItems.addLine(getTitleForItem(downloader));
    }

    String subtitle = mContext.getString(R.string.download_noti_n_progress);
    subtitle = subtitle.replace("%d", String.valueOf(progress / mActiveDownloads.size()));
    notificationBuilder.setContentText(subtitle);
    downloadItems.setBigContentTitle(subtitle); // Show the status on expanded notification

    notificationBuilder.setStyle(downloadItems);
    notificationBuilder.setProgress(0, 0, false);
}
 
Example 15
Source File: NotificationUtil.java    From talk-android with MIT License 4 votes vote down vote up
public static void showNotification(Context context, String message, MiPushMessage miPushMessage) {
    if (BizLogic.isNotificationOn()) {
        if (!BizLogic.isApplicationShowing(MainApp.CONTEXT) || MainApp.IS_SCREEN_LOCK) {

            int numMessages = MainApp.PREF_UTIL.getInt(Constant.NOTIFICATION_COUNT, 0) + 1;
            MainApp.PREF_UTIL.putInt(Constant.NOTIFICATION_COUNT, numMessages);
            List<String> msgList = jsonToList(MainApp.PREF_UTIL.getString(Constant.NOTIFICATION_CONTENT,
                    ""), String.class);
            if (msgList == null) {
                msgList = new ArrayList<>();
            }
            msgList.add(0, message);
            MainApp.PREF_UTIL.putString(Constant.NOTIFICATION_CONTENT, listToJson(msgList));

            /* Creates an explicit intent for an Activity in your app */
            Intent resultIntent = new Intent(context, HomeActivity.class);
            resultIntent.putExtra(PushMessageHelper.KEY_MESSAGE, miPushMessage);
            resultIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_CLEAR_TASK);
            resultIntent.addCategory(CATEGORY_NOTIFICATION);

            TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
            stackBuilder.addParentStack(MainActivity.class);

            /* Adds the Intent that starts the Activity to the top of the stack */
            stackBuilder.addNextIntent(resultIntent);
            PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0,
                    PendingIntent.FLAG_UPDATE_CURRENT);

            NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
            NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
            inboxStyle.setBigContentTitle(context.getString(R.string.app_name));
            inboxStyle.setSummaryText(context.getString(R.string.new_message));
            for (String mMsg : msgList) {
                inboxStyle.addLine(mMsg);
            }
            NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context);
            mBuilder.setContentTitle(context.getString(R.string.app_name)) //设置通知栏标题
                    .setStyle(inboxStyle)
                    .setContentText(context.getString(R.string.new_message))
                    .setAutoCancel(true)
                    .setContentIntent(resultPendingIntent) //设置通知栏点击意图
                    .setNumber(numMessages) //设置通知集合的数量
                    .setWhen(System.currentTimeMillis()) //通知产生的时间,会在通知信息里显示,一般是系统获取到的时间
                    .setDefaults(Notification.DEFAULT_VIBRATE | Notification.DEFAULT_LIGHTS) //向通知添加声音、闪灯和振动效果的最简单、最一致的方式是使用当前的用户默认设置,使用defaults属性,可以组合
                    .setSound(Uri.parse("android.resource://com.teambition.talk/" + R.raw.add), AudioManager.STREAM_NOTIFICATION)
                    .setSmallIcon(R.drawable.ic_notification); //设置通知小ICON
            mNotificationManager.notify(Constant.NOTIFICATION_ID, mBuilder.build());
        }
    }
}
 
Example 16
Source File: HelperNotificationAndBadge.java    From iGap-Android with GNU Affero General Public License v3.0 4 votes vote down vote up
private NotificationCompat.InboxStyle getBigStyle() {

        NotificationCompat.InboxStyle _style = new NotificationCompat.InboxStyle();

        if (isFromOnRoom) {
            _style.setBigContentTitle(list.get(0).name);

            for (int i = 0; i < unreadMessageCount && i < 3; i++) {
                _style.addLine(list.get(i).message);
            }
        } else {
            for (int i = 0; i < unreadMessageCount && i < 3; i++) {
                _style.addLine(list.get(i).name + " " + list.get(i).message);
            }
        }

        if (unreadMessageCount > 3) {
            _style.addLine("....");
        }

        String chatCount = "";

        if (countUnicChat == 1) {
            chatCount = context.getString(R.string.from) + " " + countUnicChat + " " + context.getString(R.string.chat);
        } else if (countUnicChat > 1) {
            chatCount = context.getString(R.string.from) + " " + countUnicChat + " " + context.getString(R.string.chats);
        }

        String newMessage = "";
        if (unreadMessageCount == 1) {
            newMessage = context.getString(R.string.new_message);
            chatCount = "";
        } else {
            newMessage = context.getString(R.string.new_messages);
        }

        String _summary = unreadMessageCount + " " + newMessage + " " + chatCount;
        _style.setSummaryText(_summary);

        return _style;
    }
 
Example 17
Source File: NotificationHelper.java    From fdroidclient with GNU General Public License v3.0 4 votes vote down vote up
private Notification createUpdateSummaryNotification(ArrayList<AppUpdateStatusManager.AppUpdateStatus> updates) {
    String title = context.getResources().getQuantityString(R.plurals.notification_summary_updates,
            updates.size(), updates.size());
    StringBuilder text = new StringBuilder();

    NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
    inboxStyle.setBigContentTitle(title);

    for (int i = 0; i < MAX_UPDATES_TO_SHOW && i < updates.size(); i++) {
        AppUpdateStatusManager.AppUpdateStatus entry = updates.get(i);
        App app = entry.app;
        AppUpdateStatusManager.Status status = entry.status;

        String content = getMultiItemContentString(app, status);
        SpannableStringBuilder sb = new SpannableStringBuilder(app.name);
        sb.setSpan(new StyleSpan(Typeface.BOLD), 0, sb.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
        sb.append(" ");
        sb.append(content);
        inboxStyle.addLine(sb);

        if (text.length() > 0) {
            text.append(", ");
        }
        text.append(app.name);
    }

    if (updates.size() > MAX_UPDATES_TO_SHOW) {
        int diff = updates.size() - MAX_UPDATES_TO_SHOW;
        inboxStyle.setSummaryText(context.getResources().getQuantityString(R.plurals.notification_summary_more,
                diff, diff));
    }

    // Intent to open main app list
    Intent intentObject = new Intent(context, MainActivity.class);
    intentObject.putExtra(MainActivity.EXTRA_VIEW_UPDATES, true);
    PendingIntent piAction = PendingIntent.getActivity(context, 0, intentObject, PendingIntent.FLAG_UPDATE_CURRENT);

    NotificationCompat.Builder builder =
            new NotificationCompat.Builder(context)
                    .setAutoCancel(!useStackedNotifications())
                    .setSmallIcon(R.drawable.ic_notification)
                    .setColor(ContextCompat.getColor(context, R.color.fdroid_blue))
                    .setContentTitle(title)
                    .setContentText(text)
                    .setContentIntent(piAction)
                    .setLocalOnly(true)
                    .setVisibility(NotificationCompat.VISIBILITY_SECRET)
                    .setStyle(inboxStyle);

    if (useStackedNotifications()) {
        builder.setGroup(GROUP_UPDATES)
                .setGroupSummary(true);
    }

    Intent intentDeleted = new Intent(BROADCAST_NOTIFICATIONS_ALL_UPDATES_CLEARED);
    intentDeleted.setClass(context, NotificationBroadcastReceiver.class);
    PendingIntent piDeleted = PendingIntent.getBroadcast(context, 0, intentDeleted, PendingIntent.FLAG_UPDATE_CURRENT);
    builder.setDeleteIntent(piDeleted);
    return builder.build();
}
 
Example 18
Source File: NotificationUtil.java    From sms-ticket with Apache License 2.0 4 votes vote down vote up
private static void fireNotification(Context c, int notificationId, PendingIntent contentIntent,
                                     String title, String text,
                                     List<String> rows, String summary, String ticker, int smallIcon,
                                     int largeIcon,
                                     List<Action> actions, boolean keepNotification) {
    int defaults = Notification.DEFAULT_LIGHTS;
    if (Preferences.getBoolean(c, Preferences.NOTIFICATION_VIBRATE, true)) {
        defaults |= Notification.DEFAULT_VIBRATE;
    }

    NotificationCompat.Builder builder = new NotificationCompat.Builder(c).setContentTitle(title).setSmallIcon
        (smallIcon).setLargeIcon(BitmapFactory.decodeResource(c.getResources(), largeIcon))
        .setTicker(ticker).setContentText(text)
        .setLocalOnly(true)
        .setContentIntent(contentIntent).setWhen(System.currentTimeMillis()).setAutoCancel(!keepNotification)
        .setDefaults
            (defaults);

    String soundUri = Preferences.getString(c, Preferences.NOTIFICATION_RINGTONE, null);
    if (!TextUtils.isEmpty(soundUri)) {
        builder.setSound(Uri.parse(soundUri));
    }

    if (actions != null) {
        for (Action action : actions) {
            builder.addAction(action.drawable, c.getString(action.text), action.intent);
        }
    }

    Notification notification;
    if (rows == null) {
        notification = builder.build();
    } else {
        NotificationCompat.InboxStyle styled = new NotificationCompat.InboxStyle(builder);
        for (String row : rows) {
            styled.addLine(row);
        }
        styled.setSummaryText(summary);
        notification = styled.build();
    }

    NotificationManager nm = (NotificationManager)c.getSystemService(Context.NOTIFICATION_SERVICE);
    if (nm == null) {
        DebugLog.e("Cannot obtain notification manager");
        return;
    }

    nm.notify(notificationId, notification);
}
 
Example 19
Source File: HelperNotification.java    From iGap-Android with GNU Affero General Public License v3.0 4 votes vote down vote up
private NotificationCompat.InboxStyle getBigStyle() {

            if (settingValue.separateNotification) {
                return null;
            }

            NotificationCompat.InboxStyle _style = new NotificationCompat.InboxStyle();

            if (countUniqueChat == 1) {
                _style.setBigContentTitle(messageList.get(0).name);

                for (int i = 0; i < unreadMessageCount && i < 3; i++) {
                    _style.addLine(messageList.get(i).message);
                }
            } else {
                for (int i = 0; i < unreadMessageCount && i < 3; i++) {
                    _style.addLine(messageList.get(i).name + " " + messageList.get(i).message);
                }
            }

            if (unreadMessageCount > 3) {
                _style.addLine("....");
            }

            String chatCount = "";

            if (countUniqueChat == 1) {
                chatCount = context.getString(R.string.from) + " " + countUniqueChat + " " + context.getString(R.string.chat);
            } else if (countUniqueChat > 1) {
                chatCount = context.getString(R.string.from) + " " + countUniqueChat + " " + context.getString(R.string.chats);
            }

            String newMessage = "";
            if (unreadMessageCount == 1) {
                newMessage = context.getString(R.string.new_message);
                chatCount = "";
            } else {
                newMessage = context.getString(R.string.new_messages);
            }

            String _summary = unreadMessageCount + " " + newMessage + " " + chatCount;
            _style.setSummaryText(_summary);

            return _style;
        }
 
Example 20
Source File: WebService.java    From ApkTrack with GNU General Public License v3.0 4 votes vote down vote up
/**
 * This method is called when a MessageModifiedEvent is posted on the event bus, but the
 * activity is not around to catch it.
 *
 * A notification is displayed to the user since the UI cannot be updated.
 *
 * @param ignored Never used.
 */
public void onEvent(StickyUpdatedMessage ignored)
{
    ModelModifiedMessage m = EventBus.getDefault().getStickyEvent(ModelModifiedMessage.class);
    List<InstalledApp> updated_apps = new ArrayList<InstalledApp>();
    List<Pair<ModelModifiedMessage.event_type, String> > events = m.access_events(new MessageAccessor());
    if (events.size() == 0) {
        return;
    }

    // Check the last event posted. It may not require a notification to be trigerred.
    Pair<ModelModifiedMessage.event_type, String> last = events.get(events.size() - 1);
    if (last.first != ModelModifiedMessage.event_type.APP_UPDATED) {
        return;
    }
    InstalledApp app = InstalledApp.find_app(last.second);
    if (app == null || !app.is_update_available() || app.has_notified()) {
        return;
    }

    // Build the list of apps which will be mentioned in the notification.
    for (Pair<ModelModifiedMessage.event_type, String> p : events)
    {
        if (p.first != ModelModifiedMessage.event_type.APP_UPDATED) {
            continue;
        }
        app = InstalledApp.find_app(p.second);
        if (app == null || !app.is_update_available() || app.has_notified()) {
            continue;
        }

        if (!updated_apps.contains(app)) {
            updated_apps.add(app);
        }
    }

    if (updated_apps.size() == 0) {
        return;
    }

    Resources r = getResources();
    NotificationCompat.Builder b = new NotificationCompat.Builder(this);
    // Show a notification for updated apps
    if (updated_apps.size() == 1)
    {
        app = updated_apps.get(updated_apps.size() - 1);
        b.setContentTitle(r.getString(R.string.app_updated_notification, app.get_display_name()))
                .setContentText(r.getString(R.string.app_version_available, app.get_latest_version()))
                .setTicker(r.getString(R.string.app_can_be_updated, app.get_display_name()))
                .setAutoCancel(true); //TODO: Think about launching the search/download on user click.
    }
    else
    {
        b.setContentTitle(r.getString(R.string.apps_updated_notification))
                .setContentText(r.getString(R.string.apps_updated_notification_summary,
                        updated_apps.get(updated_apps.size() - 1).get_display_name(),
                        updated_apps.size() - 1))
                .setTicker(r.getString(R.string.apps_updated_notification))
                .setAutoCancel(true);

        NotificationCompat.InboxStyle style = new NotificationCompat.InboxStyle();
        for (InstalledApp ia : updated_apps) {
            style.addLine(r.getString(R.string.app_version_available_2,
                    ia.get_display_name(),
                    ia.get_version(),
                    ia.get_latest_version()));
        }
        style.setBigContentTitle(r.getString(R.string.apps_updated_notification));
        b.setStyle(style);
    }

    // Do not post a notification with an SVG icon on <= 4.4.2 devices.
    if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.KITKAT) {
        b.setSmallIcon(R.drawable.ic_menu_refresh_png);
    }
    else {
        b.setSmallIcon(R.drawable.ic_menu_refresh);
    }

    // Open ApkTrack when the notification is clicked.
    Intent i = new Intent();
    i.setClass(this, MainActivity.class);
    PendingIntent pi = PendingIntent.getActivity(this, 0, i, PendingIntent.FLAG_ONE_SHOT);
    b.setContentIntent(pi);

    NotificationManager mgr = (NotificationManager) getSystemService(Service.NOTIFICATION_SERVICE);
    mgr.notify(1, b.build()); // Consolidate notifications.
}