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