Dnd settings pages redesign (round 1)
Test: make RunSettingsRoboTests -j40 Bug: 111475013 Change-Id: Idb6bbfdfe377b61a8fe1f7e81171bbefe23a4ebf
This commit is contained in:
@@ -21,19 +21,20 @@ import android.content.Context;
|
||||
import android.provider.Settings;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.SwitchPreference;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.SwitchPreference;
|
||||
|
||||
public class ZenModeAlarmsPreferenceController extends
|
||||
AbstractZenModePreferenceController implements Preference.OnPreferenceChangeListener {
|
||||
|
||||
protected static final String KEY = "zen_mode_alarms";
|
||||
private final String KEY;
|
||||
|
||||
public ZenModeAlarmsPreferenceController(Context context, Lifecycle lifecycle) {
|
||||
super(context, KEY, lifecycle);
|
||||
public ZenModeAlarmsPreferenceController(Context context, Lifecycle lifecycle, String key) {
|
||||
super(context, key, lifecycle);
|
||||
KEY = key;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -1,53 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.notification;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import com.android.settings.core.PreferenceControllerMixin;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
|
||||
public class ZenModeBehaviorCallsPreferenceController extends
|
||||
AbstractZenModePreferenceController implements PreferenceControllerMixin {
|
||||
|
||||
protected static final String KEY_BEHAVIOR_SETTINGS = "zen_mode_calls_settings";
|
||||
private final ZenModeSettings.SummaryBuilder mSummaryBuilder;
|
||||
|
||||
public ZenModeBehaviorCallsPreferenceController(Context context, Lifecycle lifecycle) {
|
||||
super(context, KEY_BEHAVIOR_SETTINGS, lifecycle);
|
||||
mSummaryBuilder = new ZenModeSettings.SummaryBuilder(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferenceKey() {
|
||||
return KEY_BEHAVIOR_SETTINGS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateState(Preference preference) {
|
||||
super.updateState(preference);
|
||||
|
||||
preference.setSummary(mSummaryBuilder.getCallsSettingSummary(getPolicy()));
|
||||
}
|
||||
}
|
@@ -1,54 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.notification;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import com.android.settings.core.PreferenceControllerMixin;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
|
||||
public class ZenModeBehaviorMsgEventReminderPreferenceController extends
|
||||
AbstractZenModePreferenceController implements PreferenceControllerMixin {
|
||||
|
||||
protected static final String KEY_BEHAVIOR_SETTINGS = "zen_mode_msg_event_reminder_settings";
|
||||
private final ZenModeSettings.SummaryBuilder mSummaryBuilder;
|
||||
|
||||
public ZenModeBehaviorMsgEventReminderPreferenceController(Context context,
|
||||
Lifecycle lifecycle) {
|
||||
super(context, KEY_BEHAVIOR_SETTINGS, lifecycle);
|
||||
mSummaryBuilder = new ZenModeSettings.SummaryBuilder(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferenceKey() {
|
||||
return KEY_BEHAVIOR_SETTINGS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateState(Preference preference) {
|
||||
super.updateState(preference);
|
||||
|
||||
preference.setSummary(mSummaryBuilder.getMsgEventReminderSettingSummary(getPolicy()));
|
||||
}
|
||||
}
|
@@ -1,53 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2018 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.notification;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.preference.Preference;
|
||||
|
||||
import com.android.settings.core.PreferenceControllerMixin;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
|
||||
public class ZenModeBehaviorSoundPreferenceController extends
|
||||
AbstractZenModePreferenceController implements PreferenceControllerMixin {
|
||||
|
||||
protected static final String KEY_BEHAVIOR_SETTINGS = "zen_sound_vibration_settings";
|
||||
private final ZenModeSettings.SummaryBuilder mSummaryBuilder;
|
||||
|
||||
public ZenModeBehaviorSoundPreferenceController(Context context, Lifecycle lifecycle) {
|
||||
super(context, KEY_BEHAVIOR_SETTINGS, lifecycle);
|
||||
mSummaryBuilder = new ZenModeSettings.SummaryBuilder(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferenceKey() {
|
||||
return KEY_BEHAVIOR_SETTINGS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateState(Preference preference) {
|
||||
super.updateState(preference);
|
||||
|
||||
preference.setSummary(mSummaryBuilder.getSoundSettingSummary(getPolicy()));
|
||||
}
|
||||
}
|
@@ -16,36 +16,29 @@
|
||||
|
||||
package com.android.settings.notification;
|
||||
|
||||
import android.app.NotificationManager;
|
||||
import android.content.Context;
|
||||
import android.provider.Settings;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.preference.ListPreference;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.PreferenceControllerMixin;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
|
||||
public class ZenModeCallsPreferenceController extends AbstractZenModePreferenceController implements
|
||||
Preference.OnPreferenceChangeListener {
|
||||
import androidx.preference.Preference;
|
||||
|
||||
protected static final String KEY = "zen_mode_calls";
|
||||
private final ZenModeBackend mBackend;
|
||||
private ListPreference mPreference;
|
||||
private final String[] mListValues;
|
||||
public class ZenModeCallsPreferenceController extends
|
||||
AbstractZenModePreferenceController implements PreferenceControllerMixin {
|
||||
|
||||
public ZenModeCallsPreferenceController(Context context, Lifecycle lifecycle) {
|
||||
super(context, KEY, lifecycle);
|
||||
mBackend = ZenModeBackend.getInstance(context);
|
||||
mListValues = context.getResources().getStringArray(R.array.zen_mode_contacts_values);
|
||||
private final String KEY_BEHAVIOR_SETTINGS;
|
||||
private final ZenModeSettings.SummaryBuilder mSummaryBuilder;
|
||||
|
||||
public ZenModeCallsPreferenceController(Context context, Lifecycle lifecycle,
|
||||
String key) {
|
||||
super(context, key, lifecycle);
|
||||
KEY_BEHAVIOR_SETTINGS = key;
|
||||
mSummaryBuilder = new ZenModeSettings.SummaryBuilder(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferenceKey() {
|
||||
return KEY;
|
||||
return KEY_BEHAVIOR_SETTINGS;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -53,55 +46,10 @@ public class ZenModeCallsPreferenceController extends AbstractZenModePreferenceC
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
mPreference = (ListPreference) screen.findPreference(KEY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateState(Preference preference) {
|
||||
super.updateState(preference);
|
||||
updateFromContactsValue(preference);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object selectedContactsFrom) {
|
||||
mBackend.saveSenders(NotificationManager.Policy.PRIORITY_CATEGORY_CALLS,
|
||||
ZenModeBackend.getSettingFromPrefKey(selectedContactsFrom.toString()));
|
||||
updateFromContactsValue(preference);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void updateFromContactsValue(Preference preference) {
|
||||
mPreference = (ListPreference) preference;
|
||||
switch (getZenMode()) {
|
||||
case Settings.Global.ZEN_MODE_NO_INTERRUPTIONS:
|
||||
case Settings.Global.ZEN_MODE_ALARMS:
|
||||
mPreference.setEnabled(false);
|
||||
mPreference.setValue(ZenModeBackend.ZEN_MODE_FROM_NONE);
|
||||
mPreference.setSummary(mBackend.getContactsSummary(ZenModeBackend.SOURCE_NONE));
|
||||
break;
|
||||
default:
|
||||
preference.setEnabled(true);
|
||||
preference.setSummary(mBackend.getContactsSummary(
|
||||
NotificationManager.Policy.PRIORITY_CATEGORY_CALLS));
|
||||
|
||||
final String currentVal = ZenModeBackend.getKeyFromSetting(
|
||||
mBackend.getPriorityCallSenders());
|
||||
mPreference.setValue(mListValues[getIndexOfSendersValue(currentVal)]);
|
||||
}
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
protected int getIndexOfSendersValue(String currentVal) {
|
||||
int index = 3; // defaults to "none" based on R.array.zen_mode_contacts_values
|
||||
for (int i = 0; i < mListValues.length; i++) {
|
||||
if (TextUtils.equals(currentVal, mListValues[i])) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return index;
|
||||
preference.setSummary(mSummaryBuilder.getCallsSettingSummary(getPolicy()));
|
||||
}
|
||||
}
|
||||
|
@@ -43,7 +43,7 @@ public class ZenModeCallsSettings extends ZenModeSettingsBase implements Indexab
|
||||
private static List<AbstractPreferenceController> buildPreferenceControllers(Context context,
|
||||
Lifecycle lifecycle) {
|
||||
List<AbstractPreferenceController> controllers = new ArrayList<>();
|
||||
controllers.add(new ZenModeCallsPreferenceController(context, lifecycle));
|
||||
controllers.add(new ZenModePriorityCallsPreferenceController(context, lifecycle));
|
||||
controllers.add(new ZenModeStarredContactsPreferenceController(context, lifecycle,
|
||||
PRIORITY_CATEGORY_CALLS, "zen_mode_starred_contacts_callers"));
|
||||
controllers.add(new ZenModeRepeatCallersPreferenceController(context, lifecycle,
|
||||
|
@@ -1,31 +1,38 @@
|
||||
/*
|
||||
* Copyright (C) 2018 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.notification;
|
||||
|
||||
import android.app.NotificationManager;
|
||||
import android.content.Context;
|
||||
import android.provider.Settings;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.preference.ListPreference;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.core.PreferenceControllerMixin;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
|
||||
public class ZenModeMessagesPreferenceController extends AbstractZenModePreferenceController
|
||||
implements Preference.OnPreferenceChangeListener {
|
||||
import androidx.preference.Preference;
|
||||
|
||||
protected static final String KEY = "zen_mode_messages";
|
||||
public class ZenModeMessagesPreferenceController extends
|
||||
AbstractZenModePreferenceController implements PreferenceControllerMixin {
|
||||
|
||||
private final ZenModeBackend mBackend;
|
||||
private ListPreference mPreference;
|
||||
private final String[] mListValues;
|
||||
private final String KEY;
|
||||
private final ZenModeSettings.SummaryBuilder mSummaryBuilder;
|
||||
|
||||
public ZenModeMessagesPreferenceController(Context context, Lifecycle lifecycle) {
|
||||
super(context, KEY, lifecycle);
|
||||
mBackend = ZenModeBackend.getInstance(context);
|
||||
mListValues = context.getResources().getStringArray(R.array.zen_mode_contacts_values);
|
||||
public ZenModeMessagesPreferenceController(Context context, Lifecycle lifecycle, String key) {
|
||||
super(context, key, lifecycle);
|
||||
KEY = key;
|
||||
mSummaryBuilder = new ZenModeSettings.SummaryBuilder(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -38,55 +45,9 @@ public class ZenModeMessagesPreferenceController extends AbstractZenModePreferen
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
mPreference = (ListPreference) screen.findPreference(KEY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateState(Preference preference) {
|
||||
super.updateState(preference);
|
||||
updateFromContactsValue(preference);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object selectedContactsFrom) {
|
||||
mBackend.saveSenders(NotificationManager.Policy.PRIORITY_CATEGORY_MESSAGES,
|
||||
ZenModeBackend.getSettingFromPrefKey(selectedContactsFrom.toString()));
|
||||
updateFromContactsValue(preference);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void updateFromContactsValue(Preference preference) {
|
||||
mPreference = (ListPreference) preference;
|
||||
switch (getZenMode()) {
|
||||
case Settings.Global.ZEN_MODE_NO_INTERRUPTIONS:
|
||||
case Settings.Global.ZEN_MODE_ALARMS:
|
||||
mPreference.setEnabled(false);
|
||||
mPreference.setValue(ZenModeBackend.ZEN_MODE_FROM_NONE);
|
||||
mPreference.setSummary(mBackend.getContactsSummary(ZenModeBackend.SOURCE_NONE));
|
||||
break;
|
||||
default:
|
||||
preference.setEnabled(true);
|
||||
preference.setSummary(mBackend.getContactsSummary(
|
||||
NotificationManager.Policy.PRIORITY_CATEGORY_MESSAGES));
|
||||
|
||||
final String currentVal = ZenModeBackend.getKeyFromSetting(
|
||||
mBackend.getPriorityMessageSenders());
|
||||
mPreference.setValue(mListValues[getIndexOfSendersValue(currentVal)]);
|
||||
}
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
protected int getIndexOfSendersValue(String currentVal) {
|
||||
int index = 3; // defaults to "none" based on R.array.zen_mode_contacts_values
|
||||
for (int i = 0; i < mListValues.length; i++) {
|
||||
if (TextUtils.equals(currentVal, mListValues[i])) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return index;
|
||||
// TODO: (b/111475013 - beverlyt) set messages summary
|
||||
}
|
||||
}
|
||||
|
@@ -33,7 +33,7 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@SearchIndexable
|
||||
public class ZenModeMsgEventReminderSettings extends ZenModeSettingsBase implements Indexable {
|
||||
public class ZenModeMessagesSettings extends ZenModeSettingsBase implements Indexable {
|
||||
|
||||
@Override
|
||||
protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
|
||||
@@ -43,19 +43,17 @@ public class ZenModeMsgEventReminderSettings extends ZenModeSettingsBase impleme
|
||||
private static List<AbstractPreferenceController> buildPreferenceControllers(Context context,
|
||||
Lifecycle lifecycle) {
|
||||
List<AbstractPreferenceController> controllers = new ArrayList<>();
|
||||
controllers.add(new ZenModeEventsPreferenceController(context, lifecycle));
|
||||
controllers.add(new ZenModeRemindersPreferenceController(context, lifecycle));
|
||||
controllers.add(new ZenModeMessagesPreferenceController(context, lifecycle));
|
||||
controllers.add(new ZenModePriorityMessagesPreferenceController(context, lifecycle));
|
||||
controllers.add(new ZenModeStarredContactsPreferenceController(context, lifecycle,
|
||||
PRIORITY_CATEGORY_MESSAGES, "zen_mode_starred_contacts_messages"));
|
||||
controllers.add(new ZenModeBehaviorFooterPreferenceController(context, lifecycle,
|
||||
R.string.zen_msg_event_reminder_footer));
|
||||
controllers.add(new ZenModeBehaviorFooterPreferenceController(
|
||||
context, lifecycle, R.string.zen_mode_messages_footer));
|
||||
return controllers;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getPreferenceScreenResId() {
|
||||
return R.xml.zen_mode_msg_event_reminder_settings;
|
||||
return R.xml.zen_mode_messages_settings;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -66,7 +64,7 @@ public class ZenModeMsgEventReminderSettings extends ZenModeSettingsBase impleme
|
||||
/**
|
||||
* For Search.
|
||||
*/
|
||||
public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||
public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
||||
new BaseSearchIndexProvider() {
|
||||
|
||||
@Override
|
||||
@@ -75,14 +73,15 @@ public class ZenModeMsgEventReminderSettings extends ZenModeSettingsBase impleme
|
||||
final ArrayList<SearchIndexableResource> result = new ArrayList<>();
|
||||
|
||||
final SearchIndexableResource sir = new SearchIndexableResource(context);
|
||||
sir.xmlResId = R.xml.zen_mode_msg_event_reminder_settings;
|
||||
sir.xmlResId = R.xml.zen_mode_messages_settings;
|
||||
result.add(sir);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<AbstractPreferenceController> createPreferenceControllers(Context context) {
|
||||
return buildPreferenceControllers(context, null);
|
||||
}
|
||||
};
|
||||
@Override
|
||||
public List<AbstractPreferenceController> createPreferenceControllers(
|
||||
Context context) {
|
||||
return buildPreferenceControllers(context, null);
|
||||
}
|
||||
};
|
||||
}
|
@@ -0,0 +1,107 @@
|
||||
/*
|
||||
* Copyright (C) 2018 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.notification;
|
||||
|
||||
import android.app.NotificationManager;
|
||||
import android.content.Context;
|
||||
import android.provider.Settings;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.preference.ListPreference;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
public class ZenModePriorityCallsPreferenceController extends AbstractZenModePreferenceController
|
||||
implements Preference.OnPreferenceChangeListener {
|
||||
|
||||
protected static final String KEY = "zen_mode_calls";
|
||||
private final ZenModeBackend mBackend;
|
||||
private ListPreference mPreference;
|
||||
private final String[] mListValues;
|
||||
|
||||
public ZenModePriorityCallsPreferenceController(Context context, Lifecycle lifecycle) {
|
||||
super(context, KEY, lifecycle);
|
||||
mBackend = ZenModeBackend.getInstance(context);
|
||||
mListValues = context.getResources().getStringArray(R.array.zen_mode_contacts_values);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferenceKey() {
|
||||
return KEY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
mPreference = (ListPreference) screen.findPreference(KEY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateState(Preference preference) {
|
||||
super.updateState(preference);
|
||||
updateFromContactsValue(preference);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object selectedContactsFrom) {
|
||||
mBackend.saveSenders(NotificationManager.Policy.PRIORITY_CATEGORY_CALLS,
|
||||
ZenModeBackend.getSettingFromPrefKey(selectedContactsFrom.toString()));
|
||||
updateFromContactsValue(preference);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void updateFromContactsValue(Preference preference) {
|
||||
mPreference = (ListPreference) preference;
|
||||
switch (getZenMode()) {
|
||||
case Settings.Global.ZEN_MODE_NO_INTERRUPTIONS:
|
||||
case Settings.Global.ZEN_MODE_ALARMS:
|
||||
mPreference.setEnabled(false);
|
||||
mPreference.setValue(ZenModeBackend.ZEN_MODE_FROM_NONE);
|
||||
mPreference.setSummary(mBackend.getContactsSummary(ZenModeBackend.SOURCE_NONE));
|
||||
break;
|
||||
default:
|
||||
preference.setEnabled(true);
|
||||
preference.setSummary(mBackend.getContactsSummary(
|
||||
NotificationManager.Policy.PRIORITY_CATEGORY_CALLS));
|
||||
|
||||
final String currentVal = ZenModeBackend.getKeyFromSetting(
|
||||
mBackend.getPriorityCallSenders());
|
||||
mPreference.setValue(mListValues[getIndexOfSendersValue(currentVal)]);
|
||||
}
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
protected int getIndexOfSendersValue(String currentVal) {
|
||||
int index = 3; // defaults to "none" based on R.array.zen_mode_contacts_values
|
||||
for (int i = 0; i < mListValues.length; i++) {
|
||||
if (TextUtils.equals(currentVal, mListValues[i])) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return index;
|
||||
}
|
||||
}
|
@@ -0,0 +1,107 @@
|
||||
/*
|
||||
* Copyright (C) 2018 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.notification;
|
||||
|
||||
import android.app.NotificationManager;
|
||||
import android.content.Context;
|
||||
import android.provider.Settings;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settingslib.core.lifecycle.Lifecycle;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.preference.ListPreference;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceScreen;
|
||||
|
||||
public class ZenModePriorityMessagesPreferenceController extends AbstractZenModePreferenceController
|
||||
implements Preference.OnPreferenceChangeListener {
|
||||
|
||||
protected static final String KEY = "zen_mode_messages";
|
||||
private final ZenModeBackend mBackend;
|
||||
private ListPreference mPreference;
|
||||
private final String[] mListValues;
|
||||
|
||||
public ZenModePriorityMessagesPreferenceController(Context context, Lifecycle lifecycle) {
|
||||
super(context, KEY, lifecycle);
|
||||
mBackend = ZenModeBackend.getInstance(context);
|
||||
mListValues = context.getResources().getStringArray(R.array.zen_mode_contacts_values);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPreferenceKey() {
|
||||
return KEY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAvailable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void displayPreference(PreferenceScreen screen) {
|
||||
super.displayPreference(screen);
|
||||
mPreference = (ListPreference) screen.findPreference(KEY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateState(Preference preference) {
|
||||
super.updateState(preference);
|
||||
updateFromContactsValue(preference);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object selectedContactsFrom) {
|
||||
mBackend.saveSenders(NotificationManager.Policy.PRIORITY_CATEGORY_MESSAGES,
|
||||
ZenModeBackend.getSettingFromPrefKey(selectedContactsFrom.toString()));
|
||||
updateFromContactsValue(preference);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void updateFromContactsValue(Preference preference) {
|
||||
mPreference = (ListPreference) preference;
|
||||
switch (getZenMode()) {
|
||||
case Settings.Global.ZEN_MODE_NO_INTERRUPTIONS:
|
||||
case Settings.Global.ZEN_MODE_ALARMS:
|
||||
mPreference.setEnabled(false);
|
||||
mPreference.setValue(ZenModeBackend.ZEN_MODE_FROM_NONE);
|
||||
mPreference.setSummary(mBackend.getContactsSummary(ZenModeBackend.SOURCE_NONE));
|
||||
break;
|
||||
default:
|
||||
preference.setEnabled(true);
|
||||
preference.setSummary(mBackend.getContactsSummary(
|
||||
NotificationManager.Policy.PRIORITY_CATEGORY_MESSAGES));
|
||||
|
||||
final String currentVal = ZenModeBackend.getKeyFromSetting(
|
||||
mBackend.getPriorityMessageSenders());
|
||||
mPreference.setValue(mListValues[getIndexOfSendersValue(currentVal)]);
|
||||
}
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
protected int getIndexOfSendersValue(String currentVal) {
|
||||
int index = 3; // defaults to "none" based on R.array.zen_mode_contacts_values
|
||||
for (int i = 0; i < mListValues.length; i++) {
|
||||
if (TextUtils.equals(currentVal, mListValues[i])) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return index;
|
||||
}
|
||||
}
|
@@ -82,9 +82,12 @@ public class ZenModeSettings extends ZenModeSettingsBase {
|
||||
private static List<AbstractPreferenceController> buildPreferenceControllers(Context context,
|
||||
Lifecycle lifecycle, FragmentManager fragmentManager) {
|
||||
List<AbstractPreferenceController> controllers = new ArrayList<>();
|
||||
controllers.add(new ZenModeBehaviorMsgEventReminderPreferenceController(context, lifecycle));
|
||||
controllers.add(new ZenModeBehaviorSoundPreferenceController(context, lifecycle));
|
||||
controllers.add(new ZenModeBehaviorCallsPreferenceController(context, lifecycle));
|
||||
controllers.add(new ZenModeCallsPreferenceController(context, lifecycle,
|
||||
"zen_mode_behavior_calls"));
|
||||
controllers.add(new ZenModeMessagesPreferenceController(context, lifecycle,
|
||||
"zen_mode_behavior_messages"));
|
||||
controllers.add(new ZenModeAlarmsPreferenceController(context, lifecycle,
|
||||
"zen_mode_behavior_alarms"));
|
||||
controllers.add(new ZenModeBlockedEffectsPreferenceController(context, lifecycle));
|
||||
controllers.add(new ZenModeDurationPreferenceController(context, lifecycle));
|
||||
controllers.add(new ZenModeAutomationPreferenceController(context));
|
||||
|
@@ -16,6 +16,8 @@
|
||||
|
||||
package com.android.settings.notification;
|
||||
|
||||
import static android.app.NotificationManager.Policy.PRIORITY_CATEGORY_MESSAGES;
|
||||
|
||||
import android.content.Context;
|
||||
import android.provider.SearchIndexableResource;
|
||||
|
||||
@@ -41,9 +43,16 @@ public class ZenModeSoundVibrationSettings extends ZenModeSettingsBase implement
|
||||
private static List<AbstractPreferenceController> buildPreferenceControllers(Context context,
|
||||
Lifecycle lifecycle) {
|
||||
List<AbstractPreferenceController> controllers = new ArrayList<>();
|
||||
controllers.add(new ZenModeAlarmsPreferenceController(context, lifecycle));
|
||||
controllers.add(new ZenModeCallsPreferenceController(context, lifecycle,
|
||||
"zen_mode_calls_settings"));
|
||||
controllers.add(new ZenModeMessagesPreferenceController(context, lifecycle,
|
||||
"zen_mode_messages_settings"));
|
||||
controllers.add(new ZenModeAlarmsPreferenceController(context, lifecycle,
|
||||
"zen_mode_alarms"));
|
||||
controllers.add(new ZenModeMediaPreferenceController(context, lifecycle));
|
||||
controllers.add(new ZenModeSystemPreferenceController(context, lifecycle));
|
||||
controllers.add(new ZenModeRemindersPreferenceController(context, lifecycle));
|
||||
controllers.add(new ZenModeEventsPreferenceController(context, lifecycle));
|
||||
controllers.add(new ZenModeBehaviorFooterPreferenceController(context, lifecycle,
|
||||
R.string.zen_sound_footer));
|
||||
return controllers;
|
||||
|
Reference in New Issue
Block a user