diff options
author | Julia Reynolds <juliacr@google.com> | 2015-10-01 14:34:22 -0400 |
---|---|---|
committer | Julia Reynolds <juliacr@google.com> | 2015-10-15 17:02:00 -0400 |
commit | 8e2d2bbeec74b02960504a09e02e601ee2cf5e0e (patch) | |
tree | a31351d484896cc77e2af2ca8bd170dac6284360 /packages/SystemUI | |
parent | 575b629ef8e21cca5a40acaafeee7653d90956fe (diff) | |
download | frameworks_base-8e2d2bbeec74b02960504a09e02e601ee2cf5e0e.zip frameworks_base-8e2d2bbeec74b02960504a09e02e601ee2cf5e0e.tar.gz frameworks_base-8e2d2bbeec74b02960504a09e02e601ee2cf5e0e.tar.bz2 |
Add 'until next alarm' option to QS zen panel.
Unlike the implementation in LMR1, this is a countdown condition
(a countdown until the time of what was the next alarm when the
rule was created). The rule will not change if alarms change.
Also, alarms up to 7 days in the future will be considered.
Bug: 21648799
Change-Id: Id7fa9dbdbad1539e4da19b1d0e0c4395bb13e6cb
(cherry picked from commit 0842fe87b27b9e4a7aecfec25b93dba2d39f398a)
Diffstat (limited to 'packages/SystemUI')
3 files changed, 65 insertions, 128 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/ZenModeController.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/ZenModeController.java index b2df40a..0e91b0b 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/ZenModeController.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/ZenModeController.java @@ -27,7 +27,6 @@ public interface ZenModeController { void removeCallback(Callback callback); void setZen(int zen, Uri conditionId, String reason); int getZen(); - void requestConditions(boolean request); ZenRule getManualRule(); ZenModeConfig getConfig(); long getNextAlarm(); diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/ZenModeControllerImpl.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/ZenModeControllerImpl.java index c07f1a8..96efea1 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/ZenModeControllerImpl.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/ZenModeControllerImpl.java @@ -121,15 +121,6 @@ public class ZenModeControllerImpl implements ZenModeController { } @Override - public void requestConditions(boolean request) { - mRequesting = request; - mNoMan.requestZenModeConditions(mListener, request ? Condition.FLAG_RELEVANT_NOW : 0); - if (!mRequesting) { - mConditions.clear(); - } - } - - @Override public ZenRule getManualRule() { return mConfig == null ? null : mConfig.manualRule; } diff --git a/packages/SystemUI/src/com/android/systemui/volume/ZenModePanel.java b/packages/SystemUI/src/com/android/systemui/volume/ZenModePanel.java index 3c9a7fc..3337714 100644 --- a/packages/SystemUI/src/com/android/systemui/volume/ZenModePanel.java +++ b/packages/SystemUI/src/com/android/systemui/volume/ZenModePanel.java @@ -1,4 +1,4 @@ -/* +/** * Copyright (C) 2014 The Android Open Source Project * * 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.PrintWriter; import java.util.Arrays; +import java.util.Calendar; +import java.util.GregorianCalendar; import java.util.Locale; 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 FOREVER_CONDITION_INDEX = 0; 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 = new Intent(Settings.ACTION_ZEN_MODE_SETTINGS); @@ -86,7 +90,6 @@ public class ZenModePanel extends LinearLayout { private final LayoutInflater mInflater; private final H mHandler = new H(); private final ZenPrefs mPrefs; - private final IconPulser mIconPulser; private final TransitionHelper mTransitionHelper = new TransitionHelper(); private final Uri mForeverId; private final SpTexts mSpTexts; @@ -104,9 +107,6 @@ public class ZenModePanel extends LinearLayout { private Callback mCallback; private ZenModeController mController; private boolean mCountdownConditionSupported; - private int mMaxConditions; - private int mMaxOptionalConditions; - private int mFirstConditionIndex; private boolean mRequestingConditions; private Condition mExitCondition; private int mBucketIndex = -1; @@ -125,7 +125,6 @@ public class ZenModePanel extends LinearLayout { mContext = context; mPrefs = new ZenPrefs(); mInflater = LayoutInflater.from(mContext.getApplicationContext()); - mIconPulser = new IconPulser(mContext); mForeverId = Condition.newId(mContext).appendPath("forever").build(); mSpTexts = new SpTexts(mContext); mVoiceCapable = Util.isVoiceCapable(mContext); @@ -135,7 +134,6 @@ public class ZenModePanel extends LinearLayout { public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { pw.println("ZenModePanel state:"); pw.print(" mCountdownConditionSupported="); pw.println(mCountdownConditionSupported); - pw.print(" mMaxConditions="); pw.println(mMaxConditions); pw.print(" mRequestingConditions="); pw.println(mRequestingConditions); pw.print(" mAttached="); pw.println(mAttached); pw.print(" mHidden="); pw.println(mHidden); @@ -286,14 +284,6 @@ public class ZenModePanel extends LinearLayout { if (mRequestingConditions == requesting) return; if (DEBUG) Log.d(mTag, "setRequestingConditions " + requesting); mRequestingConditions = requesting; - if (mController != null) { - AsyncTask.execute(new Runnable() { - @Override - public void run() { - mController.requestConditions(requesting); - } - }); - } if (mRequestingConditions) { mTimeCondition = parseExistingTimeCondition(mContext, mExitCondition); if (mTimeCondition != null) { @@ -304,6 +294,7 @@ public class ZenModePanel extends LinearLayout { MINUTE_BUCKETS[mBucketIndex], ActivityManager.getCurrentUser()); } if (DEBUG) Log.d(mTag, "Initial bucket index: " + mBucketIndex); + mConditions = null; // reset conditions handleUpdateConditions(); } else { @@ -314,13 +305,9 @@ public class ZenModePanel extends LinearLayout { public void init(ZenModeController controller) { mController = controller; mCountdownConditionSupported = mController.isCountdownConditionSupported(); - final int countdownDelta = mCountdownConditionSupported ? 1 : 0; - mFirstConditionIndex = COUNTDOWN_CONDITION_INDEX + countdownDelta; + final int countdownDelta = mCountdownConditionSupported ? COUNTDOWN_CONDITION_COUNT : 0; final int minConditions = 1 /*forever*/ + countdownDelta; - mMaxConditions = MathUtils.constrain(mContext.getResources() - .getInteger(R.integer.zen_mode_max_conditions), minConditions, 100); - mMaxOptionalConditions = mMaxConditions - minConditions; - for (int i = 0; i < mMaxConditions; i++) { + for (int i = 0; i < minConditions; i++) { mZenConditions.addView(mInflater.inflate(R.layout.zen_mode_condition, this, false)); } mSessionZen = getSelectedZen(-1); @@ -357,28 +344,10 @@ public class ZenModePanel extends LinearLayout { 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) { 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) { final int zen = rule != null ? rule.zenMode : Global.ZEN_MODE_OFF; handleUpdateZen(zen); @@ -410,7 +379,7 @@ public class ZenModePanel extends LinearLayout { final ConditionTag tag = getConditionTagAt(i); if (tag != null) { 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; if (span <= 0 || span > MAX_BUCKET_MINUTES * MINUTES_MS) return null; 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*/); } - 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() { if (mTransitionHelper.isTransitioning()) { - mTransitionHelper.pendingUpdateConditions(); return; } final int conditionCount = mConditions == null ? 0 : mConditions.length; if (DEBUG) Log.d(mTag, "handleUpdateConditions conditionCount=" + conditionCount); // forever - bind(forever(), mZenConditions.getChildAt(FOREVER_CONDITION_INDEX)); + bind(forever(), mZenConditions.getChildAt(FOREVER_CONDITION_INDEX), + FOREVER_CONDITION_INDEX); // countdown if (mCountdownConditionSupported && mTimeCondition != null) { - bind(mTimeCondition, mZenConditions.getChildAt(COUNTDOWN_CONDITION_INDEX)); - } - // provider conditions - for (int i = 0; i < conditionCount; i++) { - bind(mConditions[i], mZenConditions.getChildAt(mFirstConditionIndex + i)); - } - // hide the rest - for (int i = mZenConditions.getChildCount() - 1; i > mFirstConditionIndex + conditionCount; - i--) { - mZenConditions.getChildAt(i).setVisibility(GONE); + bind(mTimeCondition, mZenConditions.getChildAt(COUNTDOWN_CONDITION_INDEX), + COUNTDOWN_CONDITION_INDEX); + } + // countdown until alarm + if (mCountdownConditionSupported) { + Condition nextAlarmCondition = getTimeUntilNextAlarmCondition(); + if (nextAlarmCondition != null) { + bind(nextAlarmCondition, + mZenConditions.getChildAt(COUNTDOWN_ALARM_CONDITION_INDEX), + COUNTDOWN_ALARM_CONDITION_INDEX); + } } // ensure something is selected if (mExpanded && isShown()) { @@ -569,6 +506,33 @@ public class ZenModePanel extends LinearLayout { 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) { return (ConditionTag) mZenConditions.getChildAt(index).getTag(); } @@ -610,7 +574,8 @@ public class ZenModePanel extends LinearLayout { mTimeCondition = ZenModeConfig.toTimeCondition(mContext, MINUTE_BUCKETS[favoriteIndex], ActivityManager.getCurrentUser()); 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); } } @@ -623,7 +588,7 @@ public class ZenModePanel extends LinearLayout { 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"); final boolean enabled = condition.state == Condition.STATE_TRUE; final ConditionTag tag = @@ -640,8 +605,7 @@ public class ZenModePanel extends LinearLayout { tag.rb.setEnabled(enabled); final boolean checked = (mSessionExitCondition != null || mAttachedZen != Global.ZEN_MODE_OFF) - && (sameConditionId(mSessionExitCondition, tag.condition) - || isCountdown(mSessionExitCondition) && isCountdown(tag.condition)); + && (sameConditionId(mSessionExitCondition, tag.condition)); if (checked != tag.rb.isChecked()) { if (DEBUG) Log.d(mTag, "bind checked=" + checked + " condition=" + conditionId); tag.rb.setChecked(checked); @@ -692,7 +656,7 @@ public class ZenModePanel extends LinearLayout { button1.setOnClickListener(new OnClickListener() { @Override 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() { @Override public void onClick(View v) { - onClickTimeButton(row, tag, true /*up*/); + onClickTimeButton(row, tag, true /*up*/, rowId); } }); tag.lines.setOnClickListener(new OnClickListener() { @@ -711,7 +675,7 @@ public class ZenModePanel extends LinearLayout { }); final long time = ZenModeConfig.tryParseCountdownConditionId(conditionId); - if (time > 0) { + if (rowId != COUNTDOWN_ALARM_CONDITION_INDEX && time > 0) { button1.setVisibility(VISIBLE); button2.setVisibility(VISIBLE); if (mBucketIndex > -1) { @@ -761,7 +725,7 @@ public class ZenModePanel extends LinearLayout { 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); Condition newCondition = null; final int N = MINUTE_BUCKETS.length; @@ -777,7 +741,7 @@ public class ZenModePanel extends LinearLayout { if (up && bucketTime > time || !up && bucketTime < time) { mBucketIndex = j; newCondition = ZenModeConfig.toTimeCondition(mContext, - bucketTime, bucketMinutes, now, ActivityManager.getCurrentUser(), + bucketTime, bucketMinutes, ActivityManager.getCurrentUser(), false /*shortVersion*/); break; } @@ -794,7 +758,7 @@ public class ZenModePanel extends LinearLayout { MINUTE_BUCKETS[mBucketIndex], ActivityManager.getCurrentUser()); } mTimeCondition = newCondition; - bind(mTimeCondition, row); + bind(mTimeCondition, row, rowId); tag.rb.setChecked(true); select(mTimeCondition); announceConditionSelection(tag); @@ -838,18 +802,12 @@ public class ZenModePanel extends LinearLayout { private final ZenModeController.Callback mZenCallback = new ZenModeController.Callback() { @Override - public void onConditionsChanged(Condition[] conditions) { - mHandler.obtainMessage(H.UPDATE_CONDITIONS, conditions).sendToTarget(); - } - - @Override public void onManualRuleChanged(ZenRule rule) { mHandler.obtainMessage(H.MANUAL_RULE_CHANGED, rule).sendToTarget(); } }; 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 UPDATE_WIDGETS = 3; @@ -860,7 +818,6 @@ public class ZenModePanel extends LinearLayout { @Override public void handleMessage(Message msg) { switch (msg.what) { - case UPDATE_CONDITIONS: handleUpdateConditions((Condition[]) msg.obj); break; case MANUAL_RULE_CHANGED: handleUpdateManualRule((ZenRule) msg.obj); break; case UPDATE_WIDGETS: updateWidgets(); break; } @@ -1005,26 +962,20 @@ public class ZenModePanel extends LinearLayout { private final ArraySet<View> mTransitioningViews = new ArraySet<View>(); private boolean mTransitioning; - private boolean mPendingUpdateConditions; private boolean mPendingUpdateWidgets; public void clear() { mTransitioningViews.clear(); - mPendingUpdateConditions = mPendingUpdateWidgets = false; + mPendingUpdateWidgets = false; } public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { pw.println(" TransitionHelper state:"); - pw.print(" mPendingUpdateConditions="); pw.println(mPendingUpdateConditions); pw.print(" mPendingUpdateWidgets="); pw.println(mPendingUpdateWidgets); pw.print(" mTransitioning="); pw.println(mTransitioning); pw.print(" mTransitioningViews="); pw.println(mTransitioningViews); } - public void pendingUpdateConditions() { - mPendingUpdateConditions = true; - } - public void pendingUpdateWidgets() { mPendingUpdateWidgets = true; } @@ -1050,15 +1001,11 @@ public class ZenModePanel extends LinearLayout { @Override public void run() { if (DEBUG) Log.d(mTag, "TransitionHelper run" - + " mPendingUpdateWidgets=" + mPendingUpdateWidgets - + " mPendingUpdateConditions=" + mPendingUpdateConditions); + + " mPendingUpdateWidgets=" + mPendingUpdateWidgets); if (mPendingUpdateWidgets) { updateWidgets(); } - if (mPendingUpdateConditions) { - handleUpdateConditions(); - } - mPendingUpdateWidgets = mPendingUpdateConditions = false; + mPendingUpdateWidgets = false; } private void updateTransitioning() { @@ -1067,10 +1014,10 @@ public class ZenModePanel extends LinearLayout { mTransitioning = transitioning; if (DEBUG) Log.d(mTag, "TransitionHelper mTransitioning=" + mTransitioning); if (!mTransitioning) { - if (mPendingUpdateConditions || mPendingUpdateWidgets) { + if (mPendingUpdateWidgets) { mHandler.post(this); } else { - mPendingUpdateConditions = mPendingUpdateWidgets = false; + mPendingUpdateWidgets = false; } } } |