yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [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.statusbar.phone; |
| 18 | |
| 19 | import android.annotation.NonNull; |
| 20 | import android.annotation.Nullable; |
| 21 | import android.content.Context; |
Adrian Roos | 22af650 | 2018-02-22 16:57:08 +0100 | [diff] [blame] | 22 | import android.content.res.Configuration; |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 23 | import android.content.res.Resources; |
Issei Suzuki | 43190bd | 2018-08-20 17:28:41 +0200 | [diff] [blame] | 24 | import android.graphics.Rect; |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 25 | import android.util.Log; |
| 26 | import android.util.Pools; |
Jorim Jaggi | 71aaa40 | 2018-06-06 17:22:56 +0200 | [diff] [blame] | 27 | import android.view.DisplayCutout; |
| 28 | import android.view.Gravity; |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 29 | import android.view.View; |
| 30 | import android.view.ViewTreeObserver; |
| 31 | |
Gus Prevas | ab33679 | 2018-11-14 13:52:20 -0500 | [diff] [blame] | 32 | import androidx.collection.ArraySet; |
| 33 | |
Jason Monk | 1fd3fc3 | 2018-08-14 17:20:09 -0400 | [diff] [blame] | 34 | import com.android.systemui.Dependency; |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 35 | import com.android.systemui.Dumpable; |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 36 | import com.android.systemui.R; |
Jorim Jaggi | 71aaa40 | 2018-06-06 17:22:56 +0200 | [diff] [blame] | 37 | import com.android.systemui.ScreenDecorations; |
Beverly | 8fdb533 | 2019-02-04 14:29:49 -0500 | [diff] [blame] | 38 | import com.android.systemui.plugins.statusbar.StatusBarStateController; |
| 39 | import com.android.systemui.plugins.statusbar.StatusBarStateController.StateListener; |
Jason Monk | 1fd3fc3 | 2018-08-14 17:20:09 -0400 | [diff] [blame] | 40 | import com.android.systemui.statusbar.StatusBarState; |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 41 | import com.android.systemui.statusbar.notification.VisualStabilityManager; |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 42 | import com.android.systemui.statusbar.notification.collection.NotificationEntry; |
Gus Prevas | ab33679 | 2018-11-14 13:52:20 -0500 | [diff] [blame] | 43 | import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow; |
Adrian Roos | 22af650 | 2018-02-22 16:57:08 +0100 | [diff] [blame] | 44 | import com.android.systemui.statusbar.policy.ConfigurationController; |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 45 | import com.android.systemui.statusbar.policy.HeadsUpManager; |
| 46 | import com.android.systemui.statusbar.policy.OnHeadsUpChangedListener; |
| 47 | |
| 48 | import java.io.FileDescriptor; |
| 49 | import java.io.PrintWriter; |
| 50 | import java.util.HashSet; |
| 51 | import java.util.Stack; |
| 52 | |
| 53 | /** |
| 54 | * A implementation of HeadsUpManager for phone and car. |
| 55 | */ |
| 56 | public class HeadsUpManagerPhone extends HeadsUpManager implements Dumpable, |
James O'Leary | cbea84d | 2019-03-14 11:18:24 -0400 | [diff] [blame] | 57 | VisualStabilityManager.Callback, OnHeadsUpChangedListener, |
| 58 | ConfigurationController.ConfigurationListener, StateListener { |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 59 | private static final String TAG = "HeadsUpManagerPhone"; |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 60 | |
| 61 | private final View mStatusBarWindowView; |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 62 | private final NotificationGroupManager mGroupManager; |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 63 | private final VisualStabilityManager mVisualStabilityManager; |
James O'Leary | cbea84d | 2019-03-14 11:18:24 -0400 | [diff] [blame] | 64 | private final StatusBarTouchableRegionManager mStatusBarTouchableRegionManager; |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 65 | private boolean mReleaseOnExpandFinish; |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 66 | |
| 67 | private int mStatusBarHeight; |
| 68 | private int mHeadsUpInset; |
Jorim Jaggi | 71aaa40 | 2018-06-06 17:22:56 +0200 | [diff] [blame] | 69 | private int mDisplayCutoutTouchableRegionSize; |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 70 | private boolean mTrackingHeadsUp; |
| 71 | private HashSet<String> mSwipedOutKeys = new HashSet<>(); |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 72 | private HashSet<NotificationEntry> mEntriesToRemoveAfterExpand = new HashSet<>(); |
| 73 | private ArraySet<NotificationEntry> mEntriesToRemoveWhenReorderingAllowed |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 74 | = new ArraySet<>(); |
| 75 | private boolean mIsExpanded; |
| 76 | private int[] mTmpTwoArray = new int[2]; |
| 77 | private boolean mHeadsUpGoingAway; |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 78 | private int mStatusBarState; |
Winson Chung | 9cd2115 | 2019-05-28 15:04:08 -0700 | [diff] [blame] | 79 | private Rect mTouchableRegion = new Rect(); |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 80 | |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 81 | private AnimationStateHandler mAnimationStateHandler; |
Jason Monk | 1fd3fc3 | 2018-08-14 17:20:09 -0400 | [diff] [blame] | 82 | |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 83 | private final Pools.Pool<HeadsUpEntryPhone> mEntryPool = new Pools.Pool<HeadsUpEntryPhone>() { |
| 84 | private Stack<HeadsUpEntryPhone> mPoolObjects = new Stack<>(); |
| 85 | |
| 86 | @Override |
| 87 | public HeadsUpEntryPhone acquire() { |
| 88 | if (!mPoolObjects.isEmpty()) { |
| 89 | return mPoolObjects.pop(); |
| 90 | } |
| 91 | return new HeadsUpEntryPhone(); |
| 92 | } |
| 93 | |
| 94 | @Override |
| 95 | public boolean release(@NonNull HeadsUpEntryPhone instance) { |
| 96 | mPoolObjects.push(instance); |
| 97 | return true; |
| 98 | } |
| 99 | }; |
| 100 | |
| 101 | /////////////////////////////////////////////////////////////////////////////////////////////// |
| 102 | // Constructor: |
| 103 | |
James O'Leary | cbea84d | 2019-03-14 11:18:24 -0400 | [diff] [blame] | 104 | public HeadsUpManagerPhone(@NonNull final Context context, |
| 105 | @NonNull View statusBarWindowView, |
| 106 | @NonNull NotificationGroupManager groupManager, |
| 107 | @NonNull StatusBar bar, |
| 108 | @NonNull VisualStabilityManager visualStabilityManager) { |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 109 | super(context); |
| 110 | |
| 111 | mStatusBarWindowView = statusBarWindowView; |
James O'Leary | cbea84d | 2019-03-14 11:18:24 -0400 | [diff] [blame] | 112 | mStatusBarTouchableRegionManager = new StatusBarTouchableRegionManager(context, this, bar, |
| 113 | statusBarWindowView); |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 114 | mGroupManager = groupManager; |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 115 | mVisualStabilityManager = visualStabilityManager; |
| 116 | |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 117 | initResources(); |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 118 | |
| 119 | addListener(new OnHeadsUpChangedListener() { |
| 120 | @Override |
| 121 | public void onHeadsUpPinnedModeChanged(boolean hasPinnedNotification) { |
Kevin | d4f66a4 | 2018-08-03 13:12:51 -0700 | [diff] [blame] | 122 | if (Log.isLoggable(TAG, Log.WARN)) { |
| 123 | Log.w(TAG, "onHeadsUpPinnedModeChanged"); |
| 124 | } |
James O'Leary | cbea84d | 2019-03-14 11:18:24 -0400 | [diff] [blame] | 125 | mStatusBarTouchableRegionManager.updateTouchableRegion(); |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 126 | } |
| 127 | }); |
Lucas Dupin | 7fc9dc1 | 2019-01-03 09:19:43 -0800 | [diff] [blame] | 128 | Dependency.get(StatusBarStateController.class).addCallback(this); |
Jason Monk | 1fd3fc3 | 2018-08-14 17:20:09 -0400 | [diff] [blame] | 129 | } |
| 130 | |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 131 | public void setAnimationStateHandler(AnimationStateHandler handler) { |
| 132 | mAnimationStateHandler = handler; |
| 133 | } |
| 134 | |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 135 | private void initResources() { |
| 136 | Resources resources = mContext.getResources(); |
| 137 | mStatusBarHeight = resources.getDimensionPixelSize( |
| 138 | com.android.internal.R.dimen.status_bar_height); |
| 139 | mHeadsUpInset = mStatusBarHeight + resources.getDimensionPixelSize( |
| 140 | R.dimen.heads_up_status_bar_padding); |
Jorim Jaggi | 71aaa40 | 2018-06-06 17:22:56 +0200 | [diff] [blame] | 141 | mDisplayCutoutTouchableRegionSize = resources.getDimensionPixelSize( |
Jeff Chang | b0a061e | 2019-03-11 11:39:54 +0800 | [diff] [blame] | 142 | com.android.internal.R.dimen.display_cutout_touchable_region_size); |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | @Override |
| 146 | public void onDensityOrFontScaleChanged() { |
| 147 | super.onDensityOrFontScaleChanged(); |
| 148 | initResources(); |
| 149 | } |
| 150 | |
Jorim Jaggi | 71aaa40 | 2018-06-06 17:22:56 +0200 | [diff] [blame] | 151 | @Override |
| 152 | public void onOverlayChanged() { |
| 153 | initResources(); |
| 154 | } |
| 155 | |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 156 | /////////////////////////////////////////////////////////////////////////////////////////////// |
| 157 | // Public methods: |
| 158 | |
| 159 | /** |
| 160 | * Decides whether a click is invalid for a notification, i.e it has not been shown long enough |
| 161 | * that a user might have consciously clicked on it. |
| 162 | * |
| 163 | * @param key the key of the touched notification |
| 164 | * @return whether the touch is invalid and should be discarded |
| 165 | */ |
| 166 | public boolean shouldSwallowClick(@NonNull String key) { |
| 167 | HeadsUpManager.HeadsUpEntry entry = getHeadsUpEntry(key); |
Kevin | d4f66a4 | 2018-08-03 13:12:51 -0700 | [diff] [blame] | 168 | return entry != null && mClock.currentTimeMillis() < entry.mPostTime; |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | public void onExpandingFinished() { |
| 172 | if (mReleaseOnExpandFinish) { |
| 173 | releaseAllImmediately(); |
| 174 | mReleaseOnExpandFinish = false; |
| 175 | } else { |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 176 | for (NotificationEntry entry : mEntriesToRemoveAfterExpand) { |
Kevin | a97ea05 | 2018-09-11 13:53:18 -0700 | [diff] [blame] | 177 | if (isAlerting(entry.key)) { |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 178 | // Maybe the heads-up was removed already |
Kevin | d4f66a4 | 2018-08-03 13:12:51 -0700 | [diff] [blame] | 179 | removeAlertEntry(entry.key); |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 180 | } |
| 181 | } |
| 182 | } |
| 183 | mEntriesToRemoveAfterExpand.clear(); |
| 184 | } |
| 185 | |
| 186 | /** |
| 187 | * Sets the tracking-heads-up flag. If the flag is true, HeadsUpManager doesn't remove the entry |
| 188 | * from the list even after a Heads Up Notification is gone. |
| 189 | */ |
| 190 | public void setTrackingHeadsUp(boolean trackingHeadsUp) { |
| 191 | mTrackingHeadsUp = trackingHeadsUp; |
| 192 | } |
| 193 | |
| 194 | /** |
| 195 | * Notify that the status bar panel gets expanded or collapsed. |
| 196 | * |
| 197 | * @param isExpanded True to notify expanded, false to notify collapsed. |
| 198 | */ |
| 199 | public void setIsPanelExpanded(boolean isExpanded) { |
| 200 | if (isExpanded != mIsExpanded) { |
| 201 | mIsExpanded = isExpanded; |
| 202 | if (isExpanded) { |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 203 | mHeadsUpGoingAway = false; |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 204 | } |
James O'Leary | cbea84d | 2019-03-14 11:18:24 -0400 | [diff] [blame] | 205 | mStatusBarTouchableRegionManager.setIsStatusBarExpanded(isExpanded); |
| 206 | mStatusBarTouchableRegionManager.updateTouchableRegion(); |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 207 | } |
| 208 | } |
| 209 | |
Lucas Dupin | 7fc9dc1 | 2019-01-03 09:19:43 -0800 | [diff] [blame] | 210 | @Override |
| 211 | public void onStateChanged(int newState) { |
| 212 | mStatusBarState = newState; |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | /** |
| 216 | * Set that we are exiting the headsUp pinned mode, but some notifications might still be |
| 217 | * animating out. This is used to keep the touchable regions in a sane state. |
| 218 | */ |
| 219 | public void setHeadsUpGoingAway(boolean headsUpGoingAway) { |
| 220 | if (headsUpGoingAway != mHeadsUpGoingAway) { |
| 221 | mHeadsUpGoingAway = headsUpGoingAway; |
| 222 | if (!headsUpGoingAway) { |
James O'Leary | cbea84d | 2019-03-14 11:18:24 -0400 | [diff] [blame] | 223 | mStatusBarTouchableRegionManager.updateTouchableRegionAfterLayout(); |
| 224 | } else { |
| 225 | mStatusBarTouchableRegionManager.updateTouchableRegion(); |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 226 | } |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 227 | } |
| 228 | } |
| 229 | |
James O'Leary | cbea84d | 2019-03-14 11:18:24 -0400 | [diff] [blame] | 230 | public boolean isHeadsUpGoingAway() { |
| 231 | return mHeadsUpGoingAway; |
| 232 | } |
| 233 | |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 234 | /** |
| 235 | * Notifies that a remote input textbox in notification gets active or inactive. |
James O'Leary | cbea84d | 2019-03-14 11:18:24 -0400 | [diff] [blame] | 236 | * |
| 237 | * @param entry The entry of the target notification. |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 238 | * @param remoteInputActive True to notify active, False to notify inactive. |
| 239 | */ |
| 240 | public void setRemoteInputActive( |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 241 | @NonNull NotificationEntry entry, boolean remoteInputActive) { |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 242 | HeadsUpEntryPhone headsUpEntry = getHeadsUpEntryPhone(entry.key); |
| 243 | if (headsUpEntry != null && headsUpEntry.remoteInputActive != remoteInputActive) { |
| 244 | headsUpEntry.remoteInputActive = remoteInputActive; |
| 245 | if (remoteInputActive) { |
| 246 | headsUpEntry.removeAutoRemovalCallbacks(); |
| 247 | } else { |
| 248 | headsUpEntry.updateEntry(false /* updatePostTime */); |
| 249 | } |
| 250 | } |
| 251 | } |
| 252 | |
Gus Prevas | 21118153 | 2018-12-13 14:49:33 -0500 | [diff] [blame] | 253 | /** |
| 254 | * Sets whether an entry's menu row is exposed and therefore it should stick in the heads up |
| 255 | * area if it's pinned until it's hidden again. |
| 256 | */ |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 257 | public void setMenuShown(@NonNull NotificationEntry entry, boolean menuShown) { |
Gus Prevas | 21118153 | 2018-12-13 14:49:33 -0500 | [diff] [blame] | 258 | HeadsUpEntry headsUpEntry = getHeadsUpEntry(entry.key); |
| 259 | if (headsUpEntry instanceof HeadsUpEntryPhone && entry.isRowPinned()) { |
| 260 | ((HeadsUpEntryPhone) headsUpEntry).setMenuShownPinned(menuShown); |
| 261 | } |
| 262 | } |
| 263 | |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 264 | /////////////////////////////////////////////////////////////////////////////////////////////// |
| 265 | // HeadsUpManager public methods overrides: |
| 266 | |
| 267 | @Override |
| 268 | public boolean isTrackingHeadsUp() { |
| 269 | return mTrackingHeadsUp; |
| 270 | } |
| 271 | |
Kevin | d4f66a4 | 2018-08-03 13:12:51 -0700 | [diff] [blame] | 272 | @Override |
| 273 | public void snooze() { |
| 274 | super.snooze(); |
| 275 | mReleaseOnExpandFinish = true; |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 276 | } |
| 277 | |
| 278 | public void addSwipedOutNotification(@NonNull String key) { |
| 279 | mSwipedOutKeys.add(key); |
| 280 | } |
| 281 | |
| 282 | /////////////////////////////////////////////////////////////////////////////////////////////// |
| 283 | // Dumpable overrides: |
| 284 | |
| 285 | @Override |
| 286 | public void dump(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 287 | pw.println("HeadsUpManagerPhone state:"); |
| 288 | dumpInternal(fd, pw, args); |
| 289 | } |
| 290 | |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 291 | /** |
James O'Leary | cbea84d | 2019-03-14 11:18:24 -0400 | [diff] [blame] | 292 | * Update touch insets to include any area needed for touching a heads up notification. |
| 293 | * |
| 294 | * @param info Insets that will include heads up notification touch area after execution. |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 295 | */ |
James O'Leary | cbea84d | 2019-03-14 11:18:24 -0400 | [diff] [blame] | 296 | @Nullable |
| 297 | public void updateTouchableRegion(ViewTreeObserver.InternalInsetsInfo info) { |
| 298 | info.setTouchableInsets(ViewTreeObserver.InternalInsetsInfo.TOUCHABLE_INSETS_REGION); |
Winson Chung | 9cd2115 | 2019-05-28 15:04:08 -0700 | [diff] [blame] | 299 | info.touchableRegion.set(calculateTouchableRegion()); |
| 300 | } |
James O'Leary | cbea84d | 2019-03-14 11:18:24 -0400 | [diff] [blame] | 301 | |
Winson Chung | 9cd2115 | 2019-05-28 15:04:08 -0700 | [diff] [blame] | 302 | public Rect calculateTouchableRegion() { |
James O'Leary | cbea84d | 2019-03-14 11:18:24 -0400 | [diff] [blame] | 303 | if (!hasPinnedHeadsUp()) { |
Winson Chung | 9cd2115 | 2019-05-28 15:04:08 -0700 | [diff] [blame] | 304 | mTouchableRegion.set(0, 0, mStatusBarWindowView.getWidth(), mStatusBarHeight); |
| 305 | updateRegionForNotch(mTouchableRegion); |
James O'Leary | cbea84d | 2019-03-14 11:18:24 -0400 | [diff] [blame] | 306 | } else { |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 307 | NotificationEntry topEntry = getTopEntry(); |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 308 | if (topEntry.isChildInGroup()) { |
James O'Leary | cbea84d | 2019-03-14 11:18:24 -0400 | [diff] [blame] | 309 | final NotificationEntry groupSummary = |
| 310 | mGroupManager.getGroupSummary(topEntry.notification); |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 311 | if (groupSummary != null) { |
| 312 | topEntry = groupSummary; |
| 313 | } |
| 314 | } |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 315 | ExpandableNotificationRow topRow = topEntry.getRow(); |
| 316 | topRow.getLocationOnScreen(mTmpTwoArray); |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 317 | int minX = mTmpTwoArray[0]; |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 318 | int maxX = mTmpTwoArray[0] + topRow.getWidth(); |
| 319 | int height = topRow.getIntrinsicHeight(); |
Winson Chung | 9cd2115 | 2019-05-28 15:04:08 -0700 | [diff] [blame] | 320 | mTouchableRegion.set(minX, 0, maxX, mHeadsUpInset + height); |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 321 | } |
Winson Chung | 9cd2115 | 2019-05-28 15:04:08 -0700 | [diff] [blame] | 322 | return mTouchableRegion; |
Jorim Jaggi | 71aaa40 | 2018-06-06 17:22:56 +0200 | [diff] [blame] | 323 | } |
| 324 | |
Winson Chung | 9cd2115 | 2019-05-28 15:04:08 -0700 | [diff] [blame] | 325 | private void updateRegionForNotch(Rect region) { |
Jorim Jaggi | 71aaa40 | 2018-06-06 17:22:56 +0200 | [diff] [blame] | 326 | DisplayCutout cutout = mStatusBarWindowView.getRootWindowInsets().getDisplayCutout(); |
| 327 | if (cutout == null) { |
| 328 | return; |
| 329 | } |
| 330 | |
| 331 | // Expand touchable region such that we also catch touches that just start below the notch |
| 332 | // area. |
Issei Suzuki | 43190bd | 2018-08-20 17:28:41 +0200 | [diff] [blame] | 333 | Rect bounds = new Rect(); |
| 334 | ScreenDecorations.DisplayCutoutView.boundsFromDirection(cutout, Gravity.TOP, bounds); |
| 335 | bounds.offset(0, mDisplayCutoutTouchableRegionSize); |
Winson Chung | 9cd2115 | 2019-05-28 15:04:08 -0700 | [diff] [blame] | 336 | region.union(bounds); |
Jorim Jaggi | 71aaa40 | 2018-06-06 17:22:56 +0200 | [diff] [blame] | 337 | } |
| 338 | |
Adrian Roos | 22af650 | 2018-02-22 16:57:08 +0100 | [diff] [blame] | 339 | @Override |
Selim Cinek | bd55909 | 2019-01-28 19:38:58 -0800 | [diff] [blame] | 340 | public boolean shouldExtendLifetime(NotificationEntry entry) { |
| 341 | // We should not defer the removal if reordering isn't allowed since otherwise |
| 342 | // these won't disappear until reordering is allowed again, which happens only once |
| 343 | // the notification panel is collapsed again. |
| 344 | return mVisualStabilityManager.isReorderingAllowed() && super.shouldExtendLifetime(entry); |
| 345 | } |
| 346 | |
| 347 | @Override |
Adrian Roos | 22af650 | 2018-02-22 16:57:08 +0100 | [diff] [blame] | 348 | public void onConfigChanged(Configuration newConfig) { |
James O'Leary | cbea84d | 2019-03-14 11:18:24 -0400 | [diff] [blame] | 349 | initResources(); |
Adrian Roos | 22af650 | 2018-02-22 16:57:08 +0100 | [diff] [blame] | 350 | } |
| 351 | |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 352 | /////////////////////////////////////////////////////////////////////////////////////////////// |
| 353 | // VisualStabilityManager.Callback overrides: |
| 354 | |
| 355 | @Override |
| 356 | public void onReorderingAllowed() { |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 357 | mAnimationStateHandler.setHeadsUpGoingAwayAnimationsAllowed(false); |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 358 | for (NotificationEntry entry : mEntriesToRemoveWhenReorderingAllowed) { |
Kevin | a97ea05 | 2018-09-11 13:53:18 -0700 | [diff] [blame] | 359 | if (isAlerting(entry.key)) { |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 360 | // Maybe the heads-up was removed already |
Kevin | d4f66a4 | 2018-08-03 13:12:51 -0700 | [diff] [blame] | 361 | removeAlertEntry(entry.key); |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 362 | } |
| 363 | } |
| 364 | mEntriesToRemoveWhenReorderingAllowed.clear(); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 365 | mAnimationStateHandler.setHeadsUpGoingAwayAnimationsAllowed(true); |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 366 | } |
| 367 | |
| 368 | /////////////////////////////////////////////////////////////////////////////////////////////// |
| 369 | // HeadsUpManager utility (protected) methods overrides: |
| 370 | |
| 371 | @Override |
Kevin | d4f66a4 | 2018-08-03 13:12:51 -0700 | [diff] [blame] | 372 | protected HeadsUpEntry createAlertEntry() { |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 373 | return mEntryPool.acquire(); |
| 374 | } |
| 375 | |
| 376 | @Override |
Kevin | d4f66a4 | 2018-08-03 13:12:51 -0700 | [diff] [blame] | 377 | protected void onAlertEntryRemoved(AlertEntry alertEntry) { |
| 378 | super.onAlertEntryRemoved(alertEntry); |
| 379 | mEntryPool.release((HeadsUpEntryPhone) alertEntry); |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 380 | } |
| 381 | |
| 382 | @Override |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 383 | protected boolean shouldHeadsUpBecomePinned(NotificationEntry entry) { |
James O'Leary | cbea84d | 2019-03-14 11:18:24 -0400 | [diff] [blame] | 384 | return mStatusBarState != StatusBarState.KEYGUARD && !mIsExpanded |
| 385 | || super.shouldHeadsUpBecomePinned(entry); |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 386 | } |
| 387 | |
| 388 | @Override |
| 389 | protected void dumpInternal(FileDescriptor fd, PrintWriter pw, String[] args) { |
| 390 | super.dumpInternal(fd, pw, args); |
James O'Leary | cbea84d | 2019-03-14 11:18:24 -0400 | [diff] [blame] | 391 | pw.print(" mBarState="); |
| 392 | pw.println(mStatusBarState); |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 393 | } |
| 394 | |
| 395 | /////////////////////////////////////////////////////////////////////////////////////////////// |
| 396 | // Private utility methods: |
| 397 | |
| 398 | @Nullable |
| 399 | private HeadsUpEntryPhone getHeadsUpEntryPhone(@NonNull String key) { |
Kevin | d4f66a4 | 2018-08-03 13:12:51 -0700 | [diff] [blame] | 400 | return (HeadsUpEntryPhone) mAlertEntries.get(key); |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 401 | } |
| 402 | |
| 403 | @Nullable |
| 404 | private HeadsUpEntryPhone getTopHeadsUpEntryPhone() { |
| 405 | return (HeadsUpEntryPhone) getTopHeadsUpEntry(); |
| 406 | } |
| 407 | |
Kevin | a5ff1fa | 2018-08-21 16:35:48 -0700 | [diff] [blame] | 408 | @Override |
| 409 | protected boolean canRemoveImmediately(@NonNull String key) { |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 410 | if (mSwipedOutKeys.contains(key)) { |
| 411 | // We always instantly dismiss views being manually swiped out. |
| 412 | mSwipedOutKeys.remove(key); |
| 413 | return true; |
| 414 | } |
| 415 | |
| 416 | HeadsUpEntryPhone headsUpEntry = getHeadsUpEntryPhone(key); |
| 417 | HeadsUpEntryPhone topEntry = getTopHeadsUpEntryPhone(); |
Kevin | a5ff1fa | 2018-08-21 16:35:48 -0700 | [diff] [blame] | 418 | |
| 419 | return headsUpEntry == null || headsUpEntry != topEntry || super.canRemoveImmediately(key); |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 420 | } |
| 421 | |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 422 | /////////////////////////////////////////////////////////////////////////////////////////////// |
| 423 | // HeadsUpEntryPhone: |
| 424 | |
| 425 | protected class HeadsUpEntryPhone extends HeadsUpManager.HeadsUpEntry { |
Gus Prevas | 21118153 | 2018-12-13 14:49:33 -0500 | [diff] [blame] | 426 | |
| 427 | private boolean mMenuShownPinned; |
| 428 | |
| 429 | @Override |
| 430 | protected boolean isSticky() { |
| 431 | return super.isSticky() || mMenuShownPinned; |
| 432 | } |
| 433 | |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 434 | public void setEntry(@NonNull final NotificationEntry entry) { |
James O'Leary | cbea84d | 2019-03-14 11:18:24 -0400 | [diff] [blame] | 435 | Runnable removeHeadsUpRunnable = () -> { |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 436 | if (!mVisualStabilityManager.isReorderingAllowed()) { |
| 437 | mEntriesToRemoveWhenReorderingAllowed.add(entry); |
| 438 | mVisualStabilityManager.addReorderingAllowedCallback( |
| 439 | HeadsUpManagerPhone.this); |
| 440 | } else if (!mTrackingHeadsUp) { |
Kevin | d4f66a4 | 2018-08-03 13:12:51 -0700 | [diff] [blame] | 441 | removeAlertEntry(entry.key); |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 442 | } else { |
| 443 | mEntriesToRemoveAfterExpand.add(entry); |
| 444 | } |
| 445 | }; |
| 446 | |
Kevin | d4f66a4 | 2018-08-03 13:12:51 -0700 | [diff] [blame] | 447 | setEntry(entry, removeHeadsUpRunnable); |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 448 | } |
| 449 | |
| 450 | @Override |
| 451 | public void updateEntry(boolean updatePostTime) { |
| 452 | super.updateEntry(updatePostTime); |
| 453 | |
Kevin | d4f66a4 | 2018-08-03 13:12:51 -0700 | [diff] [blame] | 454 | if (mEntriesToRemoveAfterExpand.contains(mEntry)) { |
| 455 | mEntriesToRemoveAfterExpand.remove(mEntry); |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 456 | } |
Kevin | d4f66a4 | 2018-08-03 13:12:51 -0700 | [diff] [blame] | 457 | if (mEntriesToRemoveWhenReorderingAllowed.contains(mEntry)) { |
| 458 | mEntriesToRemoveWhenReorderingAllowed.remove(mEntry); |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 459 | } |
| 460 | } |
| 461 | |
| 462 | @Override |
Kevin | d4f66a4 | 2018-08-03 13:12:51 -0700 | [diff] [blame] | 463 | public void setExpanded(boolean expanded) { |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 464 | if (this.expanded == expanded) { |
| 465 | return; |
| 466 | } |
| 467 | |
| 468 | this.expanded = expanded; |
| 469 | if (expanded) { |
| 470 | removeAutoRemovalCallbacks(); |
| 471 | } else { |
| 472 | updateEntry(false /* updatePostTime */); |
| 473 | } |
| 474 | } |
Gus Prevas | 21118153 | 2018-12-13 14:49:33 -0500 | [diff] [blame] | 475 | |
| 476 | public void setMenuShownPinned(boolean menuShownPinned) { |
| 477 | if (mMenuShownPinned == menuShownPinned) { |
| 478 | return; |
| 479 | } |
| 480 | |
| 481 | mMenuShownPinned = menuShownPinned; |
| 482 | if (menuShownPinned) { |
| 483 | removeAutoRemovalCallbacks(); |
| 484 | } else { |
| 485 | updateEntry(false /* updatePostTime */); |
| 486 | } |
| 487 | } |
| 488 | |
| 489 | @Override |
| 490 | public void reset() { |
| 491 | super.reset(); |
| 492 | mMenuShownPinned = false; |
| 493 | } |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 494 | } |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 495 | |
| 496 | public interface AnimationStateHandler { |
| 497 | void setHeadsUpGoingAwayAnimationsAllowed(boolean allowed); |
| 498 | } |
yoshiki iguchi | 4e30e76 | 2018-02-06 12:09:23 +0900 | [diff] [blame] | 499 | } |