Merge "Update Sound settings."
This commit is contained in:
committed by
Android (Google) Code Review
commit
08a3bb368b
@@ -16,22 +16,18 @@
|
||||
|
||||
package com.android.settings.notification;
|
||||
|
||||
import android.app.NotificationManager;
|
||||
import android.content.Context;
|
||||
import android.support.v7.preference.Preference;
|
||||
import com.android.settings.R;
|
||||
|
||||
public class ZenModePreferenceController extends AdjustVolumeRestrictedPreferenceController {
|
||||
|
||||
private static final String KEY_ZEN_MODE = "zen_mode";
|
||||
private String mSummaryPrefix;
|
||||
|
||||
private ZenModeSettings.SummaryBuilder mSummaryBuilder;
|
||||
|
||||
public ZenModePreferenceController(Context context) {
|
||||
super(context);
|
||||
mSummaryBuilder = new ZenModeSettings.SummaryBuilder(context);
|
||||
mSummaryPrefix = context.getString(R.string.zen_mode_priority_settings_title) + " ";
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -48,8 +44,7 @@ public class ZenModePreferenceController extends AdjustVolumeRestrictedPreferenc
|
||||
public void updateState(Preference preference) {
|
||||
super.updateState(preference);
|
||||
if (preference.isEnabled()) {
|
||||
preference.setSummary(mSummaryPrefix + mSummaryBuilder.getPrioritySettingSummary(
|
||||
NotificationManager.from(mContext).getNotificationPolicy()));
|
||||
preference.setSummary(mSummaryBuilder.getAutomaticRulesSummary());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.android.settings.notification;
|
||||
|
||||
import android.app.AutomaticZenRule;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.NotificationManager.Policy;
|
||||
import android.content.Context;
|
||||
@@ -26,6 +27,9 @@ import android.support.v7.preference.PreferenceScreen;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.R;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
||||
public class ZenModeSettings extends ZenModeSettingsBase {
|
||||
private static final String KEY_PRIORITY_SETTINGS = "priority_settings";
|
||||
@@ -137,6 +141,29 @@ public class ZenModeSettings extends ZenModeSettingsBase {
|
||||
return s;
|
||||
}
|
||||
|
||||
String getAutomaticRulesSummary() {
|
||||
final int count = getEnabledAutomaticRulesCount();
|
||||
return count == 0 ? mContext.getString(R.string.zen_mode_settings_summary_off)
|
||||
: mContext.getResources().getQuantityString(
|
||||
R.plurals.zen_mode_settings_summary_on, count, count);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
int getEnabledAutomaticRulesCount() {
|
||||
int count = 0;
|
||||
final Map<String, AutomaticZenRule> ruleMap =
|
||||
NotificationManager.from(mContext).getAutomaticZenRules();
|
||||
if (ruleMap != null) {
|
||||
for (Entry<String, AutomaticZenRule> ruleEntry : ruleMap.entrySet()) {
|
||||
final AutomaticZenRule rule = ruleEntry.getValue();
|
||||
if (rule != null && rule.isEnabled()) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
String append(String s, boolean condition, int resId) {
|
||||
if (condition) {
|
||||
|
Reference in New Issue
Block a user