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