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