Skip to content

Commit 2cb4320

Browse files
maniac103nadlabak
authored andcommitted
Close notification view when swiping away the last notification.
If the user swiped away all swipable notifications, chances are high he expanded the notification area just for doing so.
1 parent 722a9cf commit 2cb4320

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

packages/SystemUI/src/com/android/systemui/statusbar/NotificationData.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public static final class Entry {
3535
public View row; // the outer expanded view
3636
public View content; // takes the click events and sends the PendingIntent
3737
public View expanded; // the inflated RemoteViews
38+
public boolean cancelled;
3839
}
3940
private final ArrayList<Entry> mEntries = new ArrayList<Entry>();
4041

@@ -66,6 +67,7 @@ public int add(IBinder key, StatusBarNotification notification, View row, View c
6667
entry.content = content;
6768
entry.expanded = expanded;
6869
entry.icon = icon;
70+
entry.cancelled = false;
6971
final int index = chooseIndex(notification.notification.when);
7072
mEntries.add(index, entry);
7173
return index;

packages/SystemUI/src/com/android/systemui/statusbar/StatusBarService.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -716,7 +716,7 @@ private int chooseIconIndex(boolean isOngoing, int viewIndex) {
716716
}
717717
}
718718

719-
View[] makeNotificationView(final StatusBarNotification notification, ViewGroup parent) {
719+
View[] makeNotificationView(final IBinder key, final StatusBarNotification notification, ViewGroup parent) {
720720
Notification n = notification.notification;
721721
RemoteViews remoteViews = n.contentView;
722722
if (remoteViews == null) {
@@ -731,7 +731,12 @@ View[] makeNotificationView(final StatusBarNotification notification, ViewGroup
731731
public void run() {
732732
try {
733733
mBarService.onNotificationClear(notification.pkg, notification.tag, notification.id);
734-
} catch (RemoteException e) {
734+
735+
int index = mLatest.findEntry(key);
736+
if (index >= 0) {
737+
mLatest.getEntryAt(index).cancelled = true;
738+
}
739+
} catch (RemoteException e) {
735740
// Skip it, don't crash.
736741
}
737742
}
@@ -780,7 +785,7 @@ StatusBarIconView addNotificationViews(IBinder key, StatusBarNotification notifi
780785
parent = mLatestItems;
781786
}
782787
// Construct the expanded view.
783-
final View[] views = makeNotificationView(notification, parent);
788+
final View[] views = makeNotificationView(key, notification, parent);
784789
if (views == null) {
785790
handleNotificationError(key, notification, "Couldn't expand RemoteViews for: "
786791
+ notification);
@@ -821,6 +826,10 @@ StatusBarNotification removeNotificationViews(IBinder key) {
821826
// Remove the icon.
822827
((ViewGroup)entry.icon.getParent()).removeView(entry.icon);
823828

829+
if (entry.cancelled && !mLatest.hasClearableItems()) {
830+
animateCollapse();
831+
}
832+
824833
return entry.notification;
825834
}
826835

0 commit comments

Comments
 (0)