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