Update texts for Settings->Sound->Do not disturb
- Update title to "Do not disturb preferences" - Add summary text to reflect the priority only allows preferences - Refactor the summary handling in ZenModeSettings so that the controller can get the summary text Fix: 34975939 Test: make RunSettingsRoboTests Change-Id: I3ca1dc43fe1d943735a9f625e66c89708a18300a
This commit is contained in:
@@ -6168,7 +6168,7 @@
|
|||||||
<string name="boot_sounds_title">Power on sounds</string>
|
<string name="boot_sounds_title">Power on sounds</string>
|
||||||
|
|
||||||
<!-- Sound: Title for the Do not Disturb option and associated settings page. [CHAR LIMIT=30] -->
|
<!-- Sound: Title for the Do not Disturb option and associated settings page. [CHAR LIMIT=30] -->
|
||||||
<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] -->
|
<!-- 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>
|
<string name="zen_mode_priority_settings_title">Priority only allows</string>
|
||||||
|
@@ -16,14 +16,22 @@
|
|||||||
|
|
||||||
package com.android.settings.notification;
|
package com.android.settings.notification;
|
||||||
|
|
||||||
|
import android.app.NotificationManager;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.support.v7.preference.Preference;
|
||||||
|
import com.android.settings.R;
|
||||||
|
|
||||||
public class ZenModePreferenceController extends AdjustVolumeRestrictedPreferenceController {
|
public class ZenModePreferenceController extends AdjustVolumeRestrictedPreferenceController {
|
||||||
|
|
||||||
private static final String KEY_ZEN_MODE = "zen_mode";
|
private static final String KEY_ZEN_MODE = "zen_mode";
|
||||||
|
private String mSummaryPrefix;
|
||||||
|
|
||||||
|
private ZenModeSettings.SummaryBuilder mSummaryBuilder;
|
||||||
|
|
||||||
public ZenModePreferenceController(Context context) {
|
public ZenModePreferenceController(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
|
mSummaryBuilder = new ZenModeSettings.SummaryBuilder(context);
|
||||||
|
mSummaryPrefix = context.getString(R.string.zen_mode_priority_settings_title) + " ";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -36,4 +44,12 @@ public class ZenModePreferenceController extends AdjustVolumeRestrictedPreferenc
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateState(Preference preference) {
|
||||||
|
super.updateState(preference);
|
||||||
|
if (preference.isEnabled()) {
|
||||||
|
preference.setSummary(mSummaryPrefix + mSummaryBuilder.getPrioritySettingSummary(
|
||||||
|
NotificationManager.from(mContext).getNotificationPolicy()));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -34,6 +34,7 @@ public class ZenModeSettings extends ZenModeSettingsBase {
|
|||||||
private Preference mPrioritySettings;
|
private Preference mPrioritySettings;
|
||||||
private Preference mVisualSettings;
|
private Preference mVisualSettings;
|
||||||
private Policy mPolicy;
|
private Policy mPolicy;
|
||||||
|
private SummaryBuilder mSummaryBuilder;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
@@ -45,6 +46,7 @@ public class ZenModeSettings extends ZenModeSettingsBase {
|
|||||||
mPrioritySettings = root.findPreference(KEY_PRIORITY_SETTINGS);
|
mPrioritySettings = root.findPreference(KEY_PRIORITY_SETTINGS);
|
||||||
mVisualSettings = root.findPreference(KEY_VISUAL_SETTINGS);
|
mVisualSettings = root.findPreference(KEY_VISUAL_SETTINGS);
|
||||||
mPolicy = NotificationManager.from(mContext).getNotificationPolicy();
|
mPolicy = NotificationManager.from(mContext).getNotificationPolicy();
|
||||||
|
mSummaryBuilder = new SummaryBuilder(getContext());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -77,62 +79,80 @@ public class ZenModeSettings extends ZenModeSettingsBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void updatePrioritySettingsSummary() {
|
private void updatePrioritySettingsSummary() {
|
||||||
String s = getResources().getString(R.string.zen_mode_alarms);
|
mPrioritySettings.setSummary(mSummaryBuilder.getPrioritySettingSummary(mPolicy));
|
||||||
s = append(s, isCategoryEnabled(mPolicy, Policy.PRIORITY_CATEGORY_REMINDERS),
|
|
||||||
R.string.zen_mode_reminders);
|
|
||||||
s = append(s, isCategoryEnabled(mPolicy, Policy.PRIORITY_CATEGORY_EVENTS),
|
|
||||||
R.string.zen_mode_events);
|
|
||||||
if (isCategoryEnabled(mPolicy, Policy.PRIORITY_CATEGORY_MESSAGES)) {
|
|
||||||
if (mPolicy.priorityMessageSenders == Policy.PRIORITY_SENDERS_ANY) {
|
|
||||||
s = append(s, true, R.string.zen_mode_all_messages);
|
|
||||||
} else {
|
|
||||||
s = append(s, true, R.string.zen_mode_selected_messages);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (isCategoryEnabled(mPolicy, Policy.PRIORITY_CATEGORY_CALLS)) {
|
|
||||||
if (mPolicy.priorityCallSenders == Policy.PRIORITY_SENDERS_ANY) {
|
|
||||||
s = append(s, true, R.string.zen_mode_all_callers);
|
|
||||||
} else {
|
|
||||||
s = append(s, true, R.string.zen_mode_selected_callers);
|
|
||||||
}
|
|
||||||
} else if (isCategoryEnabled(mPolicy, Policy.PRIORITY_CATEGORY_REPEAT_CALLERS)) {
|
|
||||||
s = append(s, true, R.string.zen_mode_repeat_callers);
|
|
||||||
}
|
|
||||||
mPrioritySettings.setSummary(s);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateVisualSettingsSummary() {
|
private void updateVisualSettingsSummary() {
|
||||||
String s = getString(R.string.zen_mode_all_visual_interruptions);
|
mVisualSettings.setSummary(mSummaryBuilder.getVisualSettingSummary(mPolicy));
|
||||||
if (isEffectSuppressed(Policy.SUPPRESSED_EFFECT_SCREEN_ON)
|
|
||||||
&& isEffectSuppressed(Policy.SUPPRESSED_EFFECT_SCREEN_OFF)) {
|
|
||||||
s = getString(R.string.zen_mode_no_visual_interruptions);
|
|
||||||
} else if (isEffectSuppressed(Policy.SUPPRESSED_EFFECT_SCREEN_ON)) {
|
|
||||||
s = getString(R.string.zen_mode_screen_on_visual_interruptions);
|
|
||||||
} else if (isEffectSuppressed(Policy.SUPPRESSED_EFFECT_SCREEN_OFF)) {
|
|
||||||
s = getString(R.string.zen_mode_screen_off_visual_interruptions);
|
|
||||||
}
|
|
||||||
mVisualSettings.setSummary(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isEffectSuppressed(int effect) {
|
|
||||||
return (mPolicy.suppressedVisualEffects & effect) != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isCategoryEnabled(Policy policy, int categoryType) {
|
|
||||||
return (policy.priorityCategories & categoryType) != 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
@VisibleForTesting
|
|
||||||
String append(String s, boolean condition, int resId) {
|
|
||||||
if (condition) {
|
|
||||||
final Context context = getContext();
|
|
||||||
return context.getString(R.string.join_many_items_middle, s, context.getString(resId));
|
|
||||||
}
|
|
||||||
return s;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected int getHelpResource() {
|
protected int getHelpResource() {
|
||||||
return R.string.help_uri_interruptions;
|
return R.string.help_uri_interruptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class SummaryBuilder {
|
||||||
|
|
||||||
|
private Context mContext;
|
||||||
|
|
||||||
|
public SummaryBuilder(Context context) {
|
||||||
|
mContext = context;
|
||||||
|
}
|
||||||
|
|
||||||
|
String getPrioritySettingSummary(Policy policy) {
|
||||||
|
String s = mContext.getString(R.string.zen_mode_alarms);
|
||||||
|
s = append(s, isCategoryEnabled(policy, Policy.PRIORITY_CATEGORY_REMINDERS),
|
||||||
|
R.string.zen_mode_reminders);
|
||||||
|
s = append(s, isCategoryEnabled(policy, Policy.PRIORITY_CATEGORY_EVENTS),
|
||||||
|
R.string.zen_mode_events);
|
||||||
|
if (isCategoryEnabled(policy, Policy.PRIORITY_CATEGORY_MESSAGES)) {
|
||||||
|
if (policy.priorityMessageSenders == Policy.PRIORITY_SENDERS_ANY) {
|
||||||
|
s = append(s, true, R.string.zen_mode_all_messages);
|
||||||
|
} else {
|
||||||
|
s = append(s, true, R.string.zen_mode_selected_messages);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (isCategoryEnabled(policy, Policy.PRIORITY_CATEGORY_CALLS)) {
|
||||||
|
if (policy.priorityCallSenders == Policy.PRIORITY_SENDERS_ANY) {
|
||||||
|
s = append(s, true, R.string.zen_mode_all_callers);
|
||||||
|
} else {
|
||||||
|
s = append(s, true, R.string.zen_mode_selected_callers);
|
||||||
|
}
|
||||||
|
} else if (isCategoryEnabled(policy, Policy.PRIORITY_CATEGORY_REPEAT_CALLERS)) {
|
||||||
|
s = append(s, true, R.string.zen_mode_repeat_callers);
|
||||||
|
}
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
String getVisualSettingSummary(Policy policy) {
|
||||||
|
String s = mContext.getString(R.string.zen_mode_all_visual_interruptions);
|
||||||
|
if (isEffectSuppressed(policy, Policy.SUPPRESSED_EFFECT_SCREEN_ON)
|
||||||
|
&& isEffectSuppressed(policy, Policy.SUPPRESSED_EFFECT_SCREEN_OFF)) {
|
||||||
|
s = mContext.getString(R.string.zen_mode_no_visual_interruptions);
|
||||||
|
} else if (isEffectSuppressed(policy, Policy.SUPPRESSED_EFFECT_SCREEN_ON)) {
|
||||||
|
s = mContext.getString(R.string.zen_mode_screen_on_visual_interruptions);
|
||||||
|
} else if (isEffectSuppressed(policy, Policy.SUPPRESSED_EFFECT_SCREEN_OFF)) {
|
||||||
|
s = mContext.getString(R.string.zen_mode_screen_off_visual_interruptions);
|
||||||
|
}
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
String append(String s, boolean condition, int resId) {
|
||||||
|
if (condition) {
|
||||||
|
return mContext.getString(
|
||||||
|
R.string.join_many_items_middle, s, mContext.getString(resId));
|
||||||
|
}
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isCategoryEnabled(Policy policy, int categoryType) {
|
||||||
|
return (policy.priorityCategories & categoryType) != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isEffectSuppressed(Policy policy, int effect) {
|
||||||
|
return (policy.suppressedVisualEffects & effect) != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -16,7 +16,10 @@
|
|||||||
|
|
||||||
package com.android.settings.notification;
|
package com.android.settings.notification;
|
||||||
|
|
||||||
|
import android.app.NotificationManager;
|
||||||
|
import android.app.NotificationManager.Policy;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.support.v7.preference.Preference;
|
||||||
|
|
||||||
import com.android.settings.SettingsRobolectricTestRunner;
|
import com.android.settings.SettingsRobolectricTestRunner;
|
||||||
import com.android.settings.TestConfig;
|
import com.android.settings.TestConfig;
|
||||||
@@ -27,8 +30,13 @@ import org.junit.runner.RunWith;
|
|||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.MockitoAnnotations;
|
import org.mockito.MockitoAnnotations;
|
||||||
import org.robolectric.annotation.Config;
|
import org.robolectric.annotation.Config;
|
||||||
|
import org.robolectric.util.ReflectionHelpers;
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
import static org.mockito.Matchers.anyString;
|
||||||
|
import static org.mockito.Mockito.never;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
@RunWith(SettingsRobolectricTestRunner.class)
|
@RunWith(SettingsRobolectricTestRunner.class)
|
||||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||||
@@ -36,6 +44,12 @@ public class ZenModePreferenceControllerTest {
|
|||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
|
@Mock
|
||||||
|
private Preference mPreference;
|
||||||
|
@Mock
|
||||||
|
private NotificationManager mNotificationManager;
|
||||||
|
@Mock
|
||||||
|
private Policy mPolicy;
|
||||||
|
|
||||||
private ZenModePreferenceController mController;
|
private ZenModePreferenceController mController;
|
||||||
|
|
||||||
@@ -43,6 +57,9 @@ public class ZenModePreferenceControllerTest {
|
|||||||
public void setUp() {
|
public void setUp() {
|
||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
mController = new ZenModePreferenceController(mContext);
|
mController = new ZenModePreferenceController(mContext);
|
||||||
|
when(mContext.getSystemService(Context.NOTIFICATION_SERVICE))
|
||||||
|
.thenReturn(mNotificationManager);
|
||||||
|
when(mNotificationManager.getNotificationPolicy()).thenReturn(mPolicy);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -50,4 +67,22 @@ public class ZenModePreferenceControllerTest {
|
|||||||
assertThat(mController.isAvailable()).isTrue();
|
assertThat(mController.isAvailable()).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void updateState_preferenceEnabled_shouldSetSummary() {
|
||||||
|
when(mPreference.isEnabled()).thenReturn(true);
|
||||||
|
|
||||||
|
mController.updateState(mPreference);
|
||||||
|
|
||||||
|
verify(mPreference).setSummary(anyString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void updateState_preferenceDisabled_shouldNotSetSummary() {
|
||||||
|
when(mPreference.isEnabled()).thenReturn(false);
|
||||||
|
|
||||||
|
mController.updateState(mPreference);
|
||||||
|
|
||||||
|
verify(mPreference, never()).setSummary(anyString());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -36,21 +36,20 @@ import static org.mockito.Mockito.spy;
|
|||||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||||
public class ZenModeSettingsTest {
|
public class ZenModeSettingsTest {
|
||||||
|
|
||||||
private ZenModeSettings mSettings;
|
private ZenModeSettings.SummaryBuilder mBuilder;
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
mContext = RuntimeEnvironment.application.getApplicationContext();
|
mContext = RuntimeEnvironment.application.getApplicationContext();
|
||||||
mSettings = spy(ZenModeSettings.class);
|
mBuilder = new ZenModeSettings.SummaryBuilder(mContext);
|
||||||
doReturn(mContext).when(mSettings).getContext();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAppend_conditionFalse_shouldNotAppend() {
|
public void testAppend_conditionFalse_shouldNotAppend() {
|
||||||
String original = "test";
|
String original = "test";
|
||||||
|
|
||||||
final String result = mSettings.append(original, false, R.string.zen_mode_alarms);
|
final String result = mBuilder.append(original, false, R.string.zen_mode_alarms);
|
||||||
|
|
||||||
assertThat(result).isEqualTo(original);
|
assertThat(result).isEqualTo(original);
|
||||||
}
|
}
|
||||||
@@ -60,7 +59,7 @@ public class ZenModeSettingsTest {
|
|||||||
String original = "test";
|
String original = "test";
|
||||||
String alarm = mContext.getString(R.string.zen_mode_alarms);
|
String alarm = mContext.getString(R.string.zen_mode_alarms);
|
||||||
|
|
||||||
final String result = mSettings.append(original, true, R.string.zen_mode_alarms);
|
final String result = mBuilder.append(original, true, R.string.zen_mode_alarms);
|
||||||
|
|
||||||
assertThat(result).contains(alarm);
|
assertThat(result).contains(alarm);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user