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