Merge "Add 'until next alarm' option to QS zen panel." into mnc-dr-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
a762c210d2
@@ -41,6 +41,7 @@ import org.xmlpull.v1.XmlSerializer;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
|
import java.util.GregorianCalendar;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
@@ -68,6 +69,7 @@ public class ZenModeConfig implements Parcelable {
|
|||||||
public static final int[] MINUTE_BUCKETS = generateMinuteBuckets();
|
public static final int[] MINUTE_BUCKETS = generateMinuteBuckets();
|
||||||
private static final int SECONDS_MS = 1000;
|
private static final int SECONDS_MS = 1000;
|
||||||
private static final int MINUTES_MS = 60 * SECONDS_MS;
|
private static final int MINUTES_MS = 60 * SECONDS_MS;
|
||||||
|
private static final int DAY_MINUTES = 24 * 60;
|
||||||
private static final int ZERO_VALUE_MS = 10 * SECONDS_MS;
|
private static final int ZERO_VALUE_MS = 10 * SECONDS_MS;
|
||||||
|
|
||||||
private static final boolean DEFAULT_ALLOW_CALLS = true;
|
private static final boolean DEFAULT_ALLOW_CALLS = true;
|
||||||
@@ -652,40 +654,68 @@ public class ZenModeConfig implements Parcelable {
|
|||||||
boolean shortVersion) {
|
boolean shortVersion) {
|
||||||
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(context, now + millis, minutesFromNow, now, userHandle,
|
return toTimeCondition(context, now + millis, minutesFromNow, userHandle, shortVersion);
|
||||||
shortVersion);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Condition toTimeCondition(Context context, long time, int minutes, long now,
|
public static Condition toTimeCondition(Context context, long time, int minutes,
|
||||||
int userHandle, boolean shortVersion) {
|
int userHandle, boolean shortVersion) {
|
||||||
final int num, summaryResId, line1ResId;
|
final int num;
|
||||||
|
String summary, line1, line2;
|
||||||
|
final CharSequence formattedTime = getFormattedTime(context, time, userHandle);
|
||||||
|
final Resources res = context.getResources();
|
||||||
if (minutes < 60) {
|
if (minutes < 60) {
|
||||||
// display as minutes
|
// display as minutes
|
||||||
num = minutes;
|
num = minutes;
|
||||||
summaryResId = shortVersion ? R.plurals.zen_mode_duration_minutes_summary_short
|
int summaryResId = shortVersion ? R.plurals.zen_mode_duration_minutes_summary_short
|
||||||
: R.plurals.zen_mode_duration_minutes_summary;
|
: R.plurals.zen_mode_duration_minutes_summary;
|
||||||
line1ResId = shortVersion ? R.plurals.zen_mode_duration_minutes_short
|
summary = res.getQuantityString(summaryResId, num, num, formattedTime);
|
||||||
|
int line1ResId = shortVersion ? R.plurals.zen_mode_duration_minutes_short
|
||||||
: R.plurals.zen_mode_duration_minutes;
|
: R.plurals.zen_mode_duration_minutes;
|
||||||
} else {
|
line1 = res.getQuantityString(line1ResId, num, num, formattedTime);
|
||||||
|
line2 = res.getString(R.string.zen_mode_until, formattedTime);
|
||||||
|
} else if (minutes < DAY_MINUTES) {
|
||||||
// display as hours
|
// display as hours
|
||||||
num = Math.round(minutes / 60f);
|
num = Math.round(minutes / 60f);
|
||||||
summaryResId = shortVersion ? R.plurals.zen_mode_duration_hours_summary_short
|
int summaryResId = shortVersion ? R.plurals.zen_mode_duration_hours_summary_short
|
||||||
: R.plurals.zen_mode_duration_hours_summary;
|
: R.plurals.zen_mode_duration_hours_summary;
|
||||||
line1ResId = shortVersion ? R.plurals.zen_mode_duration_hours_short
|
summary = res.getQuantityString(summaryResId, num, num, formattedTime);
|
||||||
|
int line1ResId = shortVersion ? R.plurals.zen_mode_duration_hours_short
|
||||||
: R.plurals.zen_mode_duration_hours;
|
: R.plurals.zen_mode_duration_hours;
|
||||||
|
line1 = res.getQuantityString(line1ResId, num, num, formattedTime);
|
||||||
|
line2 = res.getString(R.string.zen_mode_until, formattedTime);
|
||||||
|
} else {
|
||||||
|
// display as day/time
|
||||||
|
summary = line1 = line2 = res.getString(R.string.zen_mode_until, formattedTime);
|
||||||
}
|
}
|
||||||
final String skeleton = DateFormat.is24HourFormat(context, userHandle) ? "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, summary, line1, line2, 0, Condition.STATE_TRUE,
|
return new Condition(id, summary, line1, line2, 0, Condition.STATE_TRUE,
|
||||||
Condition.FLAG_RELEVANT_NOW);
|
Condition.FLAG_RELEVANT_NOW);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Condition toNextAlarmCondition(Context context, long now, long alarm,
|
||||||
|
int userHandle) {
|
||||||
|
final CharSequence formattedTime = getFormattedTime(context, alarm, userHandle);
|
||||||
|
final Resources res = context.getResources();
|
||||||
|
final String line1 = res.getString(R.string.zen_mode_alarm, formattedTime);
|
||||||
|
final Uri id = toCountdownConditionId(alarm);
|
||||||
|
return new Condition(id, "", line1, "", 0, Condition.STATE_TRUE,
|
||||||
|
Condition.FLAG_RELEVANT_NOW);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static CharSequence getFormattedTime(Context context, long time, int userHandle) {
|
||||||
|
String skeleton = "EEE " + (DateFormat.is24HourFormat(context, userHandle) ? "Hm" : "hma");
|
||||||
|
GregorianCalendar now = new GregorianCalendar();
|
||||||
|
GregorianCalendar endTime = new GregorianCalendar();
|
||||||
|
endTime.setTimeInMillis(time);
|
||||||
|
if (now.get(Calendar.YEAR) == endTime.get(Calendar.YEAR)
|
||||||
|
&& now.get(Calendar.MONTH) == endTime.get(Calendar.MONTH)
|
||||||
|
&& now.get(Calendar.DATE) == endTime.get(Calendar.DATE)) {
|
||||||
|
skeleton = DateFormat.is24HourFormat(context, userHandle) ? "Hm" : "hma";
|
||||||
|
}
|
||||||
|
final String pattern = DateFormat.getBestDateTimePattern(Locale.getDefault(), skeleton);
|
||||||
|
return DateFormat.format(pattern, time);
|
||||||
|
}
|
||||||
|
|
||||||
// ==== Built-in system conditions ====
|
// ==== Built-in system conditions ====
|
||||||
|
|
||||||
public static final String SYSTEM_AUTHORITY = "android";
|
public static final String SYSTEM_AUTHORITY = "android";
|
||||||
@@ -883,11 +913,6 @@ public class ZenModeConfig implements Parcelable {
|
|||||||
return UUID.randomUUID().toString().replace("-", "");
|
return UUID.randomUUID().toString().replace("-", "");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getConditionLine1(Context context, ZenModeConfig config,
|
|
||||||
int userHandle, boolean shortVersion) {
|
|
||||||
return getConditionLine(context, config, userHandle, true /*useLine1*/, shortVersion);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getConditionSummary(Context context, ZenModeConfig config,
|
public static String getConditionSummary(Context context, ZenModeConfig config,
|
||||||
int userHandle, boolean shortVersion) {
|
int userHandle, boolean shortVersion) {
|
||||||
return getConditionLine(context, config, userHandle, false /*useLine1*/, shortVersion);
|
return getConditionLine(context, config, userHandle, false /*useLine1*/, shortVersion);
|
||||||
@@ -906,8 +931,8 @@ public class ZenModeConfig implements Parcelable {
|
|||||||
if (time > 0) {
|
if (time > 0) {
|
||||||
final long now = System.currentTimeMillis();
|
final long now = System.currentTimeMillis();
|
||||||
final long span = time - now;
|
final long span = time - now;
|
||||||
c = toTimeCondition(context,
|
c = toTimeCondition(context, time, Math.round(span / (float) MINUTES_MS),
|
||||||
time, Math.round(span / (float) MINUTES_MS), now, userHandle, shortVersion);
|
userHandle, shortVersion);
|
||||||
}
|
}
|
||||||
final String rt = c == null ? "" : useLine1 ? c.line1 : c.summary;
|
final String rt = c == null ? "" : useLine1 ? c.line1 : c.summary;
|
||||||
return TextUtils.isEmpty(rt) ? "" : rt;
|
return TextUtils.isEmpty(rt) ? "" : rt;
|
||||||
|
|||||||
@@ -4036,6 +4036,9 @@
|
|||||||
<!-- Zen mode condition - line two: ending time. [CHAR LIMIT=NONE] -->
|
<!-- 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>
|
<string name="zen_mode_until">Until <xliff:g id="formattedTime" example="10:00 PM">%1$s</xliff:g></string>
|
||||||
|
|
||||||
|
<!-- Zen mode condition - line one: Until next alarm. [CHAR LIMIT=NONE] -->
|
||||||
|
<string name="zen_mode_alarm">Until <xliff:g id="formattedTime" example="10:00 PM">%1$s</xliff:g> (next alarm)</string>
|
||||||
|
|
||||||
<!-- Zen mode condition: no exit criteria. [CHAR LIMIT=NONE] -->
|
<!-- Zen mode condition: no exit criteria. [CHAR LIMIT=NONE] -->
|
||||||
<string name="zen_mode_forever">Until you turn this off</string>
|
<string name="zen_mode_forever">Until you turn this off</string>
|
||||||
|
|
||||||
|
|||||||
@@ -2083,6 +2083,7 @@
|
|||||||
<java-symbol type="string" name="zen_mode_default_events_name" />
|
<java-symbol type="string" name="zen_mode_default_events_name" />
|
||||||
<java-symbol type="array" name="config_system_condition_providers" />
|
<java-symbol type="array" name="config_system_condition_providers" />
|
||||||
<java-symbol type="string" name="muted_by" />
|
<java-symbol type="string" name="muted_by" />
|
||||||
|
<java-symbol type="string" name="zen_mode_alarm" />
|
||||||
|
|
||||||
<java-symbol type="string" name="select_day" />
|
<java-symbol type="string" name="select_day" />
|
||||||
<java-symbol type="string" name="select_year" />
|
<java-symbol type="string" name="select_year" />
|
||||||
|
|||||||
@@ -27,7 +27,6 @@ public interface ZenModeController {
|
|||||||
void removeCallback(Callback callback);
|
void removeCallback(Callback callback);
|
||||||
void setZen(int zen, Uri conditionId, String reason);
|
void setZen(int zen, Uri conditionId, String reason);
|
||||||
int getZen();
|
int getZen();
|
||||||
void requestConditions(boolean request);
|
|
||||||
ZenRule getManualRule();
|
ZenRule getManualRule();
|
||||||
ZenModeConfig getConfig();
|
ZenModeConfig getConfig();
|
||||||
long getNextAlarm();
|
long getNextAlarm();
|
||||||
|
|||||||
@@ -120,15 +120,6 @@ public class ZenModeControllerImpl implements ZenModeController {
|
|||||||
return mSetupObserver.isDeviceProvisioned() && mSetupObserver.isUserSetup();
|
return mSetupObserver.isDeviceProvisioned() && mSetupObserver.isUserSetup();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void requestConditions(boolean request) {
|
|
||||||
mRequesting = request;
|
|
||||||
mNoMan.requestZenModeConditions(mListener, request ? Condition.FLAG_RELEVANT_NOW : 0);
|
|
||||||
if (!mRequesting) {
|
|
||||||
mConditions.clear();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ZenRule getManualRule() {
|
public ZenRule getManualRule() {
|
||||||
return mConfig == null ? null : mConfig.manualRule;
|
return mConfig == null ? null : mConfig.manualRule;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/*
|
/**
|
||||||
* Copyright (C) 2014 The Android Open Source Project
|
* Copyright (C) 2014 The Android Open Source Project
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
@@ -58,6 +58,8 @@ import com.android.systemui.statusbar.policy.ZenModeController;
|
|||||||
import java.io.FileDescriptor;
|
import java.io.FileDescriptor;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Calendar;
|
||||||
|
import java.util.GregorianCalendar;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
@@ -76,6 +78,8 @@ public class ZenModePanel extends LinearLayout {
|
|||||||
private static final int DEFAULT_BUCKET_INDEX = Arrays.binarySearch(MINUTE_BUCKETS, 60);
|
private static final int DEFAULT_BUCKET_INDEX = Arrays.binarySearch(MINUTE_BUCKETS, 60);
|
||||||
private static final int FOREVER_CONDITION_INDEX = 0;
|
private static final int FOREVER_CONDITION_INDEX = 0;
|
||||||
private static final int COUNTDOWN_CONDITION_INDEX = 1;
|
private static final int COUNTDOWN_CONDITION_INDEX = 1;
|
||||||
|
private static final int COUNTDOWN_ALARM_CONDITION_INDEX = 2;
|
||||||
|
private static final int COUNTDOWN_CONDITION_COUNT = 2;
|
||||||
|
|
||||||
public static final Intent ZEN_SETTINGS
|
public static final Intent ZEN_SETTINGS
|
||||||
= new Intent(Settings.ACTION_ZEN_MODE_SETTINGS);
|
= new Intent(Settings.ACTION_ZEN_MODE_SETTINGS);
|
||||||
@@ -86,7 +90,6 @@ public class ZenModePanel extends LinearLayout {
|
|||||||
private final LayoutInflater mInflater;
|
private final LayoutInflater mInflater;
|
||||||
private final H mHandler = new H();
|
private final H mHandler = new H();
|
||||||
private final ZenPrefs mPrefs;
|
private final ZenPrefs mPrefs;
|
||||||
private final IconPulser mIconPulser;
|
|
||||||
private final TransitionHelper mTransitionHelper = new TransitionHelper();
|
private final TransitionHelper mTransitionHelper = new TransitionHelper();
|
||||||
private final Uri mForeverId;
|
private final Uri mForeverId;
|
||||||
private final SpTexts mSpTexts;
|
private final SpTexts mSpTexts;
|
||||||
@@ -104,9 +107,6 @@ public class ZenModePanel extends LinearLayout {
|
|||||||
private Callback mCallback;
|
private Callback mCallback;
|
||||||
private ZenModeController mController;
|
private ZenModeController mController;
|
||||||
private boolean mCountdownConditionSupported;
|
private boolean mCountdownConditionSupported;
|
||||||
private int mMaxConditions;
|
|
||||||
private int mMaxOptionalConditions;
|
|
||||||
private int mFirstConditionIndex;
|
|
||||||
private boolean mRequestingConditions;
|
private boolean mRequestingConditions;
|
||||||
private Condition mExitCondition;
|
private Condition mExitCondition;
|
||||||
private int mBucketIndex = -1;
|
private int mBucketIndex = -1;
|
||||||
@@ -125,7 +125,6 @@ public class ZenModePanel extends LinearLayout {
|
|||||||
mContext = context;
|
mContext = context;
|
||||||
mPrefs = new ZenPrefs();
|
mPrefs = new ZenPrefs();
|
||||||
mInflater = LayoutInflater.from(mContext.getApplicationContext());
|
mInflater = LayoutInflater.from(mContext.getApplicationContext());
|
||||||
mIconPulser = new IconPulser(mContext);
|
|
||||||
mForeverId = Condition.newId(mContext).appendPath("forever").build();
|
mForeverId = Condition.newId(mContext).appendPath("forever").build();
|
||||||
mSpTexts = new SpTexts(mContext);
|
mSpTexts = new SpTexts(mContext);
|
||||||
mVoiceCapable = Util.isVoiceCapable(mContext);
|
mVoiceCapable = Util.isVoiceCapable(mContext);
|
||||||
@@ -135,7 +134,6 @@ public class ZenModePanel extends LinearLayout {
|
|||||||
public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
|
public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
|
||||||
pw.println("ZenModePanel state:");
|
pw.println("ZenModePanel state:");
|
||||||
pw.print(" mCountdownConditionSupported="); pw.println(mCountdownConditionSupported);
|
pw.print(" mCountdownConditionSupported="); pw.println(mCountdownConditionSupported);
|
||||||
pw.print(" mMaxConditions="); pw.println(mMaxConditions);
|
|
||||||
pw.print(" mRequestingConditions="); pw.println(mRequestingConditions);
|
pw.print(" mRequestingConditions="); pw.println(mRequestingConditions);
|
||||||
pw.print(" mAttached="); pw.println(mAttached);
|
pw.print(" mAttached="); pw.println(mAttached);
|
||||||
pw.print(" mHidden="); pw.println(mHidden);
|
pw.print(" mHidden="); pw.println(mHidden);
|
||||||
@@ -286,14 +284,6 @@ public class ZenModePanel extends LinearLayout {
|
|||||||
if (mRequestingConditions == requesting) return;
|
if (mRequestingConditions == requesting) return;
|
||||||
if (DEBUG) Log.d(mTag, "setRequestingConditions " + requesting);
|
if (DEBUG) Log.d(mTag, "setRequestingConditions " + requesting);
|
||||||
mRequestingConditions = requesting;
|
mRequestingConditions = requesting;
|
||||||
if (mController != null) {
|
|
||||||
AsyncTask.execute(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
mController.requestConditions(requesting);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
if (mRequestingConditions) {
|
if (mRequestingConditions) {
|
||||||
mTimeCondition = parseExistingTimeCondition(mContext, mExitCondition);
|
mTimeCondition = parseExistingTimeCondition(mContext, mExitCondition);
|
||||||
if (mTimeCondition != null) {
|
if (mTimeCondition != null) {
|
||||||
@@ -304,6 +294,7 @@ public class ZenModePanel extends LinearLayout {
|
|||||||
MINUTE_BUCKETS[mBucketIndex], ActivityManager.getCurrentUser());
|
MINUTE_BUCKETS[mBucketIndex], ActivityManager.getCurrentUser());
|
||||||
}
|
}
|
||||||
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
|
||||||
handleUpdateConditions();
|
handleUpdateConditions();
|
||||||
} else {
|
} else {
|
||||||
@@ -314,13 +305,9 @@ public class ZenModePanel extends LinearLayout {
|
|||||||
public void init(ZenModeController controller) {
|
public void init(ZenModeController controller) {
|
||||||
mController = controller;
|
mController = controller;
|
||||||
mCountdownConditionSupported = mController.isCountdownConditionSupported();
|
mCountdownConditionSupported = mController.isCountdownConditionSupported();
|
||||||
final int countdownDelta = mCountdownConditionSupported ? 1 : 0;
|
final int countdownDelta = mCountdownConditionSupported ? COUNTDOWN_CONDITION_COUNT : 0;
|
||||||
mFirstConditionIndex = COUNTDOWN_CONDITION_INDEX + countdownDelta;
|
|
||||||
final int minConditions = 1 /*forever*/ + countdownDelta;
|
final int minConditions = 1 /*forever*/ + countdownDelta;
|
||||||
mMaxConditions = MathUtils.constrain(mContext.getResources()
|
for (int i = 0; i < minConditions; i++) {
|
||||||
.getInteger(R.integer.zen_mode_max_conditions), minConditions, 100);
|
|
||||||
mMaxOptionalConditions = mMaxConditions - minConditions;
|
|
||||||
for (int i = 0; i < mMaxConditions; i++) {
|
|
||||||
mZenConditions.addView(mInflater.inflate(R.layout.zen_mode_condition, this, false));
|
mZenConditions.addView(mInflater.inflate(R.layout.zen_mode_condition, this, false));
|
||||||
}
|
}
|
||||||
mSessionZen = getSelectedZen(-1);
|
mSessionZen = getSelectedZen(-1);
|
||||||
@@ -357,28 +344,10 @@ public class ZenModePanel extends LinearLayout {
|
|||||||
return condition == null ? null : condition.copy();
|
return condition == null ? null : condition.copy();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getExitConditionText(Context context, Condition exitCondition) {
|
|
||||||
if (exitCondition == null) {
|
|
||||||
return foreverSummary(context);
|
|
||||||
} else if (isCountdown(exitCondition)) {
|
|
||||||
final Condition condition = parseExistingTimeCondition(context, exitCondition);
|
|
||||||
return condition != null ? condition.summary : foreverSummary(context);
|
|
||||||
} else {
|
|
||||||
return exitCondition.summary;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCallback(Callback callback) {
|
public void setCallback(Callback callback) {
|
||||||
mCallback = callback;
|
mCallback = callback;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showSilentHint() {
|
|
||||||
if (DEBUG) Log.d(mTag, "showSilentHint");
|
|
||||||
if (mZenButtons == null || mZenButtons.getChildCount() == 0) return;
|
|
||||||
final View noneButton = mZenButtons.getChildAt(0);
|
|
||||||
mIconPulser.start(noneButton);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void handleUpdateManualRule(ZenRule rule) {
|
private void handleUpdateManualRule(ZenRule rule) {
|
||||||
final int zen = rule != null ? rule.zenMode : Global.ZEN_MODE_OFF;
|
final int zen = rule != null ? rule.zenMode : Global.ZEN_MODE_OFF;
|
||||||
handleUpdateZen(zen);
|
handleUpdateZen(zen);
|
||||||
@@ -410,7 +379,7 @@ public class ZenModePanel extends LinearLayout {
|
|||||||
final ConditionTag tag = getConditionTagAt(i);
|
final ConditionTag tag = getConditionTagAt(i);
|
||||||
if (tag != null) {
|
if (tag != null) {
|
||||||
if (sameConditionId(tag.condition, mExitCondition)) {
|
if (sameConditionId(tag.condition, mExitCondition)) {
|
||||||
bind(exitCondition, mZenConditions.getChildAt(i));
|
bind(exitCondition, mZenConditions.getChildAt(i), i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -495,64 +464,32 @@ public class ZenModePanel extends LinearLayout {
|
|||||||
final long span = time - now;
|
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(context,
|
return ZenModeConfig.toTimeCondition(context,
|
||||||
time, Math.round(span / (float) MINUTES_MS), now, ActivityManager.getCurrentUser(),
|
time, Math.round(span / (float) MINUTES_MS), ActivityManager.getCurrentUser(),
|
||||||
false /*shortVersion*/);
|
false /*shortVersion*/);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleUpdateConditions(Condition[] conditions) {
|
|
||||||
conditions = trimConditions(conditions);
|
|
||||||
if (Arrays.equals(conditions, mConditions)) {
|
|
||||||
final int count = mConditions == null ? 0 : mConditions.length;
|
|
||||||
if (DEBUG) Log.d(mTag, "handleUpdateConditions unchanged conditionCount=" + count);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
mConditions = conditions;
|
|
||||||
handleUpdateConditions();
|
|
||||||
}
|
|
||||||
|
|
||||||
private Condition[] trimConditions(Condition[] conditions) {
|
|
||||||
if (conditions == null || conditions.length <= mMaxOptionalConditions) {
|
|
||||||
// no need to trim
|
|
||||||
return conditions;
|
|
||||||
}
|
|
||||||
// look for current exit condition, ensure it is included if found
|
|
||||||
int found = -1;
|
|
||||||
for (int i = 0; i < conditions.length; i++) {
|
|
||||||
final Condition c = conditions[i];
|
|
||||||
if (mSessionExitCondition != null && sameConditionId(mSessionExitCondition, c)) {
|
|
||||||
found = i;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
final Condition[] rt = Arrays.copyOf(conditions, mMaxOptionalConditions);
|
|
||||||
if (found >= mMaxOptionalConditions) {
|
|
||||||
// found after the first N, promote to the end of the first N
|
|
||||||
rt[mMaxOptionalConditions - 1] = conditions[found];
|
|
||||||
}
|
|
||||||
return rt;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void handleUpdateConditions() {
|
private void handleUpdateConditions() {
|
||||||
if (mTransitionHelper.isTransitioning()) {
|
if (mTransitionHelper.isTransitioning()) {
|
||||||
mTransitionHelper.pendingUpdateConditions();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final int conditionCount = mConditions == null ? 0 : mConditions.length;
|
final int conditionCount = mConditions == null ? 0 : mConditions.length;
|
||||||
if (DEBUG) Log.d(mTag, "handleUpdateConditions conditionCount=" + conditionCount);
|
if (DEBUG) Log.d(mTag, "handleUpdateConditions conditionCount=" + conditionCount);
|
||||||
// forever
|
// forever
|
||||||
bind(forever(), mZenConditions.getChildAt(FOREVER_CONDITION_INDEX));
|
bind(forever(), mZenConditions.getChildAt(FOREVER_CONDITION_INDEX),
|
||||||
|
FOREVER_CONDITION_INDEX);
|
||||||
// countdown
|
// countdown
|
||||||
if (mCountdownConditionSupported && mTimeCondition != null) {
|
if (mCountdownConditionSupported && mTimeCondition != null) {
|
||||||
bind(mTimeCondition, mZenConditions.getChildAt(COUNTDOWN_CONDITION_INDEX));
|
bind(mTimeCondition, mZenConditions.getChildAt(COUNTDOWN_CONDITION_INDEX),
|
||||||
|
COUNTDOWN_CONDITION_INDEX);
|
||||||
}
|
}
|
||||||
// provider conditions
|
// countdown until alarm
|
||||||
for (int i = 0; i < conditionCount; i++) {
|
if (mCountdownConditionSupported) {
|
||||||
bind(mConditions[i], mZenConditions.getChildAt(mFirstConditionIndex + i));
|
Condition nextAlarmCondition = getTimeUntilNextAlarmCondition();
|
||||||
}
|
if (nextAlarmCondition != null) {
|
||||||
// hide the rest
|
bind(nextAlarmCondition,
|
||||||
for (int i = mZenConditions.getChildCount() - 1; i > mFirstConditionIndex + conditionCount;
|
mZenConditions.getChildAt(COUNTDOWN_ALARM_CONDITION_INDEX),
|
||||||
i--) {
|
COUNTDOWN_ALARM_CONDITION_INDEX);
|
||||||
mZenConditions.getChildAt(i).setVisibility(GONE);
|
}
|
||||||
}
|
}
|
||||||
// ensure something is selected
|
// ensure something is selected
|
||||||
if (mExpanded && isShown()) {
|
if (mExpanded && isShown()) {
|
||||||
@@ -569,6 +506,33 @@ public class ZenModePanel extends LinearLayout {
|
|||||||
return context.getString(com.android.internal.R.string.zen_mode_forever);
|
return context.getString(com.android.internal.R.string.zen_mode_forever);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Returns a time condition if the next alarm is within the next week.
|
||||||
|
private Condition getTimeUntilNextAlarmCondition() {
|
||||||
|
GregorianCalendar weekRange = new GregorianCalendar();
|
||||||
|
final long now = weekRange.getTimeInMillis();
|
||||||
|
setToMidnight(weekRange);
|
||||||
|
weekRange.roll(Calendar.DATE, 6);
|
||||||
|
final long nextAlarmMs = mController.getNextAlarm();
|
||||||
|
if (nextAlarmMs > 0) {
|
||||||
|
GregorianCalendar nextAlarm = new GregorianCalendar();
|
||||||
|
nextAlarm.setTimeInMillis(nextAlarmMs);
|
||||||
|
setToMidnight(nextAlarm);
|
||||||
|
|
||||||
|
if (weekRange.compareTo(nextAlarm) >= 0) {
|
||||||
|
return ZenModeConfig.toNextAlarmCondition(mContext, now, nextAlarmMs,
|
||||||
|
ActivityManager.getCurrentUser());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setToMidnight(Calendar calendar) {
|
||||||
|
calendar.set(Calendar.HOUR_OF_DAY, 0);
|
||||||
|
calendar.set(Calendar.MINUTE, 0);
|
||||||
|
calendar.set(Calendar.SECOND, 0);
|
||||||
|
calendar.set(Calendar.MILLISECOND, 0);
|
||||||
|
}
|
||||||
|
|
||||||
private ConditionTag getConditionTagAt(int index) {
|
private ConditionTag getConditionTagAt(int index) {
|
||||||
return (ConditionTag) mZenConditions.getChildAt(index).getTag();
|
return (ConditionTag) mZenConditions.getChildAt(index).getTag();
|
||||||
}
|
}
|
||||||
@@ -610,7 +574,8 @@ public class ZenModePanel extends LinearLayout {
|
|||||||
mTimeCondition = ZenModeConfig.toTimeCondition(mContext,
|
mTimeCondition = ZenModeConfig.toTimeCondition(mContext,
|
||||||
MINUTE_BUCKETS[favoriteIndex], ActivityManager.getCurrentUser());
|
MINUTE_BUCKETS[favoriteIndex], ActivityManager.getCurrentUser());
|
||||||
mBucketIndex = favoriteIndex;
|
mBucketIndex = favoriteIndex;
|
||||||
bind(mTimeCondition, mZenConditions.getChildAt(COUNTDOWN_CONDITION_INDEX));
|
bind(mTimeCondition, mZenConditions.getChildAt(COUNTDOWN_CONDITION_INDEX),
|
||||||
|
COUNTDOWN_CONDITION_INDEX);
|
||||||
getConditionTagAt(COUNTDOWN_CONDITION_INDEX).rb.setChecked(true);
|
getConditionTagAt(COUNTDOWN_CONDITION_INDEX).rb.setChecked(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -623,7 +588,7 @@ public class ZenModePanel extends LinearLayout {
|
|||||||
return c != null && mForeverId.equals(c.id);
|
return c != null && mForeverId.equals(c.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void bind(final Condition condition, final View row) {
|
private void bind(final Condition condition, final View row, final int rowId) {
|
||||||
if (condition == null) throw new IllegalArgumentException("condition must not be null");
|
if (condition == null) throw new IllegalArgumentException("condition must not be null");
|
||||||
final boolean enabled = condition.state == Condition.STATE_TRUE;
|
final boolean enabled = condition.state == Condition.STATE_TRUE;
|
||||||
final ConditionTag tag =
|
final ConditionTag tag =
|
||||||
@@ -640,8 +605,7 @@ public class ZenModePanel extends LinearLayout {
|
|||||||
tag.rb.setEnabled(enabled);
|
tag.rb.setEnabled(enabled);
|
||||||
final boolean checked = (mSessionExitCondition != null
|
final boolean checked = (mSessionExitCondition != null
|
||||||
|| mAttachedZen != Global.ZEN_MODE_OFF)
|
|| mAttachedZen != Global.ZEN_MODE_OFF)
|
||||||
&& (sameConditionId(mSessionExitCondition, tag.condition)
|
&& (sameConditionId(mSessionExitCondition, tag.condition));
|
||||||
|| isCountdown(mSessionExitCondition) && isCountdown(tag.condition));
|
|
||||||
if (checked != tag.rb.isChecked()) {
|
if (checked != tag.rb.isChecked()) {
|
||||||
if (DEBUG) Log.d(mTag, "bind checked=" + checked + " condition=" + conditionId);
|
if (DEBUG) Log.d(mTag, "bind checked=" + checked + " condition=" + conditionId);
|
||||||
tag.rb.setChecked(checked);
|
tag.rb.setChecked(checked);
|
||||||
@@ -692,7 +656,7 @@ public class ZenModePanel extends LinearLayout {
|
|||||||
button1.setOnClickListener(new OnClickListener() {
|
button1.setOnClickListener(new OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
onClickTimeButton(row, tag, false /*down*/);
|
onClickTimeButton(row, tag, false /*down*/, rowId);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -700,7 +664,7 @@ public class ZenModePanel extends LinearLayout {
|
|||||||
button2.setOnClickListener(new OnClickListener() {
|
button2.setOnClickListener(new OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
onClickTimeButton(row, tag, true /*up*/);
|
onClickTimeButton(row, tag, true /*up*/, rowId);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
tag.lines.setOnClickListener(new OnClickListener() {
|
tag.lines.setOnClickListener(new OnClickListener() {
|
||||||
@@ -711,7 +675,7 @@ public class ZenModePanel extends LinearLayout {
|
|||||||
});
|
});
|
||||||
|
|
||||||
final long time = ZenModeConfig.tryParseCountdownConditionId(conditionId);
|
final long time = ZenModeConfig.tryParseCountdownConditionId(conditionId);
|
||||||
if (time > 0) {
|
if (rowId != COUNTDOWN_ALARM_CONDITION_INDEX && time > 0) {
|
||||||
button1.setVisibility(VISIBLE);
|
button1.setVisibility(VISIBLE);
|
||||||
button2.setVisibility(VISIBLE);
|
button2.setVisibility(VISIBLE);
|
||||||
if (mBucketIndex > -1) {
|
if (mBucketIndex > -1) {
|
||||||
@@ -761,7 +725,7 @@ public class ZenModePanel extends LinearLayout {
|
|||||||
tag.line1.getText()));
|
tag.line1.getText()));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onClickTimeButton(View row, ConditionTag tag, boolean up) {
|
private void onClickTimeButton(View row, ConditionTag tag, boolean up, int rowId) {
|
||||||
MetricsLogger.action(mContext, MetricsLogger.QS_DND_TIME, up);
|
MetricsLogger.action(mContext, MetricsLogger.QS_DND_TIME, up);
|
||||||
Condition newCondition = null;
|
Condition newCondition = null;
|
||||||
final int N = MINUTE_BUCKETS.length;
|
final int N = MINUTE_BUCKETS.length;
|
||||||
@@ -777,7 +741,7 @@ public class ZenModePanel extends LinearLayout {
|
|||||||
if (up && bucketTime > time || !up && bucketTime < time) {
|
if (up && bucketTime > time || !up && bucketTime < time) {
|
||||||
mBucketIndex = j;
|
mBucketIndex = j;
|
||||||
newCondition = ZenModeConfig.toTimeCondition(mContext,
|
newCondition = ZenModeConfig.toTimeCondition(mContext,
|
||||||
bucketTime, bucketMinutes, now, ActivityManager.getCurrentUser(),
|
bucketTime, bucketMinutes, ActivityManager.getCurrentUser(),
|
||||||
false /*shortVersion*/);
|
false /*shortVersion*/);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -794,7 +758,7 @@ public class ZenModePanel extends LinearLayout {
|
|||||||
MINUTE_BUCKETS[mBucketIndex], ActivityManager.getCurrentUser());
|
MINUTE_BUCKETS[mBucketIndex], ActivityManager.getCurrentUser());
|
||||||
}
|
}
|
||||||
mTimeCondition = newCondition;
|
mTimeCondition = newCondition;
|
||||||
bind(mTimeCondition, row);
|
bind(mTimeCondition, row, rowId);
|
||||||
tag.rb.setChecked(true);
|
tag.rb.setChecked(true);
|
||||||
select(mTimeCondition);
|
select(mTimeCondition);
|
||||||
announceConditionSelection(tag);
|
announceConditionSelection(tag);
|
||||||
@@ -837,11 +801,6 @@ public class ZenModePanel extends LinearLayout {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private final ZenModeController.Callback mZenCallback = new ZenModeController.Callback() {
|
private final ZenModeController.Callback mZenCallback = new ZenModeController.Callback() {
|
||||||
@Override
|
|
||||||
public void onConditionsChanged(Condition[] conditions) {
|
|
||||||
mHandler.obtainMessage(H.UPDATE_CONDITIONS, conditions).sendToTarget();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onManualRuleChanged(ZenRule rule) {
|
public void onManualRuleChanged(ZenRule rule) {
|
||||||
mHandler.obtainMessage(H.MANUAL_RULE_CHANGED, rule).sendToTarget();
|
mHandler.obtainMessage(H.MANUAL_RULE_CHANGED, rule).sendToTarget();
|
||||||
@@ -849,7 +808,6 @@ public class ZenModePanel extends LinearLayout {
|
|||||||
};
|
};
|
||||||
|
|
||||||
private final class H extends Handler {
|
private final class H extends Handler {
|
||||||
private static final int UPDATE_CONDITIONS = 1;
|
|
||||||
private static final int MANUAL_RULE_CHANGED = 2;
|
private static final int MANUAL_RULE_CHANGED = 2;
|
||||||
private static final int UPDATE_WIDGETS = 3;
|
private static final int UPDATE_WIDGETS = 3;
|
||||||
|
|
||||||
@@ -860,7 +818,6 @@ public class ZenModePanel extends LinearLayout {
|
|||||||
@Override
|
@Override
|
||||||
public void handleMessage(Message msg) {
|
public void handleMessage(Message msg) {
|
||||||
switch (msg.what) {
|
switch (msg.what) {
|
||||||
case UPDATE_CONDITIONS: handleUpdateConditions((Condition[]) msg.obj); break;
|
|
||||||
case MANUAL_RULE_CHANGED: handleUpdateManualRule((ZenRule) msg.obj); break;
|
case MANUAL_RULE_CHANGED: handleUpdateManualRule((ZenRule) msg.obj); break;
|
||||||
case UPDATE_WIDGETS: updateWidgets(); break;
|
case UPDATE_WIDGETS: updateWidgets(); break;
|
||||||
}
|
}
|
||||||
@@ -1005,26 +962,20 @@ public class ZenModePanel extends LinearLayout {
|
|||||||
private final ArraySet<View> mTransitioningViews = new ArraySet<View>();
|
private final ArraySet<View> mTransitioningViews = new ArraySet<View>();
|
||||||
|
|
||||||
private boolean mTransitioning;
|
private boolean mTransitioning;
|
||||||
private boolean mPendingUpdateConditions;
|
|
||||||
private boolean mPendingUpdateWidgets;
|
private boolean mPendingUpdateWidgets;
|
||||||
|
|
||||||
public void clear() {
|
public void clear() {
|
||||||
mTransitioningViews.clear();
|
mTransitioningViews.clear();
|
||||||
mPendingUpdateConditions = mPendingUpdateWidgets = false;
|
mPendingUpdateWidgets = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
|
public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
|
||||||
pw.println(" TransitionHelper state:");
|
pw.println(" TransitionHelper state:");
|
||||||
pw.print(" mPendingUpdateConditions="); pw.println(mPendingUpdateConditions);
|
|
||||||
pw.print(" mPendingUpdateWidgets="); pw.println(mPendingUpdateWidgets);
|
pw.print(" mPendingUpdateWidgets="); pw.println(mPendingUpdateWidgets);
|
||||||
pw.print(" mTransitioning="); pw.println(mTransitioning);
|
pw.print(" mTransitioning="); pw.println(mTransitioning);
|
||||||
pw.print(" mTransitioningViews="); pw.println(mTransitioningViews);
|
pw.print(" mTransitioningViews="); pw.println(mTransitioningViews);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void pendingUpdateConditions() {
|
|
||||||
mPendingUpdateConditions = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void pendingUpdateWidgets() {
|
public void pendingUpdateWidgets() {
|
||||||
mPendingUpdateWidgets = true;
|
mPendingUpdateWidgets = true;
|
||||||
}
|
}
|
||||||
@@ -1050,15 +1001,11 @@ public class ZenModePanel extends LinearLayout {
|
|||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (DEBUG) Log.d(mTag, "TransitionHelper run"
|
if (DEBUG) Log.d(mTag, "TransitionHelper run"
|
||||||
+ " mPendingUpdateWidgets=" + mPendingUpdateWidgets
|
+ " mPendingUpdateWidgets=" + mPendingUpdateWidgets);
|
||||||
+ " mPendingUpdateConditions=" + mPendingUpdateConditions);
|
|
||||||
if (mPendingUpdateWidgets) {
|
if (mPendingUpdateWidgets) {
|
||||||
updateWidgets();
|
updateWidgets();
|
||||||
}
|
}
|
||||||
if (mPendingUpdateConditions) {
|
mPendingUpdateWidgets = false;
|
||||||
handleUpdateConditions();
|
|
||||||
}
|
|
||||||
mPendingUpdateWidgets = mPendingUpdateConditions = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateTransitioning() {
|
private void updateTransitioning() {
|
||||||
@@ -1067,10 +1014,10 @@ public class ZenModePanel extends LinearLayout {
|
|||||||
mTransitioning = transitioning;
|
mTransitioning = transitioning;
|
||||||
if (DEBUG) Log.d(mTag, "TransitionHelper mTransitioning=" + mTransitioning);
|
if (DEBUG) Log.d(mTag, "TransitionHelper mTransitioning=" + mTransitioning);
|
||||||
if (!mTransitioning) {
|
if (!mTransitioning) {
|
||||||
if (mPendingUpdateConditions || mPendingUpdateWidgets) {
|
if (mPendingUpdateWidgets) {
|
||||||
mHandler.post(this);
|
mHandler.post(this);
|
||||||
} else {
|
} else {
|
||||||
mPendingUpdateConditions = mPendingUpdateWidgets = false;
|
mPendingUpdateWidgets = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user