diff options
Diffstat (limited to 'samples/browseable/ActiveNotifications/src/com.example.android.activenotifications/ActiveNotificationsFragment.java')
-rw-r--r-- | samples/browseable/ActiveNotifications/src/com.example.android.activenotifications/ActiveNotificationsFragment.java | 39 |
1 files changed, 20 insertions, 19 deletions
diff --git a/samples/browseable/ActiveNotifications/src/com.example.android.activenotifications/ActiveNotificationsFragment.java b/samples/browseable/ActiveNotifications/src/com.example.android.activenotifications/ActiveNotificationsFragment.java index db0dbac6f..d752a36f2 100644 --- a/samples/browseable/ActiveNotifications/src/com.example.android.activenotifications/ActiveNotificationsFragment.java +++ b/samples/browseable/ActiveNotifications/src/com.example.android.activenotifications/ActiveNotificationsFragment.java @@ -129,23 +129,12 @@ public class ActiveNotificationsFragment extends Fragment { * Adds/updates/removes the notification summary as necessary. */ protected void updateNotificationSummary() { - final StatusBarNotification[] activeNotifications = mNotificationManager - .getActiveNotifications(); - - int numberOfNotifications = activeNotifications.length; - // Since the notifications might include a summary notification remove it from the count if - // it is present. - for (StatusBarNotification notification : activeNotifications) { - if (notification.getId() == NOTIFICATION_GROUP_SUMMARY_ID) { - numberOfNotifications--; - break; - } - } + int numberOfNotifications = getNumberOfNotifications(); if (numberOfNotifications > 1) { // Add/update the notification summary. String notificationContent = getString(R.string.sample_notification_summary_content, - "" + numberOfNotifications); + numberOfNotifications); final NotificationCompat.Builder builder = new NotificationCompat.Builder(getActivity()) .setSmallIcon(R.mipmap.ic_notification) .setStyle(new NotificationCompat.BigTextStyle() @@ -165,12 +154,7 @@ public class ActiveNotificationsFragment extends Fragment { * display them to the user. */ protected void updateNumberOfNotifications() { - // [BEGIN get_active_notifications] - // Query the currently displayed notifications. - final StatusBarNotification[] activeNotifications = mNotificationManager - .getActiveNotifications(); - // [END get_active_notifications] - final int numberOfNotifications = activeNotifications.length; + final int numberOfNotifications = getNumberOfNotifications(); mNumberOfNotifications.setText(getString(R.string.active_notifications, numberOfNotifications)); Log.i(TAG, getString(R.string.active_notifications, numberOfNotifications)); @@ -190,4 +174,21 @@ public class ActiveNotificationsFragment extends Fragment { } return notificationId; } + + private int getNumberOfNotifications() { + // [BEGIN get_active_notifications] + // Query the currently displayed notifications. + final StatusBarNotification[] activeNotifications = mNotificationManager + .getActiveNotifications(); + // [END get_active_notifications] + + // Since the notifications might include a summary notification remove it from the count if + // it is present. + for (StatusBarNotification notification : activeNotifications) { + if (notification.getId() == NOTIFICATION_GROUP_SUMMARY_ID) { + return activeNotifications.length - 1; + } + } + return activeNotifications.length; + } } |