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