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