Add custom dnd pages for each dnd auto rule

- Fix strings
- Add zen custom settings dialog when custom settings are being applied
Test: make RunSettingsRoboTests -j40
Bug: 111475013
Fixes: 120787133
Fixes: 120796642
Fixes: 120865472
Change-Id: I34d6b4b23d36277e3704416d65e2418418c124e1
This commit is contained in:
Beverly
2018-12-11 16:19:33 -05:00
parent f30fb4b20b
commit b9f38af689
50 changed files with 3582 additions and 159 deletions

View File

@@ -0,0 +1,61 @@
/*
* 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.AutomaticZenRule;
import android.content.Context;
import android.os.Bundle;
import androidx.preference.Preference;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settingslib.core.lifecycle.Lifecycle;
abstract class AbstractZenCustomRulePreferenceController extends
AbstractZenModePreferenceController implements PreferenceControllerMixin {
String mId;
AutomaticZenRule mRule;
AbstractZenCustomRulePreferenceController(Context context, String key,
Lifecycle lifecycle) {
super(context, key, lifecycle);
}
@Override
public void updateState(Preference preference) {
if (mId != null) {
mRule = mBackend.getAutomaticZenRule(mId);
}
}
@Override
public boolean isAvailable() {
return mRule != null;
}
public void onResume(AutomaticZenRule rule, String id) {
mId = id;
mRule = rule;
}
Bundle createBundle() {
Bundle bundle = new Bundle();
bundle.putString(ZenCustomRuleSettings.RULE_ID, mId);
return bundle;
}
}

View File

@@ -50,7 +50,7 @@ abstract public class AbstractZenModePreferenceController extends
@VisibleForTesting
protected SettingObserver mSettingObserver;
private final String KEY;
final String KEY;
final private NotificationManager mNotificationManager;
protected static ZenModeConfigWrapper mZenModeConfigWrapper;
protected MetricsFeatureProvider mMetricsFeatureProvider;

View File

@@ -0,0 +1,81 @@
/*
* 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 android.os.Bundle;
import android.service.notification.ZenPolicy;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.R;
import com.android.settingslib.core.AbstractPreferenceController;
import java.util.ArrayList;
import java.util.List;
public class ZenCustomRuleBlockedEffectsSettings extends ZenCustomRuleSettingsBase {
@Override
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
mFooterPreferenceMixin.createFooterPreference().setTitle(
R.string.zen_mode_blocked_effects_footer);
}
@Override
protected int getPreferenceScreenResId() {
return R.xml.zen_mode_block_settings;
}
@Override
protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
mControllers = new ArrayList<>();
mControllers.add(new ZenRuleVisEffectPreferenceController(context, getSettingsLifecycle(),
"zen_effect_intent", ZenPolicy.VISUAL_EFFECT_FULL_SCREEN_INTENT,
MetricsEvent.ACTION_ZEN_BLOCK_FULL_SCREEN_INTENTS, null));
mControllers.add(new ZenRuleVisEffectPreferenceController(context, getSettingsLifecycle(),
"zen_effect_light", ZenPolicy.VISUAL_EFFECT_LIGHTS,
MetricsEvent.ACTION_ZEN_BLOCK_LIGHT, null));
mControllers.add(new ZenRuleVisEffectPreferenceController(context, getSettingsLifecycle(),
"zen_effect_peek", ZenPolicy.VISUAL_EFFECT_PEEK,
MetricsEvent.ACTION_ZEN_BLOCK_PEEK, null));
mControllers.add(new ZenRuleVisEffectPreferenceController(context, getSettingsLifecycle(),
"zen_effect_status", ZenPolicy.VISUAL_EFFECT_STATUS_BAR,
MetricsEvent.ACTION_ZEN_BLOCK_STATUS,
new int[] {ZenPolicy.VISUAL_EFFECT_NOTIFICATION_LIST}));
mControllers.add(new ZenRuleVisEffectPreferenceController(context, getSettingsLifecycle(),
"zen_effect_badge", ZenPolicy.VISUAL_EFFECT_BADGE,
MetricsEvent.ACTION_ZEN_BLOCK_BADGE, null));
mControllers.add(new ZenRuleVisEffectPreferenceController(context, getSettingsLifecycle(),
"zen_effect_ambient", ZenPolicy.VISUAL_EFFECT_AMBIENT,
MetricsEvent.ACTION_ZEN_BLOCK_AMBIENT, null));
mControllers.add(new ZenRuleVisEffectPreferenceController(context, getSettingsLifecycle(),
"zen_effect_list", ZenPolicy.VISUAL_EFFECT_NOTIFICATION_LIST,
MetricsEvent.ACTION_ZEN_BLOCK_NOTIFICATION_LIST, null));
return mControllers;
}
@Override
String getPreferenceCategoryKey() {
return null;
}
@Override
public int getMetricsCategory() {
return MetricsEvent.ZEN_CUSTOM_RULE_VIS_EFFECTS;
}
}

View File

@@ -0,0 +1,81 @@
/*
* 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 android.os.Bundle;
import android.service.notification.ZenPolicy;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.R;
import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.widget.FooterPreference;
import java.util.ArrayList;
import java.util.List;
public class ZenCustomRuleCallsSettings extends ZenCustomRuleSettingsBase {
private static final String CALLS_KEY = "zen_mode_calls";
private static final String REPEAT_CALLERS_KEY = "zen_mode_repeat_callers";
private static final String STARRED_CONTACTS_KEY = "zen_mode_starred_contacts_callers";
private static final String PREFERENCE_CATEGORY_KEY = "zen_mode_settings_category_calls";
@Override
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
}
@Override
protected int getPreferenceScreenResId() {
return com.android.settings.R.xml.zen_mode_calls_settings;
}
@Override
public int getMetricsCategory() {
return MetricsProto.MetricsEvent.ZEN_CUSTOM_RULE_CALLS;
}
@Override
protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
mControllers = new ArrayList<>();
mControllers.add(new ZenRuleCallsPreferenceController(context, CALLS_KEY,
getSettingsLifecycle()));
mControllers.add(new ZenRuleRepeatCallersPreferenceController(context,
REPEAT_CALLERS_KEY, getSettingsLifecycle(), context.getResources()
.getInteger(com.android.internal.R.integer.config_zen_repeat_callers_threshold)));
mControllers.add(new ZenRuleStarredContactsPreferenceController(context,
getSettingsLifecycle(), ZenPolicy.PRIORITY_CATEGORY_CALLS, STARRED_CONTACTS_KEY));
return mControllers;
}
@Override
String getPreferenceCategoryKey() {
return PREFERENCE_CATEGORY_KEY;
}
@Override
public void updatePreferences() {
super.updatePreferences();
PreferenceScreen screen = getPreferenceScreen();
Preference footerPreference = screen.findPreference(FooterPreference.KEY_FOOTER);
footerPreference.setTitle(mContext.getResources().getString(
R.string.zen_mode_custom_calls_footer, mRule.getName()));
}
}

View File

@@ -0,0 +1,160 @@
/*
* 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.os.Bundle;
import android.service.notification.ZenPolicy;
import androidx.preference.Preference;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.R;
import com.android.settings.core.SubSettingLauncher;
import com.android.settingslib.core.AbstractPreferenceController;
import java.util.ArrayList;
import java.util.List;
public class ZenCustomRuleConfigSettings extends ZenCustomRuleSettingsBase {
private static final String CALLS_KEY = "zen_rule_calls_settings";
private static final String MESSAGES_KEY = "zen_rule_messages_settings";
private static final String ALARMS_KEY = "zen_rule_alarms";
private static final String MEDIA_KEY = "zen_rule_media";
private static final String SYSTEM_KEY = "zen_rule_system";
private static final String REMINDERS_KEY = "zen_rule_reminders";
private static final String EVENTS_KEY = "zen_rule_events";
private static final String NOTIFICATIONS_KEY = "zen_rule_notifications";
private static final String PREFERENCE_CATEGORY_KEY = "zen_custom_rule_configuration_category";
private Preference mCallsPreference;
private Preference mMessagesPreference;
private Preference mNotificationsPreference;
private ZenModeSettings.SummaryBuilder mSummaryBuilder;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
mSummaryBuilder = new ZenModeSettings.SummaryBuilder(mContext);
mCallsPreference = getPreferenceScreen().findPreference(CALLS_KEY);
mCallsPreference.setOnPreferenceClickListener(
new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
new SubSettingLauncher(mContext)
.setDestination(ZenCustomRuleCallsSettings.class.getName())
.setArguments(createZenRuleBundle())
.setSourceMetricsCategory(MetricsEvent.ZEN_CUSTOM_RULE_CALLS)
.launch();
return true;
}
});
mMessagesPreference = getPreferenceScreen().findPreference(MESSAGES_KEY);
mMessagesPreference.setOnPreferenceClickListener(
new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
new SubSettingLauncher(mContext)
.setDestination(ZenCustomRuleMessagesSettings.class.getName())
.setArguments(createZenRuleBundle())
.setSourceMetricsCategory(MetricsEvent.ZEN_CUSTOM_RULE_MESSAGES)
.launch();
return true;
}
});
mNotificationsPreference = getPreferenceScreen().findPreference(NOTIFICATIONS_KEY);
mNotificationsPreference.setOnPreferenceClickListener(
new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
new SubSettingLauncher(mContext)
.setDestination(ZenCustomRuleNotificationsSettings.class.getName())
.setArguments(createZenRuleBundle())
.setSourceMetricsCategory
(MetricsEvent.ZEN_CUSTOM_RULE_NOTIFICATION_RESTRICTIONS)
.launch();
return true;
}
});
updateSummaries();
}
@Override
public void onZenModeConfigChanged() {
super.onZenModeConfigChanged();
updateSummaries();
}
/**
* Updates summaries of preferences without preference controllers
*/
private void updateSummaries() {
NotificationManager.Policy noManPolicy = mBackend.toNotificationPolicy(
mRule.getZenPolicy());
mCallsPreference.setSummary(mSummaryBuilder.getCallsSettingSummary(noManPolicy));
mMessagesPreference.setSummary(mSummaryBuilder.getMessagesSettingSummary(noManPolicy));
mNotificationsPreference.setSummary(mSummaryBuilder.getBlockedEffectsSummary(noManPolicy));
}
@Override
protected int getPreferenceScreenResId() {
return R.xml.zen_mode_custom_rule_configuration;
}
@Override
public int getMetricsCategory() {
return MetricsEvent.ZEN_CUSTOM_RULE_SOUND_SETTINGS;
}
@Override
protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
mControllers = new ArrayList<>();
mControllers.add(new ZenRuleCustomSwitchPreferenceController(context,
getSettingsLifecycle(), ALARMS_KEY, ZenPolicy.PRIORITY_CATEGORY_ALARMS,
MetricsEvent.ACTION_ZEN_ALLOW_ALARMS));
mControllers.add(new ZenRuleCustomSwitchPreferenceController(context,
getSettingsLifecycle(), MEDIA_KEY, ZenPolicy.PRIORITY_CATEGORY_MEDIA,
MetricsEvent.ACTION_ZEN_ALLOW_MEDIA));
mControllers.add(new ZenRuleCustomSwitchPreferenceController(context,
getSettingsLifecycle(), SYSTEM_KEY, ZenPolicy.PRIORITY_CATEGORY_SYSTEM,
MetricsEvent.ACTION_ZEN_ALLOW_SYSTEM));
mControllers.add(new ZenRuleCustomSwitchPreferenceController(context,
getSettingsLifecycle(), REMINDERS_KEY, ZenPolicy.PRIORITY_CATEGORY_REMINDERS,
MetricsEvent.ACTION_ZEN_ALLOW_REMINDERS));
mControllers.add(new ZenRuleCustomSwitchPreferenceController(context,
getSettingsLifecycle(), EVENTS_KEY, ZenPolicy.PRIORITY_CATEGORY_EVENTS,
MetricsEvent.ACTION_ZEN_ALLOW_EVENTS));
return mControllers;
}
@Override
String getPreferenceCategoryKey() {
return PREFERENCE_CATEGORY_KEY;
}
@Override
public void onResume() {
super.onResume();
updateSummaries();
}
}

