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