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