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; |
John Spurlock | b478252 | 2014-08-22 14:54:46 -0400 | [diff] [blame] | 22 | import android.content.ComponentName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 23 | import android.content.Context; |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 24 | import android.content.DialogInterface; |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 25 | import android.content.DialogInterface.OnDismissListener; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 26 | import android.content.Intent; |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 27 | import android.content.IntentFilter; |
John Spurlock | b478252 | 2014-08-22 14:54:46 -0400 | [diff] [blame] | 28 | import android.content.pm.PackageManager; |
John Spurlock | b478252 | 2014-08-22 14:54:46 -0400 | [diff] [blame] | 29 | import android.content.pm.ServiceInfo; |
John Spurlock | 7e6809a | 2014-08-06 16:03:14 -0400 | [diff] [blame] | 30 | import android.content.res.Configuration; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 31 | import android.content.res.Resources; |
John Spurlock | ad494bc | 2014-07-19 15:56:19 -0400 | [diff] [blame] | 32 | import android.content.res.TypedArray; |
John Spurlock | 2078caf | 2014-05-29 22:20:14 -0400 | [diff] [blame] | 33 | import android.graphics.PixelFormat; |
| 34 | import android.graphics.drawable.ColorDrawable; |
John Spurlock | 7b41467 | 2014-07-18 13:02:39 -0400 | [diff] [blame] | 35 | import android.media.AudioAttributes; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 36 | import android.media.AudioManager; |
| 37 | import android.media.AudioService; |
| 38 | import android.media.AudioSystem; |
Marco Nelissen | 69f593c | 2009-07-28 09:55:04 -0700 | [diff] [blame] | 39 | import android.media.RingtoneManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 40 | import android.media.ToneGenerator; |
RoboErik | 19c9518 | 2014-06-23 15:38:48 -0700 | [diff] [blame] | 41 | import android.media.VolumeProvider; |
| 42 | import android.media.session.MediaController; |
RoboErik | d2b8c94 | 2014-08-19 11:23:40 -0700 | [diff] [blame] | 43 | import android.media.session.MediaController.PlaybackInfo; |
Marco Nelissen | 69f593c | 2009-07-28 09:55:04 -0700 | [diff] [blame] | 44 | import android.net.Uri; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 45 | import android.os.Handler; |
| 46 | import android.os.Message; |
| 47 | import android.os.Vibrator; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 48 | import android.util.Log; |
John Spurlock | ad494bc | 2014-07-19 15:56:19 -0400 | [diff] [blame] | 49 | import android.util.SparseArray; |
John Spurlock | 2d28d6e | 2014-08-01 13:10:14 -0400 | [diff] [blame] | 50 | import android.view.KeyEvent; |
John Spurlock | 3346a80 | 2014-05-20 16:25:37 -0400 | [diff] [blame] | 51 | import android.view.LayoutInflater; |
| 52 | import android.view.MotionEvent; |
| 53 | import android.view.View; |
John Spurlock | 7f1df5e | 2014-05-31 19:11:40 -0400 | [diff] [blame] | 54 | import android.view.View.OnClickListener; |
John Spurlock | 3346a80 | 2014-05-20 16:25:37 -0400 | [diff] [blame] | 55 | import android.view.ViewGroup; |
| 56 | import android.view.Window; |
| 57 | import android.view.WindowManager; |
Amith Yamasani | 284e630 | 2011-09-16 18:24:47 -0700 | [diff] [blame] | 58 | import android.view.WindowManager.LayoutParams; |
Selim Cinek | 9f6ceb1 | 2014-08-29 16:28:39 +0200 | [diff] [blame] | 59 | import android.view.accessibility.AccessibilityManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 60 | import android.widget.ImageView; |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 61 | import android.widget.SeekBar; |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 62 | import android.widget.SeekBar.OnSeekBarChangeListener; |
John Spurlock | b478252 | 2014-08-22 14:54:46 -0400 | [diff] [blame] | 63 | import android.widget.TextView; |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 64 | |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 65 | import com.android.internal.R; |
John Spurlock | 3513460 | 2014-07-24 18:10:48 -0400 | [diff] [blame] | 66 | import com.android.systemui.statusbar.phone.SystemUIDialog; |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 67 | import com.android.systemui.statusbar.policy.ZenModeController; |
| 68 | |
John Spurlock | ad494bc | 2014-07-19 15:56:19 -0400 | [diff] [blame] | 69 | import java.io.FileDescriptor; |
| 70 | import java.io.PrintWriter; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 71 | |
| 72 | /** |
John Spurlock | 3346a80 | 2014-05-20 16:25:37 -0400 | [diff] [blame] | 73 | * Handles the user interface for the volume keys. |
Dianne Hackborn | e8ecde1 | 2011-08-03 18:55:19 -0700 | [diff] [blame] | 74 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 75 | * @hide |
| 76 | */ |
John Spurlock | 3346a80 | 2014-05-20 16:25:37 -0400 | [diff] [blame] | 77 | public class VolumePanel extends Handler { |
John Spurlock | ae641c9 | 2014-06-30 18:11:40 -0400 | [diff] [blame] | 78 | private static final String TAG = "VolumePanel"; |
| 79 | private static boolean LOGD = Log.isLoggable(TAG, Log.DEBUG); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 80 | |
John Spurlock | 3346a80 | 2014-05-20 16:25:37 -0400 | [diff] [blame] | 81 | 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] | 82 | |
| 83 | /** |
| 84 | * The delay before vibrating. This small period exists so if the user is |
| 85 | * moving to silent mode, it will not emit a short vibrate (it normally |
| 86 | * would since vibrate is between normal mode and silent mode using hardware |
| 87 | * keys). |
| 88 | */ |
| 89 | public static final int VIBRATE_DELAY = 300; |
| 90 | |
| 91 | private static final int VIBRATE_DURATION = 300; |
| 92 | private static final int BEEP_DURATION = 150; |
| 93 | private static final int MAX_VOLUME = 100; |
| 94 | private static final int FREE_DELAY = 10000; |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 95 | private static final int TIMEOUT_DELAY = 3000; |
John Spurlock | 8845da7 | 2014-07-07 21:29:48 -0400 | [diff] [blame] | 96 | private static final int TIMEOUT_DELAY_SHORT = 1500; |
John Spurlock | ea9938c | 2014-07-11 18:51:32 -0400 | [diff] [blame] | 97 | private static final int TIMEOUT_DELAY_COLLAPSED = 4500; |
John Spurlock | 3513460 | 2014-07-24 18:10:48 -0400 | [diff] [blame] | 98 | private static final int TIMEOUT_DELAY_SAFETY_WARNING = 5000; |
John Spurlock | 3bd4fee | 2014-05-29 20:51:09 -0400 | [diff] [blame] | 99 | private static final int TIMEOUT_DELAY_EXPANDED = 10000; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 100 | |
| 101 | private static final int MSG_VOLUME_CHANGED = 0; |
| 102 | private static final int MSG_FREE_RESOURCES = 1; |
| 103 | private static final int MSG_PLAY_SOUND = 2; |
| 104 | private static final int MSG_STOP_SOUNDS = 3; |
| 105 | private static final int MSG_VIBRATE = 4; |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 106 | private static final int MSG_TIMEOUT = 5; |
| 107 | private static final int MSG_RINGER_MODE_CHANGED = 6; |
Mike Lockwood | ce952c8 | 2011-11-14 10:47:42 -0800 | [diff] [blame] | 108 | private static final int MSG_MUTE_CHANGED = 7; |
Jean-Michel Trivi | 3114ce3 | 2012-06-11 15:03:52 -0700 | [diff] [blame] | 109 | private static final int MSG_REMOTE_VOLUME_CHANGED = 8; |
| 110 | private static final int MSG_REMOTE_VOLUME_UPDATE_IF_SHOWN = 9; |
| 111 | private static final int MSG_SLIDER_VISIBILITY_CHANGED = 10; |
Eric Laurent | c34dcc1 | 2012-09-10 13:51:52 -0700 | [diff] [blame] | 112 | private static final int MSG_DISPLAY_SAFE_VOLUME_WARNING = 11; |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 113 | private static final int MSG_LAYOUT_DIRECTION = 12; |
John Spurlock | 45601d6 | 2014-08-07 17:40:50 -0400 | [diff] [blame] | 114 | private static final int MSG_ZEN_MODE_AVAILABLE_CHANGED = 13; |
John Spurlock | ae641c9 | 2014-06-30 18:11:40 -0400 | [diff] [blame] | 115 | private static final int MSG_USER_ACTIVITY = 14; |
John Spurlock | b478252 | 2014-08-22 14:54:46 -0400 | [diff] [blame] | 116 | private static final int MSG_NOTIFICATION_EFFECTS_SUPPRESSOR_CHANGED = 15; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 117 | |
Mike Lockwood | 8dc1dab | 2011-10-27 09:52:41 -0400 | [diff] [blame] | 118 | // Pseudo stream type for master volume |
Mike Lockwood | 4767690 | 2011-11-08 10:31:21 -0800 | [diff] [blame] | 119 | private static final int STREAM_MASTER = -100; |
RoboErik | 2811dd3 | 2014-08-12 09:48:13 -0700 | [diff] [blame] | 120 | // Pseudo stream type for remote volume |
| 121 | private static final int STREAM_REMOTE_MUSIC = -200; |
Mike Lockwood | 8dc1dab | 2011-10-27 09:52:41 -0400 | [diff] [blame] | 122 | |
John Spurlock | 7b41467 | 2014-07-18 13:02:39 -0400 | [diff] [blame] | 123 | private static final AudioAttributes VIBRATION_ATTRIBUTES = new AudioAttributes.Builder() |
| 124 | .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION) |
| 125 | .setUsage(AudioAttributes.USAGE_ASSISTANCE_SONIFICATION) |
| 126 | .build(); |
| 127 | |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 128 | private final String mTag; |
John Spurlock | 3346a80 | 2014-05-20 16:25:37 -0400 | [diff] [blame] | 129 | protected final Context mContext; |
| 130 | private final AudioManager mAudioManager; |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 131 | private final ZenModeController mZenController; |
Marco Nelissen | 69f593c | 2009-07-28 09:55:04 -0700 | [diff] [blame] | 132 | private boolean mRingIsSilent; |
Amith Yamasani | 71def77 | 2011-10-12 12:25:24 -0700 | [diff] [blame] | 133 | private boolean mVoiceCapable; |
John Spurlock | 45601d6 | 2014-08-07 17:40:50 -0400 | [diff] [blame] | 134 | private boolean mZenModeAvailable; |
John Spurlock | 8845da7 | 2014-07-07 21:29:48 -0400 | [diff] [blame] | 135 | private boolean mZenPanelExpanded; |
John Spurlock | 3bd4fee | 2014-05-29 20:51:09 -0400 | [diff] [blame] | 136 | private int mTimeoutDelay = TIMEOUT_DELAY; |
John Spurlock | ad494bc | 2014-07-19 15:56:19 -0400 | [diff] [blame] | 137 | private float mDisabledAlpha; |
| 138 | private int mLastRingerMode = AudioManager.RINGER_MODE_NORMAL; |
| 139 | private int mLastRingerProgress = 0; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 140 | |
Christopher Tate | c4b78d2 | 2012-05-22 13:57:58 -0700 | [diff] [blame] | 141 | // True if we want to play tones on the system stream when the master stream is specified. |
| 142 | private final boolean mPlayMasterStreamTones; |
| 143 | |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 144 | |
| 145 | /** Volume panel content view */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 146 | private final View mView; |
John Spurlock | eb2727b | 2014-07-19 23:11:36 -0400 | [diff] [blame] | 147 | /** Dialog hosting the panel */ |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 148 | private final Dialog mDialog; |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 149 | |
Amith Yamasani | baf6dbf | 2011-08-18 17:40:29 -0700 | [diff] [blame] | 150 | /** The visible portion of the volume overlay */ |
| 151 | private final ViewGroup mPanel; |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 152 | /** Contains the slider and its touchable icons */ |
| 153 | private final ViewGroup mSliderPanel; |
John Spurlock | eb2727b | 2014-07-19 23:11:36 -0400 | [diff] [blame] | 154 | /** The zen mode configuration panel view */ |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 155 | private ZenModePanel mZenPanel; |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 156 | |
John Spurlock | ae641c9 | 2014-06-30 18:11:40 -0400 | [diff] [blame] | 157 | private Callback mCallback; |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 158 | |
| 159 | /** Currently active stream that shows up at the top of the list of sliders */ |
| 160 | private int mActiveStreamType = -1; |
| 161 | /** All the slider controls mapped by stream type */ |
John Spurlock | ad494bc | 2014-07-19 15:56:19 -0400 | [diff] [blame] | 162 | private SparseArray<StreamControl> mStreamControls; |
Selim Cinek | 9f6ceb1 | 2014-08-29 16:28:39 +0200 | [diff] [blame] | 163 | private final AccessibilityManager mAccessibilityManager; |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 164 | |
Amith Yamasani | 71def77 | 2011-10-12 12:25:24 -0700 | [diff] [blame] | 165 | private enum StreamResources { |
| 166 | BluetoothSCOStream(AudioManager.STREAM_BLUETOOTH_SCO, |
| 167 | R.string.volume_icon_description_bluetooth, |
| 168 | R.drawable.ic_audio_bt, |
| 169 | R.drawable.ic_audio_bt, |
| 170 | false), |
| 171 | RingerStream(AudioManager.STREAM_RING, |
| 172 | R.string.volume_icon_description_ringer, |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 173 | com.android.systemui.R.drawable.ic_ringer_audible, |
John Spurlock | ad494bc | 2014-07-19 15:56:19 -0400 | [diff] [blame] | 174 | com.android.systemui.R.drawable.ic_ringer_vibrate, |
Amith Yamasani | 71def77 | 2011-10-12 12:25:24 -0700 | [diff] [blame] | 175 | false), |
| 176 | VoiceStream(AudioManager.STREAM_VOICE_CALL, |
| 177 | R.string.volume_icon_description_incall, |
| 178 | R.drawable.ic_audio_phone, |
| 179 | R.drawable.ic_audio_phone, |
| 180 | false), |
Amith Yamasani | 92e1b2d | 2011-10-14 17:24:47 -0700 | [diff] [blame] | 181 | AlarmStream(AudioManager.STREAM_ALARM, |
| 182 | R.string.volume_alarm, |
| 183 | R.drawable.ic_audio_alarm, |
| 184 | R.drawable.ic_audio_alarm_mute, |
| 185 | false), |
Amith Yamasani | 71def77 | 2011-10-12 12:25:24 -0700 | [diff] [blame] | 186 | MediaStream(AudioManager.STREAM_MUSIC, |
| 187 | R.string.volume_icon_description_media, |
| 188 | R.drawable.ic_audio_vol, |
| 189 | R.drawable.ic_audio_vol_mute, |
| 190 | true), |
| 191 | NotificationStream(AudioManager.STREAM_NOTIFICATION, |
| 192 | R.string.volume_icon_description_notification, |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 193 | com.android.systemui.R.drawable.ic_ringer_audible, |
John Spurlock | ad494bc | 2014-07-19 15:56:19 -0400 | [diff] [blame] | 194 | com.android.systemui.R.drawable.ic_ringer_vibrate, |
Mike Lockwood | 8dc1dab | 2011-10-27 09:52:41 -0400 | [diff] [blame] | 195 | true), |
| 196 | // for now, use media resources for master volume |
| 197 | MasterStream(STREAM_MASTER, |
Jean-Michel Trivi | 3114ce3 | 2012-06-11 15:03:52 -0700 | [diff] [blame] | 198 | R.string.volume_icon_description_media, //FIXME should have its own description |
Mike Lockwood | 8dc1dab | 2011-10-27 09:52:41 -0400 | [diff] [blame] | 199 | R.drawable.ic_audio_vol, |
| 200 | R.drawable.ic_audio_vol_mute, |
Jean-Michel Trivi | 3114ce3 | 2012-06-11 15:03:52 -0700 | [diff] [blame] | 201 | false), |
RoboErik | 2811dd3 | 2014-08-12 09:48:13 -0700 | [diff] [blame] | 202 | RemoteStream(STREAM_REMOTE_MUSIC, |
Jean-Michel Trivi | 3114ce3 | 2012-06-11 15:03:52 -0700 | [diff] [blame] | 203 | R.string.volume_icon_description_media, //FIXME should have its own description |
| 204 | R.drawable.ic_media_route_on_holo_dark, |
| 205 | R.drawable.ic_media_route_disabled_holo_dark, |
| 206 | false);// will be dynamically updated |
Amith Yamasani | 71def77 | 2011-10-12 12:25:24 -0700 | [diff] [blame] | 207 | |
| 208 | int streamType; |
| 209 | int descRes; |
| 210 | int iconRes; |
| 211 | int iconMuteRes; |
| 212 | // RING, VOICE_CALL & BLUETOOTH_SCO are hidden unless explicitly requested |
| 213 | boolean show; |
| 214 | |
| 215 | StreamResources(int streamType, int descRes, int iconRes, int iconMuteRes, boolean show) { |
| 216 | this.streamType = streamType; |
| 217 | this.descRes = descRes; |
| 218 | this.iconRes = iconRes; |
| 219 | this.iconMuteRes = iconMuteRes; |
| 220 | this.show = show; |
| 221 | } |
Alan Viverette | e8ebaf3 | 2014-04-11 15:44:15 -0700 | [diff] [blame] | 222 | } |
Amith Yamasani | 71def77 | 2011-10-12 12:25:24 -0700 | [diff] [blame] | 223 | |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 224 | // List of stream types and their order |
Amith Yamasani | 71def77 | 2011-10-12 12:25:24 -0700 | [diff] [blame] | 225 | private static final StreamResources[] STREAMS = { |
| 226 | StreamResources.BluetoothSCOStream, |
| 227 | StreamResources.RingerStream, |
| 228 | StreamResources.VoiceStream, |
| 229 | StreamResources.MediaStream, |
Amith Yamasani | 92e1b2d | 2011-10-14 17:24:47 -0700 | [diff] [blame] | 230 | StreamResources.NotificationStream, |
Mike Lockwood | 8dc1dab | 2011-10-27 09:52:41 -0400 | [diff] [blame] | 231 | StreamResources.AlarmStream, |
Jean-Michel Trivi | 3114ce3 | 2012-06-11 15:03:52 -0700 | [diff] [blame] | 232 | StreamResources.MasterStream, |
| 233 | StreamResources.RemoteStream |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 234 | }; |
| 235 | |
| 236 | /** Object that contains data for each slider */ |
| 237 | private class StreamControl { |
| 238 | int streamType; |
RoboErik | 19c9518 | 2014-06-23 15:38:48 -0700 | [diff] [blame] | 239 | MediaController controller; |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 240 | ViewGroup group; |
| 241 | ImageView icon; |
| 242 | SeekBar seekbarView; |
John Spurlock | b478252 | 2014-08-22 14:54:46 -0400 | [diff] [blame] | 243 | TextView suppressorView; |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 244 | int iconRes; |
| 245 | int iconMuteRes; |
John Spurlock | b478252 | 2014-08-22 14:54:46 -0400 | [diff] [blame] | 246 | int iconSuppressedRes; |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 247 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 248 | |
| 249 | // Synchronize when accessing this |
| 250 | private ToneGenerator mToneGenerators[]; |
| 251 | private Vibrator mVibrator; |
| 252 | |
John Spurlock | 3513460 | 2014-07-24 18:10:48 -0400 | [diff] [blame] | 253 | private static AlertDialog sSafetyWarning; |
| 254 | private static Object sSafetyWarningLock = new Object(); |
Eric Laurent | c34dcc1 | 2012-09-10 13:51:52 -0700 | [diff] [blame] | 255 | |
John Spurlock | 3513460 | 2014-07-24 18:10:48 -0400 | [diff] [blame] | 256 | private static class SafetyWarning extends SystemUIDialog |
| 257 | implements DialogInterface.OnDismissListener, DialogInterface.OnClickListener { |
Eric Laurent | fde16d5 | 2012-12-03 14:42:39 -0800 | [diff] [blame] | 258 | private final Context mContext; |
Eric Laurent | fde16d5 | 2012-12-03 14:42:39 -0800 | [diff] [blame] | 259 | private final VolumePanel mVolumePanel; |
John Spurlock | 3513460 | 2014-07-24 18:10:48 -0400 | [diff] [blame] | 260 | private final AudioManager mAudioManager; |
Eric Laurent | c34dcc1 | 2012-09-10 13:51:52 -0700 | [diff] [blame] | 261 | |
John Spurlock | 2d28d6e | 2014-08-01 13:10:14 -0400 | [diff] [blame] | 262 | private boolean mNewVolumeUp; |
| 263 | |
John Spurlock | 3513460 | 2014-07-24 18:10:48 -0400 | [diff] [blame] | 264 | SafetyWarning(Context context, VolumePanel volumePanel, AudioManager audioManager) { |
| 265 | super(context); |
Eric Laurent | c34dcc1 | 2012-09-10 13:51:52 -0700 | [diff] [blame] | 266 | mContext = context; |
Eric Laurent | fde16d5 | 2012-12-03 14:42:39 -0800 | [diff] [blame] | 267 | mVolumePanel = volumePanel; |
John Spurlock | 3513460 | 2014-07-24 18:10:48 -0400 | [diff] [blame] | 268 | mAudioManager = audioManager; |
| 269 | |
| 270 | setMessage(mContext.getString(com.android.internal.R.string.safe_media_volume_warning)); |
| 271 | setButton(DialogInterface.BUTTON_POSITIVE, |
| 272 | mContext.getString(com.android.internal.R.string.yes), this); |
| 273 | setButton(DialogInterface.BUTTON_NEGATIVE, |
| 274 | mContext.getString(com.android.internal.R.string.no), (OnClickListener) null); |
| 275 | setOnDismissListener(this); |
| 276 | |
Eric Laurent | c34dcc1 | 2012-09-10 13:51:52 -0700 | [diff] [blame] | 277 | IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS); |
John Spurlock | 3513460 | 2014-07-24 18:10:48 -0400 | [diff] [blame] | 278 | context.registerReceiver(mReceiver, filter); |
Eric Laurent | c34dcc1 | 2012-09-10 13:51:52 -0700 | [diff] [blame] | 279 | } |
| 280 | |
| 281 | @Override |
John Spurlock | 2d28d6e | 2014-08-01 13:10:14 -0400 | [diff] [blame] | 282 | public boolean onKeyDown(int keyCode, KeyEvent event) { |
| 283 | if (keyCode == KeyEvent.KEYCODE_VOLUME_UP && event.getRepeatCount() == 0) { |
| 284 | mNewVolumeUp = true; |
| 285 | } |
| 286 | return super.onKeyDown(keyCode, event); |
| 287 | } |
| 288 | |
| 289 | @Override |
| 290 | public boolean onKeyUp(int keyCode, KeyEvent event) { |
| 291 | if (keyCode == KeyEvent.KEYCODE_VOLUME_UP && mNewVolumeUp) { |
| 292 | if (LOGD) Log.d(TAG, "Confirmed warning via VOLUME_UP"); |
| 293 | mAudioManager.disableSafeMediaVolume(); |
| 294 | dismiss(); |
| 295 | } |
| 296 | return super.onKeyUp(keyCode, event); |
| 297 | } |
| 298 | |
| 299 | @Override |
John Spurlock | 3513460 | 2014-07-24 18:10:48 -0400 | [diff] [blame] | 300 | public void onClick(DialogInterface dialog, int which) { |
| 301 | mAudioManager.disableSafeMediaVolume(); |
Eric Laurent | c34dcc1 | 2012-09-10 13:51:52 -0700 | [diff] [blame] | 302 | } |
| 303 | |
Alan Viverette | 494fb7b | 2014-04-10 18:12:56 -0700 | [diff] [blame] | 304 | @Override |
Eric Laurent | c34dcc1 | 2012-09-10 13:51:52 -0700 | [diff] [blame] | 305 | public void onDismiss(DialogInterface unused) { |
John Spurlock | 3513460 | 2014-07-24 18:10:48 -0400 | [diff] [blame] | 306 | mContext.unregisterReceiver(mReceiver); |
Eric Laurent | fde16d5 | 2012-12-03 14:42:39 -0800 | [diff] [blame] | 307 | cleanUp(); |
| 308 | } |
| 309 | |
| 310 | private void cleanUp() { |
John Spurlock | 3513460 | 2014-07-24 18:10:48 -0400 | [diff] [blame] | 311 | synchronized (sSafetyWarningLock) { |
| 312 | sSafetyWarning = null; |
Eric Laurent | 0516a9e | 2012-09-19 11:53:03 -0700 | [diff] [blame] | 313 | } |
John Spurlock | 1dad272 | 2014-07-11 11:07:53 -0400 | [diff] [blame] | 314 | mVolumePanel.forceTimeout(0); |
Eric Laurent | fde16d5 | 2012-12-03 14:42:39 -0800 | [diff] [blame] | 315 | mVolumePanel.updateStates(); |
Eric Laurent | c34dcc1 | 2012-09-10 13:51:52 -0700 | [diff] [blame] | 316 | } |
John Spurlock | 3513460 | 2014-07-24 18:10:48 -0400 | [diff] [blame] | 317 | |
| 318 | private final BroadcastReceiver mReceiver = new BroadcastReceiver() { |
| 319 | @Override |
| 320 | public void onReceive(Context context, Intent intent) { |
| 321 | if (Intent.ACTION_CLOSE_SYSTEM_DIALOGS.equals(intent.getAction())) { |
| 322 | if (LOGD) Log.d(TAG, "Received ACTION_CLOSE_SYSTEM_DIALOGS"); |
| 323 | cancel(); |
| 324 | cleanUp(); |
| 325 | } |
| 326 | } |
| 327 | }; |
Eric Laurent | c34dcc1 | 2012-09-10 13:51:52 -0700 | [diff] [blame] | 328 | } |
| 329 | |
John Spurlock | eb2727b | 2014-07-19 23:11:36 -0400 | [diff] [blame] | 330 | public VolumePanel(Context context, ZenModeController zenController) { |
| 331 | mTag = String.format("%s.%08x", TAG, hashCode()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 332 | mContext = context; |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 333 | mZenController = zenController; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 334 | mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); |
Selim Cinek | 9f6ceb1 | 2014-08-29 16:28:39 +0200 | [diff] [blame] | 335 | mAccessibilityManager = (AccessibilityManager) context.getSystemService( |
| 336 | Context.ACCESSIBILITY_SERVICE); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 337 | |
Mike Lockwood | 8dc1dab | 2011-10-27 09:52:41 -0400 | [diff] [blame] | 338 | // For now, only show master volume if master volume is supported |
Alan Viverette | e8ebaf3 | 2014-04-11 15:44:15 -0700 | [diff] [blame] | 339 | final Resources res = context.getResources(); |
| 340 | final boolean useMasterVolume = res.getBoolean(R.bool.config_useMasterVolume); |
Mike Lockwood | 8dc1dab | 2011-10-27 09:52:41 -0400 | [diff] [blame] | 341 | if (useMasterVolume) { |
| 342 | for (int i = 0; i < STREAMS.length; i++) { |
| 343 | StreamResources streamRes = STREAMS[i]; |
| 344 | streamRes.show = (streamRes.streamType == STREAM_MASTER); |
| 345 | } |
| 346 | } |
John Spurlock | eb2727b | 2014-07-19 23:11:36 -0400 | [diff] [blame] | 347 | if (LOGD) Log.d(mTag, "new VolumePanel"); |
| 348 | |
John Spurlock | ad494bc | 2014-07-19 15:56:19 -0400 | [diff] [blame] | 349 | mDisabledAlpha = 0.5f; |
| 350 | if (mContext.getTheme() != null) { |
| 351 | final TypedArray arr = mContext.getTheme().obtainStyledAttributes( |
| 352 | new int[] { android.R.attr.disabledAlpha }); |
| 353 | mDisabledAlpha = arr.getFloat(0, mDisabledAlpha); |
| 354 | arr.recycle(); |
| 355 | } |
| 356 | |
John Spurlock | eb2727b | 2014-07-19 23:11:36 -0400 | [diff] [blame] | 357 | mDialog = new Dialog(context) { |
| 358 | @Override |
| 359 | public boolean onTouchEvent(MotionEvent event) { |
| 360 | if (isShowing() && event.getAction() == MotionEvent.ACTION_OUTSIDE && |
John Spurlock | 3513460 | 2014-07-24 18:10:48 -0400 | [diff] [blame] | 361 | sSafetyWarning == null) { |
John Spurlock | eb2727b | 2014-07-19 23:11:36 -0400 | [diff] [blame] | 362 | forceTimeout(0); |
| 363 | return true; |
Amith Yamasani | 284e630 | 2011-09-16 18:24:47 -0700 | [diff] [blame] | 364 | } |
John Spurlock | eb2727b | 2014-07-19 23:11:36 -0400 | [diff] [blame] | 365 | return false; |
| 366 | } |
| 367 | }; |
Alan Viverette | e8ebaf3 | 2014-04-11 15:44:15 -0700 | [diff] [blame] | 368 | |
John Spurlock | eb2727b | 2014-07-19 23:11:36 -0400 | [diff] [blame] | 369 | final Window window = mDialog.getWindow(); |
John Spurlock | eb2727b | 2014-07-19 23:11:36 -0400 | [diff] [blame] | 370 | window.requestFeature(Window.FEATURE_NO_TITLE); |
John Spurlock | eb2727b | 2014-07-19 23:11:36 -0400 | [diff] [blame] | 371 | mDialog.setCanceledOnTouchOutside(true); |
| 372 | mDialog.setContentView(com.android.systemui.R.layout.volume_dialog); |
| 373 | mDialog.setOnDismissListener(new OnDismissListener() { |
| 374 | @Override |
| 375 | public void onDismiss(DialogInterface dialog) { |
| 376 | mActiveStreamType = -1; |
| 377 | mAudioManager.forceVolumeControlStream(mActiveStreamType); |
| 378 | setZenPanelVisible(false); |
| 379 | } |
| 380 | }); |
Alan Viverette | e8ebaf3 | 2014-04-11 15:44:15 -0700 | [diff] [blame] | 381 | |
John Spurlock | eb2727b | 2014-07-19 23:11:36 -0400 | [diff] [blame] | 382 | mDialog.create(); |
Alan Viverette | 494fb7b | 2014-04-10 18:12:56 -0700 | [diff] [blame] | 383 | |
John Spurlock | 7e6809a | 2014-08-06 16:03:14 -0400 | [diff] [blame] | 384 | final LayoutParams lp = window.getAttributes(); |
| 385 | lp.token = null; |
| 386 | lp.y = res.getDimensionPixelOffset(com.android.systemui.R.dimen.volume_panel_top); |
| 387 | lp.type = LayoutParams.TYPE_STATUS_BAR_PANEL; |
| 388 | lp.format = PixelFormat.TRANSLUCENT; |
| 389 | lp.windowAnimations = com.android.systemui.R.style.VolumePanelAnimation; |
| 390 | lp.setTitle(TAG); |
| 391 | window.setAttributes(lp); |
| 392 | |
| 393 | updateWidth(); |
| 394 | |
| 395 | window.setBackgroundDrawable(new ColorDrawable(0x00000000)); |
| 396 | window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); |
| 397 | window.addFlags(LayoutParams.FLAG_NOT_FOCUSABLE |
| 398 | | LayoutParams.FLAG_NOT_TOUCH_MODAL |
| 399 | | LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH |
| 400 | | LayoutParams.FLAG_HARDWARE_ACCELERATED); |
John Spurlock | eb2727b | 2014-07-19 23:11:36 -0400 | [diff] [blame] | 401 | mView = window.findViewById(R.id.content); |
| 402 | mView.setOnTouchListener(new View.OnTouchListener() { |
| 403 | @Override |
| 404 | public boolean onTouch(View v, MotionEvent event) { |
| 405 | resetTimeout(); |
| 406 | return false; |
| 407 | } |
| 408 | }); |
Alan Viverette | 494fb7b | 2014-04-10 18:12:56 -0700 | [diff] [blame] | 409 | |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 410 | mPanel = (ViewGroup) mView.findViewById(com.android.systemui.R.id.visible_panel); |
| 411 | mSliderPanel = (ViewGroup) mView.findViewById(com.android.systemui.R.id.slider_panel); |
John Spurlock | eb2727b | 2014-07-19 23:11:36 -0400 | [diff] [blame] | 412 | mZenPanel = (ZenModePanel) mView.findViewById(com.android.systemui.R.id.zen_mode_panel); |
| 413 | initZenModePanel(); |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 414 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 415 | mToneGenerators = new ToneGenerator[AudioSystem.getNumStreamTypes()]; |
Alan Viverette | e8ebaf3 | 2014-04-11 15:44:15 -0700 | [diff] [blame] | 416 | mVibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE); |
Amith Yamasani | 71def77 | 2011-10-12 12:25:24 -0700 | [diff] [blame] | 417 | mVoiceCapable = context.getResources().getBoolean(R.bool.config_voice_capable); |
Alan Viverette | e8ebaf3 | 2014-04-11 15:44:15 -0700 | [diff] [blame] | 418 | |
John Spurlock | 45601d6 | 2014-08-07 17:40:50 -0400 | [diff] [blame] | 419 | if (mZenController != null && !useMasterVolume) { |
| 420 | mZenModeAvailable = mZenController.isZenAvailable(); |
| 421 | mZenController.addCallback(mZenCallback); |
| 422 | } |
Amith Yamasani | 42722bf | 2011-07-22 10:34:27 -0700 | [diff] [blame] | 423 | |
Alan Viverette | e8ebaf3 | 2014-04-11 15:44:15 -0700 | [diff] [blame] | 424 | final boolean masterVolumeOnly = res.getBoolean(R.bool.config_useMasterVolume); |
| 425 | final boolean masterVolumeKeySounds = res.getBoolean(R.bool.config_useVolumeKeySounds); |
Christopher Tate | c4b78d2 | 2012-05-22 13:57:58 -0700 | [diff] [blame] | 426 | mPlayMasterStreamTones = masterVolumeOnly && masterVolumeKeySounds; |
| 427 | |
John Spurlock | 8c79d2e | 2014-07-24 15:15:25 -0400 | [diff] [blame] | 428 | registerReceiver(); |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 429 | } |
| 430 | |
John Spurlock | 7e6809a | 2014-08-06 16:03:14 -0400 | [diff] [blame] | 431 | public void onConfigurationChanged(Configuration newConfig) { |
| 432 | updateWidth(); |
| 433 | } |
| 434 | |
| 435 | private void updateWidth() { |
| 436 | final Resources res = mContext.getResources(); |
| 437 | final LayoutParams lp = mDialog.getWindow().getAttributes(); |
| 438 | lp.width = res.getDimensionPixelSize(com.android.systemui.R.dimen.notification_panel_width); |
| 439 | lp.gravity = |
| 440 | res.getInteger(com.android.systemui.R.integer.notification_panel_layout_gravity); |
| 441 | mDialog.getWindow().setAttributes(lp); |
| 442 | } |
| 443 | |
John Spurlock | ad494bc | 2014-07-19 15:56:19 -0400 | [diff] [blame] | 444 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 445 | pw.println("VolumePanel state:"); |
| 446 | pw.print(" mTag="); pw.println(mTag); |
| 447 | pw.print(" mRingIsSilent="); pw.println(mRingIsSilent); |
| 448 | pw.print(" mVoiceCapable="); pw.println(mVoiceCapable); |
John Spurlock | 45601d6 | 2014-08-07 17:40:50 -0400 | [diff] [blame] | 449 | pw.print(" mZenModeAvailable="); pw.println(mZenModeAvailable); |
John Spurlock | ad494bc | 2014-07-19 15:56:19 -0400 | [diff] [blame] | 450 | pw.print(" mZenPanelExpanded="); pw.println(mZenPanelExpanded); |
| 451 | pw.print(" mTimeoutDelay="); pw.println(mTimeoutDelay); |
| 452 | pw.print(" mDisabledAlpha="); pw.println(mDisabledAlpha); |
| 453 | pw.print(" mLastRingerMode="); pw.println(mLastRingerMode); |
| 454 | pw.print(" mLastRingerProgress="); pw.println(mLastRingerProgress); |
| 455 | pw.print(" mPlayMasterStreamTones="); pw.println(mPlayMasterStreamTones); |
| 456 | pw.print(" isShowing()="); pw.println(isShowing()); |
| 457 | pw.print(" mCallback="); pw.println(mCallback); |
| 458 | pw.print(" sConfirmSafeVolumeDialog="); |
John Spurlock | 3513460 | 2014-07-24 18:10:48 -0400 | [diff] [blame] | 459 | pw.println(sSafetyWarning != null ? "<not null>" : null); |
John Spurlock | ad494bc | 2014-07-19 15:56:19 -0400 | [diff] [blame] | 460 | pw.print(" mActiveStreamType="); pw.println(mActiveStreamType); |
| 461 | pw.print(" mStreamControls="); |
| 462 | if (mStreamControls == null) { |
| 463 | pw.println("null"); |
| 464 | } else { |
| 465 | final int N = mStreamControls.size(); |
| 466 | pw.print("<size "); pw.print(N); pw.println('>'); |
| 467 | for (int i = 0; i < N; i++) { |
| 468 | final StreamControl sc = mStreamControls.valueAt(i); |
| 469 | pw.print(" stream "); pw.print(sc.streamType); pw.print(":"); |
| 470 | if (sc.seekbarView != null) { |
| 471 | pw.print(" progress="); pw.print(sc.seekbarView.getProgress()); |
| 472 | pw.print(" of "); pw.print(sc.seekbarView.getMax()); |
| 473 | if (!sc.seekbarView.isEnabled()) pw.print(" (disabled)"); |
| 474 | } |
| 475 | if (sc.icon != null && sc.icon.isClickable()) pw.print(" (clickable)"); |
| 476 | pw.println(); |
| 477 | } |
| 478 | } |
| 479 | } |
| 480 | |
John Spurlock | eb2727b | 2014-07-19 23:11:36 -0400 | [diff] [blame] | 481 | private void initZenModePanel() { |
| 482 | mZenPanel.init(mZenController); |
| 483 | mZenPanel.setCallback(new ZenModePanel.Callback() { |
| 484 | @Override |
| 485 | public void onMoreSettings() { |
| 486 | if (mCallback != null) { |
| 487 | mCallback.onZenSettings(); |
| 488 | } |
| 489 | } |
| 490 | |
| 491 | @Override |
| 492 | public void onInteraction() { |
| 493 | resetTimeout(); |
| 494 | } |
| 495 | |
| 496 | @Override |
| 497 | public void onExpanded(boolean expanded) { |
| 498 | if (mZenPanelExpanded == expanded) return; |
| 499 | mZenPanelExpanded = expanded; |
| 500 | updateTimeoutDelay(); |
| 501 | resetTimeout(); |
| 502 | } |
| 503 | }); |
John Spurlock | 7f8f22a | 2014-07-02 18:54:17 -0400 | [diff] [blame] | 504 | } |
| 505 | |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 506 | private void setLayoutDirection(int layoutDirection) { |
Fabrice Di Meglio | 8c02884 | 2013-01-09 18:20:38 -0800 | [diff] [blame] | 507 | mPanel.setLayoutDirection(layoutDirection); |
| 508 | updateStates(); |
| 509 | } |
| 510 | |
John Spurlock | 8c79d2e | 2014-07-24 15:15:25 -0400 | [diff] [blame] | 511 | private void registerReceiver() { |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 512 | final IntentFilter filter = new IntentFilter(); |
| 513 | filter.addAction(AudioManager.RINGER_MODE_CHANGED_ACTION); |
John Spurlock | 8c79d2e | 2014-07-24 15:15:25 -0400 | [diff] [blame] | 514 | filter.addAction(Intent.ACTION_SCREEN_OFF); |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 515 | mContext.registerReceiver(new BroadcastReceiver() { |
Alan Viverette | 494fb7b | 2014-04-10 18:12:56 -0700 | [diff] [blame] | 516 | @Override |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 517 | public void onReceive(Context context, Intent intent) { |
| 518 | final String action = intent.getAction(); |
| 519 | |
| 520 | if (AudioManager.RINGER_MODE_CHANGED_ACTION.equals(action)) { |
| 521 | removeMessages(MSG_RINGER_MODE_CHANGED); |
| 522 | sendMessage(obtainMessage(MSG_RINGER_MODE_CHANGED)); |
| 523 | } |
John Spurlock | 8c79d2e | 2014-07-24 15:15:25 -0400 | [diff] [blame] | 524 | |
| 525 | if (Intent.ACTION_SCREEN_OFF.equals(action)) { |
| 526 | postDismiss(0); |
| 527 | } |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 528 | } |
| 529 | }, filter); |
| 530 | } |
| 531 | |
| 532 | private boolean isMuted(int streamType) { |
Mike Lockwood | 8dc1dab | 2011-10-27 09:52:41 -0400 | [diff] [blame] | 533 | if (streamType == STREAM_MASTER) { |
Eric Laurent | 8c78752 | 2012-05-14 14:09:43 -0700 | [diff] [blame] | 534 | return mAudioManager.isMasterMute(); |
RoboErik | 2811dd3 | 2014-08-12 09:48:13 -0700 | [diff] [blame] | 535 | } else if (streamType == STREAM_REMOTE_MUSIC) { |
RoboErik | 19c9518 | 2014-06-23 15:38:48 -0700 | [diff] [blame] | 536 | // TODO do we need to support a distinct mute property for remote? |
| 537 | return false; |
Mike Lockwood | 8dc1dab | 2011-10-27 09:52:41 -0400 | [diff] [blame] | 538 | } else { |
Eric Laurent | 8c78752 | 2012-05-14 14:09:43 -0700 | [diff] [blame] | 539 | return mAudioManager.isStreamMute(streamType); |
Mike Lockwood | 8dc1dab | 2011-10-27 09:52:41 -0400 | [diff] [blame] | 540 | } |
| 541 | } |
| 542 | |
| 543 | private int getStreamMaxVolume(int streamType) { |
Mike Lockwood | 8dc1dab | 2011-10-27 09:52:41 -0400 | [diff] [blame] | 544 | if (streamType == STREAM_MASTER) { |
Eric Laurent | 8c78752 | 2012-05-14 14:09:43 -0700 | [diff] [blame] | 545 | return mAudioManager.getMasterMaxVolume(); |
RoboErik | 2811dd3 | 2014-08-12 09:48:13 -0700 | [diff] [blame] | 546 | } else if (streamType == STREAM_REMOTE_MUSIC) { |
RoboErik | 19c9518 | 2014-06-23 15:38:48 -0700 | [diff] [blame] | 547 | if (mStreamControls != null) { |
| 548 | StreamControl sc = mStreamControls.get(streamType); |
| 549 | if (sc != null && sc.controller != null) { |
RoboErik | d2b8c94 | 2014-08-19 11:23:40 -0700 | [diff] [blame] | 550 | PlaybackInfo ai = sc.controller.getPlaybackInfo(); |
RoboErik | a66c40b | 2014-08-15 15:21:41 -0700 | [diff] [blame] | 551 | return ai.getMaxVolume(); |
RoboErik | 19c9518 | 2014-06-23 15:38:48 -0700 | [diff] [blame] | 552 | } |
| 553 | } |
| 554 | return -1; |
Mike Lockwood | 8dc1dab | 2011-10-27 09:52:41 -0400 | [diff] [blame] | 555 | } else { |
Eric Laurent | 8c78752 | 2012-05-14 14:09:43 -0700 | [diff] [blame] | 556 | return mAudioManager.getStreamMaxVolume(streamType); |
Mike Lockwood | 8dc1dab | 2011-10-27 09:52:41 -0400 | [diff] [blame] | 557 | } |
| 558 | } |
| 559 | |
| 560 | private int getStreamVolume(int streamType) { |
Mike Lockwood | 8dc1dab | 2011-10-27 09:52:41 -0400 | [diff] [blame] | 561 | if (streamType == STREAM_MASTER) { |
Eric Laurent | 8c78752 | 2012-05-14 14:09:43 -0700 | [diff] [blame] | 562 | return mAudioManager.getMasterVolume(); |
RoboErik | 2811dd3 | 2014-08-12 09:48:13 -0700 | [diff] [blame] | 563 | } else if (streamType == STREAM_REMOTE_MUSIC) { |
RoboErik | 19c9518 | 2014-06-23 15:38:48 -0700 | [diff] [blame] | 564 | if (mStreamControls != null) { |
| 565 | StreamControl sc = mStreamControls.get(streamType); |
| 566 | if (sc != null && sc.controller != null) { |
RoboErik | d2b8c94 | 2014-08-19 11:23:40 -0700 | [diff] [blame] | 567 | PlaybackInfo ai = sc.controller.getPlaybackInfo(); |
RoboErik | a66c40b | 2014-08-15 15:21:41 -0700 | [diff] [blame] | 568 | return ai.getCurrentVolume(); |
RoboErik | 19c9518 | 2014-06-23 15:38:48 -0700 | [diff] [blame] | 569 | } |
| 570 | } |
| 571 | return -1; |
Mike Lockwood | 8dc1dab | 2011-10-27 09:52:41 -0400 | [diff] [blame] | 572 | } else { |
Eric Laurent | 8c78752 | 2012-05-14 14:09:43 -0700 | [diff] [blame] | 573 | return mAudioManager.getStreamVolume(streamType); |
Mike Lockwood | 8dc1dab | 2011-10-27 09:52:41 -0400 | [diff] [blame] | 574 | } |
| 575 | } |
| 576 | |
RoboErik | 19c9518 | 2014-06-23 15:38:48 -0700 | [diff] [blame] | 577 | private void setStreamVolume(StreamControl sc, int index, int flags) { |
RoboErik | 2811dd3 | 2014-08-12 09:48:13 -0700 | [diff] [blame] | 578 | if (sc.streamType == STREAM_REMOTE_MUSIC) { |
RoboErik | 19c9518 | 2014-06-23 15:38:48 -0700 | [diff] [blame] | 579 | if (sc.controller != null) { |
| 580 | sc.controller.setVolumeTo(index, flags); |
| 581 | } else { |
Jean-Michel Trivi | 6582041 | 2014-06-30 12:10:44 -0700 | [diff] [blame] | 582 | Log.w(mTag, "Adjusting remote volume without a controller!"); |
RoboErik | 19c9518 | 2014-06-23 15:38:48 -0700 | [diff] [blame] | 583 | } |
| 584 | } else if (getStreamVolume(sc.streamType) != index) { |
| 585 | if (sc.streamType == STREAM_MASTER) { |
| 586 | mAudioManager.setMasterVolume(index, flags); |
| 587 | } else { |
| 588 | mAudioManager.setStreamVolume(sc.streamType, index, flags); |
| 589 | } |
Mike Lockwood | 8dc1dab | 2011-10-27 09:52:41 -0400 | [diff] [blame] | 590 | } |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 591 | } |
| 592 | |
| 593 | private void createSliders() { |
Alan Viverette | 494fb7b | 2014-04-10 18:12:56 -0700 | [diff] [blame] | 594 | final Resources res = mContext.getResources(); |
| 595 | final LayoutInflater inflater = (LayoutInflater) mContext.getSystemService( |
| 596 | Context.LAYOUT_INFLATER_SERVICE); |
| 597 | |
John Spurlock | ad494bc | 2014-07-19 15:56:19 -0400 | [diff] [blame] | 598 | mStreamControls = new SparseArray<StreamControl>(STREAMS.length); |
Alan Viverette | 494fb7b | 2014-04-10 18:12:56 -0700 | [diff] [blame] | 599 | |
Amith Yamasani | 71def77 | 2011-10-12 12:25:24 -0700 | [diff] [blame] | 600 | for (int i = 0; i < STREAMS.length; i++) { |
| 601 | StreamResources streamRes = STREAMS[i]; |
Alan Viverette | 494fb7b | 2014-04-10 18:12:56 -0700 | [diff] [blame] | 602 | |
| 603 | final int streamType = streamRes.streamType; |
Alan Viverette | 494fb7b | 2014-04-10 18:12:56 -0700 | [diff] [blame] | 604 | |
| 605 | final StreamControl sc = new StreamControl(); |
Amith Yamasani | d47a3aee | 2011-08-23 11:11:35 -0700 | [diff] [blame] | 606 | sc.streamType = streamType; |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 607 | sc.group = (ViewGroup) inflater.inflate( |
| 608 | com.android.systemui.R.layout.volume_panel_item, null); |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 609 | sc.group.setTag(sc); |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 610 | 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] | 611 | sc.icon.setTag(sc); |
Amith Yamasani | 71def77 | 2011-10-12 12:25:24 -0700 | [diff] [blame] | 612 | sc.icon.setContentDescription(res.getString(streamRes.descRes)); |
| 613 | sc.iconRes = streamRes.iconRes; |
| 614 | sc.iconMuteRes = streamRes.iconMuteRes; |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 615 | sc.icon.setImageResource(sc.iconRes); |
John Spurlock | 7f1df5e | 2014-05-31 19:11:40 -0400 | [diff] [blame] | 616 | sc.icon.setClickable(isNotificationOrRing(streamType)); |
| 617 | if (sc.icon.isClickable()) { |
John Spurlock | ab4ea76 | 2014-07-19 18:50:16 -0400 | [diff] [blame] | 618 | sc.icon.setSoundEffectsEnabled(false); |
John Spurlock | 7f1df5e | 2014-05-31 19:11:40 -0400 | [diff] [blame] | 619 | sc.icon.setOnClickListener(new OnClickListener() { |
| 620 | @Override |
| 621 | public void onClick(View v) { |
| 622 | resetTimeout(); |
| 623 | toggle(sc); |
| 624 | } |
| 625 | }); |
John Spurlock | b478252 | 2014-08-22 14:54:46 -0400 | [diff] [blame] | 626 | sc.iconSuppressedRes = com.android.systemui.R.drawable.ic_ringer_mute; |
John Spurlock | 7f1df5e | 2014-05-31 19:11:40 -0400 | [diff] [blame] | 627 | } |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 628 | sc.seekbarView = (SeekBar) sc.group.findViewById(com.android.systemui.R.id.seekbar); |
John Spurlock | b478252 | 2014-08-22 14:54:46 -0400 | [diff] [blame] | 629 | sc.suppressorView = |
| 630 | (TextView) sc.group.findViewById(com.android.systemui.R.id.suppressor); |
| 631 | sc.suppressorView.setVisibility(View.GONE); |
Alan Viverette | 494fb7b | 2014-04-10 18:12:56 -0700 | [diff] [blame] | 632 | final int plusOne = (streamType == AudioSystem.STREAM_BLUETOOTH_SCO || |
Amith Yamasani | d47a3aee | 2011-08-23 11:11:35 -0700 | [diff] [blame] | 633 | streamType == AudioSystem.STREAM_VOICE_CALL) ? 1 : 0; |
Mike Lockwood | 8dc1dab | 2011-10-27 09:52:41 -0400 | [diff] [blame] | 634 | sc.seekbarView.setMax(getStreamMaxVolume(streamType) + plusOne); |
Alan Viverette | e8ebaf3 | 2014-04-11 15:44:15 -0700 | [diff] [blame] | 635 | sc.seekbarView.setOnSeekBarChangeListener(mSeekListener); |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 636 | sc.seekbarView.setTag(sc); |
Amith Yamasani | d47a3aee | 2011-08-23 11:11:35 -0700 | [diff] [blame] | 637 | mStreamControls.put(streamType, sc); |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 638 | } |
| 639 | } |
| 640 | |
John Spurlock | 7f1df5e | 2014-05-31 19:11:40 -0400 | [diff] [blame] | 641 | private void toggle(StreamControl sc) { |
| 642 | if (mAudioManager.getRingerMode() == AudioManager.RINGER_MODE_NORMAL) { |
| 643 | mAudioManager.setRingerMode(AudioManager.RINGER_MODE_VIBRATE); |
| 644 | postVolumeChanged(sc.streamType, AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_VIBRATE); |
| 645 | } else { |
| 646 | mAudioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL); |
| 647 | postVolumeChanged(sc.streamType, AudioManager.FLAG_PLAY_SOUND); |
| 648 | } |
| 649 | } |
| 650 | |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 651 | private void reorderSliders(int activeStreamType) { |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 652 | mSliderPanel.removeAllViews(); |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 653 | |
Alan Viverette | 494fb7b | 2014-04-10 18:12:56 -0700 | [diff] [blame] | 654 | final StreamControl active = mStreamControls.get(activeStreamType); |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 655 | if (active == null) { |
John Spurlock | ae641c9 | 2014-06-30 18:11:40 -0400 | [diff] [blame] | 656 | Log.e(TAG, "Missing stream type! - " + activeStreamType); |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 657 | mActiveStreamType = -1; |
| 658 | } else { |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 659 | mSliderPanel.addView(active.group); |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 660 | mActiveStreamType = activeStreamType; |
| 661 | active.group.setVisibility(View.VISIBLE); |
| 662 | updateSlider(active); |
John Spurlock | 8845da7 | 2014-07-07 21:29:48 -0400 | [diff] [blame] | 663 | updateTimeoutDelay(); |
John Spurlock | 45601d6 | 2014-08-07 17:40:50 -0400 | [diff] [blame] | 664 | updateZenPanelVisible(); |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 665 | } |
| 666 | } |
| 667 | |
John Spurlock | ad494bc | 2014-07-19 15:56:19 -0400 | [diff] [blame] | 668 | private void updateSliderProgress(StreamControl sc, int progress) { |
| 669 | final boolean isRinger = isNotificationOrRing(sc.streamType); |
| 670 | if (isRinger && mAudioManager.getRingerMode() == AudioManager.RINGER_MODE_SILENT) { |
| 671 | progress = mLastRingerProgress; |
| 672 | } |
| 673 | if (progress < 0) { |
| 674 | progress = getStreamVolume(sc.streamType); |
| 675 | } |
| 676 | sc.seekbarView.setProgress(progress); |
| 677 | if (isRinger) { |
| 678 | mLastRingerProgress = progress; |
| 679 | } |
| 680 | } |
| 681 | |
| 682 | private void updateSliderIcon(StreamControl sc, boolean muted) { |
| 683 | if (isNotificationOrRing(sc.streamType)) { |
| 684 | int ringerMode = mAudioManager.getRingerMode(); |
| 685 | if (ringerMode == AudioManager.RINGER_MODE_SILENT) { |
| 686 | ringerMode = mLastRingerMode; |
| 687 | } else { |
| 688 | mLastRingerMode = ringerMode; |
| 689 | } |
| 690 | muted = ringerMode == AudioManager.RINGER_MODE_VIBRATE; |
| 691 | } |
| 692 | sc.icon.setImageResource(muted ? sc.iconMuteRes : sc.iconRes); |
| 693 | } |
| 694 | |
John Spurlock | b478252 | 2014-08-22 14:54:46 -0400 | [diff] [blame] | 695 | private void updateSliderSupressor(StreamControl sc) { |
| 696 | final ComponentName suppressor = isNotificationOrRing(sc.streamType) |
| 697 | ? mZenController.getEffectsSuppressor() : null; |
| 698 | if (suppressor == null) { |
| 699 | sc.seekbarView.setVisibility(View.VISIBLE); |
| 700 | sc.suppressorView.setVisibility(View.GONE); |
| 701 | } else { |
| 702 | sc.seekbarView.setVisibility(View.GONE); |
| 703 | sc.suppressorView.setVisibility(View.VISIBLE); |
| 704 | sc.suppressorView.setText(mContext.getString(com.android.systemui.R.string.muted_by, |
| 705 | getSuppressorCaption(suppressor))); |
| 706 | sc.icon.setImageResource(sc.iconSuppressedRes); |
| 707 | } |
| 708 | } |
| 709 | |
| 710 | private String getSuppressorCaption(ComponentName suppressor) { |
| 711 | final PackageManager pm = mContext.getPackageManager(); |
| 712 | try { |
| 713 | final ServiceInfo info = pm.getServiceInfo(suppressor, 0); |
| 714 | if (info != null) { |
| 715 | final CharSequence seq = info.loadLabel(pm); |
| 716 | if (seq != null) { |
| 717 | final String str = seq.toString().trim(); |
| 718 | if (str.length() > 0) { |
| 719 | return str; |
| 720 | } |
| 721 | } |
| 722 | } |
| 723 | } catch (Throwable e) { |
| 724 | Log.w(TAG, "Error loading suppressor caption", e); |
| 725 | } |
| 726 | return suppressor.getPackageName(); |
| 727 | } |
| 728 | |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 729 | /** Update the mute and progress state of a slider */ |
| 730 | private void updateSlider(StreamControl sc) { |
John Spurlock | ad494bc | 2014-07-19 15:56:19 -0400 | [diff] [blame] | 731 | updateSliderProgress(sc, -1); |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 732 | final boolean muted = isMuted(sc.streamType); |
Fabrice Di Meglio | 8c02884 | 2013-01-09 18:20:38 -0800 | [diff] [blame] | 733 | // Force reloading the image resource |
| 734 | sc.icon.setImageDrawable(null); |
John Spurlock | ad494bc | 2014-07-19 15:56:19 -0400 | [diff] [blame] | 735 | updateSliderIcon(sc, muted); |
John Spurlock | 7f1df5e | 2014-05-31 19:11:40 -0400 | [diff] [blame] | 736 | updateSliderEnabled(sc, muted, false); |
John Spurlock | b478252 | 2014-08-22 14:54:46 -0400 | [diff] [blame] | 737 | updateSliderSupressor(sc); |
John Spurlock | 7f1df5e | 2014-05-31 19:11:40 -0400 | [diff] [blame] | 738 | } |
| 739 | |
John Spurlock | 5f640e4 | 2014-05-31 20:15:59 -0400 | [diff] [blame] | 740 | private void updateSliderEnabled(final StreamControl sc, boolean muted, boolean fixedVolume) { |
| 741 | final boolean wasEnabled = sc.seekbarView.isEnabled(); |
John Spurlock | ae641c9 | 2014-06-30 18:11:40 -0400 | [diff] [blame] | 742 | final boolean isRinger = isNotificationOrRing(sc.streamType); |
RoboErik | 2811dd3 | 2014-08-12 09:48:13 -0700 | [diff] [blame] | 743 | if (sc.streamType == STREAM_REMOTE_MUSIC) { |
Jean-Michel Trivi | 3114ce3 | 2012-06-11 15:03:52 -0700 | [diff] [blame] | 744 | // never disable touch interactions for remote playback, the muting is not tied to |
| 745 | // the state of the phone. |
RoboErik | 19c9518 | 2014-06-23 15:38:48 -0700 | [diff] [blame] | 746 | sc.seekbarView.setEnabled(!fixedVolume); |
John Spurlock | ae641c9 | 2014-06-30 18:11:40 -0400 | [diff] [blame] | 747 | } else if (isRinger && mAudioManager.getRingerMode() == AudioManager.RINGER_MODE_SILENT) { |
John Spurlock | 7f1df5e | 2014-05-31 19:11:40 -0400 | [diff] [blame] | 748 | sc.seekbarView.setEnabled(false); |
John Spurlock | ae641c9 | 2014-06-30 18:11:40 -0400 | [diff] [blame] | 749 | sc.icon.setEnabled(false); |
John Spurlock | ad494bc | 2014-07-19 15:56:19 -0400 | [diff] [blame] | 750 | sc.icon.setAlpha(mDisabledAlpha); |
John Spurlock | ae641c9 | 2014-06-30 18:11:40 -0400 | [diff] [blame] | 751 | sc.icon.setClickable(false); |
John Spurlock | 4f0f120 | 2014-08-05 13:28:33 -0400 | [diff] [blame] | 752 | } else if (fixedVolume || |
| 753 | (sc.streamType != mAudioManager.getMasterStreamType() && muted) || |
| 754 | (sSafetyWarning != null)) { |
| 755 | sc.seekbarView.setEnabled(false); |
Eric Laurent | 8c78752 | 2012-05-14 14:09:43 -0700 | [diff] [blame] | 756 | } else { |
| 757 | sc.seekbarView.setEnabled(true); |
John Spurlock | ae641c9 | 2014-06-30 18:11:40 -0400 | [diff] [blame] | 758 | sc.icon.setEnabled(true); |
John Spurlock | ad494bc | 2014-07-19 15:56:19 -0400 | [diff] [blame] | 759 | sc.icon.setAlpha(1f); |
Eric Laurent | 8c78752 | 2012-05-14 14:09:43 -0700 | [diff] [blame] | 760 | } |
John Spurlock | ae641c9 | 2014-06-30 18:11:40 -0400 | [diff] [blame] | 761 | // show the silent hint when the disabled slider is touched in silent mode |
| 762 | if (isRinger && wasEnabled != sc.seekbarView.isEnabled()) { |
John Spurlock | 5f640e4 | 2014-05-31 20:15:59 -0400 | [diff] [blame] | 763 | if (sc.seekbarView.isEnabled()) { |
John Spurlock | ae641c9 | 2014-06-30 18:11:40 -0400 | [diff] [blame] | 764 | sc.group.setOnTouchListener(null); |
| 765 | sc.icon.setClickable(true); |
John Spurlock | 5f640e4 | 2014-05-31 20:15:59 -0400 | [diff] [blame] | 766 | } else { |
John Spurlock | ae641c9 | 2014-06-30 18:11:40 -0400 | [diff] [blame] | 767 | final View.OnTouchListener showHintOnTouch = new View.OnTouchListener() { |
John Spurlock | 5f640e4 | 2014-05-31 20:15:59 -0400 | [diff] [blame] | 768 | @Override |
| 769 | public boolean onTouch(View v, MotionEvent event) { |
| 770 | resetTimeout(); |
John Spurlock | ae641c9 | 2014-06-30 18:11:40 -0400 | [diff] [blame] | 771 | showSilentHint(); |
John Spurlock | 5f640e4 | 2014-05-31 20:15:59 -0400 | [diff] [blame] | 772 | return false; |
| 773 | } |
John Spurlock | ae641c9 | 2014-06-30 18:11:40 -0400 | [diff] [blame] | 774 | }; |
| 775 | sc.group.setOnTouchListener(showHintOnTouch); |
John Spurlock | 5f640e4 | 2014-05-31 20:15:59 -0400 | [diff] [blame] | 776 | } |
| 777 | } |
| 778 | } |
| 779 | |
John Spurlock | ae641c9 | 2014-06-30 18:11:40 -0400 | [diff] [blame] | 780 | private void showSilentHint() { |
| 781 | if (mZenPanel != null) { |
| 782 | mZenPanel.showSilentHint(); |
| 783 | } |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 784 | } |
| 785 | |
John Spurlock | 7f1df5e | 2014-05-31 19:11:40 -0400 | [diff] [blame] | 786 | private static boolean isNotificationOrRing(int streamType) { |
| 787 | return streamType == AudioManager.STREAM_RING |
| 788 | || streamType == AudioManager.STREAM_NOTIFICATION; |
| 789 | } |
| 790 | |
John Spurlock | ae641c9 | 2014-06-30 18:11:40 -0400 | [diff] [blame] | 791 | public void setCallback(Callback callback) { |
| 792 | mCallback = callback; |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 793 | } |
| 794 | |
John Spurlock | 8845da7 | 2014-07-07 21:29:48 -0400 | [diff] [blame] | 795 | private void updateTimeoutDelay() { |
Selim Cinek | 1cf8906 | 2014-08-29 19:21:44 +0200 | [diff] [blame^] | 796 | mTimeoutDelay = sSafetyWarning != null ? TIMEOUT_DELAY_SAFETY_WARNING |
John Spurlock | 3513460 | 2014-07-24 18:10:48 -0400 | [diff] [blame] | 797 | : mActiveStreamType == AudioManager.STREAM_MUSIC ? TIMEOUT_DELAY_SHORT |
John Spurlock | ea9938c | 2014-07-11 18:51:32 -0400 | [diff] [blame] | 798 | : mZenPanelExpanded ? TIMEOUT_DELAY_EXPANDED |
| 799 | : isZenPanelVisible() ? TIMEOUT_DELAY_COLLAPSED |
| 800 | : TIMEOUT_DELAY; |
| 801 | } |
| 802 | |
| 803 | private boolean isZenPanelVisible() { |
| 804 | return mZenPanel != null && mZenPanel.getVisibility() == View.VISIBLE; |
John Spurlock | 8845da7 | 2014-07-07 21:29:48 -0400 | [diff] [blame] | 805 | } |
| 806 | |
John Spurlock | ae641c9 | 2014-06-30 18:11:40 -0400 | [diff] [blame] | 807 | private void setZenPanelVisible(boolean visible) { |
| 808 | if (LOGD) Log.d(mTag, "setZenPanelVisible " + visible + " mZenPanel=" + mZenPanel); |
John Spurlock | ea9938c | 2014-07-11 18:51:32 -0400 | [diff] [blame] | 809 | final boolean changing = visible != isZenPanelVisible(); |
John Spurlock | ae641c9 | 2014-06-30 18:11:40 -0400 | [diff] [blame] | 810 | if (visible) { |
John Spurlock | eb2727b | 2014-07-19 23:11:36 -0400 | [diff] [blame] | 811 | mZenPanel.setHidden(false); |
John Spurlock | ae641c9 | 2014-06-30 18:11:40 -0400 | [diff] [blame] | 812 | resetTimeout(); |
| 813 | } else { |
John Spurlock | eb2727b | 2014-07-19 23:11:36 -0400 | [diff] [blame] | 814 | mZenPanel.setHidden(true); |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 815 | } |
John Spurlock | ea9938c | 2014-07-11 18:51:32 -0400 | [diff] [blame] | 816 | if (changing) { |
| 817 | updateTimeoutDelay(); |
| 818 | resetTimeout(); |
| 819 | } |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 820 | } |
| 821 | |
Eric Laurent | fde16d5 | 2012-12-03 14:42:39 -0800 | [diff] [blame] | 822 | public void updateStates() { |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 823 | final int count = mSliderPanel.getChildCount(); |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 824 | for (int i = 0; i < count; i++) { |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 825 | StreamControl sc = (StreamControl) mSliderPanel.getChildAt(i).getTag(); |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 826 | updateSlider(sc); |
| 827 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 828 | } |
| 829 | |
John Spurlock | 45601d6 | 2014-08-07 17:40:50 -0400 | [diff] [blame] | 830 | private void updateZenPanelVisible() { |
| 831 | setZenPanelVisible(mZenModeAvailable && isNotificationOrRing(mActiveStreamType)); |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 832 | } |
| 833 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 834 | public void postVolumeChanged(int streamType, int flags) { |
| 835 | if (hasMessages(MSG_VOLUME_CHANGED)) return; |
Amith Yamasani | a654986 | 2012-05-30 17:29:28 -0700 | [diff] [blame] | 836 | synchronized (this) { |
| 837 | if (mStreamControls == null) { |
| 838 | createSliders(); |
| 839 | } |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 840 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 841 | removeMessages(MSG_FREE_RESOURCES); |
| 842 | obtainMessage(MSG_VOLUME_CHANGED, streamType, flags).sendToTarget(); |
| 843 | } |
| 844 | |
RoboErik | 19c9518 | 2014-06-23 15:38:48 -0700 | [diff] [blame] | 845 | public void postRemoteVolumeChanged(MediaController controller, int flags) { |
Jean-Michel Trivi | 3114ce3 | 2012-06-11 15:03:52 -0700 | [diff] [blame] | 846 | if (hasMessages(MSG_REMOTE_VOLUME_CHANGED)) return; |
| 847 | synchronized (this) { |
| 848 | if (mStreamControls == null) { |
| 849 | createSliders(); |
| 850 | } |
| 851 | } |
| 852 | removeMessages(MSG_FREE_RESOURCES); |
RoboErik | 19c9518 | 2014-06-23 15:38:48 -0700 | [diff] [blame] | 853 | obtainMessage(MSG_REMOTE_VOLUME_CHANGED, flags, 0, controller).sendToTarget(); |
Jean-Michel Trivi | 3114ce3 | 2012-06-11 15:03:52 -0700 | [diff] [blame] | 854 | } |
| 855 | |
| 856 | public void postRemoteSliderVisibility(boolean visible) { |
| 857 | obtainMessage(MSG_SLIDER_VISIBILITY_CHANGED, |
RoboErik | 2811dd3 | 2014-08-12 09:48:13 -0700 | [diff] [blame] | 858 | STREAM_REMOTE_MUSIC, visible ? 1 : 0).sendToTarget(); |
Jean-Michel Trivi | 3114ce3 | 2012-06-11 15:03:52 -0700 | [diff] [blame] | 859 | } |
| 860 | |
| 861 | /** |
| 862 | * Called by AudioService when it has received new remote playback information that |
| 863 | * would affect the VolumePanel display (mainly volumes). The difference with |
| 864 | * {@link #postRemoteVolumeChanged(int, int)} is that the handling of the posted message |
| 865 | * (MSG_REMOTE_VOLUME_UPDATE_IF_SHOWN) will only update the volume slider if it is being |
| 866 | * displayed. |
| 867 | * This special code path is due to the fact that remote volume updates arrive to AudioService |
| 868 | * asynchronously. So after AudioService has sent the volume update (which should be treated |
| 869 | * as a request to update the volume), the application will likely set a new volume. If the UI |
| 870 | * is still up, we need to refresh the display to show this new value. |
| 871 | */ |
| 872 | public void postHasNewRemotePlaybackInfo() { |
| 873 | if (hasMessages(MSG_REMOTE_VOLUME_UPDATE_IF_SHOWN)) return; |
| 874 | // don't create or prevent resources to be freed, if they disappear, this update came too |
| 875 | // late and shouldn't warrant the panel to be displayed longer |
| 876 | obtainMessage(MSG_REMOTE_VOLUME_UPDATE_IF_SHOWN).sendToTarget(); |
| 877 | } |
| 878 | |
Mike Lockwood | 8dc1dab | 2011-10-27 09:52:41 -0400 | [diff] [blame] | 879 | public void postMasterVolumeChanged(int flags) { |
| 880 | postVolumeChanged(STREAM_MASTER, flags); |
| 881 | } |
| 882 | |
Mike Lockwood | ce952c8 | 2011-11-14 10:47:42 -0800 | [diff] [blame] | 883 | public void postMuteChanged(int streamType, int flags) { |
| 884 | if (hasMessages(MSG_VOLUME_CHANGED)) return; |
Amith Yamasani | a654986 | 2012-05-30 17:29:28 -0700 | [diff] [blame] | 885 | synchronized (this) { |
| 886 | if (mStreamControls == null) { |
| 887 | createSliders(); |
| 888 | } |
Mike Lockwood | ce952c8 | 2011-11-14 10:47:42 -0800 | [diff] [blame] | 889 | } |
| 890 | removeMessages(MSG_FREE_RESOURCES); |
| 891 | obtainMessage(MSG_MUTE_CHANGED, streamType, flags).sendToTarget(); |
| 892 | } |
| 893 | |
| 894 | public void postMasterMuteChanged(int flags) { |
| 895 | postMuteChanged(STREAM_MASTER, flags); |
| 896 | } |
| 897 | |
Eric Laurent | fde16d5 | 2012-12-03 14:42:39 -0800 | [diff] [blame] | 898 | public void postDisplaySafeVolumeWarning(int flags) { |
Eric Laurent | 0516a9e | 2012-09-19 11:53:03 -0700 | [diff] [blame] | 899 | if (hasMessages(MSG_DISPLAY_SAFE_VOLUME_WARNING)) return; |
Eric Laurent | fde16d5 | 2012-12-03 14:42:39 -0800 | [diff] [blame] | 900 | obtainMessage(MSG_DISPLAY_SAFE_VOLUME_WARNING, flags, 0).sendToTarget(); |
Eric Laurent | c34dcc1 | 2012-09-10 13:51:52 -0700 | [diff] [blame] | 901 | } |
| 902 | |
John Spurlock | 1dad272 | 2014-07-11 11:07:53 -0400 | [diff] [blame] | 903 | public void postDismiss(long delay) { |
| 904 | forceTimeout(delay); |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 905 | } |
| 906 | |
| 907 | public void postLayoutDirection(int layoutDirection) { |
| 908 | removeMessages(MSG_LAYOUT_DIRECTION); |
John Spurlock | 84da84c | 2014-05-31 22:21:52 -0400 | [diff] [blame] | 909 | obtainMessage(MSG_LAYOUT_DIRECTION, layoutDirection, 0).sendToTarget(); |
John Spurlock | 3346a80 | 2014-05-20 16:25:37 -0400 | [diff] [blame] | 910 | } |
| 911 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 912 | /** |
| 913 | * Override this if you have other work to do when the volume changes (for |
| 914 | * example, vibrating, playing a sound, etc.). Make sure to call through to |
| 915 | * the superclass implementation. |
| 916 | */ |
| 917 | protected void onVolumeChanged(int streamType, int flags) { |
| 918 | |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 919 | 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] | 920 | |
| 921 | if ((flags & AudioManager.FLAG_SHOW_UI) != 0) { |
Amith Yamasani | a654986 | 2012-05-30 17:29:28 -0700 | [diff] [blame] | 922 | synchronized (this) { |
| 923 | if (mActiveStreamType != streamType) { |
| 924 | reorderSliders(streamType); |
| 925 | } |
RoboErik | 19c9518 | 2014-06-23 15:38:48 -0700 | [diff] [blame] | 926 | onShowVolumeChanged(streamType, flags, null); |
Amith Yamasani | e3361b8 | 2011-02-10 18:20:50 -0800 | [diff] [blame] | 927 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 928 | } |
| 929 | |
Marco Nelissen | 69f593c | 2009-07-28 09:55:04 -0700 | [diff] [blame] | 930 | if ((flags & AudioManager.FLAG_PLAY_SOUND) != 0 && ! mRingIsSilent) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 931 | removeMessages(MSG_PLAY_SOUND); |
| 932 | sendMessageDelayed(obtainMessage(MSG_PLAY_SOUND, streamType, flags), PLAY_SOUND_DELAY); |
| 933 | } |
| 934 | |
| 935 | if ((flags & AudioManager.FLAG_REMOVE_SOUND_AND_VIBRATE) != 0) { |
| 936 | removeMessages(MSG_PLAY_SOUND); |
| 937 | removeMessages(MSG_VIBRATE); |
| 938 | onStopSounds(); |
| 939 | } |
| 940 | |
| 941 | removeMessages(MSG_FREE_RESOURCES); |
| 942 | sendMessageDelayed(obtainMessage(MSG_FREE_RESOURCES), FREE_DELAY); |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 943 | resetTimeout(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 944 | } |
| 945 | |
Mike Lockwood | ce952c8 | 2011-11-14 10:47:42 -0800 | [diff] [blame] | 946 | protected void onMuteChanged(int streamType, int flags) { |
| 947 | |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 948 | if (LOGD) Log.d(mTag, "onMuteChanged(streamType: " + streamType + ", flags: " + flags + ")"); |
Mike Lockwood | ce952c8 | 2011-11-14 10:47:42 -0800 | [diff] [blame] | 949 | |
| 950 | StreamControl sc = mStreamControls.get(streamType); |
| 951 | if (sc != null) { |
John Spurlock | ad494bc | 2014-07-19 15:56:19 -0400 | [diff] [blame] | 952 | updateSliderIcon(sc, isMuted(sc.streamType)); |
Mike Lockwood | ce952c8 | 2011-11-14 10:47:42 -0800 | [diff] [blame] | 953 | } |
| 954 | |
| 955 | onVolumeChanged(streamType, flags); |
| 956 | } |
| 957 | |
RoboErik | 19c9518 | 2014-06-23 15:38:48 -0700 | [diff] [blame] | 958 | protected void onShowVolumeChanged(int streamType, int flags, MediaController controller) { |
Eric Laurent | 8c78752 | 2012-05-14 14:09:43 -0700 | [diff] [blame] | 959 | int index = getStreamVolume(streamType); |
Eric Laurent | d72d51c | 2011-02-03 18:47:47 -0800 | [diff] [blame] | 960 | |
Marco Nelissen | 69f593c | 2009-07-28 09:55:04 -0700 | [diff] [blame] | 961 | mRingIsSilent = false; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 962 | |
| 963 | if (LOGD) { |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 964 | Log.d(mTag, "onShowVolumeChanged(streamType: " + streamType |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 965 | + ", flags: " + flags + "), index: " + index); |
| 966 | } |
| 967 | |
| 968 | // get max volume for progress bar |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 969 | |
Mike Lockwood | 8dc1dab | 2011-10-27 09:52:41 -0400 | [diff] [blame] | 970 | int max = getStreamMaxVolume(streamType); |
RoboErik | 19c9518 | 2014-06-23 15:38:48 -0700 | [diff] [blame] | 971 | StreamControl sc = mStreamControls.get(streamType); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 972 | |
| 973 | switch (streamType) { |
| 974 | |
| 975 | case AudioManager.STREAM_RING: { |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 976 | // setRingerIcon(); |
Marco Nelissen | 69f593c | 2009-07-28 09:55:04 -0700 | [diff] [blame] | 977 | Uri ringuri = RingtoneManager.getActualDefaultRingtoneUri( |
| 978 | mContext, RingtoneManager.TYPE_RINGTONE); |
| 979 | if (ringuri == null) { |
Marco Nelissen | 69f593c | 2009-07-28 09:55:04 -0700 | [diff] [blame] | 980 | mRingIsSilent = true; |
| 981 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 982 | break; |
| 983 | } |
| 984 | |
| 985 | case AudioManager.STREAM_MUSIC: { |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 986 | // Special case for when Bluetooth is active for music |
Glenn Kasten | 8b4b97a | 2011-02-04 13:54:26 -0800 | [diff] [blame] | 987 | if ((mAudioManager.getDevicesForStream(AudioManager.STREAM_MUSIC) & |
| 988 | (AudioManager.DEVICE_OUT_BLUETOOTH_A2DP | |
| 989 | AudioManager.DEVICE_OUT_BLUETOOTH_A2DP_HEADPHONES | |
| 990 | AudioManager.DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER)) != 0) { |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 991 | 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] | 992 | } else { |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 993 | 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] | 994 | } |
| 995 | break; |
| 996 | } |
| 997 | |
| 998 | case AudioManager.STREAM_VOICE_CALL: { |
| 999 | /* |
| 1000 | * For in-call voice call volume, there is no inaudible volume. |
| 1001 | * Rescale the UI control so the progress bar doesn't go all |
| 1002 | * the way to zero and don't show the mute icon. |
| 1003 | */ |
| 1004 | index++; |
| 1005 | max++; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1006 | break; |
| 1007 | } |
| 1008 | |
| 1009 | case AudioManager.STREAM_ALARM: { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1010 | break; |
| 1011 | } |
| 1012 | |
| 1013 | case AudioManager.STREAM_NOTIFICATION: { |
Marco Nelissen | 69f593c | 2009-07-28 09:55:04 -0700 | [diff] [blame] | 1014 | Uri ringuri = RingtoneManager.getActualDefaultRingtoneUri( |
| 1015 | mContext, RingtoneManager.TYPE_NOTIFICATION); |
| 1016 | if (ringuri == null) { |
Marco Nelissen | 69f593c | 2009-07-28 09:55:04 -0700 | [diff] [blame] | 1017 | mRingIsSilent = true; |
| 1018 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1019 | break; |
| 1020 | } |
| 1021 | |
| 1022 | case AudioManager.STREAM_BLUETOOTH_SCO: { |
| 1023 | /* |
| 1024 | * For in-call voice call volume, there is no inaudible volume. |
| 1025 | * Rescale the UI control so the progress bar doesn't go all |
| 1026 | * the way to zero and don't show the mute icon. |
| 1027 | */ |
| 1028 | index++; |
| 1029 | max++; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1030 | break; |
| 1031 | } |
Jean-Michel Trivi | 3114ce3 | 2012-06-11 15:03:52 -0700 | [diff] [blame] | 1032 | |
RoboErik | 2811dd3 | 2014-08-12 09:48:13 -0700 | [diff] [blame] | 1033 | case STREAM_REMOTE_MUSIC: { |
RoboErik | 19c9518 | 2014-06-23 15:38:48 -0700 | [diff] [blame] | 1034 | if (controller == null && sc != null) { |
| 1035 | // If we weren't passed one try using the last one set. |
| 1036 | controller = sc.controller; |
| 1037 | } |
| 1038 | if (controller == null) { |
| 1039 | // We still don't have one, ignore the command. |
| 1040 | Log.w(mTag, "sent remote volume change without a controller!"); |
| 1041 | } else { |
RoboErik | d2b8c94 | 2014-08-19 11:23:40 -0700 | [diff] [blame] | 1042 | PlaybackInfo vi = controller.getPlaybackInfo(); |
RoboErik | 19c9518 | 2014-06-23 15:38:48 -0700 | [diff] [blame] | 1043 | index = vi.getCurrentVolume(); |
| 1044 | max = vi.getMaxVolume(); |
| 1045 | if ((vi.getVolumeControl() & VolumeProvider.VOLUME_CONTROL_FIXED) != 0) { |
| 1046 | // if the remote volume is fixed add the flag for the UI |
| 1047 | flags |= AudioManager.FLAG_FIXED_VOLUME; |
| 1048 | } |
| 1049 | } |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 1050 | if (LOGD) { Log.d(mTag, "showing remote volume "+index+" over "+ max); } |
Jean-Michel Trivi | 3114ce3 | 2012-06-11 15:03:52 -0700 | [diff] [blame] | 1051 | break; |
| 1052 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1053 | } |
| 1054 | |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 1055 | if (sc != null) { |
RoboErik | 2811dd3 | 2014-08-12 09:48:13 -0700 | [diff] [blame] | 1056 | if (streamType == STREAM_REMOTE_MUSIC && controller != sc.controller) { |
RoboErik | 19c9518 | 2014-06-23 15:38:48 -0700 | [diff] [blame] | 1057 | if (sc.controller != null) { |
| 1058 | sc.controller.removeCallback(mMediaControllerCb); |
| 1059 | } |
| 1060 | sc.controller = controller; |
| 1061 | if (controller != null) { |
| 1062 | sc.controller.addCallback(mMediaControllerCb); |
| 1063 | } |
| 1064 | } |
Amith Yamasani | d47a3aee | 2011-08-23 11:11:35 -0700 | [diff] [blame] | 1065 | if (sc.seekbarView.getMax() != max) { |
| 1066 | sc.seekbarView.setMax(max); |
| 1067 | } |
John Spurlock | ad494bc | 2014-07-19 15:56:19 -0400 | [diff] [blame] | 1068 | updateSliderProgress(sc, index); |
John Spurlock | 7f1df5e | 2014-05-31 19:11:40 -0400 | [diff] [blame] | 1069 | updateSliderEnabled(sc, isMuted(streamType), |
| 1070 | (flags & AudioManager.FLAG_FIXED_VOLUME) != 0); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1071 | } |
| 1072 | |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 1073 | if (!isShowing()) { |
RoboErik | 2811dd3 | 2014-08-12 09:48:13 -0700 | [diff] [blame] | 1074 | int stream = (streamType == STREAM_REMOTE_MUSIC) ? -1 : streamType; |
Jean-Michel Trivi | 3114ce3 | 2012-06-11 15:03:52 -0700 | [diff] [blame] | 1075 | // when the stream is for remote playback, use -1 to reset the stream type evaluation |
| 1076 | mAudioManager.forceVolumeControlStream(stream); |
John Spurlock | eb2727b | 2014-07-19 23:11:36 -0400 | [diff] [blame] | 1077 | mDialog.show(); |
| 1078 | if (mCallback != null) { |
| 1079 | mCallback.onVisible(true); |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 1080 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1081 | } |
| 1082 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1083 | // Do a little vibrate if applicable (only when going into vibrate mode) |
RoboErik | 2811dd3 | 2014-08-12 09:48:13 -0700 | [diff] [blame] | 1084 | if ((streamType != STREAM_REMOTE_MUSIC) && |
Jean-Michel Trivi | 3114ce3 | 2012-06-11 15:03:52 -0700 | [diff] [blame] | 1085 | ((flags & AudioManager.FLAG_VIBRATE) != 0) && |
John Spurlock | 3346a80 | 2014-05-20 16:25:37 -0400 | [diff] [blame] | 1086 | mAudioManager.isStreamAffectedByRingerMode(streamType) && |
Eric Laurent | 8c78752 | 2012-05-14 14:09:43 -0700 | [diff] [blame] | 1087 | mAudioManager.getRingerMode() == AudioManager.RINGER_MODE_VIBRATE) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1088 | sendMessageDelayed(obtainMessage(MSG_VIBRATE), VIBRATE_DELAY); |
| 1089 | } |
John Spurlock | a11b4af | 2014-06-01 11:52:23 -0400 | [diff] [blame] | 1090 | |
| 1091 | // 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] | 1092 | if ((flags & AudioManager.FLAG_SHOW_SILENT_HINT) != 0) { |
| 1093 | showSilentHint(); |
John Spurlock | a11b4af | 2014-06-01 11:52:23 -0400 | [diff] [blame] | 1094 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1095 | } |
| 1096 | |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 1097 | private boolean isShowing() { |
John Spurlock | eb2727b | 2014-07-19 23:11:36 -0400 | [diff] [blame] | 1098 | return mDialog.isShowing(); |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 1099 | } |
| 1100 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1101 | protected void onPlaySound(int streamType, int flags) { |
| 1102 | |
| 1103 | if (hasMessages(MSG_STOP_SOUNDS)) { |
| 1104 | removeMessages(MSG_STOP_SOUNDS); |
| 1105 | // Force stop right now |
| 1106 | onStopSounds(); |
| 1107 | } |
| 1108 | |
| 1109 | synchronized (this) { |
| 1110 | ToneGenerator toneGen = getOrCreateToneGenerator(streamType); |
Eric Laurent | 733a42b | 2011-01-19 10:41:57 -0800 | [diff] [blame] | 1111 | if (toneGen != null) { |
| 1112 | toneGen.startTone(ToneGenerator.TONE_PROP_BEEP); |
| 1113 | sendMessageDelayed(obtainMessage(MSG_STOP_SOUNDS), BEEP_DURATION); |
| 1114 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1115 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1116 | } |
| 1117 | |
| 1118 | protected void onStopSounds() { |
| 1119 | |
| 1120 | synchronized (this) { |
| 1121 | int numStreamTypes = AudioSystem.getNumStreamTypes(); |
| 1122 | for (int i = numStreamTypes - 1; i >= 0; i--) { |
| 1123 | ToneGenerator toneGen = mToneGenerators[i]; |
| 1124 | if (toneGen != null) { |
| 1125 | toneGen.stopTone(); |
| 1126 | } |
| 1127 | } |
| 1128 | } |
| 1129 | } |
| 1130 | |
| 1131 | protected void onVibrate() { |
| 1132 | |
| 1133 | // Make sure we ended up in vibrate ringer mode |
Eric Laurent | 8c78752 | 2012-05-14 14:09:43 -0700 | [diff] [blame] | 1134 | if (mAudioManager.getRingerMode() != AudioManager.RINGER_MODE_VIBRATE) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1135 | return; |
| 1136 | } |
| 1137 | |
John Spurlock | 7b41467 | 2014-07-18 13:02:39 -0400 | [diff] [blame] | 1138 | mVibrator.vibrate(VIBRATE_DURATION, VIBRATION_ATTRIBUTES); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1139 | } |
| 1140 | |
RoboErik | 19c9518 | 2014-06-23 15:38:48 -0700 | [diff] [blame] | 1141 | protected void onRemoteVolumeChanged(MediaController controller, int flags) { |
| 1142 | if (LOGD) Log.d(mTag, "onRemoteVolumeChanged(controller:" + controller + ", flags: " + flags |
| 1143 | + ")"); |
Jean-Michel Trivi | 3114ce3 | 2012-06-11 15:03:52 -0700 | [diff] [blame] | 1144 | |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 1145 | if (((flags & AudioManager.FLAG_SHOW_UI) != 0) || isShowing()) { |
Jean-Michel Trivi | 3114ce3 | 2012-06-11 15:03:52 -0700 | [diff] [blame] | 1146 | synchronized (this) { |
RoboErik | 2811dd3 | 2014-08-12 09:48:13 -0700 | [diff] [blame] | 1147 | if (mActiveStreamType != STREAM_REMOTE_MUSIC) { |
| 1148 | reorderSliders(STREAM_REMOTE_MUSIC); |
Jean-Michel Trivi | 3114ce3 | 2012-06-11 15:03:52 -0700 | [diff] [blame] | 1149 | } |
RoboErik | 2811dd3 | 2014-08-12 09:48:13 -0700 | [diff] [blame] | 1150 | onShowVolumeChanged(STREAM_REMOTE_MUSIC, flags, controller); |
Jean-Michel Trivi | 3114ce3 | 2012-06-11 15:03:52 -0700 | [diff] [blame] | 1151 | } |
| 1152 | } else { |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 1153 | 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] | 1154 | } |
| 1155 | |
Jean-Michel Trivi | 3114ce3 | 2012-06-11 15:03:52 -0700 | [diff] [blame] | 1156 | removeMessages(MSG_FREE_RESOURCES); |
| 1157 | sendMessageDelayed(obtainMessage(MSG_FREE_RESOURCES), FREE_DELAY); |
Jean-Michel Trivi | 3114ce3 | 2012-06-11 15:03:52 -0700 | [diff] [blame] | 1158 | resetTimeout(); |
| 1159 | } |
| 1160 | |
| 1161 | protected void onRemoteVolumeUpdateIfShown() { |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 1162 | if (LOGD) Log.d(mTag, "onRemoteVolumeUpdateIfShown()"); |
| 1163 | if (isShowing() |
RoboErik | 2811dd3 | 2014-08-12 09:48:13 -0700 | [diff] [blame] | 1164 | && (mActiveStreamType == STREAM_REMOTE_MUSIC) |
Jean-Michel Trivi | 3114ce3 | 2012-06-11 15:03:52 -0700 | [diff] [blame] | 1165 | && (mStreamControls != null)) { |
RoboErik | 2811dd3 | 2014-08-12 09:48:13 -0700 | [diff] [blame] | 1166 | onShowVolumeChanged(STREAM_REMOTE_MUSIC, 0, null); |
Jean-Michel Trivi | 3114ce3 | 2012-06-11 15:03:52 -0700 | [diff] [blame] | 1167 | } |
| 1168 | } |
| 1169 | |
RoboErik | 19c9518 | 2014-06-23 15:38:48 -0700 | [diff] [blame] | 1170 | /** |
| 1171 | * Clear the current remote stream controller. |
| 1172 | */ |
| 1173 | private void clearRemoteStreamController() { |
| 1174 | if (mStreamControls != null) { |
RoboErik | 2811dd3 | 2014-08-12 09:48:13 -0700 | [diff] [blame] | 1175 | StreamControl sc = mStreamControls.get(STREAM_REMOTE_MUSIC); |
RoboErik | 19c9518 | 2014-06-23 15:38:48 -0700 | [diff] [blame] | 1176 | if (sc != null) { |
| 1177 | if (sc.controller != null) { |
| 1178 | sc.controller.removeCallback(mMediaControllerCb); |
| 1179 | sc.controller = null; |
| 1180 | } |
| 1181 | } |
| 1182 | } |
| 1183 | } |
Jean-Michel Trivi | 3114ce3 | 2012-06-11 15:03:52 -0700 | [diff] [blame] | 1184 | |
| 1185 | /** |
RoboErik | 2811dd3 | 2014-08-12 09:48:13 -0700 | [diff] [blame] | 1186 | * Handler for MSG_SLIDER_VISIBILITY_CHANGED Hide or show a slider |
| 1187 | * |
| 1188 | * @param streamType can be a valid stream type value, or |
| 1189 | * VolumePanel.STREAM_MASTER, or VolumePanel.STREAM_REMOTE_MUSIC |
Jean-Michel Trivi | 3114ce3 | 2012-06-11 15:03:52 -0700 | [diff] [blame] | 1190 | * @param visible |
| 1191 | */ |
| 1192 | synchronized protected void onSliderVisibilityChanged(int streamType, int visible) { |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 1193 | if (LOGD) Log.d(mTag, "onSliderVisibilityChanged(stream="+streamType+", visi="+visible+")"); |
Jean-Michel Trivi | 3114ce3 | 2012-06-11 15:03:52 -0700 | [diff] [blame] | 1194 | boolean isVisible = (visible == 1); |
| 1195 | for (int i = STREAMS.length - 1 ; i >= 0 ; i--) { |
| 1196 | StreamResources streamRes = STREAMS[i]; |
| 1197 | if (streamRes.streamType == streamType) { |
| 1198 | streamRes.show = isVisible; |
| 1199 | if (!isVisible && (mActiveStreamType == streamType)) { |
| 1200 | mActiveStreamType = -1; |
| 1201 | } |
| 1202 | break; |
| 1203 | } |
| 1204 | } |
| 1205 | } |
| 1206 | |
Eric Laurent | fde16d5 | 2012-12-03 14:42:39 -0800 | [diff] [blame] | 1207 | protected void onDisplaySafeVolumeWarning(int flags) { |
John Spurlock | 3513460 | 2014-07-24 18:10:48 -0400 | [diff] [blame] | 1208 | if ((flags & (AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_SHOW_UI_WARNINGS)) != 0 |
| 1209 | || isShowing()) { |
| 1210 | synchronized (sSafetyWarningLock) { |
| 1211 | if (sSafetyWarning != null) { |
Eric Laurent | fde16d5 | 2012-12-03 14:42:39 -0800 | [diff] [blame] | 1212 | return; |
| 1213 | } |
John Spurlock | 3513460 | 2014-07-24 18:10:48 -0400 | [diff] [blame] | 1214 | sSafetyWarning = new SafetyWarning(mContext, this, mAudioManager); |
| 1215 | sSafetyWarning.show(); |
Eric Laurent | fde16d5 | 2012-12-03 14:42:39 -0800 | [diff] [blame] | 1216 | } |
| 1217 | updateStates(); |
Eric Laurent | c34dcc1 | 2012-09-10 13:51:52 -0700 | [diff] [blame] | 1218 | } |
Selim Cinek | 1cf8906 | 2014-08-29 19:21:44 +0200 | [diff] [blame^] | 1219 | if (mAccessibilityManager.isTouchExplorationEnabled()) { |
| 1220 | removeMessages(MSG_TIMEOUT); |
| 1221 | } else { |
| 1222 | updateTimeoutDelay(); |
| 1223 | resetTimeout(); |
| 1224 | } |
Eric Laurent | c34dcc1 | 2012-09-10 13:51:52 -0700 | [diff] [blame] | 1225 | } |
| 1226 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1227 | /** |
| 1228 | * Lock on this VolumePanel instance as long as you use the returned ToneGenerator. |
| 1229 | */ |
| 1230 | private ToneGenerator getOrCreateToneGenerator(int streamType) { |
Christopher Tate | c4b78d2 | 2012-05-22 13:57:58 -0700 | [diff] [blame] | 1231 | if (streamType == STREAM_MASTER) { |
| 1232 | // For devices that use the master volume setting only but still want to |
| 1233 | // play a volume-changed tone, direct the master volume pseudostream to |
| 1234 | // the system stream's tone generator. |
| 1235 | if (mPlayMasterStreamTones) { |
| 1236 | streamType = AudioManager.STREAM_SYSTEM; |
| 1237 | } else { |
| 1238 | return null; |
| 1239 | } |
| 1240 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1241 | synchronized (this) { |
| 1242 | if (mToneGenerators[streamType] == null) { |
Eric Laurent | 733a42b | 2011-01-19 10:41:57 -0800 | [diff] [blame] | 1243 | try { |
| 1244 | mToneGenerators[streamType] = new ToneGenerator(streamType, MAX_VOLUME); |
| 1245 | } catch (RuntimeException e) { |
| 1246 | if (LOGD) { |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 1247 | Log.d(mTag, "ToneGenerator constructor failed with " |
Eric Laurent | 733a42b | 2011-01-19 10:41:57 -0800 | [diff] [blame] | 1248 | + "RuntimeException: " + e); |
| 1249 | } |
| 1250 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1251 | } |
Eric Laurent | 733a42b | 2011-01-19 10:41:57 -0800 | [diff] [blame] | 1252 | return mToneGenerators[streamType]; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1253 | } |
| 1254 | } |
| 1255 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1256 | |
| 1257 | /** |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 1258 | * Switch between icons because Bluetooth music is same as music volume, but with |
| 1259 | * different icons. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1260 | */ |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 1261 | private void setMusicIcon(int resId, int resMuteId) { |
| 1262 | StreamControl sc = mStreamControls.get(AudioManager.STREAM_MUSIC); |
| 1263 | if (sc != null) { |
| 1264 | sc.iconRes = resId; |
| 1265 | sc.iconMuteRes = resMuteId; |
John Spurlock | ad494bc | 2014-07-19 15:56:19 -0400 | [diff] [blame] | 1266 | updateSliderIcon(sc, isMuted(sc.streamType)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1267 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1268 | } |
| 1269 | |
| 1270 | protected void onFreeResources() { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1271 | synchronized (this) { |
| 1272 | for (int i = mToneGenerators.length - 1; i >= 0; i--) { |
| 1273 | if (mToneGenerators[i] != null) { |
| 1274 | mToneGenerators[i].release(); |
| 1275 | } |
| 1276 | mToneGenerators[i] = null; |
| 1277 | } |
| 1278 | } |
| 1279 | } |
| 1280 | |
| 1281 | @Override |
| 1282 | public void handleMessage(Message msg) { |
| 1283 | switch (msg.what) { |
| 1284 | |
| 1285 | case MSG_VOLUME_CHANGED: { |
| 1286 | onVolumeChanged(msg.arg1, msg.arg2); |
| 1287 | break; |
| 1288 | } |
| 1289 | |
Mike Lockwood | ce952c8 | 2011-11-14 10:47:42 -0800 | [diff] [blame] | 1290 | case MSG_MUTE_CHANGED: { |
| 1291 | onMuteChanged(msg.arg1, msg.arg2); |
| 1292 | break; |
| 1293 | } |
| 1294 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1295 | case MSG_FREE_RESOURCES: { |
| 1296 | onFreeResources(); |
| 1297 | break; |
| 1298 | } |
| 1299 | |
| 1300 | case MSG_STOP_SOUNDS: { |
| 1301 | onStopSounds(); |
| 1302 | break; |
| 1303 | } |
| 1304 | |
| 1305 | case MSG_PLAY_SOUND: { |
| 1306 | onPlaySound(msg.arg1, msg.arg2); |
| 1307 | break; |
| 1308 | } |
| 1309 | |
| 1310 | case MSG_VIBRATE: { |
| 1311 | onVibrate(); |
| 1312 | break; |
| 1313 | } |
| 1314 | |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 1315 | case MSG_TIMEOUT: { |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 1316 | if (isShowing()) { |
John Spurlock | eb2727b | 2014-07-19 23:11:36 -0400 | [diff] [blame] | 1317 | mDialog.dismiss(); |
| 1318 | clearRemoteStreamController(); |
| 1319 | mActiveStreamType = -1; |
| 1320 | if (mCallback != null) { |
| 1321 | mCallback.onVisible(false); |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 1322 | } |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 1323 | } |
John Spurlock | 3513460 | 2014-07-24 18:10:48 -0400 | [diff] [blame] | 1324 | synchronized (sSafetyWarningLock) { |
| 1325 | if (sSafetyWarning != null) { |
| 1326 | if (LOGD) Log.d(mTag, "SafetyWarning timeout"); |
| 1327 | sSafetyWarning.dismiss(); |
Eric Laurent | fde16d5 | 2012-12-03 14:42:39 -0800 | [diff] [blame] | 1328 | } |
| 1329 | } |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 1330 | break; |
| 1331 | } |
John Spurlock | b478252 | 2014-08-22 14:54:46 -0400 | [diff] [blame] | 1332 | |
| 1333 | case MSG_RINGER_MODE_CHANGED: |
| 1334 | case MSG_NOTIFICATION_EFFECTS_SUPPRESSOR_CHANGED: { |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 1335 | if (isShowing()) { |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 1336 | updateStates(); |
| 1337 | } |
| 1338 | break; |
| 1339 | } |
Jean-Michel Trivi | 3114ce3 | 2012-06-11 15:03:52 -0700 | [diff] [blame] | 1340 | |
| 1341 | case MSG_REMOTE_VOLUME_CHANGED: { |
RoboErik | 19c9518 | 2014-06-23 15:38:48 -0700 | [diff] [blame] | 1342 | onRemoteVolumeChanged((MediaController) msg.obj, msg.arg1); |
Jean-Michel Trivi | 3114ce3 | 2012-06-11 15:03:52 -0700 | [diff] [blame] | 1343 | break; |
| 1344 | } |
| 1345 | |
| 1346 | case MSG_REMOTE_VOLUME_UPDATE_IF_SHOWN: |
| 1347 | onRemoteVolumeUpdateIfShown(); |
| 1348 | break; |
| 1349 | |
| 1350 | case MSG_SLIDER_VISIBILITY_CHANGED: |
| 1351 | onSliderVisibilityChanged(msg.arg1, msg.arg2); |
| 1352 | break; |
Eric Laurent | c34dcc1 | 2012-09-10 13:51:52 -0700 | [diff] [blame] | 1353 | |
| 1354 | case MSG_DISPLAY_SAFE_VOLUME_WARNING: |
Eric Laurent | fde16d5 | 2012-12-03 14:42:39 -0800 | [diff] [blame] | 1355 | onDisplaySafeVolumeWarning(msg.arg1); |
Eric Laurent | c34dcc1 | 2012-09-10 13:51:52 -0700 | [diff] [blame] | 1356 | break; |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 1357 | |
| 1358 | case MSG_LAYOUT_DIRECTION: |
| 1359 | setLayoutDirection(msg.arg1); |
| 1360 | break; |
| 1361 | |
John Spurlock | 45601d6 | 2014-08-07 17:40:50 -0400 | [diff] [blame] | 1362 | case MSG_ZEN_MODE_AVAILABLE_CHANGED: |
| 1363 | mZenModeAvailable = msg.arg1 != 0; |
| 1364 | updateZenPanelVisible(); |
John Spurlock | ae641c9 | 2014-06-30 18:11:40 -0400 | [diff] [blame] | 1365 | break; |
| 1366 | |
| 1367 | case MSG_USER_ACTIVITY: |
| 1368 | if (mCallback != null) { |
| 1369 | mCallback.onInteraction(); |
| 1370 | } |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 1371 | break; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1372 | } |
| 1373 | } |
| 1374 | |
John Spurlock | ae641c9 | 2014-06-30 18:11:40 -0400 | [diff] [blame] | 1375 | private void resetTimeout() { |
John Spurlock | ea9938c | 2014-07-11 18:51:32 -0400 | [diff] [blame] | 1376 | if (LOGD) Log.d(mTag, "resetTimeout at " + System.currentTimeMillis() |
| 1377 | + " delay=" + mTimeoutDelay); |
Selim Cinek | 1cf8906 | 2014-08-29 19:21:44 +0200 | [diff] [blame^] | 1378 | if (sSafetyWarning == null || !mAccessibilityManager.isTouchExplorationEnabled()) { |
| 1379 | removeMessages(MSG_TIMEOUT); |
| 1380 | sendEmptyMessageDelayed(MSG_TIMEOUT, mTimeoutDelay); |
| 1381 | removeMessages(MSG_USER_ACTIVITY); |
| 1382 | sendEmptyMessage(MSG_USER_ACTIVITY); |
| 1383 | } |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 1384 | } |
| 1385 | |
John Spurlock | 1dad272 | 2014-07-11 11:07:53 -0400 | [diff] [blame] | 1386 | private void forceTimeout(long delay) { |
Amith Yamasani | baf6dbf | 2011-08-18 17:40:29 -0700 | [diff] [blame] | 1387 | removeMessages(MSG_TIMEOUT); |
John Spurlock | 1dad272 | 2014-07-11 11:07:53 -0400 | [diff] [blame] | 1388 | sendEmptyMessageDelayed(MSG_TIMEOUT, delay); |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 1389 | } |
| 1390 | |
| 1391 | public ZenModeController getZenController() { |
| 1392 | return mZenController; |
Amith Yamasani | baf6dbf | 2011-08-18 17:40:29 -0700 | [diff] [blame] | 1393 | } |
| 1394 | |
Alan Viverette | e8ebaf3 | 2014-04-11 15:44:15 -0700 | [diff] [blame] | 1395 | private final OnSeekBarChangeListener mSeekListener = new OnSeekBarChangeListener() { |
| 1396 | @Override |
| 1397 | public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { |
| 1398 | final Object tag = seekBar.getTag(); |
| 1399 | if (fromUser && tag instanceof StreamControl) { |
| 1400 | StreamControl sc = (StreamControl) tag; |
John Spurlock | ac9ab5b | 2014-07-20 13:09:44 -0400 | [diff] [blame] | 1401 | setStreamVolume(sc, progress, |
| 1402 | AudioManager.FLAG_SHOW_UI | AudioManager.FLAG_VIBRATE); |
Alan Viverette | e8ebaf3 | 2014-04-11 15:44:15 -0700 | [diff] [blame] | 1403 | } |
| 1404 | resetTimeout(); |
| 1405 | } |
| 1406 | |
| 1407 | @Override |
| 1408 | public void onStartTrackingTouch(SeekBar seekBar) { |
| 1409 | } |
| 1410 | |
| 1411 | @Override |
| 1412 | public void onStopTrackingTouch(SeekBar seekBar) { |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 1413 | } |
Alan Viverette | e8ebaf3 | 2014-04-11 15:44:15 -0700 | [diff] [blame] | 1414 | }; |
Amith Yamasani | 2bbdd77 | 2011-02-02 18:54:13 -0800 | [diff] [blame] | 1415 | |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 1416 | private final ZenModeController.Callback mZenCallback = new ZenModeController.Callback() { |
John Spurlock | b478252 | 2014-08-22 14:54:46 -0400 | [diff] [blame] | 1417 | @Override |
John Spurlock | 45601d6 | 2014-08-07 17:40:50 -0400 | [diff] [blame] | 1418 | public void onZenAvailableChanged(boolean available) { |
| 1419 | obtainMessage(MSG_ZEN_MODE_AVAILABLE_CHANGED, available ? 1 : 0, 0).sendToTarget(); |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 1420 | } |
John Spurlock | b478252 | 2014-08-22 14:54:46 -0400 | [diff] [blame] | 1421 | @Override |
| 1422 | public void onEffectsSupressorChanged() { |
| 1423 | obtainMessage(MSG_NOTIFICATION_EFFECTS_SUPPRESSOR_CHANGED, |
| 1424 | mZenController.getEffectsSuppressor()).sendToTarget(); |
| 1425 | } |
John Spurlock | 8600534 | 2014-05-23 11:58:00 -0400 | [diff] [blame] | 1426 | }; |
RoboErik | 19c9518 | 2014-06-23 15:38:48 -0700 | [diff] [blame] | 1427 | |
| 1428 | private final MediaController.Callback mMediaControllerCb = new MediaController.Callback() { |
RoboErik | d2b8c94 | 2014-08-19 11:23:40 -0700 | [diff] [blame] | 1429 | public void onAudioInfoChanged(PlaybackInfo info) { |
RoboErik | 19c9518 | 2014-06-23 15:38:48 -0700 | [diff] [blame] | 1430 | onRemoteVolumeUpdateIfShown(); |
| 1431 | } |
| 1432 | }; |
John Spurlock | ae641c9 | 2014-06-30 18:11:40 -0400 | [diff] [blame] | 1433 | |
| 1434 | public interface Callback { |
| 1435 | void onZenSettings(); |
| 1436 | void onInteraction(); |
John Spurlock | 33f4e04 | 2014-07-11 13:10:58 -0400 | [diff] [blame] | 1437 | void onVisible(boolean visible); |
John Spurlock | ae641c9 | 2014-06-30 18:11:40 -0400 | [diff] [blame] | 1438 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1439 | } |