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