blob: 7000e82369e11a0c2d03553e4b3331658fcc784f [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2007 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
John Spurlock3346a802014-05-20 16:25:37 -040017package com.android.systemui.volume;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080018
Eric Laurentc34dcc12012-09-10 13:51:52 -070019import android.app.AlertDialog;
Amith Yamasani2bbdd772011-02-02 18:54:13 -080020import android.app.Dialog;
Amith Yamasani2bbdd772011-02-02 18:54:13 -080021import android.content.BroadcastReceiver;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080022import android.content.Context;
Amith Yamasani2bbdd772011-02-02 18:54:13 -080023import android.content.DialogInterface;
John Spurlock86005342014-05-23 11:58:00 -040024import android.content.DialogInterface.OnDismissListener;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080025import android.content.Intent;
Amith Yamasani2bbdd772011-02-02 18:54:13 -080026import android.content.IntentFilter;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080027import android.content.res.Resources;
John Spurlock2078caf2014-05-29 22:20:14 -040028import android.graphics.PixelFormat;
29import android.graphics.drawable.ColorDrawable;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080030import android.media.AudioManager;
31import android.media.AudioService;
32import android.media.AudioSystem;
Marco Nelissen69f593c2009-07-28 09:55:04 -070033import android.media.RingtoneManager;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080034import android.media.ToneGenerator;
Marco Nelissen69f593c2009-07-28 09:55:04 -070035import android.net.Uri;
John Spurlock3bd4fee2014-05-29 20:51:09 -040036import android.os.AsyncTask;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080037import android.os.Handler;
38import android.os.Message;
39import android.os.Vibrator;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080040import android.util.Log;
John Spurlock3346a802014-05-20 16:25:37 -040041import android.view.Gravity;
42import android.view.LayoutInflater;
43import android.view.MotionEvent;
44import android.view.View;
John Spurlock7f1df5e2014-05-31 19:11:40 -040045import android.view.View.OnClickListener;
46import android.view.View.OnLongClickListener;
John Spurlock3346a802014-05-20 16:25:37 -040047import android.view.ViewGroup;
John Spurlock86005342014-05-23 11:58:00 -040048import android.view.ViewStub;
John Spurlock3346a802014-05-20 16:25:37 -040049import android.view.Window;
50import android.view.WindowManager;
Amith Yamasani284e6302011-09-16 18:24:47 -070051import android.view.WindowManager.LayoutParams;
John Spurlock2078caf2014-05-29 22:20:14 -040052import android.widget.FrameLayout;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080053import android.widget.ImageView;
Amith Yamasani2bbdd772011-02-02 18:54:13 -080054import android.widget.SeekBar;
Amith Yamasani2bbdd772011-02-02 18:54:13 -080055import android.widget.SeekBar.OnSeekBarChangeListener;
56
John Spurlock86005342014-05-23 11:58:00 -040057import com.android.internal.R;
58import com.android.systemui.statusbar.policy.ZenModeController;
59
Amith Yamasani2bbdd772011-02-02 18:54:13 -080060import java.util.HashMap;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080061
62/**
John Spurlock3346a802014-05-20 16:25:37 -040063 * Handles the user interface for the volume keys.
Dianne Hackborne8ecde12011-08-03 18:55:19 -070064 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080065 * @hide
66 */
John Spurlock3346a802014-05-20 16:25:37 -040067public class VolumePanel extends Handler {
Marco Nelissen69f593c2009-07-28 09:55:04 -070068 private static boolean LOGD = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080069
John Spurlock3346a802014-05-20 16:25:37 -040070 private static final int PLAY_SOUND_DELAY = AudioService.PLAY_SOUND_DELAY;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080071
72 /**
73 * The delay before vibrating. This small period exists so if the user is
74 * moving to silent mode, it will not emit a short vibrate (it normally
75 * would since vibrate is between normal mode and silent mode using hardware
76 * keys).
77 */
78 public static final int VIBRATE_DELAY = 300;
79
80 private static final int VIBRATE_DURATION = 300;
81 private static final int BEEP_DURATION = 150;
82 private static final int MAX_VOLUME = 100;
83 private static final int FREE_DELAY = 10000;
Amith Yamasani2bbdd772011-02-02 18:54:13 -080084 private static final int TIMEOUT_DELAY = 3000;
John Spurlock3bd4fee2014-05-29 20:51:09 -040085 private static final int TIMEOUT_DELAY_EXPANDED = 10000;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080086
87 private static final int MSG_VOLUME_CHANGED = 0;
88 private static final int MSG_FREE_RESOURCES = 1;
89 private static final int MSG_PLAY_SOUND = 2;
90 private static final int MSG_STOP_SOUNDS = 3;
91 private static final int MSG_VIBRATE = 4;
Amith Yamasani2bbdd772011-02-02 18:54:13 -080092 private static final int MSG_TIMEOUT = 5;
93 private static final int MSG_RINGER_MODE_CHANGED = 6;
Mike Lockwoodce952c82011-11-14 10:47:42 -080094 private static final int MSG_MUTE_CHANGED = 7;
Jean-Michel Trivi3114ce32012-06-11 15:03:52 -070095 private static final int MSG_REMOTE_VOLUME_CHANGED = 8;
96 private static final int MSG_REMOTE_VOLUME_UPDATE_IF_SHOWN = 9;
97 private static final int MSG_SLIDER_VISIBILITY_CHANGED = 10;
Eric Laurentc34dcc12012-09-10 13:51:52 -070098 private static final int MSG_DISPLAY_SAFE_VOLUME_WARNING = 11;
John Spurlock86005342014-05-23 11:58:00 -040099 private static final int MSG_LAYOUT_DIRECTION = 12;
100 private static final int MSG_ZEN_MODE_CHANGED = 13;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800101
Mike Lockwood8dc1dab2011-10-27 09:52:41 -0400102 // Pseudo stream type for master volume
Mike Lockwood47676902011-11-08 10:31:21 -0800103 private static final int STREAM_MASTER = -100;
Jean-Michel Trivi3114ce32012-06-11 15:03:52 -0700104 // Pseudo stream type for remote volume is defined in AudioService.STREAM_REMOTE_MUSIC
Mike Lockwood8dc1dab2011-10-27 09:52:41 -0400105
John Spurlock86005342014-05-23 11:58:00 -0400106 private final String mTag;
John Spurlock3346a802014-05-20 16:25:37 -0400107 protected final Context mContext;
108 private final AudioManager mAudioManager;
John Spurlock86005342014-05-23 11:58:00 -0400109 private final ZenModeController mZenController;
Marco Nelissen69f593c2009-07-28 09:55:04 -0700110 private boolean mRingIsSilent;
Amith Yamasani71def772011-10-12 12:25:24 -0700111 private boolean mVoiceCapable;
John Spurlock86005342014-05-23 11:58:00 -0400112 private boolean mZenModeCapable;
John Spurlock3bd4fee2014-05-29 20:51:09 -0400113 private int mTimeoutDelay = TIMEOUT_DELAY;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800114
Christopher Tatec4b78d22012-05-22 13:57:58 -0700115 // True if we want to play tones on the system stream when the master stream is specified.
116 private final boolean mPlayMasterStreamTones;
117
John Spurlock86005342014-05-23 11:58:00 -0400118
119 /** Volume panel content view */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800120 private final View mView;
John Spurlock86005342014-05-23 11:58:00 -0400121 /** Dialog hosting the panel, if not embedded */
122 private final Dialog mDialog;
123 /** Parent view hosting the panel, if embedded */
124 private final ViewGroup mParent;
Amith Yamasani2bbdd772011-02-02 18:54:13 -0800125
Amith Yamasanibaf6dbf2011-08-18 17:40:29 -0700126 /** The visible portion of the volume overlay */
127 private final ViewGroup mPanel;
John Spurlock86005342014-05-23 11:58:00 -0400128 /** Contains the slider and its touchable icons */
129 private final ViewGroup mSliderPanel;
130 /** The button that expands the dialog to show the zen panel */
131 private final ImageView mExpandButton;
132 /** Dummy divider icon that needs to vanish with the expand button */
133 private final View mExpandDivider;
134 /** The zen mode configuration panel view stub */
135 private final ViewStub mZenPanelStub;
136 /** The zen mode configuration panel view, once inflated */
137 private ZenModePanel mZenPanel;
138 /** Dummy divider icon that needs to vanish with the zen panel */
139 private final View mZenPanelDivider;
140
141 private ZenModePanel.Callback mZenPanelCallback;
Amith Yamasani2bbdd772011-02-02 18:54:13 -0800142
143 /** Currently active stream that shows up at the top of the list of sliders */
144 private int mActiveStreamType = -1;
145 /** All the slider controls mapped by stream type */
146 private HashMap<Integer,StreamControl> mStreamControls;
147
Amith Yamasani71def772011-10-12 12:25:24 -0700148 private enum StreamResources {
149 BluetoothSCOStream(AudioManager.STREAM_BLUETOOTH_SCO,
150 R.string.volume_icon_description_bluetooth,
151 R.drawable.ic_audio_bt,
152 R.drawable.ic_audio_bt,
153 false),
154 RingerStream(AudioManager.STREAM_RING,
155 R.string.volume_icon_description_ringer,
John Spurlock86005342014-05-23 11:58:00 -0400156 com.android.systemui.R.drawable.ic_ringer_audible,
157 com.android.systemui.R.drawable.ic_ringer_silent,
Amith Yamasani71def772011-10-12 12:25:24 -0700158 false),
159 VoiceStream(AudioManager.STREAM_VOICE_CALL,
160 R.string.volume_icon_description_incall,
161 R.drawable.ic_audio_phone,
162 R.drawable.ic_audio_phone,
163 false),
Amith Yamasani92e1b2d2011-10-14 17:24:47 -0700164 AlarmStream(AudioManager.STREAM_ALARM,
165 R.string.volume_alarm,
166 R.drawable.ic_audio_alarm,
167 R.drawable.ic_audio_alarm_mute,
168 false),
Amith Yamasani71def772011-10-12 12:25:24 -0700169 MediaStream(AudioManager.STREAM_MUSIC,
170 R.string.volume_icon_description_media,
171 R.drawable.ic_audio_vol,
172 R.drawable.ic_audio_vol_mute,
173 true),
174 NotificationStream(AudioManager.STREAM_NOTIFICATION,
175 R.string.volume_icon_description_notification,
John Spurlock86005342014-05-23 11:58:00 -0400176 com.android.systemui.R.drawable.ic_ringer_audible,
177 com.android.systemui.R.drawable.ic_ringer_silent,
Mike Lockwood8dc1dab2011-10-27 09:52:41 -0400178 true),
179 // for now, use media resources for master volume
180 MasterStream(STREAM_MASTER,
Jean-Michel Trivi3114ce32012-06-11 15:03:52 -0700181 R.string.volume_icon_description_media, //FIXME should have its own description
Mike Lockwood8dc1dab2011-10-27 09:52:41 -0400182 R.drawable.ic_audio_vol,
183 R.drawable.ic_audio_vol_mute,
Jean-Michel Trivi3114ce32012-06-11 15:03:52 -0700184 false),
185 RemoteStream(AudioService.STREAM_REMOTE_MUSIC,
186 R.string.volume_icon_description_media, //FIXME should have its own description
187 R.drawable.ic_media_route_on_holo_dark,
188 R.drawable.ic_media_route_disabled_holo_dark,
189 false);// will be dynamically updated
Amith Yamasani71def772011-10-12 12:25:24 -0700190
191 int streamType;
192 int descRes;
193 int iconRes;
194 int iconMuteRes;
195 // RING, VOICE_CALL & BLUETOOTH_SCO are hidden unless explicitly requested
196 boolean show;
197
198 StreamResources(int streamType, int descRes, int iconRes, int iconMuteRes, boolean show) {
199 this.streamType = streamType;
200 this.descRes = descRes;
201 this.iconRes = iconRes;
202 this.iconMuteRes = iconMuteRes;
203 this.show = show;
204 }
Alan Viverettee8ebaf32014-04-11 15:44:15 -0700205 }
Amith Yamasani71def772011-10-12 12:25:24 -0700206
Amith Yamasani2bbdd772011-02-02 18:54:13 -0800207 // List of stream types and their order
Amith Yamasani71def772011-10-12 12:25:24 -0700208 private static final StreamResources[] STREAMS = {
209 StreamResources.BluetoothSCOStream,
210 StreamResources.RingerStream,
211 StreamResources.VoiceStream,
212 StreamResources.MediaStream,
Amith Yamasani92e1b2d2011-10-14 17:24:47 -0700213 StreamResources.NotificationStream,
Mike Lockwood8dc1dab2011-10-27 09:52:41 -0400214 StreamResources.AlarmStream,
Jean-Michel Trivi3114ce32012-06-11 15:03:52 -0700215 StreamResources.MasterStream,
216 StreamResources.RemoteStream
Amith Yamasani2bbdd772011-02-02 18:54:13 -0800217 };
218
219 /** Object that contains data for each slider */
220 private class StreamControl {
221 int streamType;
222 ViewGroup group;
223 ImageView icon;
224 SeekBar seekbarView;
225 int iconRes;
226 int iconMuteRes;
227 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800228
229 // Synchronize when accessing this
230 private ToneGenerator mToneGenerators[];
231 private Vibrator mVibrator;
232
Eric Laurentc34dcc12012-09-10 13:51:52 -0700233 private static AlertDialog sConfirmSafeVolumeDialog;
Eric Laurent0516a9e2012-09-19 11:53:03 -0700234 private static Object sConfirmSafeVolumeLock = new Object();
Eric Laurentc34dcc12012-09-10 13:51:52 -0700235
236 private static class WarningDialogReceiver extends BroadcastReceiver
237 implements DialogInterface.OnDismissListener {
Eric Laurentfde16d52012-12-03 14:42:39 -0800238 private final Context mContext;
239 private final Dialog mDialog;
240 private final VolumePanel mVolumePanel;
Eric Laurentc34dcc12012-09-10 13:51:52 -0700241
Eric Laurentfde16d52012-12-03 14:42:39 -0800242 WarningDialogReceiver(Context context, Dialog dialog, VolumePanel volumePanel) {
Eric Laurentc34dcc12012-09-10 13:51:52 -0700243 mContext = context;
244 mDialog = dialog;
Eric Laurentfde16d52012-12-03 14:42:39 -0800245 mVolumePanel = volumePanel;
Eric Laurentc34dcc12012-09-10 13:51:52 -0700246 IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
247 context.registerReceiver(this, filter);
248 }
249
250 @Override
251 public void onReceive(Context context, Intent intent) {
252 mDialog.cancel();
Eric Laurentfde16d52012-12-03 14:42:39 -0800253 cleanUp();
Eric Laurentc34dcc12012-09-10 13:51:52 -0700254 }
255
Alan Viverette494fb7b2014-04-10 18:12:56 -0700256 @Override
Eric Laurentc34dcc12012-09-10 13:51:52 -0700257 public void onDismiss(DialogInterface unused) {
258 mContext.unregisterReceiver(this);
Eric Laurentfde16d52012-12-03 14:42:39 -0800259 cleanUp();
260 }
261
262 private void cleanUp() {
Eric Laurent0516a9e2012-09-19 11:53:03 -0700263 synchronized (sConfirmSafeVolumeLock) {
264 sConfirmSafeVolumeDialog = null;
265 }
Eric Laurentfde16d52012-12-03 14:42:39 -0800266 mVolumePanel.forceTimeout();
267 mVolumePanel.updateStates();
Eric Laurentc34dcc12012-09-10 13:51:52 -0700268 }
269 }
270
271
John Spurlock86005342014-05-23 11:58:00 -0400272 public VolumePanel(Context context, ViewGroup parent, ZenModeController zenController) {
273 mTag = String.format("VolumePanel%s.%08x", parent == null ? "Dialog" : "", hashCode());
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800274 mContext = context;
John Spurlock86005342014-05-23 11:58:00 -0400275 mParent = parent;
276 mZenController = zenController;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800277 mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800278
Mike Lockwood8dc1dab2011-10-27 09:52:41 -0400279 // For now, only show master volume if master volume is supported
Alan Viverettee8ebaf32014-04-11 15:44:15 -0700280 final Resources res = context.getResources();
281 final boolean useMasterVolume = res.getBoolean(R.bool.config_useMasterVolume);
Mike Lockwood8dc1dab2011-10-27 09:52:41 -0400282 if (useMasterVolume) {
283 for (int i = 0; i < STREAMS.length; i++) {
284 StreamResources streamRes = STREAMS[i];
285 streamRes.show = (streamRes.streamType == STREAM_MASTER);
286 }
287 }
John Spurlock86005342014-05-23 11:58:00 -0400288 if (LOGD) Log.d(mTag, String.format("new VolumePanel hasParent=%s", parent != null));
John Spurlock86005342014-05-23 11:58:00 -0400289 if (parent == null) {
290 // dialog mode
291 mDialog = new Dialog(context) {
292 @Override
293 public boolean onTouchEvent(MotionEvent event) {
294 if (isShowing() && event.getAction() == MotionEvent.ACTION_OUTSIDE &&
295 sConfirmSafeVolumeDialog == null) {
296 forceTimeout();
297 return true;
298 }
299 return false;
Amith Yamasani284e6302011-09-16 18:24:47 -0700300 }
John Spurlock86005342014-05-23 11:58:00 -0400301 };
Alan Viverettee8ebaf32014-04-11 15:44:15 -0700302
John Spurlock86005342014-05-23 11:58:00 -0400303 // Change some window properties
304 final Window window = mDialog.getWindow();
305 final LayoutParams lp = window.getAttributes();
306 lp.token = null;
307 // Offset from the top
308 lp.y = res.getDimensionPixelOffset(com.android.systemui.R.dimen.volume_panel_top);
309 lp.width = res.getDimensionPixelSize(com.android.systemui.R.dimen.volume_panel_width);
310 lp.type = LayoutParams.TYPE_VOLUME_OVERLAY;
John Spurlock2078caf2014-05-29 22:20:14 -0400311 lp.format = PixelFormat.TRANSLUCENT;
John Spurlock86005342014-05-23 11:58:00 -0400312 lp.windowAnimations = R.style.Animation_VolumePanel;
John Spurlock86005342014-05-23 11:58:00 -0400313 window.setAttributes(lp);
314 window.setGravity(Gravity.TOP);
315 window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
316 window.requestFeature(Window.FEATURE_NO_TITLE);
317 window.addFlags(LayoutParams.FLAG_NOT_FOCUSABLE
318 | LayoutParams.FLAG_NOT_TOUCH_MODAL
John Spurlock2078caf2014-05-29 22:20:14 -0400319 | LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH
320 | LayoutParams.FLAG_HARDWARE_ACCELERATED);
John Spurlock86005342014-05-23 11:58:00 -0400321 mDialog.setCanceledOnTouchOutside(true);
John Spurlock7f1df5e2014-05-31 19:11:40 -0400322 mDialog.setContentView(com.android.systemui.R.layout.volume_dialog);
John Spurlock86005342014-05-23 11:58:00 -0400323 mDialog.setOnDismissListener(new OnDismissListener() {
324 @Override
325 public void onDismiss(DialogInterface dialog) {
326 mActiveStreamType = -1;
327 mAudioManager.forceVolumeControlStream(mActiveStreamType);
328 }
329 });
Alan Viverettee8ebaf32014-04-11 15:44:15 -0700330
John Spurlock86005342014-05-23 11:58:00 -0400331 mDialog.create();
John Spurlock7f1df5e2014-05-31 19:11:40 -0400332 // temporary workaround, until we support window-level shadows
John Spurlock2078caf2014-05-29 22:20:14 -0400333 mDialog.getWindow().setBackgroundDrawable(new ColorDrawable(0x00000000));
Alan Viverette494fb7b2014-04-10 18:12:56 -0700334
John Spurlock86005342014-05-23 11:58:00 -0400335 mView = window.findViewById(R.id.content);
336 mView.setOnTouchListener(new View.OnTouchListener() {
337 @Override
338 public boolean onTouch(View v, MotionEvent event) {
339 resetTimeout();
340 return false;
341 }
342 });
Alan Viverette494fb7b2014-04-10 18:12:56 -0700343
John Spurlock86005342014-05-23 11:58:00 -0400344 } else {
345 // embedded mode
346 mDialog = null;
John Spurlock7f1df5e2014-05-31 19:11:40 -0400347 mView = LayoutInflater.from(mContext).inflate(
348 com.android.systemui.R.layout.volume_panel, parent, true);
John Spurlock86005342014-05-23 11:58:00 -0400349 }
350 mPanel = (ViewGroup) mView.findViewById(com.android.systemui.R.id.visible_panel);
351 mSliderPanel = (ViewGroup) mView.findViewById(com.android.systemui.R.id.slider_panel);
352 mExpandButton = (ImageView) mView.findViewById(com.android.systemui.R.id.expand_button);
353 mExpandDivider = mView.findViewById(com.android.systemui.R.id.expand_button_divider);
354 mZenPanelStub = (ViewStub)mView.findViewById(com.android.systemui.R.id.zen_panel_stub);
355 mZenPanelDivider = mView.findViewById(com.android.systemui.R.id.zen_panel_divider);
Amith Yamasani2bbdd772011-02-02 18:54:13 -0800356
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800357 mToneGenerators = new ToneGenerator[AudioSystem.getNumStreamTypes()];
Alan Viverettee8ebaf32014-04-11 15:44:15 -0700358 mVibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
Amith Yamasani71def772011-10-12 12:25:24 -0700359 mVoiceCapable = context.getResources().getBoolean(R.bool.config_voice_capable);
Alan Viverettee8ebaf32014-04-11 15:44:15 -0700360
John Spurlock86005342014-05-23 11:58:00 -0400361 mZenModeCapable = !useMasterVolume && mZenController != null;
362 mZenPanelDivider.setVisibility(View.GONE);
363 mExpandButton.setOnClickListener(mClickListener);
364 updateZenMode(mZenController == null ? false : mZenController.isZen());
365 mZenController.addCallback(mZenCallback);
Amith Yamasani42722bf2011-07-22 10:34:27 -0700366
Alan Viverettee8ebaf32014-04-11 15:44:15 -0700367 final boolean masterVolumeOnly = res.getBoolean(R.bool.config_useMasterVolume);
368 final boolean masterVolumeKeySounds = res.getBoolean(R.bool.config_useVolumeKeySounds);
Christopher Tatec4b78d22012-05-22 13:57:58 -0700369 mPlayMasterStreamTones = masterVolumeOnly && masterVolumeKeySounds;
370
Amith Yamasani2bbdd772011-02-02 18:54:13 -0800371 listenToRingerMode();
372 }
373
John Spurlock86005342014-05-23 11:58:00 -0400374 private void setLayoutDirection(int layoutDirection) {
Fabrice Di Meglio8c028842013-01-09 18:20:38 -0800375 mPanel.setLayoutDirection(layoutDirection);
376 updateStates();
377 }
378
Amith Yamasani2bbdd772011-02-02 18:54:13 -0800379 private void listenToRingerMode() {
380 final IntentFilter filter = new IntentFilter();
381 filter.addAction(AudioManager.RINGER_MODE_CHANGED_ACTION);
382 mContext.registerReceiver(new BroadcastReceiver() {
Alan Viverette494fb7b2014-04-10 18:12:56 -0700383 @Override
Amith Yamasani2bbdd772011-02-02 18:54:13 -0800384 public void onReceive(Context context, Intent intent) {
385 final String action = intent.getAction();
386
387 if (AudioManager.RINGER_MODE_CHANGED_ACTION.equals(action)) {
388 removeMessages(MSG_RINGER_MODE_CHANGED);
389 sendMessage(obtainMessage(MSG_RINGER_MODE_CHANGED));
390 }
391 }
392 }, filter);
393 }
394
395 private boolean isMuted(int streamType) {
Mike Lockwood8dc1dab2011-10-27 09:52:41 -0400396 if (streamType == STREAM_MASTER) {
Eric Laurent8c787522012-05-14 14:09:43 -0700397 return mAudioManager.isMasterMute();
Jean-Michel Trivi3114ce32012-06-11 15:03:52 -0700398 } else if (streamType == AudioService.STREAM_REMOTE_MUSIC) {
John Spurlock3346a802014-05-20 16:25:37 -0400399 return (mAudioManager.getRemoteStreamVolume() <= 0);
Mike Lockwood8dc1dab2011-10-27 09:52:41 -0400400 } else {
Eric Laurent8c787522012-05-14 14:09:43 -0700401 return mAudioManager.isStreamMute(streamType);
Mike Lockwood8dc1dab2011-10-27 09:52:41 -0400402 }
403 }
404
405 private int getStreamMaxVolume(int streamType) {
Mike Lockwood8dc1dab2011-10-27 09:52:41 -0400406 if (streamType == STREAM_MASTER) {
Eric Laurent8c787522012-05-14 14:09:43 -0700407 return mAudioManager.getMasterMaxVolume();
Jean-Michel Trivi3114ce32012-06-11 15:03:52 -0700408 } else if (streamType == AudioService.STREAM_REMOTE_MUSIC) {
John Spurlock3346a802014-05-20 16:25:37 -0400409 return mAudioManager.getRemoteStreamMaxVolume();
Mike Lockwood8dc1dab2011-10-27 09:52:41 -0400410 } else {
Eric Laurent8c787522012-05-14 14:09:43 -0700411 return mAudioManager.getStreamMaxVolume(streamType);
Mike Lockwood8dc1dab2011-10-27 09:52:41 -0400412 }
413 }
414
415 private int getStreamVolume(int streamType) {
Mike Lockwood8dc1dab2011-10-27 09:52:41 -0400416 if (streamType == STREAM_MASTER) {
Eric Laurent8c787522012-05-14 14:09:43 -0700417 return mAudioManager.getMasterVolume();
Jean-Michel Trivi3114ce32012-06-11 15:03:52 -0700418 } else if (streamType == AudioService.STREAM_REMOTE_MUSIC) {
John Spurlock3346a802014-05-20 16:25:37 -0400419 return mAudioManager.getRemoteStreamVolume();
Mike Lockwood8dc1dab2011-10-27 09:52:41 -0400420 } else {
Eric Laurent8c787522012-05-14 14:09:43 -0700421 return mAudioManager.getStreamVolume(streamType);
Mike Lockwood8dc1dab2011-10-27 09:52:41 -0400422 }
423 }
424
425 private void setStreamVolume(int streamType, int index, int flags) {
Mike Lockwood8dc1dab2011-10-27 09:52:41 -0400426 if (streamType == STREAM_MASTER) {
Eric Laurent8c787522012-05-14 14:09:43 -0700427 mAudioManager.setMasterVolume(index, flags);
Jean-Michel Trivi3114ce32012-06-11 15:03:52 -0700428 } else if (streamType == AudioService.STREAM_REMOTE_MUSIC) {
John Spurlock3346a802014-05-20 16:25:37 -0400429 mAudioManager.setRemoteStreamVolume(index);
Mike Lockwood8dc1dab2011-10-27 09:52:41 -0400430 } else {
Eric Laurent8c787522012-05-14 14:09:43 -0700431 mAudioManager.setStreamVolume(streamType, index, flags);
Mike Lockwood8dc1dab2011-10-27 09:52:41 -0400432 }
Amith Yamasani2bbdd772011-02-02 18:54:13 -0800433 }
434
435 private void createSliders() {
Alan Viverette494fb7b2014-04-10 18:12:56 -0700436 final Resources res = mContext.getResources();
437 final LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(
438 Context.LAYOUT_INFLATER_SERVICE);
439
Amith Yamasani71def772011-10-12 12:25:24 -0700440 mStreamControls = new HashMap<Integer, StreamControl>(STREAMS.length);
Alan Viverette494fb7b2014-04-10 18:12:56 -0700441
Amith Yamasani71def772011-10-12 12:25:24 -0700442 for (int i = 0; i < STREAMS.length; i++) {
443 StreamResources streamRes = STREAMS[i];
Alan Viverette494fb7b2014-04-10 18:12:56 -0700444
445 final int streamType = streamRes.streamType;
Alan Viverette494fb7b2014-04-10 18:12:56 -0700446
447 final StreamControl sc = new StreamControl();
Amith Yamasanid47a3aee2011-08-23 11:11:35 -0700448 sc.streamType = streamType;
John Spurlock86005342014-05-23 11:58:00 -0400449 sc.group = (ViewGroup) inflater.inflate(
450 com.android.systemui.R.layout.volume_panel_item, null);
Amith Yamasani2bbdd772011-02-02 18:54:13 -0800451 sc.group.setTag(sc);
John Spurlock86005342014-05-23 11:58:00 -0400452 sc.icon = (ImageView) sc.group.findViewById(com.android.systemui.R.id.stream_icon);
Amith Yamasani2bbdd772011-02-02 18:54:13 -0800453 sc.icon.setTag(sc);
Amith Yamasani71def772011-10-12 12:25:24 -0700454 sc.icon.setContentDescription(res.getString(streamRes.descRes));
455 sc.iconRes = streamRes.iconRes;
456 sc.iconMuteRes = streamRes.iconMuteRes;
Amith Yamasani2bbdd772011-02-02 18:54:13 -0800457 sc.icon.setImageResource(sc.iconRes);
John Spurlock7f1df5e2014-05-31 19:11:40 -0400458 sc.icon.setClickable(isNotificationOrRing(streamType));
459 if (sc.icon.isClickable()) {
460 sc.icon.setOnClickListener(new OnClickListener() {
461 @Override
462 public void onClick(View v) {
463 resetTimeout();
464 toggle(sc);
465 }
466 });
467 sc.icon.setOnLongClickListener(new OnLongClickListener() {
468 @Override
469 public boolean onLongClick(View v) {
470 resetTimeout();
471 longToggle(sc);
472 return true;
473 }
474 });
475 }
John Spurlock86005342014-05-23 11:58:00 -0400476 sc.seekbarView = (SeekBar) sc.group.findViewById(com.android.systemui.R.id.seekbar);
Alan Viverette494fb7b2014-04-10 18:12:56 -0700477 final int plusOne = (streamType == AudioSystem.STREAM_BLUETOOTH_SCO ||
Amith Yamasanid47a3aee2011-08-23 11:11:35 -0700478 streamType == AudioSystem.STREAM_VOICE_CALL) ? 1 : 0;
Mike Lockwood8dc1dab2011-10-27 09:52:41 -0400479 sc.seekbarView.setMax(getStreamMaxVolume(streamType) + plusOne);
Alan Viverettee8ebaf32014-04-11 15:44:15 -0700480 sc.seekbarView.setOnSeekBarChangeListener(mSeekListener);
Amith Yamasani2bbdd772011-02-02 18:54:13 -0800481 sc.seekbarView.setTag(sc);
Amith Yamasanid47a3aee2011-08-23 11:11:35 -0700482 mStreamControls.put(streamType, sc);
Amith Yamasani2bbdd772011-02-02 18:54:13 -0800483 }
484 }
485
John Spurlock7f1df5e2014-05-31 19:11:40 -0400486 private void toggle(StreamControl sc) {
487 if (mAudioManager.getRingerMode() == AudioManager.RINGER_MODE_NORMAL) {
488 mAudioManager.setRingerMode(AudioManager.RINGER_MODE_VIBRATE);
489 postVolumeChanged(sc.streamType, AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_VIBRATE);
490 } else {
491 mAudioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
492 postVolumeChanged(sc.streamType, AudioManager.FLAG_PLAY_SOUND);
493 }
494 }
495
496 private void longToggle(StreamControl sc) {
497 if (mAudioManager.getRingerMode() == AudioManager.RINGER_MODE_SILENT) {
498 mAudioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
499 postVolumeChanged(sc.streamType, AudioManager.FLAG_PLAY_SOUND);
500 } else {
501 mAudioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT);
502 postVolumeChanged(sc.streamType, AudioManager.FLAG_SHOW_UI); // disable the slider
503 }
504 }
505
Amith Yamasani2bbdd772011-02-02 18:54:13 -0800506 private void reorderSliders(int activeStreamType) {
John Spurlock86005342014-05-23 11:58:00 -0400507 mSliderPanel.removeAllViews();
Amith Yamasani2bbdd772011-02-02 18:54:13 -0800508
Alan Viverette494fb7b2014-04-10 18:12:56 -0700509 final StreamControl active = mStreamControls.get(activeStreamType);
Amith Yamasani2bbdd772011-02-02 18:54:13 -0800510 if (active == null) {
511 Log.e("VolumePanel", "Missing stream type! - " + activeStreamType);
512 mActiveStreamType = -1;
513 } else {
John Spurlock86005342014-05-23 11:58:00 -0400514 mSliderPanel.addView(active.group);
Amith Yamasani2bbdd772011-02-02 18:54:13 -0800515 mActiveStreamType = activeStreamType;
516 active.group.setVisibility(View.VISIBLE);
517 updateSlider(active);
John Spurlock86005342014-05-23 11:58:00 -0400518 updateZenMode(mZenController == null ? false : mZenController.isZen());
Amith Yamasani2bbdd772011-02-02 18:54:13 -0800519 }
520 }
521
522 /** Update the mute and progress state of a slider */
523 private void updateSlider(StreamControl sc) {
Eric Laurent8c787522012-05-14 14:09:43 -0700524 sc.seekbarView.setProgress(getStreamVolume(sc.streamType));
Amith Yamasani2bbdd772011-02-02 18:54:13 -0800525 final boolean muted = isMuted(sc.streamType);
Fabrice Di Meglio8c028842013-01-09 18:20:38 -0800526 // Force reloading the image resource
527 sc.icon.setImageDrawable(null);
Amith Yamasani2bbdd772011-02-02 18:54:13 -0800528 sc.icon.setImageResource(muted ? sc.iconMuteRes : sc.iconRes);
John Spurlock7f1df5e2014-05-31 19:11:40 -0400529 if (isNotificationOrRing(sc.streamType) &&
Eric Laurent8c787522012-05-14 14:09:43 -0700530 mAudioManager.getRingerMode() == AudioManager.RINGER_MODE_VIBRATE) {
John Spurlock86005342014-05-23 11:58:00 -0400531 sc.icon.setImageResource(com.android.systemui.R.drawable.ic_ringer_vibrate);
Amith Yamasanic696a532011-10-28 17:02:37 -0700532 }
John Spurlock7f1df5e2014-05-31 19:11:40 -0400533 updateSliderEnabled(sc, muted, false);
534 }
535
536 private void updateSliderEnabled(StreamControl sc, boolean muted, boolean fixedVolume) {
Jean-Michel Trivi3114ce32012-06-11 15:03:52 -0700537 if (sc.streamType == AudioService.STREAM_REMOTE_MUSIC) {
538 // never disable touch interactions for remote playback, the muting is not tied to
539 // the state of the phone.
540 sc.seekbarView.setEnabled(true);
John Spurlock7f1df5e2014-05-31 19:11:40 -0400541 } else if (fixedVolume ||
542 (sc.streamType != mAudioManager.getMasterStreamType() && muted) ||
Eric Laurentfde16d52012-12-03 14:42:39 -0800543 (sConfirmSafeVolumeDialog != null)) {
Eric Laurent8c787522012-05-14 14:09:43 -0700544 sc.seekbarView.setEnabled(false);
John Spurlock7f1df5e2014-05-31 19:11:40 -0400545 } else if (isNotificationOrRing(sc.streamType)
546 && mAudioManager.getRingerMode() == AudioManager.RINGER_MODE_SILENT) {
547 sc.seekbarView.setEnabled(false);
Eric Laurent8c787522012-05-14 14:09:43 -0700548 } else {
549 sc.seekbarView.setEnabled(true);
550 }
Amith Yamasani2bbdd772011-02-02 18:54:13 -0800551 }
552
John Spurlock7f1df5e2014-05-31 19:11:40 -0400553 private static boolean isNotificationOrRing(int streamType) {
554 return streamType == AudioManager.STREAM_RING
555 || streamType == AudioManager.STREAM_NOTIFICATION;
556 }
557
John Spurlock86005342014-05-23 11:58:00 -0400558 public void setZenModePanelCallback(ZenModePanel.Callback callback) {
559 mZenPanelCallback = callback;
560 }
561
Amith Yamasani2bbdd772011-02-02 18:54:13 -0800562 private void expand() {
John Spurlock86005342014-05-23 11:58:00 -0400563 if (LOGD) Log.d(mTag, "expand mZenPanel=" + mZenPanel);
564 if (mZenPanel == null) {
565 mZenPanel = (ZenModePanel) mZenPanelStub.inflate();
566 mZenPanel.init(mZenController);
567 mZenPanel.setCallback(new ZenModePanel.Callback() {
568 @Override
569 public void onMoreSettings() {
570 if (mZenPanelCallback != null) {
571 mZenPanelCallback.onMoreSettings();
572 }
573 }
574
575 @Override
576 public void onInteraction() {
John Spurlock3bd4fee2014-05-29 20:51:09 -0400577 resetTimeout();
John Spurlock86005342014-05-23 11:58:00 -0400578 if (mZenPanelCallback != null) {
579 mZenPanelCallback.onInteraction();
580 }
581 }
582 });
Amith Yamasani2bbdd772011-02-02 18:54:13 -0800583 }
John Spurlock86005342014-05-23 11:58:00 -0400584 mZenPanel.setVisibility(View.VISIBLE);
585 mZenPanelDivider.setVisibility(View.VISIBLE);
John Spurlock3bd4fee2014-05-29 20:51:09 -0400586 mTimeoutDelay = TIMEOUT_DELAY_EXPANDED;
587 resetTimeout();
Amith Yamasani2bbdd772011-02-02 18:54:13 -0800588 }
589
590 private void collapse() {
John Spurlock86005342014-05-23 11:58:00 -0400591 if (LOGD) Log.d(mTag, "collapse mZenPanel=" + mZenPanel);
592 if (mZenPanel != null) {
593 mZenPanel.setVisibility(View.GONE);
Amith Yamasani2bbdd772011-02-02 18:54:13 -0800594 }
John Spurlock86005342014-05-23 11:58:00 -0400595 mZenPanelDivider.setVisibility(View.GONE);
John Spurlock3bd4fee2014-05-29 20:51:09 -0400596 mTimeoutDelay = TIMEOUT_DELAY;
597 resetTimeout();
Amith Yamasani2bbdd772011-02-02 18:54:13 -0800598 }
599
Eric Laurentfde16d52012-12-03 14:42:39 -0800600 public void updateStates() {
John Spurlock86005342014-05-23 11:58:00 -0400601 final int count = mSliderPanel.getChildCount();
Amith Yamasani2bbdd772011-02-02 18:54:13 -0800602 for (int i = 0; i < count; i++) {
John Spurlock86005342014-05-23 11:58:00 -0400603 StreamControl sc = (StreamControl) mSliderPanel.getChildAt(i).getTag();
Amith Yamasani2bbdd772011-02-02 18:54:13 -0800604 updateSlider(sc);
605 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800606 }
607
John Spurlock86005342014-05-23 11:58:00 -0400608 private void updateZenMode(boolean zen) {
609 if (mZenModeCapable) {
John Spurlock7f1df5e2014-05-31 19:11:40 -0400610 final boolean show = isNotificationOrRing(mActiveStreamType);
John Spurlock86005342014-05-23 11:58:00 -0400611 mExpandButton.setVisibility(show ? View.VISIBLE : View.GONE);
612 mExpandDivider.setVisibility(show ? View.VISIBLE : View.GONE);
613 mExpandButton.setImageResource(zen ? com.android.systemui.R.drawable.ic_vol_zen_on
614 : com.android.systemui.R.drawable.ic_vol_zen_off);
615 } else {
616 mExpandButton.setVisibility(View.GONE);
617 mExpandDivider.setVisibility(View.GONE);
618 }
619 }
620
621 public void postZenModeChanged(boolean zen) {
622 removeMessages(MSG_ZEN_MODE_CHANGED);
623 obtainMessage(MSG_ZEN_MODE_CHANGED, zen ? 1 : 0).sendToTarget();
624 }
625
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800626 public void postVolumeChanged(int streamType, int flags) {
627 if (hasMessages(MSG_VOLUME_CHANGED)) return;
Amith Yamasania6549862012-05-30 17:29:28 -0700628 synchronized (this) {
629 if (mStreamControls == null) {
630 createSliders();
631 }
Amith Yamasani2bbdd772011-02-02 18:54:13 -0800632 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800633 removeMessages(MSG_FREE_RESOURCES);
634 obtainMessage(MSG_VOLUME_CHANGED, streamType, flags).sendToTarget();
635 }
636
Jean-Michel Trivi3114ce32012-06-11 15:03:52 -0700637 public void postRemoteVolumeChanged(int streamType, int flags) {
638 if (hasMessages(MSG_REMOTE_VOLUME_CHANGED)) return;
639 synchronized (this) {
640 if (mStreamControls == null) {
641 createSliders();
642 }
643 }
644 removeMessages(MSG_FREE_RESOURCES);
645 obtainMessage(MSG_REMOTE_VOLUME_CHANGED, streamType, flags).sendToTarget();
646 }
647
648 public void postRemoteSliderVisibility(boolean visible) {
649 obtainMessage(MSG_SLIDER_VISIBILITY_CHANGED,
650 AudioService.STREAM_REMOTE_MUSIC, visible ? 1 : 0).sendToTarget();
651 }
652
653 /**
654 * Called by AudioService when it has received new remote playback information that
655 * would affect the VolumePanel display (mainly volumes). The difference with
656 * {@link #postRemoteVolumeChanged(int, int)} is that the handling of the posted message
657 * (MSG_REMOTE_VOLUME_UPDATE_IF_SHOWN) will only update the volume slider if it is being
658 * displayed.
659 * This special code path is due to the fact that remote volume updates arrive to AudioService
660 * asynchronously. So after AudioService has sent the volume update (which should be treated
661 * as a request to update the volume), the application will likely set a new volume. If the UI
662 * is still up, we need to refresh the display to show this new value.
663 */
664 public void postHasNewRemotePlaybackInfo() {
665 if (hasMessages(MSG_REMOTE_VOLUME_UPDATE_IF_SHOWN)) return;
666 // don't create or prevent resources to be freed, if they disappear, this update came too
667 // late and shouldn't warrant the panel to be displayed longer
668 obtainMessage(MSG_REMOTE_VOLUME_UPDATE_IF_SHOWN).sendToTarget();
669 }
670
Mike Lockwood8dc1dab2011-10-27 09:52:41 -0400671 public void postMasterVolumeChanged(int flags) {
672 postVolumeChanged(STREAM_MASTER, flags);
673 }
674
Mike Lockwoodce952c82011-11-14 10:47:42 -0800675 public void postMuteChanged(int streamType, int flags) {
676 if (hasMessages(MSG_VOLUME_CHANGED)) return;
Amith Yamasania6549862012-05-30 17:29:28 -0700677 synchronized (this) {
678 if (mStreamControls == null) {
679 createSliders();
680 }
Mike Lockwoodce952c82011-11-14 10:47:42 -0800681 }
682 removeMessages(MSG_FREE_RESOURCES);
683 obtainMessage(MSG_MUTE_CHANGED, streamType, flags).sendToTarget();
684 }
685
686 public void postMasterMuteChanged(int flags) {
687 postMuteChanged(STREAM_MASTER, flags);
688 }
689
Eric Laurentfde16d52012-12-03 14:42:39 -0800690 public void postDisplaySafeVolumeWarning(int flags) {
Eric Laurent0516a9e2012-09-19 11:53:03 -0700691 if (hasMessages(MSG_DISPLAY_SAFE_VOLUME_WARNING)) return;
Eric Laurentfde16d52012-12-03 14:42:39 -0800692 obtainMessage(MSG_DISPLAY_SAFE_VOLUME_WARNING, flags, 0).sendToTarget();
Eric Laurentc34dcc12012-09-10 13:51:52 -0700693 }
694
John Spurlock3346a802014-05-20 16:25:37 -0400695 public void postDismiss() {
John Spurlock86005342014-05-23 11:58:00 -0400696 forceTimeout();
697 }
698
699 public void postLayoutDirection(int layoutDirection) {
700 removeMessages(MSG_LAYOUT_DIRECTION);
701 obtainMessage(MSG_LAYOUT_DIRECTION, layoutDirection).sendToTarget();
John Spurlock3346a802014-05-20 16:25:37 -0400702 }
703
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800704 /**
705 * Override this if you have other work to do when the volume changes (for
706 * example, vibrating, playing a sound, etc.). Make sure to call through to
707 * the superclass implementation.
708 */
709 protected void onVolumeChanged(int streamType, int flags) {
710
John Spurlock86005342014-05-23 11:58:00 -0400711 if (LOGD) Log.d(mTag, "onVolumeChanged(streamType: " + streamType + ", flags: " + flags + ")");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800712
713 if ((flags & AudioManager.FLAG_SHOW_UI) != 0) {
Amith Yamasania6549862012-05-30 17:29:28 -0700714 synchronized (this) {
715 if (mActiveStreamType != streamType) {
716 reorderSliders(streamType);
717 }
718 onShowVolumeChanged(streamType, flags);
Amith Yamasanie3361b82011-02-10 18:20:50 -0800719 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800720 }
721
Marco Nelissen69f593c2009-07-28 09:55:04 -0700722 if ((flags & AudioManager.FLAG_PLAY_SOUND) != 0 && ! mRingIsSilent) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800723 removeMessages(MSG_PLAY_SOUND);
724 sendMessageDelayed(obtainMessage(MSG_PLAY_SOUND, streamType, flags), PLAY_SOUND_DELAY);
725 }
726
727 if ((flags & AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE) != 0) {
728 removeMessages(MSG_PLAY_SOUND);
729 removeMessages(MSG_VIBRATE);
730 onStopSounds();
731 }
732
733 removeMessages(MSG_FREE_RESOURCES);
734 sendMessageDelayed(obtainMessage(MSG_FREE_RESOURCES), FREE_DELAY);
Amith Yamasani2bbdd772011-02-02 18:54:13 -0800735 resetTimeout();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800736 }
737
Mike Lockwoodce952c82011-11-14 10:47:42 -0800738 protected void onMuteChanged(int streamType, int flags) {
739
John Spurlock86005342014-05-23 11:58:00 -0400740 if (LOGD) Log.d(mTag, "onMuteChanged(streamType: " + streamType + ", flags: " + flags + ")");
Mike Lockwoodce952c82011-11-14 10:47:42 -0800741
742 StreamControl sc = mStreamControls.get(streamType);
743 if (sc != null) {
744 sc.icon.setImageResource(isMuted(sc.streamType) ? sc.iconMuteRes : sc.iconRes);
745 }
746
747 onVolumeChanged(streamType, flags);
748 }
749
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800750 protected void onShowVolumeChanged(int streamType, int flags) {
Eric Laurent8c787522012-05-14 14:09:43 -0700751 int index = getStreamVolume(streamType);
Eric Laurentd72d51c2011-02-03 18:47:47 -0800752
Marco Nelissen69f593c2009-07-28 09:55:04 -0700753 mRingIsSilent = false;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800754
755 if (LOGD) {
John Spurlock86005342014-05-23 11:58:00 -0400756 Log.d(mTag, "onShowVolumeChanged(streamType: " + streamType
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800757 + ", flags: " + flags + "), index: " + index);
758 }
759
760 // get max volume for progress bar
Amith Yamasani2bbdd772011-02-02 18:54:13 -0800761
Mike Lockwood8dc1dab2011-10-27 09:52:41 -0400762 int max = getStreamMaxVolume(streamType);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800763
764 switch (streamType) {
765
766 case AudioManager.STREAM_RING: {
Amith Yamasani2bbdd772011-02-02 18:54:13 -0800767// setRingerIcon();
Marco Nelissen69f593c2009-07-28 09:55:04 -0700768 Uri ringuri = RingtoneManager.getActualDefaultRingtoneUri(
769 mContext, RingtoneManager.TYPE_RINGTONE);
770 if (ringuri == null) {
Marco Nelissen69f593c2009-07-28 09:55:04 -0700771 mRingIsSilent = true;
772 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800773 break;
774 }
775
776 case AudioManager.STREAM_MUSIC: {
Amith Yamasani2bbdd772011-02-02 18:54:13 -0800777 // Special case for when Bluetooth is active for music
Glenn Kasten8b4b97a2011-02-04 13:54:26 -0800778 if ((mAudioManager.getDevicesForStream(AudioManager.STREAM_MUSIC) &
779 (AudioManager.DEVICE_OUT_BLUETOOTH_A2DP |
780 AudioManager.DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES |
781 AudioManager.DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER)) != 0) {
Amith Yamasani2bbdd772011-02-02 18:54:13 -0800782 setMusicIcon(R.drawable.ic_audio_bt, R.drawable.ic_audio_bt_mute);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800783 } else {
Amith Yamasani2bbdd772011-02-02 18:54:13 -0800784 setMusicIcon(R.drawable.ic_audio_vol, R.drawable.ic_audio_vol_mute);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800785 }
786 break;
787 }
788
789 case AudioManager.STREAM_VOICE_CALL: {
790 /*
791 * For in-call voice call volume, there is no inaudible volume.
792 * Rescale the UI control so the progress bar doesn't go all
793 * the way to zero and don't show the mute icon.
794 */
795 index++;
796 max++;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800797 break;
798 }
799
800 case AudioManager.STREAM_ALARM: {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800801 break;
802 }
803
804 case AudioManager.STREAM_NOTIFICATION: {
Marco Nelissen69f593c2009-07-28 09:55:04 -0700805 Uri ringuri = RingtoneManager.getActualDefaultRingtoneUri(
806 mContext, RingtoneManager.TYPE_NOTIFICATION);
807 if (ringuri == null) {
Marco Nelissen69f593c2009-07-28 09:55:04 -0700808 mRingIsSilent = true;
809 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800810 break;
811 }
812
813 case AudioManager.STREAM_BLUETOOTH_SCO: {
814 /*
815 * For in-call voice call volume, there is no inaudible volume.
816 * Rescale the UI control so the progress bar doesn't go all
817 * the way to zero and don't show the mute icon.
818 */
819 index++;
820 max++;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800821 break;
822 }
Jean-Michel Trivi3114ce32012-06-11 15:03:52 -0700823
824 case AudioService.STREAM_REMOTE_MUSIC: {
John Spurlock86005342014-05-23 11:58:00 -0400825 if (LOGD) { Log.d(mTag, "showing remote volume "+index+" over "+ max); }
Jean-Michel Trivi3114ce32012-06-11 15:03:52 -0700826 break;
827 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800828 }
829
Amith Yamasani2bbdd772011-02-02 18:54:13 -0800830 StreamControl sc = mStreamControls.get(streamType);
831 if (sc != null) {
Amith Yamasanid47a3aee2011-08-23 11:11:35 -0700832 if (sc.seekbarView.getMax() != max) {
833 sc.seekbarView.setMax(max);
834 }
Eric Laurent4bbcc652012-09-24 14:26:30 -0700835
Amith Yamasani2bbdd772011-02-02 18:54:13 -0800836 sc.seekbarView.setProgress(index);
John Spurlock7f1df5e2014-05-31 19:11:40 -0400837 updateSliderEnabled(sc, isMuted(streamType),
838 (flags & AudioManager.FLAG_FIXED_VOLUME) != 0);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800839 }
840
John Spurlock86005342014-05-23 11:58:00 -0400841 if (!isShowing()) {
Jean-Michel Trivi3114ce32012-06-11 15:03:52 -0700842 int stream = (streamType == AudioService.STREAM_REMOTE_MUSIC) ? -1 : streamType;
843 // when the stream is for remote playback, use -1 to reset the stream type evaluation
844 mAudioManager.forceVolumeControlStream(stream);
Alan Viverettee8ebaf32014-04-11 15:44:15 -0700845
Amith Yamasani2bbdd772011-02-02 18:54:13 -0800846 // Showing dialog - use collapsed state
John Spurlock86005342014-05-23 11:58:00 -0400847 if (mZenModeCapable) {
Amith Yamasani42722bf2011-07-22 10:34:27 -0700848 collapse();
849 }
John Spurlock86005342014-05-23 11:58:00 -0400850 if (mDialog != null) {
851 mDialog.show();
852 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800853 }
854
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800855 // Do a little vibrate if applicable (only when going into vibrate mode)
Jean-Michel Trivi3114ce32012-06-11 15:03:52 -0700856 if ((streamType != AudioService.STREAM_REMOTE_MUSIC) &&
857 ((flags & AudioManager.FLAG_VIBRATE) != 0) &&
John Spurlock3346a802014-05-20 16:25:37 -0400858 mAudioManager.isStreamAffectedByRingerMode(streamType) &&
Eric Laurent8c787522012-05-14 14:09:43 -0700859 mAudioManager.getRingerMode() == AudioManager.RINGER_MODE_VIBRATE) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800860 sendMessageDelayed(obtainMessage(MSG_VIBRATE), VIBRATE_DELAY);
861 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800862 }
863
John Spurlock86005342014-05-23 11:58:00 -0400864 private boolean isShowing() {
865 return mDialog != null ? mDialog.isShowing() : mParent.isAttachedToWindow();
866 }
867
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800868 protected void onPlaySound(int streamType, int flags) {
869
870 if (hasMessages(MSG_STOP_SOUNDS)) {
871 removeMessages(MSG_STOP_SOUNDS);
872 // Force stop right now
873 onStopSounds();
874 }
875
876 synchronized (this) {
877 ToneGenerator toneGen = getOrCreateToneGenerator(streamType);
Eric Laurent733a42b2011-01-19 10:41:57 -0800878 if (toneGen != null) {
879 toneGen.startTone(ToneGenerator.TONE_PROP_BEEP);
880 sendMessageDelayed(obtainMessage(MSG_STOP_SOUNDS), BEEP_DURATION);
881 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800882 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800883 }
884
885 protected void onStopSounds() {
886
887 synchronized (this) {
888 int numStreamTypes = AudioSystem.getNumStreamTypes();
889 for (int i = numStreamTypes - 1; i >= 0; i--) {
890 ToneGenerator toneGen = mToneGenerators[i];
891 if (toneGen != null) {
892 toneGen.stopTone();
893 }
894 }
895 }
896 }
897
898 protected void onVibrate() {
899
900 // Make sure we ended up in vibrate ringer mode
Eric Laurent8c787522012-05-14 14:09:43 -0700901 if (mAudioManager.getRingerMode() != AudioManager.RINGER_MODE_VIBRATE) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800902 return;
903 }
904
John Spurlockf9e1a0b2014-03-19 22:09:06 -0400905 mVibrator.vibrate(VIBRATE_DURATION, AudioManager.STREAM_SYSTEM);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800906 }
907
Jean-Michel Trivi3114ce32012-06-11 15:03:52 -0700908 protected void onRemoteVolumeChanged(int streamType, int flags) {
909 // streamType is the real stream type being affected, but for the UI sliders, we
910 // refer to AudioService.STREAM_REMOTE_MUSIC. We still play the beeps on the real
911 // stream type.
John Spurlock86005342014-05-23 11:58:00 -0400912 if (LOGD) Log.d(mTag, "onRemoteVolumeChanged(stream:"+streamType+", flags: " + flags + ")");
Jean-Michel Trivi3114ce32012-06-11 15:03:52 -0700913
John Spurlock86005342014-05-23 11:58:00 -0400914 if (((flags & AudioManager.FLAG_SHOW_UI) != 0) || isShowing()) {
Jean-Michel Trivi3114ce32012-06-11 15:03:52 -0700915 synchronized (this) {
916 if (mActiveStreamType != AudioService.STREAM_REMOTE_MUSIC) {
917 reorderSliders(AudioService.STREAM_REMOTE_MUSIC);
918 }
919 onShowVolumeChanged(AudioService.STREAM_REMOTE_MUSIC, flags);
920 }
921 } else {
John Spurlock86005342014-05-23 11:58:00 -0400922 if (LOGD) Log.d(mTag, "not calling onShowVolumeChanged(), no FLAG_SHOW_UI or no UI");
Jean-Michel Trivi3114ce32012-06-11 15:03:52 -0700923 }
924
925 if ((flags & AudioManager.FLAG_PLAY_SOUND) != 0 && ! mRingIsSilent) {
926 removeMessages(MSG_PLAY_SOUND);
927 sendMessageDelayed(obtainMessage(MSG_PLAY_SOUND, streamType, flags), PLAY_SOUND_DELAY);
928 }
929
930 if ((flags & AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE) != 0) {
931 removeMessages(MSG_PLAY_SOUND);
932 removeMessages(MSG_VIBRATE);
933 onStopSounds();
934 }
935
936 removeMessages(MSG_FREE_RESOURCES);
937 sendMessageDelayed(obtainMessage(MSG_FREE_RESOURCES), FREE_DELAY);
Jean-Michel Trivi3114ce32012-06-11 15:03:52 -0700938 resetTimeout();
939 }
940
941 protected void onRemoteVolumeUpdateIfShown() {
John Spurlock86005342014-05-23 11:58:00 -0400942 if (LOGD) Log.d(mTag, "onRemoteVolumeUpdateIfShown()");
943 if (isShowing()
Jean-Michel Trivi3114ce32012-06-11 15:03:52 -0700944 && (mActiveStreamType == AudioService.STREAM_REMOTE_MUSIC)
945 && (mStreamControls != null)) {
946 onShowVolumeChanged(AudioService.STREAM_REMOTE_MUSIC, 0);
947 }
948 }
949
950
951 /**
952 * Handler for MSG_SLIDER_VISIBILITY_CHANGED
953 * Hide or show a slider
954 * @param streamType can be a valid stream type value, or VolumePanel.STREAM_MASTER,
955 * or AudioService.STREAM_REMOTE_MUSIC
956 * @param visible
957 */
958 synchronized protected void onSliderVisibilityChanged(int streamType, int visible) {
John Spurlock86005342014-05-23 11:58:00 -0400959 if (LOGD) Log.d(mTag, "onSliderVisibilityChanged(stream="+streamType+", visi="+visible+")");
Jean-Michel Trivi3114ce32012-06-11 15:03:52 -0700960 boolean isVisible = (visible == 1);
961 for (int i = STREAMS.length - 1 ; i >= 0 ; i--) {
962 StreamResources streamRes = STREAMS[i];
963 if (streamRes.streamType == streamType) {
964 streamRes.show = isVisible;
965 if (!isVisible && (mActiveStreamType == streamType)) {
966 mActiveStreamType = -1;
967 }
968 break;
969 }
970 }
971 }
972
Eric Laurentfde16d52012-12-03 14:42:39 -0800973 protected void onDisplaySafeVolumeWarning(int flags) {
John Spurlock86005342014-05-23 11:58:00 -0400974 if ((flags & AudioManager.FLAG_SHOW_UI) != 0 || isShowing()) {
Eric Laurentfde16d52012-12-03 14:42:39 -0800975 synchronized (sConfirmSafeVolumeLock) {
976 if (sConfirmSafeVolumeDialog != null) {
977 return;
978 }
979 sConfirmSafeVolumeDialog = new AlertDialog.Builder(mContext)
980 .setMessage(com.android.internal.R.string.safe_media_volume_warning)
981 .setPositiveButton(com.android.internal.R.string.yes,
982 new DialogInterface.OnClickListener() {
Alan Viverettee8ebaf32014-04-11 15:44:15 -0700983 @Override
Eric Laurentfde16d52012-12-03 14:42:39 -0800984 public void onClick(DialogInterface dialog, int which) {
John Spurlock3346a802014-05-20 16:25:37 -0400985 mAudioManager.disableSafeMediaVolume();
Eric Laurentfde16d52012-12-03 14:42:39 -0800986 }
987 })
988 .setNegativeButton(com.android.internal.R.string.no, null)
989 .setIconAttribute(android.R.attr.alertDialogIcon)
990 .create();
991 final WarningDialogReceiver warning = new WarningDialogReceiver(mContext,
992 sConfirmSafeVolumeDialog, this);
Eric Laurent0516a9e2012-09-19 11:53:03 -0700993
Eric Laurentfde16d52012-12-03 14:42:39 -0800994 sConfirmSafeVolumeDialog.setOnDismissListener(warning);
995 sConfirmSafeVolumeDialog.getWindow().setType(
996 WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG);
997 sConfirmSafeVolumeDialog.show();
998 }
999 updateStates();
Eric Laurentc34dcc12012-09-10 13:51:52 -07001000 }
Eric Laurentfde16d52012-12-03 14:42:39 -08001001 resetTimeout();
Eric Laurentc34dcc12012-09-10 13:51:52 -07001002 }
1003
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001004 /**
1005 * Lock on this VolumePanel instance as long as you use the returned ToneGenerator.
1006 */
1007 private ToneGenerator getOrCreateToneGenerator(int streamType) {
Christopher Tatec4b78d22012-05-22 13:57:58 -07001008 if (streamType == STREAM_MASTER) {
1009 // For devices that use the master volume setting only but still want to
1010 // play a volume-changed tone, direct the master volume pseudostream to
1011 // the system stream's tone generator.
1012 if (mPlayMasterStreamTones) {
1013 streamType = AudioManager.STREAM_SYSTEM;
1014 } else {
1015 return null;
1016 }
1017 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001018 synchronized (this) {
1019 if (mToneGenerators[streamType] == null) {
Eric Laurent733a42b2011-01-19 10:41:57 -08001020 try {
1021 mToneGenerators[streamType] = new ToneGenerator(streamType, MAX_VOLUME);
1022 } catch (RuntimeException e) {
1023 if (LOGD) {
John Spurlock86005342014-05-23 11:58:00 -04001024 Log.d(mTag, "ToneGenerator constructor failed with "
Eric Laurent733a42b2011-01-19 10:41:57 -08001025 + "RuntimeException: " + e);
1026 }
1027 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001028 }
Eric Laurent733a42b2011-01-19 10:41:57 -08001029 return mToneGenerators[streamType];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001030 }
1031 }
1032
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001033
1034 /**
Amith Yamasani2bbdd772011-02-02 18:54:13 -08001035 * Switch between icons because Bluetooth music is same as music volume, but with
1036 * different icons.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001037 */
Amith Yamasani2bbdd772011-02-02 18:54:13 -08001038 private void setMusicIcon(int resId, int resMuteId) {
1039 StreamControl sc = mStreamControls.get(AudioManager.STREAM_MUSIC);
1040 if (sc != null) {
1041 sc.iconRes = resId;
1042 sc.iconMuteRes = resMuteId;
1043 sc.icon.setImageResource(isMuted(sc.streamType) ? sc.iconMuteRes : sc.iconRes);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001044 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001045 }
1046
1047 protected void onFreeResources() {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001048 synchronized (this) {
1049 for (int i = mToneGenerators.length - 1; i >= 0; i--) {
1050 if (mToneGenerators[i] != null) {
1051 mToneGenerators[i].release();
1052 }
1053 mToneGenerators[i] = null;
1054 }
1055 }
1056 }
1057
1058 @Override
1059 public void handleMessage(Message msg) {
1060 switch (msg.what) {
1061
1062 case MSG_VOLUME_CHANGED: {
1063 onVolumeChanged(msg.arg1, msg.arg2);
1064 break;
1065 }
1066
Mike Lockwoodce952c82011-11-14 10:47:42 -08001067 case MSG_MUTE_CHANGED: {
1068 onMuteChanged(msg.arg1, msg.arg2);
1069 break;
1070 }
1071
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001072 case MSG_FREE_RESOURCES: {
1073 onFreeResources();
1074 break;
1075 }
1076
1077 case MSG_STOP_SOUNDS: {
1078 onStopSounds();
1079 break;
1080 }
1081
1082 case MSG_PLAY_SOUND: {
1083 onPlaySound(msg.arg1, msg.arg2);
1084 break;
1085 }
1086
1087 case MSG_VIBRATE: {
1088 onVibrate();
1089 break;
1090 }
1091
Amith Yamasani2bbdd772011-02-02 18:54:13 -08001092 case MSG_TIMEOUT: {
John Spurlock86005342014-05-23 11:58:00 -04001093 if (isShowing()) {
1094 if (mDialog != null) {
1095 mDialog.dismiss();
John Spurlockf71205c2014-05-29 10:17:51 -04001096 mActiveStreamType = -1;
John Spurlock86005342014-05-23 11:58:00 -04001097 }
Amith Yamasani2bbdd772011-02-02 18:54:13 -08001098 }
Eric Laurentfde16d52012-12-03 14:42:39 -08001099 synchronized (sConfirmSafeVolumeLock) {
1100 if (sConfirmSafeVolumeDialog != null) {
1101 sConfirmSafeVolumeDialog.dismiss();
1102 }
1103 }
Amith Yamasani2bbdd772011-02-02 18:54:13 -08001104 break;
1105 }
1106 case MSG_RINGER_MODE_CHANGED: {
John Spurlock86005342014-05-23 11:58:00 -04001107 if (isShowing()) {
Amith Yamasani2bbdd772011-02-02 18:54:13 -08001108 updateStates();
1109 }
1110 break;
1111 }
Jean-Michel Trivi3114ce32012-06-11 15:03:52 -07001112
1113 case MSG_REMOTE_VOLUME_CHANGED: {
1114 onRemoteVolumeChanged(msg.arg1, msg.arg2);
1115 break;
1116 }
1117
1118 case MSG_REMOTE_VOLUME_UPDATE_IF_SHOWN:
1119 onRemoteVolumeUpdateIfShown();
1120 break;
1121
1122 case MSG_SLIDER_VISIBILITY_CHANGED:
1123 onSliderVisibilityChanged(msg.arg1, msg.arg2);
1124 break;
Eric Laurentc34dcc12012-09-10 13:51:52 -07001125
1126 case MSG_DISPLAY_SAFE_VOLUME_WARNING:
Eric Laurentfde16d52012-12-03 14:42:39 -08001127 onDisplaySafeVolumeWarning(msg.arg1);
Eric Laurentc34dcc12012-09-10 13:51:52 -07001128 break;
John Spurlock86005342014-05-23 11:58:00 -04001129
1130 case MSG_LAYOUT_DIRECTION:
1131 setLayoutDirection(msg.arg1);
1132 break;
1133
1134 case MSG_ZEN_MODE_CHANGED:
1135 updateZenMode(msg.arg1 != 0);
1136 break;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001137 }
1138 }
1139
John Spurlock86005342014-05-23 11:58:00 -04001140 public void resetTimeout() {
1141 if (LOGD) Log.d(mTag, "resetTimeout at " + System.currentTimeMillis());
Amith Yamasani2bbdd772011-02-02 18:54:13 -08001142 removeMessages(MSG_TIMEOUT);
John Spurlock3bd4fee2014-05-29 20:51:09 -04001143 sendEmptyMessageDelayed(MSG_TIMEOUT, mTimeoutDelay);
Amith Yamasani2bbdd772011-02-02 18:54:13 -08001144 }
1145
Amith Yamasanibaf6dbf2011-08-18 17:40:29 -07001146 private void forceTimeout() {
1147 removeMessages(MSG_TIMEOUT);
John Spurlock86005342014-05-23 11:58:00 -04001148 sendEmptyMessage(MSG_TIMEOUT);
1149 }
1150
1151 public ZenModeController getZenController() {
1152 return mZenController;
Amith Yamasanibaf6dbf2011-08-18 17:40:29 -07001153 }
1154
Alan Viverettee8ebaf32014-04-11 15:44:15 -07001155 private final OnSeekBarChangeListener mSeekListener = new OnSeekBarChangeListener() {
1156 @Override
1157 public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
1158 final Object tag = seekBar.getTag();
1159 if (fromUser && tag instanceof StreamControl) {
1160 StreamControl sc = (StreamControl) tag;
1161 if (getStreamVolume(sc.streamType) != progress) {
1162 setStreamVolume(sc.streamType, progress, 0);
1163 }
1164 }
1165 resetTimeout();
1166 }
1167
1168 @Override
1169 public void onStartTrackingTouch(SeekBar seekBar) {
1170 }
1171
1172 @Override
1173 public void onStopTrackingTouch(SeekBar seekBar) {
1174 final Object tag = seekBar.getTag();
1175 if (tag instanceof StreamControl) {
1176 StreamControl sc = (StreamControl) tag;
1177 // Because remote volume updates are asynchronous, AudioService
1178 // might have received a new remote volume value since the
1179 // finger adjusted the slider. So when the progress of the
1180 // slider isn't being tracked anymore, adjust the slider to the
1181 // last "published" remote volume value, so the UI reflects the
1182 // actual volume.
1183 if (sc.streamType == AudioService.STREAM_REMOTE_MUSIC) {
1184 seekBar.setProgress(getStreamVolume(AudioService.STREAM_REMOTE_MUSIC));
1185 }
Amith Yamasani2bbdd772011-02-02 18:54:13 -08001186 }
1187 }
Alan Viverettee8ebaf32014-04-11 15:44:15 -07001188 };
Amith Yamasani2bbdd772011-02-02 18:54:13 -08001189
Alan Viverettee8ebaf32014-04-11 15:44:15 -07001190 private final View.OnClickListener mClickListener = new View.OnClickListener() {
1191 @Override
1192 public void onClick(View v) {
John Spurlock86005342014-05-23 11:58:00 -04001193 if (v == mExpandButton && mZenController != null) {
1194 final boolean newZen = !mZenController.isZen();
John Spurlock3bd4fee2014-05-29 20:51:09 -04001195 AsyncTask.execute(new Runnable() {
1196 @Override
1197 public void run() {
1198 mZenController.setZen(newZen);
1199 }
1200 });
John Spurlock86005342014-05-23 11:58:00 -04001201 if (newZen) {
1202 expand();
1203 } else {
1204 collapse();
1205 }
Jean-Michel Trivi3114ce32012-06-11 15:03:52 -07001206 }
Alan Viverettee8ebaf32014-04-11 15:44:15 -07001207 resetTimeout();
Jean-Michel Trivi3114ce32012-06-11 15:03:52 -07001208 }
Alan Viverettee8ebaf32014-04-11 15:44:15 -07001209 };
John Spurlock86005342014-05-23 11:58:00 -04001210
1211 private final ZenModeController.Callback mZenCallback = new ZenModeController.Callback() {
1212 public void onZenChanged(boolean zen) {
John Spurlock7f1df5e2014-05-31 19:11:40 -04001213 postZenModeChanged(zen);
John Spurlock86005342014-05-23 11:58:00 -04001214 }
1215 };
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001216}