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