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