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