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