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