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