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