John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 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 | 5adeabc | 2015-05-05 14:50:43 -0400 | [diff] [blame] | 19 | import static android.accessibilityservice.AccessibilityServiceInfo.FEEDBACK_ALL_MASK; |
John Spurlock | f09838b | 2015-06-11 16:14:44 -0400 | [diff] [blame] | 20 | import static android.accessibilityservice.AccessibilityServiceInfo.FEEDBACK_GENERIC; |
John Spurlock | 5adeabc | 2015-05-05 14:50:43 -0400 | [diff] [blame] | 21 | |
| 22 | import android.accessibilityservice.AccessibilityServiceInfo; |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 23 | import android.animation.LayoutTransition; |
| 24 | import android.animation.ObjectAnimator; |
| 25 | import android.animation.ValueAnimator; |
| 26 | import android.annotation.SuppressLint; |
| 27 | import android.app.Dialog; |
| 28 | import android.app.KeyguardManager; |
| 29 | import android.content.Context; |
John Spurlock | 77bb25af | 2015-05-11 12:12:07 -0400 | [diff] [blame] | 30 | import android.content.res.ColorStateList; |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 31 | import android.content.res.Resources; |
| 32 | import android.graphics.Color; |
| 33 | import android.graphics.PixelFormat; |
| 34 | import android.graphics.Rect; |
| 35 | import android.graphics.drawable.AnimatedVectorDrawable; |
| 36 | import android.graphics.drawable.ColorDrawable; |
| 37 | import android.graphics.drawable.Drawable; |
| 38 | import android.media.AudioManager; |
| 39 | import android.media.AudioSystem; |
John Spurlock | 5adeabc | 2015-05-05 14:50:43 -0400 | [diff] [blame] | 40 | import android.os.Debug; |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 41 | import android.os.Handler; |
| 42 | import android.os.Looper; |
| 43 | import android.os.Message; |
| 44 | import android.os.SystemClock; |
| 45 | import android.provider.Settings.Global; |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 46 | import android.util.DisplayMetrics; |
| 47 | import android.util.Log; |
| 48 | import android.util.SparseBooleanArray; |
| 49 | import android.view.Gravity; |
| 50 | import android.view.MotionEvent; |
| 51 | import android.view.View; |
John Spurlock | 5adeabc | 2015-05-05 14:50:43 -0400 | [diff] [blame] | 52 | import android.view.View.AccessibilityDelegate; |
| 53 | import android.view.View.OnAttachStateChangeListener; |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 54 | import android.view.View.OnClickListener; |
| 55 | import android.view.View.OnLayoutChangeListener; |
| 56 | import android.view.View.OnTouchListener; |
| 57 | import android.view.ViewGroup; |
| 58 | import android.view.ViewGroup.MarginLayoutParams; |
| 59 | import android.view.Window; |
| 60 | import android.view.WindowManager; |
John Spurlock | 5adeabc | 2015-05-05 14:50:43 -0400 | [diff] [blame] | 61 | import android.view.accessibility.AccessibilityEvent; |
| 62 | import android.view.accessibility.AccessibilityManager; |
| 63 | import android.view.accessibility.AccessibilityManager.AccessibilityStateChangeListener; |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 64 | import android.view.animation.DecelerateInterpolator; |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 65 | import android.widget.ImageButton; |
| 66 | import android.widget.LinearLayout; |
| 67 | import android.widget.SeekBar; |
| 68 | import android.widget.SeekBar.OnSeekBarChangeListener; |
| 69 | import android.widget.TextView; |
| 70 | |
| 71 | import com.android.systemui.R; |
| 72 | import com.android.systemui.statusbar.policy.ZenModeController; |
| 73 | import com.android.systemui.volume.VolumeDialogController.State; |
| 74 | import com.android.systemui.volume.VolumeDialogController.StreamState; |
| 75 | |
| 76 | import java.io.PrintWriter; |
| 77 | import java.util.ArrayList; |
| 78 | import java.util.List; |
| 79 | |
| 80 | /** |
| 81 | * Visual presentation of the volume dialog. |
| 82 | * |
| 83 | * A client of VolumeDialogController and its state model. |
| 84 | * |
| 85 | * Methods ending in "H" must be called on the (ui) handler. |
| 86 | */ |
| 87 | public class VolumeDialog { |
| 88 | private static final String TAG = Util.logTag(VolumeDialog.class); |
| 89 | |
| 90 | private static final long USER_ATTEMPT_GRACE_PERIOD = 1000; |
| 91 | private static final int WAIT_FOR_RIPPLE = 200; |
| 92 | private static final int UPDATE_ANIMATION_DURATION = 80; |
| 93 | |
| 94 | private final Context mContext; |
| 95 | private final H mHandler = new H(); |
| 96 | private final VolumeDialogController mController; |
| 97 | |
| 98 | private final CustomDialog mDialog; |
| 99 | private final ViewGroup mDialogView; |
| 100 | private final ViewGroup mDialogContentView; |
| 101 | private final ImageButton mExpandButton; |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 102 | private final View mSettingsButton; |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 103 | private final List<VolumeRow> mRows = new ArrayList<VolumeRow>(); |
| 104 | private final SpTexts mSpTexts; |
| 105 | private final SparseBooleanArray mDynamic = new SparseBooleanArray(); |
| 106 | private final KeyguardManager mKeyguard; |
| 107 | private final int mExpandButtonAnimationDuration; |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 108 | private final ZenFooter mZenFooter; |
| 109 | private final LayoutTransition mLayoutTransition; |
John Spurlock | 76b52b3 | 2015-04-03 00:00:12 -0400 | [diff] [blame] | 110 | private final Object mSafetyWarningLock = new Object(); |
John Spurlock | 5adeabc | 2015-05-05 14:50:43 -0400 | [diff] [blame] | 111 | private final Accessibility mAccessibility = new Accessibility(); |
John Spurlock | 77bb25af | 2015-05-11 12:12:07 -0400 | [diff] [blame] | 112 | private final ColorStateList mActiveSliderTint; |
| 113 | private final ColorStateList mInactiveSliderTint; |
John Spurlock | 22def3d | 2015-06-17 11:56:12 -0400 | [diff] [blame] | 114 | private final VolumeDialogMotion mMotion; |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 115 | |
| 116 | private boolean mShowing; |
| 117 | private boolean mExpanded; |
| 118 | private int mActiveStream; |
John Spurlock | f55b7f2 | 2015-04-13 19:21:26 -0400 | [diff] [blame] | 119 | private boolean mShowHeaders = VolumePrefs.DEFAULT_SHOW_HEADERS; |
John Spurlock | f55b7f2 | 2015-04-13 19:21:26 -0400 | [diff] [blame] | 120 | private boolean mAutomute = VolumePrefs.DEFAULT_ENABLE_AUTOMUTE; |
| 121 | private boolean mSilentMode = VolumePrefs.DEFAULT_ENABLE_SILENT_MODE; |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 122 | private State mState; |
John Spurlock | 76b52b3 | 2015-04-03 00:00:12 -0400 | [diff] [blame] | 123 | private int mExpandButtonRes; |
John Spurlock | 22def3d | 2015-06-17 11:56:12 -0400 | [diff] [blame] | 124 | private boolean mExpandButtonAnimationRunning; |
John Spurlock | 76b52b3 | 2015-04-03 00:00:12 -0400 | [diff] [blame] | 125 | private SafetyWarningDialog mSafetyWarning; |
John Spurlock | f55b7f2 | 2015-04-13 19:21:26 -0400 | [diff] [blame] | 126 | private Callback mCallback; |
John Spurlock | 22def3d | 2015-06-17 11:56:12 -0400 | [diff] [blame] | 127 | private boolean mPendingStateChanged; |
| 128 | private boolean mPendingRecheckAll; |
| 129 | private long mCollapseTime; |
Jun Mukai | 3f5d713 | 2015-07-21 14:10:09 -0700 | [diff] [blame^] | 130 | private boolean mHovering = false; |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 131 | |
John Spurlock | d9c75db | 2015-04-28 11:19:13 -0400 | [diff] [blame] | 132 | public VolumeDialog(Context context, int windowType, VolumeDialogController controller, |
John Spurlock | f55b7f2 | 2015-04-13 19:21:26 -0400 | [diff] [blame] | 133 | ZenModeController zenModeController, Callback callback) { |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 134 | mContext = context; |
| 135 | mController = controller; |
John Spurlock | f55b7f2 | 2015-04-13 19:21:26 -0400 | [diff] [blame] | 136 | mCallback = callback; |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 137 | mSpTexts = new SpTexts(mContext); |
| 138 | mKeyguard = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE); |
| 139 | |
| 140 | mDialog = new CustomDialog(mContext); |
| 141 | |
| 142 | final Window window = mDialog.getWindow(); |
| 143 | window.requestFeature(Window.FEATURE_NO_TITLE); |
| 144 | window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); |
| 145 | window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); |
| 146 | window.addFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
| 147 | | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN |
| 148 | | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL |
| 149 | | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
| 150 | | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH |
| 151 | | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED); |
| 152 | mDialog.setCanceledOnTouchOutside(true); |
| 153 | final Resources res = mContext.getResources(); |
| 154 | final WindowManager.LayoutParams lp = window.getAttributes(); |
John Spurlock | d9c75db | 2015-04-28 11:19:13 -0400 | [diff] [blame] | 155 | lp.type = windowType; |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 156 | lp.format = PixelFormat.TRANSLUCENT; |
| 157 | lp.setTitle(VolumeDialog.class.getSimpleName()); |
| 158 | lp.gravity = Gravity.TOP | Gravity.CENTER_HORIZONTAL; |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 159 | lp.y = res.getDimensionPixelSize(R.dimen.volume_offset_top); |
| 160 | lp.gravity = Gravity.TOP; |
Jorim Jaggi | 6d712e0 | 2015-07-06 16:18:11 -0700 | [diff] [blame] | 161 | lp.windowAnimations = -1; |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 162 | window.setAttributes(lp); |
John Spurlock | 67a0f85 | 2015-06-15 15:35:47 -0400 | [diff] [blame] | 163 | window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING); |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 164 | |
John Spurlock | 77bb25af | 2015-05-11 12:12:07 -0400 | [diff] [blame] | 165 | mActiveSliderTint = loadColorStateList(R.color.system_accent_color); |
| 166 | mInactiveSliderTint = loadColorStateList(R.color.volume_slider_inactive); |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 167 | mDialog.setContentView(R.layout.volume_dialog); |
| 168 | mDialogView = (ViewGroup) mDialog.findViewById(R.id.volume_dialog); |
Jun Mukai | 3f5d713 | 2015-07-21 14:10:09 -0700 | [diff] [blame^] | 169 | mDialogView.setOnHoverListener(new View.OnHoverListener() { |
| 170 | @Override |
| 171 | public boolean onHover(View v, MotionEvent event) { |
| 172 | int action = event.getActionMasked(); |
| 173 | mHovering = (action == MotionEvent.ACTION_HOVER_ENTER) |
| 174 | || (action == MotionEvent.ACTION_HOVER_MOVE); |
| 175 | rescheduleTimeoutH(); |
| 176 | return true; |
| 177 | } |
| 178 | }); |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 179 | mDialogContentView = (ViewGroup) mDialog.findViewById(R.id.volume_dialog_content); |
| 180 | mExpandButton = (ImageButton) mDialogView.findViewById(R.id.volume_expand_button); |
| 181 | mExpandButton.setOnClickListener(mClickExpand); |
| 182 | updateWindowWidthH(); |
| 183 | updateExpandButtonH(); |
| 184 | mLayoutTransition = new LayoutTransition(); |
| 185 | mLayoutTransition.setDuration(new ValueAnimator().getDuration() / 2); |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 186 | mDialogContentView.setLayoutTransition(mLayoutTransition); |
John Spurlock | 22def3d | 2015-06-17 11:56:12 -0400 | [diff] [blame] | 187 | mMotion = new VolumeDialogMotion(mDialog, mDialogView, mDialogContentView, mExpandButton, |
| 188 | new VolumeDialogMotion.Callback() { |
| 189 | @Override |
| 190 | public void onAnimatingChanged(boolean animating) { |
| 191 | if (animating) return; |
| 192 | if (mPendingStateChanged) { |
| 193 | mHandler.sendEmptyMessage(H.STATE_CHANGED); |
| 194 | mPendingStateChanged = false; |
| 195 | } |
| 196 | if (mPendingRecheckAll) { |
| 197 | mHandler.sendEmptyMessage(H.RECHECK_ALL); |
| 198 | mPendingRecheckAll = false; |
| 199 | } |
| 200 | } |
| 201 | }); |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 202 | |
| 203 | addRow(AudioManager.STREAM_RING, |
| 204 | R.drawable.ic_volume_ringer, R.drawable.ic_volume_ringer_mute, true); |
| 205 | addRow(AudioManager.STREAM_MUSIC, |
| 206 | R.drawable.ic_volume_media, R.drawable.ic_volume_media_mute, true); |
| 207 | addRow(AudioManager.STREAM_ALARM, |
| 208 | R.drawable.ic_volume_alarm, R.drawable.ic_volume_alarm_mute, false); |
| 209 | addRow(AudioManager.STREAM_VOICE_CALL, |
| 210 | R.drawable.ic_volume_voice, R.drawable.ic_volume_voice, false); |
| 211 | addRow(AudioManager.STREAM_BLUETOOTH_SCO, |
| 212 | R.drawable.ic_volume_bt_sco, R.drawable.ic_volume_bt_sco, false); |
| 213 | addRow(AudioManager.STREAM_SYSTEM, |
| 214 | R.drawable.ic_volume_system, R.drawable.ic_volume_system_mute, false); |
| 215 | |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 216 | mSettingsButton = mDialog.findViewById(R.id.volume_settings_button); |
| 217 | mSettingsButton.setOnClickListener(mClickSettings); |
| 218 | mExpandButtonAnimationDuration = res.getInteger(R.integer.volume_expand_animation_duration); |
| 219 | mZenFooter = (ZenFooter) mDialog.findViewById(R.id.volume_zen_footer); |
John Spurlock | d9c75db | 2015-04-28 11:19:13 -0400 | [diff] [blame] | 220 | mZenFooter.init(zenModeController); |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 221 | |
John Spurlock | 5adeabc | 2015-05-05 14:50:43 -0400 | [diff] [blame] | 222 | mAccessibility.init(); |
| 223 | |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 224 | controller.addCallback(mControllerCallbackH, mHandler); |
| 225 | controller.getState(); |
| 226 | } |
| 227 | |
John Spurlock | 77bb25af | 2015-05-11 12:12:07 -0400 | [diff] [blame] | 228 | private ColorStateList loadColorStateList(int colorResId) { |
| 229 | return ColorStateList.valueOf(mContext.getColor(colorResId)); |
| 230 | } |
| 231 | |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 232 | private void updateWindowWidthH() { |
| 233 | final ViewGroup.LayoutParams lp = mDialogView.getLayoutParams(); |
| 234 | final DisplayMetrics dm = mContext.getResources().getDisplayMetrics(); |
| 235 | if (D.BUG) Log.d(TAG, "updateWindowWidth dm.w=" + dm.widthPixels); |
| 236 | int w = dm.widthPixels; |
| 237 | final int max = mContext.getResources() |
| 238 | .getDimensionPixelSize(R.dimen.standard_notification_panel_width); |
| 239 | if (w > max) { |
| 240 | w = max; |
| 241 | } |
| 242 | w -= mContext.getResources().getDimensionPixelSize(R.dimen.notification_side_padding) * 2; |
| 243 | lp.width = w; |
| 244 | mDialogView.setLayoutParams(lp); |
| 245 | } |
| 246 | |
| 247 | public void setStreamImportant(int stream, boolean important) { |
| 248 | mHandler.obtainMessage(H.SET_STREAM_IMPORTANT, stream, important ? 1 : 0).sendToTarget(); |
| 249 | } |
| 250 | |
| 251 | public void setShowHeaders(boolean showHeaders) { |
| 252 | if (showHeaders == mShowHeaders) return; |
| 253 | mShowHeaders = showHeaders; |
| 254 | mHandler.sendEmptyMessage(H.RECHECK_ALL); |
| 255 | } |
| 256 | |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 257 | public void setAutomute(boolean automute) { |
| 258 | if (mAutomute == automute) return; |
| 259 | mAutomute = automute; |
| 260 | mHandler.sendEmptyMessage(H.RECHECK_ALL); |
| 261 | } |
| 262 | |
| 263 | public void setSilentMode(boolean silentMode) { |
| 264 | if (mSilentMode == silentMode) return; |
| 265 | mSilentMode = silentMode; |
| 266 | mHandler.sendEmptyMessage(H.RECHECK_ALL); |
| 267 | } |
| 268 | |
| 269 | private void addRow(int stream, int iconRes, int iconMuteRes, boolean important) { |
| 270 | final VolumeRow row = initRow(stream, iconRes, iconMuteRes, important); |
| 271 | if (!mRows.isEmpty()) { |
| 272 | final View v = new View(mContext); |
John Spurlock | 22def3d | 2015-06-17 11:56:12 -0400 | [diff] [blame] | 273 | v.setId(android.R.id.background); |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 274 | final int h = mContext.getResources() |
| 275 | .getDimensionPixelSize(R.dimen.volume_slider_interspacing); |
| 276 | final LinearLayout.LayoutParams lp = |
| 277 | new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, h); |
| 278 | mDialogContentView.addView(v, mDialogContentView.getChildCount() - 1, lp); |
| 279 | row.space = v; |
| 280 | } |
| 281 | row.settingsButton.addOnLayoutChangeListener(new OnLayoutChangeListener() { |
| 282 | @Override |
| 283 | public void onLayoutChange(View v, int left, int top, int right, int bottom, |
| 284 | int oldLeft, int oldTop, int oldRight, int oldBottom) { |
John Spurlock | 22def3d | 2015-06-17 11:56:12 -0400 | [diff] [blame] | 285 | final boolean moved = oldLeft != left || oldTop != top; |
| 286 | if (D.BUG) Log.d(TAG, "onLayoutChange moved=" + moved |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 287 | + " old=" + new Rect(oldLeft, oldTop, oldRight, oldBottom).toShortString() |
| 288 | + " new=" + new Rect(left,top,right,bottom).toShortString()); |
John Spurlock | 22def3d | 2015-06-17 11:56:12 -0400 | [diff] [blame] | 289 | if (moved) { |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 290 | for (int i = 0; i < mDialogContentView.getChildCount(); i++) { |
| 291 | final View c = mDialogContentView.getChildAt(i); |
| 292 | if (!c.isShown()) continue; |
| 293 | if (c == row.view) { |
| 294 | repositionExpandAnim(row); |
| 295 | } |
| 296 | return; |
| 297 | } |
| 298 | } |
| 299 | } |
| 300 | }); |
| 301 | // add new row just before the footer |
| 302 | mDialogContentView.addView(row.view, mDialogContentView.getChildCount() - 1); |
| 303 | mRows.add(row); |
| 304 | } |
| 305 | |
| 306 | private boolean isAttached() { |
| 307 | return mDialogContentView != null && mDialogContentView.isAttachedToWindow(); |
| 308 | } |
| 309 | |
| 310 | private VolumeRow getActiveRow() { |
| 311 | for (VolumeRow row : mRows) { |
| 312 | if (row.stream == mActiveStream) { |
| 313 | return row; |
| 314 | } |
| 315 | } |
| 316 | return mRows.get(0); |
| 317 | } |
| 318 | |
| 319 | private VolumeRow findRow(int stream) { |
| 320 | for (VolumeRow row : mRows) { |
| 321 | if (row.stream == stream) return row; |
| 322 | } |
| 323 | return null; |
| 324 | } |
| 325 | |
| 326 | private void repositionExpandAnim(VolumeRow row) { |
| 327 | final int[] loc = new int[2]; |
| 328 | row.settingsButton.getLocationInWindow(loc); |
| 329 | final MarginLayoutParams mlp = (MarginLayoutParams) mDialogView.getLayoutParams(); |
| 330 | final int x = loc[0] - mlp.leftMargin; |
| 331 | final int y = loc[1] - mlp.topMargin; |
| 332 | if (D.BUG) Log.d(TAG, "repositionExpandAnim x=" + x + " y=" + y); |
| 333 | mExpandButton.setTranslationX(x); |
| 334 | mExpandButton.setTranslationY(y); |
John Spurlock | 22def3d | 2015-06-17 11:56:12 -0400 | [diff] [blame] | 335 | mExpandButton.setTag((Integer) y); |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 336 | } |
| 337 | |
| 338 | public void dump(PrintWriter writer) { |
| 339 | writer.println(VolumeDialog.class.getSimpleName() + " state:"); |
| 340 | writer.print(" mShowing: "); writer.println(mShowing); |
| 341 | writer.print(" mExpanded: "); writer.println(mExpanded); |
John Spurlock | 22def3d | 2015-06-17 11:56:12 -0400 | [diff] [blame] | 342 | writer.print(" mExpandButtonAnimationRunning: "); |
| 343 | writer.println(mExpandButtonAnimationRunning); |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 344 | writer.print(" mActiveStream: "); writer.println(mActiveStream); |
| 345 | writer.print(" mDynamic: "); writer.println(mDynamic); |
| 346 | writer.print(" mShowHeaders: "); writer.println(mShowHeaders); |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 347 | writer.print(" mAutomute: "); writer.println(mAutomute); |
| 348 | writer.print(" mSilentMode: "); writer.println(mSilentMode); |
John Spurlock | 22def3d | 2015-06-17 11:56:12 -0400 | [diff] [blame] | 349 | writer.print(" mCollapseTime: "); writer.println(mCollapseTime); |
John Spurlock | 84ee67c | 2015-05-20 23:33:43 -0400 | [diff] [blame] | 350 | writer.print(" mAccessibility.mFeedbackEnabled: "); |
| 351 | writer.println(mAccessibility.mFeedbackEnabled); |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 352 | } |
| 353 | |
| 354 | private static int getImpliedLevel(SeekBar seekBar, int progress) { |
| 355 | final int m = seekBar.getMax(); |
| 356 | final int n = m / 100 - 1; |
| 357 | final int level = progress == 0 ? 0 |
| 358 | : progress == m ? (m / 100) : (1 + (int)((progress / (float) m) * n)); |
| 359 | return level; |
| 360 | } |
| 361 | |
| 362 | @SuppressLint("InflateParams") |
| 363 | private VolumeRow initRow(final int stream, int iconRes, int iconMuteRes, boolean important) { |
| 364 | final VolumeRow row = new VolumeRow(); |
| 365 | row.stream = stream; |
| 366 | row.iconRes = iconRes; |
| 367 | row.iconMuteRes = iconMuteRes; |
| 368 | row.important = important; |
| 369 | row.view = mDialog.getLayoutInflater().inflate(R.layout.volume_dialog_row, null); |
| 370 | row.view.setTag(row); |
| 371 | row.header = (TextView) row.view.findViewById(R.id.volume_row_header); |
| 372 | mSpTexts.add(row.header); |
| 373 | row.slider = (SeekBar) row.view.findViewById(R.id.volume_row_slider); |
| 374 | row.slider.setOnSeekBarChangeListener(new VolumeSeekBarChangeListener(row)); |
| 375 | |
| 376 | // forward events above the slider into the slider |
| 377 | row.view.setOnTouchListener(new OnTouchListener() { |
| 378 | private final Rect mSliderHitRect = new Rect(); |
| 379 | private boolean mDragging; |
| 380 | |
| 381 | @SuppressLint("ClickableViewAccessibility") |
| 382 | @Override |
| 383 | public boolean onTouch(View v, MotionEvent event) { |
| 384 | row.slider.getHitRect(mSliderHitRect); |
| 385 | if (!mDragging && event.getActionMasked() == MotionEvent.ACTION_DOWN |
| 386 | && event.getY() < mSliderHitRect.top) { |
| 387 | mDragging = true; |
| 388 | } |
| 389 | if (mDragging) { |
| 390 | event.offsetLocation(-mSliderHitRect.left, -mSliderHitRect.top); |
| 391 | row.slider.dispatchTouchEvent(event); |
| 392 | if (event.getActionMasked() == MotionEvent.ACTION_UP |
| 393 | || event.getActionMasked() == MotionEvent.ACTION_CANCEL) { |
| 394 | mDragging = false; |
| 395 | } |
| 396 | return true; |
| 397 | } |
| 398 | return false; |
| 399 | } |
| 400 | }); |
| 401 | row.icon = (ImageButton) row.view.findViewById(R.id.volume_row_icon); |
| 402 | row.icon.setImageResource(iconRes); |
| 403 | row.icon.setOnClickListener(new OnClickListener() { |
| 404 | @Override |
| 405 | public void onClick(View v) { |
Chris Wren | e565ee6 | 2015-06-17 15:24:56 -0400 | [diff] [blame] | 406 | Events.writeEvent(mContext, Events.EVENT_ICON_CLICK, row.stream, row.iconState); |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 407 | mController.setActiveStream(row.stream); |
| 408 | if (row.stream == AudioManager.STREAM_RING) { |
| 409 | final boolean hasVibrator = mController.hasVibrator(); |
| 410 | if (mState.ringerModeInternal == AudioManager.RINGER_MODE_NORMAL) { |
| 411 | if (hasVibrator) { |
| 412 | mController.setRingerMode(AudioManager.RINGER_MODE_VIBRATE, false); |
| 413 | } else { |
| 414 | final boolean wasZero = row.ss.level == 0; |
| 415 | mController.setStreamVolume(stream, wasZero ? row.lastAudibleLevel : 0); |
| 416 | } |
| 417 | } else { |
| 418 | mController.setRingerMode(AudioManager.RINGER_MODE_NORMAL, false); |
| 419 | if (row.ss.level == 0) { |
| 420 | mController.setStreamVolume(stream, 1); |
| 421 | } |
| 422 | } |
| 423 | } else { |
John Spurlock | b0a2e5f | 2015-06-09 14:41:52 -0400 | [diff] [blame] | 424 | final boolean vmute = row.ss.level == 0; |
| 425 | mController.setStreamVolume(stream, vmute ? row.lastAudibleLevel : 0); |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 426 | } |
| 427 | row.userAttempt = 0; // reset the grace period, slider should update immediately |
| 428 | } |
| 429 | }); |
| 430 | row.settingsButton = (ImageButton) row.view.findViewById(R.id.volume_settings_button); |
| 431 | row.settingsButton.setOnClickListener(mClickSettings); |
| 432 | return row; |
| 433 | } |
| 434 | |
| 435 | public void destroy() { |
| 436 | mController.removeCallback(mControllerCallbackH); |
| 437 | } |
| 438 | |
| 439 | public void show(int reason) { |
| 440 | mHandler.obtainMessage(H.SHOW, reason, 0).sendToTarget(); |
| 441 | } |
| 442 | |
| 443 | public void dismiss(int reason) { |
| 444 | mHandler.obtainMessage(H.DISMISS, reason, 0).sendToTarget(); |
| 445 | } |
| 446 | |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 447 | private void showH(int reason) { |
John Spurlock | 22def3d | 2015-06-17 11:56:12 -0400 | [diff] [blame] | 448 | if (D.BUG) Log.d(TAG, "showH r=" + Events.DISMISS_REASONS[reason]); |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 449 | mHandler.removeMessages(H.SHOW); |
| 450 | mHandler.removeMessages(H.DISMISS); |
| 451 | rescheduleTimeoutH(); |
| 452 | if (mShowing) return; |
| 453 | mShowing = true; |
John Spurlock | 22def3d | 2015-06-17 11:56:12 -0400 | [diff] [blame] | 454 | mMotion.startShow(); |
Chris Wren | e565ee6 | 2015-06-17 15:24:56 -0400 | [diff] [blame] | 455 | Events.writeEvent(mContext, Events.EVENT_SHOW_DIALOG, reason, mKeyguard.isKeyguardLocked()); |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 456 | mController.notifyVisible(true); |
| 457 | } |
| 458 | |
| 459 | protected void rescheduleTimeoutH() { |
| 460 | mHandler.removeMessages(H.DISMISS); |
John Spurlock | f09838b | 2015-06-11 16:14:44 -0400 | [diff] [blame] | 461 | final int timeout = computeTimeoutH(); |
| 462 | mHandler.sendMessageDelayed(mHandler |
| 463 | .obtainMessage(H.DISMISS, Events.DISMISS_REASON_TIMEOUT, 0), timeout); |
John Spurlock | 5adeabc | 2015-05-05 14:50:43 -0400 | [diff] [blame] | 464 | if (D.BUG) Log.d(TAG, "rescheduleTimeout " + timeout + " " + Debug.getCaller()); |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 465 | mController.userActivity(); |
| 466 | } |
| 467 | |
| 468 | private int computeTimeoutH() { |
John Spurlock | f09838b | 2015-06-11 16:14:44 -0400 | [diff] [blame] | 469 | if (mAccessibility.mFeedbackEnabled) return 20000; |
Jun Mukai | 3f5d713 | 2015-07-21 14:10:09 -0700 | [diff] [blame^] | 470 | if (mHovering) return 16000; |
John Spurlock | 76b52b3 | 2015-04-03 00:00:12 -0400 | [diff] [blame] | 471 | if (mSafetyWarning != null) return 5000; |
John Spurlock | 22def3d | 2015-06-17 11:56:12 -0400 | [diff] [blame] | 472 | if (mExpanded || mExpandButtonAnimationRunning) return 5000; |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 473 | if (mActiveStream == AudioManager.STREAM_MUSIC) return 1500; |
| 474 | return 3000; |
| 475 | } |
| 476 | |
| 477 | protected void dismissH(int reason) { |
Jason Monk | 305e0ba | 2015-07-06 15:53:59 -0400 | [diff] [blame] | 478 | if (mMotion.isAnimating()) { |
| 479 | return; |
| 480 | } |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 481 | mHandler.removeMessages(H.DISMISS); |
| 482 | mHandler.removeMessages(H.SHOW); |
| 483 | if (!mShowing) return; |
| 484 | mShowing = false; |
John Spurlock | 22def3d | 2015-06-17 11:56:12 -0400 | [diff] [blame] | 485 | mMotion.startDismiss(new Runnable() { |
| 486 | @Override |
| 487 | public void run() { |
| 488 | setExpandedH(false); |
| 489 | } |
| 490 | }); |
Chris Wren | e565ee6 | 2015-06-17 15:24:56 -0400 | [diff] [blame] | 491 | Events.writeEvent(mContext, Events.EVENT_DISMISS_DIALOG, reason); |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 492 | mController.notifyVisible(false); |
John Spurlock | 76b52b3 | 2015-04-03 00:00:12 -0400 | [diff] [blame] | 493 | synchronized (mSafetyWarningLock) { |
| 494 | if (mSafetyWarning != null) { |
| 495 | if (D.BUG) Log.d(TAG, "SafetyWarning dismissed"); |
| 496 | mSafetyWarning.dismiss(); |
| 497 | } |
| 498 | } |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 499 | } |
| 500 | |
John Spurlock | 22def3d | 2015-06-17 11:56:12 -0400 | [diff] [blame] | 501 | private void updateDialogBottomMarginH() { |
| 502 | final long diff = System.currentTimeMillis() - mCollapseTime; |
| 503 | final boolean collapsing = mCollapseTime != 0 && diff < getConservativeCollapseDuration(); |
| 504 | final ViewGroup.MarginLayoutParams mlp = (MarginLayoutParams) mDialogView.getLayoutParams(); |
| 505 | final int bottomMargin = collapsing ? mDialogContentView.getHeight() : |
| 506 | mContext.getResources().getDimensionPixelSize(R.dimen.volume_dialog_margin_bottom); |
| 507 | if (bottomMargin != mlp.bottomMargin) { |
| 508 | if (D.BUG) Log.d(TAG, "bottomMargin " + mlp.bottomMargin + " -> " + bottomMargin); |
| 509 | mlp.bottomMargin = bottomMargin; |
| 510 | mDialogView.setLayoutParams(mlp); |
| 511 | } |
| 512 | } |
| 513 | |
| 514 | private long getConservativeCollapseDuration() { |
| 515 | return mExpandButtonAnimationDuration * 3; |
| 516 | } |
| 517 | |
| 518 | private void prepareForCollapse() { |
| 519 | mHandler.removeMessages(H.UPDATE_BOTTOM_MARGIN); |
| 520 | mCollapseTime = System.currentTimeMillis(); |
| 521 | updateDialogBottomMarginH(); |
| 522 | mHandler.sendEmptyMessageDelayed(H.UPDATE_BOTTOM_MARGIN, getConservativeCollapseDuration()); |
| 523 | } |
| 524 | |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 525 | private void setExpandedH(boolean expanded) { |
| 526 | if (mExpanded == expanded) return; |
| 527 | mExpanded = expanded; |
John Spurlock | 22def3d | 2015-06-17 11:56:12 -0400 | [diff] [blame] | 528 | mExpandButtonAnimationRunning = isAttached(); |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 529 | if (D.BUG) Log.d(TAG, "setExpandedH " + expanded); |
John Spurlock | 22def3d | 2015-06-17 11:56:12 -0400 | [diff] [blame] | 530 | if (!mExpanded && mExpandButtonAnimationRunning) { |
| 531 | prepareForCollapse(); |
| 532 | } |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 533 | updateRowsH(); |
John Spurlock | 22def3d | 2015-06-17 11:56:12 -0400 | [diff] [blame] | 534 | if (mExpandButtonAnimationRunning) { |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 535 | final Drawable d = mExpandButton.getDrawable(); |
| 536 | if (d instanceof AnimatedVectorDrawable) { |
| 537 | // workaround to reset drawable |
| 538 | final AnimatedVectorDrawable avd = (AnimatedVectorDrawable) d.getConstantState() |
| 539 | .newDrawable(); |
| 540 | mExpandButton.setImageDrawable(avd); |
| 541 | avd.start(); |
| 542 | mHandler.postDelayed(new Runnable() { |
| 543 | @Override |
| 544 | public void run() { |
John Spurlock | 22def3d | 2015-06-17 11:56:12 -0400 | [diff] [blame] | 545 | mExpandButtonAnimationRunning = false; |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 546 | updateExpandButtonH(); |
| 547 | rescheduleTimeoutH(); |
| 548 | } |
| 549 | }, mExpandButtonAnimationDuration); |
| 550 | } |
| 551 | } |
| 552 | rescheduleTimeoutH(); |
| 553 | } |
| 554 | |
| 555 | private void updateExpandButtonH() { |
John Spurlock | 22def3d | 2015-06-17 11:56:12 -0400 | [diff] [blame] | 556 | if (D.BUG) Log.d(TAG, "updateExpandButtonH"); |
| 557 | mExpandButton.setClickable(!mExpandButtonAnimationRunning); |
| 558 | if (mExpandButtonAnimationRunning && isAttached()) return; |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 559 | final int res = mExpanded ? R.drawable.ic_volume_collapse_animation |
| 560 | : R.drawable.ic_volume_expand_animation; |
John Spurlock | 76b52b3 | 2015-04-03 00:00:12 -0400 | [diff] [blame] | 561 | if (res == mExpandButtonRes) return; |
| 562 | mExpandButtonRes = res; |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 563 | mExpandButton.setImageResource(res); |
John Spurlock | 5adeabc | 2015-05-05 14:50:43 -0400 | [diff] [blame] | 564 | mExpandButton.setContentDescription(mContext.getString(mExpanded ? |
| 565 | R.string.accessibility_volume_collapse : R.string.accessibility_volume_expand)); |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 566 | } |
| 567 | |
| 568 | private boolean isVisibleH(VolumeRow row, boolean isActive) { |
| 569 | return mExpanded && row.view.getVisibility() == View.VISIBLE |
| 570 | || (mExpanded && (row.important || isActive)) |
| 571 | || !mExpanded && isActive; |
| 572 | } |
| 573 | |
| 574 | private void updateRowsH() { |
John Spurlock | 22def3d | 2015-06-17 11:56:12 -0400 | [diff] [blame] | 575 | if (D.BUG) Log.d(TAG, "updateRowsH"); |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 576 | final VolumeRow activeRow = getActiveRow(); |
| 577 | updateFooterH(); |
| 578 | updateExpandButtonH(); |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 579 | if (!mShowing) { |
| 580 | trimObsoleteH(); |
| 581 | } |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 582 | // apply changes to all rows |
| 583 | for (VolumeRow row : mRows) { |
| 584 | final boolean isActive = row == activeRow; |
| 585 | final boolean visible = isVisibleH(row, isActive); |
| 586 | Util.setVisOrGone(row.view, visible); |
| 587 | Util.setVisOrGone(row.space, visible && mExpanded); |
| 588 | final int expandButtonRes = mExpanded ? R.drawable.ic_volume_settings : 0; |
| 589 | if (expandButtonRes != row.cachedExpandButtonRes) { |
| 590 | row.cachedExpandButtonRes = expandButtonRes; |
| 591 | if (expandButtonRes == 0) { |
| 592 | row.settingsButton.setImageDrawable(null); |
| 593 | } else { |
| 594 | row.settingsButton.setImageResource(expandButtonRes); |
| 595 | } |
| 596 | } |
John Spurlock | d9c75db | 2015-04-28 11:19:13 -0400 | [diff] [blame] | 597 | Util.setVisOrInvis(row.settingsButton, false); |
John Spurlock | 0265657 | 2015-06-10 09:33:34 -0400 | [diff] [blame] | 598 | updateVolumeRowHeaderVisibleH(row); |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 599 | row.header.setAlpha(mExpanded && isActive ? 1 : 0.5f); |
John Spurlock | ecc8058 | 2015-05-13 16:23:14 -0400 | [diff] [blame] | 600 | updateVolumeRowSliderTintH(row, isActive); |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 601 | } |
| 602 | } |
| 603 | |
| 604 | private void trimObsoleteH() { |
John Spurlock | 22def3d | 2015-06-17 11:56:12 -0400 | [diff] [blame] | 605 | if (D.BUG) Log.d(TAG, "trimObsoleteH"); |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 606 | for (int i = mRows.size() -1; i >= 0; i--) { |
| 607 | final VolumeRow row = mRows.get(i); |
| 608 | if (row.ss == null || !row.ss.dynamic) continue; |
| 609 | if (!mDynamic.get(row.stream)) { |
| 610 | mRows.remove(i); |
| 611 | mDialogContentView.removeView(row.view); |
| 612 | mDialogContentView.removeView(row.space); |
| 613 | } |
| 614 | } |
| 615 | } |
| 616 | |
| 617 | private void onStateChangedH(State state) { |
John Spurlock | 22def3d | 2015-06-17 11:56:12 -0400 | [diff] [blame] | 618 | final boolean animating = mMotion.isAnimating(); |
| 619 | if (D.BUG) Log.d(TAG, "onStateChangedH animating=" + animating); |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 620 | mState = state; |
John Spurlock | 22def3d | 2015-06-17 11:56:12 -0400 | [diff] [blame] | 621 | if (animating) { |
| 622 | mPendingStateChanged = true; |
| 623 | return; |
| 624 | } |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 625 | mDynamic.clear(); |
| 626 | // add any new dynamic rows |
| 627 | for (int i = 0; i < state.states.size(); i++) { |
| 628 | final int stream = state.states.keyAt(i); |
| 629 | final StreamState ss = state.states.valueAt(i); |
| 630 | if (!ss.dynamic) continue; |
| 631 | mDynamic.put(stream, true); |
| 632 | if (findRow(stream) == null) { |
| 633 | addRow(stream, R.drawable.ic_volume_remote, R.drawable.ic_volume_remote_mute, true); |
| 634 | } |
| 635 | } |
| 636 | |
| 637 | if (mActiveStream != state.activeStream) { |
| 638 | mActiveStream = state.activeStream; |
| 639 | updateRowsH(); |
| 640 | rescheduleTimeoutH(); |
| 641 | } |
| 642 | for (VolumeRow row : mRows) { |
| 643 | updateVolumeRowH(row); |
| 644 | } |
| 645 | updateFooterH(); |
| 646 | } |
| 647 | |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 648 | private void updateFooterH() { |
John Spurlock | 22def3d | 2015-06-17 11:56:12 -0400 | [diff] [blame] | 649 | if (D.BUG) Log.d(TAG, "updateFooterH"); |
| 650 | final boolean wasVisible = mZenFooter.getVisibility() == View.VISIBLE; |
| 651 | final boolean visible = mState.zenMode != Global.ZEN_MODE_OFF; |
| 652 | if (wasVisible != visible && !visible) { |
| 653 | prepareForCollapse(); |
| 654 | } |
| 655 | Util.setVisOrGone(mZenFooter, visible); |
John Spurlock | d9c75db | 2015-04-28 11:19:13 -0400 | [diff] [blame] | 656 | mZenFooter.update(); |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 657 | } |
| 658 | |
| 659 | private void updateVolumeRowH(VolumeRow row) { |
John Spurlock | 22def3d | 2015-06-17 11:56:12 -0400 | [diff] [blame] | 660 | if (D.BUG) Log.d(TAG, "updateVolumeRowH s=" + row.stream); |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 661 | if (mState == null) return; |
| 662 | final StreamState ss = mState.states.get(row.stream); |
| 663 | if (ss == null) return; |
| 664 | row.ss = ss; |
| 665 | if (ss.level > 0) { |
| 666 | row.lastAudibleLevel = ss.level; |
| 667 | } |
John Spurlock | b0a2e5f | 2015-06-09 14:41:52 -0400 | [diff] [blame] | 668 | if (ss.level == row.requestedLevel) { |
| 669 | row.requestedLevel = -1; |
| 670 | } |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 671 | final boolean isRingStream = row.stream == AudioManager.STREAM_RING; |
| 672 | final boolean isSystemStream = row.stream == AudioManager.STREAM_SYSTEM; |
John Spurlock | d9c75db | 2015-04-28 11:19:13 -0400 | [diff] [blame] | 673 | final boolean isAlarmStream = row.stream == AudioManager.STREAM_ALARM; |
| 674 | final boolean isMusicStream = row.stream == AudioManager.STREAM_MUSIC; |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 675 | final boolean isRingVibrate = isRingStream |
| 676 | && mState.ringerModeInternal == AudioManager.RINGER_MODE_VIBRATE; |
John Spurlock | d9c75db | 2015-04-28 11:19:13 -0400 | [diff] [blame] | 677 | final boolean isRingSilent = isRingStream |
| 678 | && mState.ringerModeInternal == AudioManager.RINGER_MODE_SILENT; |
| 679 | final boolean isZenAlarms = mState.zenMode == Global.ZEN_MODE_ALARMS; |
| 680 | final boolean isZenNone = mState.zenMode == Global.ZEN_MODE_NO_INTERRUPTIONS; |
| 681 | final boolean isZenPriority = mState.zenMode == Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS; |
| 682 | final boolean isRingZenNone = (isRingStream || isSystemStream) && isZenNone; |
| 683 | final boolean isRingLimited = isRingStream && isZenPriority; |
| 684 | final boolean zenMuted = isZenAlarms ? (isRingStream || isSystemStream) |
| 685 | : isZenNone ? (isRingStream || isSystemStream || isAlarmStream || isMusicStream) |
| 686 | : false; |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 687 | |
| 688 | // update slider max |
| 689 | final int max = ss.levelMax * 100; |
| 690 | if (max != row.slider.getMax()) { |
| 691 | row.slider.setMax(max); |
| 692 | } |
| 693 | |
| 694 | // update header visible |
John Spurlock | 0265657 | 2015-06-10 09:33:34 -0400 | [diff] [blame] | 695 | updateVolumeRowHeaderVisibleH(row); |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 696 | |
| 697 | // update header text |
John Spurlock | 0265657 | 2015-06-10 09:33:34 -0400 | [diff] [blame] | 698 | String text = ss.name; |
| 699 | if (mShowHeaders) { |
| 700 | if (isRingZenNone) { |
| 701 | text = mContext.getString(R.string.volume_stream_muted_dnd, ss.name); |
| 702 | } else if (isRingVibrate && isRingLimited) { |
| 703 | text = mContext.getString(R.string.volume_stream_vibrate_dnd, ss.name); |
| 704 | } else if (isRingVibrate) { |
| 705 | text = mContext.getString(R.string.volume_stream_vibrate, ss.name); |
| 706 | } else if (ss.muted || mAutomute && ss.level == 0) { |
| 707 | text = mContext.getString(R.string.volume_stream_muted, ss.name); |
| 708 | } else if (isRingLimited) { |
| 709 | text = mContext.getString(R.string.volume_stream_limited_dnd, ss.name); |
| 710 | } |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 711 | } |
| 712 | Util.setText(row.header, text); |
| 713 | |
| 714 | // update icon |
John Spurlock | d9c75db | 2015-04-28 11:19:13 -0400 | [diff] [blame] | 715 | final boolean iconEnabled = (mAutomute || ss.muteSupported) && !zenMuted; |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 716 | row.icon.setEnabled(iconEnabled); |
| 717 | row.icon.setAlpha(iconEnabled ? 1 : 0.5f); |
| 718 | final int iconRes = |
John Spurlock | 76b52b3 | 2015-04-03 00:00:12 -0400 | [diff] [blame] | 719 | isRingVibrate ? R.drawable.ic_volume_ringer_vibrate |
John Spurlock | d9c75db | 2015-04-28 11:19:13 -0400 | [diff] [blame] | 720 | : isRingSilent || zenMuted ? row.cachedIconRes |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 721 | : ss.routedToBluetooth ? |
John Spurlock | f15ef11 | 2015-04-09 22:04:14 -0400 | [diff] [blame] | 722 | (ss.muted ? R.drawable.ic_volume_media_bt_mute |
| 723 | : R.drawable.ic_volume_media_bt) |
John Spurlock | 76b52b3 | 2015-04-03 00:00:12 -0400 | [diff] [blame] | 724 | : mAutomute && ss.level == 0 ? row.iconMuteRes |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 725 | : (ss.muted ? row.iconMuteRes : row.iconRes); |
| 726 | if (iconRes != row.cachedIconRes) { |
| 727 | if (row.cachedIconRes != 0 && isRingVibrate) { |
| 728 | mController.vibrate(); |
| 729 | } |
| 730 | row.cachedIconRes = iconRes; |
| 731 | row.icon.setImageResource(iconRes); |
| 732 | } |
| 733 | row.iconState = |
| 734 | iconRes == R.drawable.ic_volume_ringer_vibrate ? Events.ICON_STATE_VIBRATE |
John Spurlock | f15ef11 | 2015-04-09 22:04:14 -0400 | [diff] [blame] | 735 | : (iconRes == R.drawable.ic_volume_media_bt_mute || iconRes == row.iconMuteRes) |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 736 | ? Events.ICON_STATE_MUTE |
John Spurlock | f15ef11 | 2015-04-09 22:04:14 -0400 | [diff] [blame] | 737 | : (iconRes == R.drawable.ic_volume_media_bt || iconRes == row.iconRes) |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 738 | ? Events.ICON_STATE_UNMUTE |
| 739 | : Events.ICON_STATE_UNKNOWN; |
John Spurlock | 5adeabc | 2015-05-05 14:50:43 -0400 | [diff] [blame] | 740 | row.icon.setContentDescription(ss.name); |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 741 | |
| 742 | // update slider |
John Spurlock | b0a2e5f | 2015-06-09 14:41:52 -0400 | [diff] [blame] | 743 | final boolean enableSlider = !zenMuted; |
| 744 | final int vlevel = row.ss.muted && (isRingVibrate || !isRingStream && !zenMuted) ? 0 |
| 745 | : row.ss.level; |
| 746 | updateVolumeRowSliderH(row, enableSlider, vlevel); |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 747 | } |
| 748 | |
John Spurlock | 0265657 | 2015-06-10 09:33:34 -0400 | [diff] [blame] | 749 | private void updateVolumeRowHeaderVisibleH(VolumeRow row) { |
| 750 | final boolean dynamic = row.ss != null && row.ss.dynamic; |
| 751 | final boolean showHeaders = mShowHeaders || mExpanded && dynamic; |
| 752 | if (row.cachedShowHeaders != showHeaders) { |
| 753 | row.cachedShowHeaders = showHeaders; |
| 754 | Util.setVisOrGone(row.header, showHeaders); |
| 755 | } |
| 756 | } |
| 757 | |
John Spurlock | ecc8058 | 2015-05-13 16:23:14 -0400 | [diff] [blame] | 758 | private void updateVolumeRowSliderTintH(VolumeRow row, boolean isActive) { |
John Spurlock | 67a0f85 | 2015-06-15 15:35:47 -0400 | [diff] [blame] | 759 | if (isActive && mExpanded) { |
John Spurlock | 67a0f85 | 2015-06-15 15:35:47 -0400 | [diff] [blame] | 760 | row.slider.requestFocus(); |
John Spurlock | 67a0f85 | 2015-06-15 15:35:47 -0400 | [diff] [blame] | 761 | } |
John Spurlock | ecc8058 | 2015-05-13 16:23:14 -0400 | [diff] [blame] | 762 | final ColorStateList tint = isActive && row.slider.isEnabled() ? mActiveSliderTint |
| 763 | : mInactiveSliderTint; |
| 764 | if (tint == row.cachedSliderTint) return; |
| 765 | row.cachedSliderTint = tint; |
| 766 | row.slider.setProgressTintList(tint); |
| 767 | row.slider.setThumbTintList(tint); |
| 768 | } |
| 769 | |
John Spurlock | b0a2e5f | 2015-06-09 14:41:52 -0400 | [diff] [blame] | 770 | private void updateVolumeRowSliderH(VolumeRow row, boolean enable, int vlevel) { |
| 771 | row.slider.setEnabled(enable); |
John Spurlock | ecc8058 | 2015-05-13 16:23:14 -0400 | [diff] [blame] | 772 | updateVolumeRowSliderTintH(row, row.stream == mActiveStream); |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 773 | if (row.tracking) { |
| 774 | return; // don't update if user is sliding |
| 775 | } |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 776 | final int progress = row.slider.getProgress(); |
| 777 | final int level = getImpliedLevel(row.slider, progress); |
| 778 | final boolean rowVisible = row.view.getVisibility() == View.VISIBLE; |
| 779 | final boolean inGracePeriod = (SystemClock.uptimeMillis() - row.userAttempt) |
| 780 | < USER_ATTEMPT_GRACE_PERIOD; |
| 781 | mHandler.removeMessages(H.RECHECK, row); |
| 782 | if (mShowing && rowVisible && inGracePeriod) { |
| 783 | if (D.BUG) Log.d(TAG, "inGracePeriod"); |
| 784 | mHandler.sendMessageAtTime(mHandler.obtainMessage(H.RECHECK, row), |
| 785 | row.userAttempt + USER_ATTEMPT_GRACE_PERIOD); |
| 786 | return; // don't update if visible and in grace period |
| 787 | } |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 788 | if (vlevel == level) { |
| 789 | if (mShowing && rowVisible) { |
| 790 | return; // don't clamp if visible |
| 791 | } |
| 792 | } |
| 793 | final int newProgress = vlevel * 100; |
| 794 | if (progress != newProgress) { |
| 795 | if (mShowing && rowVisible) { |
| 796 | // animate! |
| 797 | if (row.anim != null && row.anim.isRunning() |
| 798 | && row.animTargetProgress == newProgress) { |
| 799 | return; // already animating to the target progress |
| 800 | } |
| 801 | // start/update animation |
| 802 | if (row.anim == null) { |
| 803 | row.anim = ObjectAnimator.ofInt(row.slider, "progress", progress, newProgress); |
| 804 | row.anim.setInterpolator(new DecelerateInterpolator()); |
| 805 | } else { |
| 806 | row.anim.cancel(); |
| 807 | row.anim.setIntValues(progress, newProgress); |
| 808 | } |
| 809 | row.animTargetProgress = newProgress; |
| 810 | row.anim.setDuration(UPDATE_ANIMATION_DURATION); |
| 811 | row.anim.start(); |
| 812 | } else { |
| 813 | // update slider directly to clamped value |
| 814 | if (row.anim != null) { |
| 815 | row.anim.cancel(); |
| 816 | } |
| 817 | row.slider.setProgress(newProgress); |
| 818 | } |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 819 | } |
| 820 | } |
| 821 | |
| 822 | private void recheckH(VolumeRow row) { |
| 823 | if (row == null) { |
| 824 | if (D.BUG) Log.d(TAG, "recheckH ALL"); |
| 825 | trimObsoleteH(); |
| 826 | for (VolumeRow r : mRows) { |
| 827 | updateVolumeRowH(r); |
| 828 | } |
| 829 | } else { |
| 830 | if (D.BUG) Log.d(TAG, "recheckH " + row.stream); |
| 831 | updateVolumeRowH(row); |
| 832 | } |
| 833 | } |
| 834 | |
| 835 | private void setStreamImportantH(int stream, boolean important) { |
| 836 | for (VolumeRow row : mRows) { |
| 837 | if (row.stream == stream) { |
| 838 | row.important = important; |
| 839 | return; |
| 840 | } |
| 841 | } |
| 842 | } |
| 843 | |
John Spurlock | 76b52b3 | 2015-04-03 00:00:12 -0400 | [diff] [blame] | 844 | private void showSafetyWarningH(int flags) { |
| 845 | if ((flags & (AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_SHOW_UI_WARNINGS)) != 0 |
| 846 | || mShowing) { |
| 847 | synchronized (mSafetyWarningLock) { |
| 848 | if (mSafetyWarning != null) { |
| 849 | return; |
| 850 | } |
| 851 | mSafetyWarning = new SafetyWarningDialog(mContext, mController.getAudioManager()) { |
| 852 | @Override |
| 853 | protected void cleanUp() { |
| 854 | synchronized (mSafetyWarningLock) { |
| 855 | mSafetyWarning = null; |
| 856 | } |
| 857 | recheckH(null); |
| 858 | } |
| 859 | }; |
| 860 | mSafetyWarning.show(); |
| 861 | } |
| 862 | recheckH(null); |
| 863 | } |
| 864 | rescheduleTimeoutH(); |
| 865 | } |
| 866 | |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 867 | private final VolumeDialogController.Callbacks mControllerCallbackH |
| 868 | = new VolumeDialogController.Callbacks() { |
| 869 | @Override |
| 870 | public void onShowRequested(int reason) { |
| 871 | showH(reason); |
| 872 | } |
| 873 | |
| 874 | @Override |
| 875 | public void onDismissRequested(int reason) { |
| 876 | dismissH(reason); |
| 877 | } |
| 878 | |
John Spurlock | 76b52b3 | 2015-04-03 00:00:12 -0400 | [diff] [blame] | 879 | @Override |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 880 | public void onScreenOff() { |
| 881 | dismissH(Events.DISMISS_REASON_SCREEN_OFF); |
| 882 | } |
| 883 | |
| 884 | @Override |
| 885 | public void onStateChanged(State state) { |
| 886 | onStateChangedH(state); |
| 887 | } |
| 888 | |
| 889 | @Override |
| 890 | public void onLayoutDirectionChanged(int layoutDirection) { |
| 891 | mDialogView.setLayoutDirection(layoutDirection); |
| 892 | } |
| 893 | |
| 894 | @Override |
| 895 | public void onConfigurationChanged() { |
| 896 | updateWindowWidthH(); |
| 897 | mSpTexts.update(); |
John Spurlock | 9ea3a1e | 2015-05-06 17:12:18 -0400 | [diff] [blame] | 898 | mZenFooter.onConfigurationChanged(); |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 899 | } |
| 900 | |
| 901 | @Override |
| 902 | public void onShowVibrateHint() { |
| 903 | if (mSilentMode) { |
| 904 | mController.setRingerMode(AudioManager.RINGER_MODE_SILENT, false); |
| 905 | } |
| 906 | } |
| 907 | |
John Spurlock | 76b52b3 | 2015-04-03 00:00:12 -0400 | [diff] [blame] | 908 | @Override |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 909 | public void onShowSilentHint() { |
| 910 | if (mSilentMode) { |
| 911 | mController.setRingerMode(AudioManager.RINGER_MODE_NORMAL, false); |
| 912 | } |
| 913 | } |
John Spurlock | 76b52b3 | 2015-04-03 00:00:12 -0400 | [diff] [blame] | 914 | |
| 915 | @Override |
| 916 | public void onShowSafetyWarning(int flags) { |
| 917 | showSafetyWarningH(flags); |
| 918 | } |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 919 | }; |
| 920 | |
| 921 | private final OnClickListener mClickExpand = new OnClickListener() { |
| 922 | @Override |
| 923 | public void onClick(View v) { |
John Spurlock | 22def3d | 2015-06-17 11:56:12 -0400 | [diff] [blame] | 924 | if (mExpandButtonAnimationRunning) return; |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 925 | final boolean newExpand = !mExpanded; |
Chris Wren | e565ee6 | 2015-06-17 15:24:56 -0400 | [diff] [blame] | 926 | Events.writeEvent(mContext, Events.EVENT_EXPAND, newExpand); |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 927 | setExpandedH(newExpand); |
| 928 | } |
| 929 | }; |
| 930 | |
| 931 | private final OnClickListener mClickSettings = new OnClickListener() { |
| 932 | @Override |
| 933 | public void onClick(View v) { |
| 934 | mSettingsButton.postDelayed(new Runnable() { |
| 935 | @Override |
| 936 | public void run() { |
Chris Wren | e565ee6 | 2015-06-17 15:24:56 -0400 | [diff] [blame] | 937 | Events.writeEvent(mContext, Events.EVENT_SETTINGS_CLICK); |
John Spurlock | f55b7f2 | 2015-04-13 19:21:26 -0400 | [diff] [blame] | 938 | if (mCallback != null) { |
| 939 | mCallback.onSettingsClicked(); |
| 940 | } |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 941 | } |
| 942 | }, WAIT_FOR_RIPPLE); |
| 943 | } |
| 944 | }; |
| 945 | |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 946 | private final class H extends Handler { |
| 947 | private static final int SHOW = 1; |
| 948 | private static final int DISMISS = 2; |
| 949 | private static final int RECHECK = 3; |
| 950 | private static final int RECHECK_ALL = 4; |
| 951 | private static final int SET_STREAM_IMPORTANT = 5; |
| 952 | private static final int RESCHEDULE_TIMEOUT = 6; |
John Spurlock | 22def3d | 2015-06-17 11:56:12 -0400 | [diff] [blame] | 953 | private static final int STATE_CHANGED = 7; |
| 954 | private static final int UPDATE_BOTTOM_MARGIN = 8; |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 955 | |
| 956 | public H() { |
| 957 | super(Looper.getMainLooper()); |
| 958 | } |
| 959 | |
| 960 | @Override |
| 961 | public void handleMessage(Message msg) { |
| 962 | switch (msg.what) { |
| 963 | case SHOW: showH(msg.arg1); break; |
| 964 | case DISMISS: dismissH(msg.arg1); break; |
| 965 | case RECHECK: recheckH((VolumeRow) msg.obj); break; |
| 966 | case RECHECK_ALL: recheckH(null); break; |
| 967 | case SET_STREAM_IMPORTANT: setStreamImportantH(msg.arg1, msg.arg2 != 0); break; |
| 968 | case RESCHEDULE_TIMEOUT: rescheduleTimeoutH(); break; |
John Spurlock | 22def3d | 2015-06-17 11:56:12 -0400 | [diff] [blame] | 969 | case STATE_CHANGED: onStateChangedH(mState); break; |
| 970 | case UPDATE_BOTTOM_MARGIN: updateDialogBottomMarginH(); break; |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 971 | } |
| 972 | } |
| 973 | } |
| 974 | |
| 975 | private final class CustomDialog extends Dialog { |
| 976 | public CustomDialog(Context context) { |
| 977 | super(context); |
| 978 | } |
| 979 | |
| 980 | @Override |
| 981 | public boolean dispatchTouchEvent(MotionEvent ev) { |
| 982 | rescheduleTimeoutH(); |
| 983 | return super.dispatchTouchEvent(ev); |
| 984 | } |
| 985 | |
| 986 | @Override |
| 987 | protected void onStop() { |
| 988 | super.onStop(); |
John Spurlock | 22def3d | 2015-06-17 11:56:12 -0400 | [diff] [blame] | 989 | final boolean animating = mMotion.isAnimating(); |
| 990 | if (D.BUG) Log.d(TAG, "onStop animating=" + animating); |
| 991 | if (animating) { |
| 992 | mPendingRecheckAll = true; |
| 993 | return; |
| 994 | } |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 995 | mHandler.sendEmptyMessage(H.RECHECK_ALL); |
| 996 | } |
| 997 | |
| 998 | @Override |
| 999 | public boolean onTouchEvent(MotionEvent event) { |
| 1000 | if (isShowing()) { |
| 1001 | if (event.getAction() == MotionEvent.ACTION_OUTSIDE) { |
| 1002 | dismissH(Events.DISMISS_REASON_TOUCH_OUTSIDE); |
| 1003 | return true; |
| 1004 | } |
| 1005 | } |
| 1006 | return false; |
| 1007 | } |
| 1008 | } |
| 1009 | |
| 1010 | private final class VolumeSeekBarChangeListener implements OnSeekBarChangeListener { |
| 1011 | private final VolumeRow mRow; |
| 1012 | |
| 1013 | private VolumeSeekBarChangeListener(VolumeRow row) { |
| 1014 | mRow = row; |
| 1015 | } |
| 1016 | |
| 1017 | @Override |
| 1018 | public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { |
| 1019 | if (mRow.ss == null) return; |
| 1020 | if (D.BUG) Log.d(TAG, AudioSystem.streamToString(mRow.stream) |
| 1021 | + " onProgressChanged " + progress + " fromUser=" + fromUser); |
| 1022 | if (!fromUser) return; |
| 1023 | if (mRow.ss.levelMin > 0) { |
| 1024 | final int minProgress = mRow.ss.levelMin * 100; |
| 1025 | if (progress < minProgress) { |
| 1026 | seekBar.setProgress(minProgress); |
| 1027 | } |
| 1028 | } |
| 1029 | final int userLevel = getImpliedLevel(seekBar, progress); |
| 1030 | if (mRow.ss.level != userLevel || mRow.ss.muted && userLevel > 0) { |
| 1031 | mRow.userAttempt = SystemClock.uptimeMillis(); |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 1032 | if (mRow.requestedLevel != userLevel) { |
| 1033 | mController.setStreamVolume(mRow.stream, userLevel); |
| 1034 | mRow.requestedLevel = userLevel; |
Chris Wren | e565ee6 | 2015-06-17 15:24:56 -0400 | [diff] [blame] | 1035 | Events.writeEvent(mContext, Events.EVENT_TOUCH_LEVEL_CHANGED, mRow.stream, |
| 1036 | userLevel); |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 1037 | } |
| 1038 | } |
| 1039 | } |
| 1040 | |
| 1041 | @Override |
| 1042 | public void onStartTrackingTouch(SeekBar seekBar) { |
| 1043 | if (D.BUG) Log.d(TAG, "onStartTrackingTouch"+ " " + mRow.stream); |
| 1044 | mController.setActiveStream(mRow.stream); |
| 1045 | mRow.tracking = true; |
| 1046 | } |
| 1047 | |
| 1048 | @Override |
| 1049 | public void onStopTrackingTouch(SeekBar seekBar) { |
| 1050 | if (D.BUG) Log.d(TAG, "onStopTrackingTouch"+ " " + mRow.stream); |
| 1051 | mRow.tracking = false; |
| 1052 | mRow.userAttempt = SystemClock.uptimeMillis(); |
| 1053 | int userLevel = getImpliedLevel(seekBar, seekBar.getProgress()); |
Chris Wren | e565ee6 | 2015-06-17 15:24:56 -0400 | [diff] [blame] | 1054 | Events.writeEvent(mContext, Events.EVENT_TOUCH_LEVEL_DONE, mRow.stream, userLevel); |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 1055 | if (mRow.ss.level != userLevel) { |
| 1056 | mHandler.sendMessageDelayed(mHandler.obtainMessage(H.RECHECK, mRow), |
| 1057 | USER_ATTEMPT_GRACE_PERIOD); |
| 1058 | } |
| 1059 | } |
| 1060 | } |
| 1061 | |
John Spurlock | f09838b | 2015-06-11 16:14:44 -0400 | [diff] [blame] | 1062 | private final class Accessibility extends AccessibilityDelegate { |
John Spurlock | 5adeabc | 2015-05-05 14:50:43 -0400 | [diff] [blame] | 1063 | private AccessibilityManager mMgr; |
| 1064 | private boolean mFeedbackEnabled; |
| 1065 | |
| 1066 | public void init() { |
| 1067 | mMgr = (AccessibilityManager) mContext.getSystemService(Context.ACCESSIBILITY_SERVICE); |
| 1068 | mDialogView.addOnAttachStateChangeListener(new OnAttachStateChangeListener() { |
| 1069 | @Override |
| 1070 | public void onViewDetachedFromWindow(View v) { |
John Spurlock | 22def3d | 2015-06-17 11:56:12 -0400 | [diff] [blame] | 1071 | if (D.BUG) Log.d(TAG, "onViewDetachedFromWindow"); |
John Spurlock | 5adeabc | 2015-05-05 14:50:43 -0400 | [diff] [blame] | 1072 | // noop |
| 1073 | } |
| 1074 | |
| 1075 | @Override |
| 1076 | public void onViewAttachedToWindow(View v) { |
John Spurlock | 22def3d | 2015-06-17 11:56:12 -0400 | [diff] [blame] | 1077 | if (D.BUG) Log.d(TAG, "onViewAttachedToWindow"); |
John Spurlock | 5adeabc | 2015-05-05 14:50:43 -0400 | [diff] [blame] | 1078 | updateFeedbackEnabled(); |
| 1079 | } |
| 1080 | }); |
John Spurlock | f09838b | 2015-06-11 16:14:44 -0400 | [diff] [blame] | 1081 | mDialogView.setAccessibilityDelegate(this); |
John Spurlock | 5adeabc | 2015-05-05 14:50:43 -0400 | [diff] [blame] | 1082 | mMgr.addAccessibilityStateChangeListener(new AccessibilityStateChangeListener() { |
| 1083 | @Override |
| 1084 | public void onAccessibilityStateChanged(boolean enabled) { |
| 1085 | updateFeedbackEnabled(); |
| 1086 | } |
| 1087 | }); |
| 1088 | updateFeedbackEnabled(); |
| 1089 | } |
| 1090 | |
John Spurlock | f09838b | 2015-06-11 16:14:44 -0400 | [diff] [blame] | 1091 | @Override |
| 1092 | public boolean onRequestSendAccessibilityEvent(ViewGroup host, View child, |
| 1093 | AccessibilityEvent event) { |
| 1094 | rescheduleTimeoutH(); |
| 1095 | return super.onRequestSendAccessibilityEvent(host, child, event); |
| 1096 | } |
| 1097 | |
John Spurlock | 5adeabc | 2015-05-05 14:50:43 -0400 | [diff] [blame] | 1098 | private void updateFeedbackEnabled() { |
| 1099 | mFeedbackEnabled = computeFeedbackEnabled(); |
| 1100 | } |
| 1101 | |
| 1102 | private boolean computeFeedbackEnabled() { |
John Spurlock | f09838b | 2015-06-11 16:14:44 -0400 | [diff] [blame] | 1103 | // are there any enabled non-generic a11y services? |
John Spurlock | 5adeabc | 2015-05-05 14:50:43 -0400 | [diff] [blame] | 1104 | final List<AccessibilityServiceInfo> services = |
| 1105 | mMgr.getEnabledAccessibilityServiceList(FEEDBACK_ALL_MASK); |
| 1106 | for (AccessibilityServiceInfo asi : services) { |
John Spurlock | f09838b | 2015-06-11 16:14:44 -0400 | [diff] [blame] | 1107 | if (asi.feedbackType != 0 && asi.feedbackType != FEEDBACK_GENERIC) { |
John Spurlock | 5adeabc | 2015-05-05 14:50:43 -0400 | [diff] [blame] | 1108 | return true; |
| 1109 | } |
| 1110 | } |
| 1111 | return false; |
| 1112 | } |
| 1113 | } |
| 1114 | |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 1115 | private static class VolumeRow { |
| 1116 | private View view; |
| 1117 | private View space; |
| 1118 | private TextView header; |
| 1119 | private ImageButton icon; |
| 1120 | private SeekBar slider; |
| 1121 | private ImageButton settingsButton; |
| 1122 | private int stream; |
| 1123 | private StreamState ss; |
| 1124 | private long userAttempt; // last user-driven slider change |
| 1125 | private boolean tracking; // tracking slider touch |
John Spurlock | b0a2e5f | 2015-06-09 14:41:52 -0400 | [diff] [blame] | 1126 | private int requestedLevel = -1; // pending user-requested level via progress changed |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 1127 | private int iconRes; |
| 1128 | private int iconMuteRes; |
| 1129 | private boolean important; |
| 1130 | private int cachedIconRes; |
John Spurlock | ecc8058 | 2015-05-13 16:23:14 -0400 | [diff] [blame] | 1131 | private ColorStateList cachedSliderTint; |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 1132 | private int iconState; // from Events |
John Spurlock | f55b7f2 | 2015-04-13 19:21:26 -0400 | [diff] [blame] | 1133 | private boolean cachedShowHeaders = VolumePrefs.DEFAULT_SHOW_HEADERS; |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 1134 | private int cachedExpandButtonRes; |
| 1135 | private ObjectAnimator anim; // slider progress animation for non-touch-related updates |
| 1136 | private int animTargetProgress; |
| 1137 | private int lastAudibleLevel = 1; |
| 1138 | } |
John Spurlock | f55b7f2 | 2015-04-13 19:21:26 -0400 | [diff] [blame] | 1139 | |
| 1140 | public interface Callback { |
| 1141 | void onSettingsClicked(); |
| 1142 | void onZenSettingsClicked(); |
| 1143 | void onZenPrioritySettingsClicked(); |
| 1144 | } |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 1145 | } |