From c90e6fe863bb5ac84612bd777d3b352f69265950 Mon Sep 17 00:00:00 2001 From: John Spurlock Date: Tue, 28 Oct 2014 11:21:42 -0400 Subject: [PATCH] Zen: Show "(until 4:56 PM)" in exit conditions. Implement two-line exit conditions, display the duration + end time on separate lines. Bug: 16824863 Change-Id: I8dabc83042fce604ccb86b463b9bb547c7903c64 --- .../service/notification/ZenModeConfig.java | 37 ++++++++--- core/res/res/values/strings.xml | 19 +++++- core/res/res/values/symbols.xml | 3 + .../res/layout/zen_mode_condition.xml | 34 +++++++--- .../android/systemui/volume/ZenModePanel.java | 62 +++++++++++++------ 5 files changed, 118 insertions(+), 37 deletions(-) diff --git a/core/java/android/service/notification/ZenModeConfig.java b/core/java/android/service/notification/ZenModeConfig.java index 882a3c83d7acb..9a84a1ee9009f 100644 --- a/core/java/android/service/notification/ZenModeConfig.java +++ b/core/java/android/service/notification/ZenModeConfig.java @@ -17,11 +17,13 @@ package android.service.notification; import android.content.ComponentName; +import android.content.Context; import android.content.res.Resources; import android.net.Uri; import android.os.Parcel; import android.os.Parcelable; import android.text.TextUtils; +import android.text.format.DateFormat; import android.util.Slog; import org.xmlpull.v1.XmlPullParser; @@ -32,8 +34,11 @@ import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.Calendar; +import java.util.Locale; import java.util.Objects; +import com.android.internal.R; + /** * Persisted configuration for zen mode. * @@ -461,20 +466,34 @@ public class ZenModeConfig implements Parcelable { return downtime; } - public static Condition toTimeCondition(int minutesFromNow) { + public static Condition toTimeCondition(Context context, int minutesFromNow) { final long now = System.currentTimeMillis(); final long millis = minutesFromNow == 0 ? ZERO_VALUE_MS : minutesFromNow * MINUTES_MS; - return toTimeCondition(now + millis, minutesFromNow); + return toTimeCondition(context, now + millis, minutesFromNow, now); } - public static Condition toTimeCondition(long time, int minutes) { - final int num = minutes < 60 ? minutes : Math.round(minutes / 60f); - final int resId = minutes < 60 - ? com.android.internal.R.plurals.zen_mode_duration_minutes - : com.android.internal.R.plurals.zen_mode_duration_hours; - final String caption = Resources.getSystem().getQuantityString(resId, num, num); + public static Condition toTimeCondition(Context context, long time, int minutes, long now) { + final int num, summaryResId, line1ResId; + if (minutes < 60) { + // display as minutes + num = minutes; + summaryResId = R.plurals.zen_mode_duration_minutes_summary; + line1ResId = R.plurals.zen_mode_duration_minutes; + } else { + // display as hours + num = Math.round(minutes / 60f); + summaryResId = com.android.internal.R.plurals.zen_mode_duration_hours_summary; + line1ResId = com.android.internal.R.plurals.zen_mode_duration_hours; + } + final String skeleton = DateFormat.is24HourFormat(context) ? "Hm" : "hma"; + final String pattern = DateFormat.getBestDateTimePattern(Locale.getDefault(), skeleton); + final CharSequence formattedTime = DateFormat.format(pattern, time); + final Resources res = context.getResources(); + final String summary = res.getQuantityString(summaryResId, num, num, formattedTime); + final String line1 = res.getQuantityString(line1ResId, num, num, formattedTime); + final String line2 = res.getString(R.string.zen_mode_until, formattedTime); final Uri id = toCountdownConditionId(time); - return new Condition(id, caption, "", "", 0, Condition.STATE_TRUE, + return new Condition(id, summary, line1, line2, 0, Condition.STATE_TRUE, Condition.FLAG_RELEVANT_NOW); } diff --git a/core/res/res/values/strings.xml b/core/res/res/values/strings.xml index c6437f35ef64b..89f6a9a11f057 100644 --- a/core/res/res/values/strings.xml +++ b/core/res/res/values/strings.xml @@ -4873,18 +4873,33 @@ Until your downtime ends at %1$s - + + + For one minute (until %1$s) + For %1$d minutes (until %2$s) + + + + + For one hour (until %1$s) + For %1$d hours (until %2$s) + + + For one minute For %d minutes - + For one hour For %d hours + + Until %1$s + Indefinitely diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml index a11fdbcbd68e3..d86413f88877d 100644 --- a/core/res/res/values/symbols.xml +++ b/core/res/res/values/symbols.xml @@ -1984,6 +1984,9 @@ + + + diff --git a/packages/SystemUI/res/layout/zen_mode_condition.xml b/packages/SystemUI/res/layout/zen_mode_condition.xml index ad0d2dc370140..a9ad1fc7a0bd0 100644 --- a/packages/SystemUI/res/layout/zen_mode_condition.xml +++ b/packages/SystemUI/res/layout/zen_mode_condition.xml @@ -29,16 +29,34 @@ android:layout_alignParentStart="true" android:gravity="center" /> - + android:layout_toStartOf="@android:id/button1"> + + + + + + MAX_BUCKET_MINUTES * MINUTES_MS) return null; - return ZenModeConfig.toTimeCondition(time, Math.round(span / (float) MINUTES_MS)); + return ZenModeConfig.toTimeCondition(mContext, + time, Math.round(span / (float) MINUTES_MS), now); } private void handleUpdateConditions(Condition[] conditions) { @@ -395,7 +399,7 @@ public class ZenModePanel extends LinearLayout { if (favoriteIndex == -1) { getConditionTagAt(FOREVER_CONDITION_INDEX).rb.setChecked(true); } else { - mTimeCondition = ZenModeConfig.toTimeCondition(MINUTE_BUCKETS[favoriteIndex]); + mTimeCondition = ZenModeConfig.toTimeCondition(mContext, MINUTE_BUCKETS[favoriteIndex]); mBucketIndex = favoriteIndex; bind(mTimeCondition, mZenConditions.getChildAt(TIME_CONDITION_INDEX)); getConditionTagAt(TIME_CONDITION_INDEX).rb.setChecked(true); @@ -451,16 +455,32 @@ public class ZenModePanel extends LinearLayout { } }); - if (tag.title == null) { - tag.title = (TextView) row.findViewById(android.R.id.title); + if (tag.lines == null) { + tag.lines = row.findViewById(android.R.id.content); } + if (tag.line1 == null) { + tag.line1 = (TextView) row.findViewById(android.R.id.text1); + } + if (tag.line2 == null) { + tag.line2 = (TextView) row.findViewById(android.R.id.text2); + } + final String line1, line2; if (condition == null) { - tag.title.setText(mContext.getString(com.android.internal.R.string.zen_mode_forever)); + line1 = mContext.getString(com.android.internal.R.string.zen_mode_forever); + line2 = null; } else { - tag.title.setText(condition.summary); + line1 = !TextUtils.isEmpty(condition.line1) ? condition.line1 : condition.summary; + line2 = condition.line2; } - tag.title.setEnabled(enabled); - tag.title.setAlpha(enabled ? 1 : .4f); + tag.line1.setText(line1); + if (TextUtils.isEmpty(line2)) { + tag.line2.setVisibility(GONE); + } else { + tag.line2.setVisibility(VISIBLE); + tag.line2.setText(line2); + } + tag.lines.setEnabled(enabled); + tag.lines.setAlpha(enabled ? 1 : .4f); final ImageView button1 = (ImageView) row.findViewById(android.R.id.button1); button1.setOnClickListener(new OnClickListener() { @@ -477,7 +497,7 @@ public class ZenModePanel extends LinearLayout { onClickTimeButton(row, tag, true /*up*/); } }); - tag.title.setOnClickListener(new OnClickListener() { + tag.lines.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { tag.rb.setChecked(true); @@ -492,7 +512,8 @@ public class ZenModePanel extends LinearLayout { } else { final long span = time - System.currentTimeMillis(); button1.setEnabled(span > MIN_BUCKET_MINUTES * MINUTES_MS); - final Condition maxCondition = ZenModeConfig.toTimeCondition(MAX_BUCKET_MINUTES); + final Condition maxCondition = ZenModeConfig.toTimeCondition(mContext, + MAX_BUCKET_MINUTES); button2.setEnabled(!Objects.equals(condition.summary, maxCondition.summary)); } @@ -505,7 +526,7 @@ public class ZenModePanel extends LinearLayout { // wire up interaction callbacks for newly-added condition rows if (convertView == null) { Interaction.register(tag.rb, mInteractionCallback); - Interaction.register(tag.title, mInteractionCallback); + Interaction.register(tag.lines, mInteractionCallback); Interaction.register(button1, mInteractionCallback); Interaction.register(button2, mInteractionCallback); } @@ -525,7 +546,7 @@ public class ZenModePanel extends LinearLayout { return; } announceForAccessibility(mContext.getString(R.string.zen_mode_and_condition, modeText, - tag.title.getText())); + tag.line1.getText())); } private void onClickTimeButton(View row, ConditionTag tag, boolean up) { @@ -542,18 +563,21 @@ public class ZenModePanel extends LinearLayout { final long bucketTime = now + bucketMinutes * MINUTES_MS; if (up && bucketTime > time || !up && bucketTime < time) { mBucketIndex = j; - newCondition = ZenModeConfig.toTimeCondition(bucketTime, bucketMinutes); + newCondition = ZenModeConfig.toTimeCondition(mContext, + bucketTime, bucketMinutes, now); break; } } if (newCondition == null) { mBucketIndex = DEFAULT_BUCKET_INDEX; - newCondition = ZenModeConfig.toTimeCondition(MINUTE_BUCKETS[mBucketIndex]); + newCondition = ZenModeConfig.toTimeCondition(mContext, + MINUTE_BUCKETS[mBucketIndex]); } } else { // on a known index, simply increment or decrement mBucketIndex = Math.max(0, Math.min(N - 1, mBucketIndex + (up ? 1 : -1))); - newCondition = ZenModeConfig.toTimeCondition(MINUTE_BUCKETS[mBucketIndex]); + newCondition = ZenModeConfig.toTimeCondition(mContext, + MINUTE_BUCKETS[mBucketIndex]); } mTimeCondition = newCondition; bind(mTimeCondition, row); @@ -640,7 +664,9 @@ public class ZenModePanel extends LinearLayout { // used as the view tag on condition rows private static class ConditionTag { RadioButton rb; - TextView title; + View lines; + TextView line1; + TextView line2; Condition condition; }