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