blob: 48fec7dd5968a06c5c625dbcde81350057f1e6a9 [file] [log] [blame]
Selim Cinek25fd4e2b2015-02-20 17:46:07 +01001/*
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
17package com.android.systemui.statusbar.phone;
18
Selim Cinek25fd4e2b2015-02-20 17:46:07 +010019import android.service.notification.StatusBarNotification;
Selim Cinek23c80342016-03-17 18:27:36 -070020import android.support.annotation.Nullable;
Selim Cinek25fd4e2b2015-02-20 17:46:07 +010021
22import com.android.systemui.statusbar.ExpandableNotificationRow;
23import com.android.systemui.statusbar.NotificationData;
Selim Cinek9c4c4142015-12-04 16:44:56 -080024import com.android.systemui.statusbar.StatusBarState;
Selim Cinekef5127e2015-12-21 16:55:58 -080025import com.android.systemui.statusbar.policy.HeadsUpManager;
Selim Cinek25fd4e2b2015-02-20 17:46:07 +010026
Selim Cinek52941c52016-05-07 18:29:32 -040027import java.io.FileDescriptor;
28import java.io.PrintWriter;
Selim Cinek25fd4e2b2015-02-20 17:46:07 +010029import java.util.HashMap;
30import java.util.HashSet;
Selim Cinek967ed2a2016-04-08 18:29:11 -070031import java.util.Iterator;
Selim Cinek52941c52016-05-07 18:29:32 -040032import java.util.Map;
Julia Reynoldse46bb372016-03-17 11:05:58 -040033import java.util.Objects;
Selim Cinek25fd4e2b2015-02-20 17:46:07 +010034
35/**
36 * A class to handle notifications and their corresponding groups.
37 */
Selim Cinekef5127e2015-12-21 16:55:58 -080038public class NotificationGroupManager implements HeadsUpManager.OnHeadsUpChangedListener {
Selim Cinek25fd4e2b2015-02-20 17:46:07 +010039
40 private final HashMap<String, NotificationGroup> mGroupMap = new HashMap<>();
41 private OnGroupChangeListener mListener;
42 private int mBarState = -1;
Selim Cineka6c0cef2016-03-18 11:42:25 -070043 private HashMap<String, StatusBarNotification> mIsolatedEntries = new HashMap<>();
Selim Cinek967ed2a2016-04-08 18:29:11 -070044 private HeadsUpManager mHeadsUpManager;
Selim Cinek25fd4e2b2015-02-20 17:46:07 +010045
46 public void setOnGroupChangeListener(OnGroupChangeListener listener) {
47 mListener = listener;
48 }
49
50 public boolean isGroupExpanded(StatusBarNotification sbn) {
Selim Cinekef5127e2015-12-21 16:55:58 -080051 NotificationGroup group = mGroupMap.get(getGroupKey(sbn));
Selim Cinek25fd4e2b2015-02-20 17:46:07 +010052 if (group == null) {
53 return false;
54 }
55 return group.expanded;
56 }
57
58 public void setGroupExpanded(StatusBarNotification sbn, boolean expanded) {
Selim Cinekef5127e2015-12-21 16:55:58 -080059 NotificationGroup group = mGroupMap.get(getGroupKey(sbn));
Selim Cinek25fd4e2b2015-02-20 17:46:07 +010060 if (group == null) {
61 return;
62 }
63 setGroupExpanded(group, expanded);
64 }
65
66 private void setGroupExpanded(NotificationGroup group, boolean expanded) {
67 group.expanded = expanded;
68 if (group.summary != null) {
69 mListener.onGroupExpansionChanged(group.summary.row, expanded);
70 }
71 }
72
73 public void onEntryRemoved(NotificationData.Entry removed) {
74 onEntryRemovedInternal(removed, removed.notification);
Selim Cinek52941c52016-05-07 18:29:32 -040075 mIsolatedEntries.remove(removed.key);
Selim Cinek25fd4e2b2015-02-20 17:46:07 +010076 }
77
78 /**
79 * An entry was removed.
80 *
81 * @param removed the removed entry
82 * @param sbn the notification the entry has, which doesn't need to be the same as it's internal
83 * notification
84 */
85 private void onEntryRemovedInternal(NotificationData.Entry removed,
86 final StatusBarNotification sbn) {
Selim Cinekef5127e2015-12-21 16:55:58 -080087 String groupKey = getGroupKey(sbn);
Selim Cinek25fd4e2b2015-02-20 17:46:07 +010088 final NotificationGroup group = mGroupMap.get(groupKey);
Selim Cinek0b4aeab2015-09-01 17:07:38 -070089 if (group == null) {
90 // When an app posts 2 different notifications as summary of the same group, then a
91 // cancellation of the first notification removes this group.
92 // This situation is not supported and we will not allow such notifications anymore in
93 // the close future. See b/23676310 for reference.
94 return;
95 }
Selim Cinekef5127e2015-12-21 16:55:58 -080096 if (isGroupChild(sbn)) {
Selim Cinek25fd4e2b2015-02-20 17:46:07 +010097 group.children.remove(removed);
Selim Cineke73ad212015-11-03 19:11:08 -080098 } else {
99 group.summary = null;
Selim Cinek25fd4e2b2015-02-20 17:46:07 +0100100 }
Selim Cinek2a739342016-03-17 10:28:55 -0700101 updateSuppression(group);
Selim Cinek25fd4e2b2015-02-20 17:46:07 +0100102 if (group.children.isEmpty()) {
103 if (group.summary == null) {
104 mGroupMap.remove(groupKey);
Selim Cinek25fd4e2b2015-02-20 17:46:07 +0100105 }
106 }
107 }
108
Selim Cinekef5127e2015-12-21 16:55:58 -0800109 public void onEntryAdded(final NotificationData.Entry added) {
110 final StatusBarNotification sbn = added.notification;
111 boolean isGroupChild = isGroupChild(sbn);
112 String groupKey = getGroupKey(sbn);
Selim Cinek25fd4e2b2015-02-20 17:46:07 +0100113 NotificationGroup group = mGroupMap.get(groupKey);
114 if (group == null) {
115 group = new NotificationGroup();
116 mGroupMap.put(groupKey, group);
117 }
Selim Cinekef5127e2015-12-21 16:55:58 -0800118 if (isGroupChild) {
Selim Cineke73ad212015-11-03 19:11:08 -0800119 group.children.add(added);
Selim Cinek2a739342016-03-17 10:28:55 -0700120 updateSuppression(group);
Selim Cineke73ad212015-11-03 19:11:08 -0800121 } else {
Selim Cinek25fd4e2b2015-02-20 17:46:07 +0100122 group.summary = added;
Selim Cinekb5605e52015-02-20 18:21:41 +0100123 group.expanded = added.row.areChildrenExpanded();
Selim Cinek2a739342016-03-17 10:28:55 -0700124 updateSuppression(group);
Selim Cinek25fd4e2b2015-02-20 17:46:07 +0100125 if (!group.children.isEmpty()) {
Selim Cinek50e74672016-05-05 15:58:10 -0400126 HashSet<NotificationData.Entry> childrenCopy =
127 (HashSet<NotificationData.Entry>) group.children.clone();
128 for (NotificationData.Entry child : childrenCopy) {
129 onEntryBecomingChild(child);
130 }
Selim Cinek25fd4e2b2015-02-20 17:46:07 +0100131 mListener.onGroupCreatedFromChildren(group);
132 }
Selim Cinek25fd4e2b2015-02-20 17:46:07 +0100133 }
134 }
135
Selim Cinek50e74672016-05-05 15:58:10 -0400136 private void onEntryBecomingChild(NotificationData.Entry entry) {
137 if (entry.row.isHeadsUp()) {
138 onHeadsUpStateChanged(entry, true);
139 }
140 }
141
Julia Reynoldse46bb372016-03-17 11:05:58 -0400142 public void onEntryBundlingUpdated(final NotificationData.Entry updated,
143 final String overrideGroupKey) {
144 final StatusBarNotification oldSbn = updated.notification.clone();
145 if (!Objects.equals(oldSbn.getOverrideGroupKey(), overrideGroupKey)) {
146 updated.notification.setOverrideGroupKey(overrideGroupKey);
147 onEntryUpdated(updated, oldSbn);
148 }
149 }
150
Selim Cinek2a739342016-03-17 10:28:55 -0700151 private void updateSuppression(NotificationGroup group) {
Selim Cinek23c80342016-03-17 18:27:36 -0700152 if (group == null) {
153 return;
154 }
Selim Cinek2a739342016-03-17 10:28:55 -0700155 boolean prevSuppressed = group.suppressed;
Selim Cinek23c80342016-03-17 18:27:36 -0700156 group.suppressed = group.summary != null && !group.expanded
157 && (group.children.size() == 1
158 || (group.children.size() == 0
Julia Reynoldse46bb372016-03-17 11:05:58 -0400159 && group.summary.notification.getNotification().isGroupSummary()
Selim Cinek23c80342016-03-17 18:27:36 -0700160 && hasIsolatedChildren(group)));
Selim Cinek2a739342016-03-17 10:28:55 -0700161 if (prevSuppressed != group.suppressed) {
Selim Cinek967ed2a2016-04-08 18:29:11 -0700162 if (group.suppressed) {
163 handleSuppressedSummaryHeadsUpped(group.summary);
164 }
Selim Cinek2a739342016-03-17 10:28:55 -0700165 mListener.onGroupsChanged();
166 }
167 }
168
Selim Cinek23c80342016-03-17 18:27:36 -0700169 private boolean hasIsolatedChildren(NotificationGroup group) {
170 return getNumberOfIsolatedChildren(group.summary.notification.getGroupKey()) != 0;
171 }
172
173 private int getNumberOfIsolatedChildren(String groupKey) {
174 int count = 0;
Selim Cineka6c0cef2016-03-18 11:42:25 -0700175 for (StatusBarNotification sbn : mIsolatedEntries.values()) {
Selim Cinek23c80342016-03-17 18:27:36 -0700176 if (sbn.getGroupKey().equals(groupKey) && isIsolated(sbn)) {
177 count++;
178 }
179 }
180 return count;
181 }
182
Selim Cinek967ed2a2016-04-08 18:29:11 -0700183 private NotificationData.Entry getIsolatedChild(String groupKey) {
184 for (StatusBarNotification sbn : mIsolatedEntries.values()) {
185 if (sbn.getGroupKey().equals(groupKey) && isIsolated(sbn)) {
186 return mGroupMap.get(sbn.getKey()).summary;
187 }
188 }
189 return null;
190 }
191
Selim Cinek25fd4e2b2015-02-20 17:46:07 +0100192 public void onEntryUpdated(NotificationData.Entry entry,
193 StatusBarNotification oldNotification) {
Selim Cinekef5127e2015-12-21 16:55:58 -0800194 if (mGroupMap.get(getGroupKey(oldNotification)) != null) {
Selim Cinek25fd4e2b2015-02-20 17:46:07 +0100195 onEntryRemovedInternal(entry, oldNotification);
196 }
197 onEntryAdded(entry);
Selim Cineka6c0cef2016-03-18 11:42:25 -0700198 if (isIsolated(entry.notification)) {
199 mIsolatedEntries.put(entry.key, entry.notification);
Selim Cinek23c80342016-03-17 18:27:36 -0700200 String oldKey = oldNotification.getGroupKey();
201 String newKey = entry.notification.getGroupKey();
202 if (!oldKey.equals(newKey)) {
203 updateSuppression(mGroupMap.get(oldKey));
204 updateSuppression(mGroupMap.get(newKey));
205 }
Selim Cinek50e74672016-05-05 15:58:10 -0400206 } else if (!isGroupChild(oldNotification) && isGroupChild(entry.notification)) {
207 onEntryBecomingChild(entry);
Selim Cinek23c80342016-03-17 18:27:36 -0700208 }
Selim Cinek25fd4e2b2015-02-20 17:46:07 +0100209 }
210
Selim Cinek2a739342016-03-17 10:28:55 -0700211 public boolean isSummaryOfSuppressedGroup(StatusBarNotification sbn) {
Selim Cinek23c80342016-03-17 18:27:36 -0700212 return isGroupSuppressed(getGroupKey(sbn)) && sbn.getNotification().isGroupSummary();
Selim Cinek25fd4e2b2015-02-20 17:46:07 +0100213 }
214
Selim Cinek23c80342016-03-17 18:27:36 -0700215 public boolean isOnlyChildInSuppressedGroup(StatusBarNotification sbn) {
216 return isGroupSuppressed(sbn.getGroupKey())
Julia Reynoldse46bb372016-03-17 11:05:58 -0400217 && !sbn.getNotification().isGroupSummary()
Selim Cinek23c80342016-03-17 18:27:36 -0700218 && getTotalNumberOfChildren(sbn) == 1;
Selim Cinek2a739342016-03-17 10:28:55 -0700219 }
220
Selim Cinek23c80342016-03-17 18:27:36 -0700221 private int getTotalNumberOfChildren(StatusBarNotification sbn) {
222 return getNumberOfIsolatedChildren(sbn.getGroupKey())
223 + mGroupMap.get(sbn.getGroupKey()).children.size();
224 }
225
226 private boolean isGroupSuppressed(String groupKey) {
227 NotificationGroup group = mGroupMap.get(groupKey);
Selim Cinek2a739342016-03-17 10:28:55 -0700228 return group != null && group.suppressed;
Selim Cinek25fd4e2b2015-02-20 17:46:07 +0100229 }
230
Selim Cinek9c4c4142015-12-04 16:44:56 -0800231 public void setStatusBarState(int newState) {
232 if (mBarState == newState) {
233 return;
234 }
235 mBarState = newState;
236 if (mBarState == StatusBarState.KEYGUARD) {
Selim Cinek9184f9c2016-02-02 17:36:53 -0800237 collapseAllGroups();
238 }
239 }
240
241 public void collapseAllGroups() {
242 for (NotificationGroup group : mGroupMap.values()) {
243 if (group.expanded) {
244 setGroupExpanded(group, false);
Selim Cinek9c4c4142015-12-04 16:44:56 -0800245 }
Selim Cinek2a739342016-03-17 10:28:55 -0700246 updateSuppression(group);
Selim Cinek9c4c4142015-12-04 16:44:56 -0800247 }
248 }
249
Selim Cinek25fd4e2b2015-02-20 17:46:07 +0100250 /**
251 * @return whether a given notification is a child in a group which has a summary
252 */
253 public boolean isChildInGroupWithSummary(StatusBarNotification sbn) {
Selim Cinekef5127e2015-12-21 16:55:58 -0800254 if (!isGroupChild(sbn)) {
Selim Cinek25fd4e2b2015-02-20 17:46:07 +0100255 return false;
256 }
Selim Cinekef5127e2015-12-21 16:55:58 -0800257 NotificationGroup group = mGroupMap.get(getGroupKey(sbn));
Selim Cinek2a739342016-03-17 10:28:55 -0700258 if (group == null || group.summary == null || group.suppressed) {
Selim Cinek25fd4e2b2015-02-20 17:46:07 +0100259 return false;
260 }
Selim Cinek3f19f602016-05-02 18:01:56 -0700261 if (group.children.isEmpty()) {
262 // If the suppression of a group changes because the last child was removed, this can
263 // still be called temporarily because the child hasn't been fully removed yet. Let's
264 // make sure we still return false in that case.
265 return false;
266 }
Selim Cinek25fd4e2b2015-02-20 17:46:07 +0100267 return true;
268 }
269
Selim Cinek263398f2015-10-21 17:40:23 -0700270 /**
271 * @return whether a given notification is a summary in a group which has children
272 */
273 public boolean isSummaryOfGroup(StatusBarNotification sbn) {
Selim Cinekef5127e2015-12-21 16:55:58 -0800274 if (!isGroupSummary(sbn)) {
Selim Cinek263398f2015-10-21 17:40:23 -0700275 return false;
276 }
Selim Cinekef5127e2015-12-21 16:55:58 -0800277 NotificationGroup group = mGroupMap.get(getGroupKey(sbn));
Selim Cinek263398f2015-10-21 17:40:23 -0700278 if (group == null) {
279 return false;
280 }
281 return !group.children.isEmpty();
282 }
283
Selim Cinek23c80342016-03-17 18:27:36 -0700284 /**
285 * Get the summary of a specified status bar notification. For isolated notification this return
286 * itself.
287 */
Selim Cinek25fd4e2b2015-02-20 17:46:07 +0100288 public ExpandableNotificationRow getGroupSummary(StatusBarNotification sbn) {
Selim Cinek23c80342016-03-17 18:27:36 -0700289 return getGroupSummary(getGroupKey(sbn));
290 }
291
292 /**
293 * Similar to {@link #getGroupSummary(StatusBarNotification)} but doesn't get the visual summary
294 * but the logical summary, i.e when a child is isolated, it still returns the summary as if
295 * it wasn't isolated.
296 */
297 public ExpandableNotificationRow getLogicalGroupSummary(
298 StatusBarNotification sbn) {
299 return getGroupSummary(sbn.getGroupKey());
300 }
301
302 @Nullable
303 private ExpandableNotificationRow getGroupSummary(String groupKey) {
304 NotificationGroup group = mGroupMap.get(groupKey);
Selim Cinek25fd4e2b2015-02-20 17:46:07 +0100305 return group == null ? null
306 : group.summary == null ? null
Selim Cinek23c80342016-03-17 18:27:36 -0700307 : group.summary.row;
Selim Cinek25fd4e2b2015-02-20 17:46:07 +0100308 }
309
Selim Cinek83bc7832015-10-22 13:26:54 -0700310 public void toggleGroupExpansion(StatusBarNotification sbn) {
Selim Cinekef5127e2015-12-21 16:55:58 -0800311 NotificationGroup group = mGroupMap.get(getGroupKey(sbn));
Selim Cinek83bc7832015-10-22 13:26:54 -0700312 if (group == null) {
313 return;
314 }
315 setGroupExpanded(group, !group.expanded);
316 }
317
Selim Cinekef5127e2015-12-21 16:55:58 -0800318 private boolean isIsolated(StatusBarNotification sbn) {
Selim Cineka6c0cef2016-03-18 11:42:25 -0700319 return mIsolatedEntries.containsKey(sbn.getKey());
Selim Cinekef5127e2015-12-21 16:55:58 -0800320 }
321
322 private boolean isGroupSummary(StatusBarNotification sbn) {
323 if (isIsolated(sbn)) {
324 return true;
325 }
326 return sbn.getNotification().isGroupSummary();
327 }
Julia Reynoldse46bb372016-03-17 11:05:58 -0400328
Selim Cinekef5127e2015-12-21 16:55:58 -0800329 private boolean isGroupChild(StatusBarNotification sbn) {
330 if (isIsolated(sbn)) {
331 return false;
332 }
Julia Reynoldse46bb372016-03-17 11:05:58 -0400333 return sbn.isGroup() && !sbn.getNotification().isGroupSummary();
Selim Cinekef5127e2015-12-21 16:55:58 -0800334 }
335
336 private String getGroupKey(StatusBarNotification sbn) {
337 if (isIsolated(sbn)) {
338 return sbn.getKey();
339 }
340 return sbn.getGroupKey();
341 }
342
343 @Override
344 public void onHeadsUpPinnedModeChanged(boolean inPinnedMode) {
345 }
346
347 @Override
348 public void onHeadsUpPinned(ExpandableNotificationRow headsUp) {
349 }
350
351 @Override
352 public void onHeadsUpUnPinned(ExpandableNotificationRow headsUp) {
353 }
354
355 @Override
356 public void onHeadsUpStateChanged(NotificationData.Entry entry, boolean isHeadsUp) {
357 final StatusBarNotification sbn = entry.notification;
358 if (entry.row.isHeadsUp()) {
Selim Cineka6c0cef2016-03-18 11:42:25 -0700359 if (shouldIsolate(sbn)) {
Selim Cinek23c80342016-03-17 18:27:36 -0700360 // We will be isolated now, so lets update the groups
361 onEntryRemovedInternal(entry, entry.notification);
Selim Cineka6c0cef2016-03-18 11:42:25 -0700362
363 mIsolatedEntries.put(sbn.getKey(), sbn);
364
Selim Cinek23c80342016-03-17 18:27:36 -0700365 onEntryAdded(entry);
366 // We also need to update the suppression of the old group, because this call comes
367 // even before the groupManager knows about the notification at all.
368 // When the notification gets added afterwards it is already isolated and therefore
369 // it doesn't lead to an update.
370 updateSuppression(mGroupMap.get(entry.notification.getGroupKey()));
371 mListener.onGroupsChanged();
Selim Cinek967ed2a2016-04-08 18:29:11 -0700372 } else {
373 handleSuppressedSummaryHeadsUpped(entry);
Selim Cinekef5127e2015-12-21 16:55:58 -0800374 }
375 } else {
Selim Cineka6c0cef2016-03-18 11:42:25 -0700376 if (mIsolatedEntries.containsKey(sbn.getKey())) {
377 // not isolated anymore, we need to update the groups
378 onEntryRemovedInternal(entry, entry.notification);
379 mIsolatedEntries.remove(sbn.getKey());
380 onEntryAdded(entry);
381 mListener.onGroupsChanged();
Selim Cinekef5127e2015-12-21 16:55:58 -0800382 }
383 }
384 }
385
Selim Cinek967ed2a2016-04-08 18:29:11 -0700386 private void handleSuppressedSummaryHeadsUpped(NotificationData.Entry entry) {
387 StatusBarNotification sbn = entry.notification;
388 if (!isGroupSuppressed(sbn.getGroupKey())
389 || !sbn.getNotification().isGroupSummary()
390 || !entry.row.isHeadsUp()) {
391 return;
392 }
393 // The parent of a suppressed group got huned, lets hun the child!
394 NotificationGroup notificationGroup = mGroupMap.get(sbn.getGroupKey());
395 if (notificationGroup != null) {
396 Iterator<NotificationData.Entry> iterator = notificationGroup.children.iterator();
397 NotificationData.Entry child = iterator.hasNext() ? iterator.next() : null;
398 if (child == null) {
399 child = getIsolatedChild(sbn.getGroupKey());
400 }
401 if (child != null) {
402 if (mHeadsUpManager.isHeadsUp(child.key)) {
403 mHeadsUpManager.updateNotification(child, true);
404 } else {
405 mHeadsUpManager.showNotification(child);
406 }
407 }
408 }
409 mHeadsUpManager.releaseImmediately(entry.key);
410 }
411
Selim Cineka6c0cef2016-03-18 11:42:25 -0700412 private boolean shouldIsolate(StatusBarNotification sbn) {
413 NotificationGroup notificationGroup = mGroupMap.get(sbn.getGroupKey());
Julia Reynoldse46bb372016-03-17 11:05:58 -0400414 return (sbn.isGroup() && !sbn.getNotification().isGroupSummary())
Selim Cineka6c0cef2016-03-18 11:42:25 -0700415 && (sbn.getNotification().fullScreenIntent != null
416 || notificationGroup == null
417 || !notificationGroup.expanded
418 || isGroupNotFullyVisible(notificationGroup));
419 }
420
421 private boolean isGroupNotFullyVisible(NotificationGroup notificationGroup) {
422 return notificationGroup.summary == null
423 || notificationGroup.summary.row.getClipTopOptimization() > 0
424 || notificationGroup.summary.row.getClipTopAmount() > 0
425 || notificationGroup.summary.row.getTranslationY() < 0;
426 }
427
Selim Cinek967ed2a2016-04-08 18:29:11 -0700428 public void setHeadsUpManager(HeadsUpManager headsUpManager) {
429 mHeadsUpManager = headsUpManager;
430 }
431
Selim Cinek52941c52016-05-07 18:29:32 -0400432 public void dump(FileDescriptor fd, PrintWriter pw, String[] args) {
433 pw.println("GroupManager state:");
434 pw.println(" number of groups: " + mGroupMap.size());
435 for (Map.Entry<String, NotificationGroup> entry : mGroupMap.entrySet()) {
436 pw.println("\n key: " + entry.getKey()); pw.println(entry.getValue());
437 }
438 pw.println("\n isolated entries: " + mIsolatedEntries.size());
439 for (Map.Entry<String, StatusBarNotification> entry : mIsolatedEntries.entrySet()) {
440 pw.print(" "); pw.print(entry.getKey());
441 pw.print(", "); pw.println(entry.getValue());
442 }
443 }
444
Selim Cinek25fd4e2b2015-02-20 17:46:07 +0100445 public static class NotificationGroup {
446 public final HashSet<NotificationData.Entry> children = new HashSet<>();
447 public NotificationData.Entry summary;
448 public boolean expanded;
Selim Cinek2a739342016-03-17 10:28:55 -0700449 /**
450 * Is this notification group suppressed, i.e its summary is hidden
451 */
452 public boolean suppressed;
Selim Cinek52941c52016-05-07 18:29:32 -0400453
454 @Override
455 public String toString() {
456 String result = " summary:\n " + summary.notification;
457 result += "\n children size: " + children.size();
458 for (NotificationData.Entry child : children) {
459 result += "\n " + child.notification;
460 }
461 return result;
462 }
Selim Cinek25fd4e2b2015-02-20 17:46:07 +0100463 }
464
465 public interface OnGroupChangeListener {
466 /**
467 * The expansion of a group has changed.
468 *
469 * @param changedRow the row for which the expansion has changed, which is also the summary
470 * @param expanded a boolean indicating the new expanded state
471 */
472 void onGroupExpansionChanged(ExpandableNotificationRow changedRow, boolean expanded);
473
474 /**
Selim Cinek25fd4e2b2015-02-20 17:46:07 +0100475 * A group of children just received a summary notification and should therefore become
476 * children of it.
477 *
478 * @param group the group created
479 */
480 void onGroupCreatedFromChildren(NotificationGroup group);
Selim Cinekef5127e2015-12-21 16:55:58 -0800481
482 /**
Selim Cinek2a739342016-03-17 10:28:55 -0700483 * The groups have changed. This can happen if the isolation of a child has changes or if a
484 * group became suppressed / unsuppressed
Selim Cinekef5127e2015-12-21 16:55:58 -0800485 */
Selim Cinek2a739342016-03-17 10:28:55 -0700486 void onGroupsChanged();
Selim Cinek25fd4e2b2015-02-20 17:46:07 +0100487 }
488}