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