diff options
author | John Spurlock <jspurlock@google.com> | 2015-05-29 12:04:21 -0400 |
---|---|---|
committer | John Spurlock <jspurlock@google.com> | 2015-05-29 12:18:34 -0400 |
commit | 8be53eaaf7b2dcc5617c6ed6bef14d15cbe9e28d (patch) | |
tree | 65157a18d1fe40bf128b272bcf1771b57d6d7a4e /packages/SystemUI/src/com/android/systemui/volume | |
parent | f40d08f8a3094ac5d5478efc5de0b96f57d2c5df (diff) | |
download | frameworks_base-8be53eaaf7b2dcc5617c6ed6bef14d15cbe9e28d.zip frameworks_base-8be53eaaf7b2dcc5617c6ed6bef14d15cbe9e28d.tar.gz frameworks_base-8be53eaaf7b2dcc5617c6ed6bef14d15cbe9e28d.tar.bz2 |
Zen: Add warning text if total silence will eat the next alarm.
Bug: 21359239
Change-Id: I8a69738e6488f40f24eed622529c913b6c3865a0
Diffstat (limited to 'packages/SystemUI/src/com/android/systemui/volume')
-rw-r--r-- | packages/SystemUI/src/com/android/systemui/volume/ZenModePanel.java | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/volume/ZenModePanel.java b/packages/SystemUI/src/com/android/systemui/volume/ZenModePanel.java index ec24d75..027d637 100644 --- a/packages/SystemUI/src/com/android/systemui/volume/ZenModePanel.java +++ b/packages/SystemUI/src/com/android/systemui/volume/ZenModePanel.java @@ -35,6 +35,7 @@ import android.service.notification.Condition; import android.service.notification.ZenModeConfig; import android.service.notification.ZenModeConfig.ZenRule; import android.text.TextUtils; +import android.text.format.DateFormat; import android.util.ArraySet; import android.util.AttributeSet; import android.util.Log; @@ -57,6 +58,7 @@ import com.android.systemui.statusbar.policy.ZenModeController; import java.io.FileDescriptor; import java.io.PrintWriter; import java.util.Arrays; +import java.util.Locale; import java.util.Objects; public class ZenModePanel extends LinearLayout { @@ -96,6 +98,7 @@ public class ZenModePanel extends LinearLayout { private View mZenIntroductionConfirm; private View mZenIntroductionCustomize; private LinearLayout mZenConditions; + private TextView mZenAlarmWarning; private Callback mCallback; private ZenModeController mController; @@ -176,6 +179,7 @@ public class ZenModePanel extends LinearLayout { }); mZenConditions = (LinearLayout) findViewById(R.id.zen_conditions); + mZenAlarmWarning = (TextView) findViewById(R.id.zen_alarm_warning); } @Override @@ -436,6 +440,40 @@ public class ZenModePanel extends LinearLayout { : R.string.zen_silence_introduction); mZenIntroductionCustomize.setVisibility(zenImportant ? VISIBLE : GONE); } + final String warning = computeAlarmWarningText(zenNone); + mZenAlarmWarning.setVisibility(warning != null ? VISIBLE : GONE); + mZenAlarmWarning.setText(warning); + } + + private String computeAlarmWarningText(boolean zenNone) { + if (!zenNone) { + return null; + } + final long now = System.currentTimeMillis(); + final long nextAlarm = mController.getNextAlarm(); + if (nextAlarm < now) { + return null; + } + int warningRes = 0; + if (mSessionExitCondition == null || isForever(mSessionExitCondition)) { + warningRes = R.string.zen_alarm_warning_indef; + } else { + final long time = ZenModeConfig.tryParseCountdownConditionId(mSessionExitCondition.id); + if (time > now && nextAlarm < time) { + warningRes = R.string.zen_alarm_warning; + } + } + if (warningRes == 0) { + return null; + } + final boolean soon = (nextAlarm - now) < 24 * 60 * 60 * 1000; + final boolean is24 = DateFormat.is24HourFormat(mContext, ActivityManager.getCurrentUser()); + final String skeleton = soon ? (is24 ? "Hm" : "hma") : (is24 ? "EEEHm" : "EEEhma"); + final String pattern = DateFormat.getBestDateTimePattern(Locale.getDefault(), skeleton); + final CharSequence formattedTime = DateFormat.format(pattern, nextAlarm); + final int templateRes = soon ? R.string.alarm_template : R.string.alarm_template_far; + final String template = getResources().getString(templateRes, formattedTime); + return getResources().getString(warningRes, template); } private static Condition parseExistingTimeCondition(Context context, Condition condition) { |