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