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