From d7815fe18fff943abfef39e55839bb16e93dc022 Mon Sep 17 00:00:00 2001 From: Julia Reynolds Date: Fri, 30 Mar 2018 14:04:55 -0400 Subject: [PATCH] Notification settings updates - smaller icons - text update - fx header - fix category header Test: make -j RunSettingsRoboTests Change-Id: If822d6db31a8dccf20ee88182cda1aee34aa7675 Fixes: 77325154 Fixes: 77323406 Fixes: 77324677 Fixes: 74408368 --- res/layout/preference_app.xml | 4 ++-- res/values/strings.xml | 4 ++-- .../notification/AppNotificationSettings.java | 6 ++--- .../BadgePreferenceController.java | 2 +- .../BlockPreferenceController.java | 3 +-- .../HeaderPreferenceController.java | 6 +++-- .../ImportancePreferenceController.java | 2 +- .../LightsPreferenceController.java | 5 ++-- .../NotificationPreferenceController.java | 7 ++++++ ...centNotifyingAppsPreferenceController.java | 4 ++-- .../SoundPreferenceController.java | 3 +-- .../VibrationPreferenceController.java | 2 +- .../HeaderPreferenceControllerTest.java | 10 ++++++++ .../NotificationPreferenceControllerTest.java | 24 +++++++++++++++++++ 14 files changed, 62 insertions(+), 20 deletions(-) diff --git a/res/layout/preference_app.xml b/res/layout/preference_app.xml index 2e134dee207..66050410847 100644 --- a/res/layout/preference_app.xml +++ b/res/layout/preference_app.xml @@ -95,8 +95,8 @@ android:id="@android:id/widget_frame" android:layout_width="wrap_content" android:layout_height="match_parent" - android:gravity="end|center_vertical" - android:paddingStart="16dp" + android:gravity="center" + android:minWidth="64dp" android:orientation="vertical" /> diff --git a/res/values/strings.xml b/res/values/strings.xml index 0922ebb13c3..d7179d51824 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -7513,9 +7513,9 @@ Notification assistant - ~%1$s sent daily + ~%1$s per day - ~%1$s sent weekly + ~%1$s per week Never diff --git a/src/com/android/settings/notification/AppNotificationSettings.java b/src/com/android/settings/notification/AppNotificationSettings.java index d334b9217b7..c028298e0bd 100644 --- a/src/com/android/settings/notification/AppNotificationSettings.java +++ b/src/com/android/settings/notification/AppNotificationSettings.java @@ -167,9 +167,9 @@ public class AppNotificationSettings extends NotificationSettingsBase { getPreferenceScreen().addPreference(groupCategory); mDynamicPreferences.add(groupCategory); if (group.getId() == null) { - groupCategory.setTitle(mChannelGroupList.size() > 1 - ? R.string.notification_channels_other - : R.string.notification_channels); + if (mChannelGroupList.size() > 1) { + groupCategory.setTitle(R.string.notification_channels_other); + } groupCategory.setKey(KEY_GENERAL_CATEGORY); } else { groupCategory.setTitle(group.getName()); diff --git a/src/com/android/settings/notification/BadgePreferenceController.java b/src/com/android/settings/notification/BadgePreferenceController.java index 8f0376c0627..e768ad18090 100644 --- a/src/com/android/settings/notification/BadgePreferenceController.java +++ b/src/com/android/settings/notification/BadgePreferenceController.java @@ -57,7 +57,7 @@ public class BadgePreferenceController extends NotificationPreferenceController return false; } if (mChannel != null) { - if (NotificationChannel.DEFAULT_CHANNEL_ID.equals(mChannel.getId())) { + if (isDefaultChannel()) { return true; } else { return mAppRow.showBadge; diff --git a/src/com/android/settings/notification/BlockPreferenceController.java b/src/com/android/settings/notification/BlockPreferenceController.java index 9ea29feccca..7c6201eeedf 100644 --- a/src/com/android/settings/notification/BlockPreferenceController.java +++ b/src/com/android/settings/notification/BlockPreferenceController.java @@ -98,8 +98,7 @@ public class BlockPreferenceController extends NotificationPreferenceController // it was blocked and we are unblocking it. if (blocked || originalImportance == IMPORTANCE_NONE) { final int importance = blocked ? IMPORTANCE_NONE - : DEFAULT_CHANNEL_ID.equals(mChannel.getId()) - ? IMPORTANCE_UNSPECIFIED : IMPORTANCE_DEFAULT; + : isDefaultChannel() ? IMPORTANCE_UNSPECIFIED : IMPORTANCE_DEFAULT; mChannel.setImportance(importance); saveChannel(); } diff --git a/src/com/android/settings/notification/HeaderPreferenceController.java b/src/com/android/settings/notification/HeaderPreferenceController.java index ff687e8049f..d5e289b3173 100644 --- a/src/com/android/settings/notification/HeaderPreferenceController.java +++ b/src/com/android/settings/notification/HeaderPreferenceController.java @@ -31,6 +31,8 @@ import com.android.settings.applications.LayoutPreference; import com.android.settings.core.PreferenceControllerMixin; import com.android.settings.widget.EntityHeaderController; +import java.util.Objects; + public class HeaderPreferenceController extends NotificationPreferenceController implements PreferenceControllerMixin { @@ -72,7 +74,7 @@ public class HeaderPreferenceController extends NotificationPreferenceController } CharSequence getLabel() { - return mChannel != null ? mChannel.getName() + return (mChannel != null && !isDefaultChannel()) ? mChannel.getName() : mChannelGroup != null ? mChannelGroup.getName() : mAppRow.label; @@ -80,7 +82,7 @@ public class HeaderPreferenceController extends NotificationPreferenceController @Override public CharSequence getSummary() { - if (mChannel != null) { + if (mChannel != null && !isDefaultChannel()) { if (mChannelGroup != null && !TextUtils.isEmpty(mChannelGroup.getName())) { final SpannableStringBuilder summary = new SpannableStringBuilder(); diff --git a/src/com/android/settings/notification/ImportancePreferenceController.java b/src/com/android/settings/notification/ImportancePreferenceController.java index f95c34ae6ae..60b2ebe0250 100644 --- a/src/com/android/settings/notification/ImportancePreferenceController.java +++ b/src/com/android/settings/notification/ImportancePreferenceController.java @@ -58,7 +58,7 @@ public class ImportancePreferenceController extends NotificationPreferenceContro if (mChannel == null) { return false; } - return !NotificationChannel.DEFAULT_CHANNEL_ID.equals(mChannel.getId()); + return !isDefaultChannel(); } @Override diff --git a/src/com/android/settings/notification/LightsPreferenceController.java b/src/com/android/settings/notification/LightsPreferenceController.java index 230c3e295d2..9d5a6c55d74 100644 --- a/src/com/android/settings/notification/LightsPreferenceController.java +++ b/src/com/android/settings/notification/LightsPreferenceController.java @@ -50,8 +50,9 @@ public class LightsPreferenceController extends NotificationPreferenceController if (mChannel == null) { return false; } - return checkCanBeVisible(NotificationManager.IMPORTANCE_DEFAULT) && canPulseLight() - && !NotificationChannel.DEFAULT_CHANNEL_ID.equals(mChannel.getId()); + return checkCanBeVisible(NotificationManager.IMPORTANCE_DEFAULT) + && canPulseLight() + && !isDefaultChannel(); } public void updateState(Preference preference) { diff --git a/src/com/android/settings/notification/NotificationPreferenceController.java b/src/com/android/settings/notification/NotificationPreferenceController.java index c0bb7050045..1a65351659e 100644 --- a/src/com/android/settings/notification/NotificationPreferenceController.java +++ b/src/com/android/settings/notification/NotificationPreferenceController.java @@ -184,4 +184,11 @@ public abstract class NotificationPreferenceController extends AbstractPreferenc protected boolean hasValidGroup() { return mChannelGroup != null; } + + protected final boolean isDefaultChannel() { + if (mChannel == null) { + return false; + } + return Objects.equals(NotificationChannel.DEFAULT_CHANNEL_ID, mChannel.getId()); + } } diff --git a/src/com/android/settings/notification/RecentNotifyingAppsPreferenceController.java b/src/com/android/settings/notification/RecentNotifyingAppsPreferenceController.java index 3867640c86f..4079099f8ec 100644 --- a/src/com/android/settings/notification/RecentNotifyingAppsPreferenceController.java +++ b/src/com/android/settings/notification/RecentNotifyingAppsPreferenceController.java @@ -37,14 +37,13 @@ import android.util.Log; import com.android.internal.logging.nano.MetricsProto; import com.android.settings.R; import com.android.settings.applications.AppInfoBase; -import com.android.settings.applications.InstalledAppCounter; import com.android.settings.core.PreferenceControllerMixin; import com.android.settings.core.SubSettingLauncher; +import com.android.settingslib.TwoTargetPreference; import com.android.settingslib.applications.AppUtils; import com.android.settingslib.applications.ApplicationsState; import com.android.settingslib.core.AbstractPreferenceController; import com.android.settingslib.utils.StringUtil; -import com.android.settingslib.wrapper.PackageManagerWrapper; import java.util.ArrayList; import java.util.Arrays; @@ -211,6 +210,7 @@ public class RecentNotifyingAppsPreferenceController extends AbstractPreferenceC pref.setKey(pkgName); pref.setTitle(appEntry.label); pref.setIcon(mIconDrawableFactory.getBadgedIcon(appEntry.info)); + pref.setIconSize(TwoTargetPreference.ICON_SIZE_SMALL); pref.setSummary(StringUtil.formatRelativeTime(mContext, System.currentTimeMillis() - app.getLastNotified(), true)); pref.setOrder(i); diff --git a/src/com/android/settings/notification/SoundPreferenceController.java b/src/com/android/settings/notification/SoundPreferenceController.java index e4414b6908a..4ae6ebe99c6 100644 --- a/src/com/android/settings/notification/SoundPreferenceController.java +++ b/src/com/android/settings/notification/SoundPreferenceController.java @@ -59,8 +59,7 @@ public class SoundPreferenceController extends NotificationPreferenceController if (mChannel == null) { return false; } - return checkCanBeVisible(NotificationManager.IMPORTANCE_DEFAULT) - && !NotificationChannel.DEFAULT_CHANNEL_ID.equals(mChannel.getId()); + return checkCanBeVisible(NotificationManager.IMPORTANCE_DEFAULT) && !isDefaultChannel(); } @Override diff --git a/src/com/android/settings/notification/VibrationPreferenceController.java b/src/com/android/settings/notification/VibrationPreferenceController.java index f9b786dc2d8..9df8e04013f 100644 --- a/src/com/android/settings/notification/VibrationPreferenceController.java +++ b/src/com/android/settings/notification/VibrationPreferenceController.java @@ -47,7 +47,7 @@ public class VibrationPreferenceController extends NotificationPreferenceControl return false; } return checkCanBeVisible(NotificationManager.IMPORTANCE_DEFAULT) - && !NotificationChannel.DEFAULT_CHANNEL_ID.equals(mChannel.getId()) + && !isDefaultChannel() && mVibrator != null && mVibrator.hasVibrator(); } diff --git a/tests/robotests/src/com/android/settings/notification/HeaderPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/HeaderPreferenceControllerTest.java index 29773d2cc1a..9a766470836 100644 --- a/tests/robotests/src/com/android/settings/notification/HeaderPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/notification/HeaderPreferenceControllerTest.java @@ -109,6 +109,11 @@ public class HeaderPreferenceControllerTest { NotificationChannel channel = new NotificationChannel("cid", "cname", IMPORTANCE_NONE); mController.onResume(appRow, channel, group, null); assertEquals(channel.getName(), mController.getLabel()); + + NotificationChannel defaultChannel = new NotificationChannel( + NotificationChannel.DEFAULT_CHANNEL_ID, "", IMPORTANCE_NONE); + mController.onResume(appRow, defaultChannel, null, null); + assertEquals(appRow.label, mController.getLabel()); } @Test @@ -130,5 +135,10 @@ public class HeaderPreferenceControllerTest { mController.onResume(appRow, channel, null, null); assertFalse(mController.getSummary().toString().contains(group.getName())); assertTrue(mController.getSummary().toString().contains(appRow.label)); + + NotificationChannel defaultChannel = new NotificationChannel( + NotificationChannel.DEFAULT_CHANNEL_ID, "", IMPORTANCE_NONE); + mController.onResume(appRow, defaultChannel, null, null); + assertEquals("", mController.getSummary()); } } diff --git a/tests/robotests/src/com/android/settings/notification/NotificationPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/notification/NotificationPreferenceControllerTest.java index 3ead72a2f31..4fe384e981b 100644 --- a/tests/robotests/src/com/android/settings/notification/NotificationPreferenceControllerTest.java +++ b/tests/robotests/src/com/android/settings/notification/NotificationPreferenceControllerTest.java @@ -294,6 +294,30 @@ public class NotificationPreferenceControllerTest { assertTrue(mController.isChannelGroupBlockable()); } + @Test + public void testIsDefaultChannel_noChannel() { + mController.onResume(mock(NotificationBackend.AppRow.class), null, null, null); + + assertFalse(mController.isDefaultChannel()); + } + + @Test + public void testIsDefaultChannel_nonDefaultChannel() { + NotificationChannel channel = mock(NotificationChannel.class); + mController.onResume(mock(NotificationBackend.AppRow.class), channel, null, null); + + assertFalse(mController.isDefaultChannel()); + } + + @Test + public void testIsDefaultChannel() { + NotificationChannel channel = mock(NotificationChannel.class); + when(channel.getId()).thenReturn(NotificationChannel.DEFAULT_CHANNEL_ID); + mController.onResume(mock(NotificationBackend.AppRow.class), channel, null, null); + + assertTrue(mController.isDefaultChannel()); + } + private final class TestPreferenceController extends NotificationPreferenceController { private TestPreferenceController(Context context, NotificationBackend backend) {