Julia Reynolds | 0842fe8 | 2015-10-01 14:34:22 -0400 | [diff] [blame] | 1 | /** |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.systemui.volume; |
| 18 | |
John Spurlock | 3e07701 | 2014-11-29 13:22:21 -0500 | [diff] [blame] | 19 | import android.animation.LayoutTransition; |
John Spurlock | 530052a | 2014-11-30 16:26:19 -0500 | [diff] [blame] | 20 | import android.animation.LayoutTransition.TransitionListener; |
Selim Cinek | 9c4a707 | 2014-11-21 17:44:34 +0100 | [diff] [blame] | 21 | import android.app.ActivityManager; |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 22 | import android.content.Context; |
| 23 | import android.content.Intent; |
John Spurlock | 856edeb | 2014-06-01 20:36:47 -0400 | [diff] [blame] | 24 | import android.content.SharedPreferences; |
| 25 | import android.content.SharedPreferences.OnSharedPreferenceChangeListener; |
John Spurlock | 814ee6ab | 2015-05-18 11:16:38 -0400 | [diff] [blame] | 26 | import android.content.res.Configuration; |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 27 | import android.net.Uri; |
John Spurlock | 530052a | 2014-11-30 16:26:19 -0500 | [diff] [blame] | 28 | import android.os.AsyncTask; |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 29 | import android.os.Handler; |
| 30 | import android.os.Looper; |
| 31 | import android.os.Message; |
| 32 | import android.provider.Settings; |
John Spurlock | ae641c9 | 2014-06-30 18:11:40 -0400 | [diff] [blame] | 33 | import android.provider.Settings.Global; |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 34 | import android.service.notification.Condition; |
John Spurlock | 856edeb | 2014-06-01 20:36:47 -0400 | [diff] [blame] | 35 | import android.service.notification.ZenModeConfig; |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 36 | import android.service.notification.ZenModeConfig.ZenRule; |
John Spurlock | c90e6fe | 2014-10-28 11:21:42 -0400 | [diff] [blame] | 37 | import android.text.TextUtils; |
John Spurlock | 8be53ea | 2015-05-29 12:04:21 -0400 | [diff] [blame] | 38 | import android.text.format.DateFormat; |
John Spurlock | 530052a | 2014-11-30 16:26:19 -0500 | [diff] [blame] | 39 | import android.util.ArraySet; |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 40 | import android.util.AttributeSet; |
John Spurlock | 856edeb | 2014-06-01 20:36:47 -0400 | [diff] [blame] | 41 | import android.util.Log; |
John Spurlock | 8f8ecd6 | 2014-08-27 17:46:03 -0400 | [diff] [blame] | 42 | import android.util.MathUtils; |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 43 | import android.view.LayoutInflater; |
| 44 | import android.view.View; |
John Spurlock | 3e07701 | 2014-11-29 13:22:21 -0500 | [diff] [blame] | 45 | import android.view.ViewGroup; |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 46 | import android.widget.CompoundButton; |
| 47 | import android.widget.CompoundButton.OnCheckedChangeListener; |
| 48 | import android.widget.ImageView; |
| 49 | import android.widget.LinearLayout; |
| 50 | import android.widget.RadioButton; |
| 51 | import android.widget.TextView; |
| 52 | |
Chris Wren | 9e7283f | 2015-05-08 17:23:47 -0400 | [diff] [blame] | 53 | import com.android.internal.logging.MetricsLogger; |
Chris Wren | f6e9228b | 2016-01-26 18:04:35 -0500 | [diff] [blame] | 54 | import com.android.internal.logging.MetricsProto.MetricsEvent; |
John Spurlock | f55b7f2 | 2015-04-13 19:21:26 -0400 | [diff] [blame] | 55 | import com.android.systemui.Prefs; |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 56 | import com.android.systemui.R; |
| 57 | import com.android.systemui.statusbar.policy.ZenModeController; |
| 58 | |
John Spurlock | 530052a | 2014-11-30 16:26:19 -0500 | [diff] [blame] | 59 | import java.io.FileDescriptor; |
| 60 | import java.io.PrintWriter; |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 61 | import java.util.Arrays; |
Julia Reynolds | 0842fe8 | 2015-10-01 14:34:22 -0400 | [diff] [blame] | 62 | import java.util.Calendar; |
| 63 | import java.util.GregorianCalendar; |
John Spurlock | 8be53ea | 2015-05-29 12:04:21 -0400 | [diff] [blame] | 64 | import java.util.Locale; |
John Spurlock | 856edeb | 2014-06-01 20:36:47 -0400 | [diff] [blame] | 65 | import java.util.Objects; |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 66 | |
| 67 | public class ZenModePanel extends LinearLayout { |
John Spurlock | ae641c9 | 2014-06-30 18:11:40 -0400 | [diff] [blame] | 68 | private static final String TAG = "ZenModePanel"; |
| 69 | private static final boolean DEBUG = Log.isLoggable(TAG, Log.DEBUG); |
John Spurlock | 856edeb | 2014-06-01 20:36:47 -0400 | [diff] [blame] | 70 | |
John Spurlock | 50806fc | 2014-07-15 10:22:02 -0400 | [diff] [blame] | 71 | private static final int SECONDS_MS = 1000; |
| 72 | private static final int MINUTES_MS = 60 * SECONDS_MS; |
| 73 | |
Julia Reynolds | 0ca82fe | 2015-11-05 11:08:02 -0500 | [diff] [blame] | 74 | private static final int[] MINUTE_BUCKETS = ZenModeConfig.MINUTE_BUCKETS; |
John Spurlock | 856edeb | 2014-06-01 20:36:47 -0400 | [diff] [blame] | 75 | private static final int MIN_BUCKET_MINUTES = MINUTE_BUCKETS[0]; |
| 76 | private static final int MAX_BUCKET_MINUTES = MINUTE_BUCKETS[MINUTE_BUCKETS.length - 1]; |
| 77 | private static final int DEFAULT_BUCKET_INDEX = Arrays.binarySearch(MINUTE_BUCKETS, 60); |
John Spurlock | ae641c9 | 2014-06-30 18:11:40 -0400 | [diff] [blame] | 78 | private static final int FOREVER_CONDITION_INDEX = 0; |
John Spurlock | 530052a | 2014-11-30 16:26:19 -0500 | [diff] [blame] | 79 | private static final int COUNTDOWN_CONDITION_INDEX = 1; |
Julia Reynolds | 0842fe8 | 2015-10-01 14:34:22 -0400 | [diff] [blame] | 80 | private static final int COUNTDOWN_ALARM_CONDITION_INDEX = 2; |
Julia Reynolds | 8e2d2bb | 2015-10-01 14:34:22 -0400 | [diff] [blame] | 81 | private static final int COUNTDOWN_CONDITION_COUNT = 2; |
John Spurlock | 856edeb | 2014-06-01 20:36:47 -0400 | [diff] [blame] | 82 | |
John Spurlock | f55b7f2 | 2015-04-13 19:21:26 -0400 | [diff] [blame] | 83 | public static final Intent ZEN_SETTINGS |
| 84 | = new Intent(Settings.ACTION_ZEN_MODE_SETTINGS); |
| 85 | public static final Intent ZEN_PRIORITY_SETTINGS |
| 86 | = new Intent(Settings.ACTION_ZEN_MODE_PRIORITY_SETTINGS); |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 87 | |
John Spurlock | 7f1df5e | 2014-05-31 19:11:40 -0400 | [diff] [blame] | 88 | private final Context mContext; |
Muyuan Li | 94fa1df | 2016-03-23 12:09:38 -0700 | [diff] [blame] | 89 | protected final LayoutInflater mInflater; |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 90 | private final H mHandler = new H(); |
John Spurlock | f55b7f2 | 2015-04-13 19:21:26 -0400 | [diff] [blame] | 91 | private final ZenPrefs mPrefs; |
John Spurlock | 530052a | 2014-11-30 16:26:19 -0500 | [diff] [blame] | 92 | private final TransitionHelper mTransitionHelper = new TransitionHelper(); |
John Spurlock | 0b68850 | 2014-12-22 15:13:30 -0500 | [diff] [blame] | 93 | private final Uri mForeverId; |
John Spurlock | d896323 | 2015-06-08 16:26:12 -0400 | [diff] [blame] | 94 | private final SpTexts mSpTexts; |
John Spurlock | 856edeb | 2014-06-01 20:36:47 -0400 | [diff] [blame] | 95 | |
John Spurlock | eb2727b | 2014-07-19 23:11:36 -0400 | [diff] [blame] | 96 | private String mTag = TAG + "/" + Integer.toHexString(System.identityHashCode(this)); |
John Spurlock | ae641c9 | 2014-06-30 18:11:40 -0400 | [diff] [blame] | 97 | |
Muyuan Li | 8303bd2 | 2016-03-23 20:08:26 -0700 | [diff] [blame] | 98 | protected SegmentedButtons mZenButtons; |
John Spurlock | f55b7f2 | 2015-04-13 19:21:26 -0400 | [diff] [blame] | 99 | private View mZenIntroduction; |
John Spurlock | d9c75db | 2015-04-28 11:19:13 -0400 | [diff] [blame] | 100 | private TextView mZenIntroductionMessage; |
John Spurlock | f55b7f2 | 2015-04-13 19:21:26 -0400 | [diff] [blame] | 101 | private View mZenIntroductionConfirm; |
John Spurlock | d896323 | 2015-06-08 16:26:12 -0400 | [diff] [blame] | 102 | private TextView mZenIntroductionCustomize; |
Muyuan Li | 94fa1df | 2016-03-23 12:09:38 -0700 | [diff] [blame] | 103 | protected LinearLayout mZenConditions; |
John Spurlock | 8be53ea | 2015-05-29 12:04:21 -0400 | [diff] [blame] | 104 | private TextView mZenAlarmWarning; |
John Spurlock | ae641c9 | 2014-06-30 18:11:40 -0400 | [diff] [blame] | 105 | |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 106 | private Callback mCallback; |
| 107 | private ZenModeController mController; |
John Spurlock | ad680d4 | 2015-01-30 15:48:15 -0500 | [diff] [blame] | 108 | private boolean mCountdownConditionSupported; |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 109 | private boolean mRequestingConditions; |
John Spurlock | 4db0d98 | 2014-08-13 09:19:03 -0400 | [diff] [blame] | 110 | private Condition mExitCondition; |
John Spurlock | 856edeb | 2014-06-01 20:36:47 -0400 | [diff] [blame] | 111 | private int mBucketIndex = -1; |
John Spurlock | ae641c9 | 2014-06-30 18:11:40 -0400 | [diff] [blame] | 112 | private boolean mExpanded; |
John Spurlock | 530052a | 2014-11-30 16:26:19 -0500 | [diff] [blame] | 113 | private boolean mHidden; |
John Spurlock | fbb3d6f | 2014-07-17 11:17:11 -0400 | [diff] [blame] | 114 | private int mSessionZen; |
John Spurlock | 8f8ecd6 | 2014-08-27 17:46:03 -0400 | [diff] [blame] | 115 | private int mAttachedZen; |
John Spurlock | 3e07701 | 2014-11-29 13:22:21 -0500 | [diff] [blame] | 116 | private boolean mAttached; |
John Spurlock | 4db0d98 | 2014-08-13 09:19:03 -0400 | [diff] [blame] | 117 | private Condition mSessionExitCondition; |
John Spurlock | 4db0d98 | 2014-08-13 09:19:03 -0400 | [diff] [blame] | 118 | private Condition[] mConditions; |
| 119 | private Condition mTimeCondition; |
Julia Reynolds | 0842fe8 | 2015-10-01 14:34:22 -0400 | [diff] [blame] | 120 | private Condition mTimeUntilAlarmCondition; |
John Spurlock | cbd7a31 | 2015-06-21 10:46:28 -0400 | [diff] [blame] | 121 | private boolean mVoiceCapable; |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 122 | |
| 123 | public ZenModePanel(Context context, AttributeSet attrs) { |
| 124 | super(context, attrs); |
John Spurlock | 7f1df5e | 2014-05-31 19:11:40 -0400 | [diff] [blame] | 125 | mContext = context; |
John Spurlock | f55b7f2 | 2015-04-13 19:21:26 -0400 | [diff] [blame] | 126 | mPrefs = new ZenPrefs(); |
John Spurlock | f7d2213 | 2014-07-10 19:03:00 -0400 | [diff] [blame] | 127 | mInflater = LayoutInflater.from(mContext.getApplicationContext()); |
John Spurlock | 0b68850 | 2014-12-22 15:13:30 -0500 | [diff] [blame] | 128 | mForeverId = Condition.newId(mContext).appendPath("forever").build(); |
John Spurlock | d896323 | 2015-06-08 16:26:12 -0400 | [diff] [blame] | 129 | mSpTexts = new SpTexts(mContext); |
John Spurlock | cbd7a31 | 2015-06-21 10:46:28 -0400 | [diff] [blame] | 130 | mVoiceCapable = Util.isVoiceCapable(mContext); |
John Spurlock | 856edeb | 2014-06-01 20:36:47 -0400 | [diff] [blame] | 131 | if (DEBUG) Log.d(mTag, "new ZenModePanel"); |
| 132 | } |
| 133 | |
John Spurlock | 530052a | 2014-11-30 16:26:19 -0500 | [diff] [blame] | 134 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 135 | pw.println("ZenModePanel state:"); |
| 136 | pw.print(" mCountdownConditionSupported="); pw.println(mCountdownConditionSupported); |
John Spurlock | 530052a | 2014-11-30 16:26:19 -0500 | [diff] [blame] | 137 | pw.print(" mRequestingConditions="); pw.println(mRequestingConditions); |
| 138 | pw.print(" mAttached="); pw.println(mAttached); |
| 139 | pw.print(" mHidden="); pw.println(mHidden); |
| 140 | pw.print(" mExpanded="); pw.println(mExpanded); |
| 141 | pw.print(" mSessionZen="); pw.println(mSessionZen); |
| 142 | pw.print(" mAttachedZen="); pw.println(mAttachedZen); |
John Spurlock | d9c75db | 2015-04-28 11:19:13 -0400 | [diff] [blame] | 143 | pw.print(" mConfirmedPriorityIntroduction="); |
| 144 | pw.println(mPrefs.mConfirmedPriorityIntroduction); |
| 145 | pw.print(" mConfirmedSilenceIntroduction="); |
| 146 | pw.println(mPrefs.mConfirmedSilenceIntroduction); |
John Spurlock | cbd7a31 | 2015-06-21 10:46:28 -0400 | [diff] [blame] | 147 | pw.print(" mVoiceCapable="); pw.println(mVoiceCapable); |
John Spurlock | 530052a | 2014-11-30 16:26:19 -0500 | [diff] [blame] | 148 | mTransitionHelper.dump(fd, pw, args); |
| 149 | } |
| 150 | |
Muyuan Li | 8303bd2 | 2016-03-23 20:08:26 -0700 | [diff] [blame] | 151 | protected void createZenButtons() { |
John Spurlock | ae641c9 | 2014-06-30 18:11:40 -0400 | [diff] [blame] | 152 | mZenButtons = (SegmentedButtons) findViewById(R.id.zen_buttons); |
John Spurlock | 4f1163c | 2015-04-02 17:41:21 -0400 | [diff] [blame] | 153 | mZenButtons.addButton(R.string.interruption_level_none_twoline, |
John Spurlock | bd1abe6 | 2015-06-10 17:18:38 -0400 | [diff] [blame] | 154 | R.string.interruption_level_none_with_warning, |
John Spurlock | 4f1163c | 2015-04-02 17:41:21 -0400 | [diff] [blame] | 155 | Global.ZEN_MODE_NO_INTERRUPTIONS); |
| 156 | mZenButtons.addButton(R.string.interruption_level_alarms_twoline, |
John Spurlock | a1c7ffe | 2015-06-08 15:34:05 -0400 | [diff] [blame] | 157 | R.string.interruption_level_alarms, |
John Spurlock | 4f1163c | 2015-04-02 17:41:21 -0400 | [diff] [blame] | 158 | Global.ZEN_MODE_ALARMS); |
| 159 | mZenButtons.addButton(R.string.interruption_level_priority_twoline, |
John Spurlock | a1c7ffe | 2015-06-08 15:34:05 -0400 | [diff] [blame] | 160 | R.string.interruption_level_priority, |
John Spurlock | 4291fb7 | 2014-09-16 17:02:23 -0400 | [diff] [blame] | 161 | Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS); |
John Spurlock | ae641c9 | 2014-06-30 18:11:40 -0400 | [diff] [blame] | 162 | mZenButtons.setCallback(mZenButtonsCallback); |
Muyuan Li | 8303bd2 | 2016-03-23 20:08:26 -0700 | [diff] [blame] | 163 | } |
John Spurlock | ae641c9 | 2014-06-30 18:11:40 -0400 | [diff] [blame] | 164 | |
Muyuan Li | 8303bd2 | 2016-03-23 20:08:26 -0700 | [diff] [blame] | 165 | @Override |
| 166 | protected void onFinishInflate() { |
| 167 | super.onFinishInflate(); |
| 168 | createZenButtons(); |
John Spurlock | f55b7f2 | 2015-04-13 19:21:26 -0400 | [diff] [blame] | 169 | mZenIntroduction = findViewById(R.id.zen_introduction); |
John Spurlock | d9c75db | 2015-04-28 11:19:13 -0400 | [diff] [blame] | 170 | mZenIntroductionMessage = (TextView) findViewById(R.id.zen_introduction_message); |
John Spurlock | d896323 | 2015-06-08 16:26:12 -0400 | [diff] [blame] | 171 | mSpTexts.add(mZenIntroductionMessage); |
John Spurlock | f55b7f2 | 2015-04-13 19:21:26 -0400 | [diff] [blame] | 172 | mZenIntroductionConfirm = findViewById(R.id.zen_introduction_confirm); |
| 173 | mZenIntroductionConfirm.setOnClickListener(new OnClickListener() { |
| 174 | @Override |
| 175 | public void onClick(View v) { |
| 176 | confirmZenIntroduction(); |
| 177 | } |
| 178 | }); |
John Spurlock | d896323 | 2015-06-08 16:26:12 -0400 | [diff] [blame] | 179 | mZenIntroductionCustomize = (TextView) findViewById(R.id.zen_introduction_customize); |
John Spurlock | f55b7f2 | 2015-04-13 19:21:26 -0400 | [diff] [blame] | 180 | mZenIntroductionCustomize.setOnClickListener(new OnClickListener() { |
| 181 | @Override |
| 182 | public void onClick(View v) { |
| 183 | confirmZenIntroduction(); |
| 184 | if (mCallback != null) { |
| 185 | mCallback.onPrioritySettings(); |
| 186 | } |
| 187 | } |
| 188 | }); |
John Spurlock | d896323 | 2015-06-08 16:26:12 -0400 | [diff] [blame] | 189 | mSpTexts.add(mZenIntroductionCustomize); |
John Spurlock | f55b7f2 | 2015-04-13 19:21:26 -0400 | [diff] [blame] | 190 | |
John Spurlock | ae641c9 | 2014-06-30 18:11:40 -0400 | [diff] [blame] | 191 | mZenConditions = (LinearLayout) findViewById(R.id.zen_conditions); |
John Spurlock | 8be53ea | 2015-05-29 12:04:21 -0400 | [diff] [blame] | 192 | mZenAlarmWarning = (TextView) findViewById(R.id.zen_alarm_warning); |
John Spurlock | 814ee6ab | 2015-05-18 11:16:38 -0400 | [diff] [blame] | 193 | } |
John Spurlock | 530052a | 2014-11-30 16:26:19 -0500 | [diff] [blame] | 194 | |
John Spurlock | 814ee6ab | 2015-05-18 11:16:38 -0400 | [diff] [blame] | 195 | @Override |
| 196 | protected void onConfigurationChanged(Configuration newConfig) { |
| 197 | super.onConfigurationChanged(newConfig); |
| 198 | if (mZenButtons != null) { |
| 199 | mZenButtons.updateLocale(); |
| 200 | } |
John Spurlock | 3e07701 | 2014-11-29 13:22:21 -0500 | [diff] [blame] | 201 | } |
| 202 | |
John Spurlock | f55b7f2 | 2015-04-13 19:21:26 -0400 | [diff] [blame] | 203 | private void confirmZenIntroduction() { |
John Spurlock | d9c75db | 2015-04-28 11:19:13 -0400 | [diff] [blame] | 204 | final String prefKey = prefKeyForConfirmation(getSelectedZen(Global.ZEN_MODE_OFF)); |
| 205 | if (prefKey == null) return; |
| 206 | if (DEBUG) Log.d(TAG, "confirmZenIntroduction " + prefKey); |
| 207 | Prefs.putBoolean(mContext, prefKey, true); |
John Spurlock | f55b7f2 | 2015-04-13 19:21:26 -0400 | [diff] [blame] | 208 | mHandler.sendEmptyMessage(H.UPDATE_WIDGETS); |
| 209 | } |
| 210 | |
John Spurlock | d9c75db | 2015-04-28 11:19:13 -0400 | [diff] [blame] | 211 | private static String prefKeyForConfirmation(int zen) { |
| 212 | switch (zen) { |
| 213 | case Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS: |
| 214 | return Prefs.Key.DND_CONFIRMED_PRIORITY_INTRODUCTION; |
| 215 | case Global.ZEN_MODE_NO_INTERRUPTIONS: |
| 216 | return Prefs.Key.DND_CONFIRMED_SILENCE_INTRODUCTION; |
| 217 | default: |
| 218 | return null; |
John Spurlock | 530052a | 2014-11-30 16:26:19 -0500 | [diff] [blame] | 219 | } |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | @Override |
John Spurlock | 856edeb | 2014-06-01 20:36:47 -0400 | [diff] [blame] | 223 | protected void onAttachedToWindow() { |
| 224 | super.onAttachedToWindow(); |
| 225 | if (DEBUG) Log.d(mTag, "onAttachedToWindow"); |
John Spurlock | 3e07701 | 2014-11-29 13:22:21 -0500 | [diff] [blame] | 226 | mAttached = true; |
John Spurlock | 8f8ecd6 | 2014-08-27 17:46:03 -0400 | [diff] [blame] | 227 | mAttachedZen = getSelectedZen(-1); |
| 228 | mSessionZen = mAttachedZen; |
John Spurlock | 530052a | 2014-11-30 16:26:19 -0500 | [diff] [blame] | 229 | mTransitionHelper.clear(); |
| 230 | setSessionExitCondition(copy(mExitCondition)); |
John Spurlock | 50806fc | 2014-07-15 10:22:02 -0400 | [diff] [blame] | 231 | updateWidgets(); |
John Spurlock | 3e07701 | 2014-11-29 13:22:21 -0500 | [diff] [blame] | 232 | setRequestingConditions(!mHidden); |
John Spurlock | 856edeb | 2014-06-01 20:36:47 -0400 | [diff] [blame] | 233 | } |
| 234 | |
| 235 | @Override |
| 236 | protected void onDetachedFromWindow() { |
| 237 | super.onDetachedFromWindow(); |
| 238 | if (DEBUG) Log.d(mTag, "onDetachedFromWindow"); |
John Spurlock | 8f8ecd6 | 2014-08-27 17:46:03 -0400 | [diff] [blame] | 239 | checkForAttachedZenChange(); |
John Spurlock | 3e07701 | 2014-11-29 13:22:21 -0500 | [diff] [blame] | 240 | mAttached = false; |
John Spurlock | 8f8ecd6 | 2014-08-27 17:46:03 -0400 | [diff] [blame] | 241 | mAttachedZen = -1; |
John Spurlock | fbb3d6f | 2014-07-17 11:17:11 -0400 | [diff] [blame] | 242 | mSessionZen = -1; |
John Spurlock | 530052a | 2014-11-30 16:26:19 -0500 | [diff] [blame] | 243 | setSessionExitCondition(null); |
John Spurlock | 3e07701 | 2014-11-29 13:22:21 -0500 | [diff] [blame] | 244 | setRequestingConditions(false); |
John Spurlock | 530052a | 2014-11-30 16:26:19 -0500 | [diff] [blame] | 245 | mTransitionHelper.clear(); |
| 246 | } |
| 247 | |
| 248 | private void setSessionExitCondition(Condition condition) { |
| 249 | if (Objects.equals(condition, mSessionExitCondition)) return; |
| 250 | if (DEBUG) Log.d(mTag, "mSessionExitCondition=" + getConditionId(condition)); |
| 251 | mSessionExitCondition = condition; |
John Spurlock | 856edeb | 2014-06-01 20:36:47 -0400 | [diff] [blame] | 252 | } |
| 253 | |
John Spurlock | eb2727b | 2014-07-19 23:11:36 -0400 | [diff] [blame] | 254 | public void setHidden(boolean hidden) { |
| 255 | if (mHidden == hidden) return; |
John Spurlock | 3e07701 | 2014-11-29 13:22:21 -0500 | [diff] [blame] | 256 | if (DEBUG) Log.d(mTag, "hidden=" + hidden); |
John Spurlock | eb2727b | 2014-07-19 23:11:36 -0400 | [diff] [blame] | 257 | mHidden = hidden; |
John Spurlock | 3e07701 | 2014-11-29 13:22:21 -0500 | [diff] [blame] | 258 | setRequestingConditions(mAttached && !mHidden); |
John Spurlock | eb2727b | 2014-07-19 23:11:36 -0400 | [diff] [blame] | 259 | updateWidgets(); |
| 260 | } |
| 261 | |
John Spurlock | 8f8ecd6 | 2014-08-27 17:46:03 -0400 | [diff] [blame] | 262 | private void checkForAttachedZenChange() { |
| 263 | final int selectedZen = getSelectedZen(-1); |
| 264 | if (DEBUG) Log.d(mTag, "selectedZen=" + selectedZen); |
| 265 | if (selectedZen != mAttachedZen) { |
| 266 | if (DEBUG) Log.d(mTag, "attachedZen: " + mAttachedZen + " -> " + selectedZen); |
| 267 | if (selectedZen == Global.ZEN_MODE_NO_INTERRUPTIONS) { |
| 268 | mPrefs.trackNoneSelected(); |
| 269 | } |
| 270 | } |
| 271 | } |
| 272 | |
John Spurlock | ae641c9 | 2014-06-30 18:11:40 -0400 | [diff] [blame] | 273 | private void setExpanded(boolean expanded) { |
| 274 | if (expanded == mExpanded) return; |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 275 | if (DEBUG) Log.d(mTag, "setExpanded " + expanded); |
John Spurlock | ae641c9 | 2014-06-30 18:11:40 -0400 | [diff] [blame] | 276 | mExpanded = expanded; |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 277 | if (mExpanded && isShown()) { |
John Spurlock | 3e07701 | 2014-11-29 13:22:21 -0500 | [diff] [blame] | 278 | ensureSelection(); |
| 279 | } |
John Spurlock | ae641c9 | 2014-06-30 18:11:40 -0400 | [diff] [blame] | 280 | updateWidgets(); |
John Spurlock | ae641c9 | 2014-06-30 18:11:40 -0400 | [diff] [blame] | 281 | fireExpanded(); |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 282 | } |
| 283 | |
| 284 | /** Start or stop requesting relevant zen mode exit conditions */ |
John Spurlock | 530052a | 2014-11-30 16:26:19 -0500 | [diff] [blame] | 285 | private void setRequestingConditions(final boolean requesting) { |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 286 | if (mRequestingConditions == requesting) return; |
John Spurlock | 856edeb | 2014-06-01 20:36:47 -0400 | [diff] [blame] | 287 | if (DEBUG) Log.d(mTag, "setRequestingConditions " + requesting); |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 288 | mRequestingConditions = requesting; |
John Spurlock | 856edeb | 2014-06-01 20:36:47 -0400 | [diff] [blame] | 289 | if (mRequestingConditions) { |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 290 | mTimeCondition = parseExistingTimeCondition(mContext, mExitCondition); |
John Spurlock | 4db0d98 | 2014-08-13 09:19:03 -0400 | [diff] [blame] | 291 | if (mTimeCondition != null) { |
John Spurlock | 856edeb | 2014-06-01 20:36:47 -0400 | [diff] [blame] | 292 | mBucketIndex = -1; |
| 293 | } else { |
| 294 | mBucketIndex = DEFAULT_BUCKET_INDEX; |
John Spurlock | c90e6fe | 2014-10-28 11:21:42 -0400 | [diff] [blame] | 295 | mTimeCondition = ZenModeConfig.toTimeCondition(mContext, |
Selim Cinek | 9c4a707 | 2014-11-21 17:44:34 +0100 | [diff] [blame] | 296 | MINUTE_BUCKETS[mBucketIndex], ActivityManager.getCurrentUser()); |
John Spurlock | 856edeb | 2014-06-01 20:36:47 -0400 | [diff] [blame] | 297 | } |
| 298 | if (DEBUG) Log.d(mTag, "Initial bucket index: " + mBucketIndex); |
Julia Reynolds | 0842fe8 | 2015-10-01 14:34:22 -0400 | [diff] [blame] | 299 | |
John Spurlock | 4db0d98 | 2014-08-13 09:19:03 -0400 | [diff] [blame] | 300 | mConditions = null; // reset conditions |
| 301 | handleUpdateConditions(); |
John Spurlock | 856edeb | 2014-06-01 20:36:47 -0400 | [diff] [blame] | 302 | } else { |
John Spurlock | 530052a | 2014-11-30 16:26:19 -0500 | [diff] [blame] | 303 | hideAllConditions(); |
John Spurlock | 856edeb | 2014-06-01 20:36:47 -0400 | [diff] [blame] | 304 | } |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 305 | } |
| 306 | |
Muyuan Li | 94fa1df | 2016-03-23 12:09:38 -0700 | [diff] [blame] | 307 | protected void addZenConditions(int count) { |
| 308 | for (int i = 0; i < count; i++) { |
| 309 | mZenConditions.addView(mInflater.inflate(R.layout.zen_mode_condition, this, false)); |
| 310 | } |
| 311 | } |
| 312 | |
John Spurlock | eb2727b | 2014-07-19 23:11:36 -0400 | [diff] [blame] | 313 | public void init(ZenModeController controller) { |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 314 | mController = controller; |
John Spurlock | ad680d4 | 2015-01-30 15:48:15 -0500 | [diff] [blame] | 315 | mCountdownConditionSupported = mController.isCountdownConditionSupported(); |
Julia Reynolds | 8e2d2bb | 2015-10-01 14:34:22 -0400 | [diff] [blame] | 316 | final int countdownDelta = mCountdownConditionSupported ? COUNTDOWN_CONDITION_COUNT : 0; |
John Spurlock | ad680d4 | 2015-01-30 15:48:15 -0500 | [diff] [blame] | 317 | final int minConditions = 1 /*forever*/ + countdownDelta; |
Muyuan Li | 94fa1df | 2016-03-23 12:09:38 -0700 | [diff] [blame] | 318 | addZenConditions(minConditions); |
John Spurlock | fbb3d6f | 2014-07-17 11:17:11 -0400 | [diff] [blame] | 319 | mSessionZen = getSelectedZen(-1); |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 320 | handleUpdateManualRule(mController.getManualRule()); |
John Spurlock | 4db0d98 | 2014-08-13 09:19:03 -0400 | [diff] [blame] | 321 | if (DEBUG) Log.d(mTag, "init mExitCondition=" + mExitCondition); |
John Spurlock | 530052a | 2014-11-30 16:26:19 -0500 | [diff] [blame] | 322 | hideAllConditions(); |
John Spurlock | 856edeb | 2014-06-01 20:36:47 -0400 | [diff] [blame] | 323 | mController.addCallback(mZenCallback); |
John Spurlock | ae641c9 | 2014-06-30 18:11:40 -0400 | [diff] [blame] | 324 | } |
| 325 | |
Jason Monk | e2f4771 | 2014-09-09 09:35:55 -0400 | [diff] [blame] | 326 | public void updateLocale() { |
John Spurlock | 4291fb7 | 2014-09-16 17:02:23 -0400 | [diff] [blame] | 327 | mZenButtons.updateLocale(); |
Jason Monk | e2f4771 | 2014-09-09 09:35:55 -0400 | [diff] [blame] | 328 | } |
| 329 | |
John Spurlock | 4db0d98 | 2014-08-13 09:19:03 -0400 | [diff] [blame] | 330 | private void setExitCondition(Condition exitCondition) { |
John Spurlock | 25c3421 | 2014-11-12 09:16:49 -0500 | [diff] [blame] | 331 | if (Objects.equals(mExitCondition, exitCondition)) return; |
John Spurlock | 4db0d98 | 2014-08-13 09:19:03 -0400 | [diff] [blame] | 332 | mExitCondition = exitCondition; |
John Spurlock | 530052a | 2014-11-30 16:26:19 -0500 | [diff] [blame] | 333 | if (DEBUG) Log.d(mTag, "mExitCondition=" + getConditionId(mExitCondition)); |
John Spurlock | 89f060a | 2014-07-16 21:03:15 -0400 | [diff] [blame] | 334 | updateWidgets(); |
John Spurlock | ae641c9 | 2014-06-30 18:11:40 -0400 | [diff] [blame] | 335 | } |
| 336 | |
John Spurlock | 4db0d98 | 2014-08-13 09:19:03 -0400 | [diff] [blame] | 337 | private static Uri getConditionId(Condition condition) { |
| 338 | return condition != null ? condition.id : null; |
| 339 | } |
| 340 | |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 341 | private Uri getRealConditionId(Condition condition) { |
| 342 | return isForever(condition) ? null : getConditionId(condition); |
| 343 | } |
| 344 | |
John Spurlock | 4db0d98 | 2014-08-13 09:19:03 -0400 | [diff] [blame] | 345 | private static boolean sameConditionId(Condition lhs, Condition rhs) { |
| 346 | return lhs == null ? rhs == null : rhs != null && lhs.id.equals(rhs.id); |
| 347 | } |
| 348 | |
| 349 | private static Condition copy(Condition condition) { |
| 350 | return condition == null ? null : condition.copy(); |
| 351 | } |
| 352 | |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 353 | public void setCallback(Callback callback) { |
| 354 | mCallback = callback; |
| 355 | } |
| 356 | |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 357 | private void handleUpdateManualRule(ZenRule rule) { |
| 358 | final int zen = rule != null ? rule.zenMode : Global.ZEN_MODE_OFF; |
| 359 | handleUpdateZen(zen); |
| 360 | final Condition c = rule != null ? rule.condition : null; |
| 361 | handleExitConditionChanged(c); |
| 362 | } |
| 363 | |
John Spurlock | ae641c9 | 2014-06-30 18:11:40 -0400 | [diff] [blame] | 364 | private void handleUpdateZen(int zen) { |
John Spurlock | fbb3d6f | 2014-07-17 11:17:11 -0400 | [diff] [blame] | 365 | if (mSessionZen != -1 && mSessionZen != zen) { |
John Spurlock | d9c75db | 2015-04-28 11:19:13 -0400 | [diff] [blame] | 366 | setExpanded(isShown()); |
John Spurlock | fbb3d6f | 2014-07-17 11:17:11 -0400 | [diff] [blame] | 367 | mSessionZen = zen; |
John Spurlock | ae641c9 | 2014-06-30 18:11:40 -0400 | [diff] [blame] | 368 | } |
Chris Wren | 4572cbc | 2015-06-29 11:27:18 -0400 | [diff] [blame] | 369 | mZenButtons.setSelectedValue(zen, false /* fromClick */); |
John Spurlock | ae641c9 | 2014-06-30 18:11:40 -0400 | [diff] [blame] | 370 | updateWidgets(); |
John Spurlock | 530052a | 2014-11-30 16:26:19 -0500 | [diff] [blame] | 371 | handleUpdateConditions(); |
| 372 | if (mExpanded) { |
| 373 | final Condition selected = getSelectedCondition(); |
| 374 | if (!Objects.equals(mExitCondition, selected)) { |
| 375 | select(selected); |
| 376 | } |
| 377 | } |
| 378 | } |
| 379 | |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 380 | private void handleExitConditionChanged(Condition exitCondition) { |
| 381 | setExitCondition(exitCondition); |
| 382 | if (DEBUG) Log.d(mTag, "handleExitConditionChanged " + mExitCondition); |
| 383 | final int N = getVisibleConditions(); |
| 384 | for (int i = 0; i < N; i++) { |
| 385 | final ConditionTag tag = getConditionTagAt(i); |
| 386 | if (tag != null) { |
| 387 | if (sameConditionId(tag.condition, mExitCondition)) { |
Julia Reynolds | 0842fe8 | 2015-10-01 14:34:22 -0400 | [diff] [blame] | 388 | bind(exitCondition, mZenConditions.getChildAt(i), i); |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 389 | } |
| 390 | } |
| 391 | } |
| 392 | } |
| 393 | |
John Spurlock | 530052a | 2014-11-30 16:26:19 -0500 | [diff] [blame] | 394 | private Condition getSelectedCondition() { |
| 395 | final int N = getVisibleConditions(); |
| 396 | for (int i = 0; i < N; i++) { |
| 397 | final ConditionTag tag = getConditionTagAt(i); |
| 398 | if (tag != null && tag.rb.isChecked()) { |
| 399 | return tag.condition; |
| 400 | } |
| 401 | } |
| 402 | return null; |
John Spurlock | ae641c9 | 2014-06-30 18:11:40 -0400 | [diff] [blame] | 403 | } |
| 404 | |
| 405 | private int getSelectedZen(int defValue) { |
| 406 | final Object zen = mZenButtons.getSelectedValue(); |
| 407 | return zen != null ? (Integer) zen : defValue; |
| 408 | } |
| 409 | |
| 410 | private void updateWidgets() { |
John Spurlock | 530052a | 2014-11-30 16:26:19 -0500 | [diff] [blame] | 411 | if (mTransitionHelper.isTransitioning()) { |
| 412 | mTransitionHelper.pendingUpdateWidgets(); |
| 413 | return; |
| 414 | } |
John Spurlock | ae641c9 | 2014-06-30 18:11:40 -0400 | [diff] [blame] | 415 | final int zen = getSelectedZen(Global.ZEN_MODE_OFF); |
John Spurlock | ae641c9 | 2014-06-30 18:11:40 -0400 | [diff] [blame] | 416 | final boolean zenImportant = zen == Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS; |
| 417 | final boolean zenNone = zen == Global.ZEN_MODE_NO_INTERRUPTIONS; |
John Spurlock | d9c75db | 2015-04-28 11:19:13 -0400 | [diff] [blame] | 418 | final boolean introduction = (zenImportant && !mPrefs.mConfirmedPriorityIntroduction |
| 419 | || zenNone && !mPrefs.mConfirmedSilenceIntroduction); |
John Spurlock | ae641c9 | 2014-06-30 18:11:40 -0400 | [diff] [blame] | 420 | |
John Spurlock | eb2727b | 2014-07-19 23:11:36 -0400 | [diff] [blame] | 421 | mZenButtons.setVisibility(mHidden ? GONE : VISIBLE); |
John Spurlock | f55b7f2 | 2015-04-13 19:21:26 -0400 | [diff] [blame] | 422 | mZenIntroduction.setVisibility(introduction ? VISIBLE : GONE); |
John Spurlock | d9c75db | 2015-04-28 11:19:13 -0400 | [diff] [blame] | 423 | if (introduction) { |
| 424 | mZenIntroductionMessage.setText(zenImportant ? R.string.zen_priority_introduction |
John Spurlock | cbd7a31 | 2015-06-21 10:46:28 -0400 | [diff] [blame] | 425 | : mVoiceCapable ? R.string.zen_silence_introduction_voice |
John Spurlock | d9c75db | 2015-04-28 11:19:13 -0400 | [diff] [blame] | 426 | : R.string.zen_silence_introduction); |
| 427 | mZenIntroductionCustomize.setVisibility(zenImportant ? VISIBLE : GONE); |
| 428 | } |
John Spurlock | 8be53ea | 2015-05-29 12:04:21 -0400 | [diff] [blame] | 429 | final String warning = computeAlarmWarningText(zenNone); |
| 430 | mZenAlarmWarning.setVisibility(warning != null ? VISIBLE : GONE); |
| 431 | mZenAlarmWarning.setText(warning); |
| 432 | } |
| 433 | |
| 434 | private String computeAlarmWarningText(boolean zenNone) { |
| 435 | if (!zenNone) { |
| 436 | return null; |
| 437 | } |
| 438 | final long now = System.currentTimeMillis(); |
| 439 | final long nextAlarm = mController.getNextAlarm(); |
| 440 | if (nextAlarm < now) { |
| 441 | return null; |
| 442 | } |
| 443 | int warningRes = 0; |
| 444 | if (mSessionExitCondition == null || isForever(mSessionExitCondition)) { |
| 445 | warningRes = R.string.zen_alarm_warning_indef; |
| 446 | } else { |
| 447 | final long time = ZenModeConfig.tryParseCountdownConditionId(mSessionExitCondition.id); |
| 448 | if (time > now && nextAlarm < time) { |
| 449 | warningRes = R.string.zen_alarm_warning; |
| 450 | } |
| 451 | } |
| 452 | if (warningRes == 0) { |
| 453 | return null; |
| 454 | } |
| 455 | final boolean soon = (nextAlarm - now) < 24 * 60 * 60 * 1000; |
| 456 | final boolean is24 = DateFormat.is24HourFormat(mContext, ActivityManager.getCurrentUser()); |
| 457 | final String skeleton = soon ? (is24 ? "Hm" : "hma") : (is24 ? "EEEHm" : "EEEhma"); |
| 458 | final String pattern = DateFormat.getBestDateTimePattern(Locale.getDefault(), skeleton); |
| 459 | final CharSequence formattedTime = DateFormat.format(pattern, nextAlarm); |
| 460 | final int templateRes = soon ? R.string.alarm_template : R.string.alarm_template_far; |
| 461 | final String template = getResources().getString(templateRes, formattedTime); |
| 462 | return getResources().getString(warningRes, template); |
John Spurlock | 89f060a | 2014-07-16 21:03:15 -0400 | [diff] [blame] | 463 | } |
| 464 | |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 465 | private static Condition parseExistingTimeCondition(Context context, Condition condition) { |
John Spurlock | 4db0d98 | 2014-08-13 09:19:03 -0400 | [diff] [blame] | 466 | if (condition == null) return null; |
| 467 | final long time = ZenModeConfig.tryParseCountdownConditionId(condition.id); |
John Spurlock | 856edeb | 2014-06-01 20:36:47 -0400 | [diff] [blame] | 468 | if (time == 0) return null; |
John Spurlock | c90e6fe | 2014-10-28 11:21:42 -0400 | [diff] [blame] | 469 | final long now = System.currentTimeMillis(); |
| 470 | final long span = time - now; |
John Spurlock | 856edeb | 2014-06-01 20:36:47 -0400 | [diff] [blame] | 471 | if (span <= 0 || span > MAX_BUCKET_MINUTES * MINUTES_MS) return null; |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 472 | return ZenModeConfig.toTimeCondition(context, |
Julia Reynolds | 0842fe8 | 2015-10-01 14:34:22 -0400 | [diff] [blame] | 473 | time, Math.round(span / (float) MINUTES_MS), ActivityManager.getCurrentUser(), |
John Spurlock | bbde267 | 2015-05-13 15:42:04 -0400 | [diff] [blame] | 474 | false /*shortVersion*/); |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 475 | } |
| 476 | |
John Spurlock | 4db0d98 | 2014-08-13 09:19:03 -0400 | [diff] [blame] | 477 | private void handleUpdateConditions() { |
John Spurlock | 530052a | 2014-11-30 16:26:19 -0500 | [diff] [blame] | 478 | if (mTransitionHelper.isTransitioning()) { |
John Spurlock | 530052a | 2014-11-30 16:26:19 -0500 | [diff] [blame] | 479 | return; |
| 480 | } |
John Spurlock | 4db0d98 | 2014-08-13 09:19:03 -0400 | [diff] [blame] | 481 | final int conditionCount = mConditions == null ? 0 : mConditions.length; |
| 482 | if (DEBUG) Log.d(mTag, "handleUpdateConditions conditionCount=" + conditionCount); |
John Spurlock | 4db0d98 | 2014-08-13 09:19:03 -0400 | [diff] [blame] | 483 | // forever |
Julia Reynolds | 0842fe8 | 2015-10-01 14:34:22 -0400 | [diff] [blame] | 484 | bind(forever(), mZenConditions.getChildAt(FOREVER_CONDITION_INDEX), |
| 485 | FOREVER_CONDITION_INDEX); |
John Spurlock | 4db0d98 | 2014-08-13 09:19:03 -0400 | [diff] [blame] | 486 | // countdown |
John Spurlock | 0b68850 | 2014-12-22 15:13:30 -0500 | [diff] [blame] | 487 | if (mCountdownConditionSupported && mTimeCondition != null) { |
Julia Reynolds | 0842fe8 | 2015-10-01 14:34:22 -0400 | [diff] [blame] | 488 | bind(mTimeCondition, mZenConditions.getChildAt(COUNTDOWN_CONDITION_INDEX), |
| 489 | COUNTDOWN_CONDITION_INDEX); |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 490 | } |
Julia Reynolds | 0842fe8 | 2015-10-01 14:34:22 -0400 | [diff] [blame] | 491 | // countdown until alarm |
Julia Reynolds | 8e2d2bb | 2015-10-01 14:34:22 -0400 | [diff] [blame] | 492 | if (mCountdownConditionSupported) { |
| 493 | Condition nextAlarmCondition = getTimeUntilNextAlarmCondition(); |
| 494 | if (nextAlarmCondition != null) { |
| 495 | bind(nextAlarmCondition, |
| 496 | mZenConditions.getChildAt(COUNTDOWN_ALARM_CONDITION_INDEX), |
| 497 | COUNTDOWN_ALARM_CONDITION_INDEX); |
| 498 | } |
John Spurlock | 4db0d98 | 2014-08-13 09:19:03 -0400 | [diff] [blame] | 499 | } |
John Spurlock | 3e07701 | 2014-11-29 13:22:21 -0500 | [diff] [blame] | 500 | // ensure something is selected |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 501 | if (mExpanded && isShown()) { |
John Spurlock | 3e07701 | 2014-11-29 13:22:21 -0500 | [diff] [blame] | 502 | ensureSelection(); |
| 503 | } |
Jason Monk | e138f55 | 2016-01-18 09:21:45 -0500 | [diff] [blame] | 504 | mZenConditions.setVisibility(mSessionZen != Global.ZEN_MODE_OFF ? View.VISIBLE : View.GONE); |
John Spurlock | 4db0d98 | 2014-08-13 09:19:03 -0400 | [diff] [blame] | 505 | } |
| 506 | |
John Spurlock | 0b68850 | 2014-12-22 15:13:30 -0500 | [diff] [blame] | 507 | private Condition forever() { |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 508 | return new Condition(mForeverId, foreverSummary(mContext), "", "", 0 /*icon*/, |
| 509 | Condition.STATE_TRUE, 0 /*flags*/); |
John Spurlock | 0b68850 | 2014-12-22 15:13:30 -0500 | [diff] [blame] | 510 | } |
| 511 | |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 512 | private static String foreverSummary(Context context) { |
| 513 | return context.getString(com.android.internal.R.string.zen_mode_forever); |
John Spurlock | 0b68850 | 2014-12-22 15:13:30 -0500 | [diff] [blame] | 514 | } |
| 515 | |
Julia Reynolds | 0842fe8 | 2015-10-01 14:34:22 -0400 | [diff] [blame] | 516 | // Returns a time condition if the next alarm is within the next week. |
| 517 | private Condition getTimeUntilNextAlarmCondition() { |
| 518 | GregorianCalendar weekRange = new GregorianCalendar(); |
| 519 | final long now = weekRange.getTimeInMillis(); |
| 520 | setToMidnight(weekRange); |
Dan Sandler | 12d3393 | 2015-12-29 15:45:39 -0500 | [diff] [blame] | 521 | weekRange.add(Calendar.DATE, 6); |
Julia Reynolds | 0842fe8 | 2015-10-01 14:34:22 -0400 | [diff] [blame] | 522 | final long nextAlarmMs = mController.getNextAlarm(); |
| 523 | if (nextAlarmMs > 0) { |
| 524 | GregorianCalendar nextAlarm = new GregorianCalendar(); |
| 525 | nextAlarm.setTimeInMillis(nextAlarmMs); |
| 526 | setToMidnight(nextAlarm); |
| 527 | |
| 528 | if (weekRange.compareTo(nextAlarm) >= 0) { |
Julia Reynolds | 1998ee5 | 2016-02-11 13:49:08 -0500 | [diff] [blame] | 529 | return ZenModeConfig.toNextAlarmCondition(mContext, now, |
| 530 | nextAlarmMs, ActivityManager.getCurrentUser()); |
Julia Reynolds | 0842fe8 | 2015-10-01 14:34:22 -0400 | [diff] [blame] | 531 | } |
| 532 | } |
| 533 | return null; |
| 534 | } |
| 535 | |
| 536 | private void setToMidnight(Calendar calendar) { |
| 537 | calendar.set(Calendar.HOUR_OF_DAY, 0); |
| 538 | calendar.set(Calendar.MINUTE, 0); |
| 539 | calendar.set(Calendar.SECOND, 0); |
| 540 | calendar.set(Calendar.MILLISECOND, 0); |
| 541 | } |
| 542 | |
John Spurlock | 856edeb | 2014-06-01 20:36:47 -0400 | [diff] [blame] | 543 | private ConditionTag getConditionTagAt(int index) { |
John Spurlock | ae641c9 | 2014-06-30 18:11:40 -0400 | [diff] [blame] | 544 | return (ConditionTag) mZenConditions.getChildAt(index).getTag(); |
John Spurlock | 856edeb | 2014-06-01 20:36:47 -0400 | [diff] [blame] | 545 | } |
| 546 | |
John Spurlock | 530052a | 2014-11-30 16:26:19 -0500 | [diff] [blame] | 547 | private int getVisibleConditions() { |
| 548 | int rt = 0; |
| 549 | final int N = mZenConditions.getChildCount(); |
| 550 | for (int i = 0; i < N; i++) { |
| 551 | rt += mZenConditions.getChildAt(i).getVisibility() == VISIBLE ? 1 : 0; |
| 552 | } |
| 553 | return rt; |
| 554 | } |
| 555 | |
| 556 | private void hideAllConditions() { |
| 557 | final int N = mZenConditions.getChildCount(); |
| 558 | for (int i = 0; i < N; i++) { |
| 559 | mZenConditions.getChildAt(i).setVisibility(GONE); |
| 560 | } |
| 561 | } |
| 562 | |
John Spurlock | 3e07701 | 2014-11-29 13:22:21 -0500 | [diff] [blame] | 563 | private void ensureSelection() { |
John Spurlock | 856edeb | 2014-06-01 20:36:47 -0400 | [diff] [blame] | 564 | // are we left without anything selected? if so, set a default |
John Spurlock | 530052a | 2014-11-30 16:26:19 -0500 | [diff] [blame] | 565 | final int visibleConditions = getVisibleConditions(); |
| 566 | if (visibleConditions == 0) return; |
| 567 | for (int i = 0; i < visibleConditions; i++) { |
| 568 | final ConditionTag tag = getConditionTagAt(i); |
| 569 | if (tag != null && tag.rb.isChecked()) { |
| 570 | if (DEBUG) Log.d(mTag, "Not selecting a default, checked=" + tag.condition); |
John Spurlock | 856edeb | 2014-06-01 20:36:47 -0400 | [diff] [blame] | 571 | return; |
| 572 | } |
| 573 | } |
John Spurlock | 530052a | 2014-11-30 16:26:19 -0500 | [diff] [blame] | 574 | final ConditionTag foreverTag = getConditionTagAt(FOREVER_CONDITION_INDEX); |
| 575 | if (foreverTag == null) return; |
John Spurlock | 856edeb | 2014-06-01 20:36:47 -0400 | [diff] [blame] | 576 | if (DEBUG) Log.d(mTag, "Selecting a default"); |
John Spurlock | 8f8ecd6 | 2014-08-27 17:46:03 -0400 | [diff] [blame] | 577 | final int favoriteIndex = mPrefs.getMinuteIndex(); |
John Spurlock | 530052a | 2014-11-30 16:26:19 -0500 | [diff] [blame] | 578 | if (favoriteIndex == -1 || !mCountdownConditionSupported) { |
Julia Reynolds | 617a780 | 2016-04-29 14:32:46 -0400 | [diff] [blame] | 579 | setChecked(foreverTag.rb, true); |
John Spurlock | 856edeb | 2014-06-01 20:36:47 -0400 | [diff] [blame] | 580 | } else { |
Selim Cinek | 9c4a707 | 2014-11-21 17:44:34 +0100 | [diff] [blame] | 581 | mTimeCondition = ZenModeConfig.toTimeCondition(mContext, |
| 582 | MINUTE_BUCKETS[favoriteIndex], ActivityManager.getCurrentUser()); |
John Spurlock | 856edeb | 2014-06-01 20:36:47 -0400 | [diff] [blame] | 583 | mBucketIndex = favoriteIndex; |
Julia Reynolds | 0842fe8 | 2015-10-01 14:34:22 -0400 | [diff] [blame] | 584 | bind(mTimeCondition, mZenConditions.getChildAt(COUNTDOWN_CONDITION_INDEX), |
| 585 | COUNTDOWN_CONDITION_INDEX); |
Julia Reynolds | 617a780 | 2016-04-29 14:32:46 -0400 | [diff] [blame] | 586 | setChecked(getConditionTagAt(COUNTDOWN_CONDITION_INDEX).rb, true); |
| 587 | } |
| 588 | } |
| 589 | |
| 590 | private void setChecked(RadioButton rb, boolean checked) { |
| 591 | final int N = getVisibleConditions(); |
| 592 | for (int i = 0; i < N; i++) { |
| 593 | final ConditionTag tag = getConditionTagAt(i); |
| 594 | if (tag != null && tag.rb.isChecked() && !Objects.equals(tag.rb, rb)) { |
| 595 | tag.rb.setChecked(false); |
| 596 | } |
| 597 | } |
| 598 | if (rb.isChecked() != checked) { |
| 599 | rb.setChecked(checked); |
John Spurlock | 856edeb | 2014-06-01 20:36:47 -0400 | [diff] [blame] | 600 | } |
| 601 | } |
| 602 | |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 603 | private static boolean isCountdown(Condition c) { |
John Spurlock | 530052a | 2014-11-30 16:26:19 -0500 | [diff] [blame] | 604 | return c != null && ZenModeConfig.isValidCountdownConditionId(c.id); |
| 605 | } |
| 606 | |
John Spurlock | 0b68850 | 2014-12-22 15:13:30 -0500 | [diff] [blame] | 607 | private boolean isForever(Condition c) { |
| 608 | return c != null && mForeverId.equals(c.id); |
| 609 | } |
| 610 | |
Julia Reynolds | 0842fe8 | 2015-10-01 14:34:22 -0400 | [diff] [blame] | 611 | private void bind(final Condition condition, final View row, final int rowId) { |
John Spurlock | 0b68850 | 2014-12-22 15:13:30 -0500 | [diff] [blame] | 612 | if (condition == null) throw new IllegalArgumentException("condition must not be null"); |
| 613 | final boolean enabled = condition.state == Condition.STATE_TRUE; |
John Spurlock | 856edeb | 2014-06-01 20:36:47 -0400 | [diff] [blame] | 614 | final ConditionTag tag = |
| 615 | row.getTag() != null ? (ConditionTag) row.getTag() : new ConditionTag(); |
| 616 | row.setTag(tag); |
John Spurlock | 530052a | 2014-11-30 16:26:19 -0500 | [diff] [blame] | 617 | final boolean first = tag.rb == null; |
John Spurlock | 856edeb | 2014-06-01 20:36:47 -0400 | [diff] [blame] | 618 | if (tag.rb == null) { |
| 619 | tag.rb = (RadioButton) row.findViewById(android.R.id.checkbox); |
| 620 | } |
John Spurlock | 4db0d98 | 2014-08-13 09:19:03 -0400 | [diff] [blame] | 621 | tag.condition = condition; |
John Spurlock | 530052a | 2014-11-30 16:26:19 -0500 | [diff] [blame] | 622 | final Uri conditionId = getConditionId(tag.condition); |
| 623 | if (DEBUG) Log.d(mTag, "bind i=" + mZenConditions.indexOfChild(row) + " first=" + first |
| 624 | + " condition=" + conditionId); |
John Spurlock | 856edeb | 2014-06-01 20:36:47 -0400 | [diff] [blame] | 625 | tag.rb.setEnabled(enabled); |
| 626 | tag.rb.setOnCheckedChangeListener(new OnCheckedChangeListener() { |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 627 | @Override |
| 628 | public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { |
John Spurlock | ae641c9 | 2014-06-30 18:11:40 -0400 | [diff] [blame] | 629 | if (mExpanded && isChecked) { |
Julia Reynolds | 617a780 | 2016-04-29 14:32:46 -0400 | [diff] [blame] | 630 | setChecked(tag.rb, isChecked); |
John Spurlock | 530052a | 2014-11-30 16:26:19 -0500 | [diff] [blame] | 631 | if (DEBUG) Log.d(mTag, "onCheckedChanged " + conditionId); |
Chris Wren | f6e9228b | 2016-01-26 18:04:35 -0500 | [diff] [blame] | 632 | MetricsLogger.action(mContext, MetricsEvent.QS_DND_CONDITION_SELECT); |
John Spurlock | 4db0d98 | 2014-08-13 09:19:03 -0400 | [diff] [blame] | 633 | select(tag.condition); |
John Spurlock | a0457c2 | 2014-09-26 13:22:08 -0400 | [diff] [blame] | 634 | announceConditionSelection(tag); |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 635 | } |
| 636 | } |
| 637 | }); |
John Spurlock | a0457c2 | 2014-09-26 13:22:08 -0400 | [diff] [blame] | 638 | |
John Spurlock | c90e6fe | 2014-10-28 11:21:42 -0400 | [diff] [blame] | 639 | if (tag.lines == null) { |
| 640 | tag.lines = row.findViewById(android.R.id.content); |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 641 | } |
John Spurlock | c90e6fe | 2014-10-28 11:21:42 -0400 | [diff] [blame] | 642 | if (tag.line1 == null) { |
| 643 | tag.line1 = (TextView) row.findViewById(android.R.id.text1); |
John Spurlock | d896323 | 2015-06-08 16:26:12 -0400 | [diff] [blame] | 644 | mSpTexts.add(tag.line1); |
John Spurlock | c90e6fe | 2014-10-28 11:21:42 -0400 | [diff] [blame] | 645 | } |
| 646 | if (tag.line2 == null) { |
| 647 | tag.line2 = (TextView) row.findViewById(android.R.id.text2); |
John Spurlock | d896323 | 2015-06-08 16:26:12 -0400 | [diff] [blame] | 648 | mSpTexts.add(tag.line2); |
John Spurlock | c90e6fe | 2014-10-28 11:21:42 -0400 | [diff] [blame] | 649 | } |
John Spurlock | 0b68850 | 2014-12-22 15:13:30 -0500 | [diff] [blame] | 650 | final String line1 = !TextUtils.isEmpty(condition.line1) ? condition.line1 |
| 651 | : condition.summary; |
| 652 | final String line2 = condition.line2; |
John Spurlock | c90e6fe | 2014-10-28 11:21:42 -0400 | [diff] [blame] | 653 | tag.line1.setText(line1); |
| 654 | if (TextUtils.isEmpty(line2)) { |
| 655 | tag.line2.setVisibility(GONE); |
| 656 | } else { |
| 657 | tag.line2.setVisibility(VISIBLE); |
| 658 | tag.line2.setText(line2); |
| 659 | } |
| 660 | tag.lines.setEnabled(enabled); |
| 661 | tag.lines.setAlpha(enabled ? 1 : .4f); |
John Spurlock | a0457c2 | 2014-09-26 13:22:08 -0400 | [diff] [blame] | 662 | |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 663 | final ImageView button1 = (ImageView) row.findViewById(android.R.id.button1); |
| 664 | button1.setOnClickListener(new OnClickListener() { |
| 665 | @Override |
| 666 | public void onClick(View v) { |
Julia Reynolds | 0842fe8 | 2015-10-01 14:34:22 -0400 | [diff] [blame] | 667 | onClickTimeButton(row, tag, false /*down*/, rowId); |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 668 | } |
| 669 | }); |
| 670 | |
| 671 | final ImageView button2 = (ImageView) row.findViewById(android.R.id.button2); |
| 672 | button2.setOnClickListener(new OnClickListener() { |
| 673 | @Override |
| 674 | public void onClick(View v) { |
Julia Reynolds | 0842fe8 | 2015-10-01 14:34:22 -0400 | [diff] [blame] | 675 | onClickTimeButton(row, tag, true /*up*/, rowId); |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 676 | } |
| 677 | }); |
John Spurlock | c90e6fe | 2014-10-28 11:21:42 -0400 | [diff] [blame] | 678 | tag.lines.setOnClickListener(new OnClickListener() { |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 679 | @Override |
| 680 | public void onClick(View v) { |
Julia Reynolds | 617a780 | 2016-04-29 14:32:46 -0400 | [diff] [blame] | 681 | setChecked(tag.rb, true); |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 682 | } |
| 683 | }); |
John Spurlock | 856edeb | 2014-06-01 20:36:47 -0400 | [diff] [blame] | 684 | |
John Spurlock | 530052a | 2014-11-30 16:26:19 -0500 | [diff] [blame] | 685 | final long time = ZenModeConfig.tryParseCountdownConditionId(conditionId); |
Julia Reynolds | 0842fe8 | 2015-10-01 14:34:22 -0400 | [diff] [blame] | 686 | if (rowId != COUNTDOWN_ALARM_CONDITION_INDEX && time > 0) { |
John Spurlock | 530052a | 2014-11-30 16:26:19 -0500 | [diff] [blame] | 687 | button1.setVisibility(VISIBLE); |
| 688 | button2.setVisibility(VISIBLE); |
John Spurlock | 856edeb | 2014-06-01 20:36:47 -0400 | [diff] [blame] | 689 | if (mBucketIndex > -1) { |
| 690 | button1.setEnabled(mBucketIndex > 0); |
| 691 | button2.setEnabled(mBucketIndex < MINUTE_BUCKETS.length - 1); |
| 692 | } else { |
| 693 | final long span = time - System.currentTimeMillis(); |
| 694 | button1.setEnabled(span > MIN_BUCKET_MINUTES * MINUTES_MS); |
John Spurlock | c90e6fe | 2014-10-28 11:21:42 -0400 | [diff] [blame] | 695 | final Condition maxCondition = ZenModeConfig.toTimeCondition(mContext, |
Selim Cinek | 9c4a707 | 2014-11-21 17:44:34 +0100 | [diff] [blame] | 696 | MAX_BUCKET_MINUTES, ActivityManager.getCurrentUser()); |
John Spurlock | 856edeb | 2014-06-01 20:36:47 -0400 | [diff] [blame] | 697 | button2.setEnabled(!Objects.equals(condition.summary, maxCondition.summary)); |
| 698 | } |
| 699 | |
| 700 | button1.setAlpha(button1.isEnabled() ? 1f : .5f); |
| 701 | button2.setAlpha(button2.isEnabled() ? 1f : .5f); |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 702 | } else { |
John Spurlock | 530052a | 2014-11-30 16:26:19 -0500 | [diff] [blame] | 703 | button1.setVisibility(GONE); |
| 704 | button2.setVisibility(GONE); |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 705 | } |
John Spurlock | a0457c2 | 2014-09-26 13:22:08 -0400 | [diff] [blame] | 706 | // wire up interaction callbacks for newly-added condition rows |
John Spurlock | 530052a | 2014-11-30 16:26:19 -0500 | [diff] [blame] | 707 | if (first) { |
John Spurlock | a0457c2 | 2014-09-26 13:22:08 -0400 | [diff] [blame] | 708 | Interaction.register(tag.rb, mInteractionCallback); |
John Spurlock | c90e6fe | 2014-10-28 11:21:42 -0400 | [diff] [blame] | 709 | Interaction.register(tag.lines, mInteractionCallback); |
John Spurlock | a0457c2 | 2014-09-26 13:22:08 -0400 | [diff] [blame] | 710 | Interaction.register(button1, mInteractionCallback); |
| 711 | Interaction.register(button2, mInteractionCallback); |
| 712 | } |
John Spurlock | 530052a | 2014-11-30 16:26:19 -0500 | [diff] [blame] | 713 | row.setVisibility(VISIBLE); |
John Spurlock | a0457c2 | 2014-09-26 13:22:08 -0400 | [diff] [blame] | 714 | } |
| 715 | |
| 716 | private void announceConditionSelection(ConditionTag tag) { |
| 717 | final int zen = getSelectedZen(Global.ZEN_MODE_OFF); |
| 718 | String modeText; |
| 719 | switch(zen) { |
| 720 | case Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS: |
John Spurlock | d9c75db | 2015-04-28 11:19:13 -0400 | [diff] [blame] | 721 | modeText = mContext.getString(R.string.interruption_level_priority); |
John Spurlock | a0457c2 | 2014-09-26 13:22:08 -0400 | [diff] [blame] | 722 | break; |
| 723 | case Global.ZEN_MODE_NO_INTERRUPTIONS: |
John Spurlock | d9c75db | 2015-04-28 11:19:13 -0400 | [diff] [blame] | 724 | modeText = mContext.getString(R.string.interruption_level_none); |
John Spurlock | a0457c2 | 2014-09-26 13:22:08 -0400 | [diff] [blame] | 725 | break; |
John Spurlock | 4f1163c | 2015-04-02 17:41:21 -0400 | [diff] [blame] | 726 | case Global.ZEN_MODE_ALARMS: |
John Spurlock | d9c75db | 2015-04-28 11:19:13 -0400 | [diff] [blame] | 727 | modeText = mContext.getString(R.string.interruption_level_alarms); |
John Spurlock | 4f1163c | 2015-04-02 17:41:21 -0400 | [diff] [blame] | 728 | break; |
| 729 | default: |
John Spurlock | a0457c2 | 2014-09-26 13:22:08 -0400 | [diff] [blame] | 730 | return; |
| 731 | } |
| 732 | announceForAccessibility(mContext.getString(R.string.zen_mode_and_condition, modeText, |
John Spurlock | c90e6fe | 2014-10-28 11:21:42 -0400 | [diff] [blame] | 733 | tag.line1.getText())); |
John Spurlock | 856edeb | 2014-06-01 20:36:47 -0400 | [diff] [blame] | 734 | } |
| 735 | |
Julia Reynolds | 0842fe8 | 2015-10-01 14:34:22 -0400 | [diff] [blame] | 736 | private void onClickTimeButton(View row, ConditionTag tag, boolean up, int rowId) { |
Chris Wren | f6e9228b | 2016-01-26 18:04:35 -0500 | [diff] [blame] | 737 | MetricsLogger.action(mContext, MetricsEvent.QS_DND_TIME, up); |
John Spurlock | 856edeb | 2014-06-01 20:36:47 -0400 | [diff] [blame] | 738 | Condition newCondition = null; |
| 739 | final int N = MINUTE_BUCKETS.length; |
| 740 | if (mBucketIndex == -1) { |
| 741 | // not on a known index, search for the next or prev bucket by time |
John Spurlock | 4db0d98 | 2014-08-13 09:19:03 -0400 | [diff] [blame] | 742 | final Uri conditionId = getConditionId(tag.condition); |
| 743 | final long time = ZenModeConfig.tryParseCountdownConditionId(conditionId); |
John Spurlock | 856edeb | 2014-06-01 20:36:47 -0400 | [diff] [blame] | 744 | final long now = System.currentTimeMillis(); |
| 745 | for (int i = 0; i < N; i++) { |
| 746 | int j = up ? i : N - 1 - i; |
| 747 | final int bucketMinutes = MINUTE_BUCKETS[j]; |
| 748 | final long bucketTime = now + bucketMinutes * MINUTES_MS; |
| 749 | if (up && bucketTime > time || !up && bucketTime < time) { |
| 750 | mBucketIndex = j; |
John Spurlock | c90e6fe | 2014-10-28 11:21:42 -0400 | [diff] [blame] | 751 | newCondition = ZenModeConfig.toTimeCondition(mContext, |
Julia Reynolds | 0842fe8 | 2015-10-01 14:34:22 -0400 | [diff] [blame] | 752 | bucketTime, bucketMinutes, ActivityManager.getCurrentUser(), |
John Spurlock | bbde267 | 2015-05-13 15:42:04 -0400 | [diff] [blame] | 753 | false /*shortVersion*/); |
John Spurlock | 856edeb | 2014-06-01 20:36:47 -0400 | [diff] [blame] | 754 | break; |
| 755 | } |
| 756 | } |
| 757 | if (newCondition == null) { |
| 758 | mBucketIndex = DEFAULT_BUCKET_INDEX; |
John Spurlock | c90e6fe | 2014-10-28 11:21:42 -0400 | [diff] [blame] | 759 | newCondition = ZenModeConfig.toTimeCondition(mContext, |
Selim Cinek | 9c4a707 | 2014-11-21 17:44:34 +0100 | [diff] [blame] | 760 | MINUTE_BUCKETS[mBucketIndex], ActivityManager.getCurrentUser()); |
John Spurlock | 856edeb | 2014-06-01 20:36:47 -0400 | [diff] [blame] | 761 | } |
| 762 | } else { |
| 763 | // on a known index, simply increment or decrement |
| 764 | mBucketIndex = Math.max(0, Math.min(N - 1, mBucketIndex + (up ? 1 : -1))); |
John Spurlock | c90e6fe | 2014-10-28 11:21:42 -0400 | [diff] [blame] | 765 | newCondition = ZenModeConfig.toTimeCondition(mContext, |
Selim Cinek | 9c4a707 | 2014-11-21 17:44:34 +0100 | [diff] [blame] | 766 | MINUTE_BUCKETS[mBucketIndex], ActivityManager.getCurrentUser()); |
John Spurlock | 856edeb | 2014-06-01 20:36:47 -0400 | [diff] [blame] | 767 | } |
John Spurlock | 4db0d98 | 2014-08-13 09:19:03 -0400 | [diff] [blame] | 768 | mTimeCondition = newCondition; |
Julia Reynolds | 0842fe8 | 2015-10-01 14:34:22 -0400 | [diff] [blame] | 769 | bind(mTimeCondition, row, rowId); |
Julia Reynolds | 617a780 | 2016-04-29 14:32:46 -0400 | [diff] [blame] | 770 | setChecked(tag.rb, true); |
John Spurlock | 4db0d98 | 2014-08-13 09:19:03 -0400 | [diff] [blame] | 771 | select(mTimeCondition); |
John Spurlock | a0457c2 | 2014-09-26 13:22:08 -0400 | [diff] [blame] | 772 | announceConditionSelection(tag); |
John Spurlock | 856edeb | 2014-06-01 20:36:47 -0400 | [diff] [blame] | 773 | } |
| 774 | |
John Spurlock | 530052a | 2014-11-30 16:26:19 -0500 | [diff] [blame] | 775 | private void select(final Condition condition) { |
John Spurlock | 4db0d98 | 2014-08-13 09:19:03 -0400 | [diff] [blame] | 776 | if (DEBUG) Log.d(mTag, "select " + condition); |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 777 | if (mSessionZen == -1 || mSessionZen == Global.ZEN_MODE_OFF) { |
| 778 | if (DEBUG) Log.d(mTag, "Ignoring condition selection outside of manual zen"); |
| 779 | return; |
| 780 | } |
| 781 | final Uri realConditionId = getRealConditionId(condition); |
John Spurlock | 856edeb | 2014-06-01 20:36:47 -0400 | [diff] [blame] | 782 | if (mController != null) { |
John Spurlock | 530052a | 2014-11-30 16:26:19 -0500 | [diff] [blame] | 783 | AsyncTask.execute(new Runnable() { |
| 784 | @Override |
| 785 | public void run() { |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 786 | mController.setZen(mSessionZen, realConditionId, TAG + ".selectCondition"); |
John Spurlock | 530052a | 2014-11-30 16:26:19 -0500 | [diff] [blame] | 787 | } |
| 788 | }); |
John Spurlock | 856edeb | 2014-06-01 20:36:47 -0400 | [diff] [blame] | 789 | } |
John Spurlock | 4db0d98 | 2014-08-13 09:19:03 -0400 | [diff] [blame] | 790 | setExitCondition(condition); |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 791 | if (realConditionId == null) { |
John Spurlock | 8f8ecd6 | 2014-08-27 17:46:03 -0400 | [diff] [blame] | 792 | mPrefs.setMinuteIndex(-1); |
John Spurlock | 530052a | 2014-11-30 16:26:19 -0500 | [diff] [blame] | 793 | } else if (isCountdown(condition) && mBucketIndex != -1) { |
John Spurlock | 8f8ecd6 | 2014-08-27 17:46:03 -0400 | [diff] [blame] | 794 | mPrefs.setMinuteIndex(mBucketIndex); |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 795 | } |
John Spurlock | 530052a | 2014-11-30 16:26:19 -0500 | [diff] [blame] | 796 | setSessionExitCondition(copy(condition)); |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 797 | } |
| 798 | |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 799 | private void fireInteraction() { |
| 800 | if (mCallback != null) { |
| 801 | mCallback.onInteraction(); |
| 802 | } |
| 803 | } |
| 804 | |
John Spurlock | ae641c9 | 2014-06-30 18:11:40 -0400 | [diff] [blame] | 805 | private void fireExpanded() { |
| 806 | if (mCallback != null) { |
| 807 | mCallback.onExpanded(mExpanded); |
| 808 | } |
| 809 | } |
| 810 | |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 811 | private final ZenModeController.Callback mZenCallback = new ZenModeController.Callback() { |
| 812 | @Override |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 813 | public void onManualRuleChanged(ZenRule rule) { |
| 814 | mHandler.obtainMessage(H.MANUAL_RULE_CHANGED, rule).sendToTarget(); |
John Spurlock | 856edeb | 2014-06-01 20:36:47 -0400 | [diff] [blame] | 815 | } |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 816 | }; |
| 817 | |
| 818 | private final class H extends Handler { |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 819 | private static final int MANUAL_RULE_CHANGED = 2; |
John Spurlock | f55b7f2 | 2015-04-13 19:21:26 -0400 | [diff] [blame] | 820 | private static final int UPDATE_WIDGETS = 3; |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 821 | |
| 822 | private H() { |
| 823 | super(Looper.getMainLooper()); |
| 824 | } |
| 825 | |
| 826 | @Override |
| 827 | public void handleMessage(Message msg) { |
John Spurlock | f55b7f2 | 2015-04-13 19:21:26 -0400 | [diff] [blame] | 828 | switch (msg.what) { |
John Spurlock | f55b7f2 | 2015-04-13 19:21:26 -0400 | [diff] [blame] | 829 | case MANUAL_RULE_CHANGED: handleUpdateManualRule((ZenRule) msg.obj); break; |
| 830 | case UPDATE_WIDGETS: updateWidgets(); break; |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 831 | } |
| 832 | } |
| 833 | } |
| 834 | |
| 835 | public interface Callback { |
John Spurlock | f55b7f2 | 2015-04-13 19:21:26 -0400 | [diff] [blame] | 836 | void onPrioritySettings(); |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 837 | void onInteraction(); |
John Spurlock | ae641c9 | 2014-06-30 18:11:40 -0400 | [diff] [blame] | 838 | void onExpanded(boolean expanded); |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 839 | } |
John Spurlock | 856edeb | 2014-06-01 20:36:47 -0400 | [diff] [blame] | 840 | |
| 841 | // used as the view tag on condition rows |
| 842 | private static class ConditionTag { |
| 843 | RadioButton rb; |
John Spurlock | c90e6fe | 2014-10-28 11:21:42 -0400 | [diff] [blame] | 844 | View lines; |
| 845 | TextView line1; |
| 846 | TextView line2; |
John Spurlock | 4db0d98 | 2014-08-13 09:19:03 -0400 | [diff] [blame] | 847 | Condition condition; |
John Spurlock | 856edeb | 2014-06-01 20:36:47 -0400 | [diff] [blame] | 848 | } |
| 849 | |
John Spurlock | f55b7f2 | 2015-04-13 19:21:26 -0400 | [diff] [blame] | 850 | private final class ZenPrefs implements OnSharedPreferenceChangeListener { |
John Spurlock | 8f8ecd6 | 2014-08-27 17:46:03 -0400 | [diff] [blame] | 851 | private final int mNoneDangerousThreshold; |
John Spurlock | 856edeb | 2014-06-01 20:36:47 -0400 | [diff] [blame] | 852 | |
| 853 | private int mMinuteIndex; |
John Spurlock | 8f8ecd6 | 2014-08-27 17:46:03 -0400 | [diff] [blame] | 854 | private int mNoneSelected; |
John Spurlock | d9c75db | 2015-04-28 11:19:13 -0400 | [diff] [blame] | 855 | private boolean mConfirmedPriorityIntroduction; |
| 856 | private boolean mConfirmedSilenceIntroduction; |
John Spurlock | 856edeb | 2014-06-01 20:36:47 -0400 | [diff] [blame] | 857 | |
John Spurlock | f55b7f2 | 2015-04-13 19:21:26 -0400 | [diff] [blame] | 858 | private ZenPrefs() { |
John Spurlock | 8f8ecd6 | 2014-08-27 17:46:03 -0400 | [diff] [blame] | 859 | mNoneDangerousThreshold = mContext.getResources() |
| 860 | .getInteger(R.integer.zen_mode_alarm_warning_threshold); |
John Spurlock | f55b7f2 | 2015-04-13 19:21:26 -0400 | [diff] [blame] | 861 | Prefs.registerListener(mContext, this); |
John Spurlock | 856edeb | 2014-06-01 20:36:47 -0400 | [diff] [blame] | 862 | updateMinuteIndex(); |
John Spurlock | 8f8ecd6 | 2014-08-27 17:46:03 -0400 | [diff] [blame] | 863 | updateNoneSelected(); |
John Spurlock | d9c75db | 2015-04-28 11:19:13 -0400 | [diff] [blame] | 864 | updateConfirmedPriorityIntroduction(); |
| 865 | updateConfirmedSilenceIntroduction(); |
John Spurlock | 8f8ecd6 | 2014-08-27 17:46:03 -0400 | [diff] [blame] | 866 | } |
| 867 | |
| 868 | public void trackNoneSelected() { |
| 869 | mNoneSelected = clampNoneSelected(mNoneSelected + 1); |
| 870 | if (DEBUG) Log.d(mTag, "Setting none selected: " + mNoneSelected + " threshold=" |
| 871 | + mNoneDangerousThreshold); |
John Spurlock | f55b7f2 | 2015-04-13 19:21:26 -0400 | [diff] [blame] | 872 | Prefs.putInt(mContext, Prefs.Key.DND_NONE_SELECTED, mNoneSelected); |
John Spurlock | 856edeb | 2014-06-01 20:36:47 -0400 | [diff] [blame] | 873 | } |
| 874 | |
| 875 | public int getMinuteIndex() { |
| 876 | return mMinuteIndex; |
| 877 | } |
| 878 | |
| 879 | public void setMinuteIndex(int minuteIndex) { |
John Spurlock | 8f8ecd6 | 2014-08-27 17:46:03 -0400 | [diff] [blame] | 880 | minuteIndex = clampIndex(minuteIndex); |
John Spurlock | 856edeb | 2014-06-01 20:36:47 -0400 | [diff] [blame] | 881 | if (minuteIndex == mMinuteIndex) return; |
John Spurlock | 8f8ecd6 | 2014-08-27 17:46:03 -0400 | [diff] [blame] | 882 | mMinuteIndex = clampIndex(minuteIndex); |
John Spurlock | 856edeb | 2014-06-01 20:36:47 -0400 | [diff] [blame] | 883 | if (DEBUG) Log.d(mTag, "Setting favorite minute index: " + mMinuteIndex); |
John Spurlock | f55b7f2 | 2015-04-13 19:21:26 -0400 | [diff] [blame] | 884 | Prefs.putInt(mContext, Prefs.Key.DND_FAVORITE_BUCKET_INDEX, mMinuteIndex); |
John Spurlock | 856edeb | 2014-06-01 20:36:47 -0400 | [diff] [blame] | 885 | } |
| 886 | |
| 887 | @Override |
| 888 | public void onSharedPreferenceChanged(SharedPreferences prefs, String key) { |
| 889 | updateMinuteIndex(); |
John Spurlock | 8f8ecd6 | 2014-08-27 17:46:03 -0400 | [diff] [blame] | 890 | updateNoneSelected(); |
John Spurlock | d9c75db | 2015-04-28 11:19:13 -0400 | [diff] [blame] | 891 | updateConfirmedPriorityIntroduction(); |
| 892 | updateConfirmedSilenceIntroduction(); |
John Spurlock | 856edeb | 2014-06-01 20:36:47 -0400 | [diff] [blame] | 893 | } |
| 894 | |
| 895 | private void updateMinuteIndex() { |
John Spurlock | f55b7f2 | 2015-04-13 19:21:26 -0400 | [diff] [blame] | 896 | mMinuteIndex = clampIndex(Prefs.getInt(mContext, |
| 897 | Prefs.Key.DND_FAVORITE_BUCKET_INDEX, DEFAULT_BUCKET_INDEX)); |
John Spurlock | 856edeb | 2014-06-01 20:36:47 -0400 | [diff] [blame] | 898 | if (DEBUG) Log.d(mTag, "Favorite minute index: " + mMinuteIndex); |
| 899 | } |
| 900 | |
John Spurlock | 8f8ecd6 | 2014-08-27 17:46:03 -0400 | [diff] [blame] | 901 | private int clampIndex(int index) { |
| 902 | return MathUtils.constrain(index, -1, MINUTE_BUCKETS.length - 1); |
| 903 | } |
| 904 | |
| 905 | private void updateNoneSelected() { |
John Spurlock | f55b7f2 | 2015-04-13 19:21:26 -0400 | [diff] [blame] | 906 | mNoneSelected = clampNoneSelected(Prefs.getInt(mContext, |
| 907 | Prefs.Key.DND_NONE_SELECTED, 0)); |
John Spurlock | 8f8ecd6 | 2014-08-27 17:46:03 -0400 | [diff] [blame] | 908 | if (DEBUG) Log.d(mTag, "None selected: " + mNoneSelected); |
| 909 | } |
| 910 | |
| 911 | private int clampNoneSelected(int noneSelected) { |
| 912 | return MathUtils.constrain(noneSelected, 0, Integer.MAX_VALUE); |
John Spurlock | 856edeb | 2014-06-01 20:36:47 -0400 | [diff] [blame] | 913 | } |
John Spurlock | f55b7f2 | 2015-04-13 19:21:26 -0400 | [diff] [blame] | 914 | |
John Spurlock | d9c75db | 2015-04-28 11:19:13 -0400 | [diff] [blame] | 915 | private void updateConfirmedPriorityIntroduction() { |
John Spurlock | f55b7f2 | 2015-04-13 19:21:26 -0400 | [diff] [blame] | 916 | final boolean confirmed = Prefs.getBoolean(mContext, |
| 917 | Prefs.Key.DND_CONFIRMED_PRIORITY_INTRODUCTION, false); |
John Spurlock | d9c75db | 2015-04-28 11:19:13 -0400 | [diff] [blame] | 918 | if (confirmed == mConfirmedPriorityIntroduction) return; |
| 919 | mConfirmedPriorityIntroduction = confirmed; |
| 920 | if (DEBUG) Log.d(mTag, "Confirmed priority introduction: " |
| 921 | + mConfirmedPriorityIntroduction); |
| 922 | } |
| 923 | |
| 924 | private void updateConfirmedSilenceIntroduction() { |
| 925 | final boolean confirmed = Prefs.getBoolean(mContext, |
| 926 | Prefs.Key.DND_CONFIRMED_SILENCE_INTRODUCTION, false); |
| 927 | if (confirmed == mConfirmedSilenceIntroduction) return; |
| 928 | mConfirmedSilenceIntroduction = confirmed; |
| 929 | if (DEBUG) Log.d(mTag, "Confirmed silence introduction: " |
| 930 | + mConfirmedSilenceIntroduction); |
John Spurlock | f55b7f2 | 2015-04-13 19:21:26 -0400 | [diff] [blame] | 931 | } |
John Spurlock | 856edeb | 2014-06-01 20:36:47 -0400 | [diff] [blame] | 932 | } |
John Spurlock | ae641c9 | 2014-06-30 18:11:40 -0400 | [diff] [blame] | 933 | |
Muyuan Li | 8303bd2 | 2016-03-23 20:08:26 -0700 | [diff] [blame] | 934 | protected final SegmentedButtons.Callback mZenButtonsCallback = new SegmentedButtons.Callback() { |
John Spurlock | ae641c9 | 2014-06-30 18:11:40 -0400 | [diff] [blame] | 935 | @Override |
Chris Wren | 4572cbc | 2015-06-29 11:27:18 -0400 | [diff] [blame] | 936 | public void onSelected(final Object value, boolean fromClick) { |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 937 | if (value != null && mZenButtons.isShown() && isAttachedToWindow()) { |
John Spurlock | d9c75db | 2015-04-28 11:19:13 -0400 | [diff] [blame] | 938 | final int zen = (Integer) value; |
Chris Wren | 4572cbc | 2015-06-29 11:27:18 -0400 | [diff] [blame] | 939 | if (fromClick) { |
Chris Wren | f6e9228b | 2016-01-26 18:04:35 -0500 | [diff] [blame] | 940 | MetricsLogger.action(mContext, MetricsEvent.QS_DND_ZEN_SELECT, zen); |
Chris Wren | 4572cbc | 2015-06-29 11:27:18 -0400 | [diff] [blame] | 941 | } |
John Spurlock | d9c75db | 2015-04-28 11:19:13 -0400 | [diff] [blame] | 942 | if (DEBUG) Log.d(mTag, "mZenButtonsCallback selected=" + zen); |
John Spurlock | b2278d6 | 2015-04-07 12:47:12 -0400 | [diff] [blame] | 943 | final Uri realConditionId = getRealConditionId(mSessionExitCondition); |
John Spurlock | 530052a | 2014-11-30 16:26:19 -0500 | [diff] [blame] | 944 | AsyncTask.execute(new Runnable() { |
| 945 | @Override |
| 946 | public void run() { |
John Spurlock | d9c75db | 2015-04-28 11:19:13 -0400 | [diff] [blame] | 947 | mController.setZen(zen, realConditionId, TAG + ".selectZen"); |
| 948 | if (zen != Global.ZEN_MODE_OFF) { |
| 949 | Prefs.putInt(mContext, Prefs.Key.DND_FAVORITE_ZEN, zen); |
| 950 | } |
John Spurlock | 530052a | 2014-11-30 16:26:19 -0500 | [diff] [blame] | 951 | } |
| 952 | }); |
John Spurlock | ae641c9 | 2014-06-30 18:11:40 -0400 | [diff] [blame] | 953 | } |
| 954 | } |
John Spurlock | a0457c2 | 2014-09-26 13:22:08 -0400 | [diff] [blame] | 955 | |
| 956 | @Override |
| 957 | public void onInteraction() { |
| 958 | fireInteraction(); |
| 959 | } |
| 960 | }; |
| 961 | |
| 962 | private final Interaction.Callback mInteractionCallback = new Interaction.Callback() { |
| 963 | @Override |
| 964 | public void onInteraction() { |
| 965 | fireInteraction(); |
| 966 | } |
John Spurlock | ae641c9 | 2014-06-30 18:11:40 -0400 | [diff] [blame] | 967 | }; |
John Spurlock | 530052a | 2014-11-30 16:26:19 -0500 | [diff] [blame] | 968 | |
| 969 | private final class TransitionHelper implements TransitionListener, Runnable { |
| 970 | private final ArraySet<View> mTransitioningViews = new ArraySet<View>(); |
| 971 | |
| 972 | private boolean mTransitioning; |
John Spurlock | 530052a | 2014-11-30 16:26:19 -0500 | [diff] [blame] | 973 | private boolean mPendingUpdateWidgets; |
| 974 | |
| 975 | public void clear() { |
| 976 | mTransitioningViews.clear(); |
Julia Reynolds | 0842fe8 | 2015-10-01 14:34:22 -0400 | [diff] [blame] | 977 | mPendingUpdateWidgets = false; |
John Spurlock | 530052a | 2014-11-30 16:26:19 -0500 | [diff] [blame] | 978 | } |
| 979 | |
| 980 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 981 | pw.println(" TransitionHelper state:"); |
John Spurlock | 530052a | 2014-11-30 16:26:19 -0500 | [diff] [blame] | 982 | pw.print(" mPendingUpdateWidgets="); pw.println(mPendingUpdateWidgets); |
| 983 | pw.print(" mTransitioning="); pw.println(mTransitioning); |
| 984 | pw.print(" mTransitioningViews="); pw.println(mTransitioningViews); |
| 985 | } |
| 986 | |
John Spurlock | 530052a | 2014-11-30 16:26:19 -0500 | [diff] [blame] | 987 | public void pendingUpdateWidgets() { |
| 988 | mPendingUpdateWidgets = true; |
| 989 | } |
| 990 | |
| 991 | public boolean isTransitioning() { |
| 992 | return !mTransitioningViews.isEmpty(); |
| 993 | } |
| 994 | |
| 995 | @Override |
| 996 | public void startTransition(LayoutTransition transition, |
| 997 | ViewGroup container, View view, int transitionType) { |
| 998 | mTransitioningViews.add(view); |
| 999 | updateTransitioning(); |
| 1000 | } |
| 1001 | |
| 1002 | @Override |
| 1003 | public void endTransition(LayoutTransition transition, |
| 1004 | ViewGroup container, View view, int transitionType) { |
| 1005 | mTransitioningViews.remove(view); |
| 1006 | updateTransitioning(); |
| 1007 | } |
| 1008 | |
| 1009 | @Override |
| 1010 | public void run() { |
| 1011 | if (DEBUG) Log.d(mTag, "TransitionHelper run" |
Julia Reynolds | 0842fe8 | 2015-10-01 14:34:22 -0400 | [diff] [blame] | 1012 | + " mPendingUpdateWidgets=" + mPendingUpdateWidgets); |
John Spurlock | 530052a | 2014-11-30 16:26:19 -0500 | [diff] [blame] | 1013 | if (mPendingUpdateWidgets) { |
| 1014 | updateWidgets(); |
| 1015 | } |
Julia Reynolds | 0842fe8 | 2015-10-01 14:34:22 -0400 | [diff] [blame] | 1016 | mPendingUpdateWidgets = false; |
John Spurlock | 530052a | 2014-11-30 16:26:19 -0500 | [diff] [blame] | 1017 | } |
| 1018 | |
| 1019 | private void updateTransitioning() { |
| 1020 | final boolean transitioning = isTransitioning(); |
| 1021 | if (mTransitioning == transitioning) return; |
| 1022 | mTransitioning = transitioning; |
| 1023 | if (DEBUG) Log.d(mTag, "TransitionHelper mTransitioning=" + mTransitioning); |
| 1024 | if (!mTransitioning) { |
Julia Reynolds | 0842fe8 | 2015-10-01 14:34:22 -0400 | [diff] [blame] | 1025 | if (mPendingUpdateWidgets) { |
John Spurlock | 530052a | 2014-11-30 16:26:19 -0500 | [diff] [blame] | 1026 | mHandler.post(this); |
| 1027 | } else { |
Julia Reynolds | 0842fe8 | 2015-10-01 14:34:22 -0400 | [diff] [blame] | 1028 | mPendingUpdateWidgets = false; |
John Spurlock | 530052a | 2014-11-30 16:26:19 -0500 | [diff] [blame] | 1029 | } |
| 1030 | } |
| 1031 | } |
| 1032 | } |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 1033 | } |