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