Moved zenMode visual effects + automatic rule page
- Automatic zen rules have their own page like in N - Minor string changes to page and add rule dialog - Zen mode visual effects was moved into behavior settings Bug: 63077372 Test: $ make SettingsUnitTests -j40 $ adb install -r ${OUT}/data/app/SettingsUnitTests/SettingsUnitTests.apk $ adb shell am instrument -w com.android.settings.tests.unit/android.support.test.runner.AndroidJUnitRunner Change-Id: I9635f8f7969b76d036bc06ec44705815e540777a
This commit is contained in:
@@ -16,37 +16,22 @@
|
||||
|
||||
package com.android.settings.notification;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.app.AutomaticZenRule;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.NotificationManager.Policy;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.ServiceInfo;
|
||||
import android.content.res.Resources;
|
||||
import android.os.Bundle;
|
||||
import android.provider.SearchIndexableResource;
|
||||
import android.provider.Settings;
|
||||
import android.service.notification.ConditionProviderService;
|
||||
import android.service.notification.ZenModeConfig;
|
||||
import android.support.annotation.VisibleForTesting;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceCategory;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
import android.support.v7.preference.PreferenceViewHolder;
|
||||
import android.view.View;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.search.BaseSearchIndexProvider;
|
||||
import com.android.settings.search.Indexable;
|
||||
import com.android.settings.utils.ManagedServiceSettings;
|
||||
import com.android.settings.utils.ZenServiceListing;
|
||||
import com.android.settingslib.TwoTargetPreference;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@@ -57,19 +42,13 @@ import java.util.Map.Entry;
|
||||
|
||||
public class ZenModeSettings extends ZenModeSettingsBase implements Indexable {
|
||||
|
||||
public static final String KEY_VISUAL_SETTINGS = "zen_mode_visual_interruptions_settings";
|
||||
private static final String KEY_BEHAVIOR_SETTINGS = "zen_mode_behavior_settings";
|
||||
private static final String KEY_AUTOMATIC_RULES = "zen_mode_automatic_rules";
|
||||
private static final String KEY_AUTOMATION_SETTINGS = "zen_mode_automation_settings";
|
||||
|
||||
static final ManagedServiceSettings.Config CONFIG = getConditionProviderConfig();
|
||||
|
||||
private PreferenceCategory mAutomaticRules;
|
||||
private Preference mBehaviorSettings;
|
||||
private Preference mVisualSettings;
|
||||
private Preference mAutomationSettings;
|
||||
private Policy mPolicy;
|
||||
private SummaryBuilder mSummaryBuilder;
|
||||
private PackageManager mPm;
|
||||
private ZenServiceListing mServiceListing;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
@@ -78,14 +57,10 @@ public class ZenModeSettings extends ZenModeSettingsBase implements Indexable {
|
||||
addPreferencesFromResource(R.xml.zen_mode_settings);
|
||||
final PreferenceScreen root = getPreferenceScreen();
|
||||
|
||||
mAutomaticRules = (PreferenceCategory) root.findPreference(KEY_AUTOMATIC_RULES);
|
||||
mBehaviorSettings = root.findPreference(KEY_BEHAVIOR_SETTINGS);
|
||||
mVisualSettings = root.findPreference(KEY_VISUAL_SETTINGS);
|
||||
mAutomationSettings = root.findPreference(KEY_AUTOMATION_SETTINGS);
|
||||
mPolicy = NotificationManager.from(mContext).getNotificationPolicy();
|
||||
mSummaryBuilder = new SummaryBuilder(getContext());
|
||||
mPm = mContext.getPackageManager();
|
||||
mServiceListing = new ZenServiceListing(mContext, CONFIG);
|
||||
mServiceListing.reloadApprovedServices();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -115,168 +90,15 @@ public class ZenModeSettings extends ZenModeSettingsBase implements Indexable {
|
||||
|
||||
private void updateControls() {
|
||||
updateBehaviorSettingsSummary();
|
||||
updateVisualSettingsSummary();
|
||||
updateAutomaticRules();
|
||||
updateAutomationSettingsSummary();
|
||||
}
|
||||
|
||||
private void updateBehaviorSettingsSummary() {
|
||||
mBehaviorSettings.setSummary(mSummaryBuilder.getBehaviorSettingSummary(mPolicy, mZenMode));
|
||||
}
|
||||
|
||||
private void updateVisualSettingsSummary() {
|
||||
mVisualSettings.setSummary(mSummaryBuilder.getVisualSettingSummary(mPolicy));
|
||||
}
|
||||
|
||||
private void updateAutomaticRules() {
|
||||
mAutomaticRules.removeAll();
|
||||
final Map.Entry<String,AutomaticZenRule>[] sortedRules = sortedRules();
|
||||
for (Map.Entry<String,AutomaticZenRule> sortedRule : sortedRules) {
|
||||
ZenRulePreference pref = new ZenRulePreference(getPrefContext(), sortedRule);
|
||||
if (pref.appExists) {
|
||||
mAutomaticRules.addPreference(pref);
|
||||
}
|
||||
}
|
||||
final Preference p = new Preference(getPrefContext());
|
||||
p.setIcon(R.drawable.ic_menu_add);
|
||||
p.setTitle(R.string.zen_mode_add_rule);
|
||||
p.setPersistent(false);
|
||||
p.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
mMetricsFeatureProvider.action(mContext, MetricsEvent.ACTION_ZEN_ADD_RULE);
|
||||
showAddRuleDialog();
|
||||
return true;
|
||||
}
|
||||
});
|
||||
mAutomaticRules.addPreference(p);
|
||||
}
|
||||
|
||||
private void showAddRuleDialog() {
|
||||
new ZenRuleSelectionDialog(mContext, mServiceListing) {
|
||||
@Override
|
||||
public void onSystemRuleSelected(ZenRuleInfo ri) {
|
||||
showNameRuleDialog(ri);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onExternalRuleSelected(ZenRuleInfo ri) {
|
||||
Intent intent = new Intent().setComponent(ri.configurationActivity);
|
||||
startActivity(intent);
|
||||
}
|
||||
}.show();
|
||||
}
|
||||
|
||||
private String computeRuleSummary(AutomaticZenRule rule, boolean isSystemRule,
|
||||
CharSequence providerLabel) {
|
||||
final String mode = computeZenModeCaption(getResources(), rule.getInterruptionFilter());
|
||||
final String ruleState = (rule == null || !rule.isEnabled())
|
||||
? getString(R.string.switch_off_text)
|
||||
: getString(R.string.zen_mode_rule_summary_enabled_combination, mode);
|
||||
|
||||
return ruleState;
|
||||
}
|
||||
|
||||
private static ManagedServiceSettings.Config getConditionProviderConfig() {
|
||||
final ManagedServiceSettings.Config c = new ManagedServiceSettings.Config();
|
||||
c.tag = TAG;
|
||||
c.intentAction = ConditionProviderService.SERVICE_INTERFACE;
|
||||
c.permission = android.Manifest.permission.BIND_CONDITION_PROVIDER_SERVICE;
|
||||
c.noun = "condition provider";
|
||||
return c;
|
||||
}
|
||||
|
||||
private static String computeZenModeCaption(Resources res, int zenMode) {
|
||||
switch (zenMode) {
|
||||
case NotificationManager.INTERRUPTION_FILTER_ALARMS:
|
||||
return res.getString(R.string.zen_mode_option_alarms);
|
||||
case NotificationManager.INTERRUPTION_FILTER_PRIORITY:
|
||||
return res.getString(R.string.zen_mode_option_important_interruptions);
|
||||
case NotificationManager.INTERRUPTION_FILTER_NONE:
|
||||
return res.getString(R.string.zen_mode_option_no_interruptions);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static ZenRuleInfo getRuleInfo(PackageManager pm, ServiceInfo si) {
|
||||
if (si == null || si.metaData == null) return null;
|
||||
final String ruleType = si.metaData.getString(ConditionProviderService.META_DATA_RULE_TYPE);
|
||||
final ComponentName configurationActivity = getSettingsActivity(si);
|
||||
if (ruleType != null && !ruleType.trim().isEmpty() && configurationActivity != null) {
|
||||
final ZenRuleInfo ri = new ZenRuleInfo();
|
||||
ri.serviceComponent = new ComponentName(si.packageName, si.name);
|
||||
ri.settingsAction = Settings.ACTION_ZEN_MODE_EXTERNAL_RULE_SETTINGS;
|
||||
ri.title = ruleType;
|
||||
ri.packageName = si.packageName;
|
||||
ri.configurationActivity = getSettingsActivity(si);
|
||||
ri.packageLabel = si.applicationInfo.loadLabel(pm);
|
||||
ri.ruleInstanceLimit =
|
||||
si.metaData.getInt(ConditionProviderService.META_DATA_RULE_INSTANCE_LIMIT, -1);
|
||||
return ri;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static ComponentName getSettingsActivity(ServiceInfo si) {
|
||||
if (si == null || si.metaData == null) return null;
|
||||
final String configurationActivity =
|
||||
si.metaData.getString(ConditionProviderService.META_DATA_CONFIGURATION_ACTIVITY);
|
||||
if (configurationActivity != null) {
|
||||
return ComponentName.unflattenFromString(configurationActivity);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void showNameRuleDialog(final ZenRuleInfo ri) {
|
||||
new ZenRuleNameDialog(mContext, null) {
|
||||
@Override
|
||||
public void onOk(String ruleName) {
|
||||
mMetricsFeatureProvider.action(mContext, MetricsEvent.ACTION_ZEN_ADD_RULE_OK);
|
||||
AutomaticZenRule rule = new AutomaticZenRule(ruleName, ri.serviceComponent,
|
||||
ri.defaultConditionId, NotificationManager.INTERRUPTION_FILTER_PRIORITY,
|
||||
true);
|
||||
String savedRuleId = addZenRule(rule);
|
||||
if (savedRuleId != null) {
|
||||
startActivity(getRuleIntent(ri.settingsAction, null, savedRuleId));
|
||||
}
|
||||
}
|
||||
}.show();
|
||||
}
|
||||
|
||||
private void showDeleteRuleDialog(final String ruleId, final CharSequence ruleName) {
|
||||
new AlertDialog.Builder(mContext)
|
||||
.setMessage(getString(R.string.zen_mode_delete_rule_confirmation, ruleName))
|
||||
.setNegativeButton(R.string.cancel, null)
|
||||
.setPositiveButton(R.string.zen_mode_delete_rule_button,
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
mMetricsFeatureProvider.action(mContext,
|
||||
MetricsEvent.ACTION_ZEN_DELETE_RULE_OK);
|
||||
removeZenRule(ruleId);
|
||||
}
|
||||
})
|
||||
.show();
|
||||
}
|
||||
|
||||
private Intent getRuleIntent(String settingsAction, ComponentName configurationActivity,
|
||||
String ruleId) {
|
||||
Intent intent = new Intent()
|
||||
.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
|
||||
.putExtra(ConditionProviderService.EXTRA_RULE_ID, ruleId);
|
||||
if (configurationActivity != null) {
|
||||
intent.setComponent(configurationActivity);
|
||||
} else {
|
||||
intent.setAction(settingsAction);
|
||||
}
|
||||
return intent;
|
||||
}
|
||||
|
||||
private Map.Entry<String,AutomaticZenRule>[] sortedRules() {
|
||||
final Map.Entry<String,AutomaticZenRule>[] rt =
|
||||
mRules.toArray(new Map.Entry[mRules.size()]);
|
||||
Arrays.sort(rt, RULE_COMPARATOR);
|
||||
return rt;
|
||||
private void updateAutomationSettingsSummary() {
|
||||
mAutomationSettings.setSummary(mSummaryBuilder.getAutomaticRulesSummary());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -284,67 +106,6 @@ public class ZenModeSettings extends ZenModeSettingsBase implements Indexable {
|
||||
return R.string.help_uri_interruptions;
|
||||
}
|
||||
|
||||
private class ZenRulePreference extends TwoTargetPreference {
|
||||
final CharSequence mName;
|
||||
final String mId;
|
||||
final boolean appExists;
|
||||
|
||||
public ZenRulePreference(Context context,
|
||||
final Map.Entry<String, AutomaticZenRule> ruleEntry) {
|
||||
super(context);
|
||||
|
||||
final AutomaticZenRule rule = ruleEntry.getValue();
|
||||
mName = rule.getName();
|
||||
mId = ruleEntry.getKey();
|
||||
|
||||
final boolean isSchedule = ZenModeConfig.isValidScheduleConditionId(
|
||||
rule.getConditionId());
|
||||
final boolean isEvent = ZenModeConfig.isValidEventConditionId(rule.getConditionId());
|
||||
final boolean isSystemRule = isSchedule || isEvent;
|
||||
|
||||
try {
|
||||
ApplicationInfo info = mPm.getApplicationInfo(rule.getOwner().getPackageName(), 0);
|
||||
setSummary(computeRuleSummary(rule, isSystemRule, info.loadLabel(mPm)));
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
appExists = false;
|
||||
return;
|
||||
}
|
||||
|
||||
appExists = true;
|
||||
setTitle(rule.getName());
|
||||
setPersistent(false);
|
||||
|
||||
final String action = isSchedule ? ZenModeScheduleRuleSettings.ACTION
|
||||
: isEvent ? ZenModeEventRuleSettings.ACTION : "";
|
||||
ServiceInfo si = mServiceListing.findService(rule.getOwner());
|
||||
ComponentName settingsActivity = getSettingsActivity(si);
|
||||
setIntent(getRuleIntent(action, settingsActivity, mId));
|
||||
setSelectable(settingsActivity != null || isSystemRule);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getSecondTargetResId() {
|
||||
return R.layout.zen_rule_widget;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(PreferenceViewHolder view) {
|
||||
super.onBindViewHolder(view);
|
||||
|
||||
View v = view.findViewById(R.id.delete_zen_rule);
|
||||
if (v != null) {
|
||||
v.setOnClickListener(mDeleteListener);
|
||||
}
|
||||
}
|
||||
|
||||
private final View.OnClickListener mDeleteListener = new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
showDeleteRuleDialog(mId, mName);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static class SummaryBuilder {
|
||||
|
||||
private Context mContext;
|
||||
@@ -393,19 +154,6 @@ public class ZenModeSettings extends ZenModeSettingsBase implements Indexable {
|
||||
return mContext.getString(R.string.zen_mode_behavior_no_sound_except, s);
|
||||
}
|
||||
|
||||
String getVisualSettingSummary(Policy policy) {
|
||||
String s = mContext.getString(R.string.zen_mode_all_visual_interruptions);
|
||||
if (isEffectSuppressed(policy, Policy.SUPPRESSED_EFFECT_SCREEN_ON)
|
||||
&& isEffectSuppressed(policy, Policy.SUPPRESSED_EFFECT_SCREEN_OFF)) {
|
||||
s = mContext.getString(R.string.zen_mode_no_visual_interruptions);
|
||||
} else if (isEffectSuppressed(policy, Policy.SUPPRESSED_EFFECT_SCREEN_ON)) {
|
||||
s = mContext.getString(R.string.zen_mode_screen_on_visual_interruptions);
|
||||
} else if (isEffectSuppressed(policy, Policy.SUPPRESSED_EFFECT_SCREEN_OFF)) {
|
||||
s = mContext.getString(R.string.zen_mode_screen_off_visual_interruptions);
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
String getAutomaticRulesSummary() {
|
||||
final int count = getEnabledAutomaticRulesCount();
|
||||
return count == 0 ? mContext.getString(R.string.zen_mode_settings_summary_off)
|
||||
@@ -479,7 +227,7 @@ public class ZenModeSettings extends ZenModeSettingsBase implements Indexable {
|
||||
}
|
||||
}
|
||||
|
||||
private static final Comparator<Map.Entry<String,AutomaticZenRule>> RULE_COMPARATOR =
|
||||
private static final Comparator<Entry<String,AutomaticZenRule>> RULE_COMPARATOR =
|
||||
new Comparator<Map.Entry<String,AutomaticZenRule>>() {
|
||||
@Override
|
||||
public int compare(Map.Entry<String,AutomaticZenRule> lhs,
|
||||
@@ -502,6 +250,7 @@ public class ZenModeSettings extends ZenModeSettingsBase implements Indexable {
|
||||
return type + rule.getName().toString();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* For Search.
|
||||
*/
|
||||
@@ -515,4 +264,5 @@ public class ZenModeSettings extends ZenModeSettingsBase implements Indexable {
|
||||
return Arrays.asList(sir);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user