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