Loading packages/SystemUI/res/values/strings.xml +7 −3 Original line number Original line Diff line number Diff line Loading @@ -1382,11 +1382,15 @@ of notifications. Replaces the channel name and only appears when there is more than one channel. --> of notifications. Replaces the channel name and only appears when there is more than one channel. --> <string name="notification_num_channels"> <xliff:g id="number">%d</xliff:g> notification categories</string> <string name="notification_num_channels"> <xliff:g id="number">%d</xliff:g> notification categories</string> <!-- Notification: Control panel: Label that shows when an app has not upgraded to use channels. Hints that the user's only option is to block all of the app's notifications. --> <string name="notification_default_channel_desc">This app doesn\'t have notification categories</string> <!-- Notification: Control panel: Label that shows how many channels this application has <!-- Notification: Control panel: Label that shows how many channels this application has defined, describing the current notification channel as "1 out of n categories from this app". --> defined, describing the current notification channel as "1 out of n notification categories from this app". --> <plurals name="notification_num_channels_desc"> <plurals name="notification_num_channels_desc"> <item quantity="one">1 out of <xliff:g id="number">%d</xliff:g> category from this app</item> <item quantity="one">1 out of <xliff:g id="number">%d</xliff:g> notification category from this app</item> <item quantity="other">1 out of <xliff:g id="number">%d</xliff:g> categories from this app</item> <item quantity="other">1 out of <xliff:g id="number">%d</xliff:g> notification categories from this app</item> </plurals> </plurals> <!-- Notification: Control panel: For bundles of notifications, this label that lists the <!-- Notification: Control panel: For bundles of notifications, this label that lists the Loading packages/SystemUI/src/com/android/systemui/statusbar/NotificationInfo.java +30 −28 Original line number Original line Diff line number Diff line Loading @@ -99,11 +99,14 @@ public class NotificationInfo extends LinearLayout implements GutsContent { mINotificationManager = iNotificationManager; mINotificationManager = iNotificationManager; mPkg = pkg; mPkg = pkg; mNotificationChannels = notificationChannels; mNotificationChannels = notificationChannels; boolean isSingleDefaultChannel = false; if (mNotificationChannels.isEmpty()) { if (mNotificationChannels.isEmpty()) { throw new IllegalArgumentException("bindNotification requires at least one channel"); throw new IllegalArgumentException("bindNotification requires at least one channel"); } else if (mNotificationChannels.size() == 1) { } else if (mNotificationChannels.size() == 1) { mSingleNotificationChannel = mNotificationChannels.get(0); mSingleNotificationChannel = mNotificationChannels.get(0); mStartingUserImportance = mSingleNotificationChannel.getImportance(); mStartingUserImportance = mSingleNotificationChannel.getImportance(); isSingleDefaultChannel = mSingleNotificationChannel.getId() .equals(NotificationChannel.DEFAULT_CHANNEL_ID); } else { } else { mSingleNotificationChannel = null; mSingleNotificationChannel = null; } } Loading Loading @@ -135,13 +138,17 @@ public class NotificationInfo extends LinearLayout implements GutsContent { String channelsDescText; String channelsDescText; mNumChannelsView = (TextView) (findViewById(R.id.num_channels_desc)); mNumChannelsView = (TextView) (findViewById(R.id.num_channels_desc)); if (isSingleDefaultChannel) { channelsDescText = mContext.getString(R.string.notification_default_channel_desc); } else { switch (mNotificationChannels.size()) { switch (mNotificationChannels.size()) { case 1: case 1: channelsDescText = String.format(mContext.getResources().getQuantityString( channelsDescText = String.format(mContext.getResources().getQuantityString( R.plurals.notification_num_channels_desc, numChannels), numChannels); R.plurals.notification_num_channels_desc, numChannels), numChannels); break; break; case 2: case 2: channelsDescText = mContext.getString(R.string.notification_channels_list_desc_2, channelsDescText = mContext.getString( R.string.notification_channels_list_desc_2, mNotificationChannels.get(0).getName(), mNotificationChannels.get(0).getName(), mNotificationChannels.get(1).getName()); mNotificationChannels.get(1).getName()); break; break; Loading @@ -149,20 +156,21 @@ public class NotificationInfo extends LinearLayout implements GutsContent { final int numOthers = mNotificationChannels.size() - 2; final int numOthers = mNotificationChannels.size() - 2; channelsDescText = String.format( channelsDescText = String.format( mContext.getResources().getQuantityString( mContext.getResources().getQuantityString( R.plurals.notification_channels_list_desc_2_and_others, numOthers), R.plurals.notification_channels_list_desc_2_and_others, numOthers), mNotificationChannels.get(0).getName(), mNotificationChannels.get(0).getName(), mNotificationChannels.get(1).getName(), mNotificationChannels.get(1).getName(), numOthers); numOthers); } } } mNumChannelsView.setText(channelsDescText); mNumChannelsView.setText(channelsDescText); if (mSingleNotificationChannel == null) { if (mSingleNotificationChannel == null) { // Multiple channels don't use a channel name for the title. // Multiple channels don't use a channel name for the title. channelNameText = mContext.getString(R.string.notification_num_channels, channelNameText = mContext.getString(R.string.notification_num_channels, mNotificationChannels.size()); mNotificationChannels.size()); } else if (mSingleNotificationChannel.getId() } else if (isSingleDefaultChannel) { .equals(NotificationChannel.DEFAULT_CHANNEL_ID)) { // If this is the default channel, don't use our channel-specific text. // If this is the placeholder channel, don't use our channel-specific text. channelNameText = mContext.getString(R.string.notification_header_default_channel); channelNameText = mContext.getString(R.string.notification_header_default_channel); } else { } else { channelNameText = mSingleNotificationChannel.getName(); channelNameText = mSingleNotificationChannel.getName(); Loading Loading @@ -282,15 +290,9 @@ public class NotificationInfo extends LinearLayout implements GutsContent { } } private void updateSecondaryText() { private void updateSecondaryText() { final boolean defaultChannel = mSingleNotificationChannel != null && mSingleNotificationChannel.getId().equals(NotificationChannel.DEFAULT_CHANNEL_ID); final boolean disabled = mSingleNotificationChannel != null && final boolean disabled = mSingleNotificationChannel != null && getSelectedImportance() == NotificationManager.IMPORTANCE_NONE; getSelectedImportance() == NotificationManager.IMPORTANCE_NONE; if (defaultChannel) { if (disabled) { // Don't show any secondary text if this is from the default channel. mChannelDisabledView.setVisibility(View.GONE); mNumChannelsView.setVisibility(View.GONE); } else if (disabled) { mChannelDisabledView.setVisibility(View.VISIBLE); mChannelDisabledView.setVisibility(View.VISIBLE); mNumChannelsView.setVisibility(View.GONE); mNumChannelsView.setVisibility(View.GONE); } else { } else { Loading packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationInfoTest.java +7 −4 Original line number Original line Diff line number Diff line Loading @@ -260,12 +260,14 @@ public class NotificationInfoTest extends SysuiTestCase { } } @Test @Test public void testBindNotification_NumChannelsTextHiddenWhenDefaultChannel() throws Exception { public void testBindNotification_NumChannelsTextUniqueWhenDefaultChannel() throws Exception { mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, TEST_PACKAGE_NAME, Arrays.asList(mDefaultNotificationChannel), null, null, null); TEST_PACKAGE_NAME, Arrays.asList(mDefaultNotificationChannel), null, null, null); final TextView numChannelsView = final TextView numChannelsView = (TextView) mNotificationInfo.findViewById(R.id.num_channels_desc); (TextView) mNotificationInfo.findViewById(R.id.num_channels_desc); assertTrue(numChannelsView.getVisibility() != View.VISIBLE); assertEquals(View.VISIBLE, numChannelsView.getVisibility()); assertEquals(mContext.getString(R.string.notification_default_channel_desc), numChannelsView.getText()); } } @Test @Test Loading Loading @@ -390,13 +392,14 @@ public class NotificationInfoTest extends SysuiTestCase { @Test @Test @UiThreadTest @UiThreadTest public void testBindNotification_ChannelDisabledTextHiddenWhenDefaultChannel() public void testBindNotification_ChannelDisabledTextShowsForDefaultChannel() throws Exception { throws Exception { mDefaultNotificationChannel.setImportance(NotificationManager.IMPORTANCE_NONE); mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, TEST_PACKAGE_NAME, Arrays.asList(mDefaultNotificationChannel), null, null, null); TEST_PACKAGE_NAME, Arrays.asList(mDefaultNotificationChannel), null, null, null); final TextView channelDisabledView = final TextView channelDisabledView = (TextView) mNotificationInfo.findViewById(R.id.channel_disabled); (TextView) mNotificationInfo.findViewById(R.id.channel_disabled); assertTrue(channelDisabledView.getVisibility() != View.VISIBLE); assertEquals(View.VISIBLE, channelDisabledView.getVisibility()); } } @Test @Test Loading Loading
packages/SystemUI/res/values/strings.xml +7 −3 Original line number Original line Diff line number Diff line Loading @@ -1382,11 +1382,15 @@ of notifications. Replaces the channel name and only appears when there is more than one channel. --> of notifications. Replaces the channel name and only appears when there is more than one channel. --> <string name="notification_num_channels"> <xliff:g id="number">%d</xliff:g> notification categories</string> <string name="notification_num_channels"> <xliff:g id="number">%d</xliff:g> notification categories</string> <!-- Notification: Control panel: Label that shows when an app has not upgraded to use channels. Hints that the user's only option is to block all of the app's notifications. --> <string name="notification_default_channel_desc">This app doesn\'t have notification categories</string> <!-- Notification: Control panel: Label that shows how many channels this application has <!-- Notification: Control panel: Label that shows how many channels this application has defined, describing the current notification channel as "1 out of n categories from this app". --> defined, describing the current notification channel as "1 out of n notification categories from this app". --> <plurals name="notification_num_channels_desc"> <plurals name="notification_num_channels_desc"> <item quantity="one">1 out of <xliff:g id="number">%d</xliff:g> category from this app</item> <item quantity="one">1 out of <xliff:g id="number">%d</xliff:g> notification category from this app</item> <item quantity="other">1 out of <xliff:g id="number">%d</xliff:g> categories from this app</item> <item quantity="other">1 out of <xliff:g id="number">%d</xliff:g> notification categories from this app</item> </plurals> </plurals> <!-- Notification: Control panel: For bundles of notifications, this label that lists the <!-- Notification: Control panel: For bundles of notifications, this label that lists the Loading
packages/SystemUI/src/com/android/systemui/statusbar/NotificationInfo.java +30 −28 Original line number Original line Diff line number Diff line Loading @@ -99,11 +99,14 @@ public class NotificationInfo extends LinearLayout implements GutsContent { mINotificationManager = iNotificationManager; mINotificationManager = iNotificationManager; mPkg = pkg; mPkg = pkg; mNotificationChannels = notificationChannels; mNotificationChannels = notificationChannels; boolean isSingleDefaultChannel = false; if (mNotificationChannels.isEmpty()) { if (mNotificationChannels.isEmpty()) { throw new IllegalArgumentException("bindNotification requires at least one channel"); throw new IllegalArgumentException("bindNotification requires at least one channel"); } else if (mNotificationChannels.size() == 1) { } else if (mNotificationChannels.size() == 1) { mSingleNotificationChannel = mNotificationChannels.get(0); mSingleNotificationChannel = mNotificationChannels.get(0); mStartingUserImportance = mSingleNotificationChannel.getImportance(); mStartingUserImportance = mSingleNotificationChannel.getImportance(); isSingleDefaultChannel = mSingleNotificationChannel.getId() .equals(NotificationChannel.DEFAULT_CHANNEL_ID); } else { } else { mSingleNotificationChannel = null; mSingleNotificationChannel = null; } } Loading Loading @@ -135,13 +138,17 @@ public class NotificationInfo extends LinearLayout implements GutsContent { String channelsDescText; String channelsDescText; mNumChannelsView = (TextView) (findViewById(R.id.num_channels_desc)); mNumChannelsView = (TextView) (findViewById(R.id.num_channels_desc)); if (isSingleDefaultChannel) { channelsDescText = mContext.getString(R.string.notification_default_channel_desc); } else { switch (mNotificationChannels.size()) { switch (mNotificationChannels.size()) { case 1: case 1: channelsDescText = String.format(mContext.getResources().getQuantityString( channelsDescText = String.format(mContext.getResources().getQuantityString( R.plurals.notification_num_channels_desc, numChannels), numChannels); R.plurals.notification_num_channels_desc, numChannels), numChannels); break; break; case 2: case 2: channelsDescText = mContext.getString(R.string.notification_channels_list_desc_2, channelsDescText = mContext.getString( R.string.notification_channels_list_desc_2, mNotificationChannels.get(0).getName(), mNotificationChannels.get(0).getName(), mNotificationChannels.get(1).getName()); mNotificationChannels.get(1).getName()); break; break; Loading @@ -149,20 +156,21 @@ public class NotificationInfo extends LinearLayout implements GutsContent { final int numOthers = mNotificationChannels.size() - 2; final int numOthers = mNotificationChannels.size() - 2; channelsDescText = String.format( channelsDescText = String.format( mContext.getResources().getQuantityString( mContext.getResources().getQuantityString( R.plurals.notification_channels_list_desc_2_and_others, numOthers), R.plurals.notification_channels_list_desc_2_and_others, numOthers), mNotificationChannels.get(0).getName(), mNotificationChannels.get(0).getName(), mNotificationChannels.get(1).getName(), mNotificationChannels.get(1).getName(), numOthers); numOthers); } } } mNumChannelsView.setText(channelsDescText); mNumChannelsView.setText(channelsDescText); if (mSingleNotificationChannel == null) { if (mSingleNotificationChannel == null) { // Multiple channels don't use a channel name for the title. // Multiple channels don't use a channel name for the title. channelNameText = mContext.getString(R.string.notification_num_channels, channelNameText = mContext.getString(R.string.notification_num_channels, mNotificationChannels.size()); mNotificationChannels.size()); } else if (mSingleNotificationChannel.getId() } else if (isSingleDefaultChannel) { .equals(NotificationChannel.DEFAULT_CHANNEL_ID)) { // If this is the default channel, don't use our channel-specific text. // If this is the placeholder channel, don't use our channel-specific text. channelNameText = mContext.getString(R.string.notification_header_default_channel); channelNameText = mContext.getString(R.string.notification_header_default_channel); } else { } else { channelNameText = mSingleNotificationChannel.getName(); channelNameText = mSingleNotificationChannel.getName(); Loading Loading @@ -282,15 +290,9 @@ public class NotificationInfo extends LinearLayout implements GutsContent { } } private void updateSecondaryText() { private void updateSecondaryText() { final boolean defaultChannel = mSingleNotificationChannel != null && mSingleNotificationChannel.getId().equals(NotificationChannel.DEFAULT_CHANNEL_ID); final boolean disabled = mSingleNotificationChannel != null && final boolean disabled = mSingleNotificationChannel != null && getSelectedImportance() == NotificationManager.IMPORTANCE_NONE; getSelectedImportance() == NotificationManager.IMPORTANCE_NONE; if (defaultChannel) { if (disabled) { // Don't show any secondary text if this is from the default channel. mChannelDisabledView.setVisibility(View.GONE); mNumChannelsView.setVisibility(View.GONE); } else if (disabled) { mChannelDisabledView.setVisibility(View.VISIBLE); mChannelDisabledView.setVisibility(View.VISIBLE); mNumChannelsView.setVisibility(View.GONE); mNumChannelsView.setVisibility(View.GONE); } else { } else { Loading
packages/SystemUI/tests/src/com/android/systemui/statusbar/NotificationInfoTest.java +7 −4 Original line number Original line Diff line number Diff line Loading @@ -260,12 +260,14 @@ public class NotificationInfoTest extends SysuiTestCase { } } @Test @Test public void testBindNotification_NumChannelsTextHiddenWhenDefaultChannel() throws Exception { public void testBindNotification_NumChannelsTextUniqueWhenDefaultChannel() throws Exception { mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, TEST_PACKAGE_NAME, Arrays.asList(mDefaultNotificationChannel), null, null, null); TEST_PACKAGE_NAME, Arrays.asList(mDefaultNotificationChannel), null, null, null); final TextView numChannelsView = final TextView numChannelsView = (TextView) mNotificationInfo.findViewById(R.id.num_channels_desc); (TextView) mNotificationInfo.findViewById(R.id.num_channels_desc); assertTrue(numChannelsView.getVisibility() != View.VISIBLE); assertEquals(View.VISIBLE, numChannelsView.getVisibility()); assertEquals(mContext.getString(R.string.notification_default_channel_desc), numChannelsView.getText()); } } @Test @Test Loading Loading @@ -390,13 +392,14 @@ public class NotificationInfoTest extends SysuiTestCase { @Test @Test @UiThreadTest @UiThreadTest public void testBindNotification_ChannelDisabledTextHiddenWhenDefaultChannel() public void testBindNotification_ChannelDisabledTextShowsForDefaultChannel() throws Exception { throws Exception { mDefaultNotificationChannel.setImportance(NotificationManager.IMPORTANCE_NONE); mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, mNotificationInfo.bindNotification(mMockPackageManager, mMockINotificationManager, TEST_PACKAGE_NAME, Arrays.asList(mDefaultNotificationChannel), null, null, null); TEST_PACKAGE_NAME, Arrays.asList(mDefaultNotificationChannel), null, null, null); final TextView channelDisabledView = final TextView channelDisabledView = (TextView) mNotificationInfo.findViewById(R.id.channel_disabled); (TextView) mNotificationInfo.findViewById(R.id.channel_disabled); assertTrue(channelDisabledView.getVisibility() != View.VISIBLE); assertEquals(View.VISIBLE, channelDisabledView.getVisibility()); } } @Test @Test Loading