summaryrefslogtreecommitdiffstats
path: root/src/com/android/settings/notification
diff options
context:
space:
mode:
authorJohn Spurlock <jspurlock@google.com>2015-04-09 23:57:23 -0400
committerJohn Spurlock <jspurlock@google.com>2015-04-10 00:02:32 -0400
commitd333a7d9f10500ec45377e099955031017d6a158 (patch)
tree8534a44554e32965472b38110fc4be6020cb7021 /src/com/android/settings/notification
parent45fa140b8c6846b4546fdeabebf989ae9102cebb (diff)
downloadpackages_apps_Settings-d333a7d9f10500ec45377e099955031017d6a158.zip
packages_apps_Settings-d333a7d9f10500ec45377e099955031017d6a158.tar.gz
packages_apps_Settings-d333a7d9f10500ec45377e099955031017d6a158.tar.bz2
Settings: Improve automatic rule summary when enabled.
Bug: 20064962 Change-Id: I139679def84f0ba3ea859399499a5657fd85e763
Diffstat (limited to 'src/com/android/settings/notification')
-rw-r--r--src/com/android/settings/notification/ZenModeAutomationSettings.java68
-rw-r--r--src/com/android/settings/notification/ZenModeScheduleRuleSettings.java4
-rw-r--r--src/com/android/settings/notification/ZenModeSettings.java12
3 files changed, 75 insertions, 9 deletions
diff --git a/src/com/android/settings/notification/ZenModeAutomationSettings.java b/src/com/android/settings/notification/ZenModeAutomationSettings.java
index 09de7d1..c43d99e 100644
--- a/src/com/android/settings/notification/ZenModeAutomationSettings.java
+++ b/src/com/android/settings/notification/ZenModeAutomationSettings.java
@@ -16,6 +16,8 @@
package com.android.settings.notification;
+import static android.service.notification.ZenModeConfig.ALL_DAYS;
+
import android.content.Intent;
import android.os.Bundle;
import android.preference.Preference;
@@ -25,6 +27,7 @@ import android.provider.Settings.Global;
import android.service.notification.ZenModeConfig;
import android.service.notification.ZenModeConfig.ScheduleInfo;
import android.service.notification.ZenModeConfig.ZenRule;
+import android.text.format.DateFormat;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
@@ -33,7 +36,14 @@ import android.view.MenuItem;
import com.android.internal.logging.MetricsLogger;
import com.android.settings.R;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.TreeSet;
+
public class ZenModeAutomationSettings extends ZenModeSettingsBase {
+ private static final SimpleDateFormat DAY_FORMAT = new SimpleDateFormat("EEE");
+
+ private final Calendar mCalendar = Calendar.getInstance();
@Override
public void onCreate(Bundle icicle) {
@@ -115,7 +125,7 @@ public class ZenModeAutomationSettings extends ZenModeSettingsBase {
if (!ZenModeConfig.isValidScheduleConditionId(rule.conditionId)) continue;
final Preference p = new Preference(mContext);
p.setTitle(rule.name);
- p.setSummary(rule.enabled ? R.string.switch_on_text : R.string.switch_off_text);
+ p.setSummary(computeRuleSummary(rule));
p.setPersistent(false);
p.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
@@ -133,4 +143,60 @@ public class ZenModeAutomationSettings extends ZenModeSettingsBase {
return MetricsLogger.NOTIFICATION_ZEN_MODE_AUTOMATION;
}
+ private String computeRuleSummary(ZenRule rule) {
+ if (rule == null || !rule.enabled) return getString(R.string.switch_off_text);
+ final ScheduleInfo schedule = ZenModeConfig.tryParseScheduleConditionId(rule.conditionId);
+ if (schedule == null) return getString(R.string.switch_on_text);
+ final String days = computeContiguousDayRanges(schedule.days);
+ final String start = getTime(schedule.startHour, schedule.startMinute);
+ final String end = getTime(schedule.endHour, schedule.endMinute);
+ final String time = getString(R.string.summary_range_verbal_combination, start, end);
+ final String mode = ZenModeSettings.computeZenModeCaption(getResources(), rule.zenMode);
+ return getString(R.string.zen_mode_rule_summary_template, days, time, mode);
+ }
+
+ private String getTime(int hour, int minute) {
+ mCalendar.set(Calendar.HOUR_OF_DAY, hour);
+ mCalendar.set(Calendar.MINUTE, minute);
+ return DateFormat.getTimeFormat(mContext).format(mCalendar.getTime());
+ }
+
+ private String computeContiguousDayRanges(int[] days) {
+ final TreeSet<Integer> daySet = new TreeSet<>();
+ for (int i = 0; days != null && i < days.length; i++) {
+ daySet.add(days[i]);
+ }
+ if (daySet.isEmpty()) {
+ return getString(R.string.zen_mode_schedule_rule_days_none);
+ }
+ final int N = ALL_DAYS.length;
+ if (daySet.size() == N) {
+ return getString(R.string.zen_mode_schedule_rule_days_all);
+ }
+ String rt = null;
+ for (int i = 0; i < N; i++) {
+ final int startDay = ALL_DAYS[i];
+ final boolean active = daySet.contains(startDay);
+ if (!active) continue;
+ int end = 0;
+ while (daySet.contains(ALL_DAYS[(i + end + 1) % N])) {
+ end++;
+ }
+ if (!(i == 0 && daySet.contains(ALL_DAYS[N - 1]))) {
+ final String v = end == 0 ? dayString(startDay)
+ : getString(R.string.summary_range_symbol_combination,
+ dayString(startDay),
+ dayString(ALL_DAYS[(i + end) % N]));
+ rt = rt == null ? v : getString(R.string.summary_divider_text, rt, v);
+ }
+ i += end;
+ }
+ return rt;
+ }
+
+ private String dayString(int day) {
+ mCalendar.set(Calendar.DAY_OF_WEEK, day);
+ return DAY_FORMAT.format(mCalendar.getTime());
+ }
+
}
diff --git a/src/com/android/settings/notification/ZenModeScheduleRuleSettings.java b/src/com/android/settings/notification/ZenModeScheduleRuleSettings.java
index 7bec3c4..f0f0294 100644
--- a/src/com/android/settings/notification/ZenModeScheduleRuleSettings.java
+++ b/src/com/android/settings/notification/ZenModeScheduleRuleSettings.java
@@ -209,8 +209,8 @@ public class ZenModeScheduleRuleSettings extends ZenModeSettingsBase
return true;
}
if (DEBUG) Log.d(TAG, "onPrefChange end h=" + hour + " m=" + minute);
- mSchedule.startHour = hour;
- mSchedule.startMinute = minute;
+ mSchedule.endHour = hour;
+ mSchedule.endMinute = minute;
mRule.conditionId = ZenModeConfig.toScheduleConditionId(mSchedule);
mRule.condition = null;
mRule.snoozing = false;
diff --git a/src/com/android/settings/notification/ZenModeSettings.java b/src/com/android/settings/notification/ZenModeSettings.java
index 4ff5e0f..88ecef5 100644
--- a/src/com/android/settings/notification/ZenModeSettings.java
+++ b/src/com/android/settings/notification/ZenModeSettings.java
@@ -126,21 +126,21 @@ public class ZenModeSettings extends ZenModeSettingsBase
updateControls();
}
- private String computeZenModeCaption(int zenMode) {
+ public static String computeZenModeCaption(Resources res, int zenMode) {
switch (zenMode) {
case Global.ZEN_MODE_ALARMS:
- return getString(R.string.zen_mode_option_alarms);
+ return res.getString(R.string.zen_mode_option_alarms);
case Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS:
- return getString(R.string.zen_mode_option_important_interruptions);
+ return res.getString(R.string.zen_mode_option_important_interruptions);
case Global.ZEN_MODE_NO_INTERRUPTIONS:
- return getString(R.string.zen_mode_option_no_interruptions);
+ return res.getString(R.string.zen_mode_option_no_interruptions);
default:
return null;
}
}
private String computeZenModeSummaryLine() {
- final String caption = computeZenModeCaption(mZenMode);
+ final String caption = computeZenModeCaption(getResources(), mZenMode);
if (caption == null) return null; // zen mode off
final String conditionText = ZenModeConfig.getConditionLine1(mContext, mConfig,
UserHandle.myUserId());
@@ -190,7 +190,7 @@ public class ZenModeSettings extends ZenModeSettingsBase
ScrollView scrollView = new ScrollView(mContext);
scrollView.addView(zenModeConditionSelection);
mDialog = new AlertDialog.Builder(getActivity())
- .setTitle(computeZenModeCaption(zenMode))
+ .setTitle(computeZenModeCaption(getResources(), zenMode))
.setView(scrollView)
.setPositiveButton(R.string.okay, positiveListener)
.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {