Selim Cinek | 25fd4e2b | 2015-02-20 17:46:07 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 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 | |
Selim Cinek | 25fd4e2b | 2015-02-20 17:46:07 +0100 | [diff] [blame] | 19 | import android.service.notification.StatusBarNotification; |
Selim Cinek | 23c8034 | 2016-03-17 18:27:36 -0700 | [diff] [blame] | 20 | import android.support.annotation.Nullable; |
Selim Cinek | 25fd4e2b | 2015-02-20 17:46:07 +0100 | [diff] [blame] | 21 | |
| 22 | import com.android.systemui.statusbar.ExpandableNotificationRow; |
| 23 | import com.android.systemui.statusbar.NotificationData; |
Selim Cinek | 9c4c414 | 2015-12-04 16:44:56 -0800 | [diff] [blame] | 24 | import com.android.systemui.statusbar.StatusBarState; |
Selim Cinek | ef5127e | 2015-12-21 16:55:58 -0800 | [diff] [blame] | 25 | import com.android.systemui.statusbar.policy.HeadsUpManager; |
Selim Cinek | 25fd4e2b | 2015-02-20 17:46:07 +0100 | [diff] [blame] | 26 | |
| 27 | import java.util.HashMap; |
| 28 | import java.util.HashSet; |
Julia Reynolds | e46bb37 | 2016-03-17 11:05:58 -0400 | [diff] [blame^] | 29 | import java.util.Objects; |
Selim Cinek | 25fd4e2b | 2015-02-20 17:46:07 +0100 | [diff] [blame] | 30 | |
| 31 | /** |
| 32 | * A class to handle notifications and their corresponding groups. |
| 33 | */ |
Selim Cinek | ef5127e | 2015-12-21 16:55:58 -0800 | [diff] [blame] | 34 | public class NotificationGroupManager implements HeadsUpManager.OnHeadsUpChangedListener { |
Selim Cinek | 25fd4e2b | 2015-02-20 17:46:07 +0100 | [diff] [blame] | 35 | |
| 36 | private final HashMap<String, NotificationGroup> mGroupMap = new HashMap<>(); |
| 37 | private OnGroupChangeListener mListener; |
| 38 | private int mBarState = -1; |
Selim Cinek | a6c0cef | 2016-03-18 11:42:25 -0700 | [diff] [blame] | 39 | private HashMap<String, StatusBarNotification> mIsolatedEntries = new HashMap<>(); |
Selim Cinek | 25fd4e2b | 2015-02-20 17:46:07 +0100 | [diff] [blame] | 40 | |
| 41 | public void setOnGroupChangeListener(OnGroupChangeListener listener) { |
| 42 | mListener = listener; |
| 43 | } |
| 44 | |
| 45 | public boolean isGroupExpanded(StatusBarNotification sbn) { |
Selim Cinek | ef5127e | 2015-12-21 16:55:58 -0800 | [diff] [blame] | 46 | NotificationGroup group = mGroupMap.get(getGroupKey(sbn)); |
Selim Cinek | 25fd4e2b | 2015-02-20 17:46:07 +0100 | [diff] [blame] | 47 | if (group == null) { |
| 48 | return false; |
| 49 | } |
| 50 | return group.expanded; |
| 51 | } |
| 52 | |
| 53 | public void setGroupExpanded(StatusBarNotification sbn, boolean expanded) { |
Selim Cinek | ef5127e | 2015-12-21 16:55:58 -0800 | [diff] [blame] | 54 | NotificationGroup group = mGroupMap.get(getGroupKey(sbn)); |
Selim Cinek | 25fd4e2b | 2015-02-20 17:46:07 +0100 | [diff] [blame] | 55 | if (group == null) { |
| 56 | return; |
| 57 | } |
| 58 | setGroupExpanded(group, expanded); |
| 59 | } |
| 60 | |
| 61 | private void setGroupExpanded(NotificationGroup group, boolean expanded) { |
| 62 | group.expanded = expanded; |
| 63 | if (group.summary != null) { |
| 64 | mListener.onGroupExpansionChanged(group.summary.row, expanded); |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | public void onEntryRemoved(NotificationData.Entry removed) { |
| 69 | onEntryRemovedInternal(removed, removed.notification); |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * An entry was removed. |
| 74 | * |
| 75 | * @param removed the removed entry |
| 76 | * @param sbn the notification the entry has, which doesn't need to be the same as it's internal |
| 77 | * notification |
| 78 | */ |
| 79 | private void onEntryRemovedInternal(NotificationData.Entry removed, |
| 80 | final StatusBarNotification sbn) { |
Selim Cinek | ef5127e | 2015-12-21 16:55:58 -0800 | [diff] [blame] | 81 | String groupKey = getGroupKey(sbn); |
Selim Cinek | 25fd4e2b | 2015-02-20 17:46:07 +0100 | [diff] [blame] | 82 | final NotificationGroup group = mGroupMap.get(groupKey); |
Selim Cinek | 0b4aeab | 2015-09-01 17:07:38 -0700 | [diff] [blame] | 83 | if (group == null) { |
| 84 | // When an app posts 2 different notifications as summary of the same group, then a |
| 85 | // cancellation of the first notification removes this group. |
| 86 | // This situation is not supported and we will not allow such notifications anymore in |
| 87 | // the close future. See b/23676310 for reference. |
| 88 | return; |
| 89 | } |
Selim Cinek | ef5127e | 2015-12-21 16:55:58 -0800 | [diff] [blame] | 90 | if (isGroupChild(sbn)) { |
Selim Cinek | 25fd4e2b | 2015-02-20 17:46:07 +0100 | [diff] [blame] | 91 | group.children.remove(removed); |
Selim Cinek | e73ad21 | 2015-11-03 19:11:08 -0800 | [diff] [blame] | 92 | } else { |
| 93 | group.summary = null; |
Selim Cinek | 25fd4e2b | 2015-02-20 17:46:07 +0100 | [diff] [blame] | 94 | } |
Selim Cinek | 2a73934 | 2016-03-17 10:28:55 -0700 | [diff] [blame] | 95 | updateSuppression(group); |
Selim Cinek | 25fd4e2b | 2015-02-20 17:46:07 +0100 | [diff] [blame] | 96 | if (group.children.isEmpty()) { |
| 97 | if (group.summary == null) { |
| 98 | mGroupMap.remove(groupKey); |
Selim Cinek | 25fd4e2b | 2015-02-20 17:46:07 +0100 | [diff] [blame] | 99 | } |
| 100 | } |
| 101 | } |
| 102 | |
Selim Cinek | ef5127e | 2015-12-21 16:55:58 -0800 | [diff] [blame] | 103 | public void onEntryAdded(final NotificationData.Entry added) { |
| 104 | final StatusBarNotification sbn = added.notification; |
| 105 | boolean isGroupChild = isGroupChild(sbn); |
| 106 | String groupKey = getGroupKey(sbn); |
Selim Cinek | 25fd4e2b | 2015-02-20 17:46:07 +0100 | [diff] [blame] | 107 | NotificationGroup group = mGroupMap.get(groupKey); |
| 108 | if (group == null) { |
| 109 | group = new NotificationGroup(); |
| 110 | mGroupMap.put(groupKey, group); |
| 111 | } |
Selim Cinek | ef5127e | 2015-12-21 16:55:58 -0800 | [diff] [blame] | 112 | if (isGroupChild) { |
Selim Cinek | e73ad21 | 2015-11-03 19:11:08 -0800 | [diff] [blame] | 113 | group.children.add(added); |
Selim Cinek | 2a73934 | 2016-03-17 10:28:55 -0700 | [diff] [blame] | 114 | updateSuppression(group); |
Selim Cinek | e73ad21 | 2015-11-03 19:11:08 -0800 | [diff] [blame] | 115 | } else { |
Selim Cinek | 25fd4e2b | 2015-02-20 17:46:07 +0100 | [diff] [blame] | 116 | group.summary = added; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 117 | group.expanded = added.row.areChildrenExpanded(); |
Selim Cinek | 2a73934 | 2016-03-17 10:28:55 -0700 | [diff] [blame] | 118 | updateSuppression(group); |
Selim Cinek | 25fd4e2b | 2015-02-20 17:46:07 +0100 | [diff] [blame] | 119 | if (!group.children.isEmpty()) { |
| 120 | mListener.onGroupCreatedFromChildren(group); |
| 121 | } |
Selim Cinek | 25fd4e2b | 2015-02-20 17:46:07 +0100 | [diff] [blame] | 122 | } |
| 123 | } |
| 124 | |
Julia Reynolds | e46bb37 | 2016-03-17 11:05:58 -0400 | [diff] [blame^] | 125 | public void onEntryBundlingUpdated(final NotificationData.Entry updated, |
| 126 | final String overrideGroupKey) { |
| 127 | final StatusBarNotification oldSbn = updated.notification.clone(); |
| 128 | if (!Objects.equals(oldSbn.getOverrideGroupKey(), overrideGroupKey)) { |
| 129 | updated.notification.setOverrideGroupKey(overrideGroupKey); |
| 130 | onEntryUpdated(updated, oldSbn); |
| 131 | } |
| 132 | } |
| 133 | |
Selim Cinek | 2a73934 | 2016-03-17 10:28:55 -0700 | [diff] [blame] | 134 | private void updateSuppression(NotificationGroup group) { |
Selim Cinek | 23c8034 | 2016-03-17 18:27:36 -0700 | [diff] [blame] | 135 | if (group == null) { |
| 136 | return; |
| 137 | } |
Selim Cinek | 2a73934 | 2016-03-17 10:28:55 -0700 | [diff] [blame] | 138 | boolean prevSuppressed = group.suppressed; |
Selim Cinek | 23c8034 | 2016-03-17 18:27:36 -0700 | [diff] [blame] | 139 | group.suppressed = group.summary != null && !group.expanded |
| 140 | && (group.children.size() == 1 |
| 141 | || (group.children.size() == 0 |
Julia Reynolds | e46bb37 | 2016-03-17 11:05:58 -0400 | [diff] [blame^] | 142 | && group.summary.notification.getNotification().isGroupSummary() |
Selim Cinek | 23c8034 | 2016-03-17 18:27:36 -0700 | [diff] [blame] | 143 | && hasIsolatedChildren(group))); |
Selim Cinek | 2a73934 | 2016-03-17 10:28:55 -0700 | [diff] [blame] | 144 | if (prevSuppressed != group.suppressed) { |
| 145 | mListener.onGroupsChanged(); |
| 146 | } |
| 147 | } |
| 148 | |
Selim Cinek | 23c8034 | 2016-03-17 18:27:36 -0700 | [diff] [blame] | 149 | private boolean hasIsolatedChildren(NotificationGroup group) { |
| 150 | return getNumberOfIsolatedChildren(group.summary.notification.getGroupKey()) != 0; |
| 151 | } |
| 152 | |
| 153 | private int getNumberOfIsolatedChildren(String groupKey) { |
| 154 | int count = 0; |
Selim Cinek | a6c0cef | 2016-03-18 11:42:25 -0700 | [diff] [blame] | 155 | for (StatusBarNotification sbn : mIsolatedEntries.values()) { |
Selim Cinek | 23c8034 | 2016-03-17 18:27:36 -0700 | [diff] [blame] | 156 | if (sbn.getGroupKey().equals(groupKey) && isIsolated(sbn)) { |
| 157 | count++; |
| 158 | } |
| 159 | } |
| 160 | return count; |
| 161 | } |
| 162 | |
Selim Cinek | 25fd4e2b | 2015-02-20 17:46:07 +0100 | [diff] [blame] | 163 | public void onEntryUpdated(NotificationData.Entry entry, |
| 164 | StatusBarNotification oldNotification) { |
Selim Cinek | ef5127e | 2015-12-21 16:55:58 -0800 | [diff] [blame] | 165 | if (mGroupMap.get(getGroupKey(oldNotification)) != null) { |
Selim Cinek | 25fd4e2b | 2015-02-20 17:46:07 +0100 | [diff] [blame] | 166 | onEntryRemovedInternal(entry, oldNotification); |
| 167 | } |
| 168 | onEntryAdded(entry); |
Selim Cinek | a6c0cef | 2016-03-18 11:42:25 -0700 | [diff] [blame] | 169 | if (isIsolated(entry.notification)) { |
| 170 | mIsolatedEntries.put(entry.key, entry.notification); |
Selim Cinek | 23c8034 | 2016-03-17 18:27:36 -0700 | [diff] [blame] | 171 | String oldKey = oldNotification.getGroupKey(); |
| 172 | String newKey = entry.notification.getGroupKey(); |
| 173 | if (!oldKey.equals(newKey)) { |
| 174 | updateSuppression(mGroupMap.get(oldKey)); |
| 175 | updateSuppression(mGroupMap.get(newKey)); |
| 176 | } |
| 177 | } |
Selim Cinek | 25fd4e2b | 2015-02-20 17:46:07 +0100 | [diff] [blame] | 178 | } |
| 179 | |
Selim Cinek | 2a73934 | 2016-03-17 10:28:55 -0700 | [diff] [blame] | 180 | public boolean isSummaryOfSuppressedGroup(StatusBarNotification sbn) { |
Selim Cinek | 23c8034 | 2016-03-17 18:27:36 -0700 | [diff] [blame] | 181 | return isGroupSuppressed(getGroupKey(sbn)) && sbn.getNotification().isGroupSummary(); |
Selim Cinek | 25fd4e2b | 2015-02-20 17:46:07 +0100 | [diff] [blame] | 182 | } |
| 183 | |
Selim Cinek | 23c8034 | 2016-03-17 18:27:36 -0700 | [diff] [blame] | 184 | public boolean isOnlyChildInSuppressedGroup(StatusBarNotification sbn) { |
| 185 | return isGroupSuppressed(sbn.getGroupKey()) |
Julia Reynolds | e46bb37 | 2016-03-17 11:05:58 -0400 | [diff] [blame^] | 186 | && !sbn.getNotification().isGroupSummary() |
Selim Cinek | 23c8034 | 2016-03-17 18:27:36 -0700 | [diff] [blame] | 187 | && getTotalNumberOfChildren(sbn) == 1; |
Selim Cinek | 2a73934 | 2016-03-17 10:28:55 -0700 | [diff] [blame] | 188 | } |
| 189 | |
Selim Cinek | 23c8034 | 2016-03-17 18:27:36 -0700 | [diff] [blame] | 190 | private int getTotalNumberOfChildren(StatusBarNotification sbn) { |
| 191 | return getNumberOfIsolatedChildren(sbn.getGroupKey()) |
| 192 | + mGroupMap.get(sbn.getGroupKey()).children.size(); |
| 193 | } |
| 194 | |
| 195 | private boolean isGroupSuppressed(String groupKey) { |
| 196 | NotificationGroup group = mGroupMap.get(groupKey); |
Selim Cinek | 2a73934 | 2016-03-17 10:28:55 -0700 | [diff] [blame] | 197 | return group != null && group.suppressed; |
Selim Cinek | 25fd4e2b | 2015-02-20 17:46:07 +0100 | [diff] [blame] | 198 | } |
| 199 | |
Selim Cinek | 9c4c414 | 2015-12-04 16:44:56 -0800 | [diff] [blame] | 200 | public void setStatusBarState(int newState) { |
| 201 | if (mBarState == newState) { |
| 202 | return; |
| 203 | } |
| 204 | mBarState = newState; |
| 205 | if (mBarState == StatusBarState.KEYGUARD) { |
Selim Cinek | 9184f9c | 2016-02-02 17:36:53 -0800 | [diff] [blame] | 206 | collapseAllGroups(); |
| 207 | } |
| 208 | } |
| 209 | |
| 210 | public void collapseAllGroups() { |
| 211 | for (NotificationGroup group : mGroupMap.values()) { |
| 212 | if (group.expanded) { |
| 213 | setGroupExpanded(group, false); |
Selim Cinek | 9c4c414 | 2015-12-04 16:44:56 -0800 | [diff] [blame] | 214 | } |
Selim Cinek | 2a73934 | 2016-03-17 10:28:55 -0700 | [diff] [blame] | 215 | updateSuppression(group); |
Selim Cinek | 9c4c414 | 2015-12-04 16:44:56 -0800 | [diff] [blame] | 216 | } |
| 217 | } |
| 218 | |
Selim Cinek | 25fd4e2b | 2015-02-20 17:46:07 +0100 | [diff] [blame] | 219 | /** |
| 220 | * @return whether a given notification is a child in a group which has a summary |
| 221 | */ |
| 222 | public boolean isChildInGroupWithSummary(StatusBarNotification sbn) { |
Selim Cinek | ef5127e | 2015-12-21 16:55:58 -0800 | [diff] [blame] | 223 | if (!isGroupChild(sbn)) { |
Selim Cinek | 25fd4e2b | 2015-02-20 17:46:07 +0100 | [diff] [blame] | 224 | return false; |
| 225 | } |
Selim Cinek | ef5127e | 2015-12-21 16:55:58 -0800 | [diff] [blame] | 226 | NotificationGroup group = mGroupMap.get(getGroupKey(sbn)); |
Selim Cinek | 2a73934 | 2016-03-17 10:28:55 -0700 | [diff] [blame] | 227 | if (group == null || group.summary == null || group.suppressed) { |
Selim Cinek | 25fd4e2b | 2015-02-20 17:46:07 +0100 | [diff] [blame] | 228 | return false; |
| 229 | } |
| 230 | return true; |
| 231 | } |
| 232 | |
Selim Cinek | 263398f | 2015-10-21 17:40:23 -0700 | [diff] [blame] | 233 | /** |
| 234 | * @return whether a given notification is a summary in a group which has children |
| 235 | */ |
| 236 | public boolean isSummaryOfGroup(StatusBarNotification sbn) { |
Selim Cinek | ef5127e | 2015-12-21 16:55:58 -0800 | [diff] [blame] | 237 | if (!isGroupSummary(sbn)) { |
Selim Cinek | 263398f | 2015-10-21 17:40:23 -0700 | [diff] [blame] | 238 | return false; |
| 239 | } |
Selim Cinek | ef5127e | 2015-12-21 16:55:58 -0800 | [diff] [blame] | 240 | NotificationGroup group = mGroupMap.get(getGroupKey(sbn)); |
Selim Cinek | 263398f | 2015-10-21 17:40:23 -0700 | [diff] [blame] | 241 | if (group == null) { |
| 242 | return false; |
| 243 | } |
| 244 | return !group.children.isEmpty(); |
| 245 | } |
| 246 | |
Selim Cinek | 23c8034 | 2016-03-17 18:27:36 -0700 | [diff] [blame] | 247 | /** |
| 248 | * Get the summary of a specified status bar notification. For isolated notification this return |
| 249 | * itself. |
| 250 | */ |
Selim Cinek | 25fd4e2b | 2015-02-20 17:46:07 +0100 | [diff] [blame] | 251 | public ExpandableNotificationRow getGroupSummary(StatusBarNotification sbn) { |
Selim Cinek | 23c8034 | 2016-03-17 18:27:36 -0700 | [diff] [blame] | 252 | return getGroupSummary(getGroupKey(sbn)); |
| 253 | } |
| 254 | |
| 255 | /** |
| 256 | * Similar to {@link #getGroupSummary(StatusBarNotification)} but doesn't get the visual summary |
| 257 | * but the logical summary, i.e when a child is isolated, it still returns the summary as if |
| 258 | * it wasn't isolated. |
| 259 | */ |
| 260 | public ExpandableNotificationRow getLogicalGroupSummary( |
| 261 | StatusBarNotification sbn) { |
| 262 | return getGroupSummary(sbn.getGroupKey()); |
| 263 | } |
| 264 | |
| 265 | @Nullable |
| 266 | private ExpandableNotificationRow getGroupSummary(String groupKey) { |
| 267 | NotificationGroup group = mGroupMap.get(groupKey); |
Selim Cinek | 25fd4e2b | 2015-02-20 17:46:07 +0100 | [diff] [blame] | 268 | return group == null ? null |
| 269 | : group.summary == null ? null |
Selim Cinek | 23c8034 | 2016-03-17 18:27:36 -0700 | [diff] [blame] | 270 | : group.summary.row; |
Selim Cinek | 25fd4e2b | 2015-02-20 17:46:07 +0100 | [diff] [blame] | 271 | } |
| 272 | |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 273 | public void toggleGroupExpansion(StatusBarNotification sbn) { |
Selim Cinek | ef5127e | 2015-12-21 16:55:58 -0800 | [diff] [blame] | 274 | NotificationGroup group = mGroupMap.get(getGroupKey(sbn)); |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 275 | if (group == null) { |
| 276 | return; |
| 277 | } |
| 278 | setGroupExpanded(group, !group.expanded); |
| 279 | } |
| 280 | |
Selim Cinek | ef5127e | 2015-12-21 16:55:58 -0800 | [diff] [blame] | 281 | private boolean isIsolated(StatusBarNotification sbn) { |
Selim Cinek | a6c0cef | 2016-03-18 11:42:25 -0700 | [diff] [blame] | 282 | return mIsolatedEntries.containsKey(sbn.getKey()); |
Selim Cinek | ef5127e | 2015-12-21 16:55:58 -0800 | [diff] [blame] | 283 | } |
| 284 | |
| 285 | private boolean isGroupSummary(StatusBarNotification sbn) { |
| 286 | if (isIsolated(sbn)) { |
| 287 | return true; |
| 288 | } |
| 289 | return sbn.getNotification().isGroupSummary(); |
| 290 | } |
Julia Reynolds | e46bb37 | 2016-03-17 11:05:58 -0400 | [diff] [blame^] | 291 | |
Selim Cinek | ef5127e | 2015-12-21 16:55:58 -0800 | [diff] [blame] | 292 | private boolean isGroupChild(StatusBarNotification sbn) { |
| 293 | if (isIsolated(sbn)) { |
| 294 | return false; |
| 295 | } |
Julia Reynolds | e46bb37 | 2016-03-17 11:05:58 -0400 | [diff] [blame^] | 296 | return sbn.isGroup() && !sbn.getNotification().isGroupSummary(); |
Selim Cinek | ef5127e | 2015-12-21 16:55:58 -0800 | [diff] [blame] | 297 | } |
| 298 | |
| 299 | private String getGroupKey(StatusBarNotification sbn) { |
| 300 | if (isIsolated(sbn)) { |
| 301 | return sbn.getKey(); |
| 302 | } |
| 303 | return sbn.getGroupKey(); |
| 304 | } |
| 305 | |
| 306 | @Override |
| 307 | public void onHeadsUpPinnedModeChanged(boolean inPinnedMode) { |
| 308 | } |
| 309 | |
| 310 | @Override |
| 311 | public void onHeadsUpPinned(ExpandableNotificationRow headsUp) { |
| 312 | } |
| 313 | |
| 314 | @Override |
| 315 | public void onHeadsUpUnPinned(ExpandableNotificationRow headsUp) { |
| 316 | } |
| 317 | |
| 318 | @Override |
| 319 | public void onHeadsUpStateChanged(NotificationData.Entry entry, boolean isHeadsUp) { |
| 320 | final StatusBarNotification sbn = entry.notification; |
| 321 | if (entry.row.isHeadsUp()) { |
Selim Cinek | a6c0cef | 2016-03-18 11:42:25 -0700 | [diff] [blame] | 322 | if (shouldIsolate(sbn)) { |
Selim Cinek | 23c8034 | 2016-03-17 18:27:36 -0700 | [diff] [blame] | 323 | // We will be isolated now, so lets update the groups |
| 324 | onEntryRemovedInternal(entry, entry.notification); |
Selim Cinek | a6c0cef | 2016-03-18 11:42:25 -0700 | [diff] [blame] | 325 | |
| 326 | mIsolatedEntries.put(sbn.getKey(), sbn); |
| 327 | |
Selim Cinek | 23c8034 | 2016-03-17 18:27:36 -0700 | [diff] [blame] | 328 | onEntryAdded(entry); |
| 329 | // We also need to update the suppression of the old group, because this call comes |
| 330 | // even before the groupManager knows about the notification at all. |
| 331 | // When the notification gets added afterwards it is already isolated and therefore |
| 332 | // it doesn't lead to an update. |
| 333 | updateSuppression(mGroupMap.get(entry.notification.getGroupKey())); |
| 334 | mListener.onGroupsChanged(); |
Selim Cinek | ef5127e | 2015-12-21 16:55:58 -0800 | [diff] [blame] | 335 | } |
| 336 | } else { |
Selim Cinek | a6c0cef | 2016-03-18 11:42:25 -0700 | [diff] [blame] | 337 | if (mIsolatedEntries.containsKey(sbn.getKey())) { |
| 338 | // not isolated anymore, we need to update the groups |
| 339 | onEntryRemovedInternal(entry, entry.notification); |
| 340 | mIsolatedEntries.remove(sbn.getKey()); |
| 341 | onEntryAdded(entry); |
| 342 | mListener.onGroupsChanged(); |
Selim Cinek | ef5127e | 2015-12-21 16:55:58 -0800 | [diff] [blame] | 343 | } |
| 344 | } |
| 345 | } |
| 346 | |
Selim Cinek | a6c0cef | 2016-03-18 11:42:25 -0700 | [diff] [blame] | 347 | private boolean shouldIsolate(StatusBarNotification sbn) { |
| 348 | NotificationGroup notificationGroup = mGroupMap.get(sbn.getGroupKey()); |
Julia Reynolds | e46bb37 | 2016-03-17 11:05:58 -0400 | [diff] [blame^] | 349 | return (sbn.isGroup() && !sbn.getNotification().isGroupSummary()) |
Selim Cinek | a6c0cef | 2016-03-18 11:42:25 -0700 | [diff] [blame] | 350 | && (sbn.getNotification().fullScreenIntent != null |
| 351 | || notificationGroup == null |
| 352 | || !notificationGroup.expanded |
| 353 | || isGroupNotFullyVisible(notificationGroup)); |
| 354 | } |
| 355 | |
| 356 | private boolean isGroupNotFullyVisible(NotificationGroup notificationGroup) { |
| 357 | return notificationGroup.summary == null |
| 358 | || notificationGroup.summary.row.getClipTopOptimization() > 0 |
| 359 | || notificationGroup.summary.row.getClipTopAmount() > 0 |
| 360 | || notificationGroup.summary.row.getTranslationY() < 0; |
| 361 | } |
| 362 | |
Selim Cinek | 25fd4e2b | 2015-02-20 17:46:07 +0100 | [diff] [blame] | 363 | public static class NotificationGroup { |
| 364 | public final HashSet<NotificationData.Entry> children = new HashSet<>(); |
| 365 | public NotificationData.Entry summary; |
| 366 | public boolean expanded; |
Selim Cinek | 2a73934 | 2016-03-17 10:28:55 -0700 | [diff] [blame] | 367 | /** |
| 368 | * Is this notification group suppressed, i.e its summary is hidden |
| 369 | */ |
| 370 | public boolean suppressed; |
Selim Cinek | 25fd4e2b | 2015-02-20 17:46:07 +0100 | [diff] [blame] | 371 | } |
| 372 | |
| 373 | public interface OnGroupChangeListener { |
| 374 | /** |
| 375 | * The expansion of a group has changed. |
| 376 | * |
| 377 | * @param changedRow the row for which the expansion has changed, which is also the summary |
| 378 | * @param expanded a boolean indicating the new expanded state |
| 379 | */ |
| 380 | void onGroupExpansionChanged(ExpandableNotificationRow changedRow, boolean expanded); |
| 381 | |
| 382 | /** |
Selim Cinek | 25fd4e2b | 2015-02-20 17:46:07 +0100 | [diff] [blame] | 383 | * A group of children just received a summary notification and should therefore become |
| 384 | * children of it. |
| 385 | * |
| 386 | * @param group the group created |
| 387 | */ |
| 388 | void onGroupCreatedFromChildren(NotificationGroup group); |
Selim Cinek | ef5127e | 2015-12-21 16:55:58 -0800 | [diff] [blame] | 389 | |
| 390 | /** |
Selim Cinek | 2a73934 | 2016-03-17 10:28:55 -0700 | [diff] [blame] | 391 | * The groups have changed. This can happen if the isolation of a child has changes or if a |
| 392 | * group became suppressed / unsuppressed |
Selim Cinek | ef5127e | 2015-12-21 16:55:58 -0800 | [diff] [blame] | 393 | */ |
Selim Cinek | 2a73934 | 2016-03-17 10:28:55 -0700 | [diff] [blame] | 394 | void onGroupsChanged(); |
Selim Cinek | 25fd4e2b | 2015-02-20 17:46:07 +0100 | [diff] [blame] | 395 | } |
| 396 | } |