View File

@@ -0,0 +1,72 @@
/*
* 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 android.service.notification.ZenPolicy;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.R;
import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.widget.FooterPreference;
import java.util.ArrayList;
import java.util.List;
public class ZenCustomRuleMessagesSettings extends ZenCustomRuleSettingsBase {
private static final String MESSAGES_KEY = "zen_mode_messages";
private static final String STARRED_CONTACTS_KEY = "zen_mode_starred_contacts_messages";
private static final String PREFERENCE_CATEGORY_KEY = "zen_mode_settings_category_messages";
@Override
protected int getPreferenceScreenResId() {
return com.android.settings.R.xml.zen_mode_messages_settings;
}
@Override
public int getMetricsCategory() {
return MetricsProto.MetricsEvent.ZEN_CUSTOM_RULE_MESSAGES;
}
@Override
protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
mControllers = new ArrayList<>();
mControllers.add(new ZenRuleMessagesPreferenceController(context, MESSAGES_KEY,
getSettingsLifecycle()));
mControllers.add(new ZenRuleStarredContactsPreferenceController(context,
getSettingsLifecycle(), ZenPolicy.PRIORITY_CATEGORY_MESSAGES,
STARRED_CONTACTS_KEY));
return mControllers;
}
@Override
String getPreferenceCategoryKey() {
return PREFERENCE_CATEGORY_KEY;
}
@Override
public void updatePreferences() {
super.updatePreferences();
PreferenceScreen screen = getPreferenceScreen();
Preference footerPreference = screen.findPreference(FooterPreference.KEY_FOOTER);
footerPreference.setTitle(mContext.getResources().getString(
R.string.zen_mode_custom_messages_footer, mRule.getName()));
}
}

View File

@@ -0,0 +1,63 @@
/*
* 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 com.android.internal.logging.nano.MetricsProto;
import com.android.settings.R;
import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settingslib.widget.FooterPreference;
import java.util.ArrayList;
import java.util.List;
public class ZenCustomRuleNotificationsSettings extends ZenCustomRuleSettingsBase {
private static final String VIS_EFFECTS_ALL_KEY = "zen_mute_notifications";
private static final String VIS_EFFECTS_NONE_KEY = "zen_hide_notifications";
private static final String VIS_EFFECTS_CUSTOM_KEY = "zen_custom";
private static final String PREFERENCE_CATEGORY_KEY = "restrict_category";
@Override
protected int getPreferenceScreenResId() {
return R.xml.zen_mode_restrict_notifications_settings;
}
@Override
protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
mControllers = new ArrayList<>();
mControllers.add(new ZenRuleVisEffectsAllPreferenceController(
context, getSettingsLifecycle(), VIS_EFFECTS_ALL_KEY));
mControllers.add(new ZenRuleVisEffectsNonePreferenceController(
context, getSettingsLifecycle(), VIS_EFFECTS_NONE_KEY));
mControllers.add(new ZenRuleVisEffectsCustomPreferenceController(
context, getSettingsLifecycle(), VIS_EFFECTS_CUSTOM_KEY));
mControllers.add(new ZenRuleNotifFooterPreferenceController(context, getSettingsLifecycle(),
FooterPreference.KEY_FOOTER));
return mControllers;
}
@Override
String getPreferenceCategoryKey() {
return PREFERENCE_CATEGORY_KEY;
}
@Override
public int getMetricsCategory() {
return MetricsProto.MetricsEvent.ZEN_CUSTOM_RULE_NOTIFICATION_RESTRICTIONS;
}
}

View File

@@ -0,0 +1,57 @@
/*
* 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 com.android.internal.logging.nano.MetricsProto;
import com.android.settings.R;
import com.android.settingslib.core.AbstractPreferenceController;
import java.util.ArrayList;
import java.util.List;
public class ZenCustomRuleSettings extends ZenCustomRuleSettingsBase {
private static final String RULE_DEFAULT_POLICY_KEY = "zen_custom_rule_setting_default";
private static final String CUSTOM_RULE_POLICY_KEY = "zen_custom_rule_setting";
private static final String PREFERENCE_CATEGORY_KEY = "zen_custom_rule_category";
@Override
protected int getPreferenceScreenResId() {
return R.xml.zen_mode_custom_rule_settings;
}
@Override
public int getMetricsCategory() {
return MetricsProto.MetricsEvent.ZEN_CUSTOM_RULE_SETTINGS;
}
@Override
protected List<AbstractPreferenceController> createPreferenceControllers(Context context) {
mControllers = new ArrayList<>();
mControllers.add(new ZenRuleDefaultPolicyPreferenceController(
context, getSettingsLifecycle(), RULE_DEFAULT_POLICY_KEY));
mControllers.add(new ZenRuleCustomPolicyPreferenceController(
context, getSettingsLifecycle(), CUSTOM_RULE_POLICY_KEY));
return mControllers;
}
@Override
String getPreferenceCategoryKey() {
return PREFERENCE_CATEGORY_KEY;
}
}

View File

@@ -0,0 +1,103 @@
/*
* 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.AutomaticZenRule;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import com.android.settings.R;
import com.android.settingslib.core.AbstractPreferenceController;
import java.util.ArrayList;
import java.util.List;
abstract class ZenCustomRuleSettingsBase extends ZenModeSettingsBase {
static final String TAG = "ZenCustomRuleSettings";
static final String RULE_ID = "RULE_ID";
String mId;
AutomaticZenRule mRule;
List<AbstractPreferenceController> mControllers = new ArrayList<>();
/**
* @return null if no preference category exists
*/
abstract String getPreferenceCategoryKey();
@Override
public void onAttach(Context context) {
super.onAttach(context);
Bundle bundle = getArguments();
if (bundle != null && bundle.containsKey(RULE_ID)) {
mId = bundle.getString(RULE_ID);
mRule = mBackend.getAutomaticZenRule(mId);
} else {
Log.d(TAG, "Rule id required to set custom dnd rule config settings");
this.finish();
}
}
@Override
public void onZenModeConfigChanged() {
super.onZenModeConfigChanged();
updatePreferences();
}
public void updatePreferences() {
mRule = mBackend.getAutomaticZenRule(mId);
final PreferenceScreen screen = getPreferenceScreen();
String categoryKey = getPreferenceCategoryKey();
if (categoryKey != null) {
Preference prefCategory = screen.findPreference(categoryKey);
if (prefCategory != null) {
prefCategory.setTitle(mContext.getResources().getString(
com.android.settings.R.string.zen_mode_custom_behavior_category_title,
mRule.getName()));
}
}
for (AbstractPreferenceController controller : mControllers) {
AbstractZenCustomRulePreferenceController zenRuleController =
(AbstractZenCustomRulePreferenceController) controller;
zenRuleController.onResume(mRule, mId);
zenRuleController.displayPreference(screen);
updatePreference(zenRuleController);
}
}
@Override
public int getHelpResource() {
return R.string.help_uri_interruptions;
}
@Override
public void onResume() {
super.onResume();
updatePreferences();
}
Bundle createZenRuleBundle() {
Bundle bundle = new Bundle();
bundle.putString(RULE_ID, mId);
return bundle;
}
}

