Made ranking consistent with heads Up manager

Change-Id: I8e83c2e7e5a5635c1c0fb83cf2b4614965336786
This commit is contained in:
Selim Cinek
2015-04-13 16:09:49 -07:00
parent c80fdb11f5
commit fbe9a44a15
4 changed files with 36 additions and 17 deletions

View File

@@ -1925,9 +1925,9 @@ public abstract class BaseStatusBar extends SystemUI implements
entry.icon.set(ic);
inflateViews(entry, mStackScroller);
}
updateHeadsUp(key, entry, shouldInterrupt, alertAgain);
mNotificationData.updateRanking(ranking);
updateNotifications();
updateHeadsUp(key, entry, shouldInterrupt, alertAgain);
// Update the veto button accordingly (and as a result, whether this row is
// swipe-dismissable)

View File

@@ -25,6 +25,7 @@ import android.util.ArrayMap;
import android.view.View;
import com.android.systemui.statusbar.phone.NotificationGroupManager;
import com.android.systemui.statusbar.policy.HeadsUpManager;
import java.io.PrintWriter;
import java.util.ArrayList;
@@ -37,6 +38,7 @@ import java.util.Comparator;
public class NotificationData {
private final Environment mEnvironment;
private HeadsUpManager mHeadsUpManager;
public static final class Entry {
public String key;
@@ -98,43 +100,47 @@ public class NotificationData {
private RankingMap mRankingMap;
private final Ranking mTmpRanking = new Ranking();
public void setHeadsUpManager(HeadsUpManager headsUpManager) {
mHeadsUpManager = headsUpManager;
}
private final Comparator<Entry> mRankingComparator = new Comparator<Entry>() {
private final Ranking mRankingA = new Ranking();
private final Ranking mRankingB = new Ranking();
@Override
public int compare(Entry a, Entry b) {
// Upsort current media notification.
String mediaNotification = mEnvironment.getCurrentMediaNotificationKey();
boolean aMedia = a.key.equals(mediaNotification);
boolean bMedia = b.key.equals(mediaNotification);
if (aMedia != bMedia) {
return aMedia ? -1 : 1;
}
final StatusBarNotification na = a.notification;
final StatusBarNotification nb = b.notification;
// Upsort PRIORITY_MAX system notifications
boolean aSystemMax = na.getNotification().priority >= Notification.PRIORITY_MAX &&
isSystemNotification(na);
boolean bSystemMax = nb.getNotification().priority >= Notification.PRIORITY_MAX &&
isSystemNotification(nb);
if (aSystemMax != bSystemMax) {
return aSystemMax ? -1 : 1;
}
int d = nb.getScore() - na.getScore();
// RankingMap as received from NoMan.
if (mRankingMap != null) {
boolean isHeadsUp = a.row.isHeadsUp();
if (isHeadsUp != b.row.isHeadsUp()) {
return isHeadsUp ? -1 : 1;
} else if (isHeadsUp) {
// Provide consistent ranking with headsUpManager
return mHeadsUpManager.compare(a, b);
} else if (aMedia != bMedia) {
// Upsort current media notification.
return aMedia ? -1 : 1;
} else if (aSystemMax != bSystemMax) {
// Upsort PRIORITY_MAX system notifications
return aSystemMax ? -1 : 1;
} else if (mRankingMap != null) {
// RankingMap as received from NoMan
mRankingMap.getRanking(a.key, mRankingA);
mRankingMap.getRanking(b.key, mRankingB);
return mRankingA.getRank() - mRankingB.getRank();
}
int d = nb.getScore() - na.getScore();
if (a.interruption != b.interruption) {
return a.interruption ? -1 : 1;
} else if (d != 0) {
} if (d != 0) {
return d;
} else {
return (int) (nb.getNotification().when - na.getNotification().when);

View File

@@ -621,6 +621,7 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
mHeadsUpManager.addListener(this);
mHeadsUpManager.addListener(mNotificationPanel);
mNotificationPanel.setHeadsUpManager(mHeadsUpManager);
mNotificationData.setHeadsUpManager(mHeadsUpManager);
if (MULTIUSER_DEBUG) {
mNotificationPanelDebugText = (TextView) mNotificationPanel.findViewById(
@@ -1856,7 +1857,10 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
if (mHeadsUpEntriesToRemoveOnSwitch.isEmpty()) {
mLatestRankingMap = null;
}
} else {
updateNotificationRanking(null);
}
}
/**

View File

@@ -438,6 +438,15 @@ public class HeadsUpManager implements ViewTreeObserver.OnComputeInternalInsetsL
return topEntry != null ? topEntry.entry.row.getHeadsUpHeight() : 0;
}
public int compare(NotificationData.Entry a, NotificationData.Entry b) {
HeadsUpEntry aEntry = getHeadsUpEntry(a.key);
HeadsUpEntry bEntry = getHeadsUpEntry(b.key);
if (aEntry == null || bEntry == null) {
return aEntry == null ? 1 : -1;
}
return aEntry.compareTo(bEntry);
}
public class HeadsUpEntry implements Comparable<HeadsUpEntry> {
public NotificationData.Entry entry;
public long postTime;