Update Sound settings.
- change the summary to show the automatic rules info instead. - removed ringtone preference category - add dividers above DND and Emergency broadcast Change-Id: Iee497d194b70af72cfd69b315d639ca62720643b Fix: 34975939 Test: make RunSettingsRoboTests
This commit is contained in:
@@ -6320,7 +6320,7 @@
|
||||
</plurals>
|
||||
|
||||
<!-- Sound: Title for the Do not Disturb option and associated settings page. [CHAR LIMIT=50]-->
|
||||
<string name="zen_mode_settings_title">Do Not Disturb</string>
|
||||
<string name="zen_mode_settings_title">Do Not Disturb preferences</string>
|
||||
|
||||
<!-- Do not disturb: Title for the Priority interruptions option and associated settings page. [CHAR LIMIT=30] -->
|
||||
<string name="zen_mode_priority_settings_title">Priority only allows</string>
|
||||
|
@@ -56,11 +56,8 @@
|
||||
android:title="@string/zen_mode_settings_title"
|
||||
settings:useAdminDisabledSummary="true"
|
||||
settings:keywords="@string/keywords_sounds_and_notifications_interruptions"
|
||||
android:fragment="com.android.settings.notification.ZenModeSettings" />
|
||||
|
||||
<PreferenceCategory
|
||||
android:key="ringtones_preferecence_category"
|
||||
android:title="@string/ringtones_category_preference_title" >
|
||||
android:fragment="com.android.settings.notification.ZenModeSettings"
|
||||
settings:allowDividerAbove="true" />
|
||||
|
||||
<!-- Phone ringtone -->
|
||||
<com.android.settings.DefaultRingtonePreference
|
||||
@@ -68,7 +65,8 @@
|
||||
android:title="@string/ringtone_title"
|
||||
android:dialogTitle="@string/ringtone_title"
|
||||
android:summary="@string/summary_placeholder"
|
||||
android:ringtoneType="ringtone" />
|
||||
android:ringtoneType="ringtone"
|
||||
settings:allowDividerAbove="true" />
|
||||
|
||||
<!-- Default notification ringtone -->
|
||||
<com.android.settings.DefaultRingtonePreference
|
||||
@@ -87,8 +85,6 @@
|
||||
android:persistent="false"
|
||||
android:ringtoneType="alarm" />
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
<!-- Other sounds -->
|
||||
<PreferenceCategory
|
||||
android:key="other_sound_preferecence_category"
|
||||
@@ -144,7 +140,8 @@
|
||||
<com.android.settingslib.RestrictedPreference
|
||||
android:key="cell_broadcast_settings"
|
||||
android:title="@string/cell_broadcast_settings"
|
||||
settings:useAdminDisabledSummary="true">
|
||||
settings:useAdminDisabledSummary="true"
|
||||
settings:allowDividerAbove="true" >
|
||||
<intent
|
||||
android:action="android.intent.action.MAIN"
|
||||
android:targetPackage="com.android.cellbroadcastreceiver"
|
||||
|
@@ -16,22 +16,18 @@
|
||||
|
||||
package com.android.settings.notification;
|
||||
|
||||
import android.app.NotificationManager;
|
||||
import android.content.Context;
|
||||
import android.support.v7.preference.Preference;
|
||||
import com.android.settings.R;
|
||||
|
||||
public class ZenModePreferenceController extends AdjustVolumeRestrictedPreferenceController {
|
||||
|
||||
private static final String KEY_ZEN_MODE = "zen_mode";
|
||||
private String mSummaryPrefix;
|
||||
|
||||
private ZenModeSettings.SummaryBuilder mSummaryBuilder;
|
||||
|
||||
public ZenModePreferenceController(Context context) {
|
||||
super(context);
|
||||
mSummaryBuilder = new ZenModeSettings.SummaryBuilder(context);
|
||||
mSummaryPrefix = context.getString(R.string.zen_mode_priority_settings_title) + " ";
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -48,8 +44,7 @@ public class ZenModePreferenceController extends AdjustVolumeRestrictedPreferenc
|
||||
public void updateState(Preference preference) {
|
||||
super.updateState(preference);
|
||||
if (preference.isEnabled()) {
|
||||
preference.setSummary(mSummaryPrefix + mSummaryBuilder.getPrioritySettingSummary(
|
||||
NotificationManager.from(mContext).getNotificationPolicy()));
|
||||
preference.setSummary(mSummaryBuilder.getAutomaticRulesSummary());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.android.settings.notification;
|
||||
|
||||
import android.app.AutomaticZenRule;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.NotificationManager.Policy;
|
||||
import android.content.Context;
|
||||
@@ -26,6 +27,9 @@ import android.support.v7.preference.PreferenceScreen;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.R;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
public class ZenModeSettings extends ZenModeSettingsBase {
|
||||
private static final String KEY_PRIORITY_SETTINGS = "priority_settings";
|
||||
@@ -137,6 +141,29 @@ public class ZenModeSettings extends ZenModeSettingsBase {
|
||||
return s;
|
||||
}
|
||||
|
||||
String getAutomaticRulesSummary() {
|
||||
final int count = getEnabledAutomaticRulesCount();
|
||||
return count == 0 ? mContext.getString(R.string.zen_mode_settings_summary_off)
|
||||
: mContext.getResources().getQuantityString(
|
||||
R.plurals.zen_mode_settings_summary_on, count, count);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
int getEnabledAutomaticRulesCount() {
|
||||
int count = 0;
|
||||
final Map<String, AutomaticZenRule> ruleMap =
|
||||
NotificationManager.from(mContext).getAutomaticZenRules();
|
||||
if (ruleMap != null) {
|
||||
for (Entry<String, AutomaticZenRule> ruleEntry : ruleMap.entrySet()) {
|
||||
final AutomaticZenRule rule = ruleEntry.getValue();
|
||||
if (rule != null && rule.isEnabled()) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
String append(String s, boolean condition, int resId) {
|
||||
if (condition) {
|
||||
|
@@ -21,6 +21,7 @@ import android.app.NotificationManager.Policy;
|
||||
import android.content.Context;
|
||||
import android.support.v7.preference.Preference;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
|
||||
@@ -30,11 +31,14 @@ import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.shadows.ShadowApplication;
|
||||
import org.robolectric.util.ReflectionHelpers;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Mockito.doReturn;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@@ -42,8 +46,6 @@ import static org.mockito.Mockito.when;
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class ZenModePreferenceControllerTest {
|
||||
|
||||
@Mock
|
||||
private Context mContext;
|
||||
@Mock
|
||||
private Preference mPreference;
|
||||
@Mock
|
||||
@@ -51,15 +53,21 @@ public class ZenModePreferenceControllerTest {
|
||||
@Mock
|
||||
private Policy mPolicy;
|
||||
|
||||
private Context mContext;
|
||||
private ZenModePreferenceController mController;
|
||||
private ZenModeSettings.SummaryBuilder mSummaryBuilder;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
ShadowApplication shadowApplication = ShadowApplication.getInstance();
|
||||
shadowApplication.setSystemService(Context.NOTIFICATION_SERVICE, mNotificationManager);
|
||||
mContext = shadowApplication.getApplicationContext();
|
||||
mController = new ZenModePreferenceController(mContext);
|
||||
when(mContext.getSystemService(Context.NOTIFICATION_SERVICE))
|
||||
.thenReturn(mNotificationManager);
|
||||
when(mNotificationManager.getNotificationPolicy()).thenReturn(mPolicy);
|
||||
mSummaryBuilder = spy(new ZenModeSettings.SummaryBuilder(mContext));
|
||||
ReflectionHelpers.setField(mController, "mSummaryBuilder", mSummaryBuilder);
|
||||
doReturn(0).when(mSummaryBuilder).getEnabledAutomaticRulesCount();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -72,8 +80,12 @@ public class ZenModePreferenceControllerTest {
|
||||
when(mPreference.isEnabled()).thenReturn(true);
|
||||
|
||||
mController.updateState(mPreference);
|
||||
verify(mPreference).setSummary(mContext.getString(R.string.zen_mode_settings_summary_off));
|
||||
|
||||
verify(mPreference).setSummary(anyString());
|
||||
doReturn(1).when(mSummaryBuilder).getEnabledAutomaticRulesCount();
|
||||
mController.updateState(mPreference);
|
||||
verify(mPreference).setSummary(mContext.getResources().getQuantityString(
|
||||
R.plurals.zen_mode_settings_summary_on, 1, 1));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Reference in New Issue
Block a user