Merge "Always show custom zen vis eff option"

This commit is contained in:
Beverly Tai
2018-05-14 20:23:31 +00:00
committed by Android (Google) Code Review
8 changed files with 32 additions and 88 deletions

View File

@@ -7931,6 +7931,9 @@
<!-- [CHAR LIMIT=20] Zen mode settings: Calls option -->
<string name="zen_mode_calls">Calls</string>
<!-- [CHAR LIMIT=40] Zen mode settings: Allow calls toggle title -->
<string name="zen_mode_calls_title">Allow calls</string>
<!-- [CHAR LIMIT=20] Zen mode settings: Calls screen footer -->
<string name="zen_mode_calls_footer">When Do Not Disturb is on, incoming calls are blocked. You can adjust settings to allow your friends, family, or other contacts to reach you.</string>
@@ -7946,6 +7949,9 @@
<!-- [CHAR LIMIT=20] Zen mode settings: Messages option -->
<string name="zen_mode_messages">Messages</string>
<!-- [CHAR LIMIT=40] Zen mode settings: Allow messages toggle title -->
<string name="zen_mode_messages_title">Allow messages</string>
<!-- [CHAR LIMIT=50] Zen mode settings: All messages summary -->
<string name="zen_mode_all_messages">Messages</string>
@@ -7985,9 +7991,15 @@
<!-- [CHAR LIMIT=50] Zen mode settings: Reminders option -->
<string name="zen_mode_reminders">Reminders</string>
<!-- [CHAR LIMIT=70] Zen mode settings: Allow reminders toggle title -->
<string name="zen_mode_reminders_title">Allow reminders</string>
<!-- [CHAR LIMIT=50] Zen mode settings: Events option -->
<string name="zen_mode_events">Events</string>
<!-- [CHAR LIMIT=70] Zen mode settings: Allow events toggle title -->
<string name="zen_mode_events_title">Allow events</string>
<!-- [CHAR LIMIT=50] Zen mode settings: All callers summary -->
<string name="zen_mode_all_callers">anyone</string>
@@ -8000,8 +8012,11 @@
<!-- [CHAR LIMIT=50] Zen mode settings: Repeat callers option -->
<string name="zen_mode_repeat_callers">Repeat callers</string>
<!-- [CHAR LIMIT=70] Zen mode settings: Allow repeat callers toggle title -->
<string name="zen_mode_repeat_callers_title">Allow repeat callers</string>
<!-- [CHAR LIMIT=50] Zen mode settings: calls summary -->
<string name="zen_mode_calls_summary_one">From <xliff:g id="caller type" example="contacts">%1$s</xliff:g> only</string>
<string name="zen_mode_calls_summary_one">From <xliff:g id="caller type" example="contacts">%1$s</xliff:g></string>
<!-- [CHAR LIMIT=50] Zen mode settings: calls summary -->
<string name="zen_mode_calls_summary_two">From <xliff:g id="caller type" example="starred contacts">%1$s</xliff:g> and <xliff:g id="callert tpye" example="repeat callers">%2$s</xliff:g></string>

View File

@@ -26,7 +26,7 @@
<!-- Calls -->
<ListPreference
android:key="zen_mode_calls"
android:title="@string/zen_mode_calls"
android:title="@string/zen_mode_calls_title"
android:entries="@array/zen_mode_contacts_entries"
android:entryValues="@array/zen_mode_contacts_values"/>
@@ -37,7 +37,7 @@
<!-- Repeat callers -->
<SwitchPreference
android:key="zen_mode_repeat_callers"
android:title="@string/zen_mode_repeat_callers" />
android:title="@string/zen_mode_repeat_callers_title" />
</PreferenceCategory>
<com.android.settingslib.widget.FooterPreference/>

View File

@@ -26,7 +26,7 @@
<!-- Messages -->
<ListPreference
android:key="zen_mode_messages"
android:title="@string/zen_mode_messages"
android:title="@string/zen_mode_messages_title"
android:entries="@array/zen_mode_contacts_entries"
android:entryValues="@array/zen_mode_contacts_values"/>
@@ -37,12 +37,12 @@
<!-- Reminders -->
<SwitchPreference
android:key="zen_mode_reminders"
android:title="@string/zen_mode_reminders"/>
android:title="@string/zen_mode_reminders_title"/>
<!-- Events -->
<SwitchPreference
android:key="zen_mode_events"
android:title="@string/zen_mode_events"/>
android:title="@string/zen_mode_events_title"/>
</PreferenceCategory>
<com.android.settingslib.widget.FooterPreference />

View File

