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 | |
John Spurlock | 5adeabc | 2015-05-05 14:50:43 -0400 | [diff] [blame] | 19 | import android.accessibilityservice.AccessibilityServiceInfo; |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 20 | import android.animation.LayoutTransition; |
Julia Reynolds | 4b006a8 | 2016-04-20 16:09:06 -0400 | [diff] [blame^] | 21 | import android.animation.ObjectAnimator; |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 22 | import android.animation.ValueAnimator; |
| 23 | import android.annotation.SuppressLint; |
| 24 | import android.app.Dialog; |
| 25 | import android.app.KeyguardManager; |
| 26 | import android.content.Context; |
Takayuki Hoshi | bb0ec55 | 2015-12-17 20:50:25 +0900 | [diff] [blame] | 27 | import android.content.pm.PackageManager; |
John Spurlock | 77bb25af | 2015-05-11 12:12:07 -0400 | [diff] [blame] | 28 | import android.content.res.ColorStateList; |
Julia Reynolds | c791e05 | 2016-02-19 16:02:01 -0500 | [diff] [blame] | 29 | import android.content.res.Configuration; |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 30 | import android.content.res.Resources; |
| 31 | import android.graphics.Color; |
| 32 | import android.graphics.PixelFormat; |
| 33 | import android.graphics.Rect; |
| 34 | import android.graphics.drawable.AnimatedVectorDrawable; |
| 35 | import android.graphics.drawable.ColorDrawable; |
| 36 | import android.graphics.drawable.Drawable; |
| 37 | import android.media.AudioManager; |
| 38 | import android.media.AudioSystem; |
John Spurlock | 5adeabc | 2015-05-05 14:50:43 -0400 | [diff] [blame] | 39 | import android.os.Debug; |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 40 | import android.os.Handler; |
| 41 | import android.os.Looper; |
| 42 | import android.os.Message; |
| 43 | import android.os.SystemClock; |
| 44 | import android.provider.Settings.Global; |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 45 | import android.util.DisplayMetrics; |
| 46 | import android.util.Log; |
Julia Reynolds | c791e05 | 2016-02-19 16:02:01 -0500 | [diff] [blame] | 47 | import android.util.Slog; |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 48 | import android.util.SparseBooleanArray; |
| 49 | import android.view.Gravity; |
| 50 | import android.view.MotionEvent; |
| 51 | import android.view.View; |
John Spurlock | 5adeabc | 2015-05-05 14:50:43 -0400 | [diff] [blame] | 52 | import android.view.View.AccessibilityDelegate; |
| 53 | import android.view.View.OnAttachStateChangeListener; |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 54 | import android.view.View.OnClickListener; |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 55 | import android.view.View.OnTouchListener; |
| 56 | import android.view.ViewGroup; |
| 57 | import android.view.ViewGroup.MarginLayoutParams; |
| 58 | import android.view.Window; |
| 59 | import android.view.WindowManager; |
John Spurlock | 5adeabc | 2015-05-05 14:50:43 -0400 | [diff] [blame] | 60 | import android.view.accessibility.AccessibilityEvent; |
| 61 | import android.view.accessibility.AccessibilityManager; |
| 62 | import android.view.accessibility.AccessibilityManager.AccessibilityStateChangeListener; |
Julia Reynolds | 4b006a8 | 2016-04-20 16:09:06 -0400 | [diff] [blame^] | 63 | import android.view.animation.DecelerateInterpolator; |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 64 | import android.widget.ImageButton; |
| 65 | import android.widget.LinearLayout; |
| 66 | import android.widget.SeekBar; |
| 67 | import android.widget.SeekBar.OnSeekBarChangeListener; |
| 68 | import android.widget.TextView; |
| 69 | |
| 70 | import com.android.systemui.R; |
| 71 | import com.android.systemui.statusbar.policy.ZenModeController; |
Jason Monk | e138f55 | 2016-01-18 09:21:45 -0500 | [diff] [blame] | 72 | import com.android.systemui.tuner.TunerService; |
Jason Monk | aa911b3 | 2016-02-10 21:01:30 -0500 | [diff] [blame] | 73 | import com.android.systemui.tuner.TunerZenModePanel; |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 74 | import com.android.systemui.volume.VolumeDialogController.State; |
| 75 | import com.android.systemui.volume.VolumeDialogController.StreamState; |
| 76 | |
| 77 | import java.io.PrintWriter; |
| 78 | import java.util.ArrayList; |
| 79 | import java.util.List; |
| 80 | |
Winson | c0d7058 | 2016-01-29 10:24:39 -0800 | [diff] [blame] | 81 | import static android.accessibilityservice.AccessibilityServiceInfo.FEEDBACK_ALL_MASK; |
| 82 | import static android.accessibilityservice.AccessibilityServiceInfo.FEEDBACK_GENERIC; |
| 83 | |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 84 | /** |
| 85 | * Visual presentation of the volume dialog. |
| 86 | * |
| 87 | * A client of VolumeDialogController and its state model. |
| 88 | * |
| 89 | * Methods ending in "H" must be called on the (ui) handler. |
| 90 | */ |
Jason Monk | e138f55 | 2016-01-18 09:21:45 -0500 | [diff] [blame] | 91 | public class VolumeDialog implements TunerService.Tunable { |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 92 | private static final String TAG = Util.logTag(VolumeDialog.class); |
| 93 | |
Jason Monk | e138f55 | 2016-01-18 09:21:45 -0500 | [diff] [blame] | 94 | public static final String SHOW_FULL_ZEN = "sysui_show_full_zen"; |
| 95 | |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 96 | private static final long USER_ATTEMPT_GRACE_PERIOD = 1000; |
Julia Reynolds | 4b006a8 | 2016-04-20 16:09:06 -0400 | [diff] [blame^] | 97 | private static final int UPDATE_ANIMATION_DURATION = 80; |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 98 | |
| 99 | private final Context mContext; |
| 100 | private final H mHandler = new H(); |
| 101 | private final VolumeDialogController mController; |
| 102 | |
Julia Reynolds | c791e05 | 2016-02-19 16:02:01 -0500 | [diff] [blame] | 103 | private CustomDialog mDialog; |
| 104 | private ViewGroup mDialogView; |
| 105 | private ViewGroup mDialogContentView; |
Julia Reynolds | c791e05 | 2016-02-19 16:02:01 -0500 | [diff] [blame] | 106 | private ImageButton mExpandButton; |
| 107 | private final List<VolumeRow> mRows = new ArrayList<>(); |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 108 | private final SpTexts mSpTexts; |
| 109 | private final SparseBooleanArray mDynamic = new SparseBooleanArray(); |
| 110 | private final KeyguardManager mKeyguard; |
Julia Reynolds | 6aa83b4 | 2015-09-08 13:41:45 -0400 | [diff] [blame] | 111 | private final AudioManager mAudioManager; |
Julia Reynolds | c791e05 | 2016-02-19 16:02:01 -0500 | [diff] [blame] | 112 | private int mExpandButtonAnimationDuration; |
| 113 | private ZenFooter mZenFooter; |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 114 | private final LayoutTransition mLayoutTransition; |
John Spurlock | 76b52b3 | 2015-04-03 00:00:12 -0400 | [diff] [blame] | 115 | private final Object mSafetyWarningLock = new Object(); |
John Spurlock | 5adeabc | 2015-05-05 14:50:43 -0400 | [diff] [blame] | 116 | private final Accessibility mAccessibility = new Accessibility(); |
John Spurlock | 77bb25af | 2015-05-11 12:12:07 -0400 | [diff] [blame] | 117 | private final ColorStateList mActiveSliderTint; |
| 118 | private final ColorStateList mInactiveSliderTint; |
Julia Reynolds | c791e05 | 2016-02-19 16:02:01 -0500 | [diff] [blame] | 119 | private VolumeDialogMotion mMotion; |
| 120 | private final int mWindowType; |
| 121 | private final ZenModeController mZenModeController; |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 122 | |
| 123 | private boolean mShowing; |
| 124 | private boolean mExpanded; |
Julia Reynolds | c791e05 | 2016-02-19 16:02:01 -0500 | [diff] [blame] | 125 | |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 126 | private int mActiveStream; |
John Spurlock | f55b7f2 | 2015-04-13 19:21:26 -0400 | [diff] [blame] | 127 | private boolean mShowHeaders = VolumePrefs.DEFAULT_SHOW_HEADERS; |
John Spurlock | f55b7f2 | 2015-04-13 19:21:26 -0400 | [diff] [blame] | 128 | private boolean mAutomute = VolumePrefs.DEFAULT_ENABLE_AUTOMUTE; |
| 129 | private boolean mSilentMode = VolumePrefs.DEFAULT_ENABLE_SILENT_MODE; |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 130 | private State mState; |
John Spurlock | 22def3d | 2015-06-17 11:56:12 -0400 | [diff] [blame] | 131 | private boolean mExpandButtonAnimationRunning; |
John Spurlock | 76b52b3 | 2015-04-03 00:00:12 -0400 | [diff] [blame] | 132 | private SafetyWarningDialog mSafetyWarning; |
John Spurlock | f55b7f2 | 2015-04-13 19:21:26 -0400 | [diff] [blame] | 133 | private Callback mCallback; |
John Spurlock | 22def3d | 2015-06-17 11:56:12 -0400 | [diff] [blame] | 134 | private boolean mPendingStateChanged; |
| 135 | private boolean mPendingRecheckAll; |
| 136 | private long mCollapseTime; |
Jun Mukai | 3f5d713 | 2015-07-21 14:10:09 -0700 | [diff] [blame] | 137 | private boolean mHovering = false; |
Julia Reynolds | c791e05 | 2016-02-19 16:02:01 -0500 | [diff] [blame] | 138 | private int mDensity; |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 139 | |
Jason Monk | e138f55 | 2016-01-18 09:21:45 -0500 | [diff] [blame] | 140 | private boolean mShowFullZen; |
Julia Reynolds | c791e05 | 2016-02-19 16:02:01 -0500 | [diff] [blame] | 141 | private TunerZenModePanel mZenPanel; |
Jason Monk | e138f55 | 2016-01-18 09:21:45 -0500 | [diff] [blame] | 142 | |
John Spurlock | d9c75db | 2015-04-28 11:19:13 -0400 | [diff] [blame] | 143 | public VolumeDialog(Context context, int windowType, VolumeDialogController controller, |
John Spurlock | f55b7f2 | 2015-04-13 19:21:26 -0400 | [diff] [blame] | 144 | ZenModeController zenModeController, Callback callback) { |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 145 | mContext = context; |
| 146 | mController = controller; |
John Spurlock | f55b7f2 | 2015-04-13 19:21:26 -0400 | [diff] [blame] | 147 | mCallback = callback; |
Julia Reynolds | c791e05 | 2016-02-19 16:02:01 -0500 | [diff] [blame] | 148 | mWindowType = windowType; |
| 149 | mZenModeController = zenModeController; |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 150 | mSpTexts = new SpTexts(mContext); |
| 151 | mKeyguard = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE); |
Julia Reynolds | 6aa83b4 | 2015-09-08 13:41:45 -0400 | [diff] [blame] | 152 | mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); |
Julia Reynolds | c791e05 | 2016-02-19 16:02:01 -0500 | [diff] [blame] | 153 | mActiveSliderTint = loadColorStateList(R.color.system_accent_color); |
| 154 | mInactiveSliderTint = loadColorStateList(R.color.volume_slider_inactive); |
| 155 | mLayoutTransition = new LayoutTransition(); |
| 156 | mLayoutTransition.setDuration(new ValueAnimator().getDuration() / 2); |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 157 | |
Julia Reynolds | c791e05 | 2016-02-19 16:02:01 -0500 | [diff] [blame] | 158 | initDialog(); |
| 159 | |
| 160 | mAccessibility.init(); |
| 161 | |
| 162 | controller.addCallback(mControllerCallbackH, mHandler); |
| 163 | controller.getState(); |
| 164 | TunerService.get(mContext).addTunable(this, SHOW_FULL_ZEN); |
| 165 | |
| 166 | final Configuration currentConfig = mContext.getResources().getConfiguration(); |
| 167 | mDensity = currentConfig.densityDpi; |
| 168 | } |
| 169 | |
| 170 | private void initDialog() { |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 171 | mDialog = new CustomDialog(mContext); |
| 172 | |
Julia Reynolds | c791e05 | 2016-02-19 16:02:01 -0500 | [diff] [blame] | 173 | mHovering = false; |
| 174 | mShowing = false; |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 175 | final Window window = mDialog.getWindow(); |
| 176 | window.requestFeature(Window.FEATURE_NO_TITLE); |
| 177 | window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); |
| 178 | window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); |
| 179 | window.addFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
| 180 | | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN |
| 181 | | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL |
| 182 | | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
| 183 | | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH |
| 184 | | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED); |
| 185 | mDialog.setCanceledOnTouchOutside(true); |
| 186 | final Resources res = mContext.getResources(); |
| 187 | final WindowManager.LayoutParams lp = window.getAttributes(); |
Julia Reynolds | c791e05 | 2016-02-19 16:02:01 -0500 | [diff] [blame] | 188 | lp.type = mWindowType; |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 189 | lp.format = PixelFormat.TRANSLUCENT; |
| 190 | lp.setTitle(VolumeDialog.class.getSimpleName()); |
| 191 | lp.gravity = Gravity.TOP | Gravity.CENTER_HORIZONTAL; |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 192 | lp.y = res.getDimensionPixelSize(R.dimen.volume_offset_top); |
| 193 | lp.gravity = Gravity.TOP; |
Jorim Jaggi | 6d712e0 | 2015-07-06 16:18:11 -0700 | [diff] [blame] | 194 | lp.windowAnimations = -1; |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 195 | window.setAttributes(lp); |
John Spurlock | 67a0f85 | 2015-06-15 15:35:47 -0400 | [diff] [blame] | 196 | window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING); |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 197 | |
Julia Reynolds | c791e05 | 2016-02-19 16:02:01 -0500 | [diff] [blame] | 198 | |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 199 | mDialog.setContentView(R.layout.volume_dialog); |
| 200 | mDialogView = (ViewGroup) mDialog.findViewById(R.id.volume_dialog); |
Jun Mukai | 3f5d713 | 2015-07-21 14:10:09 -0700 | [diff] [blame] | 201 | mDialogView.setOnHoverListener(new View.OnHoverListener() { |
| 202 | @Override |
| 203 | public boolean onHover(View v, MotionEvent event) { |
| 204 | int action = event.getActionMasked(); |
| 205 | mHovering = (action == MotionEvent.ACTION_HOVER_ENTER) |
| 206 | || (action == MotionEvent.ACTION_HOVER_MOVE); |
| 207 | rescheduleTimeoutH(); |
| 208 | return true; |
| 209 | } |
| 210 | }); |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 211 | mDialogContentView = (ViewGroup) mDialog.findViewById(R.id.volume_dialog_content); |
Julia Reynolds | c791e05 | 2016-02-19 16:02:01 -0500 | [diff] [blame] | 212 | mExpanded = false; |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 213 | mExpandButton = (ImageButton) mDialogView.findViewById(R.id.volume_expand_button); |
| 214 | mExpandButton.setOnClickListener(mClickExpand); |
| 215 | updateWindowWidthH(); |
| 216 | updateExpandButtonH(); |
Julia Reynolds | c791e05 | 2016-02-19 16:02:01 -0500 | [diff] [blame] | 217 | |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 218 | mDialogContentView.setLayoutTransition(mLayoutTransition); |
John Spurlock | 22def3d | 2015-06-17 11:56:12 -0400 | [diff] [blame] | 219 | mMotion = new VolumeDialogMotion(mDialog, mDialogView, mDialogContentView, mExpandButton, |
| 220 | new VolumeDialogMotion.Callback() { |
Julia Reynolds | c791e05 | 2016-02-19 16:02:01 -0500 | [diff] [blame] | 221 | @Override |
| 222 | public void onAnimatingChanged(boolean animating) { |
| 223 | if (animating) return; |
| 224 | if (mPendingStateChanged) { |
| 225 | mHandler.sendEmptyMessage(H.STATE_CHANGED); |
| 226 | mPendingStateChanged = false; |
| 227 | } |
| 228 | if (mPendingRecheckAll) { |
| 229 | mHandler.sendEmptyMessage(H.RECHECK_ALL); |
| 230 | mPendingRecheckAll = false; |
| 231 | } |
| 232 | } |
| 233 | }); |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 234 | |
Julia Reynolds | c791e05 | 2016-02-19 16:02:01 -0500 | [diff] [blame] | 235 | if (mRows.isEmpty()) { |
| 236 | addRow(AudioManager.STREAM_RING, |
| 237 | R.drawable.ic_volume_ringer, R.drawable.ic_volume_ringer_mute, true); |
| 238 | addRow(AudioManager.STREAM_MUSIC, |
| 239 | R.drawable.ic_volume_media, R.drawable.ic_volume_media_mute, true); |
| 240 | addRow(AudioManager.STREAM_ALARM, |
| 241 | R.drawable.ic_volume_alarm, R.drawable.ic_volume_alarm_mute, false); |
| 242 | addRow(AudioManager.STREAM_VOICE_CALL, |
| 243 | R.drawable.ic_volume_voice, R.drawable.ic_volume_voice, false); |
| 244 | addRow(AudioManager.STREAM_BLUETOOTH_SCO, |
| 245 | R.drawable.ic_volume_bt_sco, R.drawable.ic_volume_bt_sco, false); |
| 246 | addRow(AudioManager.STREAM_SYSTEM, |
| 247 | R.drawable.ic_volume_system, R.drawable.ic_volume_system_mute, false); |
| 248 | } else { |
| 249 | addExistingRows(); |
| 250 | } |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 251 | mExpandButtonAnimationDuration = res.getInteger(R.integer.volume_expand_animation_duration); |
| 252 | mZenFooter = (ZenFooter) mDialog.findViewById(R.id.volume_zen_footer); |
Julia Reynolds | c791e05 | 2016-02-19 16:02:01 -0500 | [diff] [blame] | 253 | mZenFooter.init(mZenModeController); |
Jason Monk | aa911b3 | 2016-02-10 21:01:30 -0500 | [diff] [blame] | 254 | mZenPanel = (TunerZenModePanel) mDialog.findViewById(R.id.tuner_zen_mode_panel); |
Julia Reynolds | c791e05 | 2016-02-19 16:02:01 -0500 | [diff] [blame] | 255 | mZenPanel.init(mZenModeController); |
Jason Monk | e138f55 | 2016-01-18 09:21:45 -0500 | [diff] [blame] | 256 | mZenPanel.setCallback(mZenPanelCallback); |
Jason Monk | e138f55 | 2016-01-18 09:21:45 -0500 | [diff] [blame] | 257 | } |
| 258 | |
| 259 | @Override |
| 260 | public void onTuningChanged(String key, String newValue) { |
| 261 | if (SHOW_FULL_ZEN.equals(key)) { |
| 262 | mShowFullZen = newValue != null && Integer.parseInt(newValue) != 0; |
| 263 | } |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 264 | } |
| 265 | |
John Spurlock | 77bb25af | 2015-05-11 12:12:07 -0400 | [diff] [blame] | 266 | private ColorStateList loadColorStateList(int colorResId) { |
| 267 | return ColorStateList.valueOf(mContext.getColor(colorResId)); |
| 268 | } |
| 269 | |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 270 | private void updateWindowWidthH() { |
| 271 | final ViewGroup.LayoutParams lp = mDialogView.getLayoutParams(); |
| 272 | final DisplayMetrics dm = mContext.getResources().getDisplayMetrics(); |
| 273 | if (D.BUG) Log.d(TAG, "updateWindowWidth dm.w=" + dm.widthPixels); |
| 274 | int w = dm.widthPixels; |
| 275 | final int max = mContext.getResources() |
Anthony Chen | 2f60d11 | 2016-01-26 15:34:12 -0800 | [diff] [blame] | 276 | .getDimensionPixelSize(R.dimen.volume_dialog_panel_width); |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 277 | if (w > max) { |
| 278 | w = max; |
| 279 | } |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 280 | lp.width = w; |
| 281 | mDialogView.setLayoutParams(lp); |
| 282 | } |
| 283 | |
| 284 | public void setStreamImportant(int stream, boolean important) { |
| 285 | mHandler.obtainMessage(H.SET_STREAM_IMPORTANT, stream, important ? 1 : 0).sendToTarget(); |
| 286 | } |
| 287 | |
| 288 | public void setShowHeaders(boolean showHeaders) { |
| 289 | if (showHeaders == mShowHeaders) return; |
| 290 | mShowHeaders = showHeaders; |
| 291 | mHandler.sendEmptyMessage(H.RECHECK_ALL); |
| 292 | } |
| 293 | |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 294 | public void setAutomute(boolean automute) { |
| 295 | if (mAutomute == automute) return; |
| 296 | mAutomute = automute; |
| 297 | mHandler.sendEmptyMessage(H.RECHECK_ALL); |
| 298 | } |
| 299 | |
| 300 | public void setSilentMode(boolean silentMode) { |
| 301 | if (mSilentMode == silentMode) return; |
| 302 | mSilentMode = silentMode; |
| 303 | mHandler.sendEmptyMessage(H.RECHECK_ALL); |
| 304 | } |
| 305 | |
| 306 | private void addRow(int stream, int iconRes, int iconMuteRes, boolean important) { |
Julia Reynolds | c791e05 | 2016-02-19 16:02:01 -0500 | [diff] [blame] | 307 | VolumeRow row = new VolumeRow(); |
| 308 | initRow(row, stream, iconRes, iconMuteRes, important); |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 309 | if (!mRows.isEmpty()) { |
Julia Reynolds | c791e05 | 2016-02-19 16:02:01 -0500 | [diff] [blame] | 310 | addSpacer(row); |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 311 | } |
Julia Reynolds | e80f675 | 2016-04-20 14:37:39 -0400 | [diff] [blame] | 312 | mDialogContentView.addView(row.view, mDialogContentView.getChildCount() - 2); |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 313 | mRows.add(row); |
| 314 | } |
| 315 | |
Julia Reynolds | c791e05 | 2016-02-19 16:02:01 -0500 | [diff] [blame] | 316 | private void addExistingRows() { |
| 317 | int N = mRows.size(); |
| 318 | for (int i = 0; i < N; i++) { |
| 319 | final VolumeRow row = mRows.get(i); |
| 320 | initRow(row, row.stream, row.iconRes, row.iconMuteRes, row.important); |
| 321 | if (i > 0) { |
| 322 | addSpacer(row); |
| 323 | } |
Julia Reynolds | e80f675 | 2016-04-20 14:37:39 -0400 | [diff] [blame] | 324 | mDialogContentView.addView(row.view, mDialogContentView.getChildCount() - 2); |
Julia Reynolds | c791e05 | 2016-02-19 16:02:01 -0500 | [diff] [blame] | 325 | } |
| 326 | } |
| 327 | |
| 328 | private void addSpacer(VolumeRow row) { |
| 329 | final View v = new View(mContext); |
| 330 | v.setId(android.R.id.background); |
| 331 | final int h = mContext.getResources() |
| 332 | .getDimensionPixelSize(R.dimen.volume_slider_interspacing); |
| 333 | final LinearLayout.LayoutParams lp = |
| 334 | new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, h); |
Julia Reynolds | e80f675 | 2016-04-20 14:37:39 -0400 | [diff] [blame] | 335 | mDialogContentView.addView(v, mDialogContentView.getChildCount() - 2, lp); |
Julia Reynolds | c791e05 | 2016-02-19 16:02:01 -0500 | [diff] [blame] | 336 | row.space = v; |
| 337 | } |
| 338 | |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 339 | private boolean isAttached() { |
| 340 | return mDialogContentView != null && mDialogContentView.isAttachedToWindow(); |
| 341 | } |
| 342 | |
| 343 | private VolumeRow getActiveRow() { |
| 344 | for (VolumeRow row : mRows) { |
| 345 | if (row.stream == mActiveStream) { |
| 346 | return row; |
| 347 | } |
| 348 | } |
| 349 | return mRows.get(0); |
| 350 | } |
| 351 | |
| 352 | private VolumeRow findRow(int stream) { |
| 353 | for (VolumeRow row : mRows) { |
| 354 | if (row.stream == stream) return row; |
| 355 | } |
| 356 | return null; |
| 357 | } |
| 358 | |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 359 | public void dump(PrintWriter writer) { |
| 360 | writer.println(VolumeDialog.class.getSimpleName() + " state:"); |
| 361 | writer.print(" mShowing: "); writer.println(mShowing); |
| 362 | writer.print(" mExpanded: "); writer.println(mExpanded); |
John Spurlock | 22def3d | 2015-06-17 11:56:12 -0400 | [diff] [blame] | 363 | writer.print(" mExpandButtonAnimationRunning: "); |
| 364 | writer.println(mExpandButtonAnimationRunning); |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 365 | writer.print(" mActiveStream: "); writer.println(mActiveStream); |
| 366 | writer.print(" mDynamic: "); writer.println(mDynamic); |
| 367 | writer.print(" mShowHeaders: "); writer.println(mShowHeaders); |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 368 | writer.print(" mAutomute: "); writer.println(mAutomute); |
| 369 | writer.print(" mSilentMode: "); writer.println(mSilentMode); |
John Spurlock | 22def3d | 2015-06-17 11:56:12 -0400 | [diff] [blame] | 370 | writer.print(" mCollapseTime: "); writer.println(mCollapseTime); |
John Spurlock | 84ee67c | 2015-05-20 23:33:43 -0400 | [diff] [blame] | 371 | writer.print(" mAccessibility.mFeedbackEnabled: "); |
| 372 | writer.println(mAccessibility.mFeedbackEnabled); |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 373 | } |
| 374 | |
Julia Reynolds | 4b006a8 | 2016-04-20 16:09:06 -0400 | [diff] [blame^] | 375 | private static int getImpliedLevel(SeekBar seekBar, int progress) { |
| 376 | final int m = seekBar.getMax(); |
| 377 | final int n = m / 100 - 1; |
| 378 | final int level = progress == 0 ? 0 |
| 379 | : progress == m ? (m / 100) : (1 + (int)((progress / (float) m) * n)); |
| 380 | return level; |
| 381 | } |
| 382 | |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 383 | @SuppressLint("InflateParams") |
Julia Reynolds | c791e05 | 2016-02-19 16:02:01 -0500 | [diff] [blame] | 384 | private void initRow(final VolumeRow row, final int stream, int iconRes, int iconMuteRes, |
| 385 | boolean important) { |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 386 | row.stream = stream; |
| 387 | row.iconRes = iconRes; |
| 388 | row.iconMuteRes = iconMuteRes; |
| 389 | row.important = important; |
| 390 | row.view = mDialog.getLayoutInflater().inflate(R.layout.volume_dialog_row, null); |
| 391 | row.view.setTag(row); |
| 392 | row.header = (TextView) row.view.findViewById(R.id.volume_row_header); |
| 393 | mSpTexts.add(row.header); |
| 394 | row.slider = (SeekBar) row.view.findViewById(R.id.volume_row_slider); |
| 395 | row.slider.setOnSeekBarChangeListener(new VolumeSeekBarChangeListener(row)); |
| 396 | |
| 397 | // forward events above the slider into the slider |
| 398 | row.view.setOnTouchListener(new OnTouchListener() { |
| 399 | private final Rect mSliderHitRect = new Rect(); |
| 400 | private boolean mDragging; |
| 401 | |
| 402 | @SuppressLint("ClickableViewAccessibility") |
| 403 | @Override |
| 404 | public boolean onTouch(View v, MotionEvent event) { |
| 405 | row.slider.getHitRect(mSliderHitRect); |
| 406 | if (!mDragging && event.getActionMasked() == MotionEvent.ACTION_DOWN |
| 407 | && event.getY() < mSliderHitRect.top) { |
| 408 | mDragging = true; |
| 409 | } |
| 410 | if (mDragging) { |
| 411 | event.offsetLocation(-mSliderHitRect.left, -mSliderHitRect.top); |
| 412 | row.slider.dispatchTouchEvent(event); |
| 413 | if (event.getActionMasked() == MotionEvent.ACTION_UP |
| 414 | || event.getActionMasked() == MotionEvent.ACTION_CANCEL) { |
| 415 | mDragging = false; |
| 416 | } |
| 417 | return true; |
| 418 | } |
| 419 | return false; |
| 420 | } |
| 421 | }); |
| 422 | row.icon = (ImageButton) row.view.findViewById(R.id.volume_row_icon); |
| 423 | row.icon.setImageResource(iconRes); |
| 424 | row.icon.setOnClickListener(new OnClickListener() { |
| 425 | @Override |
| 426 | public void onClick(View v) { |
Chris Wren | e565ee6 | 2015-06-17 15:24:56 -0400 | [diff] [blame] | 427 | Events.writeEvent(mContext, Events.EVENT_ICON_CLICK, row.stream, row.iconState); |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 428 | mController.setActiveStream(row.stream); |
| 429 | if (row.stream == AudioManager.STREAM_RING) { |
| 430 | final boolean hasVibrator = mController.hasVibrator(); |
| 431 | if (mState.ringerModeInternal == AudioManager.RINGER_MODE_NORMAL) { |
| 432 | if (hasVibrator) { |
| 433 | mController.setRingerMode(AudioManager.RINGER_MODE_VIBRATE, false); |
| 434 | } else { |
| 435 | final boolean wasZero = row.ss.level == 0; |
| 436 | mController.setStreamVolume(stream, wasZero ? row.lastAudibleLevel : 0); |
| 437 | } |
| 438 | } else { |
| 439 | mController.setRingerMode(AudioManager.RINGER_MODE_NORMAL, false); |
| 440 | if (row.ss.level == 0) { |
| 441 | mController.setStreamVolume(stream, 1); |
| 442 | } |
| 443 | } |
| 444 | } else { |
Julia Reynolds | 798b0c3 | 2015-09-01 14:35:53 -0400 | [diff] [blame] | 445 | final boolean vmute = row.ss.level == row.ss.levelMin; |
| 446 | mController.setStreamVolume(stream, |
| 447 | vmute ? row.lastAudibleLevel : row.ss.levelMin); |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 448 | } |
| 449 | row.userAttempt = 0; // reset the grace period, slider should update immediately |
| 450 | } |
| 451 | }); |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 452 | } |
| 453 | |
| 454 | public void destroy() { |
| 455 | mController.removeCallback(mControllerCallbackH); |
| 456 | } |
| 457 | |
| 458 | public void show(int reason) { |
| 459 | mHandler.obtainMessage(H.SHOW, reason, 0).sendToTarget(); |
| 460 | } |
| 461 | |
| 462 | public void dismiss(int reason) { |
| 463 | mHandler.obtainMessage(H.DISMISS, reason, 0).sendToTarget(); |
| 464 | } |
| 465 | |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 466 | private void showH(int reason) { |
John Spurlock | 22def3d | 2015-06-17 11:56:12 -0400 | [diff] [blame] | 467 | if (D.BUG) Log.d(TAG, "showH r=" + Events.DISMISS_REASONS[reason]); |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 468 | mHandler.removeMessages(H.SHOW); |
| 469 | mHandler.removeMessages(H.DISMISS); |
| 470 | rescheduleTimeoutH(); |
| 471 | if (mShowing) return; |
| 472 | mShowing = true; |
John Spurlock | 22def3d | 2015-06-17 11:56:12 -0400 | [diff] [blame] | 473 | mMotion.startShow(); |
Chris Wren | e565ee6 | 2015-06-17 15:24:56 -0400 | [diff] [blame] | 474 | Events.writeEvent(mContext, Events.EVENT_SHOW_DIALOG, reason, mKeyguard.isKeyguardLocked()); |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 475 | mController.notifyVisible(true); |
| 476 | } |
| 477 | |
| 478 | protected void rescheduleTimeoutH() { |
| 479 | mHandler.removeMessages(H.DISMISS); |
John Spurlock | f09838b | 2015-06-11 16:14:44 -0400 | [diff] [blame] | 480 | final int timeout = computeTimeoutH(); |
| 481 | mHandler.sendMessageDelayed(mHandler |
| 482 | .obtainMessage(H.DISMISS, Events.DISMISS_REASON_TIMEOUT, 0), timeout); |
John Spurlock | 5adeabc | 2015-05-05 14:50:43 -0400 | [diff] [blame] | 483 | if (D.BUG) Log.d(TAG, "rescheduleTimeout " + timeout + " " + Debug.getCaller()); |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 484 | mController.userActivity(); |
| 485 | } |
| 486 | |
| 487 | private int computeTimeoutH() { |
John Spurlock | f09838b | 2015-06-11 16:14:44 -0400 | [diff] [blame] | 488 | if (mAccessibility.mFeedbackEnabled) return 20000; |
Jun Mukai | 3f5d713 | 2015-07-21 14:10:09 -0700 | [diff] [blame] | 489 | if (mHovering) return 16000; |
John Spurlock | 76b52b3 | 2015-04-03 00:00:12 -0400 | [diff] [blame] | 490 | if (mSafetyWarning != null) return 5000; |
John Spurlock | 22def3d | 2015-06-17 11:56:12 -0400 | [diff] [blame] | 491 | if (mExpanded || mExpandButtonAnimationRunning) return 5000; |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 492 | if (mActiveStream == AudioManager.STREAM_MUSIC) return 1500; |
| 493 | return 3000; |
| 494 | } |
| 495 | |
| 496 | protected void dismissH(int reason) { |
Jason Monk | 305e0ba | 2015-07-06 15:53:59 -0400 | [diff] [blame] | 497 | if (mMotion.isAnimating()) { |
| 498 | return; |
| 499 | } |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 500 | mHandler.removeMessages(H.DISMISS); |
| 501 | mHandler.removeMessages(H.SHOW); |
| 502 | if (!mShowing) return; |
| 503 | mShowing = false; |
John Spurlock | 22def3d | 2015-06-17 11:56:12 -0400 | [diff] [blame] | 504 | mMotion.startDismiss(new Runnable() { |
| 505 | @Override |
| 506 | public void run() { |
| 507 | setExpandedH(false); |
| 508 | } |
| 509 | }); |
Chris Wren | e565ee6 | 2015-06-17 15:24:56 -0400 | [diff] [blame] | 510 | Events.writeEvent(mContext, Events.EVENT_DISMISS_DIALOG, reason); |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 511 | mController.notifyVisible(false); |
John Spurlock | 76b52b3 | 2015-04-03 00:00:12 -0400 | [diff] [blame] | 512 | synchronized (mSafetyWarningLock) { |
| 513 | if (mSafetyWarning != null) { |
| 514 | if (D.BUG) Log.d(TAG, "SafetyWarning dismissed"); |
| 515 | mSafetyWarning.dismiss(); |
| 516 | } |
| 517 | } |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 518 | } |
| 519 | |
John Spurlock | 22def3d | 2015-06-17 11:56:12 -0400 | [diff] [blame] | 520 | private void updateDialogBottomMarginH() { |
| 521 | final long diff = System.currentTimeMillis() - mCollapseTime; |
| 522 | final boolean collapsing = mCollapseTime != 0 && diff < getConservativeCollapseDuration(); |
| 523 | final ViewGroup.MarginLayoutParams mlp = (MarginLayoutParams) mDialogView.getLayoutParams(); |
| 524 | final int bottomMargin = collapsing ? mDialogContentView.getHeight() : |
| 525 | mContext.getResources().getDimensionPixelSize(R.dimen.volume_dialog_margin_bottom); |
| 526 | if (bottomMargin != mlp.bottomMargin) { |
| 527 | if (D.BUG) Log.d(TAG, "bottomMargin " + mlp.bottomMargin + " -> " + bottomMargin); |
| 528 | mlp.bottomMargin = bottomMargin; |
| 529 | mDialogView.setLayoutParams(mlp); |
| 530 | } |
| 531 | } |
| 532 | |
| 533 | private long getConservativeCollapseDuration() { |
| 534 | return mExpandButtonAnimationDuration * 3; |
| 535 | } |
| 536 | |
| 537 | private void prepareForCollapse() { |
| 538 | mHandler.removeMessages(H.UPDATE_BOTTOM_MARGIN); |
| 539 | mCollapseTime = System.currentTimeMillis(); |
| 540 | updateDialogBottomMarginH(); |
| 541 | mHandler.sendEmptyMessageDelayed(H.UPDATE_BOTTOM_MARGIN, getConservativeCollapseDuration()); |
| 542 | } |
| 543 | |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 544 | private void setExpandedH(boolean expanded) { |
| 545 | if (mExpanded == expanded) return; |
| 546 | mExpanded = expanded; |
John Spurlock | 22def3d | 2015-06-17 11:56:12 -0400 | [diff] [blame] | 547 | mExpandButtonAnimationRunning = isAttached(); |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 548 | if (D.BUG) Log.d(TAG, "setExpandedH " + expanded); |
John Spurlock | 22def3d | 2015-06-17 11:56:12 -0400 | [diff] [blame] | 549 | if (!mExpanded && mExpandButtonAnimationRunning) { |
| 550 | prepareForCollapse(); |
| 551 | } |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 552 | updateRowsH(); |
John Spurlock | 22def3d | 2015-06-17 11:56:12 -0400 | [diff] [blame] | 553 | if (mExpandButtonAnimationRunning) { |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 554 | final Drawable d = mExpandButton.getDrawable(); |
| 555 | if (d instanceof AnimatedVectorDrawable) { |
| 556 | // workaround to reset drawable |
| 557 | final AnimatedVectorDrawable avd = (AnimatedVectorDrawable) d.getConstantState() |
| 558 | .newDrawable(); |
| 559 | mExpandButton.setImageDrawable(avd); |
| 560 | avd.start(); |
| 561 | mHandler.postDelayed(new Runnable() { |
| 562 | @Override |
| 563 | public void run() { |
John Spurlock | 22def3d | 2015-06-17 11:56:12 -0400 | [diff] [blame] | 564 | mExpandButtonAnimationRunning = false; |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 565 | updateExpandButtonH(); |
| 566 | rescheduleTimeoutH(); |
| 567 | } |
| 568 | }, mExpandButtonAnimationDuration); |
| 569 | } |
| 570 | } |
| 571 | rescheduleTimeoutH(); |
| 572 | } |
| 573 | |
| 574 | private void updateExpandButtonH() { |
John Spurlock | 22def3d | 2015-06-17 11:56:12 -0400 | [diff] [blame] | 575 | if (D.BUG) Log.d(TAG, "updateExpandButtonH"); |
| 576 | mExpandButton.setClickable(!mExpandButtonAnimationRunning); |
| 577 | if (mExpandButtonAnimationRunning && isAttached()) return; |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 578 | final int res = mExpanded ? R.drawable.ic_volume_collapse_animation |
| 579 | : R.drawable.ic_volume_expand_animation; |
Takayuki Hoshi | bb0ec55 | 2015-12-17 20:50:25 +0900 | [diff] [blame] | 580 | if (hasTouchFeature()) { |
| 581 | mExpandButton.setImageResource(res); |
| 582 | } else { |
| 583 | // if there is no touch feature, show the volume ringer instead |
| 584 | mExpandButton.setImageResource(R.drawable.ic_volume_ringer); |
| 585 | mExpandButton.setBackgroundResource(0); // remove gray background emphasis |
| 586 | } |
John Spurlock | 5adeabc | 2015-05-05 14:50:43 -0400 | [diff] [blame] | 587 | mExpandButton.setContentDescription(mContext.getString(mExpanded ? |
| 588 | R.string.accessibility_volume_collapse : R.string.accessibility_volume_expand)); |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 589 | } |
| 590 | |
| 591 | private boolean isVisibleH(VolumeRow row, boolean isActive) { |
| 592 | return mExpanded && row.view.getVisibility() == View.VISIBLE |
| 593 | || (mExpanded && (row.important || isActive)) |
| 594 | || !mExpanded && isActive; |
| 595 | } |
| 596 | |
| 597 | private void updateRowsH() { |
John Spurlock | 22def3d | 2015-06-17 11:56:12 -0400 | [diff] [blame] | 598 | if (D.BUG) Log.d(TAG, "updateRowsH"); |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 599 | final VolumeRow activeRow = getActiveRow(); |
| 600 | updateFooterH(); |
| 601 | updateExpandButtonH(); |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 602 | if (!mShowing) { |
| 603 | trimObsoleteH(); |
| 604 | } |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 605 | // apply changes to all rows |
| 606 | for (VolumeRow row : mRows) { |
| 607 | final boolean isActive = row == activeRow; |
| 608 | final boolean visible = isVisibleH(row, isActive); |
| 609 | Util.setVisOrGone(row.view, visible); |
| 610 | Util.setVisOrGone(row.space, visible && mExpanded); |
John Spurlock | 0265657 | 2015-06-10 09:33:34 -0400 | [diff] [blame] | 611 | updateVolumeRowHeaderVisibleH(row); |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 612 | row.header.setAlpha(mExpanded && isActive ? 1 : 0.5f); |
John Spurlock | ecc8058 | 2015-05-13 16:23:14 -0400 | [diff] [blame] | 613 | updateVolumeRowSliderTintH(row, isActive); |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 614 | } |
| 615 | } |
| 616 | |
| 617 | private void trimObsoleteH() { |
John Spurlock | 22def3d | 2015-06-17 11:56:12 -0400 | [diff] [blame] | 618 | if (D.BUG) Log.d(TAG, "trimObsoleteH"); |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 619 | for (int i = mRows.size() -1; i >= 0; i--) { |
| 620 | final VolumeRow row = mRows.get(i); |
| 621 | if (row.ss == null || !row.ss.dynamic) continue; |
| 622 | if (!mDynamic.get(row.stream)) { |
| 623 | mRows.remove(i); |
Julia Reynolds | e80f675 | 2016-04-20 14:37:39 -0400 | [diff] [blame] | 624 | mDialogContentView.removeView(row.view); |
| 625 | mDialogContentView.removeView(row.space); |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 626 | } |
| 627 | } |
| 628 | } |
| 629 | |
| 630 | private void onStateChangedH(State state) { |
John Spurlock | 22def3d | 2015-06-17 11:56:12 -0400 | [diff] [blame] | 631 | final boolean animating = mMotion.isAnimating(); |
| 632 | if (D.BUG) Log.d(TAG, "onStateChangedH animating=" + animating); |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 633 | mState = state; |
John Spurlock | 22def3d | 2015-06-17 11:56:12 -0400 | [diff] [blame] | 634 | if (animating) { |
| 635 | mPendingStateChanged = true; |
| 636 | return; |
| 637 | } |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 638 | mDynamic.clear(); |
| 639 | // add any new dynamic rows |
| 640 | for (int i = 0; i < state.states.size(); i++) { |
| 641 | final int stream = state.states.keyAt(i); |
| 642 | final StreamState ss = state.states.valueAt(i); |
| 643 | if (!ss.dynamic) continue; |
| 644 | mDynamic.put(stream, true); |
| 645 | if (findRow(stream) == null) { |
| 646 | addRow(stream, R.drawable.ic_volume_remote, R.drawable.ic_volume_remote_mute, true); |
| 647 | } |
| 648 | } |
| 649 | |
| 650 | if (mActiveStream != state.activeStream) { |
| 651 | mActiveStream = state.activeStream; |
| 652 | updateRowsH(); |
| 653 | rescheduleTimeoutH(); |
| 654 | } |
| 655 | for (VolumeRow row : mRows) { |
| 656 | updateVolumeRowH(row); |
| 657 | } |
| 658 | updateFooterH(); |
| 659 | } |
| 660 | |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 661 | private void updateFooterH() { |
John Spurlock | 22def3d | 2015-06-17 11:56:12 -0400 | [diff] [blame] | 662 | if (D.BUG) Log.d(TAG, "updateFooterH"); |
| 663 | final boolean wasVisible = mZenFooter.getVisibility() == View.VISIBLE; |
Julia Reynolds | 6aa83b4 | 2015-09-08 13:41:45 -0400 | [diff] [blame] | 664 | final boolean visible = mState.zenMode != Global.ZEN_MODE_OFF |
Jason Monk | e138f55 | 2016-01-18 09:21:45 -0500 | [diff] [blame] | 665 | && (mAudioManager.isStreamAffectedByRingerMode(mActiveStream) || mExpanded) |
Jason Monk | aa911b3 | 2016-02-10 21:01:30 -0500 | [diff] [blame] | 666 | && !mZenPanel.isEditing(); |
John Spurlock | 22def3d | 2015-06-17 11:56:12 -0400 | [diff] [blame] | 667 | if (wasVisible != visible && !visible) { |
| 668 | prepareForCollapse(); |
| 669 | } |
| 670 | Util.setVisOrGone(mZenFooter, visible); |
John Spurlock | d9c75db | 2015-04-28 11:19:13 -0400 | [diff] [blame] | 671 | mZenFooter.update(); |
Jason Monk | e138f55 | 2016-01-18 09:21:45 -0500 | [diff] [blame] | 672 | |
| 673 | final boolean fullWasVisible = mZenPanel.getVisibility() == View.VISIBLE; |
Jason Monk | aa911b3 | 2016-02-10 21:01:30 -0500 | [diff] [blame] | 674 | final boolean fullVisible = mShowFullZen && !visible; |
Jason Monk | e138f55 | 2016-01-18 09:21:45 -0500 | [diff] [blame] | 675 | if (fullWasVisible != fullVisible && !fullVisible) { |
| 676 | prepareForCollapse(); |
| 677 | } |
| 678 | Util.setVisOrGone(mZenPanel, fullVisible); |
Jason Monk | aa911b3 | 2016-02-10 21:01:30 -0500 | [diff] [blame] | 679 | if (fullVisible) { |
| 680 | mZenPanel.setZenState(mState.zenMode); |
| 681 | mZenPanel.setDoneListener(new OnClickListener() { |
| 682 | @Override |
| 683 | public void onClick(View v) { |
| 684 | prepareForCollapse(); |
| 685 | mHandler.sendEmptyMessage(H.UPDATE_FOOTER); |
| 686 | } |
| 687 | }); |
| 688 | } |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 689 | } |
| 690 | |
| 691 | private void updateVolumeRowH(VolumeRow row) { |
John Spurlock | 22def3d | 2015-06-17 11:56:12 -0400 | [diff] [blame] | 692 | if (D.BUG) Log.d(TAG, "updateVolumeRowH s=" + row.stream); |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 693 | if (mState == null) return; |
| 694 | final StreamState ss = mState.states.get(row.stream); |
| 695 | if (ss == null) return; |
| 696 | row.ss = ss; |
| 697 | if (ss.level > 0) { |
| 698 | row.lastAudibleLevel = ss.level; |
| 699 | } |
John Spurlock | b0a2e5f | 2015-06-09 14:41:52 -0400 | [diff] [blame] | 700 | if (ss.level == row.requestedLevel) { |
| 701 | row.requestedLevel = -1; |
| 702 | } |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 703 | final boolean isRingStream = row.stream == AudioManager.STREAM_RING; |
| 704 | final boolean isSystemStream = row.stream == AudioManager.STREAM_SYSTEM; |
John Spurlock | d9c75db | 2015-04-28 11:19:13 -0400 | [diff] [blame] | 705 | final boolean isAlarmStream = row.stream == AudioManager.STREAM_ALARM; |
| 706 | final boolean isMusicStream = row.stream == AudioManager.STREAM_MUSIC; |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 707 | final boolean isRingVibrate = isRingStream |
| 708 | && mState.ringerModeInternal == AudioManager.RINGER_MODE_VIBRATE; |
John Spurlock | d9c75db | 2015-04-28 11:19:13 -0400 | [diff] [blame] | 709 | final boolean isRingSilent = isRingStream |
| 710 | && mState.ringerModeInternal == AudioManager.RINGER_MODE_SILENT; |
| 711 | final boolean isZenAlarms = mState.zenMode == Global.ZEN_MODE_ALARMS; |
| 712 | final boolean isZenNone = mState.zenMode == Global.ZEN_MODE_NO_INTERRUPTIONS; |
| 713 | final boolean isZenPriority = mState.zenMode == Global.ZEN_MODE_IMPORTANT_INTERRUPTIONS; |
| 714 | final boolean isRingZenNone = (isRingStream || isSystemStream) && isZenNone; |
| 715 | final boolean isRingLimited = isRingStream && isZenPriority; |
| 716 | final boolean zenMuted = isZenAlarms ? (isRingStream || isSystemStream) |
| 717 | : isZenNone ? (isRingStream || isSystemStream || isAlarmStream || isMusicStream) |
| 718 | : false; |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 719 | |
| 720 | // update slider max |
Julia Reynolds | 4b006a8 | 2016-04-20 16:09:06 -0400 | [diff] [blame^] | 721 | final int max = ss.levelMax * 100; |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 722 | if (max != row.slider.getMax()) { |
| 723 | row.slider.setMax(max); |
| 724 | } |
| 725 | |
| 726 | // update header visible |
John Spurlock | 0265657 | 2015-06-10 09:33:34 -0400 | [diff] [blame] | 727 | updateVolumeRowHeaderVisibleH(row); |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 728 | |
| 729 | // update header text |
John Spurlock | 0265657 | 2015-06-10 09:33:34 -0400 | [diff] [blame] | 730 | String text = ss.name; |
| 731 | if (mShowHeaders) { |
| 732 | if (isRingZenNone) { |
| 733 | text = mContext.getString(R.string.volume_stream_muted_dnd, ss.name); |
| 734 | } else if (isRingVibrate && isRingLimited) { |
| 735 | text = mContext.getString(R.string.volume_stream_vibrate_dnd, ss.name); |
| 736 | } else if (isRingVibrate) { |
| 737 | text = mContext.getString(R.string.volume_stream_vibrate, ss.name); |
| 738 | } else if (ss.muted || mAutomute && ss.level == 0) { |
| 739 | text = mContext.getString(R.string.volume_stream_muted, ss.name); |
| 740 | } else if (isRingLimited) { |
| 741 | text = mContext.getString(R.string.volume_stream_limited_dnd, ss.name); |
| 742 | } |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 743 | } |
| 744 | Util.setText(row.header, text); |
| 745 | |
| 746 | // update icon |
John Spurlock | d9c75db | 2015-04-28 11:19:13 -0400 | [diff] [blame] | 747 | final boolean iconEnabled = (mAutomute || ss.muteSupported) && !zenMuted; |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 748 | row.icon.setEnabled(iconEnabled); |
| 749 | row.icon.setAlpha(iconEnabled ? 1 : 0.5f); |
| 750 | final int iconRes = |
John Spurlock | 76b52b3 | 2015-04-03 00:00:12 -0400 | [diff] [blame] | 751 | isRingVibrate ? R.drawable.ic_volume_ringer_vibrate |
John Spurlock | d9c75db | 2015-04-28 11:19:13 -0400 | [diff] [blame] | 752 | : isRingSilent || zenMuted ? row.cachedIconRes |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 753 | : ss.routedToBluetooth ? |
John Spurlock | f15ef11 | 2015-04-09 22:04:14 -0400 | [diff] [blame] | 754 | (ss.muted ? R.drawable.ic_volume_media_bt_mute |
| 755 | : R.drawable.ic_volume_media_bt) |
John Spurlock | 76b52b3 | 2015-04-03 00:00:12 -0400 | [diff] [blame] | 756 | : mAutomute && ss.level == 0 ? row.iconMuteRes |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 757 | : (ss.muted ? row.iconMuteRes : row.iconRes); |
| 758 | if (iconRes != row.cachedIconRes) { |
| 759 | if (row.cachedIconRes != 0 && isRingVibrate) { |
| 760 | mController.vibrate(); |
| 761 | } |
| 762 | row.cachedIconRes = iconRes; |
| 763 | row.icon.setImageResource(iconRes); |
| 764 | } |
| 765 | row.iconState = |
| 766 | iconRes == R.drawable.ic_volume_ringer_vibrate ? Events.ICON_STATE_VIBRATE |
John Spurlock | f15ef11 | 2015-04-09 22:04:14 -0400 | [diff] [blame] | 767 | : (iconRes == R.drawable.ic_volume_media_bt_mute || iconRes == row.iconMuteRes) |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 768 | ? Events.ICON_STATE_MUTE |
John Spurlock | f15ef11 | 2015-04-09 22:04:14 -0400 | [diff] [blame] | 769 | : (iconRes == R.drawable.ic_volume_media_bt || iconRes == row.iconRes) |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 770 | ? Events.ICON_STATE_UNMUTE |
| 771 | : Events.ICON_STATE_UNKNOWN; |
Julia Reynolds | dfe0b4d | 2016-04-08 17:14:15 -0400 | [diff] [blame] | 772 | if (iconEnabled) { |
| 773 | if (isRingStream) { |
| 774 | if (isRingVibrate) { |
| 775 | row.icon.setContentDescription(mContext.getString( |
| 776 | R.string.volume_stream_content_description_unmute, |
| 777 | ss.name)); |
| 778 | } else { |
| 779 | if (mController.hasVibrator()) { |
| 780 | row.icon.setContentDescription(mContext.getString( |
| 781 | R.string.volume_stream_content_description_vibrate, |
| 782 | ss.name)); |
| 783 | } else { |
| 784 | row.icon.setContentDescription(mContext.getString( |
| 785 | R.string.volume_stream_content_description_mute, |
| 786 | ss.name)); |
| 787 | } |
| 788 | } |
| 789 | } else { |
| 790 | if (ss.muted || mAutomute && ss.level == 0) { |
| 791 | row.icon.setContentDescription(mContext.getString( |
| 792 | R.string.volume_stream_content_description_unmute, |
| 793 | ss.name)); |
| 794 | } else { |
| 795 | row.icon.setContentDescription(mContext.getString( |
| 796 | R.string.volume_stream_content_description_mute, |
| 797 | ss.name)); |
| 798 | } |
| 799 | } |
| 800 | } else { |
| 801 | row.icon.setContentDescription(ss.name); |
| 802 | } |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 803 | |
| 804 | // update slider |
John Spurlock | b0a2e5f | 2015-06-09 14:41:52 -0400 | [diff] [blame] | 805 | final boolean enableSlider = !zenMuted; |
| 806 | final int vlevel = row.ss.muted && (isRingVibrate || !isRingStream && !zenMuted) ? 0 |
| 807 | : row.ss.level; |
| 808 | updateVolumeRowSliderH(row, enableSlider, vlevel); |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 809 | } |
| 810 | |
John Spurlock | 0265657 | 2015-06-10 09:33:34 -0400 | [diff] [blame] | 811 | private void updateVolumeRowHeaderVisibleH(VolumeRow row) { |
| 812 | final boolean dynamic = row.ss != null && row.ss.dynamic; |
| 813 | final boolean showHeaders = mShowHeaders || mExpanded && dynamic; |
| 814 | if (row.cachedShowHeaders != showHeaders) { |
| 815 | row.cachedShowHeaders = showHeaders; |
| 816 | Util.setVisOrGone(row.header, showHeaders); |
| 817 | } |
| 818 | } |
| 819 | |
John Spurlock | ecc8058 | 2015-05-13 16:23:14 -0400 | [diff] [blame] | 820 | private void updateVolumeRowSliderTintH(VolumeRow row, boolean isActive) { |
John Spurlock | 67a0f85 | 2015-06-15 15:35:47 -0400 | [diff] [blame] | 821 | if (isActive && mExpanded) { |
John Spurlock | 67a0f85 | 2015-06-15 15:35:47 -0400 | [diff] [blame] | 822 | row.slider.requestFocus(); |
John Spurlock | 67a0f85 | 2015-06-15 15:35:47 -0400 | [diff] [blame] | 823 | } |
John Spurlock | ecc8058 | 2015-05-13 16:23:14 -0400 | [diff] [blame] | 824 | final ColorStateList tint = isActive && row.slider.isEnabled() ? mActiveSliderTint |
| 825 | : mInactiveSliderTint; |
| 826 | if (tint == row.cachedSliderTint) return; |
| 827 | row.cachedSliderTint = tint; |
| 828 | row.slider.setProgressTintList(tint); |
| 829 | row.slider.setThumbTintList(tint); |
| 830 | } |
| 831 | |
John Spurlock | b0a2e5f | 2015-06-09 14:41:52 -0400 | [diff] [blame] | 832 | private void updateVolumeRowSliderH(VolumeRow row, boolean enable, int vlevel) { |
| 833 | row.slider.setEnabled(enable); |
John Spurlock | ecc8058 | 2015-05-13 16:23:14 -0400 | [diff] [blame] | 834 | updateVolumeRowSliderTintH(row, row.stream == mActiveStream); |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 835 | if (row.tracking) { |
| 836 | return; // don't update if user is sliding |
| 837 | } |
Julia Reynolds | 4b006a8 | 2016-04-20 16:09:06 -0400 | [diff] [blame^] | 838 | final int progress = row.slider.getProgress(); |
| 839 | final int level = getImpliedLevel(row.slider, progress); |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 840 | final boolean rowVisible = row.view.getVisibility() == View.VISIBLE; |
| 841 | final boolean inGracePeriod = (SystemClock.uptimeMillis() - row.userAttempt) |
| 842 | < USER_ATTEMPT_GRACE_PERIOD; |
| 843 | mHandler.removeMessages(H.RECHECK, row); |
| 844 | if (mShowing && rowVisible && inGracePeriod) { |
| 845 | if (D.BUG) Log.d(TAG, "inGracePeriod"); |
| 846 | mHandler.sendMessageAtTime(mHandler.obtainMessage(H.RECHECK, row), |
| 847 | row.userAttempt + USER_ATTEMPT_GRACE_PERIOD); |
| 848 | return; // don't update if visible and in grace period |
| 849 | } |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 850 | if (vlevel == level) { |
| 851 | if (mShowing && rowVisible) { |
| 852 | return; // don't clamp if visible |
| 853 | } |
| 854 | } |
Julia Reynolds | 4b006a8 | 2016-04-20 16:09:06 -0400 | [diff] [blame^] | 855 | final int newProgress = vlevel * 100; |
| 856 | if (progress != newProgress) { |
| 857 | if (mShowing && rowVisible) { |
| 858 | // animate! |
| 859 | if (row.anim != null && row.anim.isRunning() |
| 860 | && row.animTargetProgress == newProgress) { |
| 861 | return; // already animating to the target progress |
| 862 | } |
| 863 | // start/update animation |
| 864 | if (row.anim == null) { |
| 865 | row.anim = ObjectAnimator.ofInt(row.slider, "progress", progress, newProgress); |
| 866 | row.anim.setInterpolator(new DecelerateInterpolator()); |
| 867 | } else { |
| 868 | row.anim.cancel(); |
| 869 | row.anim.setIntValues(progress, newProgress); |
| 870 | } |
| 871 | row.animTargetProgress = newProgress; |
| 872 | row.anim.setDuration(UPDATE_ANIMATION_DURATION); |
| 873 | row.anim.start(); |
| 874 | } else { |
| 875 | // update slider directly to clamped value |
| 876 | if (row.anim != null) { |
| 877 | row.anim.cancel(); |
| 878 | } |
| 879 | row.slider.setProgress(newProgress); |
| 880 | } |
| 881 | } |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 882 | } |
| 883 | |
| 884 | private void recheckH(VolumeRow row) { |
| 885 | if (row == null) { |
| 886 | if (D.BUG) Log.d(TAG, "recheckH ALL"); |
| 887 | trimObsoleteH(); |
| 888 | for (VolumeRow r : mRows) { |
| 889 | updateVolumeRowH(r); |
| 890 | } |
| 891 | } else { |
| 892 | if (D.BUG) Log.d(TAG, "recheckH " + row.stream); |
| 893 | updateVolumeRowH(row); |
| 894 | } |
| 895 | } |
| 896 | |
| 897 | private void setStreamImportantH(int stream, boolean important) { |
| 898 | for (VolumeRow row : mRows) { |
| 899 | if (row.stream == stream) { |
| 900 | row.important = important; |
| 901 | return; |
| 902 | } |
| 903 | } |
| 904 | } |
| 905 | |
John Spurlock | 76b52b3 | 2015-04-03 00:00:12 -0400 | [diff] [blame] | 906 | private void showSafetyWarningH(int flags) { |
| 907 | if ((flags & (AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_SHOW_UI_WARNINGS)) != 0 |
| 908 | || mShowing) { |
| 909 | synchronized (mSafetyWarningLock) { |
| 910 | if (mSafetyWarning != null) { |
| 911 | return; |
| 912 | } |
| 913 | mSafetyWarning = new SafetyWarningDialog(mContext, mController.getAudioManager()) { |
| 914 | @Override |
| 915 | protected void cleanUp() { |
| 916 | synchronized (mSafetyWarningLock) { |
| 917 | mSafetyWarning = null; |
| 918 | } |
| 919 | recheckH(null); |
| 920 | } |
| 921 | }; |
| 922 | mSafetyWarning.show(); |
| 923 | } |
| 924 | recheckH(null); |
| 925 | } |
| 926 | rescheduleTimeoutH(); |
| 927 | } |
| 928 | |
Takayuki Hoshi | bb0ec55 | 2015-12-17 20:50:25 +0900 | [diff] [blame] | 929 | private boolean hasTouchFeature() { |
| 930 | final PackageManager pm = mContext.getPackageManager(); |
| 931 | return pm.hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN); |
| 932 | } |
| 933 | |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 934 | private final VolumeDialogController.Callbacks mControllerCallbackH |
| 935 | = new VolumeDialogController.Callbacks() { |
| 936 | @Override |
| 937 | public void onShowRequested(int reason) { |
| 938 | showH(reason); |
| 939 | } |
| 940 | |
| 941 | @Override |
| 942 | public void onDismissRequested(int reason) { |
| 943 | dismissH(reason); |
| 944 | } |
| 945 | |
John Spurlock | 76b52b3 | 2015-04-03 00:00:12 -0400 | [diff] [blame] | 946 | @Override |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 947 | public void onScreenOff() { |
| 948 | dismissH(Events.DISMISS_REASON_SCREEN_OFF); |
| 949 | } |
| 950 | |
| 951 | @Override |
| 952 | public void onStateChanged(State state) { |
| 953 | onStateChangedH(state); |
| 954 | } |
| 955 | |
| 956 | @Override |
| 957 | public void onLayoutDirectionChanged(int layoutDirection) { |
| 958 | mDialogView.setLayoutDirection(layoutDirection); |
| 959 | } |
| 960 | |
| 961 | @Override |
| 962 | public void onConfigurationChanged() { |
Julia Reynolds | c791e05 | 2016-02-19 16:02:01 -0500 | [diff] [blame] | 963 | Configuration newConfig = mContext.getResources().getConfiguration(); |
| 964 | final int density = newConfig.densityDpi; |
| 965 | if (density != mDensity) { |
| 966 | mDialog.dismiss(); |
| 967 | initDialog(); |
| 968 | } |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 969 | updateWindowWidthH(); |
| 970 | mSpTexts.update(); |
John Spurlock | 9ea3a1e | 2015-05-06 17:12:18 -0400 | [diff] [blame] | 971 | mZenFooter.onConfigurationChanged(); |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 972 | } |
| 973 | |
| 974 | @Override |
| 975 | public void onShowVibrateHint() { |
| 976 | if (mSilentMode) { |
| 977 | mController.setRingerMode(AudioManager.RINGER_MODE_SILENT, false); |
| 978 | } |
| 979 | } |
| 980 | |
John Spurlock | 76b52b3 | 2015-04-03 00:00:12 -0400 | [diff] [blame] | 981 | @Override |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 982 | public void onShowSilentHint() { |
| 983 | if (mSilentMode) { |
| 984 | mController.setRingerMode(AudioManager.RINGER_MODE_NORMAL, false); |
| 985 | } |
| 986 | } |
John Spurlock | 76b52b3 | 2015-04-03 00:00:12 -0400 | [diff] [blame] | 987 | |
| 988 | @Override |
| 989 | public void onShowSafetyWarning(int flags) { |
| 990 | showSafetyWarningH(flags); |
| 991 | } |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 992 | }; |
| 993 | |
Jason Monk | e138f55 | 2016-01-18 09:21:45 -0500 | [diff] [blame] | 994 | private final ZenModePanel.Callback mZenPanelCallback = new ZenModePanel.Callback() { |
| 995 | @Override |
| 996 | public void onPrioritySettings() { |
| 997 | mCallback.onZenPrioritySettingsClicked(); |
| 998 | } |
| 999 | |
| 1000 | @Override |
| 1001 | public void onInteraction() { |
| 1002 | mHandler.sendEmptyMessage(H.RESCHEDULE_TIMEOUT); |
| 1003 | } |
| 1004 | |
| 1005 | @Override |
| 1006 | public void onExpanded(boolean expanded) { |
| 1007 | // noop. |
| 1008 | } |
| 1009 | }; |
| 1010 | |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 1011 | private final OnClickListener mClickExpand = new OnClickListener() { |
| 1012 | @Override |
| 1013 | public void onClick(View v) { |
John Spurlock | 22def3d | 2015-06-17 11:56:12 -0400 | [diff] [blame] | 1014 | if (mExpandButtonAnimationRunning) return; |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 1015 | final boolean newExpand = !mExpanded; |
Chris Wren | e565ee6 | 2015-06-17 15:24:56 -0400 | [diff] [blame] | 1016 | Events.writeEvent(mContext, Events.EVENT_EXPAND, newExpand); |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 1017 | setExpandedH(newExpand); |
| 1018 | } |
| 1019 | }; |
| 1020 | |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 1021 | private final class H extends Handler { |
| 1022 | private static final int SHOW = 1; |
| 1023 | private static final int DISMISS = 2; |
| 1024 | private static final int RECHECK = 3; |
| 1025 | private static final int RECHECK_ALL = 4; |
| 1026 | private static final int SET_STREAM_IMPORTANT = 5; |
| 1027 | private static final int RESCHEDULE_TIMEOUT = 6; |
John Spurlock | 22def3d | 2015-06-17 11:56:12 -0400 | [diff] [blame] | 1028 | private static final int STATE_CHANGED = 7; |
| 1029 | private static final int UPDATE_BOTTOM_MARGIN = 8; |
Jason Monk | aa911b3 | 2016-02-10 21:01:30 -0500 | [diff] [blame] | 1030 | private static final int UPDATE_FOOTER = 9; |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 1031 | |
| 1032 | public H() { |
| 1033 | super(Looper.getMainLooper()); |
| 1034 | } |
| 1035 | |
| 1036 | @Override |
| 1037 | public void handleMessage(Message msg) { |
| 1038 | switch (msg.what) { |
| 1039 | case SHOW: showH(msg.arg1); break; |
| 1040 | case DISMISS: dismissH(msg.arg1); break; |
| 1041 | case RECHECK: recheckH((VolumeRow) msg.obj); break; |
| 1042 | case RECHECK_ALL: recheckH(null); break; |
| 1043 | case SET_STREAM_IMPORTANT: setStreamImportantH(msg.arg1, msg.arg2 != 0); break; |
| 1044 | case RESCHEDULE_TIMEOUT: rescheduleTimeoutH(); break; |
John Spurlock | 22def3d | 2015-06-17 11:56:12 -0400 | [diff] [blame] | 1045 | case STATE_CHANGED: onStateChangedH(mState); break; |
| 1046 | case UPDATE_BOTTOM_MARGIN: updateDialogBottomMarginH(); break; |
Jason Monk | aa911b3 | 2016-02-10 21:01:30 -0500 | [diff] [blame] | 1047 | case UPDATE_FOOTER: updateFooterH(); break; |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 1048 | } |
| 1049 | } |
| 1050 | } |
| 1051 | |
| 1052 | private final class CustomDialog extends Dialog { |
| 1053 | public CustomDialog(Context context) { |
| 1054 | super(context); |
| 1055 | } |
| 1056 | |
| 1057 | @Override |
| 1058 | public boolean dispatchTouchEvent(MotionEvent ev) { |
| 1059 | rescheduleTimeoutH(); |
| 1060 | return super.dispatchTouchEvent(ev); |
| 1061 | } |
| 1062 | |
| 1063 | @Override |
| 1064 | protected void onStop() { |
| 1065 | super.onStop(); |
John Spurlock | 22def3d | 2015-06-17 11:56:12 -0400 | [diff] [blame] | 1066 | final boolean animating = mMotion.isAnimating(); |
| 1067 | if (D.BUG) Log.d(TAG, "onStop animating=" + animating); |
| 1068 | if (animating) { |
| 1069 | mPendingRecheckAll = true; |
| 1070 | return; |
| 1071 | } |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 1072 | mHandler.sendEmptyMessage(H.RECHECK_ALL); |
| 1073 | } |
| 1074 | |
| 1075 | @Override |
| 1076 | public boolean onTouchEvent(MotionEvent event) { |
| 1077 | if (isShowing()) { |
| 1078 | if (event.getAction() == MotionEvent.ACTION_OUTSIDE) { |
| 1079 | dismissH(Events.DISMISS_REASON_TOUCH_OUTSIDE); |
| 1080 | return true; |
| 1081 | } |
| 1082 | } |
| 1083 | return false; |
| 1084 | } |
| 1085 | } |
| 1086 | |
| 1087 | private final class VolumeSeekBarChangeListener implements OnSeekBarChangeListener { |
| 1088 | private final VolumeRow mRow; |
| 1089 | |
| 1090 | private VolumeSeekBarChangeListener(VolumeRow row) { |
| 1091 | mRow = row; |
| 1092 | } |
| 1093 | |
| 1094 | @Override |
| 1095 | public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { |
| 1096 | if (mRow.ss == null) return; |
| 1097 | if (D.BUG) Log.d(TAG, AudioSystem.streamToString(mRow.stream) |
| 1098 | + " onProgressChanged " + progress + " fromUser=" + fromUser); |
| 1099 | if (!fromUser) return; |
| 1100 | if (mRow.ss.levelMin > 0) { |
Julia Reynolds | 4b006a8 | 2016-04-20 16:09:06 -0400 | [diff] [blame^] | 1101 | final int minProgress = mRow.ss.levelMin * 100; |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 1102 | if (progress < minProgress) { |
| 1103 | seekBar.setProgress(minProgress); |
Julia Reynolds | 798b0c3 | 2015-09-01 14:35:53 -0400 | [diff] [blame] | 1104 | progress = minProgress; |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 1105 | } |
| 1106 | } |
Julia Reynolds | 4b006a8 | 2016-04-20 16:09:06 -0400 | [diff] [blame^] | 1107 | final int userLevel = getImpliedLevel(seekBar, progress); |
| 1108 | if (mRow.ss.level != userLevel || mRow.ss.muted && userLevel > 0) { |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 1109 | mRow.userAttempt = SystemClock.uptimeMillis(); |
Julia Reynolds | 4b006a8 | 2016-04-20 16:09:06 -0400 | [diff] [blame^] | 1110 | if (mRow.requestedLevel != userLevel) { |
| 1111 | mController.setStreamVolume(mRow.stream, userLevel); |
| 1112 | mRow.requestedLevel = userLevel; |
Chris Wren | e565ee6 | 2015-06-17 15:24:56 -0400 | [diff] [blame] | 1113 | Events.writeEvent(mContext, Events.EVENT_TOUCH_LEVEL_CHANGED, mRow.stream, |
Julia Reynolds | 4b006a8 | 2016-04-20 16:09:06 -0400 | [diff] [blame^] | 1114 | userLevel); |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 1115 | } |
| 1116 | } |
| 1117 | } |
| 1118 | |
| 1119 | @Override |
| 1120 | public void onStartTrackingTouch(SeekBar seekBar) { |
| 1121 | if (D.BUG) Log.d(TAG, "onStartTrackingTouch"+ " " + mRow.stream); |
| 1122 | mController.setActiveStream(mRow.stream); |
| 1123 | mRow.tracking = true; |
| 1124 | } |
| 1125 | |
| 1126 | @Override |
| 1127 | public void onStopTrackingTouch(SeekBar seekBar) { |
| 1128 | if (D.BUG) Log.d(TAG, "onStopTrackingTouch"+ " " + mRow.stream); |
| 1129 | mRow.tracking = false; |
| 1130 | mRow.userAttempt = SystemClock.uptimeMillis(); |
Julia Reynolds | 4b006a8 | 2016-04-20 16:09:06 -0400 | [diff] [blame^] | 1131 | final int userLevel = getImpliedLevel(seekBar, seekBar.getProgress()); |
Chris Wren | e565ee6 | 2015-06-17 15:24:56 -0400 | [diff] [blame] | 1132 | Events.writeEvent(mContext, Events.EVENT_TOUCH_LEVEL_DONE, mRow.stream, userLevel); |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 1133 | if (mRow.ss.level != userLevel) { |
| 1134 | mHandler.sendMessageDelayed(mHandler.obtainMessage(H.RECHECK, mRow), |
| 1135 | USER_ATTEMPT_GRACE_PERIOD); |
| 1136 | } |
| 1137 | } |
| 1138 | } |
| 1139 | |
John Spurlock | f09838b | 2015-06-11 16:14:44 -0400 | [diff] [blame] | 1140 | private final class Accessibility extends AccessibilityDelegate { |
John Spurlock | 5adeabc | 2015-05-05 14:50:43 -0400 | [diff] [blame] | 1141 | private AccessibilityManager mMgr; |
| 1142 | private boolean mFeedbackEnabled; |
| 1143 | |
| 1144 | public void init() { |
| 1145 | mMgr = (AccessibilityManager) mContext.getSystemService(Context.ACCESSIBILITY_SERVICE); |
| 1146 | mDialogView.addOnAttachStateChangeListener(new OnAttachStateChangeListener() { |
| 1147 | @Override |
| 1148 | public void onViewDetachedFromWindow(View v) { |
John Spurlock | 22def3d | 2015-06-17 11:56:12 -0400 | [diff] [blame] | 1149 | if (D.BUG) Log.d(TAG, "onViewDetachedFromWindow"); |
John Spurlock | 5adeabc | 2015-05-05 14:50:43 -0400 | [diff] [blame] | 1150 | // noop |
| 1151 | } |
| 1152 | |
| 1153 | @Override |
| 1154 | public void onViewAttachedToWindow(View v) { |
John Spurlock | 22def3d | 2015-06-17 11:56:12 -0400 | [diff] [blame] | 1155 | if (D.BUG) Log.d(TAG, "onViewAttachedToWindow"); |
John Spurlock | 5adeabc | 2015-05-05 14:50:43 -0400 | [diff] [blame] | 1156 | updateFeedbackEnabled(); |
| 1157 | } |
| 1158 | }); |
John Spurlock | f09838b | 2015-06-11 16:14:44 -0400 | [diff] [blame] | 1159 | mDialogView.setAccessibilityDelegate(this); |
John Spurlock | 5adeabc | 2015-05-05 14:50:43 -0400 | [diff] [blame] | 1160 | mMgr.addAccessibilityStateChangeListener(new AccessibilityStateChangeListener() { |
| 1161 | @Override |
| 1162 | public void onAccessibilityStateChanged(boolean enabled) { |
| 1163 | updateFeedbackEnabled(); |
| 1164 | } |
| 1165 | }); |
| 1166 | updateFeedbackEnabled(); |
| 1167 | } |
| 1168 | |
John Spurlock | f09838b | 2015-06-11 16:14:44 -0400 | [diff] [blame] | 1169 | @Override |
| 1170 | public boolean onRequestSendAccessibilityEvent(ViewGroup host, View child, |
| 1171 | AccessibilityEvent event) { |
| 1172 | rescheduleTimeoutH(); |
| 1173 | return super.onRequestSendAccessibilityEvent(host, child, event); |
| 1174 | } |
| 1175 | |
John Spurlock | 5adeabc | 2015-05-05 14:50:43 -0400 | [diff] [blame] | 1176 | private void updateFeedbackEnabled() { |
| 1177 | mFeedbackEnabled = computeFeedbackEnabled(); |
| 1178 | } |
| 1179 | |
| 1180 | private boolean computeFeedbackEnabled() { |
John Spurlock | f09838b | 2015-06-11 16:14:44 -0400 | [diff] [blame] | 1181 | // are there any enabled non-generic a11y services? |
John Spurlock | 5adeabc | 2015-05-05 14:50:43 -0400 | [diff] [blame] | 1182 | final List<AccessibilityServiceInfo> services = |
| 1183 | mMgr.getEnabledAccessibilityServiceList(FEEDBACK_ALL_MASK); |
| 1184 | for (AccessibilityServiceInfo asi : services) { |
John Spurlock | f09838b | 2015-06-11 16:14:44 -0400 | [diff] [blame] | 1185 | if (asi.feedbackType != 0 && asi.feedbackType != FEEDBACK_GENERIC) { |
John Spurlock | 5adeabc | 2015-05-05 14:50:43 -0400 | [diff] [blame] | 1186 | return true; |
| 1187 | } |
| 1188 | } |
| 1189 | return false; |
| 1190 | } |
| 1191 | } |
| 1192 | |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 1193 | private static class VolumeRow { |
| 1194 | private View view; |
| 1195 | private View space; |
| 1196 | private TextView header; |
| 1197 | private ImageButton icon; |
| 1198 | private SeekBar slider; |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 1199 | private int stream; |
| 1200 | private StreamState ss; |
| 1201 | private long userAttempt; // last user-driven slider change |
| 1202 | private boolean tracking; // tracking slider touch |
John Spurlock | b0a2e5f | 2015-06-09 14:41:52 -0400 | [diff] [blame] | 1203 | private int requestedLevel = -1; // pending user-requested level via progress changed |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 1204 | private int iconRes; |
| 1205 | private int iconMuteRes; |
| 1206 | private boolean important; |
| 1207 | private int cachedIconRes; |
John Spurlock | ecc8058 | 2015-05-13 16:23:14 -0400 | [diff] [blame] | 1208 | private ColorStateList cachedSliderTint; |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 1209 | private int iconState; // from Events |
John Spurlock | f55b7f2 | 2015-04-13 19:21:26 -0400 | [diff] [blame] | 1210 | private boolean cachedShowHeaders = VolumePrefs.DEFAULT_SHOW_HEADERS; |
Julia Reynolds | 4b006a8 | 2016-04-20 16:09:06 -0400 | [diff] [blame^] | 1211 | private ObjectAnimator anim; // slider progress animation for non-touch-related updates |
| 1212 | private int animTargetProgress; |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 1213 | private int lastAudibleLevel = 1; |
| 1214 | } |
John Spurlock | f55b7f2 | 2015-04-13 19:21:26 -0400 | [diff] [blame] | 1215 | |
| 1216 | public interface Callback { |
John Spurlock | f55b7f2 | 2015-04-13 19:21:26 -0400 | [diff] [blame] | 1217 | void onZenSettingsClicked(); |
| 1218 | void onZenPrioritySettingsClicked(); |
| 1219 | } |
John Spurlock | f88d808 | 2015-03-25 18:09:51 -0400 | [diff] [blame] | 1220 | } |