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