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