Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 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 | |
| 17 | package com.android.systemui.bubbles; |
| 18 | |
Mady Mellor | d1c78b26 | 2018-11-06 18:04:40 -0800 | [diff] [blame] | 19 | import static android.view.View.INVISIBLE; |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 20 | import static android.view.View.VISIBLE; |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 21 | import static android.view.ViewGroup.LayoutParams.MATCH_PARENT; |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 22 | |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 23 | import static com.android.systemui.statusbar.StatusBarState.SHADE; |
| 24 | import static com.android.systemui.statusbar.notification.NotificationAlertingManager.alertAgain; |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 25 | |
Mady Mellor | b4991e6 | 2019-01-10 15:14:51 -0800 | [diff] [blame] | 26 | import android.annotation.Nullable; |
Mark Renouf | cecc77b | 2019-01-30 16:32:24 -0500 | [diff] [blame] | 27 | import android.app.ActivityManager; |
Mark Renouf | c808f06 | 2019-02-07 15:20:37 -0500 | [diff] [blame] | 28 | import android.app.ActivityManager.RunningTaskInfo; |
Mark Renouf | cecc77b | 2019-01-30 16:32:24 -0500 | [diff] [blame] | 29 | import android.app.ActivityTaskManager; |
| 30 | import android.app.IActivityTaskManager; |
Mady Mellor | b4991e6 | 2019-01-10 15:14:51 -0800 | [diff] [blame] | 31 | import android.app.INotificationManager; |
Mady Mellor | 5549dd2 | 2018-11-06 18:07:34 -0800 | [diff] [blame] | 32 | import android.app.Notification; |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 33 | import android.content.Context; |
Joshua Tsuji | a19515f | 2019-02-13 18:02:29 -0500 | [diff] [blame] | 34 | import android.content.pm.ParceledListSlice; |
Mady Mellor | d1c78b26 | 2018-11-06 18:04:40 -0800 | [diff] [blame] | 35 | import android.graphics.Rect; |
Mark Renouf | cecc77b | 2019-01-30 16:32:24 -0500 | [diff] [blame] | 36 | import android.os.RemoteException; |
Mady Mellor | b4991e6 | 2019-01-10 15:14:51 -0800 | [diff] [blame] | 37 | import android.os.ServiceManager; |
Mady Mellor | ceced17 | 2018-11-27 11:18:39 -0800 | [diff] [blame] | 38 | import android.provider.Settings; |
Mady Mellor | 5549dd2 | 2018-11-06 18:07:34 -0800 | [diff] [blame] | 39 | import android.service.notification.StatusBarNotification; |
Mark Renouf | cecc77b | 2019-01-30 16:32:24 -0500 | [diff] [blame] | 40 | import android.view.Display; |
Joshua Tsuji | a19515f | 2019-02-13 18:02:29 -0500 | [diff] [blame] | 41 | import android.view.IPinnedStackController; |
| 42 | import android.view.IPinnedStackListener; |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 43 | import android.view.ViewGroup; |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 44 | import android.widget.FrameLayout; |
| 45 | |
Mark Renouf | 658c6bc | 2019-01-30 10:26:54 -0500 | [diff] [blame] | 46 | import androidx.annotation.MainThread; |
| 47 | |
Mady Mellor | ebdbbb9 | 2018-11-15 14:36:48 -0800 | [diff] [blame] | 48 | import com.android.internal.annotations.VisibleForTesting; |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 49 | import com.android.internal.statusbar.NotificationVisibility; |
Ned Burns | 01e3821 | 2019-01-03 16:32:52 -0500 | [diff] [blame] | 50 | import com.android.systemui.Dependency; |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 51 | import com.android.systemui.R; |
Beverly | 8fdb533 | 2019-02-04 14:29:49 -0500 | [diff] [blame] | 52 | import com.android.systemui.plugins.statusbar.StatusBarStateController; |
Mark Renouf | cecc77b | 2019-01-30 16:32:24 -0500 | [diff] [blame] | 53 | import com.android.systemui.shared.system.ActivityManagerWrapper; |
| 54 | import com.android.systemui.shared.system.TaskStackChangeListener; |
Joshua Tsuji | a19515f | 2019-02-13 18:02:29 -0500 | [diff] [blame] | 55 | import com.android.systemui.shared.system.WindowManagerWrapper; |
Ned Burns | 01e3821 | 2019-01-03 16:32:52 -0500 | [diff] [blame] | 56 | import com.android.systemui.statusbar.notification.NotificationEntryListener; |
| 57 | import com.android.systemui.statusbar.notification.NotificationEntryManager; |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 58 | import com.android.systemui.statusbar.notification.NotificationInterruptionStateProvider; |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 59 | import com.android.systemui.statusbar.notification.collection.NotificationEntry; |
Ned Burns | 1a5e22f | 2019-02-14 15:11:52 -0500 | [diff] [blame] | 60 | import com.android.systemui.statusbar.notification.row.NotificationContentInflater.InflationFlag; |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 61 | import com.android.systemui.statusbar.phone.StatusBarWindowController; |
| 62 | |
Mark Renouf | cecc77b | 2019-01-30 16:32:24 -0500 | [diff] [blame] | 63 | import java.util.List; |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 64 | |
Jason Monk | 27d01a62 | 2018-12-10 15:57:09 -0500 | [diff] [blame] | 65 | import javax.inject.Inject; |
| 66 | import javax.inject.Singleton; |
| 67 | |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 68 | /** |
| 69 | * Bubbles are a special type of content that can "float" on top of other apps or System UI. |
| 70 | * Bubbles can be expanded to show more content. |
| 71 | * |
| 72 | * The controller manages addition, removal, and visible state of bubbles on screen. |
| 73 | */ |
Jason Monk | 27d01a62 | 2018-12-10 15:57:09 -0500 | [diff] [blame] | 74 | @Singleton |
Mady Mellor | 3d82e68 | 2019-02-05 13:34:48 -0800 | [diff] [blame] | 75 | public class BubbleController implements BubbleExpandedView.OnBubbleBlockedListener { |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 76 | private static final int MAX_BUBBLES = 5; // TODO: actually enforce this |
| 77 | |
| 78 | private static final String TAG = "BubbleController"; |
| 79 | |
Mady Mellor | 5549dd2 | 2018-11-06 18:07:34 -0800 | [diff] [blame] | 80 | // Enables some subset of notifs to automatically become bubbles |
Ned Burns | 01e3821 | 2019-01-03 16:32:52 -0500 | [diff] [blame] | 81 | private static final boolean DEBUG_ENABLE_AUTO_BUBBLE = false; |
Mady Mellor | 5549dd2 | 2018-11-06 18:07:34 -0800 | [diff] [blame] | 82 | |
Mady Mellor | 44ee2fe | 2019-01-30 17:51:16 -0800 | [diff] [blame] | 83 | /** Flag to enable or disable the entire feature */ |
Mady Mellor | f6e3ac0 | 2019-01-29 10:37:52 -0800 | [diff] [blame] | 84 | private static final String ENABLE_BUBBLES = "experiment_enable_bubbles"; |
Mady Mellor | 44ee2fe | 2019-01-30 17:51:16 -0800 | [diff] [blame] | 85 | /** Auto bubble flags set whether different notif types should be presented as a bubble */ |
Mady Mellor | ceced17 | 2018-11-27 11:18:39 -0800 | [diff] [blame] | 86 | private static final String ENABLE_AUTO_BUBBLE_MESSAGES = "experiment_autobubble_messaging"; |
| 87 | private static final String ENABLE_AUTO_BUBBLE_ONGOING = "experiment_autobubble_ongoing"; |
| 88 | private static final String ENABLE_AUTO_BUBBLE_ALL = "experiment_autobubble_all"; |
Mady Mellor | 44ee2fe | 2019-01-30 17:51:16 -0800 | [diff] [blame] | 89 | |
| 90 | /** Use an activityView for an auto-bubbled notifs if it has an appropriate content intent */ |
Mark Renouf | 89b1a4a | 2018-12-04 14:59:45 -0500 | [diff] [blame] | 91 | private static final String ENABLE_BUBBLE_CONTENT_INTENT = "experiment_bubble_content_intent"; |
Mady Mellor | ceced17 | 2018-11-27 11:18:39 -0800 | [diff] [blame] | 92 | |
Mady Mellor | 44ee2fe | 2019-01-30 17:51:16 -0800 | [diff] [blame] | 93 | /** Whether the row of bubble circles are anchored to the top or bottom of the screen. */ |
| 94 | private static final String ENABLE_BUBBLES_AT_TOP = "experiment_enable_top_bubbles"; |
| 95 | /** Flag to position the header below the activity view */ |
| 96 | private static final String ENABLE_BUBBLE_FOOTER = "experiment_enable_bubble_footer"; |
| 97 | |
Joshua Tsuji | 010c2b1 | 2019-02-25 18:11:25 -0500 | [diff] [blame^] | 98 | private static final String BUBBLE_STIFFNESS = "experiment_bubble_stiffness"; |
| 99 | private static final String BUBBLE_BOUNCINESS = "experiment_bubble_bounciness"; |
| 100 | |
Ned Burns | 01e3821 | 2019-01-03 16:32:52 -0500 | [diff] [blame] | 101 | private final Context mContext; |
| 102 | private final NotificationEntryManager mNotificationEntryManager; |
Mark Renouf | cecc77b | 2019-01-30 16:32:24 -0500 | [diff] [blame] | 103 | private final IActivityTaskManager mActivityTaskManager; |
| 104 | private final BubbleTaskStackListener mTaskStackListener; |
Mady Mellor | d1c78b26 | 2018-11-06 18:04:40 -0800 | [diff] [blame] | 105 | private BubbleStateChangeListener mStateChangeListener; |
Mady Mellor | cd9b130 | 2018-11-06 18:08:04 -0800 | [diff] [blame] | 106 | private BubbleExpandListener mExpandListener; |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 107 | |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 108 | private BubbleData mBubbleData; |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 109 | private BubbleStackView mStackView; |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 110 | |
| 111 | // Bubbles get added to the status bar view |
Ned Burns | 01e3821 | 2019-01-03 16:32:52 -0500 | [diff] [blame] | 112 | private final StatusBarWindowController mStatusBarWindowController; |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 113 | private StatusBarStateListener mStatusBarStateListener; |
| 114 | |
| 115 | private final NotificationInterruptionStateProvider mNotificationInterruptionStateProvider = |
| 116 | Dependency.get(NotificationInterruptionStateProvider.class); |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 117 | |
Mady Mellor | b4991e6 | 2019-01-10 15:14:51 -0800 | [diff] [blame] | 118 | private INotificationManager mNotificationManagerService; |
| 119 | |
Mady Mellor | d1c78b26 | 2018-11-06 18:04:40 -0800 | [diff] [blame] | 120 | // Used for determining view rect for touch interaction |
| 121 | private Rect mTempRect = new Rect(); |
| 122 | |
Mady Mellor | 5549dd2 | 2018-11-06 18:07:34 -0800 | [diff] [blame] | 123 | /** |
Mady Mellor | d1c78b26 | 2018-11-06 18:04:40 -0800 | [diff] [blame] | 124 | * Listener to be notified when some states of the bubbles change. |
| 125 | */ |
| 126 | public interface BubbleStateChangeListener { |
| 127 | /** |
| 128 | * Called when the stack has bubbles or no longer has bubbles. |
| 129 | */ |
| 130 | void onHasBubblesChanged(boolean hasBubbles); |
| 131 | } |
| 132 | |
Mady Mellor | cd9b130 | 2018-11-06 18:08:04 -0800 | [diff] [blame] | 133 | /** |
| 134 | * Listener to find out about stack expansion / collapse events. |
| 135 | */ |
| 136 | public interface BubbleExpandListener { |
| 137 | /** |
| 138 | * Called when the expansion state of the bubble stack changes. |
Mady Mellor | cd9b130 | 2018-11-06 18:08:04 -0800 | [diff] [blame] | 139 | * @param isExpanding whether it's expanding or collapsing |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 140 | * @param key the notification key associated with bubble being expanded |
Mady Mellor | cd9b130 | 2018-11-06 18:08:04 -0800 | [diff] [blame] | 141 | */ |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 142 | void onBubbleExpandChanged(boolean isExpanding, String key); |
| 143 | } |
| 144 | |
| 145 | /** |
| 146 | * Listens for the current state of the status bar and updates the visibility state |
| 147 | * of bubbles as needed. |
| 148 | */ |
| 149 | private class StatusBarStateListener implements StatusBarStateController.StateListener { |
| 150 | private int mState; |
| 151 | /** |
| 152 | * Returns the current status bar state. |
| 153 | */ |
| 154 | public int getCurrentState() { |
| 155 | return mState; |
| 156 | } |
| 157 | |
| 158 | @Override |
| 159 | public void onStateChanged(int newState) { |
| 160 | mState = newState; |
| 161 | updateVisibility(); |
| 162 | } |
Mady Mellor | cd9b130 | 2018-11-06 18:08:04 -0800 | [diff] [blame] | 163 | } |
| 164 | |
Jason Monk | 27d01a62 | 2018-12-10 15:57:09 -0500 | [diff] [blame] | 165 | @Inject |
Mady Mellor | cfd06c1 | 2019-02-13 14:32:12 -0800 | [diff] [blame] | 166 | public BubbleController(Context context, StatusBarWindowController statusBarWindowController, |
| 167 | BubbleData data) { |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 168 | mContext = context; |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 169 | |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 170 | mNotificationEntryManager = Dependency.get(NotificationEntryManager.class); |
Ned Burns | 01e3821 | 2019-01-03 16:32:52 -0500 | [diff] [blame] | 171 | mNotificationEntryManager.addNotificationEntryListener(mEntryListener); |
Mady Mellor | b4991e6 | 2019-01-10 15:14:51 -0800 | [diff] [blame] | 172 | |
| 173 | try { |
| 174 | mNotificationManagerService = INotificationManager.Stub.asInterface( |
| 175 | ServiceManager.getServiceOrThrow(Context.NOTIFICATION_SERVICE)); |
| 176 | } catch (ServiceManager.ServiceNotFoundException e) { |
| 177 | e.printStackTrace(); |
| 178 | } |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 179 | |
| 180 | mStatusBarWindowController = statusBarWindowController; |
| 181 | mStatusBarStateListener = new StatusBarStateListener(); |
| 182 | Dependency.get(StatusBarStateController.class).addCallback(mStatusBarStateListener); |
Mark Renouf | cecc77b | 2019-01-30 16:32:24 -0500 | [diff] [blame] | 183 | |
| 184 | mActivityTaskManager = ActivityTaskManager.getService(); |
| 185 | mTaskStackListener = new BubbleTaskStackListener(); |
| 186 | ActivityManagerWrapper.getInstance().registerTaskStackListener(mTaskStackListener); |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 187 | |
Joshua Tsuji | a19515f | 2019-02-13 18:02:29 -0500 | [diff] [blame] | 188 | try { |
| 189 | WindowManagerWrapper.getInstance().addPinnedStackListener(new BubblesImeListener()); |
| 190 | } catch (RemoteException e) { |
| 191 | e.printStackTrace(); |
| 192 | } |
| 193 | |
Mady Mellor | cfd06c1 | 2019-02-13 14:32:12 -0800 | [diff] [blame] | 194 | mBubbleData = data; |
Mady Mellor | 5549dd2 | 2018-11-06 18:07:34 -0800 | [diff] [blame] | 195 | } |
| 196 | |
| 197 | /** |
Mady Mellor | d1c78b26 | 2018-11-06 18:04:40 -0800 | [diff] [blame] | 198 | * Set a listener to be notified when some states of the bubbles change. |
| 199 | */ |
| 200 | public void setBubbleStateChangeListener(BubbleStateChangeListener listener) { |
| 201 | mStateChangeListener = listener; |
| 202 | } |
| 203 | |
| 204 | /** |
Mady Mellor | cd9b130 | 2018-11-06 18:08:04 -0800 | [diff] [blame] | 205 | * Set a listener to be notified of bubble expand events. |
| 206 | */ |
| 207 | public void setExpandListener(BubbleExpandListener listener) { |
Issei Suzuki | ac9fcb7 | 2019-02-04 17:45:57 +0100 | [diff] [blame] | 208 | mExpandListener = ((isExpanding, key) -> { |
| 209 | if (listener != null) { |
| 210 | listener.onBubbleExpandChanged(isExpanding, key); |
| 211 | } |
| 212 | mStatusBarWindowController.setBubbleExpanded(isExpanding); |
| 213 | }); |
Mady Mellor | cd9b130 | 2018-11-06 18:08:04 -0800 | [diff] [blame] | 214 | if (mStackView != null) { |
| 215 | mStackView.setExpandListener(mExpandListener); |
| 216 | } |
| 217 | } |
| 218 | |
| 219 | /** |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 220 | * Whether or not there are bubbles present, regardless of them being visible on the |
| 221 | * screen (e.g. if on AOD). |
| 222 | */ |
| 223 | public boolean hasBubbles() { |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 224 | if (mStackView == null) { |
| 225 | return false; |
| 226 | } |
| 227 | for (Bubble bubble : mBubbleData.getBubbles()) { |
| 228 | if (!bubble.entry.isBubbleDismissed()) { |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 229 | return true; |
| 230 | } |
| 231 | } |
| 232 | return false; |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 233 | } |
| 234 | |
| 235 | /** |
| 236 | * Whether the stack of bubbles is expanded or not. |
| 237 | */ |
| 238 | public boolean isStackExpanded() { |
| 239 | return mStackView != null && mStackView.isExpanded(); |
| 240 | } |
| 241 | |
| 242 | /** |
| 243 | * Tell the stack of bubbles to collapse. |
| 244 | */ |
| 245 | public void collapseStack() { |
| 246 | if (mStackView != null) { |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 247 | mStackView.collapseStack(); |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 248 | } |
| 249 | } |
| 250 | |
| 251 | /** |
| 252 | * Tell the stack of bubbles to be dismissed, this will remove all of the bubbles in the stack. |
| 253 | */ |
Ned Burns | 01e3821 | 2019-01-03 16:32:52 -0500 | [diff] [blame] | 254 | void dismissStack() { |
Mady Mellor | d1c78b26 | 2018-11-06 18:04:40 -0800 | [diff] [blame] | 255 | if (mStackView == null) { |
| 256 | return; |
| 257 | } |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 258 | mStackView.stackDismissed(); |
| 259 | |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 260 | updateVisibility(); |
Ned Burns | 01e3821 | 2019-01-03 16:32:52 -0500 | [diff] [blame] | 261 | mNotificationEntryManager.updateNotifications(); |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 262 | } |
| 263 | |
| 264 | /** |
Mark Renouf | 041d726 | 2019-02-06 12:09:41 -0500 | [diff] [blame] | 265 | * Directs a back gesture at the bubble stack. When opened, the current expanded bubble |
| 266 | * is forwarded a back key down/up pair. |
| 267 | */ |
| 268 | public void performBackPressIfNeeded() { |
| 269 | if (mStackView != null) { |
| 270 | mStackView.performBackPressIfNeeded(); |
| 271 | } |
| 272 | } |
| 273 | |
| 274 | /** |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 275 | * Adds or updates a bubble associated with the provided notification entry. |
| 276 | * |
| 277 | * @param notif the notification associated with this bubble. |
| 278 | * @param updatePosition whether this update should promote the bubble to the top of the stack. |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 279 | */ |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 280 | public void updateBubble(NotificationEntry notif, boolean updatePosition) { |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 281 | if (mStackView != null && mBubbleData.getBubble(notif.key) != null) { |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 282 | // It's an update |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 283 | mStackView.updateBubble(notif, updatePosition); |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 284 | } else { |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 285 | if (mStackView == null) { |
Mady Mellor | cfd06c1 | 2019-02-13 14:32:12 -0800 | [diff] [blame] | 286 | mStackView = new BubbleStackView(mContext, mBubbleData); |
Mady Mellor | d1c78b26 | 2018-11-06 18:04:40 -0800 | [diff] [blame] | 287 | ViewGroup sbv = mStatusBarWindowController.getStatusBarView(); |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 288 | // XXX: Bug when you expand the shade on top of expanded bubble, there is no scrim |
| 289 | // between bubble and the shade |
| 290 | int bubblePosition = sbv.indexOfChild(sbv.findViewById(R.id.scrim_behind)) + 1; |
| 291 | sbv.addView(mStackView, bubblePosition, |
Joshua Tsuji | b1a796b | 2019-01-16 15:43:12 -0800 | [diff] [blame] | 292 | new FrameLayout.LayoutParams(MATCH_PARENT, MATCH_PARENT)); |
Mady Mellor | cd9b130 | 2018-11-06 18:08:04 -0800 | [diff] [blame] | 293 | if (mExpandListener != null) { |
| 294 | mStackView.setExpandListener(mExpandListener); |
| 295 | } |
Mady Mellor | e8e0771 | 2019-01-23 12:45:33 -0800 | [diff] [blame] | 296 | mStackView.setOnBlockedListener(this); |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 297 | } |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 298 | // It's new |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 299 | mStackView.addBubble(notif); |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 300 | } |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 301 | updateVisibility(); |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 302 | } |
| 303 | |
| 304 | /** |
| 305 | * Removes the bubble associated with the {@param uri}. |
Mark Renouf | 658c6bc | 2019-01-30 10:26:54 -0500 | [diff] [blame] | 306 | * <p> |
| 307 | * Must be called from the main thread. |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 308 | */ |
Mark Renouf | 658c6bc | 2019-01-30 10:26:54 -0500 | [diff] [blame] | 309 | @MainThread |
Ned Burns | 01e3821 | 2019-01-03 16:32:52 -0500 | [diff] [blame] | 310 | void removeBubble(String key) { |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 311 | if (mStackView != null) { |
| 312 | mStackView.removeBubble(key); |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 313 | } |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 314 | mNotificationEntryManager.updateNotifications(); |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 315 | updateVisibility(); |
Mady Mellor | d1c78b26 | 2018-11-06 18:04:40 -0800 | [diff] [blame] | 316 | } |
| 317 | |
Mady Mellor | e8e0771 | 2019-01-23 12:45:33 -0800 | [diff] [blame] | 318 | @Override |
| 319 | public void onBubbleBlocked(NotificationEntry entry) { |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 320 | Object[] bubbles = mBubbleData.getBubbles().toArray(); |
Mady Mellor | e8e0771 | 2019-01-23 12:45:33 -0800 | [diff] [blame] | 321 | for (int i = 0; i < bubbles.length; i++) { |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 322 | NotificationEntry e = ((Bubble) bubbles[i]).entry; |
Mady Mellor | e8e0771 | 2019-01-23 12:45:33 -0800 | [diff] [blame] | 323 | boolean samePackage = entry.notification.getPackageName().equals( |
| 324 | e.notification.getPackageName()); |
| 325 | if (samePackage) { |
| 326 | removeBubble(entry.key); |
| 327 | } |
| 328 | } |
| 329 | } |
| 330 | |
Ned Burns | 01e3821 | 2019-01-03 16:32:52 -0500 | [diff] [blame] | 331 | @SuppressWarnings("FieldCanBeLocal") |
| 332 | private final NotificationEntryListener mEntryListener = new NotificationEntryListener() { |
| 333 | @Override |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 334 | public void onPendingEntryAdded(NotificationEntry entry) { |
Mady Mellor | f6e3ac0 | 2019-01-29 10:37:52 -0800 | [diff] [blame] | 335 | if (!areBubblesEnabled(mContext)) { |
| 336 | return; |
| 337 | } |
| 338 | if (shouldAutoBubbleForFlags(mContext, entry) || shouldBubble(entry)) { |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 339 | // TODO: handle group summaries |
| 340 | // It's a new notif, it shows in the shade and as a bubble |
Ned Burns | 01e3821 | 2019-01-03 16:32:52 -0500 | [diff] [blame] | 341 | entry.setIsBubble(true); |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 342 | entry.setShowInShadeWhenBubble(true); |
| 343 | } |
| 344 | } |
| 345 | |
| 346 | @Override |
Ned Burns | 1a5e22f | 2019-02-14 15:11:52 -0500 | [diff] [blame] | 347 | public void onEntryInflated(NotificationEntry entry, @InflationFlag int inflatedFlags) { |
Mady Mellor | f6e3ac0 | 2019-01-29 10:37:52 -0800 | [diff] [blame] | 348 | if (!areBubblesEnabled(mContext)) { |
| 349 | return; |
| 350 | } |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 351 | if (entry.isBubble() && mNotificationInterruptionStateProvider.shouldBubbleUp(entry)) { |
| 352 | updateBubble(entry, true /* updatePosition */); |
| 353 | } |
| 354 | } |
| 355 | |
| 356 | @Override |
| 357 | public void onPreEntryUpdated(NotificationEntry entry) { |
Mady Mellor | f6e3ac0 | 2019-01-29 10:37:52 -0800 | [diff] [blame] | 358 | if (!areBubblesEnabled(mContext)) { |
| 359 | return; |
| 360 | } |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 361 | if (mNotificationInterruptionStateProvider.shouldBubbleUp(entry) |
| 362 | && alertAgain(entry, entry.notification.getNotification())) { |
| 363 | entry.setShowInShadeWhenBubble(true); |
| 364 | entry.setBubbleDismissed(false); // updates come back as bubbles even if dismissed |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 365 | updateBubble(entry, true /* updatePosition */); |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 366 | mStackView.updateDotVisibility(entry.key); |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 367 | } |
| 368 | } |
| 369 | |
| 370 | @Override |
| 371 | public void onEntryRemoved(NotificationEntry entry, |
| 372 | @Nullable NotificationVisibility visibility, |
| 373 | boolean removedByUser) { |
Mady Mellor | f6e3ac0 | 2019-01-29 10:37:52 -0800 | [diff] [blame] | 374 | if (!areBubblesEnabled(mContext)) { |
| 375 | return; |
| 376 | } |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 377 | entry.setShowInShadeWhenBubble(false); |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 378 | if (mStackView != null) { |
| 379 | mStackView.updateDotVisibility(entry.key); |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 380 | } |
| 381 | if (!removedByUser) { |
| 382 | // This was a cancel so we should remove the bubble |
| 383 | removeBubble(entry.key); |
Ned Burns | 01e3821 | 2019-01-03 16:32:52 -0500 | [diff] [blame] | 384 | } |
| 385 | } |
| 386 | }; |
| 387 | |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 388 | /** |
| 389 | * Lets any listeners know if bubble state has changed. |
| 390 | */ |
Mady Mellor | d1c78b26 | 2018-11-06 18:04:40 -0800 | [diff] [blame] | 391 | private void updateBubblesShowing() { |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 392 | if (mStackView == null) { |
| 393 | return; |
Mady Mellor | d1c78b26 | 2018-11-06 18:04:40 -0800 | [diff] [blame] | 394 | } |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 395 | |
Mady Mellor | d1c78b26 | 2018-11-06 18:04:40 -0800 | [diff] [blame] | 396 | boolean hadBubbles = mStatusBarWindowController.getBubblesShowing(); |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 397 | boolean hasBubblesShowing = hasBubbles() && mStackView.getVisibility() == VISIBLE; |
Mady Mellor | d1c78b26 | 2018-11-06 18:04:40 -0800 | [diff] [blame] | 398 | mStatusBarWindowController.setBubblesShowing(hasBubblesShowing); |
Mady Mellor | d1c78b26 | 2018-11-06 18:04:40 -0800 | [diff] [blame] | 399 | if (mStateChangeListener != null && hadBubbles != hasBubblesShowing) { |
| 400 | mStateChangeListener.onHasBubblesChanged(hasBubblesShowing); |
| 401 | } |
Mady Mellor | 5549dd2 | 2018-11-06 18:07:34 -0800 | [diff] [blame] | 402 | } |
| 403 | |
| 404 | /** |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 405 | * Updates the visibility of the bubbles based on current state. |
| 406 | * Does not un-bubble, just hides or un-hides. Will notify any |
| 407 | * {@link BubbleStateChangeListener}s if visibility changes. |
Mady Mellor | 5549dd2 | 2018-11-06 18:07:34 -0800 | [diff] [blame] | 408 | */ |
Mady Mellor | 3f2efdb | 2018-11-21 11:30:45 -0800 | [diff] [blame] | 409 | public void updateVisibility() { |
| 410 | if (mStatusBarStateListener.getCurrentState() == SHADE && hasBubbles()) { |
| 411 | // Bubbles only appear in unlocked shade |
| 412 | mStackView.setVisibility(hasBubbles() ? VISIBLE : INVISIBLE); |
| 413 | } else if (mStackView != null) { |
| 414 | mStackView.setVisibility(INVISIBLE); |
| 415 | collapseStack(); |
Mady Mellor | 5549dd2 | 2018-11-06 18:07:34 -0800 | [diff] [blame] | 416 | } |
Mady Mellor | d1c78b26 | 2018-11-06 18:04:40 -0800 | [diff] [blame] | 417 | updateBubblesShowing(); |
| 418 | } |
| 419 | |
| 420 | /** |
| 421 | * Rect indicating the touchable region for the bubble stack / expanded stack. |
| 422 | */ |
| 423 | public Rect getTouchableRegion() { |
| 424 | if (mStackView == null || mStackView.getVisibility() != VISIBLE) { |
| 425 | return null; |
| 426 | } |
| 427 | mStackView.getBoundsOnScreen(mTempRect); |
| 428 | return mTempRect; |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 429 | } |
| 430 | |
Mady Mellor | f6e3ac0 | 2019-01-29 10:37:52 -0800 | [diff] [blame] | 431 | @VisibleForTesting |
| 432 | BubbleStackView getStackView() { |
| 433 | return mStackView; |
| 434 | } |
| 435 | |
Mady Mellor | 5549dd2 | 2018-11-06 18:07:34 -0800 | [diff] [blame] | 436 | /** |
Mady Mellor | b4991e6 | 2019-01-10 15:14:51 -0800 | [diff] [blame] | 437 | * Whether the notification has been developer configured to bubble and is allowed by the user. |
| 438 | */ |
Mady Mellor | c18ba96 | 2019-01-29 11:11:56 -0800 | [diff] [blame] | 439 | @VisibleForTesting |
| 440 | protected boolean shouldBubble(NotificationEntry entry) { |
Mady Mellor | b4991e6 | 2019-01-10 15:14:51 -0800 | [diff] [blame] | 441 | StatusBarNotification n = entry.notification; |
Mady Mellor | c39b4ae | 2019-01-09 17:11:37 -0800 | [diff] [blame] | 442 | boolean hasOverlayIntent = n.getNotification().getBubbleMetadata() != null |
| 443 | && n.getNotification().getBubbleMetadata().getIntent() != null; |
Julia Reynolds | 4509ce7 | 2019-01-31 13:12:43 -0500 | [diff] [blame] | 444 | return hasOverlayIntent && entry.canBubble; |
Mady Mellor | b4991e6 | 2019-01-10 15:14:51 -0800 | [diff] [blame] | 445 | } |
| 446 | |
| 447 | /** |
Mady Mellor | f6e3ac0 | 2019-01-29 10:37:52 -0800 | [diff] [blame] | 448 | * Whether the notification should automatically bubble or not. Gated by secure settings flags. |
Mady Mellor | 5549dd2 | 2018-11-06 18:07:34 -0800 | [diff] [blame] | 449 | */ |
Mady Mellor | 9bad224 | 2019-01-28 11:21:51 -0800 | [diff] [blame] | 450 | @VisibleForTesting |
Mady Mellor | f6e3ac0 | 2019-01-29 10:37:52 -0800 | [diff] [blame] | 451 | protected boolean shouldAutoBubbleForFlags(Context context, NotificationEntry entry) { |
Mady Mellor | ceced17 | 2018-11-27 11:18:39 -0800 | [diff] [blame] | 452 | if (entry.isBubbleDismissed()) { |
Mady Mellor | 5549dd2 | 2018-11-06 18:07:34 -0800 | [diff] [blame] | 453 | return false; |
| 454 | } |
Mady Mellor | b4991e6 | 2019-01-10 15:14:51 -0800 | [diff] [blame] | 455 | StatusBarNotification n = entry.notification; |
Mady Mellor | ceced17 | 2018-11-27 11:18:39 -0800 | [diff] [blame] | 456 | |
| 457 | boolean autoBubbleMessages = shouldAutoBubbleMessages(context) || DEBUG_ENABLE_AUTO_BUBBLE; |
| 458 | boolean autoBubbleOngoing = shouldAutoBubbleOngoing(context) || DEBUG_ENABLE_AUTO_BUBBLE; |
| 459 | boolean autoBubbleAll = shouldAutoBubbleAll(context) || DEBUG_ENABLE_AUTO_BUBBLE; |
| 460 | |
Mady Mellor | 5549dd2 | 2018-11-06 18:07:34 -0800 | [diff] [blame] | 461 | boolean hasRemoteInput = false; |
| 462 | if (n.getNotification().actions != null) { |
| 463 | for (Notification.Action action : n.getNotification().actions) { |
| 464 | if (action.getRemoteInputs() != null) { |
| 465 | hasRemoteInput = true; |
| 466 | break; |
| 467 | } |
| 468 | } |
| 469 | } |
Mady Mellor | 711f956 | 2018-12-05 14:53:46 -0800 | [diff] [blame] | 470 | boolean isCall = Notification.CATEGORY_CALL.equals(n.getNotification().category) |
| 471 | && n.isOngoing(); |
| 472 | boolean isMusic = n.getNotification().hasMediaSession(); |
| 473 | boolean isImportantOngoing = isMusic || isCall; |
Mady Mellor | ceced17 | 2018-11-27 11:18:39 -0800 | [diff] [blame] | 474 | |
Mady Mellor | 5549dd2 | 2018-11-06 18:07:34 -0800 | [diff] [blame] | 475 | Class<? extends Notification.Style> style = n.getNotification().getNotificationStyle(); |
Mady Mellor | e317537 | 2018-12-04 17:05:11 -0800 | [diff] [blame] | 476 | boolean isMessageType = Notification.CATEGORY_MESSAGE.equals(n.getNotification().category); |
| 477 | boolean isMessageStyle = Notification.MessagingStyle.class.equals(style); |
Mady Mellor | f6e3ac0 | 2019-01-29 10:37:52 -0800 | [diff] [blame] | 478 | return (((isMessageType && hasRemoteInput) || isMessageStyle) && autoBubbleMessages) |
Mady Mellor | 711f956 | 2018-12-05 14:53:46 -0800 | [diff] [blame] | 479 | || (isImportantOngoing && autoBubbleOngoing) |
Mady Mellor | ceced17 | 2018-11-27 11:18:39 -0800 | [diff] [blame] | 480 | || autoBubbleAll; |
| 481 | } |
| 482 | |
Mark Renouf | cecc77b | 2019-01-30 16:32:24 -0500 | [diff] [blame] | 483 | /** |
| 484 | * This task stack listener is responsible for responding to tasks moved to the front |
| 485 | * which are on the default (main) display. When this happens, expanded bubbles must be |
| 486 | * collapsed so the user may interact with the app which was just moved to the front. |
| 487 | * <p> |
| 488 | * This listener is registered with SystemUI's ActivityManagerWrapper which dispatches |
| 489 | * these calls via a main thread Handler. |
| 490 | */ |
| 491 | @MainThread |
| 492 | private class BubbleTaskStackListener extends TaskStackChangeListener { |
| 493 | |
| 494 | @Nullable |
| 495 | private ActivityManager.StackInfo findStackInfo(int taskId) throws RemoteException { |
| 496 | final List<ActivityManager.StackInfo> stackInfoList = |
| 497 | mActivityTaskManager.getAllStackInfos(); |
| 498 | // Iterate through stacks from top to bottom. |
| 499 | final int stackCount = stackInfoList.size(); |
| 500 | for (int stackIndex = 0; stackIndex < stackCount; stackIndex++) { |
| 501 | final ActivityManager.StackInfo stackInfo = stackInfoList.get(stackIndex); |
| 502 | // Iterate through tasks from top to bottom. |
| 503 | for (int taskIndex = stackInfo.taskIds.length - 1; taskIndex >= 0; taskIndex--) { |
| 504 | if (stackInfo.taskIds[taskIndex] == taskId) { |
| 505 | return stackInfo; |
| 506 | } |
| 507 | } |
| 508 | } |
| 509 | return null; |
| 510 | } |
| 511 | |
| 512 | @Override |
Mark Renouf | c808f06 | 2019-02-07 15:20:37 -0500 | [diff] [blame] | 513 | public void onTaskMovedToFront(RunningTaskInfo taskInfo) { |
| 514 | if (mStackView != null && taskInfo.displayId == Display.DEFAULT_DISPLAY) { |
Mark Renouf | cecc77b | 2019-01-30 16:32:24 -0500 | [diff] [blame] | 515 | mStackView.collapseStack(); |
| 516 | } |
| 517 | } |
| 518 | |
| 519 | /** |
| 520 | * This is a workaround for the case when the activity had to be created in a new task. |
| 521 | * Existing code in ActivityStackSupervisor checks the display where the activity |
| 522 | * ultimately ended up, displays an error message toast, and calls this method instead of |
| 523 | * onTaskMovedToFront. |
| 524 | */ |
Mark Renouf | cecc77b | 2019-01-30 16:32:24 -0500 | [diff] [blame] | 525 | @Override |
Mark Renouf | c808f06 | 2019-02-07 15:20:37 -0500 | [diff] [blame] | 526 | public void onActivityLaunchOnSecondaryDisplayFailed(RunningTaskInfo taskInfo) { |
| 527 | // TODO(b/124058588): move to ActivityView.StateCallback, filter on virtualDisplay ID |
Mark Renouf | cecc77b | 2019-01-30 16:32:24 -0500 | [diff] [blame] | 528 | if (mStackView != null) { |
| 529 | mStackView.collapseStack(); |
| 530 | } |
| 531 | } |
| 532 | } |
| 533 | |
Mady Mellor | ceced17 | 2018-11-27 11:18:39 -0800 | [diff] [blame] | 534 | private static boolean shouldAutoBubbleMessages(Context context) { |
| 535 | return Settings.Secure.getInt(context.getContentResolver(), |
| 536 | ENABLE_AUTO_BUBBLE_MESSAGES, 0) != 0; |
| 537 | } |
| 538 | |
| 539 | private static boolean shouldAutoBubbleOngoing(Context context) { |
| 540 | return Settings.Secure.getInt(context.getContentResolver(), |
| 541 | ENABLE_AUTO_BUBBLE_ONGOING, 0) != 0; |
| 542 | } |
| 543 | |
| 544 | private static boolean shouldAutoBubbleAll(Context context) { |
| 545 | return Settings.Secure.getInt(context.getContentResolver(), |
| 546 | ENABLE_AUTO_BUBBLE_ALL, 0) != 0; |
Mady Mellor | 5549dd2 | 2018-11-06 18:07:34 -0800 | [diff] [blame] | 547 | } |
Mark Renouf | 89b1a4a | 2018-12-04 14:59:45 -0500 | [diff] [blame] | 548 | |
Mady Mellor | 3dff9e6 | 2019-02-05 18:12:53 -0800 | [diff] [blame] | 549 | static boolean shouldUseContentIntent(Context context) { |
Mark Renouf | 89b1a4a | 2018-12-04 14:59:45 -0500 | [diff] [blame] | 550 | return Settings.Secure.getInt(context.getContentResolver(), |
| 551 | ENABLE_BUBBLE_CONTENT_INTENT, 0) != 0; |
| 552 | } |
Mady Mellor | f6e3ac0 | 2019-01-29 10:37:52 -0800 | [diff] [blame] | 553 | |
| 554 | private static boolean areBubblesEnabled(Context context) { |
| 555 | return Settings.Secure.getInt(context.getContentResolver(), |
| 556 | ENABLE_BUBBLES, 1) != 0; |
| 557 | } |
Joshua Tsuji | a19515f | 2019-02-13 18:02:29 -0500 | [diff] [blame] | 558 | |
Mady Mellor | 44ee2fe | 2019-01-30 17:51:16 -0800 | [diff] [blame] | 559 | /** |
| 560 | * Whether bubbles should be positioned at the top of the screen or not. |
| 561 | */ |
| 562 | public static boolean showBubblesAtTop(Context context) { |
| 563 | return Settings.Secure.getInt(context.getContentResolver(), |
| 564 | ENABLE_BUBBLES_AT_TOP, 0) != 0; |
| 565 | } |
| 566 | |
| 567 | /** |
| 568 | * Whether the bubble chrome should display as a footer or not (in which case it's a header). |
| 569 | */ |
| 570 | public static boolean useFooter(Context context) { |
| 571 | return Settings.Secure.getInt(context.getContentResolver(), |
| 572 | ENABLE_BUBBLE_FOOTER, 0) != 0; |
| 573 | } |
| 574 | |
Joshua Tsuji | 010c2b1 | 2019-02-25 18:11:25 -0500 | [diff] [blame^] | 575 | /** Default stiffness to use for bubble physics animations. */ |
| 576 | public static int getBubbleStiffness(Context context, int defaultStiffness) { |
| 577 | return Settings.Secure.getInt( |
| 578 | context.getContentResolver(), BUBBLE_STIFFNESS, defaultStiffness); |
| 579 | } |
| 580 | |
| 581 | /** Default bounciness/damping ratio to use for bubble physics animations. */ |
| 582 | public static float getBubbleBounciness(Context context, float defaultBounciness) { |
| 583 | return Settings.Secure.getInt( |
| 584 | context.getContentResolver(), |
| 585 | BUBBLE_BOUNCINESS, |
| 586 | (int) (defaultBounciness * 100)) / 100f; |
| 587 | } |
| 588 | |
Joshua Tsuji | a19515f | 2019-02-13 18:02:29 -0500 | [diff] [blame] | 589 | /** PinnedStackListener that dispatches IME visibility updates to the stack. */ |
| 590 | private class BubblesImeListener extends IPinnedStackListener.Stub { |
| 591 | |
| 592 | @Override |
| 593 | public void onListenerRegistered(IPinnedStackController controller) throws RemoteException { |
| 594 | } |
| 595 | |
| 596 | @Override |
| 597 | public void onMovementBoundsChanged(Rect insetBounds, Rect normalBounds, |
| 598 | Rect animatingBounds, boolean fromImeAdjustment, boolean fromShelfAdjustment, |
| 599 | int displayRotation) throws RemoteException {} |
| 600 | |
| 601 | @Override |
| 602 | public void onImeVisibilityChanged(boolean imeVisible, int imeHeight) |
| 603 | throws RemoteException { |
| 604 | if (mStackView != null) { |
| 605 | mStackView.post(() -> { |
| 606 | mStackView.onImeVisibilityChanged(imeVisible, imeHeight); |
| 607 | }); |
| 608 | } |
| 609 | } |
| 610 | |
| 611 | @Override |
| 612 | public void onShelfVisibilityChanged(boolean shelfVisible, int shelfHeight) |
| 613 | throws RemoteException {} |
| 614 | |
| 615 | @Override |
| 616 | public void onMinimizedStateChanged(boolean isMinimized) throws RemoteException {} |
| 617 | |
| 618 | @Override |
| 619 | public void onActionsChanged(ParceledListSlice actions) throws RemoteException {} |
| 620 | } |
Mady Mellor | c3d6f7d | 2018-11-07 09:36:56 -0800 | [diff] [blame] | 621 | } |