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