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