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