diff options
author | Jose Alcerreca <jalc@google.com> | 2016-11-25 16:08:15 +0000 |
---|---|---|
committer | Jose Alcerreca <jalc@google.com> | 2016-11-25 16:52:28 +0000 |
commit | 9dfb11b62b4d2fa81cadbfbea1f9cb762f45812e (patch) | |
tree | 4d9955dad1cb53000933f5b6c3737b640f85f6b8 /notification | |
parent | a96e01f2b5ed38d455ccc85a4161d250a314488d (diff) | |
download | android-9dfb11b62b4d2fa81cadbfbea1f9cb762f45812e.tar.gz |
Fixes count bug and lint warnings
Change-Id: I9c288d0c4588a60ea33199d134faa5863597e42f
Diffstat (limited to 'notification')
2 files changed, 22 insertions, 21 deletions
diff --git a/notification/ActiveNotifications/Application/src/main/java/com/example/android/activenotifications/ActiveNotificationsFragment.java b/notification/ActiveNotifications/Application/src/main/java/com/example/android/activenotifications/ActiveNotificationsFragment.java index db0dbac6..d752a36f 100644 --- a/notification/ActiveNotifications/Application/src/main/java/com/example/android/activenotifications/ActiveNotificationsFragment.java +++ b/notification/ActiveNotifications/Application/src/main/java/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; + } } diff --git a/notification/ActiveNotifications/Application/src/main/res/values/strings.xml b/notification/ActiveNotifications/Application/src/main/res/values/strings.xml index a4275fdf..783a0744 100644 --- a/notification/ActiveNotifications/Application/src/main/res/values/strings.xml +++ b/notification/ActiveNotifications/Application/src/main/res/values/strings.xml @@ -16,8 +16,8 @@ --> <resources> <string name="add_a_notification">Add a notification</string> - <string name="active_notifications">Active Notifications: %1$s</string> + <string name="active_notifications">Active Notifications: %1$d</string> <string name="update_notification_count">Update count</string> <string name="sample_notification_content">This is a sample notification.</string> - <string name="sample_notification_summary_content">There are %s ActiveNotifications.</string> + <string name="sample_notification_summary_content">There are %d ActiveNotifications.</string> </resources> |