am ee990413: Merge "Zen: Show "(until 4:56 PM)" in exit conditions." into lmp-mr1-dev

automerge: 93e40ba

* commit '93e40ba6c4373402c7c4f430e3e575e4a0cc13eb':
  Zen: Show "(until 4:56 PM)" in exit conditions.
This commit is contained in:
John Spurlock
2014-10-28 18:08:11 +00:00
committed by android-build-merger
5 changed files with 118 additions and 37 deletions

View File

@@ -17,11 +17,13 @@
package android.service.notification; package android.service.notification;
import android.content.ComponentName; import android.content.ComponentName;
import android.content.Context;
import android.content.res.Resources; import android.content.res.Resources;
import android.net.Uri; import android.net.Uri;
import android.os.Parcel; import android.os.Parcel;
import android.os.Parcelable; import android.os.Parcelable;
import android.text.TextUtils; import android.text.TextUtils;
import android.text.format.DateFormat;
import android.util.Slog; import android.util.Slog;
import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParser;
@@ -32,8 +34,11 @@ import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Calendar; import java.util.Calendar;
import java.util.Locale;
import java.util.Objects; import java.util.Objects;
import com.android.internal.R;
/** /**
* Persisted configuration for zen mode. * Persisted configuration for zen mode.
* *
@@ -461,20 +466,34 @@ public class ZenModeConfig implements Parcelable {
return downtime; return downtime;
} }
public static Condition toTimeCondition(int minutesFromNow) { public static Condition toTimeCondition(Context context, int minutesFromNow) {
final long now = System.currentTimeMillis(); final long now = System.currentTimeMillis();
final long millis = minutesFromNow == 0 ? ZERO_VALUE_MS : minutesFromNow * MINUTES_MS; 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) { public static Condition toTimeCondition(Context context, long time, int minutes, long now) {
final int num = minutes < 60 ? minutes : Math.round(minutes / 60f); final int num, summaryResId, line1ResId;
final int resId = minutes < 60 if (minutes < 60) {
? com.android.internal.R.plurals.zen_mode_duration_minutes // display as minutes
: com.android.internal.R.plurals.zen_mode_duration_hours; num = minutes;
final String caption = Resources.getSystem().getQuantityString(resId, num, num); 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); 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); Condition.FLAG_RELEVANT_NOW);
} }

View File

@@ -4865,18 +4865,33 @@
<!-- [CHAR_LIMIT=NONE] Zen mode: Condition summary for built-in downtime condition, if active --> <!-- [CHAR_LIMIT=NONE] Zen mode: Condition summary for built-in downtime condition, if active -->
<string name="downtime_condition_summary">Until your downtime ends at <xliff:g id="formattedTime" example="10.00 PM">%1$s</xliff:g></string> <string name="downtime_condition_summary">Until your downtime ends at <xliff:g id="formattedTime" example="10.00 PM">%1$s</xliff:g></string>
<!-- Zen mode condition: time duration in minutes. [CHAR LIMIT=NONE] --> <!-- Zen mode condition - summary: time duration in minutes. [CHAR LIMIT=NONE] -->
<plurals name="zen_mode_duration_minutes_summary">
<item quantity="one">For one minute (until <xliff:g id="formattedTime" example="10:00 PM">%1$s</xliff:g>)</item>
<item quantity="other">For %1$d minutes (until <xliff:g id="formattedTime" example="10:00 PM">%2$s</xliff:g>)</item>
</plurals>
<!-- Zen mode condition - summary: time duration in hours. [CHAR LIMIT=NONE] -->
<plurals name="zen_mode_duration_hours_summary">
<item quantity="one">For one hour (until <xliff:g id="formattedTime" example="10:00 PM">%1$s</xliff:g>)</item>
<item quantity="other">For %1$d hours (until <xliff:g id="formattedTime" example="10:00 PM">%2$s</xliff:g>)</item>
</plurals>
<!-- Zen mode condition - line one: time duration in minutes. [CHAR LIMIT=NONE] -->
<plurals name="zen_mode_duration_minutes"> <plurals name="zen_mode_duration_minutes">
<item quantity="one">For one minute</item> <item quantity="one">For one minute</item>
<item quantity="other">For %d minutes</item> <item quantity="other">For %d minutes</item>
</plurals> </plurals>
<!-- Zen mode condition: time duration in hours. [CHAR LIMIT=NONE] --> <!-- Zen mode condition - line one: time duration in hours. [CHAR LIMIT=NONE] -->
<plurals name="zen_mode_duration_hours"> <plurals name="zen_mode_duration_hours">
<item quantity="one">For one hour</item> <item quantity="one">For one hour</item>
<item quantity="other">For %d hours</item> <item quantity="other">For %d hours</item>
</plurals> </plurals>
<!-- Zen mode condition - line two: ending time. [CHAR LIMIT=NONE] -->
<string name="zen_mode_until">Until <xliff:g id="formattedTime" example="10:00 PM">%1$s</xliff:g></string>
<!-- Zen mode condition: no exit criteria. [CHAR LIMIT=NONE] --> <!-- Zen mode condition: no exit criteria. [CHAR LIMIT=NONE] -->
<string name="zen_mode_forever">Indefinitely</string> <string name="zen_mode_forever">Indefinitely</string>
</resources> </resources>

View File

@@ -1984,6 +1984,9 @@
<java-symbol type="string" name="zen_mode_forever" /> <java-symbol type="string" name="zen_mode_forever" />
<java-symbol type="plurals" name="zen_mode_duration_minutes" /> <java-symbol type="plurals" name="zen_mode_duration_minutes" />
<java-symbol type="plurals" name="zen_mode_duration_hours" /> <java-symbol type="plurals" name="zen_mode_duration_hours" />
<java-symbol type="plurals" name="zen_mode_duration_minutes_summary" />
<java-symbol type="plurals" name="zen_mode_duration_hours_summary" />
<java-symbol type="string" name="zen_mode_until" />
<java-symbol type="string" name="item_is_selected" /> <java-symbol type="string" name="item_is_selected" />
<java-symbol type="string" name="day_of_week_label_typeface" /> <java-symbol type="string" name="day_of_week_label_typeface" />

View File

@@ -29,17 +29,35 @@
android:layout_alignParentStart="true" android:layout_alignParentStart="true"
android:gravity="center" /> android:gravity="center" />
<TextView <LinearLayout
android:id="@android:id/title" android:id="@android:id/content"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:orientation="vertical"
android:layout_toEndOf="@android:id/checkbox" android:layout_toEndOf="@android:id/checkbox"
android:layout_toStartOf="@android:id/button1" android:layout_toStartOf="@android:id/button1">
<TextView
android:id="@android:id/text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="end" android:ellipsize="end"
android:gravity="center_vertical" android:textAlignment="viewStart"
android:maxLines="1" android:maxLines="1"
android:textAppearance="@style/TextAppearance.QS.DetailItemPrimary" /> android:textAppearance="@style/TextAppearance.QS.DetailItemPrimary" />
<TextView
android:id="@android:id/text2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:textAlignment="viewStart"
android:maxLines="1"
android:textAppearance="@style/TextAppearance.QS.DetailItemSecondary" />
</LinearLayout>
<ImageView <ImageView
android:id="@android:id/button1" android:id="@android:id/button1"
style="@style/QSBorderlessButton" style="@style/QSBorderlessButton"

View File

@@ -31,6 +31,7 @@ import android.provider.Settings;
import android.provider.Settings.Global; import android.provider.Settings.Global;
import android.service.notification.Condition; import android.service.notification.Condition;
import android.service.notification.ZenModeConfig; import android.service.notification.ZenModeConfig;
import android.text.TextUtils;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.util.Log; import android.util.Log;
import android.util.MathUtils; import android.util.MathUtils;
@@ -220,7 +221,8 @@ public class ZenModePanel extends LinearLayout {
mBucketIndex = -1; mBucketIndex = -1;
} else { } else {
mBucketIndex = DEFAULT_BUCKET_INDEX; mBucketIndex = DEFAULT_BUCKET_INDEX;
mTimeCondition = ZenModeConfig.toTimeCondition(MINUTE_BUCKETS[mBucketIndex]); mTimeCondition = ZenModeConfig.toTimeCondition(mContext,
MINUTE_BUCKETS[mBucketIndex]);
} }
if (DEBUG) Log.d(mTag, "Initial bucket index: " + mBucketIndex); if (DEBUG) Log.d(mTag, "Initial bucket index: " + mBucketIndex);
mConditions = null; // reset conditions mConditions = null; // reset conditions
@@ -339,9 +341,11 @@ public class ZenModePanel extends LinearLayout {
if (condition == null) return null; if (condition == null) return null;
final long time = ZenModeConfig.tryParseCountdownConditionId(condition.id); final long time = ZenModeConfig.tryParseCountdownConditionId(condition.id);
if (time == 0) return null; if (time == 0) return null;
final long span = time - System.currentTimeMillis(); final long now = System.currentTimeMillis();
final long span = time - now;
if (span <= 0 || span > MAX_BUCKET_MINUTES * MINUTES_MS) return null; if (span <= 0 || span > 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) { private void handleUpdateConditions(Condition[] conditions) {
@@ -395,7 +399,7 @@ public class ZenModePanel extends LinearLayout {
if (favoriteIndex == -1) { if (favoriteIndex == -1) {
getConditionTagAt(FOREVER_CONDITION_INDEX).rb.setChecked(true); getConditionTagAt(FOREVER_CONDITION_INDEX).rb.setChecked(true);
} else { } else {
mTimeCondition = ZenModeConfig.toTimeCondition(MINUTE_BUCKETS[favoriteIndex]); mTimeCondition = ZenModeConfig.toTimeCondition(mContext, MINUTE_BUCKETS[favoriteIndex]);
mBucketIndex = favoriteIndex; mBucketIndex = favoriteIndex;
bind(mTimeCondition, mZenConditions.getChildAt(TIME_CONDITION_INDEX)); bind(mTimeCondition, mZenConditions.getChildAt(TIME_CONDITION_INDEX));
getConditionTagAt(TIME_CONDITION_INDEX).rb.setChecked(true); getConditionTagAt(TIME_CONDITION_INDEX).rb.setChecked(true);
@@ -451,16 +455,32 @@ public class ZenModePanel extends LinearLayout {
} }
}); });
if (tag.title == null) { if (tag.lines == null) {
tag.title = (TextView) row.findViewById(android.R.id.title); 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) { 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 { } else {
tag.title.setText(condition.summary); line1 = !TextUtils.isEmpty(condition.line1) ? condition.line1 : condition.summary;
line2 = condition.line2;
} }
tag.title.setEnabled(enabled); tag.line1.setText(line1);
tag.title.setAlpha(enabled ? 1 : .4f); 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); final ImageView button1 = (ImageView) row.findViewById(android.R.id.button1);
button1.setOnClickListener(new OnClickListener() { button1.setOnClickListener(new OnClickListener() {
@@ -477,7 +497,7 @@ public class ZenModePanel extends LinearLayout {
onClickTimeButton(row, tag, true /*up*/); onClickTimeButton(row, tag, true /*up*/);
} }
}); });
tag.title.setOnClickListener(new OnClickListener() { tag.lines.setOnClickListener(new OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
tag.rb.setChecked(true); tag.rb.setChecked(true);
@@ -492,7 +512,8 @@ public class ZenModePanel extends LinearLayout {
} else { } else {
final long span = time - System.currentTimeMillis(); final long span = time - System.currentTimeMillis();
button1.setEnabled(span > MIN_BUCKET_MINUTES * MINUTES_MS); 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)); 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 // wire up interaction callbacks for newly-added condition rows
if (convertView == null) { if (convertView == null) {
Interaction.register(tag.rb, mInteractionCallback); Interaction.register(tag.rb, mInteractionCallback);
Interaction.register(tag.title, mInteractionCallback); Interaction.register(tag.lines, mInteractionCallback);
Interaction.register(button1, mInteractionCallback); Interaction.register(button1, mInteractionCallback);
Interaction.register(button2, mInteractionCallback); Interaction.register(button2, mInteractionCallback);
} }
@@ -525,7 +546,7 @@ public class ZenModePanel extends LinearLayout {
return; return;
} }
announceForAccessibility(mContext.getString(R.string.zen_mode_and_condition, modeText, 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) { 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; final long bucketTime = now + bucketMinutes * MINUTES_MS;
if (up && bucketTime > time || !up && bucketTime < time) { if (up && bucketTime > time || !up && bucketTime < time) {
mBucketIndex = j; mBucketIndex = j;
newCondition = ZenModeConfig.toTimeCondition(bucketTime, bucketMinutes); newCondition = ZenModeConfig.toTimeCondition(mContext,
bucketTime, bucketMinutes, now);
break; break;
} }
} }
if (newCondition == null) { if (newCondition == null) {
mBucketIndex = DEFAULT_BUCKET_INDEX; mBucketIndex = DEFAULT_BUCKET_INDEX;
newCondition = ZenModeConfig.toTimeCondition(MINUTE_BUCKETS[mBucketIndex]); newCondition = ZenModeConfig.toTimeCondition(mContext,
MINUTE_BUCKETS[mBucketIndex]);
} }
} else { } else {
// on a known index, simply increment or decrement // on a known index, simply increment or decrement
mBucketIndex = Math.max(0, Math.min(N - 1, mBucketIndex + (up ? 1 : -1))); 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; mTimeCondition = newCondition;
bind(mTimeCondition, row); bind(mTimeCondition, row);
@@ -640,7 +664,9 @@ public class ZenModePanel extends LinearLayout {
// used as the view tag on condition rows // used as the view tag on condition rows
private static class ConditionTag { private static class ConditionTag {
RadioButton rb; RadioButton rb;
TextView title; View lines;
TextView line1;
TextView line2;
Condition condition; Condition condition;
} }