@@ -16,22 +16,15 @@
package com.android.settings.notification;
import static com.android.internal.logging.nano.MetricsProto.MetricsEvent.ACTION_ZEN_SHOW_CUSTOM;
import android.content.Context;
import android.os.Bundle;
import android.provider.SearchIndexableResource;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.R;
import com.android.settings.overlay.FeatureFactory;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.search.Indexable;
import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
import com.android.settingslib.core.lifecycle.Lifecycle;
import com.android.settingslib.search.SearchIndexable;
import com.android.settingslib.widget.FooterPreference;
@@ -42,67 +35,21 @@ import java.util.List;
@SearchIndexable(forTarget = SearchIndexable.ALL & ~SearchIndexable.ARC)
public class ZenModeRestrictNotificationsSettings extends ZenModeSettingsBase implements Indexable {
protected static final int APP_MENU_SHOW_CUSTOM = 1;
protected boolean mShowMenuSelected;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
menu.add(0, APP_MENU_SHOW_CUSTOM, 0, R.string.zen_mode_restrict_notifications_enable_custom)
.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
}
@Override
public boolean onOptionsItemSelected(MenuItem menuItem) {
if (menuItem.getItemId() == APP_MENU_SHOW_CUSTOM) {
final FeatureFactory featureFactory = FeatureFactory.getFactory(mContext);
MetricsFeatureProvider metrics = featureFactory.getMetricsFeatureProvider();
mShowMenuSelected = !mShowMenuSelected;
ZenModeVisEffectsCustomPreferenceController custom =
use(ZenModeVisEffectsCustomPreferenceController.class);
custom.setShownByMenu(mShowMenuSelected);
custom.displayPreference(getPreferenceScreen());
if (mShowMenuSelected) {
metrics.action(mContext, ACTION_ZEN_SHOW_CUSTOM, true);
} else {
metrics.action(mContext, ACTION_ZEN_SHOW_CUSTOM, false);
}
return true;
}
return false;
}
@Override
public void onPrepareOptionsMenu(Menu menu) {
if (mShowMenuSelected) {
menu.findItem(APP_MENU_SHOW_CUSTOM)
.setTitle(R.string.zen_mode_restrict_notifications_disable_custom);
} else {
menu.findItem(APP_MENU_SHOW_CUSTOM)
.setTitle(R.string.zen_mode_restrict_notifications_enable_custom);
}
if (mShowMenuSelected && use(ZenModeVisEffectsCustomPreferenceController.class)
.areCustomOptionsSelected()) {
menu.findItem(APP_MENU_SHOW_CUSTOM).setEnabled(false);
} else {
menu.findItem(APP_MENU_SHOW_CUSTOM).setEnabled(true);
}
}
@Override
protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
return buildPreferenceControllers(context, getLifecycle());
}
@Override
public int getHelpResource() {
return R.string.help_uri_interruptions;
}
private static List<AbstractPreferenceController> buildPreferenceControllers(Context context,
Lifecycle lifecycle) {
List<AbstractPreferenceController> controllers = new ArrayList<>();

View File

@@ -170,7 +170,7 @@ public class ZenModeSettings extends ZenModeSettingsBase {
} else if (numCategories == 2) {
return mContext.getString(R.string.join_two_items, enabledCategories.get(0),
enabledCategories.get(1).toLowerCase());
} else if (numCategories == 3) {
} else if (numCategories == 3){
final List<String> summaries = new ArrayList<>();
summaries.add(enabledCategories.get(0));
summaries.add(enabledCategories.get(1).toLowerCase());

View File

@@ -30,7 +30,6 @@ import com.android.settingslib.core.lifecycle.Lifecycle;
public class ZenModeVisEffectsCustomPreferenceController
extends AbstractZenModePreferenceController {
protected boolean mShowMenuSelected;
protected static final int INTERRUPTIVE_EFFECTS = Policy.SUPPRESSED_EFFECT_AMBIENT
| Policy.SUPPRESSED_EFFECT_PEEK
| Policy.SUPPRESSED_EFFECT_LIGHTS
@@ -43,13 +42,9 @@ public class ZenModeVisEffectsCustomPreferenceController
@Override
public boolean isAvailable() {
if (mShowMenuSelected) {
return true;
}
return areCustomOptionsSelected();
}
@Override
public void updateState(Preference preference) {
super.updateState(preference);
@@ -67,10 +62,6 @@ public class ZenModeVisEffectsCustomPreferenceController
});
}
protected void setShownByMenu(boolean shown) {
mShowMenuSelected = shown;
}
protected boolean areCustomOptionsSelected() {
boolean allEffectsSuppressed =
Policy.areAllVisualEffectsSuppressed(mBackend.mPolicy.suppressedVisualEffects);

View File

@@ -134,13 +134,13 @@ public class ZenModeSettingsTest {
public void testGetCallsSettingSummary_contacts() {
Policy policy = new Policy(Policy.PRIORITY_CATEGORY_ALARMS | Policy.PRIORITY_CATEGORY_CALLS,
Policy.PRIORITY_SENDERS_CONTACTS, 0, 0);
assertThat(mBuilder.getCallsSettingSummary(policy)).isEqualTo("From contacts only");
assertThat(mBuilder.getCallsSettingSummary(policy)).isEqualTo("From contacts");
}
@Test
public void testGetCallsSettingSummary_repeatCallers() {
Policy policy = new Policy(Policy.PRIORITY_CATEGORY_REPEAT_CALLERS, 0, 0, 0);
assertThat(mBuilder.getCallsSettingSummary(policy)).isEqualTo("From repeat callers only");
assertThat(mBuilder.getCallsSettingSummary(policy)).isEqualTo("From repeat callers");
}
@Test

View File

@@ -88,23 +88,14 @@ public class ZenModeVisEffectsCustomPreferenceControllerTest {
}
@Test
public void isAvailable_menuOff_noVisEffects() {
public void isAvailable_noVisEffects() {
mBackend.mPolicy = new NotificationManager.Policy(0, 0, 0, 0);
mController.mShowMenuSelected = false;
assertThat(mController.isAvailable()).isFalse();
}
@Test
public void isAvailable_menuOn_noVisEffects() {
mBackend.mPolicy = new NotificationManager.Policy(0, 0, 0, 0);
mController.mShowMenuSelected = true;
assertThat(mController.isAvailable()).isTrue();
}
@Test
public void isAvailable_menuOn_visEffects() {
public void isAvailable_visEffects() {
mBackend.mPolicy = new NotificationManager.Policy(0, 0, 0, 1);
mController.mShowMenuSelected = false;
assertThat(mController.isAvailable()).isTrue();
}