am 338bc5a4: Merge "Zen: Update condition text for current condition." into lmp-mr1-dev
automerge: 1a68ba6
* commit '1a68ba6b85473565de174f72beeb7734e49e0fa0':
Zen: Update condition text for current condition.
This commit is contained in:
@@ -244,7 +244,7 @@ public class ZenModePanel extends LinearLayout {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void setExitCondition(Condition exitCondition) {
|
private void setExitCondition(Condition exitCondition) {
|
||||||
if (sameConditionId(mExitCondition, exitCondition)) return;
|
if (Objects.equals(mExitCondition, exitCondition)) return;
|
||||||
mExitCondition = exitCondition;
|
mExitCondition = exitCondition;
|
||||||
refreshExitConditionText();
|
refreshExitConditionText();
|
||||||
updateWidgets();
|
updateWidgets();
|
||||||
|
|||||||
@@ -260,9 +260,11 @@ public class ConditionProviders extends ManagedServices {
|
|||||||
for (int i = 0; i < N; i++) {
|
for (int i = 0; i < N; i++) {
|
||||||
final Condition c = conditions[i];
|
final Condition c = conditions[i];
|
||||||
final ConditionRecord r = getRecordLocked(c.id, info.component);
|
final ConditionRecord r = getRecordLocked(c.id, info.component);
|
||||||
|
final Condition oldCondition = r.condition;
|
||||||
|
final boolean conditionUpdate = oldCondition != null && !oldCondition.equals(c);
|
||||||
r.info = info;
|
r.info = info;
|
||||||
r.condition = c;
|
r.condition = c;
|
||||||
// if manual, exit zen if false (or failed)
|
// if manual, exit zen if false (or failed), update if true (and changed)
|
||||||
if (r.isManual) {
|
if (r.isManual) {
|
||||||
if (c.state == Condition.STATE_FALSE || c.state == Condition.STATE_ERROR) {
|
if (c.state == Condition.STATE_FALSE || c.state == Condition.STATE_ERROR) {
|
||||||
final boolean failed = c.state == Condition.STATE_ERROR;
|
final boolean failed = c.state == Condition.STATE_ERROR;
|
||||||
@@ -275,6 +277,10 @@ public class ConditionProviders extends ManagedServices {
|
|||||||
"manualConditionExit");
|
"manualConditionExit");
|
||||||
unsubscribeLocked(r);
|
unsubscribeLocked(r);
|
||||||
r.isManual = false;
|
r.isManual = false;
|
||||||
|
} else if (c.state == Condition.STATE_TRUE && conditionUpdate) {
|
||||||
|
if (DEBUG) Slog.d(TAG, "Current condition updated, still true. old="
|
||||||
|
+ oldCondition + " new=" + c);
|
||||||
|
setZenModeCondition(c, "conditionUpdate");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// if automatic, exit zen if false (or failed), enter zen if true
|
// if automatic, exit zen if false (or failed), enter zen if true
|
||||||
@@ -559,7 +565,7 @@ public class ConditionProviders extends ManagedServices {
|
|||||||
// enter downtime, or update mode if reconfigured during an active downtime
|
// enter downtime, or update mode if reconfigured during an active downtime
|
||||||
if (inDowntime && (mode == Global.ZEN_MODE_OFF || downtimeCurrent) && config != null) {
|
if (inDowntime && (mode == Global.ZEN_MODE_OFF || downtimeCurrent) && config != null) {
|
||||||
final Condition condition = mDowntime.createCondition(config.toDowntimeInfo(),
|
final Condition condition = mDowntime.createCondition(config.toDowntimeInfo(),
|
||||||
Condition.STATE_TRUE);
|
config.sleepNone, Condition.STATE_TRUE);
|
||||||
mZenModeHelper.setZenMode(downtimeMode, "downtimeEnter");
|
mZenModeHelper.setZenMode(downtimeMode, "downtimeEnter");
|
||||||
setZenModeCondition(condition, "downtime");
|
setZenModeCondition(condition, "downtime");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -122,7 +122,8 @@ public class DowntimeConditionProvider extends ConditionProviderService {
|
|||||||
if (DEBUG) Slog.d(TAG, "onRequestConditions relevance=" + relevance);
|
if (DEBUG) Slog.d(TAG, "onRequestConditions relevance=" + relevance);
|
||||||
if ((relevance & Condition.FLAG_RELEVANT_NOW) != 0) {
|
if ((relevance & Condition.FLAG_RELEVANT_NOW) != 0) {
|
||||||
if (isInDowntime() && mConfig != null) {
|
if (isInDowntime() && mConfig != null) {
|
||||||
notifyCondition(createCondition(mConfig.toDowntimeInfo(), Condition.STATE_TRUE));
|
notifyCondition(createCondition(mConfig.toDowntimeInfo(), mConfig.sleepNone,
|
||||||
|
Condition.STATE_TRUE));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -135,7 +136,7 @@ public class DowntimeConditionProvider extends ConditionProviderService {
|
|||||||
final int state = mConfig.toDowntimeInfo().equals(downtime) && isInDowntime()
|
final int state = mConfig.toDowntimeInfo().equals(downtime) && isInDowntime()
|
||||||
? Condition.STATE_TRUE : Condition.STATE_FALSE;
|
? Condition.STATE_TRUE : Condition.STATE_FALSE;
|
||||||
if (DEBUG) Slog.d(TAG, "notify condition state: " + Condition.stateToString(state));
|
if (DEBUG) Slog.d(TAG, "notify condition state: " + Condition.stateToString(state));
|
||||||
notifyCondition(createCondition(downtime, state));
|
notifyCondition(createCondition(downtime, mConfig.sleepNone, state));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -157,14 +158,22 @@ public class DowntimeConditionProvider extends ConditionProviderService {
|
|||||||
return mDowntimeMode != Global.ZEN_MODE_OFF;
|
return mDowntimeMode != Global.ZEN_MODE_OFF;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Condition createCondition(DowntimeInfo downtime, int state) {
|
public Condition createCondition(DowntimeInfo downtime, boolean orAlarm, int state) {
|
||||||
if (downtime == null) return null;
|
if (downtime == null) return null;
|
||||||
final Uri id = ZenModeConfig.toDowntimeConditionId(downtime);
|
final Uri id = ZenModeConfig.toDowntimeConditionId(downtime);
|
||||||
final String skeleton = DateFormat.is24HourFormat(mContext) ? "Hm" : "hma";
|
final String skeleton = DateFormat.is24HourFormat(mContext) ? "Hm" : "hma";
|
||||||
final Locale locale = Locale.getDefault();
|
final Locale locale = Locale.getDefault();
|
||||||
final String pattern = DateFormat.getBestDateTimePattern(locale, skeleton);
|
final String pattern = DateFormat.getBestDateTimePattern(locale, skeleton);
|
||||||
final long time = getTime(System.currentTimeMillis(), downtime.endHour, downtime.endMinute);
|
final long now = System.currentTimeMillis();
|
||||||
final String formatted = new SimpleDateFormat(pattern, locale).format(new Date(time));
|
long endTime = getTime(now, downtime.endHour, downtime.endMinute);
|
||||||
|
if (orAlarm) {
|
||||||
|
final AlarmClockInfo nextAlarm = mTracker.getNextAlarm();
|
||||||
|
final long nextAlarmTime = nextAlarm != null ? nextAlarm.getTriggerTime() : 0;
|
||||||
|
if (nextAlarmTime > now && nextAlarmTime < endTime) {
|
||||||
|
endTime = nextAlarmTime;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
final String formatted = new SimpleDateFormat(pattern, locale).format(new Date(endTime));
|
||||||
final String summary = mContext.getString(R.string.downtime_condition_summary, formatted);
|
final String summary = mContext.getString(R.string.downtime_condition_summary, formatted);
|
||||||
final String line1 = mContext.getString(R.string.downtime_condition_line_one);
|
final String line1 = mContext.getString(R.string.downtime_condition_line_one);
|
||||||
return new Condition(id, summary, line1, formatted, 0, state, Condition.FLAG_RELEVANT_NOW);
|
return new Condition(id, summary, line1, formatted, 0, state, Condition.FLAG_RELEVANT_NOW);
|
||||||
@@ -302,6 +311,11 @@ public class DowntimeConditionProvider extends ConditionProviderService {
|
|||||||
|
|
||||||
private void onEvaluateNextAlarm(AlarmClockInfo nextAlarm, long wakeupTime, boolean booted) {
|
private void onEvaluateNextAlarm(AlarmClockInfo nextAlarm, long wakeupTime, boolean booted) {
|
||||||
if (!booted) return; // we don't know yet
|
if (!booted) return; // we don't know yet
|
||||||
|
// update condition description if we're in downtime (mode = none)
|
||||||
|
if (isInDowntime() && mConfig != null && mConfig.sleepNone) {
|
||||||
|
notifyCondition(createCondition(mConfig.toDowntimeInfo(), true /*orAlarm*/,
|
||||||
|
Condition.STATE_TRUE));
|
||||||
|
}
|
||||||
if (nextAlarm == null) return; // not fireable
|
if (nextAlarm == null) return; // not fireable
|
||||||
if (DEBUG) Slog.d(TAG, "onEvaluateNextAlarm " + mTracker.formatAlarmDebug(nextAlarm));
|
if (DEBUG) Slog.d(TAG, "onEvaluateNextAlarm " + mTracker.formatAlarmDebug(nextAlarm));
|
||||||
if (System.currentTimeMillis() > wakeupTime) {
|
if (System.currentTimeMillis() > wakeupTime) {
|
||||||
@@ -336,6 +350,10 @@ public class DowntimeConditionProvider extends ConditionProviderService {
|
|||||||
} else if (Intent.ACTION_TIMEZONE_CHANGED.equals(action)) {
|
} else if (Intent.ACTION_TIMEZONE_CHANGED.equals(action)) {
|
||||||
if (DEBUG) Slog.d(TAG, "timezone changed to " + TimeZone.getDefault());
|
if (DEBUG) Slog.d(TAG, "timezone changed to " + TimeZone.getDefault());
|
||||||
mCalendar.setTimeZone(TimeZone.getDefault());
|
mCalendar.setTimeZone(TimeZone.getDefault());
|
||||||
|
mFiredAlarms.clear();
|
||||||
|
} else if (Intent.ACTION_TIME_CHANGED.equals(action)) {
|
||||||
|
if (DEBUG) Slog.d(TAG, "time changed to " + now);
|
||||||
|
mFiredAlarms.clear();
|
||||||
} else {
|
} else {
|
||||||
if (DEBUG) Slog.d(TAG, action + " fired at " + now);
|
if (DEBUG) Slog.d(TAG, action + " fired at " + now);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user