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