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