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