diff options
author | John Spurlock <jspurlock@google.com> | 2014-12-22 15:13:30 -0500 |
---|---|---|
committer | John Spurlock <jspurlock@google.com> | 2014-12-22 15:13:30 -0500 |
commit | 0b688503754737a20165f0cff1833e714a5c4164 (patch) | |
tree | 99dbfc5ba3493d6486686377bfea535eef98b589 /packages | |
parent | 2c8c47daefc881c5603689be39b10cb93a0cabdf (diff) | |
download | frameworks_base-0b688503754737a20165f0cff1833e714a5c4164.zip frameworks_base-0b688503754737a20165f0cff1833e714a5c4164.tar.gz frameworks_base-0b688503754737a20165f0cff1833e714a5c4164.tar.bz2 |
Zen: Fix selection logic for "Indefinitely".
Use a signal condition value for the forever condition in the panel
to ease the distinction between no selection + selecting indef.
Bug: 18810529
Change-Id: I2590899ab43734708c72aad066653ef27f89d760
Diffstat (limited to 'packages')
-rw-r--r-- | packages/SystemUI/src/com/android/systemui/volume/ZenModePanel.java | 46 |
1 files changed, 29 insertions, 17 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/volume/ZenModePanel.java b/packages/SystemUI/src/com/android/systemui/volume/ZenModePanel.java index e250ec7..d40a2c0 100644 --- a/packages/SystemUI/src/com/android/systemui/volume/ZenModePanel.java +++ b/packages/SystemUI/src/com/android/systemui/volume/ZenModePanel.java @@ -90,6 +90,7 @@ public class ZenModePanel extends LinearLayout { private final boolean mCountdownConditionSupported; private final int mFirstConditionIndex; private final TransitionHelper mTransitionHelper = new TransitionHelper(); + private final Uri mForeverId; private String mTag = TAG + "/" + Integer.toHexString(System.identityHashCode(this)); @@ -134,6 +135,7 @@ public class ZenModePanel extends LinearLayout { mMaxConditions = MathUtils.constrain(res.getInteger(R.integer.zen_mode_max_conditions), minConditions, 100); mMaxOptionalConditions = mMaxConditions - minConditions; + mForeverId = Condition.newId(mContext).appendPath("forever").build(); if (DEBUG) Log.d(mTag, "new ZenModePanel"); } @@ -338,12 +340,11 @@ public class ZenModePanel extends LinearLayout { } private void refreshExitConditionText() { - final String forever = mContext.getString(com.android.internal.R.string.zen_mode_forever); if (mExitCondition == null) { - mExitConditionText = forever; + mExitConditionText = foreverSummary(); } else if (isCountdown(mExitCondition)) { final Condition condition = parseExistingTimeCondition(mExitCondition); - mExitConditionText = condition != null ? condition.summary : forever; + mExitConditionText = condition != null ? condition.summary : foreverSummary(); } else { mExitConditionText = mExitCondition.summary; } @@ -473,9 +474,9 @@ public class ZenModePanel extends LinearLayout { final int conditionCount = mConditions == null ? 0 : mConditions.length; if (DEBUG) Log.d(mTag, "handleUpdateConditions conditionCount=" + conditionCount); // forever - bind(null, mZenConditions.getChildAt(FOREVER_CONDITION_INDEX)); + bind(forever(), mZenConditions.getChildAt(FOREVER_CONDITION_INDEX)); // countdown - if (mCountdownConditionSupported) { + if (mCountdownConditionSupported && mTimeCondition != null) { bind(mTimeCondition, mZenConditions.getChildAt(COUNTDOWN_CONDITION_INDEX)); } // provider conditions @@ -483,7 +484,8 @@ public class ZenModePanel extends LinearLayout { bind(mConditions[i], mZenConditions.getChildAt(mFirstConditionIndex + i)); } // hide the rest - for (int i = mZenConditions.getChildCount() - 1; i > mFirstConditionIndex + conditionCount; i--) { + for (int i = mZenConditions.getChildCount() - 1; i > mFirstConditionIndex + conditionCount; + i--) { mZenConditions.getChildAt(i).setVisibility(GONE); } // ensure something is selected @@ -492,6 +494,15 @@ public class ZenModePanel extends LinearLayout { } } + private Condition forever() { + return new Condition(mForeverId, foreverSummary(), "", "", 0 /*icon*/, Condition.STATE_TRUE, + 0 /*flags*/); + } + + private String foreverSummary() { + return mContext.getString(com.android.internal.R.string.zen_mode_forever); + } + private ConditionTag getConditionTagAt(int index) { return (ConditionTag) mZenConditions.getChildAt(index).getTag(); } @@ -556,8 +567,13 @@ public class ZenModePanel extends LinearLayout { return c != null && ZenModeConfig.isValidCountdownConditionId(c.id); } + private boolean isForever(Condition c) { + return c != null && mForeverId.equals(c.id); + } + private void bind(final Condition condition, final View row) { - final boolean enabled = condition == null || condition.state == Condition.STATE_TRUE; + if (condition == null) throw new IllegalArgumentException("condition must not be null"); + final boolean enabled = condition.state == Condition.STATE_TRUE; final ConditionTag tag = row.getTag() != null ? (ConditionTag) row.getTag() : new ConditionTag(); row.setTag(tag); @@ -604,14 +620,9 @@ public class ZenModePanel extends LinearLayout { if (tag.line2 == null) { tag.line2 = (TextView) row.findViewById(android.R.id.text2); } - final String line1, line2; - if (condition == null) { - line1 = mContext.getString(com.android.internal.R.string.zen_mode_forever); - line2 = null; - } else { - line1 = !TextUtils.isEmpty(condition.line1) ? condition.line1 : condition.summary; - line2 = condition.line2; - } + final String line1 = !TextUtils.isEmpty(condition.line1) ? condition.line1 + : condition.summary; + final String line2 = condition.line2; tag.line1.setText(line1); if (TextUtils.isEmpty(line2)) { tag.line2.setVisibility(GONE); @@ -731,16 +742,17 @@ public class ZenModePanel extends LinearLayout { private void select(final Condition condition) { if (DEBUG) Log.d(mTag, "select " + condition); + final boolean isForever = isForever(condition); if (mController != null) { AsyncTask.execute(new Runnable() { @Override public void run() { - mController.setExitCondition(condition); + mController.setExitCondition(isForever ? null : condition); } }); } setExitCondition(condition); - if (condition == null) { + if (isForever) { mPrefs.setMinuteIndex(-1); } else if (isCountdown(condition) && mBucketIndex != -1) { mPrefs.setMinuteIndex(mBucketIndex); |