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