View File

@@ -23,15 +23,20 @@ import android.app.ActivityManager;
import android.app.AutomaticZenRule;
import android.app.NotificationManager;
import android.content.Context;
import android.database.Cursor;
import android.icu.text.ListFormatter;
import android.net.Uri;
import android.provider.ContactsContract;
import android.provider.Settings;
import android.service.notification.ZenModeConfig;
import android.service.notification.ZenPolicy;
import android.util.Log;
import androidx.annotation.VisibleForTesting;
import com.android.settings.R;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
@@ -116,7 +121,7 @@ public class ZenModeBackend {
return (mPolicy.priorityCategories & categoryType) != 0;
}
protected int getNewPriorityCategories(boolean allow, int categoryType) {
protected int getNewDefaultPriorityCategories(boolean allow, int categoryType) {
int priorityCategories = mPolicy.priorityCategories;
if (allow) {
priorityCategories |= categoryType;
@@ -135,7 +140,8 @@ public class ZenModeBackend {
}
protected int getPriorityMessageSenders() {
if (isPriorityCategoryEnabled(NotificationManager.Policy.PRIORITY_CATEGORY_MESSAGES)) {
if (isPriorityCategoryEnabled(
NotificationManager.Policy.PRIORITY_CATEGORY_MESSAGES)) {
return mPolicy.priorityMessageSenders;
}
return SOURCE_NONE;
@@ -151,7 +157,7 @@ public class ZenModeBackend {
}
protected void saveSoundPolicy(int category, boolean allow) {
int priorityCategories = getNewPriorityCategories(allow, category);
int priorityCategories = getNewDefaultPriorityCategories(allow, category);
savePolicy(priorityCategories, mPolicy.priorityCallSenders,
mPolicy.priorityMessageSenders, mPolicy.suppressedVisualEffects);
}
@@ -163,6 +169,7 @@ public class ZenModeBackend {
mNotificationManager.setNotificationPolicy(mPolicy);
}
private int getNewSuppressedEffects(boolean suppress, int effectType) {
int effects = mPolicy.suppressedVisualEffects;
@@ -202,7 +209,7 @@ public class ZenModeBackend {
priorityMessagesSenders = allowSendersFrom;
}
savePolicy(getNewPriorityCategories(allowSenders, category),
savePolicy(getNewDefaultPriorityCategories(allowSenders, category),
priorityCallSenders, priorityMessagesSenders, mPolicy.suppressedVisualEffects);
if (ZenModeSettingsBase.DEBUG) Log.d(TAG, "onPrefChange allow" +
@@ -236,6 +243,20 @@ public class ZenModeBackend {
return categorySenders;
}
protected static String getKeyFromZenPolicySetting(int contactType) {
switch (contactType) {
case ZenPolicy.PEOPLE_TYPE_ANYONE:
return ZEN_MODE_FROM_ANYONE;
case ZenPolicy.PEOPLE_TYPE_CONTACTS:
return ZEN_MODE_FROM_CONTACTS;
case ZenPolicy.PEOPLE_TYPE_STARRED:
return ZEN_MODE_FROM_STARRED;
case ZenPolicy.PEOPLE_TYPE_NONE:
default:
return ZEN_MODE_FROM_NONE;
}
}
protected static String getKeyFromSetting(int contactType) {
switch (contactType) {
case NotificationManager.Policy.PRIORITY_SENDERS_ANY:
@@ -288,6 +309,50 @@ public class ZenModeBackend {
}
}
protected int getContactsCallsSummary(ZenPolicy policy) {
int peopleType = policy.getPriorityCallSenders();
switch (peopleType) {
case ZenPolicy.PEOPLE_TYPE_ANYONE:
return R.string.zen_mode_from_anyone;
case ZenPolicy.PEOPLE_TYPE_CONTACTS:
return R.string.zen_mode_from_contacts;
case ZenPolicy.PEOPLE_TYPE_STARRED:
return R.string.zen_mode_from_starred;
case ZenPolicy.PEOPLE_TYPE_NONE:
default:
return R.string.zen_mode_from_none_calls;
}
}
protected int getContactsMessagesSummary(ZenPolicy policy) {
int peopleType = policy.getPriorityMessageSenders();
switch (peopleType) {
case ZenPolicy.PEOPLE_TYPE_ANYONE:
return R.string.zen_mode_from_anyone;
case ZenPolicy.PEOPLE_TYPE_CONTACTS:
return R.string.zen_mode_from_contacts;
case ZenPolicy.PEOPLE_TYPE_STARRED:
return R.string.zen_mode_from_starred;
case ZenPolicy.PEOPLE_TYPE_NONE:
default:
return R.string.zen_mode_from_none_messages;
}
}
protected static int getZenPolicySettingFromPrefKey(String key) {
switch (key) {
case ZEN_MODE_FROM_ANYONE:
return ZenPolicy.PEOPLE_TYPE_ANYONE;
case ZEN_MODE_FROM_CONTACTS:
return ZenPolicy.PEOPLE_TYPE_CONTACTS;
case ZEN_MODE_FROM_STARRED:
return ZenPolicy.PEOPLE_TYPE_STARRED;
case ZEN_MODE_FROM_NONE:
default:
return ZenPolicy.PEOPLE_TYPE_NONE;
}
}
protected static int getSettingFromPrefKey(String key) {
switch (key) {
case ZEN_MODE_FROM_ANYONE:
@@ -318,6 +383,40 @@ public class ZenModeBackend {
}
}
ZenPolicy setDefaultZenPolicy(ZenPolicy zenPolicy) {
int calls;
if (mPolicy.allowCalls()) {
calls = ZenModeConfig.getZenPolicySenders(mPolicy.allowCallsFrom());
} else {
calls = ZenPolicy.PEOPLE_TYPE_NONE;
}
int messages;
if (mPolicy.allowMessages()) {
messages = ZenModeConfig.getZenPolicySenders(mPolicy.allowMessagesFrom());
} else {
messages = ZenPolicy.PEOPLE_TYPE_NONE;
}
return new ZenPolicy.Builder(zenPolicy)
.allowAlarms(mPolicy.allowAlarms())
.allowCalls(calls)
.allowEvents(mPolicy.allowEvents())
.allowMedia(mPolicy.allowMedia())
.allowMessages(messages)
.allowReminders(mPolicy.allowReminders())
.allowRepeatCallers(mPolicy.allowRepeatCallers())
.allowSystem(mPolicy.allowSystem())
.showFullScreenIntent(mPolicy.showFullScreenIntents())
.showLights(mPolicy.showLights())
.showInAmbientDisplay(mPolicy.showAmbient())
.showInNotificationList(mPolicy.showInNotificationList())
.showBadges(mPolicy.showBadges())
.showPeeking(mPolicy.showPeeking())
.showStatusBarIcons(mPolicy.showStatusBarIcons())
.build();
}
protected Map.Entry<String, AutomaticZenRule>[] getAutomaticZenRules() {
Map<String, AutomaticZenRule> ruleMap =
NotificationManager.from(mContext).getAutomaticZenRules();
@@ -338,6 +437,70 @@ public class ZenModeBackend {
return mDefaultRuleIds;
}
NotificationManager.Policy toNotificationPolicy(ZenPolicy policy) {
ZenModeConfig config = new ZenModeConfig();
return config.toNotificationPolicy(policy);
}
@VisibleForTesting
List<String> getStarredContacts(Cursor cursor) {
List<String> starredContacts = new ArrayList<>();
if (cursor != null && cursor.moveToFirst()) {
do {
String contact = cursor.getString(0);
if (contact != null) {
starredContacts.add(contact);
}
} while (cursor.moveToNext());
}
return starredContacts;
}
private List<String> getStarredContacts() {
Cursor cursor = null;
try {
cursor = queryData();
return getStarredContacts(cursor);
} finally {
if (cursor != null) {
cursor.close();
}
}
}
public String getStarredContactsSummary() {
List<String> starredContacts = getStarredContacts();
int numStarredContacts = starredContacts.size();
List<String> displayContacts = new ArrayList<>();
if (numStarredContacts == 0) {
displayContacts.add(mContext.getString(R.string.zen_mode_from_none));
} else {
for (int i = 0; i < 2 && i < numStarredContacts; i++) {
displayContacts.add(starredContacts.get(i));
}
if (numStarredContacts == 3) {
displayContacts.add(starredContacts.get(2));
} else if (numStarredContacts > 2) {
displayContacts.add(mContext.getResources().getQuantityString(
R.plurals.zen_mode_starred_contacts_summary_additional_contacts,
numStarredContacts - 2, numStarredContacts - 2));
}
}
// values in displayContacts must not be null
return ListFormatter.getInstance().format(displayContacts);
}
private Cursor queryData() {
return mContext.getContentResolver().query(ContactsContract.Contacts.CONTENT_URI,
new String[]{ContactsContract.Contacts.DISPLAY_NAME_PRIMARY},
ContactsContract.Data.STARRED + "=1", null,
ContactsContract.Data.TIMES_CONTACTED);
}
@VisibleForTesting
public static final Comparator<Map.Entry<String, AutomaticZenRule>> RULE_COMPARATOR =
new Comparator<Map.Entry<String, AutomaticZenRule>>() {

View File

@@ -30,13 +30,15 @@ import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import com.android.settings.R;
import com.android.settingslib.core.AbstractPreferenceController;
import com.android.settings.core.SubSettingLauncher;
public abstract class ZenModeRuleSettingsBase extends ZenModeSettingsBase {
protected static final String TAG = ZenModeSettingsBase.TAG;
protected static final boolean DEBUG = ZenModeSettingsBase.DEBUG;
private final String CUSTOM_BEHAVIOR_KEY = "zen_custom_setting";
protected Context mContext;
protected boolean mDisableListeners;
protected AutomaticZenRule mRule;
@@ -45,6 +47,7 @@ public abstract class ZenModeRuleSettingsBase extends ZenModeSettingsBase {
protected ZenAutomaticRuleHeaderPreferenceController mHeader;
protected ZenRuleButtonsPreferenceController mActionButtons;
protected ZenAutomaticRuleSwitchPreferenceController mSwitch;
protected Preference mCustomBehaviorPreference;
abstract protected void onCreateInternal();
abstract protected boolean setRule(AutomaticZenRule rule);
@@ -75,6 +78,21 @@ public abstract class ZenModeRuleSettingsBase extends ZenModeSettingsBase {
}
super.onCreate(icicle);
mCustomBehaviorPreference = getPreferenceScreen().findPreference(CUSTOM_BEHAVIOR_KEY);
mCustomBehaviorPreference.setOnPreferenceClickListener(
new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
Bundle bundle = new Bundle();
bundle.putString(ZenCustomRuleSettings.RULE_ID, mId);
new SubSettingLauncher(mContext)
.setDestination(ZenCustomRuleSettings.class.getName())
.setArguments(bundle)
.setSourceMetricsCategory(0) // TODO
.launch();
return true;
}
});
onCreateInternal();
}
@@ -84,7 +102,9 @@ public abstract class ZenModeRuleSettingsBase extends ZenModeSettingsBase {
if (isUiRestricted()) {
return;
}
updateControls();
if (!refreshRuleOrFinish()) {
updateControls();
}
}
@Override
@@ -111,22 +131,6 @@ public abstract class ZenModeRuleSettingsBase extends ZenModeSettingsBase {
updatePreference(mActionButtons);
}
private void updatePreference(AbstractPreferenceController controller) {
final PreferenceScreen screen = getPreferenceScreen();
if (!controller.isAvailable()) {
return;
}
final String key = controller.getPreferenceKey();
final Preference preference = screen.findPreference(key);
if (preference == null) {
Log.d(TAG, String.format("Cannot find preference with key %s in Controller %s",
key, controller.getClass().getSimpleName()));
return;
}
controller.updateState(preference);
}
protected void updateRule(Uri newConditionId) {
mRule.setConditionId(newConditionId);
mBackend.updateZenRule(mId, mRule);
@@ -165,6 +169,11 @@ public abstract class ZenModeRuleSettingsBase extends ZenModeSettingsBase {
mDisableListeners = true;
updateControlsInternal();
updateHeader();
if (mRule.getZenPolicy() == null) {
mCustomBehaviorPreference.setSummary(R.string.zen_mode_custom_behavior_summary_default);
} else {
mCustomBehaviorPreference.setSummary(R.string.zen_mode_custom_behavior_summary);
}
mDisableListeners = false;
}
}

View File

@@ -90,7 +90,8 @@ public class ZenModeSettings extends ZenModeSettingsBase {
controllers.add(new ZenModeDurationPreferenceController(context, lifecycle));
controllers.add(new ZenModeAutomationPreferenceController(context));
controllers.add(new ZenModeButtonPreferenceController(context, lifecycle, fragmentManager));
controllers.add(new ZenModeSettingsFooterPreferenceController(context, lifecycle));
controllers.add(new ZenModeSettingsFooterPreferenceController(context, lifecycle,
fragmentManager));
return controllers;
}

View File

@@ -26,7 +26,11 @@ import android.provider.Settings;
import android.provider.Settings.Global;
import android.util.Log;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import com.android.settings.dashboard.RestrictedDashboardFragment;
import com.android.settingslib.core.AbstractPreferenceController;
abstract public class ZenModeSettingsBase extends RestrictedDashboardFragment {
protected static final String TAG = "ZenModeSettings";
@@ -121,4 +125,20 @@ abstract public class ZenModeSettingsBase extends RestrictedDashboardFragment {
}
}
}
void updatePreference(AbstractPreferenceController controller) {
final PreferenceScreen screen = getPreferenceScreen();
if (!controller.isAvailable()) {
return;
}
final String key = controller.getPreferenceKey();
final Preference preference = screen.findPreference(key);
if (preference == null) {
Log.d(TAG, String.format("Cannot find preference with key %s in Controller %s",
key, controller.getClass().getSimpleName()));
return;
}
controller.updateState(preference);
}
}

View File

@@ -16,17 +16,29 @@
package com.android.settings.notification;
import android.app.Dialog;
import android.app.NotificationManager;
import android.content.Context;
import android.content.DialogInterface;
import android.icu.text.ListFormatter;
import android.net.Uri;
import android.os.Bundle;
import android.provider.Settings;
import android.service.notification.ZenModeConfig;
import android.util.Log;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import androidx.appcompat.app.AlertDialog;
import androidx.fragment.app.FragmentManager;
import androidx.preference.Preference;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.R;
import com.android.settings.core.SubSettingLauncher;
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
import com.android.settings.utils.AnnotationSpan;
import com.android.settingslib.core.lifecycle.Lifecycle;
import java.util.ArrayList;
@@ -34,11 +46,13 @@ import java.util.List;
import java.util.Objects;
public class ZenModeSettingsFooterPreferenceController extends AbstractZenModePreferenceController {
static final String KEY = "footer_preference";
private FragmentManager mFragment;
protected static final String KEY = "footer_preference";
public ZenModeSettingsFooterPreferenceController(Context context, Lifecycle lifecycle) {
public ZenModeSettingsFooterPreferenceController(Context context, Lifecycle lifecycle,
FragmentManager fragment) {
super(context, KEY, lifecycle);
mFragment = fragment;
}
@Override
@@ -70,7 +84,7 @@ public class ZenModeSettingsFooterPreferenceController extends AbstractZenModePr
}
}
protected String getFooterText() {
protected CharSequence getFooterText() {
ZenModeConfig config = getZenModeConfig();
NotificationManager.Policy appliedPolicy = mBackend.getConsolidatedPolicy();
@@ -88,15 +102,25 @@ public class ZenModeSettingsFooterPreferenceController extends AbstractZenModePr
if (rulesNames.size() > 0) {
String rules = ListFormatter.getInstance().format(rulesNames);
if (!rules.isEmpty()) {
return mContext.getString(R.string.zen_mode_settings_dnd_custom_settings_footer,
rules);
final AnnotationSpan.LinkInfo linkInfo = new AnnotationSpan.LinkInfo(
AnnotationSpan.LinkInfo.DEFAULT_ANNOTATION, new View.OnClickListener() {
@Override
public void onClick(View v) {
showCustomSettingsDialog();
}
});
return TextUtils.concat(mContext.getResources().getString(
R.string.zen_mode_settings_dnd_custom_settings_footer, rules),
AnnotationSpan.linkify(mContext.getResources().getText(
R.string.zen_mode_settings_dnd_custom_settings_footer_link),
linkInfo));
}
}
}
return getFooterUsingDefaultPolicy(config);
return getDefaultPolicyFooter(config);
}
private String getFooterUsingDefaultPolicy(ZenModeConfig config) {
private String getDefaultPolicyFooter(ZenModeConfig config) {
String footerText = "";
long latestEndTime = -1;
@@ -162,4 +186,101 @@ public class ZenModeSettingsFooterPreferenceController extends AbstractZenModePr
}
return zenRules;
}
private void showCustomSettingsDialog() {
ZenCustomSettingsDialog dialog = new ZenCustomSettingsDialog();
dialog.setNotificationPolicy(mBackend.getConsolidatedPolicy());
dialog.show(mFragment, ZenCustomSettingsDialog.class.getName());
}
public static class ZenCustomSettingsDialog extends InstrumentedDialogFragment {
private String KEY_POLICY = "policy";
private NotificationManager.Policy mPolicy;
private ZenModeSettings.SummaryBuilder mSummaryBuilder;
public void setNotificationPolicy(NotificationManager.Policy policy) {
mPolicy = policy;
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
Context context = getActivity();
if (savedInstanceState != null) {
NotificationManager.Policy policy = savedInstanceState.getParcelable(KEY_POLICY);
if (policy != null) {
mPolicy = policy;
}
}
mSummaryBuilder = new ZenModeSettings.SummaryBuilder(context);
AlertDialog customSettingsDialog = new AlertDialog.Builder(context)
.setTitle(R.string.zen_custom_settings_dialog_title)
.setNeutralButton(R.string.zen_custom_settings_dialog_review_schedule,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {
new SubSettingLauncher(context)
.setDestination(
ZenModeAutomationSettings.class.getName())
.setSourceMetricsCategory(
MetricsEvent.NOTIFICATION_ZEN_MODE_AUTOMATION)
.launch();
}
})
.setPositiveButton(R.string.zen_custom_settings_dialog_ok, null)
.setView(LayoutInflater.from(context).inflate(context.getResources().getLayout(
R.layout.zen_custom_settings_dialog), null, false))
.create();
customSettingsDialog.setOnShowListener(new DialogInterface.OnShowListener() {
@Override
public void onShow(DialogInterface dialog) {
TextView allowCallsText = customSettingsDialog.findViewById(
R.id.zen_custom_settings_dialog_calls_allow);
TextView allowMessagesText = customSettingsDialog.findViewById(
R.id.zen_custom_settings_dialog_messages_allow);
TextView allowAlarmsText = customSettingsDialog.findViewById(
R.id.zen_custom_settings_dialog_alarms_allow);
TextView allowMediaText = customSettingsDialog.findViewById(
R.id.zen_custom_settings_dialog_media_allow);
TextView allowSystemText = customSettingsDialog.findViewById(
R.id.zen_custom_settings_dialog_system_allow);
TextView allowRemindersText = customSettingsDialog.findViewById(
R.id.zen_custom_settings_dialog_reminders_allow);
TextView allowEventsText = customSettingsDialog.findViewById(
R.id.zen_custom_settings_dialog_events_allow);
TextView notificationsText = customSettingsDialog.findViewById(
R.id.zen_custom_settings_dialog_show_notifications);
allowCallsText.setText(mSummaryBuilder.getCallsSettingSummary(mPolicy));
allowMessagesText.setText(mSummaryBuilder.getMessagesSettingSummary(mPolicy));
allowAlarmsText.setText(getAllowRes(mPolicy.allowAlarms()));
allowMediaText.setText(getAllowRes(mPolicy.allowMedia()));
allowSystemText.setText(getAllowRes(mPolicy.allowSystem()));
allowRemindersText.setText(getAllowRes(mPolicy.allowReminders()));
allowEventsText.setText(getAllowRes(mPolicy.allowEvents()));
notificationsText.setText(mSummaryBuilder.getBlockedEffectsSummary(mPolicy));
}
});
return customSettingsDialog;
}
@Override
public int getMetricsCategory() {
return MetricsEvent.ZEN_CUSTOM_SETTINGS_DIALOG;
}
private int getAllowRes(boolean allow) {
return allow ? R.string.zen_mode_sound_summary_on : R.string.zen_mode_sound_summary_off;
}
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putParcelable(KEY_POLICY, mPolicy);
}
}
}

View File

@@ -23,25 +23,15 @@ import static android.app.NotificationManager.Policy.PRIORITY_SENDERS_STARRED;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.database.Cursor;
import android.icu.text.ListFormatter;
import android.provider.Contacts;
import android.provider.ContactsContract;
import com.android.settings.R;
import com.android.settingslib.core.lifecycle.Lifecycle;
import java.util.ArrayList;
import java.util.List;
import androidx.annotation.VisibleForTesting;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import com.android.settingslib.core.lifecycle.Lifecycle;
public class ZenModeStarredContactsPreferenceController extends
AbstractZenModePreferenceController implements Preference.OnPreferenceClickListener {
protected static String KEY;
private Preference mPreference;
private final int mPriorityCategory;
private final PackageManager mPackageManager;
@@ -52,8 +42,6 @@ public class ZenModeStarredContactsPreferenceController extends
public ZenModeStarredContactsPreferenceController(Context context, Lifecycle lifecycle, int
priorityCategory, String key) {
super(context, key, lifecycle);
KEY = key;
mPriorityCategory = priorityCategory;
mPackageManager = mContext.getPackageManager();
@@ -96,29 +84,7 @@ public class ZenModeStarredContactsPreferenceController extends
@Override
public CharSequence getSummary() {
List<String> starredContacts = getStarredContacts();
int numStarredContacts = starredContacts.size();
List<String> displayContacts = new ArrayList<>();
if (numStarredContacts == 0) {
displayContacts.add(mContext.getString(R.string.zen_mode_from_none));
} else {
for (int i = 0; i < 2 && i < numStarredContacts; i++) {
displayContacts.add(starredContacts.get(i));
}
if (numStarredContacts == 3) {
displayContacts.add(starredContacts.get(2));
} else if (numStarredContacts > 2) {
displayContacts.add(mContext.getResources().getQuantityString(
R.plurals.zen_mode_starred_contacts_summary_additional_contacts,
numStarredContacts - 2, numStarredContacts - 2));
}
}
// values in displayContacts must not be null
return ListFormatter.getInstance().format(displayContacts);
return mBackend.getStarredContactsSummary();
}
@Override
@@ -131,39 +97,6 @@ public class ZenModeStarredContactsPreferenceController extends
return true;
}
@VisibleForTesting
List<String> getStarredContacts(Cursor cursor) {
List<String> starredContacts = new ArrayList<>();
if (cursor.moveToFirst()) {
do {
String contact = cursor.getString(0);
if (contact != null) {
starredContacts.add(contact);
}
} while (cursor.moveToNext());
}
return starredContacts;
}
private List<String> getStarredContacts() {
Cursor cursor = null;
try {
cursor = queryData();
return getStarredContacts(cursor);
} finally {
if (cursor != null) {
cursor.close();
}
}
}
private Cursor queryData() {
return mContext.getContentResolver().query(ContactsContract.Contacts.CONTENT_URI,
new String[]{ContactsContract.Contacts.DISPLAY_NAME_PRIMARY},
ContactsContract.Data.STARRED + "=1", null,
ContactsContract.Data.TIMES_CONTACTED);
}
private boolean isIntentValid() {
return mStarredContactsIntent.resolveActivity(mPackageManager) != null
|| mFallbackIntent.resolveActivity(mPackageManager) != null;

View File

@@ -0,0 +1,86 @@
/*
* 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 android.service.notification.ZenPolicy;
import android.text.TextUtils;
import android.util.Pair;
import androidx.annotation.VisibleForTesting;
import androidx.preference.ListPreference;
import androidx.preference.Preference;
import com.android.internal.logging.nano.MetricsProto;
import com.android.settingslib.core.lifecycle.Lifecycle;
public class ZenRuleCallsPreferenceController extends AbstractZenCustomRulePreferenceController
implements Preference.OnPreferenceChangeListener {
private final String[] mListValues;
public ZenRuleCallsPreferenceController(Context context, String key, Lifecycle lifecycle) {
super(context, key, lifecycle);
mListValues = context.getResources().getStringArray(
com.android.settings.R.array.zen_mode_contacts_values);
}
@Override
public void updateState(Preference preference) {
super.updateState(preference);
updateFromContactsValue(preference);
}
@Override
public boolean onPreferenceChange(Preference preference, Object selectedContactsFrom) {
int allowCalls = ZenModeBackend.getZenPolicySettingFromPrefKey(
selectedContactsFrom.toString());
mMetricsFeatureProvider.action(mContext, MetricsProto.MetricsEvent.ACTION_ZEN_ALLOW_CALLS,
Pair.create(MetricsProto.MetricsEvent.FIELD_ZEN_TOGGLE_EXCEPTION, allowCalls),
Pair.create(MetricsProto.MetricsEvent.FIELD_ZEN_RULE_ID, mId));
mRule.setZenPolicy(new ZenPolicy.Builder(mRule.getZenPolicy())
.allowCalls(allowCalls)
.build());
mBackend.updateZenRule(mId, mRule);
updateFromContactsValue(preference);
return true;
}
private void updateFromContactsValue(Preference preference) {
if (mRule == null || mRule.getZenPolicy() == null) {
return;
}
ListPreference listPreference = (ListPreference) preference;
listPreference.setSummary(mBackend.getContactsCallsSummary(mRule.getZenPolicy()));
final String currentVal = ZenModeBackend.getKeyFromZenPolicySetting(
mRule.getZenPolicy().getPriorityCallSenders());
listPreference.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;
}
}

View File

@@ -0,0 +1,81 @@
/*
* 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 android.service.notification.ZenPolicy;
import android.util.Log;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.core.SubSettingLauncher;
import com.android.settingslib.core.lifecycle.Lifecycle;
public class ZenRuleCustomPolicyPreferenceController extends
AbstractZenCustomRulePreferenceController {
private ZenCustomRadioButtonPreference mPreference;
public ZenRuleCustomPolicyPreferenceController(Context context, Lifecycle lifecycle,
String key) {
super(context, key, lifecycle);
}
@Override
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
mPreference = (ZenCustomRadioButtonPreference) screen.findPreference(getPreferenceKey());
mPreference.setOnGearClickListener(p -> {
setCustomPolicy();
launchCustomSettings();
});
mPreference.setOnRadioButtonClickListener(p -> {
setCustomPolicy();
launchCustomSettings();
});
}
@Override
public void updateState(Preference preference) {
super.updateState(preference);
if (mId == null || mRule == null) {
return;
}
mPreference.setChecked(mRule.getZenPolicy() != null);
}
private void setCustomPolicy() {
if (mRule.getZenPolicy() == null) {
mRule.setZenPolicy(mBackend.setDefaultZenPolicy(new ZenPolicy()));
mBackend.updateZenRule(mId, mRule);
}
}
private void launchCustomSettings() {
new SubSettingLauncher(mContext)
.setDestination(ZenCustomRuleConfigSettings.class.getName())
.setArguments(createBundle())
.setSourceMetricsCategory(MetricsProto.MetricsEvent.ZEN_CUSTOM_RULE_SOUND_SETTINGS)
.launch();
}
}

View File

@@ -0,0 +1,70 @@
/*
* 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 android.service.notification.ZenPolicy;
import android.util.Log;
import android.util.Pair;
import androidx.preference.Preference;
import androidx.preference.SwitchPreference;
import com.android.internal.logging.nano.MetricsProto;
import com.android.settingslib.core.lifecycle.Lifecycle;
public class ZenRuleCustomSwitchPreferenceController extends
AbstractZenCustomRulePreferenceController implements Preference.OnPreferenceChangeListener {
private @ZenPolicy.PriorityCategory int mCategory;
private int mMetricsCategory;
public ZenRuleCustomSwitchPreferenceController(Context context, Lifecycle lifecycle,
String key, @ZenPolicy.PriorityCategory int category, int metricsCategory) {
super(context, key, lifecycle);
mCategory = category;
mMetricsCategory = metricsCategory;
}
@Override
public void updateState(Preference preference) {
super.updateState(preference);
if (mRule == null || mRule.getZenPolicy() == null) {
return;
}
SwitchPreference pref = (SwitchPreference) preference;
pref.setChecked(mRule.getZenPolicy().isCategoryAllowed(mCategory, false));
}
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
final boolean allow = (Boolean) newValue;
if (ZenModeSettingsBase.DEBUG) {
Log.d(TAG, KEY + " onPrefChange mRule=" + mRule + " mCategory=" + mCategory
+ " allow=" + allow);
}
mMetricsFeatureProvider.action(mContext, mMetricsCategory,
Pair.create(MetricsProto.MetricsEvent.FIELD_ZEN_TOGGLE_EXCEPTION, allow ? 1 : 0),
Pair.create(MetricsProto.MetricsEvent.FIELD_ZEN_RULE_ID, mId));
mRule.setZenPolicy(new ZenPolicy.Builder(mRule.getZenPolicy())
.allowCategory(mCategory, allow)
.build());
mBackend.updateZenRule(mId, mRule);
return true;
}
}

View File

@@ -0,0 +1,60 @@
/*
* 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 android.util.Pair;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settingslib.core.lifecycle.Lifecycle;
public class ZenRuleDefaultPolicyPreferenceController extends
AbstractZenCustomRulePreferenceController implements PreferenceControllerMixin {
private ZenCustomRadioButtonPreference mPreference;
public ZenRuleDefaultPolicyPreferenceController(Context context, Lifecycle lifecycle,
String key) {
super(context, key, lifecycle);
}
@Override
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
mPreference = (ZenCustomRadioButtonPreference) screen.findPreference(getPreferenceKey());
mPreference.setOnRadioButtonClickListener(p -> {
mRule.setZenPolicy(null);
mBackend.updateZenRule(mId, mRule);
});
}
@Override
public void updateState(Preference preference) {
super.updateState(preference);
if (mId == null || mRule == null) {
return;
}
mMetricsFeatureProvider.action(mContext, MetricsEvent.ZEN_CUSTOM_RULE_DEFAULT_SETTINGS,
Pair.create(MetricsEvent.FIELD_ZEN_RULE_ID, mId));
mPreference.setChecked(mRule.getZenPolicy() == null);
}
}

View File

@@ -0,0 +1,87 @@
/*
* 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 android.service.notification.ZenPolicy;
import android.text.TextUtils;
import android.util.Pair;
import androidx.annotation.VisibleForTesting;
import androidx.preference.ListPreference;
import androidx.preference.Preference;
import com.android.internal.logging.nano.MetricsProto;
import com.android.settingslib.core.lifecycle.Lifecycle;
public class ZenRuleMessagesPreferenceController extends AbstractZenCustomRulePreferenceController
implements Preference.OnPreferenceChangeListener {
private final String[] mListValues;
public ZenRuleMessagesPreferenceController(Context context, String key, Lifecycle lifecycle) {
super(context, key, lifecycle);
mListValues = context.getResources().getStringArray(
com.android.settings.R.array.zen_mode_contacts_values);
}
@Override
public void updateState(Preference preference) {
super.updateState(preference);
updateFromContactsValue(preference);
}
@Override
public boolean onPreferenceChange(Preference preference, Object selectedContactsFrom) {
int allowMessages = ZenModeBackend.getZenPolicySettingFromPrefKey(
selectedContactsFrom.toString());
mMetricsFeatureProvider.action(mContext,
MetricsProto.MetricsEvent.ACTION_ZEN_ALLOW_MESSAGES,
Pair.create(MetricsProto.MetricsEvent.FIELD_ZEN_TOGGLE_EXCEPTION, allowMessages),
Pair.create(MetricsProto.MetricsEvent.FIELD_ZEN_RULE_ID, mId));
mRule.setZenPolicy(new ZenPolicy.Builder(mRule.getZenPolicy())
.allowMessages(allowMessages)
.build());
mBackend.updateZenRule(mId, mRule);
updateFromContactsValue(preference);
return true;
}
private void updateFromContactsValue(Preference preference) {
if (mRule == null || mRule.getZenPolicy() == null) {
return;
}
ListPreference listPreference = (ListPreference) preference;
listPreference.setSummary(mBackend.getContactsMessagesSummary(mRule.getZenPolicy()));
final String currentVal = ZenModeBackend.getKeyFromZenPolicySetting(
mRule.getZenPolicy().getPriorityMessageSenders());
listPreference.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;
}
}

View File

@@ -0,0 +1,60 @@
/*
* 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.R;
import com.android.settingslib.core.lifecycle.Lifecycle;
public class ZenRuleNotifFooterPreferenceController extends
AbstractZenCustomRulePreferenceController {
public ZenRuleNotifFooterPreferenceController(Context context, Lifecycle lifecycle,
String key) {
super(context, key, lifecycle);
}
@Override
public boolean isAvailable() {
if (!super.isAvailable() || mRule.getZenPolicy() == null) {
return false;
}
return mRule.getZenPolicy().shouldHideAllVisualEffects()
|| mRule.getZenPolicy().shouldShowAllVisualEffects();
}
@Override
public void updateState(Preference preference) {
super.updateState(preference);
if (mRule == null || mRule.getZenPolicy() == null) {
return;
}
if (mRule.getZenPolicy().shouldShowAllVisualEffects()) {
preference.setTitle(R.string.zen_mode_restrict_notifications_mute_footer);
} else if (mRule.getZenPolicy().shouldHideAllVisualEffects()) {
preference.setTitle(R.string.zen_mode_restrict_notifications_hide_footer);
} else {
preference.setTitle(null);
}
}
}

View File

@@ -0,0 +1,91 @@
/*
* 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 android.service.notification.ZenPolicy;
import android.util.Log;
import android.util.Pair;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import androidx.preference.SwitchPreference;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settingslib.core.lifecycle.Lifecycle;
public class ZenRuleRepeatCallersPreferenceController extends
AbstractZenCustomRulePreferenceController implements Preference.OnPreferenceChangeListener {
private final int mRepeatCallersThreshold;
public ZenRuleRepeatCallersPreferenceController(Context context,
String key, Lifecycle lifecycle, int repeatCallersThreshold) {
super(context, key, lifecycle);
mRepeatCallersThreshold = repeatCallersThreshold;
}
@Override
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
setRepeatCallerSummary(screen.findPreference(KEY));
}
@Override
public void updateState(Preference preference) {
super.updateState(preference);
if (mRule == null || mRule.getZenPolicy() == null) {
return;
}
SwitchPreference pref = (SwitchPreference) preference;
boolean anyCallersCanBypassDnd = mRule.getZenPolicy().getPriorityCallSenders()
== ZenPolicy.PEOPLE_TYPE_ANYONE;
// if any caller can bypass dnd then repeat callers preference is disabled
if (anyCallersCanBypassDnd) {
pref.setEnabled(false);
pref.setChecked(true);
} else {
pref.setEnabled(true);
pref.setChecked(mRule.getZenPolicy().getPriorityCategoryRepeatCallers()
== ZenPolicy.STATE_ALLOW);
}
}
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
final boolean allow = (Boolean) newValue;
if (ZenModeSettingsBase.DEBUG) {
Log.d(TAG, KEY + " onPrefChange mRule=" + mRule + " mCategory="
+ ZenPolicy.PRIORITY_CATEGORY_REPEAT_CALLERS + " allow=" + allow);
}
mMetricsFeatureProvider.action(mContext, MetricsEvent.ACTION_ZEN_ALLOW_REPEAT_CALLS,
Pair.create(MetricsEvent.FIELD_ZEN_TOGGLE_EXCEPTION, allow ? 1 : 0),
Pair.create(MetricsEvent.FIELD_ZEN_RULE_ID, mId));
mRule.setZenPolicy(new ZenPolicy.Builder(mRule.getZenPolicy())
.allowRepeatCallers(allow)
.build());
mBackend.updateZenRule(mId, mRule);
return true;
}
private void setRepeatCallerSummary(Preference preference) {
preference.setSummary(mContext.getString(
com.android.settings.R.string.zen_mode_repeat_callers_summary,
mRepeatCallersThreshold));
}
}

View File

@@ -0,0 +1,103 @@
/*
* 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 android.content.Intent;
import android.content.pm.PackageManager;
import android.provider.Contacts;
import android.service.notification.ZenPolicy;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import com.android.settingslib.core.lifecycle.Lifecycle;
public class ZenRuleStarredContactsPreferenceController extends
AbstractZenCustomRulePreferenceController implements Preference.OnPreferenceClickListener {
private Preference mPreference;
private final @ZenPolicy.PriorityCategory int mPriorityCategory;
private final PackageManager mPackageManager;
private Intent mStarredContactsIntent;
private Intent mFallbackIntent;
public ZenRuleStarredContactsPreferenceController(Context context, Lifecycle lifecycle,
@ZenPolicy.PriorityCategory int priorityCategory, String key) {
super(context, key, lifecycle);
mPriorityCategory = priorityCategory;
mPackageManager = mContext.getPackageManager();
mStarredContactsIntent = new Intent(Contacts.Intents.UI.LIST_STARRED_ACTION);
mFallbackIntent = new Intent(Intent.ACTION_MAIN);
mFallbackIntent.addCategory(Intent.CATEGORY_APP_CONTACTS);
}
@Override
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
mPreference = screen.findPreference(KEY);
if (mPreference != null) {
mPreference.setOnPreferenceClickListener(this);
}
}
@Override
public String getPreferenceKey() {
return KEY;
}
@Override
public boolean isAvailable() {
if (!super.isAvailable() || mRule.getZenPolicy() == null || !isIntentValid()) {
return false;
}
if (mPriorityCategory == ZenPolicy.PRIORITY_CATEGORY_CALLS) {
return mRule.getZenPolicy().getPriorityCallSenders() == ZenPolicy.PEOPLE_TYPE_STARRED;
} else if (mPriorityCategory == ZenPolicy.PRIORITY_CATEGORY_MESSAGES) {
return mRule.getZenPolicy().getPriorityMessageSenders()
== ZenPolicy.PEOPLE_TYPE_STARRED;
} else {
// invalid category
return false;
}
}
@Override
public CharSequence getSummary() {
return mBackend.getStarredContactsSummary();
}
@Override
public boolean onPreferenceClick(Preference preference) {
if (mStarredContactsIntent.resolveActivity(mPackageManager) != null) {
mContext.startActivity(mStarredContactsIntent);
} else {
mContext.startActivity(mFallbackIntent);
}
return true;
}
private boolean isIntentValid() {
return mStarredContactsIntent.resolveActivity(mPackageManager) != null
|| mFallbackIntent.resolveActivity(mPackageManager) != null;
}
}

View File

@@ -0,0 +1,104 @@
/*
* 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 android.service.notification.ZenPolicy;
import android.util.Log;
import android.util.Pair;
import androidx.annotation.VisibleForTesting;
import androidx.preference.CheckBoxPreference;
import androidx.preference.Preference;
import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.widget.DisabledCheckBoxPreference;
import com.android.settingslib.core.lifecycle.Lifecycle;
public class ZenRuleVisEffectPreferenceController extends AbstractZenCustomRulePreferenceController
implements Preference.OnPreferenceChangeListener {
private final int mMetricsCategory;
@VisibleForTesting protected @ZenPolicy.VisualEffect int mEffect;
// if any of these effects are suppressed, this effect must be too
@VisibleForTesting protected @ZenPolicy.VisualEffect int[] mParentSuppressedEffects;
public ZenRuleVisEffectPreferenceController(Context context, Lifecycle lifecycle, String key,
@ZenPolicy.VisualEffect int visualEffect, int metricsCategory,
@ZenPolicy.VisualEffect int[] parentSuppressedEffects) {
super(context, key, lifecycle);
mEffect = visualEffect;
mMetricsCategory = metricsCategory;
mParentSuppressedEffects = parentSuppressedEffects;
}
@Override
public boolean isAvailable() {
if (!super.isAvailable()) {
return false;
}
if (mEffect == ZenPolicy.VISUAL_EFFECT_LIGHTS) {
return mContext.getResources()
.getBoolean(com.android.internal.R.bool.config_intrusiveNotificationLed);
}
return true;
}
@Override
public void updateState(Preference preference) {
super.updateState(preference);
if (mRule == null || mRule.getZenPolicy() == null) {
return;
}
boolean suppressed = !mRule.getZenPolicy().isVisualEffectAllowed(mEffect, false);
boolean parentSuppressed = false;
if (mParentSuppressedEffects != null) {
for (@ZenPolicy.VisualEffect int parentEffect : mParentSuppressedEffects) {
if (!mRule.getZenPolicy().isVisualEffectAllowed(parentEffect, true)) {
parentSuppressed = true;
}
}
}
if (parentSuppressed) {
((CheckBoxPreference) preference).setChecked(parentSuppressed);
onPreferenceChange(preference, parentSuppressed);
((DisabledCheckBoxPreference) preference).enableCheckbox(false);
} else {
((DisabledCheckBoxPreference) preference).enableCheckbox(true);
((CheckBoxPreference) preference).setChecked(suppressed);
}
}
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
final boolean suppressEffect = (Boolean) newValue;
mMetricsFeatureProvider.action(mContext, mMetricsCategory,
Pair.create(MetricsProto.MetricsEvent.FIELD_ZEN_TOGGLE_EXCEPTION,
suppressEffect ? 1 : 0),
Pair.create(MetricsProto.MetricsEvent.FIELD_ZEN_RULE_ID, mId));
mRule.setZenPolicy(new ZenPolicy.Builder(mRule.getZenPolicy())
.showVisualEffect(mEffect, !suppressEffect)
.build());
mBackend.updateZenRule(mId, mRule);
return true;
}
}

View File

@@ -0,0 +1,64 @@
/*
* 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 android.service.notification.ZenPolicy;
import android.util.Log;
import android.util.Pair;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settingslib.core.lifecycle.Lifecycle;
public class ZenRuleVisEffectsAllPreferenceController extends
AbstractZenCustomRulePreferenceController implements PreferenceControllerMixin {
private ZenCustomRadioButtonPreference mPreference;
public ZenRuleVisEffectsAllPreferenceController(Context context, Lifecycle lifecycle,
String key) {
super(context, key, lifecycle);
}
@Override
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
mPreference = (ZenCustomRadioButtonPreference) screen.findPreference(getPreferenceKey());
mPreference.setOnRadioButtonClickListener(p -> {
mMetricsFeatureProvider.action(mContext, MetricsEvent.ACTION_ZEN_SOUND_ONLY,
Pair.create(MetricsEvent.FIELD_ZEN_RULE_ID, mId));
mRule.setZenPolicy(new ZenPolicy.Builder(mRule.getZenPolicy())
.showAllVisualEffects()
.build());
mBackend.updateZenRule(mId, mRule);
});
}
@Override
public void updateState(Preference preference) {
super.updateState(preference);
if (mId == null || mRule == null || mRule.getZenPolicy() == null) {
return;
}
mPreference.setChecked(mRule.getZenPolicy().shouldShowAllVisualEffects());
}
}

View File

@@ -0,0 +1,75 @@
/*
* 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 android.util.Pair;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settings.core.SubSettingLauncher;
import com.android.settingslib.core.lifecycle.Lifecycle;
public class ZenRuleVisEffectsCustomPreferenceController extends
AbstractZenCustomRulePreferenceController implements PreferenceControllerMixin {
private ZenCustomRadioButtonPreference mPreference;
public ZenRuleVisEffectsCustomPreferenceController(Context context, Lifecycle lifecycle,
String key) {
super(context, key, lifecycle);
}
@Override
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
mPreference = (ZenCustomRadioButtonPreference) screen.findPreference(getPreferenceKey());
mPreference.setOnGearClickListener(p -> {
launchCustomSettings();
});
mPreference.setOnRadioButtonClickListener(p -> {
launchCustomSettings();
});
}
@Override
public void updateState(Preference preference) {
super.updateState(preference);
if (mId == null || mRule == null || mRule.getZenPolicy() == null) {
return;
}
mPreference.setChecked(!mRule.getZenPolicy().shouldHideAllVisualEffects()
&& !mRule.getZenPolicy().shouldShowAllVisualEffects());
}
private void launchCustomSettings() {
mMetricsFeatureProvider.action(mContext, MetricsEvent.ACTION_ZEN_SHOW_CUSTOM,
Pair.create(MetricsEvent.FIELD_ZEN_RULE_ID, mId));
new SubSettingLauncher(mContext)
.setDestination(ZenCustomRuleBlockedEffectsSettings.class.getName())
.setArguments(createBundle())
.setSourceMetricsCategory(MetricsEvent.ZEN_CUSTOM_RULE_VIS_EFFECTS)
.launch();
}
}

View File

@@ -0,0 +1,65 @@
/*
* 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 android.service.notification.ZenPolicy;
import android.util.Log;
import android.util.Pair;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.core.PreferenceControllerMixin;
import com.android.settingslib.core.lifecycle.Lifecycle;
public class ZenRuleVisEffectsNonePreferenceController extends
AbstractZenCustomRulePreferenceController implements PreferenceControllerMixin {
private ZenCustomRadioButtonPreference mPreference;
public ZenRuleVisEffectsNonePreferenceController(Context context, Lifecycle lifecycle,
String key) {
super(context, key, lifecycle);
}
@Override
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
mPreference = (ZenCustomRadioButtonPreference) screen.findPreference(getPreferenceKey());
mPreference.setOnRadioButtonClickListener(p -> {
mMetricsFeatureProvider.action(mContext, MetricsEvent.ACTION_ZEN_SOUND_AND_VIS_EFFECTS,
Pair.create(MetricsEvent.FIELD_ZEN_RULE_ID, mId));
mRule.setZenPolicy(new ZenPolicy.Builder(mRule.getZenPolicy())
.hideAllVisualEffects()
.build());
mBackend.updateZenRule(mId, mRule);
});
}
@Override
public void updateState(Preference preference) {
super.updateState(preference);
if (mId == null || mRule == null || mRule.getZenPolicy() == null) {
return;
}
mPreference.setChecked(mRule.getZenPolicy().shouldHideAllVisualEffects());
}
}