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