The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 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 Spurlock | 3346a80 | 2014-05-20 16:25:37 -0400 | [diff] [blame] | 17 | package com.android.systemui.volume; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 18 | |
Eric Laurent | c34dcc1 | 2012-09-10 13:51:52 -0700 | [diff] [blame] | 19 | import android.app.AlertDialog; |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 20 | import android.app.Dialog; |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 21 | import android.content.BroadcastReceiver; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 22 | import android.content.Context; |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 23 | import android.content.DialogInterface; |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 24 | import android.content.DialogInterface.OnDismissListener; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 25 | import android.content.Intent; |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 26 | import android.content.IntentFilter; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 27 | import android.content.res.Resources; |
John Spurlock | 2078caf | 2014-05-29 22:20:14 -0400 | [diff] [blame^] | 28 | import android.graphics.PixelFormat; |
| 29 | import android.graphics.drawable.ColorDrawable; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 30 | import android.media.AudioManager; |
| 31 | import android.media.AudioService; |
| 32 | import android.media.AudioSystem; |
Marco Nelissen | 69f593c | 2009-07-28 09:55:04 -0700 | [diff] [blame] | 33 | import android.media.RingtoneManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 34 | import android.media.ToneGenerator; |
Marco Nelissen | 69f593c | 2009-07-28 09:55:04 -0700 | [diff] [blame] | 35 | import android.net.Uri; |
John Spurlock | 3bd4fee | 2014-05-29 20:51:09 -0400 | [diff] [blame] | 36 | import android.os.AsyncTask; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 37 | import android.os.Handler; |
| 38 | import android.os.Message; |
| 39 | import android.os.Vibrator; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 40 | import android.util.Log; |
John Spurlock | 3346a80 | 2014-05-20 16:25:37 -0400 | [diff] [blame] | 41 | import android.view.Gravity; |
| 42 | import android.view.LayoutInflater; |
| 43 | import android.view.MotionEvent; |
| 44 | import android.view.View; |
| 45 | import android.view.ViewGroup; |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 46 | import android.view.ViewStub; |
John Spurlock | 3346a80 | 2014-05-20 16:25:37 -0400 | [diff] [blame] | 47 | import android.view.Window; |
| 48 | import android.view.WindowManager; |
Amith Yamasani | 284e630 | 2011-09-16 18:24:47 -0700 | [diff] [blame] | 49 | import android.view.WindowManager.LayoutParams; |
John Spurlock | 2078caf | 2014-05-29 22:20:14 -0400 | [diff] [blame^] | 50 | import android.widget.FrameLayout; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 51 | import android.widget.ImageView; |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 52 | import android.widget.SeekBar; |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 53 | import android.widget.SeekBar.OnSeekBarChangeListener; |
| 54 | |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 55 | import com.android.internal.R; |
| 56 | import com.android.systemui.statusbar.policy.ZenModeController; |
| 57 | |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 58 | import java.util.HashMap; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 59 | |
| 60 | /** |
John Spurlock | 3346a80 | 2014-05-20 16:25:37 -0400 | [diff] [blame] | 61 | * Handles the user interface for the volume keys. |
Dianne Hackborn | e8ecde1 | 2011-08-03 18:55:19 -0700 | [diff] [blame] | 62 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 63 | * @hide |
| 64 | */ |
John Spurlock | 3346a80 | 2014-05-20 16:25:37 -0400 | [diff] [blame] | 65 | public class VolumePanel extends Handler { |
Marco Nelissen | 69f593c | 2009-07-28 09:55:04 -0700 | [diff] [blame] | 66 | private static boolean LOGD = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 67 | |
John Spurlock | 3346a80 | 2014-05-20 16:25:37 -0400 | [diff] [blame] | 68 | private static final int PLAY_SOUND_DELAY = AudioService.PLAY_SOUND_DELAY; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 69 | |
| 70 | /** |
| 71 | * The delay before vibrating. This small period exists so if the user is |
| 72 | * moving to silent mode, it will not emit a short vibrate (it normally |
| 73 | * would since vibrate is between normal mode and silent mode using hardware |
| 74 | * keys). |
| 75 | */ |
| 76 | public static final int VIBRATE_DELAY = 300; |
| 77 | |
| 78 | private static final int VIBRATE_DURATION = 300; |
| 79 | private static final int BEEP_DURATION = 150; |
| 80 | private static final int MAX_VOLUME = 100; |
| 81 | private static final int FREE_DELAY = 10000; |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 82 | private static final int TIMEOUT_DELAY = 3000; |
John Spurlock | 3bd4fee | 2014-05-29 20:51:09 -0400 | [diff] [blame] | 83 | private static final int TIMEOUT_DELAY_EXPANDED = 10000; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 84 | |
| 85 | private static final int MSG_VOLUME_CHANGED = 0; |
| 86 | private static final int MSG_FREE_RESOURCES = 1; |
| 87 | private static final int MSG_PLAY_SOUND = 2; |
| 88 | private static final int MSG_STOP_SOUNDS = 3; |
| 89 | private static final int MSG_VIBRATE = 4; |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 90 | private static final int MSG_TIMEOUT = 5; |
| 91 | private static final int MSG_RINGER_MODE_CHANGED = 6; |
Mike Lockwood | ce952c8 | 2011-11-14 10:47:42 -0800 | [diff] [blame] | 92 | private static final int MSG_MUTE_CHANGED = 7; |
Jean-Michel Trivi | 3114ce3 | 2012-06-11 15:03:52 -0700 | [diff] [blame] | 93 | private static final int MSG_REMOTE_VOLUME_CHANGED = 8; |
| 94 | private static final int MSG_REMOTE_VOLUME_UPDATE_IF_SHOWN = 9; |
| 95 | private static final int MSG_SLIDER_VISIBILITY_CHANGED = 10; |
Eric Laurent | c34dcc1 | 2012-09-10 13:51:52 -0700 | [diff] [blame] | 96 | private static final int MSG_DISPLAY_SAFE_VOLUME_WARNING = 11; |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 97 | private static final int MSG_LAYOUT_DIRECTION = 12; |
| 98 | private static final int MSG_ZEN_MODE_CHANGED = 13; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 99 | |
Mike Lockwood | 8dc1dab | 2011-10-27 09:52:41 -0400 | [diff] [blame] | 100 | // Pseudo stream type for master volume |
Mike Lockwood | 4767690 | 2011-11-08 10:31:21 -0800 | [diff] [blame] | 101 | private static final int STREAM_MASTER = -100; |
Jean-Michel Trivi | 3114ce3 | 2012-06-11 15:03:52 -0700 | [diff] [blame] | 102 | // Pseudo stream type for remote volume is defined in AudioService.STREAM_REMOTE_MUSIC |
Mike Lockwood | 8dc1dab | 2011-10-27 09:52:41 -0400 | [diff] [blame] | 103 | |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 104 | private final String mTag; |
John Spurlock | 3346a80 | 2014-05-20 16:25:37 -0400 | [diff] [blame] | 105 | protected final Context mContext; |
| 106 | private final AudioManager mAudioManager; |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 107 | private final ZenModeController mZenController; |
Marco Nelissen | 69f593c | 2009-07-28 09:55:04 -0700 | [diff] [blame] | 108 | private boolean mRingIsSilent; |
Amith Yamasani | 71def77 | 2011-10-12 12:25:24 -0700 | [diff] [blame] | 109 | private boolean mVoiceCapable; |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 110 | private boolean mZenModeCapable; |
John Spurlock | 3bd4fee | 2014-05-29 20:51:09 -0400 | [diff] [blame] | 111 | private int mTimeoutDelay = TIMEOUT_DELAY; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 112 | |
Christopher Tate | c4b78d2 | 2012-05-22 13:57:58 -0700 | [diff] [blame] | 113 | // True if we want to play tones on the system stream when the master stream is specified. |
| 114 | private final boolean mPlayMasterStreamTones; |
| 115 | |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 116 | |
| 117 | /** Volume panel content view */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 118 | private final View mView; |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 119 | /** Dialog hosting the panel, if not embedded */ |
| 120 | private final Dialog mDialog; |
| 121 | /** Parent view hosting the panel, if embedded */ |
| 122 | private final ViewGroup mParent; |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 123 | |
Amith Yamasani | baf6dbf | 2011-08-18 17:40:29 -0700 | [diff] [blame] | 124 | /** The visible portion of the volume overlay */ |
| 125 | private final ViewGroup mPanel; |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 126 | /** Contains the slider and its touchable icons */ |
| 127 | private final ViewGroup mSliderPanel; |
| 128 | /** The button that expands the dialog to show the zen panel */ |
| 129 | private final ImageView mExpandButton; |
| 130 | /** Dummy divider icon that needs to vanish with the expand button */ |
| 131 | private final View mExpandDivider; |
| 132 | /** The zen mode configuration panel view stub */ |
| 133 | private final ViewStub mZenPanelStub; |
| 134 | /** The zen mode configuration panel view, once inflated */ |
| 135 | private ZenModePanel mZenPanel; |
| 136 | /** Dummy divider icon that needs to vanish with the zen panel */ |
| 137 | private final View mZenPanelDivider; |
| 138 | |
| 139 | private ZenModePanel.Callback mZenPanelCallback; |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 140 | |
| 141 | /** Currently active stream that shows up at the top of the list of sliders */ |
| 142 | private int mActiveStreamType = -1; |
| 143 | /** All the slider controls mapped by stream type */ |
| 144 | private HashMap<Integer,StreamControl> mStreamControls; |
| 145 | |
Amith Yamasani | 71def77 | 2011-10-12 12:25:24 -0700 | [diff] [blame] | 146 | private enum StreamResources { |
| 147 | BluetoothSCOStream(AudioManager.STREAM_BLUETOOTH_SCO, |
| 148 | R.string.volume_icon_description_bluetooth, |
| 149 | R.drawable.ic_audio_bt, |
| 150 | R.drawable.ic_audio_bt, |
| 151 | false), |
| 152 | RingerStream(AudioManager.STREAM_RING, |
| 153 | R.string.volume_icon_description_ringer, |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 154 | com.android.systemui.R.drawable.ic_ringer_audible, |
| 155 | com.android.systemui.R.drawable.ic_ringer_silent, |
Amith Yamasani | 71def77 | 2011-10-12 12:25:24 -0700 | [diff] [blame] | 156 | false), |
| 157 | VoiceStream(AudioManager.STREAM_VOICE_CALL, |
| 158 | R.string.volume_icon_description_incall, |
| 159 | R.drawable.ic_audio_phone, |
| 160 | R.drawable.ic_audio_phone, |
| 161 | false), |
Amith Yamasani | 92e1b2d | 2011-10-14 17:24:47 -0700 | [diff] [blame] | 162 | AlarmStream(AudioManager.STREAM_ALARM, |
| 163 | R.string.volume_alarm, |
| 164 | R.drawable.ic_audio_alarm, |
| 165 | R.drawable.ic_audio_alarm_mute, |
| 166 | false), |
Amith Yamasani | 71def77 | 2011-10-12 12:25:24 -0700 | [diff] [blame] | 167 | MediaStream(AudioManager.STREAM_MUSIC, |
| 168 | R.string.volume_icon_description_media, |
| 169 | R.drawable.ic_audio_vol, |
| 170 | R.drawable.ic_audio_vol_mute, |
| 171 | true), |
| 172 | NotificationStream(AudioManager.STREAM_NOTIFICATION, |
| 173 | R.string.volume_icon_description_notification, |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 174 | com.android.systemui.R.drawable.ic_ringer_audible, |
| 175 | com.android.systemui.R.drawable.ic_ringer_silent, |
Mike Lockwood | 8dc1dab | 2011-10-27 09:52:41 -0400 | [diff] [blame] | 176 | true), |
| 177 | // for now, use media resources for master volume |
| 178 | MasterStream(STREAM_MASTER, |
Jean-Michel Trivi | 3114ce3 | 2012-06-11 15:03:52 -0700 | [diff] [blame] | 179 | R.string.volume_icon_description_media, //FIXME should have its own description |
Mike Lockwood | 8dc1dab | 2011-10-27 09:52:41 -0400 | [diff] [blame] | 180 | R.drawable.ic_audio_vol, |
| 181 | R.drawable.ic_audio_vol_mute, |
Jean-Michel Trivi | 3114ce3 | 2012-06-11 15:03:52 -0700 | [diff] [blame] | 182 | false), |
| 183 | RemoteStream(AudioService.STREAM_REMOTE_MUSIC, |
| 184 | R.string.volume_icon_description_media, //FIXME should have its own description |
| 185 | R.drawable.ic_media_route_on_holo_dark, |
| 186 | R.drawable.ic_media_route_disabled_holo_dark, |
| 187 | false);// will be dynamically updated |
Amith Yamasani | 71def77 | 2011-10-12 12:25:24 -0700 | [diff] [blame] | 188 | |
| 189 | int streamType; |
| 190 | int descRes; |
| 191 | int iconRes; |
| 192 | int iconMuteRes; |
| 193 | // RING, VOICE_CALL & BLUETOOTH_SCO are hidden unless explicitly requested |
| 194 | boolean show; |
| 195 | |
| 196 | StreamResources(int streamType, int descRes, int iconRes, int iconMuteRes, boolean show) { |
| 197 | this.streamType = streamType; |
| 198 | this.descRes = descRes; |
| 199 | this.iconRes = iconRes; |
| 200 | this.iconMuteRes = iconMuteRes; |
| 201 | this.show = show; |
| 202 | } |
Alan Viverette | e8ebaf3 | 2014-04-11 15:44:15 -0700 | [diff] [blame] | 203 | } |
Amith Yamasani | 71def77 | 2011-10-12 12:25:24 -0700 | [diff] [blame] | 204 | |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 205 | // List of stream types and their order |
Amith Yamasani | 71def77 | 2011-10-12 12:25:24 -0700 | [diff] [blame] | 206 | private static final StreamResources[] STREAMS = { |
| 207 | StreamResources.BluetoothSCOStream, |
| 208 | StreamResources.RingerStream, |
| 209 | StreamResources.VoiceStream, |
| 210 | StreamResources.MediaStream, |
Amith Yamasani | 92e1b2d | 2011-10-14 17:24:47 -0700 | [diff] [blame] | 211 | StreamResources.NotificationStream, |
Mike Lockwood | 8dc1dab | 2011-10-27 09:52:41 -0400 | [diff] [blame] | 212 | StreamResources.AlarmStream, |
Jean-Michel Trivi | 3114ce3 | 2012-06-11 15:03:52 -0700 | [diff] [blame] | 213 | StreamResources.MasterStream, |
| 214 | StreamResources.RemoteStream |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 215 | }; |
| 216 | |
| 217 | /** Object that contains data for each slider */ |
| 218 | private class StreamControl { |
| 219 | int streamType; |
| 220 | ViewGroup group; |
| 221 | ImageView icon; |
| 222 | SeekBar seekbarView; |
| 223 | int iconRes; |
| 224 | int iconMuteRes; |
| 225 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 226 | |
| 227 | // Synchronize when accessing this |
| 228 | private ToneGenerator mToneGenerators[]; |
| 229 | private Vibrator mVibrator; |
| 230 | |
Eric Laurent | c34dcc1 | 2012-09-10 13:51:52 -0700 | [diff] [blame] | 231 | private static AlertDialog sConfirmSafeVolumeDialog; |
Eric Laurent | 0516a9e | 2012-09-19 11:53:03 -0700 | [diff] [blame] | 232 | private static Object sConfirmSafeVolumeLock = new Object(); |
Eric Laurent | c34dcc1 | 2012-09-10 13:51:52 -0700 | [diff] [blame] | 233 | |
| 234 | private static class WarningDialogReceiver extends BroadcastReceiver |
| 235 | implements DialogInterface.OnDismissListener { |
Eric Laurent | fde16d5 | 2012-12-03 14:42:39 -0800 | [diff] [blame] | 236 | private final Context mContext; |
| 237 | private final Dialog mDialog; |
| 238 | private final VolumePanel mVolumePanel; |
Eric Laurent | c34dcc1 | 2012-09-10 13:51:52 -0700 | [diff] [blame] | 239 | |
Eric Laurent | fde16d5 | 2012-12-03 14:42:39 -0800 | [diff] [blame] | 240 | WarningDialogReceiver(Context context, Dialog dialog, VolumePanel volumePanel) { |
Eric Laurent | c34dcc1 | 2012-09-10 13:51:52 -0700 | [diff] [blame] | 241 | mContext = context; |
| 242 | mDialog = dialog; |
Eric Laurent | fde16d5 | 2012-12-03 14:42:39 -0800 | [diff] [blame] | 243 | mVolumePanel = volumePanel; |
Eric Laurent | c34dcc1 | 2012-09-10 13:51:52 -0700 | [diff] [blame] | 244 | IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS); |
| 245 | context.registerReceiver(this, filter); |
| 246 | } |
| 247 | |
| 248 | @Override |
| 249 | public void onReceive(Context context, Intent intent) { |
| 250 | mDialog.cancel(); |
Eric Laurent | fde16d5 | 2012-12-03 14:42:39 -0800 | [diff] [blame] | 251 | cleanUp(); |
Eric Laurent | c34dcc1 | 2012-09-10 13:51:52 -0700 | [diff] [blame] | 252 | } |
| 253 | |
Alan Viverette | 494fb7b | 2014-04-10 18:12:56 -0700 | [diff] [blame] | 254 | @Override |
Eric Laurent | c34dcc1 | 2012-09-10 13:51:52 -0700 | [diff] [blame] | 255 | public void onDismiss(DialogInterface unused) { |
| 256 | mContext.unregisterReceiver(this); |
Eric Laurent | fde16d5 | 2012-12-03 14:42:39 -0800 | [diff] [blame] | 257 | cleanUp(); |
| 258 | } |
| 259 | |
| 260 | private void cleanUp() { |
Eric Laurent | 0516a9e | 2012-09-19 11:53:03 -0700 | [diff] [blame] | 261 | synchronized (sConfirmSafeVolumeLock) { |
| 262 | sConfirmSafeVolumeDialog = null; |
| 263 | } |
Eric Laurent | fde16d5 | 2012-12-03 14:42:39 -0800 | [diff] [blame] | 264 | mVolumePanel.forceTimeout(); |
| 265 | mVolumePanel.updateStates(); |
Eric Laurent | c34dcc1 | 2012-09-10 13:51:52 -0700 | [diff] [blame] | 266 | } |
| 267 | } |
| 268 | |
| 269 | |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 270 | public VolumePanel(Context context, ViewGroup parent, ZenModeController zenController) { |
| 271 | mTag = String.format("VolumePanel%s.%08x", parent == null ? "Dialog" : "", hashCode()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 272 | mContext = context; |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 273 | mParent = parent; |
| 274 | mZenController = zenController; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 275 | mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 276 | |
Mike Lockwood | 8dc1dab | 2011-10-27 09:52:41 -0400 | [diff] [blame] | 277 | // For now, only show master volume if master volume is supported |
Alan Viverette | e8ebaf3 | 2014-04-11 15:44:15 -0700 | [diff] [blame] | 278 | final Resources res = context.getResources(); |
| 279 | final boolean useMasterVolume = res.getBoolean(R.bool.config_useMasterVolume); |
Mike Lockwood | 8dc1dab | 2011-10-27 09:52:41 -0400 | [diff] [blame] | 280 | if (useMasterVolume) { |
| 281 | for (int i = 0; i < STREAMS.length; i++) { |
| 282 | StreamResources streamRes = STREAMS[i]; |
| 283 | streamRes.show = (streamRes.streamType == STREAM_MASTER); |
| 284 | } |
| 285 | } |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 286 | if (LOGD) Log.d(mTag, String.format("new VolumePanel hasParent=%s", parent != null)); |
| 287 | final int layoutId = com.android.systemui.R.layout.volume_panel; |
| 288 | if (parent == null) { |
| 289 | // dialog mode |
| 290 | mDialog = new Dialog(context) { |
| 291 | @Override |
| 292 | public boolean onTouchEvent(MotionEvent event) { |
| 293 | if (isShowing() && event.getAction() == MotionEvent.ACTION_OUTSIDE && |
| 294 | sConfirmSafeVolumeDialog == null) { |
| 295 | forceTimeout(); |
| 296 | return true; |
| 297 | } |
| 298 | return false; |
Amith Yamasani | 284e630 | 2011-09-16 18:24:47 -0700 | [diff] [blame] | 299 | } |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 300 | }; |
Alan Viverette | e8ebaf3 | 2014-04-11 15:44:15 -0700 | [diff] [blame] | 301 | |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 302 | // Change some window properties |
| 303 | final Window window = mDialog.getWindow(); |
| 304 | final LayoutParams lp = window.getAttributes(); |
| 305 | lp.token = null; |
| 306 | // Offset from the top |
| 307 | lp.y = res.getDimensionPixelOffset(com.android.systemui.R.dimen.volume_panel_top); |
| 308 | lp.width = res.getDimensionPixelSize(com.android.systemui.R.dimen.volume_panel_width); |
| 309 | lp.type = LayoutParams.TYPE_VOLUME_OVERLAY; |
John Spurlock | 2078caf | 2014-05-29 22:20:14 -0400 | [diff] [blame^] | 310 | lp.format = PixelFormat.TRANSLUCENT; |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 311 | lp.windowAnimations = R.style.Animation_VolumePanel; |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 312 | window.setAttributes(lp); |
| 313 | window.setGravity(Gravity.TOP); |
| 314 | window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); |
| 315 | window.requestFeature(Window.FEATURE_NO_TITLE); |
| 316 | window.addFlags(LayoutParams.FLAG_NOT_FOCUSABLE |
| 317 | | LayoutParams.FLAG_NOT_TOUCH_MODAL |
John Spurlock | 2078caf | 2014-05-29 22:20:14 -0400 | [diff] [blame^] | 318 | | LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH |
| 319 | | LayoutParams.FLAG_HARDWARE_ACCELERATED); |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 320 | mDialog.setCanceledOnTouchOutside(true); |
John Spurlock | 2078caf | 2014-05-29 22:20:14 -0400 | [diff] [blame^] | 321 | // temporary workaround for no window shadows |
| 322 | final FrameLayout layout = new FrameLayout(mContext); |
| 323 | final int z = res.getDimensionPixelSize(com.android.systemui.R.dimen.volume_panel_z); |
| 324 | layout.setPadding(z, z, z, z); |
| 325 | final View v = LayoutInflater.from(mContext).inflate(layoutId, layout, false); |
| 326 | v.setBackgroundResource(com.android.systemui.R.drawable.qs_panel_background); |
| 327 | v.setElevation(z); |
| 328 | layout.addView(v); |
| 329 | mDialog.setContentView(layout); |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 330 | mDialog.setOnDismissListener(new OnDismissListener() { |
| 331 | @Override |
| 332 | public void onDismiss(DialogInterface dialog) { |
| 333 | mActiveStreamType = -1; |
| 334 | mAudioManager.forceVolumeControlStream(mActiveStreamType); |
| 335 | } |
| 336 | }); |
Alan Viverette | e8ebaf3 | 2014-04-11 15:44:15 -0700 | [diff] [blame] | 337 | |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 338 | mDialog.create(); |
John Spurlock | 2078caf | 2014-05-29 22:20:14 -0400 | [diff] [blame^] | 339 | mDialog.getWindow().setBackgroundDrawable(new ColorDrawable(0x00000000)); |
Alan Viverette | 494fb7b | 2014-04-10 18:12:56 -0700 | [diff] [blame] | 340 | |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 341 | mView = window.findViewById(R.id.content); |
| 342 | mView.setOnTouchListener(new View.OnTouchListener() { |
| 343 | @Override |
| 344 | public boolean onTouch(View v, MotionEvent event) { |
| 345 | resetTimeout(); |
| 346 | return false; |
| 347 | } |
| 348 | }); |
Alan Viverette | 494fb7b | 2014-04-10 18:12:56 -0700 | [diff] [blame] | 349 | |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 350 | } else { |
| 351 | // embedded mode |
| 352 | mDialog = null; |
| 353 | mView = LayoutInflater.from(mContext).inflate(layoutId, parent, true); |
| 354 | } |
| 355 | mPanel = (ViewGroup) mView.findViewById(com.android.systemui.R.id.visible_panel); |
| 356 | mSliderPanel = (ViewGroup) mView.findViewById(com.android.systemui.R.id.slider_panel); |
| 357 | mExpandButton = (ImageView) mView.findViewById(com.android.systemui.R.id.expand_button); |
| 358 | mExpandDivider = mView.findViewById(com.android.systemui.R.id.expand_button_divider); |
| 359 | mZenPanelStub = (ViewStub)mView.findViewById(com.android.systemui.R.id.zen_panel_stub); |
| 360 | mZenPanelDivider = mView.findViewById(com.android.systemui.R.id.zen_panel_divider); |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 361 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 362 | mToneGenerators = new ToneGenerator[AudioSystem.getNumStreamTypes()]; |
Alan Viverette | e8ebaf3 | 2014-04-11 15:44:15 -0700 | [diff] [blame] | 363 | mVibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE); |
Amith Yamasani | 71def77 | 2011-10-12 12:25:24 -0700 | [diff] [blame] | 364 | mVoiceCapable = context.getResources().getBoolean(R.bool.config_voice_capable); |
Alan Viverette | e8ebaf3 | 2014-04-11 15:44:15 -0700 | [diff] [blame] | 365 | |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 366 | mZenModeCapable = !useMasterVolume && mZenController != null; |
| 367 | mZenPanelDivider.setVisibility(View.GONE); |
| 368 | mExpandButton.setOnClickListener(mClickListener); |
| 369 | updateZenMode(mZenController == null ? false : mZenController.isZen()); |
| 370 | mZenController.addCallback(mZenCallback); |
Amith Yamasani | 42722bf | 2011-07-22 10:34:27 -0700 | [diff] [blame] | 371 | |
Alan Viverette | e8ebaf3 | 2014-04-11 15:44:15 -0700 | [diff] [blame] | 372 | final boolean masterVolumeOnly = res.getBoolean(R.bool.config_useMasterVolume); |
| 373 | final boolean masterVolumeKeySounds = res.getBoolean(R.bool.config_useVolumeKeySounds); |
Christopher Tate | c4b78d2 | 2012-05-22 13:57:58 -0700 | [diff] [blame] | 374 | mPlayMasterStreamTones = masterVolumeOnly && masterVolumeKeySounds; |
| 375 | |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 376 | listenToRingerMode(); |
| 377 | } |
| 378 | |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 379 | private void setLayoutDirection(int layoutDirection) { |
Fabrice Di Meglio | 8c02884 | 2013-01-09 18:20:38 -0800 | [diff] [blame] | 380 | mPanel.setLayoutDirection(layoutDirection); |
| 381 | updateStates(); |
| 382 | } |
| 383 | |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 384 | private void listenToRingerMode() { |
| 385 | final IntentFilter filter = new IntentFilter(); |
| 386 | filter.addAction(AudioManager.RINGER_MODE_CHANGED_ACTION); |
| 387 | mContext.registerReceiver(new BroadcastReceiver() { |
Alan Viverette | 494fb7b | 2014-04-10 18:12:56 -0700 | [diff] [blame] | 388 | @Override |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 389 | public void onReceive(Context context, Intent intent) { |
| 390 | final String action = intent.getAction(); |
| 391 | |
| 392 | if (AudioManager.RINGER_MODE_CHANGED_ACTION.equals(action)) { |
| 393 | removeMessages(MSG_RINGER_MODE_CHANGED); |
| 394 | sendMessage(obtainMessage(MSG_RINGER_MODE_CHANGED)); |
| 395 | } |
| 396 | } |
| 397 | }, filter); |
| 398 | } |
| 399 | |
| 400 | private boolean isMuted(int streamType) { |
Mike Lockwood | 8dc1dab | 2011-10-27 09:52:41 -0400 | [diff] [blame] | 401 | if (streamType == STREAM_MASTER) { |
Eric Laurent | 8c78752 | 2012-05-14 14:09:43 -0700 | [diff] [blame] | 402 | return mAudioManager.isMasterMute(); |
Jean-Michel Trivi | 3114ce3 | 2012-06-11 15:03:52 -0700 | [diff] [blame] | 403 | } else if (streamType == AudioService.STREAM_REMOTE_MUSIC) { |
John Spurlock | 3346a80 | 2014-05-20 16:25:37 -0400 | [diff] [blame] | 404 | return (mAudioManager.getRemoteStreamVolume() <= 0); |
Mike Lockwood | 8dc1dab | 2011-10-27 09:52:41 -0400 | [diff] [blame] | 405 | } else { |
Eric Laurent | 8c78752 | 2012-05-14 14:09:43 -0700 | [diff] [blame] | 406 | return mAudioManager.isStreamMute(streamType); |
Mike Lockwood | 8dc1dab | 2011-10-27 09:52:41 -0400 | [diff] [blame] | 407 | } |
| 408 | } |
| 409 | |
| 410 | private int getStreamMaxVolume(int streamType) { |
Mike Lockwood | 8dc1dab | 2011-10-27 09:52:41 -0400 | [diff] [blame] | 411 | if (streamType == STREAM_MASTER) { |
Eric Laurent | 8c78752 | 2012-05-14 14:09:43 -0700 | [diff] [blame] | 412 | return mAudioManager.getMasterMaxVolume(); |
Jean-Michel Trivi | 3114ce3 | 2012-06-11 15:03:52 -0700 | [diff] [blame] | 413 | } else if (streamType == AudioService.STREAM_REMOTE_MUSIC) { |
John Spurlock | 3346a80 | 2014-05-20 16:25:37 -0400 | [diff] [blame] | 414 | return mAudioManager.getRemoteStreamMaxVolume(); |
Mike Lockwood | 8dc1dab | 2011-10-27 09:52:41 -0400 | [diff] [blame] | 415 | } else { |
Eric Laurent | 8c78752 | 2012-05-14 14:09:43 -0700 | [diff] [blame] | 416 | return mAudioManager.getStreamMaxVolume(streamType); |
Mike Lockwood | 8dc1dab | 2011-10-27 09:52:41 -0400 | [diff] [blame] | 417 | } |
| 418 | } |
| 419 | |
| 420 | private int getStreamVolume(int streamType) { |
Mike Lockwood | 8dc1dab | 2011-10-27 09:52:41 -0400 | [diff] [blame] | 421 | if (streamType == STREAM_MASTER) { |
Eric Laurent | 8c78752 | 2012-05-14 14:09:43 -0700 | [diff] [blame] | 422 | return mAudioManager.getMasterVolume(); |
Jean-Michel Trivi | 3114ce3 | 2012-06-11 15:03:52 -0700 | [diff] [blame] | 423 | } else if (streamType == AudioService.STREAM_REMOTE_MUSIC) { |
John Spurlock | 3346a80 | 2014-05-20 16:25:37 -0400 | [diff] [blame] | 424 | return mAudioManager.getRemoteStreamVolume(); |
Mike Lockwood | 8dc1dab | 2011-10-27 09:52:41 -0400 | [diff] [blame] | 425 | } else { |
Eric Laurent | 8c78752 | 2012-05-14 14:09:43 -0700 | [diff] [blame] | 426 | return mAudioManager.getStreamVolume(streamType); |
Mike Lockwood | 8dc1dab | 2011-10-27 09:52:41 -0400 | [diff] [blame] | 427 | } |
| 428 | } |
| 429 | |
| 430 | private void setStreamVolume(int streamType, int index, int flags) { |
Mike Lockwood | 8dc1dab | 2011-10-27 09:52:41 -0400 | [diff] [blame] | 431 | if (streamType == STREAM_MASTER) { |
Eric Laurent | 8c78752 | 2012-05-14 14:09:43 -0700 | [diff] [blame] | 432 | mAudioManager.setMasterVolume(index, flags); |
Jean-Michel Trivi | 3114ce3 | 2012-06-11 15:03:52 -0700 | [diff] [blame] | 433 | } else if (streamType == AudioService.STREAM_REMOTE_MUSIC) { |
John Spurlock | 3346a80 | 2014-05-20 16:25:37 -0400 | [diff] [blame] | 434 | mAudioManager.setRemoteStreamVolume(index); |
Mike Lockwood | 8dc1dab | 2011-10-27 09:52:41 -0400 | [diff] [blame] | 435 | } else { |
Eric Laurent | 8c78752 | 2012-05-14 14:09:43 -0700 | [diff] [blame] | 436 | mAudioManager.setStreamVolume(streamType, index, flags); |
Mike Lockwood | 8dc1dab | 2011-10-27 09:52:41 -0400 | [diff] [blame] | 437 | } |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 438 | } |
| 439 | |
| 440 | private void createSliders() { |
Alan Viverette | 494fb7b | 2014-04-10 18:12:56 -0700 | [diff] [blame] | 441 | final Resources res = mContext.getResources(); |
| 442 | final LayoutInflater inflater = (LayoutInflater) mContext.getSystemService( |
| 443 | Context.LAYOUT_INFLATER_SERVICE); |
| 444 | |
Amith Yamasani | 71def77 | 2011-10-12 12:25:24 -0700 | [diff] [blame] | 445 | mStreamControls = new HashMap<Integer, StreamControl>(STREAMS.length); |
Alan Viverette | 494fb7b | 2014-04-10 18:12:56 -0700 | [diff] [blame] | 446 | |
Amith Yamasani | 71def77 | 2011-10-12 12:25:24 -0700 | [diff] [blame] | 447 | for (int i = 0; i < STREAMS.length; i++) { |
| 448 | StreamResources streamRes = STREAMS[i]; |
Alan Viverette | 494fb7b | 2014-04-10 18:12:56 -0700 | [diff] [blame] | 449 | |
| 450 | final int streamType = streamRes.streamType; |
Alan Viverette | 494fb7b | 2014-04-10 18:12:56 -0700 | [diff] [blame] | 451 | |
| 452 | final StreamControl sc = new StreamControl(); |
Amith Yamasani | d47a3aee | 2011-08-23 11:11:35 -0700 | [diff] [blame] | 453 | sc.streamType = streamType; |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 454 | sc.group = (ViewGroup) inflater.inflate( |
| 455 | com.android.systemui.R.layout.volume_panel_item, null); |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 456 | sc.group.setTag(sc); |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 457 | sc.icon = (ImageView) sc.group.findViewById(com.android.systemui.R.id.stream_icon); |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 458 | sc.icon.setTag(sc); |
Amith Yamasani | 71def77 | 2011-10-12 12:25:24 -0700 | [diff] [blame] | 459 | sc.icon.setContentDescription(res.getString(streamRes.descRes)); |
| 460 | sc.iconRes = streamRes.iconRes; |
| 461 | sc.iconMuteRes = streamRes.iconMuteRes; |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 462 | sc.icon.setImageResource(sc.iconRes); |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 463 | sc.seekbarView = (SeekBar) sc.group.findViewById(com.android.systemui.R.id.seekbar); |
Alan Viverette | 494fb7b | 2014-04-10 18:12:56 -0700 | [diff] [blame] | 464 | final int plusOne = (streamType == AudioSystem.STREAM_BLUETOOTH_SCO || |
Amith Yamasani | d47a3aee | 2011-08-23 11:11:35 -0700 | [diff] [blame] | 465 | streamType == AudioSystem.STREAM_VOICE_CALL) ? 1 : 0; |
Mike Lockwood | 8dc1dab | 2011-10-27 09:52:41 -0400 | [diff] [blame] | 466 | sc.seekbarView.setMax(getStreamMaxVolume(streamType) + plusOne); |
Alan Viverette | e8ebaf3 | 2014-04-11 15:44:15 -0700 | [diff] [blame] | 467 | sc.seekbarView.setOnSeekBarChangeListener(mSeekListener); |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 468 | sc.seekbarView.setTag(sc); |
Amith Yamasani | d47a3aee | 2011-08-23 11:11:35 -0700 | [diff] [blame] | 469 | mStreamControls.put(streamType, sc); |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 470 | } |
| 471 | } |
| 472 | |
| 473 | private void reorderSliders(int activeStreamType) { |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 474 | mSliderPanel.removeAllViews(); |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 475 | |
Alan Viverette | 494fb7b | 2014-04-10 18:12:56 -0700 | [diff] [blame] | 476 | final StreamControl active = mStreamControls.get(activeStreamType); |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 477 | if (active == null) { |
| 478 | Log.e("VolumePanel", "Missing stream type! - " + activeStreamType); |
| 479 | mActiveStreamType = -1; |
| 480 | } else { |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 481 | mSliderPanel.addView(active.group); |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 482 | mActiveStreamType = activeStreamType; |
| 483 | active.group.setVisibility(View.VISIBLE); |
| 484 | updateSlider(active); |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 485 | updateZenMode(mZenController == null ? false : mZenController.isZen()); |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 486 | } |
| 487 | } |
| 488 | |
| 489 | /** Update the mute and progress state of a slider */ |
| 490 | private void updateSlider(StreamControl sc) { |
Eric Laurent | 8c78752 | 2012-05-14 14:09:43 -0700 | [diff] [blame] | 491 | sc.seekbarView.setProgress(getStreamVolume(sc.streamType)); |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 492 | final boolean muted = isMuted(sc.streamType); |
Fabrice Di Meglio | 8c02884 | 2013-01-09 18:20:38 -0800 | [diff] [blame] | 493 | // Force reloading the image resource |
| 494 | sc.icon.setImageDrawable(null); |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 495 | sc.icon.setImageResource(muted ? sc.iconMuteRes : sc.iconRes); |
Eric Laurent | 8a51aca | 2013-03-25 18:36:35 -0700 | [diff] [blame] | 496 | if (((sc.streamType == AudioManager.STREAM_RING) || |
| 497 | (sc.streamType == AudioManager.STREAM_NOTIFICATION)) && |
Eric Laurent | 8c78752 | 2012-05-14 14:09:43 -0700 | [diff] [blame] | 498 | mAudioManager.getRingerMode() == AudioManager.RINGER_MODE_VIBRATE) { |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 499 | sc.icon.setImageResource(com.android.systemui.R.drawable.ic_ringer_vibrate); |
Amith Yamasani | c696a53 | 2011-10-28 17:02:37 -0700 | [diff] [blame] | 500 | } |
Jean-Michel Trivi | 3114ce3 | 2012-06-11 15:03:52 -0700 | [diff] [blame] | 501 | if (sc.streamType == AudioService.STREAM_REMOTE_MUSIC) { |
| 502 | // never disable touch interactions for remote playback, the muting is not tied to |
| 503 | // the state of the phone. |
| 504 | sc.seekbarView.setEnabled(true); |
Eric Laurent | fde16d5 | 2012-12-03 14:42:39 -0800 | [diff] [blame] | 505 | } else if ((sc.streamType != mAudioManager.getMasterStreamType() && muted) || |
| 506 | (sConfirmSafeVolumeDialog != null)) { |
Eric Laurent | 8c78752 | 2012-05-14 14:09:43 -0700 | [diff] [blame] | 507 | sc.seekbarView.setEnabled(false); |
| 508 | } else { |
| 509 | sc.seekbarView.setEnabled(true); |
| 510 | } |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 511 | } |
| 512 | |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 513 | public void setZenModePanelCallback(ZenModePanel.Callback callback) { |
| 514 | mZenPanelCallback = callback; |
| 515 | } |
| 516 | |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 517 | private void expand() { |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 518 | if (LOGD) Log.d(mTag, "expand mZenPanel=" + mZenPanel); |
| 519 | if (mZenPanel == null) { |
| 520 | mZenPanel = (ZenModePanel) mZenPanelStub.inflate(); |
| 521 | mZenPanel.init(mZenController); |
| 522 | mZenPanel.setCallback(new ZenModePanel.Callback() { |
| 523 | @Override |
| 524 | public void onMoreSettings() { |
| 525 | if (mZenPanelCallback != null) { |
| 526 | mZenPanelCallback.onMoreSettings(); |
| 527 | } |
| 528 | } |
| 529 | |
| 530 | @Override |
| 531 | public void onInteraction() { |
John Spurlock | 3bd4fee | 2014-05-29 20:51:09 -0400 | [diff] [blame] | 532 | resetTimeout(); |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 533 | if (mZenPanelCallback != null) { |
| 534 | mZenPanelCallback.onInteraction(); |
| 535 | } |
| 536 | } |
| 537 | }); |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 538 | } |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 539 | mZenPanel.setVisibility(View.VISIBLE); |
| 540 | mZenPanelDivider.setVisibility(View.VISIBLE); |
John Spurlock | 3bd4fee | 2014-05-29 20:51:09 -0400 | [diff] [blame] | 541 | mTimeoutDelay = TIMEOUT_DELAY_EXPANDED; |
| 542 | resetTimeout(); |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 543 | } |
| 544 | |
| 545 | private void collapse() { |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 546 | if (LOGD) Log.d(mTag, "collapse mZenPanel=" + mZenPanel); |
| 547 | if (mZenPanel != null) { |
| 548 | mZenPanel.setVisibility(View.GONE); |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 549 | } |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 550 | mZenPanelDivider.setVisibility(View.GONE); |
John Spurlock | 3bd4fee | 2014-05-29 20:51:09 -0400 | [diff] [blame] | 551 | mTimeoutDelay = TIMEOUT_DELAY; |
| 552 | resetTimeout(); |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 553 | } |
| 554 | |
Eric Laurent | fde16d5 | 2012-12-03 14:42:39 -0800 | [diff] [blame] | 555 | public void updateStates() { |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 556 | final int count = mSliderPanel.getChildCount(); |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 557 | for (int i = 0; i < count; i++) { |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 558 | StreamControl sc = (StreamControl) mSliderPanel.getChildAt(i).getTag(); |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 559 | updateSlider(sc); |
| 560 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 561 | } |
| 562 | |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 563 | private void updateZenMode(boolean zen) { |
| 564 | if (mZenModeCapable) { |
| 565 | final boolean show = mActiveStreamType == AudioManager.STREAM_NOTIFICATION |
| 566 | || mActiveStreamType == AudioManager.STREAM_RING; |
| 567 | mExpandButton.setVisibility(show ? View.VISIBLE : View.GONE); |
| 568 | mExpandDivider.setVisibility(show ? View.VISIBLE : View.GONE); |
| 569 | mExpandButton.setImageResource(zen ? com.android.systemui.R.drawable.ic_vol_zen_on |
| 570 | : com.android.systemui.R.drawable.ic_vol_zen_off); |
| 571 | } else { |
| 572 | mExpandButton.setVisibility(View.GONE); |
| 573 | mExpandDivider.setVisibility(View.GONE); |
| 574 | } |
| 575 | } |
| 576 | |
| 577 | public void postZenModeChanged(boolean zen) { |
| 578 | removeMessages(MSG_ZEN_MODE_CHANGED); |
| 579 | obtainMessage(MSG_ZEN_MODE_CHANGED, zen ? 1 : 0).sendToTarget(); |
| 580 | } |
| 581 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 582 | public void postVolumeChanged(int streamType, int flags) { |
| 583 | if (hasMessages(MSG_VOLUME_CHANGED)) return; |
Amith Yamasani | a654986 | 2012-05-30 17:29:28 -0700 | [diff] [blame] | 584 | synchronized (this) { |
| 585 | if (mStreamControls == null) { |
| 586 | createSliders(); |
| 587 | } |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 588 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 589 | removeMessages(MSG_FREE_RESOURCES); |
| 590 | obtainMessage(MSG_VOLUME_CHANGED, streamType, flags).sendToTarget(); |
| 591 | } |
| 592 | |
Jean-Michel Trivi | 3114ce3 | 2012-06-11 15:03:52 -0700 | [diff] [blame] | 593 | public void postRemoteVolumeChanged(int streamType, int flags) { |
| 594 | if (hasMessages(MSG_REMOTE_VOLUME_CHANGED)) return; |
| 595 | synchronized (this) { |
| 596 | if (mStreamControls == null) { |
| 597 | createSliders(); |
| 598 | } |
| 599 | } |
| 600 | removeMessages(MSG_FREE_RESOURCES); |
| 601 | obtainMessage(MSG_REMOTE_VOLUME_CHANGED, streamType, flags).sendToTarget(); |
| 602 | } |
| 603 | |
| 604 | public void postRemoteSliderVisibility(boolean visible) { |
| 605 | obtainMessage(MSG_SLIDER_VISIBILITY_CHANGED, |
| 606 | AudioService.STREAM_REMOTE_MUSIC, visible ? 1 : 0).sendToTarget(); |
| 607 | } |
| 608 | |
| 609 | /** |
| 610 | * Called by AudioService when it has received new remote playback information that |
| 611 | * would affect the VolumePanel display (mainly volumes). The difference with |
| 612 | * {@link #postRemoteVolumeChanged(int, int)} is that the handling of the posted message |
| 613 | * (MSG_REMOTE_VOLUME_UPDATE_IF_SHOWN) will only update the volume slider if it is being |
| 614 | * displayed. |
| 615 | * This special code path is due to the fact that remote volume updates arrive to AudioService |
| 616 | * asynchronously. So after AudioService has sent the volume update (which should be treated |
| 617 | * as a request to update the volume), the application will likely set a new volume. If the UI |
| 618 | * is still up, we need to refresh the display to show this new value. |
| 619 | */ |
| 620 | public void postHasNewRemotePlaybackInfo() { |
| 621 | if (hasMessages(MSG_REMOTE_VOLUME_UPDATE_IF_SHOWN)) return; |
| 622 | // don't create or prevent resources to be freed, if they disappear, this update came too |
| 623 | // late and shouldn't warrant the panel to be displayed longer |
| 624 | obtainMessage(MSG_REMOTE_VOLUME_UPDATE_IF_SHOWN).sendToTarget(); |
| 625 | } |
| 626 | |
Mike Lockwood | 8dc1dab | 2011-10-27 09:52:41 -0400 | [diff] [blame] | 627 | public void postMasterVolumeChanged(int flags) { |
| 628 | postVolumeChanged(STREAM_MASTER, flags); |
| 629 | } |
| 630 | |
Mike Lockwood | ce952c8 | 2011-11-14 10:47:42 -0800 | [diff] [blame] | 631 | public void postMuteChanged(int streamType, int flags) { |
| 632 | if (hasMessages(MSG_VOLUME_CHANGED)) return; |
Amith Yamasani | a654986 | 2012-05-30 17:29:28 -0700 | [diff] [blame] | 633 | synchronized (this) { |
| 634 | if (mStreamControls == null) { |
| 635 | createSliders(); |
| 636 | } |
Mike Lockwood | ce952c8 | 2011-11-14 10:47:42 -0800 | [diff] [blame] | 637 | } |
| 638 | removeMessages(MSG_FREE_RESOURCES); |
| 639 | obtainMessage(MSG_MUTE_CHANGED, streamType, flags).sendToTarget(); |
| 640 | } |
| 641 | |
| 642 | public void postMasterMuteChanged(int flags) { |
| 643 | postMuteChanged(STREAM_MASTER, flags); |
| 644 | } |
| 645 | |
Eric Laurent | fde16d5 | 2012-12-03 14:42:39 -0800 | [diff] [blame] | 646 | public void postDisplaySafeVolumeWarning(int flags) { |
Eric Laurent | 0516a9e | 2012-09-19 11:53:03 -0700 | [diff] [blame] | 647 | if (hasMessages(MSG_DISPLAY_SAFE_VOLUME_WARNING)) return; |
Eric Laurent | fde16d5 | 2012-12-03 14:42:39 -0800 | [diff] [blame] | 648 | obtainMessage(MSG_DISPLAY_SAFE_VOLUME_WARNING, flags, 0).sendToTarget(); |
Eric Laurent | c34dcc1 | 2012-09-10 13:51:52 -0700 | [diff] [blame] | 649 | } |
| 650 | |
John Spurlock | 3346a80 | 2014-05-20 16:25:37 -0400 | [diff] [blame] | 651 | public void postDismiss() { |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 652 | forceTimeout(); |
| 653 | } |
| 654 | |
| 655 | public void postLayoutDirection(int layoutDirection) { |
| 656 | removeMessages(MSG_LAYOUT_DIRECTION); |
| 657 | obtainMessage(MSG_LAYOUT_DIRECTION, layoutDirection).sendToTarget(); |
John Spurlock | 3346a80 | 2014-05-20 16:25:37 -0400 | [diff] [blame] | 658 | } |
| 659 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 660 | /** |
| 661 | * Override this if you have other work to do when the volume changes (for |
| 662 | * example, vibrating, playing a sound, etc.). Make sure to call through to |
| 663 | * the superclass implementation. |
| 664 | */ |
| 665 | protected void onVolumeChanged(int streamType, int flags) { |
| 666 | |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 667 | if (LOGD) Log.d(mTag, "onVolumeChanged(streamType: " + streamType + ", flags: " + flags + ")"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 668 | |
| 669 | if ((flags & AudioManager.FLAG_SHOW_UI) != 0) { |
Amith Yamasani | a654986 | 2012-05-30 17:29:28 -0700 | [diff] [blame] | 670 | synchronized (this) { |
| 671 | if (mActiveStreamType != streamType) { |
| 672 | reorderSliders(streamType); |
| 673 | } |
| 674 | onShowVolumeChanged(streamType, flags); |
Amith Yamasani | e3361b8 | 2011-02-10 18:20:50 -0800 | [diff] [blame] | 675 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 676 | } |
| 677 | |
Marco Nelissen | 69f593c | 2009-07-28 09:55:04 -0700 | [diff] [blame] | 678 | if ((flags & AudioManager.FLAG_PLAY_SOUND) != 0 && ! mRingIsSilent) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 679 | removeMessages(MSG_PLAY_SOUND); |
| 680 | sendMessageDelayed(obtainMessage(MSG_PLAY_SOUND, streamType, flags), PLAY_SOUND_DELAY); |
| 681 | } |
| 682 | |
| 683 | if ((flags & AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE) != 0) { |
| 684 | removeMessages(MSG_PLAY_SOUND); |
| 685 | removeMessages(MSG_VIBRATE); |
| 686 | onStopSounds(); |
| 687 | } |
| 688 | |
| 689 | removeMessages(MSG_FREE_RESOURCES); |
| 690 | sendMessageDelayed(obtainMessage(MSG_FREE_RESOURCES), FREE_DELAY); |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 691 | resetTimeout(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 692 | } |
| 693 | |
Mike Lockwood | ce952c8 | 2011-11-14 10:47:42 -0800 | [diff] [blame] | 694 | protected void onMuteChanged(int streamType, int flags) { |
| 695 | |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 696 | if (LOGD) Log.d(mTag, "onMuteChanged(streamType: " + streamType + ", flags: " + flags + ")"); |
Mike Lockwood | ce952c8 | 2011-11-14 10:47:42 -0800 | [diff] [blame] | 697 | |
| 698 | StreamControl sc = mStreamControls.get(streamType); |
| 699 | if (sc != null) { |
| 700 | sc.icon.setImageResource(isMuted(sc.streamType) ? sc.iconMuteRes : sc.iconRes); |
| 701 | } |
| 702 | |
| 703 | onVolumeChanged(streamType, flags); |
| 704 | } |
| 705 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 706 | protected void onShowVolumeChanged(int streamType, int flags) { |
Eric Laurent | 8c78752 | 2012-05-14 14:09:43 -0700 | [diff] [blame] | 707 | int index = getStreamVolume(streamType); |
Eric Laurent | d72d51c | 2011-02-03 18:47:47 -0800 | [diff] [blame] | 708 | |
Marco Nelissen | 69f593c | 2009-07-28 09:55:04 -0700 | [diff] [blame] | 709 | mRingIsSilent = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 710 | |
| 711 | if (LOGD) { |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 712 | Log.d(mTag, "onShowVolumeChanged(streamType: " + streamType |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 713 | + ", flags: " + flags + "), index: " + index); |
| 714 | } |
| 715 | |
| 716 | // get max volume for progress bar |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 717 | |
Mike Lockwood | 8dc1dab | 2011-10-27 09:52:41 -0400 | [diff] [blame] | 718 | int max = getStreamMaxVolume(streamType); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 719 | |
| 720 | switch (streamType) { |
| 721 | |
| 722 | case AudioManager.STREAM_RING: { |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 723 | // setRingerIcon(); |
Marco Nelissen | 69f593c | 2009-07-28 09:55:04 -0700 | [diff] [blame] | 724 | Uri ringuri = RingtoneManager.getActualDefaultRingtoneUri( |
| 725 | mContext, RingtoneManager.TYPE_RINGTONE); |
| 726 | if (ringuri == null) { |
Marco Nelissen | 69f593c | 2009-07-28 09:55:04 -0700 | [diff] [blame] | 727 | mRingIsSilent = true; |
| 728 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 729 | break; |
| 730 | } |
| 731 | |
| 732 | case AudioManager.STREAM_MUSIC: { |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 733 | // Special case for when Bluetooth is active for music |
Glenn Kasten | 8b4b97a | 2011-02-04 13:54:26 -0800 | [diff] [blame] | 734 | if ((mAudioManager.getDevicesForStream(AudioManager.STREAM_MUSIC) & |
| 735 | (AudioManager.DEVICE_OUT_BLUETOOTH_A2DP | |
| 736 | AudioManager.DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES | |
| 737 | AudioManager.DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER)) != 0) { |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 738 | setMusicIcon(R.drawable.ic_audio_bt, R.drawable.ic_audio_bt_mute); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 739 | } else { |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 740 | setMusicIcon(R.drawable.ic_audio_vol, R.drawable.ic_audio_vol_mute); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 741 | } |
| 742 | break; |
| 743 | } |
| 744 | |
| 745 | case AudioManager.STREAM_VOICE_CALL: { |
| 746 | /* |
| 747 | * For in-call voice call volume, there is no inaudible volume. |
| 748 | * Rescale the UI control so the progress bar doesn't go all |
| 749 | * the way to zero and don't show the mute icon. |
| 750 | */ |
| 751 | index++; |
| 752 | max++; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 753 | break; |
| 754 | } |
| 755 | |
| 756 | case AudioManager.STREAM_ALARM: { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 757 | break; |
| 758 | } |
| 759 | |
| 760 | case AudioManager.STREAM_NOTIFICATION: { |
Marco Nelissen | 69f593c | 2009-07-28 09:55:04 -0700 | [diff] [blame] | 761 | Uri ringuri = RingtoneManager.getActualDefaultRingtoneUri( |
| 762 | mContext, RingtoneManager.TYPE_NOTIFICATION); |
| 763 | if (ringuri == null) { |
Marco Nelissen | 69f593c | 2009-07-28 09:55:04 -0700 | [diff] [blame] | 764 | mRingIsSilent = true; |
| 765 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 766 | break; |
| 767 | } |
| 768 | |
| 769 | case AudioManager.STREAM_BLUETOOTH_SCO: { |
| 770 | /* |
| 771 | * For in-call voice call volume, there is no inaudible volume. |
| 772 | * Rescale the UI control so the progress bar doesn't go all |
| 773 | * the way to zero and don't show the mute icon. |
| 774 | */ |
| 775 | index++; |
| 776 | max++; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 777 | break; |
| 778 | } |
Jean-Michel Trivi | 3114ce3 | 2012-06-11 15:03:52 -0700 | [diff] [blame] | 779 | |
| 780 | case AudioService.STREAM_REMOTE_MUSIC: { |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 781 | if (LOGD) { Log.d(mTag, "showing remote volume "+index+" over "+ max); } |
Jean-Michel Trivi | 3114ce3 | 2012-06-11 15:03:52 -0700 | [diff] [blame] | 782 | break; |
| 783 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 784 | } |
| 785 | |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 786 | StreamControl sc = mStreamControls.get(streamType); |
| 787 | if (sc != null) { |
Amith Yamasani | d47a3aee | 2011-08-23 11:11:35 -0700 | [diff] [blame] | 788 | if (sc.seekbarView.getMax() != max) { |
| 789 | sc.seekbarView.setMax(max); |
| 790 | } |
Eric Laurent | 4bbcc65 | 2012-09-24 14:26:30 -0700 | [diff] [blame] | 791 | |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 792 | sc.seekbarView.setProgress(index); |
Eric Laurent | 4bbcc65 | 2012-09-24 14:26:30 -0700 | [diff] [blame] | 793 | if (((flags & AudioManager.FLAG_FIXED_VOLUME) != 0) || |
| 794 | (streamType != mAudioManager.getMasterStreamType() && |
| 795 | streamType != AudioService.STREAM_REMOTE_MUSIC && |
Eric Laurent | fde16d5 | 2012-12-03 14:42:39 -0800 | [diff] [blame] | 796 | isMuted(streamType)) || |
| 797 | sConfirmSafeVolumeDialog != null) { |
Eric Laurent | 8c78752 | 2012-05-14 14:09:43 -0700 | [diff] [blame] | 798 | sc.seekbarView.setEnabled(false); |
| 799 | } else { |
| 800 | sc.seekbarView.setEnabled(true); |
| 801 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 802 | } |
| 803 | |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 804 | if (!isShowing()) { |
Jean-Michel Trivi | 3114ce3 | 2012-06-11 15:03:52 -0700 | [diff] [blame] | 805 | int stream = (streamType == AudioService.STREAM_REMOTE_MUSIC) ? -1 : streamType; |
| 806 | // when the stream is for remote playback, use -1 to reset the stream type evaluation |
| 807 | mAudioManager.forceVolumeControlStream(stream); |
Alan Viverette | e8ebaf3 | 2014-04-11 15:44:15 -0700 | [diff] [blame] | 808 | |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 809 | // Showing dialog - use collapsed state |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 810 | if (mZenModeCapable) { |
Amith Yamasani | 42722bf | 2011-07-22 10:34:27 -0700 | [diff] [blame] | 811 | collapse(); |
| 812 | } |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 813 | if (mDialog != null) { |
| 814 | mDialog.show(); |
| 815 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 816 | } |
| 817 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 818 | // Do a little vibrate if applicable (only when going into vibrate mode) |
Jean-Michel Trivi | 3114ce3 | 2012-06-11 15:03:52 -0700 | [diff] [blame] | 819 | if ((streamType != AudioService.STREAM_REMOTE_MUSIC) && |
| 820 | ((flags & AudioManager.FLAG_VIBRATE) != 0) && |
John Spurlock | 3346a80 | 2014-05-20 16:25:37 -0400 | [diff] [blame] | 821 | mAudioManager.isStreamAffectedByRingerMode(streamType) && |
Eric Laurent | 8c78752 | 2012-05-14 14:09:43 -0700 | [diff] [blame] | 822 | mAudioManager.getRingerMode() == AudioManager.RINGER_MODE_VIBRATE) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 823 | sendMessageDelayed(obtainMessage(MSG_VIBRATE), VIBRATE_DELAY); |
| 824 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 825 | } |
| 826 | |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 827 | private boolean isShowing() { |
| 828 | return mDialog != null ? mDialog.isShowing() : mParent.isAttachedToWindow(); |
| 829 | } |
| 830 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 831 | protected void onPlaySound(int streamType, int flags) { |
| 832 | |
| 833 | if (hasMessages(MSG_STOP_SOUNDS)) { |
| 834 | removeMessages(MSG_STOP_SOUNDS); |
| 835 | // Force stop right now |
| 836 | onStopSounds(); |
| 837 | } |
| 838 | |
| 839 | synchronized (this) { |
| 840 | ToneGenerator toneGen = getOrCreateToneGenerator(streamType); |
Eric Laurent | 733a42b | 2011-01-19 10:41:57 -0800 | [diff] [blame] | 841 | if (toneGen != null) { |
| 842 | toneGen.startTone(ToneGenerator.TONE_PROP_BEEP); |
| 843 | sendMessageDelayed(obtainMessage(MSG_STOP_SOUNDS), BEEP_DURATION); |
| 844 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 845 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 846 | } |
| 847 | |
| 848 | protected void onStopSounds() { |
| 849 | |
| 850 | synchronized (this) { |
| 851 | int numStreamTypes = AudioSystem.getNumStreamTypes(); |
| 852 | for (int i = numStreamTypes - 1; i >= 0; i--) { |
| 853 | ToneGenerator toneGen = mToneGenerators[i]; |
| 854 | if (toneGen != null) { |
| 855 | toneGen.stopTone(); |
| 856 | } |
| 857 | } |
| 858 | } |
| 859 | } |
| 860 | |
| 861 | protected void onVibrate() { |
| 862 | |
| 863 | // Make sure we ended up in vibrate ringer mode |
Eric Laurent | 8c78752 | 2012-05-14 14:09:43 -0700 | [diff] [blame] | 864 | if (mAudioManager.getRingerMode() != AudioManager.RINGER_MODE_VIBRATE) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 865 | return; |
| 866 | } |
| 867 | |
John Spurlock | f9e1a0b | 2014-03-19 22:09:06 -0400 | [diff] [blame] | 868 | mVibrator.vibrate(VIBRATE_DURATION, AudioManager.STREAM_SYSTEM); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 869 | } |
| 870 | |
Jean-Michel Trivi | 3114ce3 | 2012-06-11 15:03:52 -0700 | [diff] [blame] | 871 | protected void onRemoteVolumeChanged(int streamType, int flags) { |
| 872 | // streamType is the real stream type being affected, but for the UI sliders, we |
| 873 | // refer to AudioService.STREAM_REMOTE_MUSIC. We still play the beeps on the real |
| 874 | // stream type. |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 875 | if (LOGD) Log.d(mTag, "onRemoteVolumeChanged(stream:"+streamType+", flags: " + flags + ")"); |
Jean-Michel Trivi | 3114ce3 | 2012-06-11 15:03:52 -0700 | [diff] [blame] | 876 | |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 877 | if (((flags & AudioManager.FLAG_SHOW_UI) != 0) || isShowing()) { |
Jean-Michel Trivi | 3114ce3 | 2012-06-11 15:03:52 -0700 | [diff] [blame] | 878 | synchronized (this) { |
| 879 | if (mActiveStreamType != AudioService.STREAM_REMOTE_MUSIC) { |
| 880 | reorderSliders(AudioService.STREAM_REMOTE_MUSIC); |
| 881 | } |
| 882 | onShowVolumeChanged(AudioService.STREAM_REMOTE_MUSIC, flags); |
| 883 | } |
| 884 | } else { |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 885 | if (LOGD) Log.d(mTag, "not calling onShowVolumeChanged(), no FLAG_SHOW_UI or no UI"); |
Jean-Michel Trivi | 3114ce3 | 2012-06-11 15:03:52 -0700 | [diff] [blame] | 886 | } |
| 887 | |
| 888 | if ((flags & AudioManager.FLAG_PLAY_SOUND) != 0 && ! mRingIsSilent) { |
| 889 | removeMessages(MSG_PLAY_SOUND); |
| 890 | sendMessageDelayed(obtainMessage(MSG_PLAY_SOUND, streamType, flags), PLAY_SOUND_DELAY); |
| 891 | } |
| 892 | |
| 893 | if ((flags & AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE) != 0) { |
| 894 | removeMessages(MSG_PLAY_SOUND); |
| 895 | removeMessages(MSG_VIBRATE); |
| 896 | onStopSounds(); |
| 897 | } |
| 898 | |
| 899 | removeMessages(MSG_FREE_RESOURCES); |
| 900 | sendMessageDelayed(obtainMessage(MSG_FREE_RESOURCES), FREE_DELAY); |
Jean-Michel Trivi | 3114ce3 | 2012-06-11 15:03:52 -0700 | [diff] [blame] | 901 | resetTimeout(); |
| 902 | } |
| 903 | |
| 904 | protected void onRemoteVolumeUpdateIfShown() { |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 905 | if (LOGD) Log.d(mTag, "onRemoteVolumeUpdateIfShown()"); |
| 906 | if (isShowing() |
Jean-Michel Trivi | 3114ce3 | 2012-06-11 15:03:52 -0700 | [diff] [blame] | 907 | && (mActiveStreamType == AudioService.STREAM_REMOTE_MUSIC) |
| 908 | && (mStreamControls != null)) { |
| 909 | onShowVolumeChanged(AudioService.STREAM_REMOTE_MUSIC, 0); |
| 910 | } |
| 911 | } |
| 912 | |
| 913 | |
| 914 | /** |
| 915 | * Handler for MSG_SLIDER_VISIBILITY_CHANGED |
| 916 | * Hide or show a slider |
| 917 | * @param streamType can be a valid stream type value, or VolumePanel.STREAM_MASTER, |
| 918 | * or AudioService.STREAM_REMOTE_MUSIC |
| 919 | * @param visible |
| 920 | */ |
| 921 | synchronized protected void onSliderVisibilityChanged(int streamType, int visible) { |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 922 | if (LOGD) Log.d(mTag, "onSliderVisibilityChanged(stream="+streamType+", visi="+visible+")"); |
Jean-Michel Trivi | 3114ce3 | 2012-06-11 15:03:52 -0700 | [diff] [blame] | 923 | boolean isVisible = (visible == 1); |
| 924 | for (int i = STREAMS.length - 1 ; i >= 0 ; i--) { |
| 925 | StreamResources streamRes = STREAMS[i]; |
| 926 | if (streamRes.streamType == streamType) { |
| 927 | streamRes.show = isVisible; |
| 928 | if (!isVisible && (mActiveStreamType == streamType)) { |
| 929 | mActiveStreamType = -1; |
| 930 | } |
| 931 | break; |
| 932 | } |
| 933 | } |
| 934 | } |
| 935 | |
Eric Laurent | fde16d5 | 2012-12-03 14:42:39 -0800 | [diff] [blame] | 936 | protected void onDisplaySafeVolumeWarning(int flags) { |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 937 | if ((flags & AudioManager.FLAG_SHOW_UI) != 0 || isShowing()) { |
Eric Laurent | fde16d5 | 2012-12-03 14:42:39 -0800 | [diff] [blame] | 938 | synchronized (sConfirmSafeVolumeLock) { |
| 939 | if (sConfirmSafeVolumeDialog != null) { |
| 940 | return; |
| 941 | } |
| 942 | sConfirmSafeVolumeDialog = new AlertDialog.Builder(mContext) |
| 943 | .setMessage(com.android.internal.R.string.safe_media_volume_warning) |
| 944 | .setPositiveButton(com.android.internal.R.string.yes, |
| 945 | new DialogInterface.OnClickListener() { |
Alan Viverette | e8ebaf3 | 2014-04-11 15:44:15 -0700 | [diff] [blame] | 946 | @Override |
Eric Laurent | fde16d5 | 2012-12-03 14:42:39 -0800 | [diff] [blame] | 947 | public void onClick(DialogInterface dialog, int which) { |
John Spurlock | 3346a80 | 2014-05-20 16:25:37 -0400 | [diff] [blame] | 948 | mAudioManager.disableSafeMediaVolume(); |
Eric Laurent | fde16d5 | 2012-12-03 14:42:39 -0800 | [diff] [blame] | 949 | } |
| 950 | }) |
| 951 | .setNegativeButton(com.android.internal.R.string.no, null) |
| 952 | .setIconAttribute(android.R.attr.alertDialogIcon) |
| 953 | .create(); |
| 954 | final WarningDialogReceiver warning = new WarningDialogReceiver(mContext, |
| 955 | sConfirmSafeVolumeDialog, this); |
Eric Laurent | 0516a9e | 2012-09-19 11:53:03 -0700 | [diff] [blame] | 956 | |
Eric Laurent | fde16d5 | 2012-12-03 14:42:39 -0800 | [diff] [blame] | 957 | sConfirmSafeVolumeDialog.setOnDismissListener(warning); |
| 958 | sConfirmSafeVolumeDialog.getWindow().setType( |
| 959 | WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG); |
| 960 | sConfirmSafeVolumeDialog.show(); |
| 961 | } |
| 962 | updateStates(); |
Eric Laurent | c34dcc1 | 2012-09-10 13:51:52 -0700 | [diff] [blame] | 963 | } |
Eric Laurent | fde16d5 | 2012-12-03 14:42:39 -0800 | [diff] [blame] | 964 | resetTimeout(); |
Eric Laurent | c34dcc1 | 2012-09-10 13:51:52 -0700 | [diff] [blame] | 965 | } |
| 966 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 967 | /** |
| 968 | * Lock on this VolumePanel instance as long as you use the returned ToneGenerator. |
| 969 | */ |
| 970 | private ToneGenerator getOrCreateToneGenerator(int streamType) { |
Christopher Tate | c4b78d2 | 2012-05-22 13:57:58 -0700 | [diff] [blame] | 971 | if (streamType == STREAM_MASTER) { |
| 972 | // For devices that use the master volume setting only but still want to |
| 973 | // play a volume-changed tone, direct the master volume pseudostream to |
| 974 | // the system stream's tone generator. |
| 975 | if (mPlayMasterStreamTones) { |
| 976 | streamType = AudioManager.STREAM_SYSTEM; |
| 977 | } else { |
| 978 | return null; |
| 979 | } |
| 980 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 981 | synchronized (this) { |
| 982 | if (mToneGenerators[streamType] == null) { |
Eric Laurent | 733a42b | 2011-01-19 10:41:57 -0800 | [diff] [blame] | 983 | try { |
| 984 | mToneGenerators[streamType] = new ToneGenerator(streamType, MAX_VOLUME); |
| 985 | } catch (RuntimeException e) { |
| 986 | if (LOGD) { |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 987 | Log.d(mTag, "ToneGenerator constructor failed with " |
Eric Laurent | 733a42b | 2011-01-19 10:41:57 -0800 | [diff] [blame] | 988 | + "RuntimeException: " + e); |
| 989 | } |
| 990 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 991 | } |
Eric Laurent | 733a42b | 2011-01-19 10:41:57 -0800 | [diff] [blame] | 992 | return mToneGenerators[streamType]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 993 | } |
| 994 | } |
| 995 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 996 | |
| 997 | /** |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 998 | * Switch between icons because Bluetooth music is same as music volume, but with |
| 999 | * different icons. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1000 | */ |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 1001 | private void setMusicIcon(int resId, int resMuteId) { |
| 1002 | StreamControl sc = mStreamControls.get(AudioManager.STREAM_MUSIC); |
| 1003 | if (sc != null) { |
| 1004 | sc.iconRes = resId; |
| 1005 | sc.iconMuteRes = resMuteId; |
| 1006 | sc.icon.setImageResource(isMuted(sc.streamType) ? sc.iconMuteRes : sc.iconRes); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1007 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1008 | } |
| 1009 | |
| 1010 | protected void onFreeResources() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1011 | synchronized (this) { |
| 1012 | for (int i = mToneGenerators.length - 1; i >= 0; i--) { |
| 1013 | if (mToneGenerators[i] != null) { |
| 1014 | mToneGenerators[i].release(); |
| 1015 | } |
| 1016 | mToneGenerators[i] = null; |
| 1017 | } |
| 1018 | } |
| 1019 | } |
| 1020 | |
| 1021 | @Override |
| 1022 | public void handleMessage(Message msg) { |
| 1023 | switch (msg.what) { |
| 1024 | |
| 1025 | case MSG_VOLUME_CHANGED: { |
| 1026 | onVolumeChanged(msg.arg1, msg.arg2); |
| 1027 | break; |
| 1028 | } |
| 1029 | |
Mike Lockwood | ce952c8 | 2011-11-14 10:47:42 -0800 | [diff] [blame] | 1030 | case MSG_MUTE_CHANGED: { |
| 1031 | onMuteChanged(msg.arg1, msg.arg2); |
| 1032 | break; |
| 1033 | } |
| 1034 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1035 | case MSG_FREE_RESOURCES: { |
| 1036 | onFreeResources(); |
| 1037 | break; |
| 1038 | } |
| 1039 | |
| 1040 | case MSG_STOP_SOUNDS: { |
| 1041 | onStopSounds(); |
| 1042 | break; |
| 1043 | } |
| 1044 | |
| 1045 | case MSG_PLAY_SOUND: { |
| 1046 | onPlaySound(msg.arg1, msg.arg2); |
| 1047 | break; |
| 1048 | } |
| 1049 | |
| 1050 | case MSG_VIBRATE: { |
| 1051 | onVibrate(); |
| 1052 | break; |
| 1053 | } |
| 1054 | |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 1055 | case MSG_TIMEOUT: { |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 1056 | if (isShowing()) { |
| 1057 | if (mDialog != null) { |
| 1058 | mDialog.dismiss(); |
John Spurlock | f71205c | 2014-05-29 10:17:51 -0400 | [diff] [blame] | 1059 | mActiveStreamType = -1; |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 1060 | } |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 1061 | } |
Eric Laurent | fde16d5 | 2012-12-03 14:42:39 -0800 | [diff] [blame] | 1062 | synchronized (sConfirmSafeVolumeLock) { |
| 1063 | if (sConfirmSafeVolumeDialog != null) { |
| 1064 | sConfirmSafeVolumeDialog.dismiss(); |
| 1065 | } |
| 1066 | } |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 1067 | break; |
| 1068 | } |
| 1069 | case MSG_RINGER_MODE_CHANGED: { |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 1070 | if (isShowing()) { |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 1071 | updateStates(); |
| 1072 | } |
| 1073 | break; |
| 1074 | } |
Jean-Michel Trivi | 3114ce3 | 2012-06-11 15:03:52 -0700 | [diff] [blame] | 1075 | |
| 1076 | case MSG_REMOTE_VOLUME_CHANGED: { |
| 1077 | onRemoteVolumeChanged(msg.arg1, msg.arg2); |
| 1078 | break; |
| 1079 | } |
| 1080 | |
| 1081 | case MSG_REMOTE_VOLUME_UPDATE_IF_SHOWN: |
| 1082 | onRemoteVolumeUpdateIfShown(); |
| 1083 | break; |
| 1084 | |
| 1085 | case MSG_SLIDER_VISIBILITY_CHANGED: |
| 1086 | onSliderVisibilityChanged(msg.arg1, msg.arg2); |
| 1087 | break; |
Eric Laurent | c34dcc1 | 2012-09-10 13:51:52 -0700 | [diff] [blame] | 1088 | |
| 1089 | case MSG_DISPLAY_SAFE_VOLUME_WARNING: |
Eric Laurent | fde16d5 | 2012-12-03 14:42:39 -0800 | [diff] [blame] | 1090 | onDisplaySafeVolumeWarning(msg.arg1); |
Eric Laurent | c34dcc1 | 2012-09-10 13:51:52 -0700 | [diff] [blame] | 1091 | break; |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 1092 | |
| 1093 | case MSG_LAYOUT_DIRECTION: |
| 1094 | setLayoutDirection(msg.arg1); |
| 1095 | break; |
| 1096 | |
| 1097 | case MSG_ZEN_MODE_CHANGED: |
| 1098 | updateZenMode(msg.arg1 != 0); |
| 1099 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1100 | } |
| 1101 | } |
| 1102 | |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 1103 | public void resetTimeout() { |
| 1104 | if (LOGD) Log.d(mTag, "resetTimeout at " + System.currentTimeMillis()); |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 1105 | removeMessages(MSG_TIMEOUT); |
John Spurlock | 3bd4fee | 2014-05-29 20:51:09 -0400 | [diff] [blame] | 1106 | sendEmptyMessageDelayed(MSG_TIMEOUT, mTimeoutDelay); |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 1107 | } |
| 1108 | |
Amith Yamasani | baf6dbf | 2011-08-18 17:40:29 -0700 | [diff] [blame] | 1109 | private void forceTimeout() { |
| 1110 | removeMessages(MSG_TIMEOUT); |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 1111 | sendEmptyMessage(MSG_TIMEOUT); |
| 1112 | } |
| 1113 | |
| 1114 | public ZenModeController getZenController() { |
| 1115 | return mZenController; |
Amith Yamasani | baf6dbf | 2011-08-18 17:40:29 -0700 | [diff] [blame] | 1116 | } |
| 1117 | |
Alan Viverette | e8ebaf3 | 2014-04-11 15:44:15 -0700 | [diff] [blame] | 1118 | private final OnSeekBarChangeListener mSeekListener = new OnSeekBarChangeListener() { |
| 1119 | @Override |
| 1120 | public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { |
| 1121 | final Object tag = seekBar.getTag(); |
| 1122 | if (fromUser && tag instanceof StreamControl) { |
| 1123 | StreamControl sc = (StreamControl) tag; |
| 1124 | if (getStreamVolume(sc.streamType) != progress) { |
| 1125 | setStreamVolume(sc.streamType, progress, 0); |
| 1126 | } |
| 1127 | } |
| 1128 | resetTimeout(); |
| 1129 | } |
| 1130 | |
| 1131 | @Override |
| 1132 | public void onStartTrackingTouch(SeekBar seekBar) { |
| 1133 | } |
| 1134 | |
| 1135 | @Override |
| 1136 | public void onStopTrackingTouch(SeekBar seekBar) { |
| 1137 | final Object tag = seekBar.getTag(); |
| 1138 | if (tag instanceof StreamControl) { |
| 1139 | StreamControl sc = (StreamControl) tag; |
| 1140 | // Because remote volume updates are asynchronous, AudioService |
| 1141 | // might have received a new remote volume value since the |
| 1142 | // finger adjusted the slider. So when the progress of the |
| 1143 | // slider isn't being tracked anymore, adjust the slider to the |
| 1144 | // last "published" remote volume value, so the UI reflects the |
| 1145 | // actual volume. |
| 1146 | if (sc.streamType == AudioService.STREAM_REMOTE_MUSIC) { |
| 1147 | seekBar.setProgress(getStreamVolume(AudioService.STREAM_REMOTE_MUSIC)); |
| 1148 | } |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 1149 | } |
| 1150 | } |
Alan Viverette | e8ebaf3 | 2014-04-11 15:44:15 -0700 | [diff] [blame] | 1151 | }; |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 1152 | |
Alan Viverette | e8ebaf3 | 2014-04-11 15:44:15 -0700 | [diff] [blame] | 1153 | private final View.OnClickListener mClickListener = new View.OnClickListener() { |
| 1154 | @Override |
| 1155 | public void onClick(View v) { |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 1156 | if (v == mExpandButton && mZenController != null) { |
| 1157 | final boolean newZen = !mZenController.isZen(); |
John Spurlock | 3bd4fee | 2014-05-29 20:51:09 -0400 | [diff] [blame] | 1158 | AsyncTask.execute(new Runnable() { |
| 1159 | @Override |
| 1160 | public void run() { |
| 1161 | mZenController.setZen(newZen); |
| 1162 | } |
| 1163 | }); |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 1164 | if (newZen) { |
| 1165 | expand(); |
| 1166 | } else { |
| 1167 | collapse(); |
| 1168 | } |
Jean-Michel Trivi | 3114ce3 | 2012-06-11 15:03:52 -0700 | [diff] [blame] | 1169 | } |
Alan Viverette | e8ebaf3 | 2014-04-11 15:44:15 -0700 | [diff] [blame] | 1170 | resetTimeout(); |
Jean-Michel Trivi | 3114ce3 | 2012-06-11 15:03:52 -0700 | [diff] [blame] | 1171 | } |
Alan Viverette | e8ebaf3 | 2014-04-11 15:44:15 -0700 | [diff] [blame] | 1172 | }; |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 1173 | |
| 1174 | private final ZenModeController.Callback mZenCallback = new ZenModeController.Callback() { |
| 1175 | public void onZenChanged(boolean zen) { |
| 1176 | updateZenMode(zen); |
| 1177 | } |
| 1178 | }; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1179 | } |