Merge "Cleaning up the notification data structures."

This commit is contained in:
Daniel Sandler
2010-08-04 13:12:15 -07:00
committed by Android (Google) Code Review
3 changed files with 38 additions and 54 deletions

View File

@@ -22,6 +22,7 @@ import android.view.View;
import com.android.internal.statusbar.StatusBarNotification;
import java.util.Comparator;
import java.util.ArrayList;
/**
@@ -43,30 +44,35 @@ public class NotificationData {
}
}
private final ArrayList<Entry> mEntries = new ArrayList<Entry>();
private final Comparator<Entry> mEntryCmp = new Comparator<Entry>() {
public int compare(Entry a, Entry b) {
return (int)(a.notification.notification.when - b.notification.notification.when);
}
};
public int size() {
return mEntries.size();
}
public Entry getEntryAt(int index) {
return mEntries.get(index);
}
public int findEntry(IBinder key) {
final int N = mEntries.size();
for (int i=0; i<N; i++) {
Entry entry = mEntries.get(i);
if (entry.key == key) {
return i;
public Entry findByKey(IBinder key) {
for (Entry e : mEntries) {
if (e.key == key) {
return e;
}
}
return -1;
return null;
}
public int add(Entry entry) {
final int index = chooseIndex(entry.notification.notification.when);
mEntries.add(index, entry);
return index;
int i;
int N = mEntries.size();
for (i=0; i<N; i++) {
if (mEntryCmp.compare(mEntries.get(i), entry) > 0) {
break;
}
}
mEntries.add(i, entry);
return i;
}
public int add(IBinder key, StatusBarNotification notification, View row, View content,
@@ -82,36 +88,19 @@ public class NotificationData {
}
public Entry remove(IBinder key) {
final int N = mEntries.size();
for (int i=0; i<N; i++) {
Entry entry = mEntries.get(i);
if (entry.key == key) {
mEntries.remove(i);
return entry;
}
Entry e = findByKey(key);
if (e != null) {
mEntries.remove(e);
}
return null;
}
private int chooseIndex(final long when) {
final int N = mEntries.size();
for (int i=0; i<N; i++) {
Entry entry = mEntries.get(i);
if (entry.notification.notification.when > when) {
return i;
}
}
return N;
return e;
}
/**
* Return whether there are any visible items (i.e. items without an error).
*/
public boolean hasVisibleItems() {
final int N = mEntries.size();
for (int i=0; i<N; i++) {
Entry entry = mEntries.get(i);
if (entry.expanded != null) { // the view successfully inflated
for (Entry e : mEntries) {
if (e.expanded != null) { // the view successfully inflated
return true;
}
}
@@ -122,11 +111,9 @@ public class NotificationData {
* Return whether there are any clearable items (that aren't errors).
*/
public boolean hasClearableItems() {
final int N = mEntries.size();
for (int i=0; i<N; i++) {
Entry entry = mEntries.get(i);
if (entry.expanded != null) { // the view successfully inflated
if ((entry.notification.notification.flags & Notification.FLAG_NO_CLEAR) == 0) {
for (Entry e : mEntries) {
if (e.expanded != null) { // the view successfully inflated
if ((e.notification.notification.flags & Notification.FLAG_NO_CLEAR) == 0) {
return true;
}
}

View File

@@ -353,7 +353,7 @@ public class PhoneStatusBarService extends StatusBarService {
if (immersive) {
if ((notification.notification.flags & Notification.FLAG_HIGH_PRIORITY) != 0) {
Slog.d(TAG, "Presenting high-priority notification in immersive activity");
// @@@ special new transient ticker mode
// special new transient ticker mode
// 1. Populate mIntruderAlertView
ImageView alertIcon = (ImageView) mIntruderAlertView.findViewById(R.id.alertIcon);
@@ -399,18 +399,17 @@ public class PhoneStatusBarService extends StatusBarService {
Slog.d(TAG, "updateNotification key=" + key + " notification=" + notification);
NotificationData oldList;
int oldIndex = mOngoing.findEntry(key);
if (oldIndex >= 0) {
NotificationData.Entry oldEntry = mOngoing.findByKey(key);
if (oldEntry != null) {
oldList = mOngoing;
} else {
oldIndex = mLatest.findEntry(key);
if (oldIndex < 0) {
oldEntry = mLatest.findByKey(key);
if (oldEntry == null) {
Slog.w(TAG, "updateNotification for unknown key: " + key);
return;
}
oldList = mLatest;
}
final NotificationData.Entry oldEntry = oldList.getEntryAt(oldIndex);
final StatusBarNotification oldNotification = oldEntry.notification;
final RemoteViews oldContentView = oldNotification.notification.contentView;

View File

@@ -49,7 +49,7 @@ import com.android.systemui.statusbar.*;
import com.android.systemui.R;
public class TabletStatusBarService extends StatusBarService {
public static final boolean DEBUG = true;
public static final boolean DEBUG = false;
public static final String TAG = "TabletStatusBar";
View mStatusBarView;
@@ -195,15 +195,13 @@ public class TabletStatusBarService extends StatusBarService {
public void updateNotification(IBinder key, StatusBarNotification notification) {
if (DEBUG) Slog.d(TAG, "updateNotification(" + key + " -> " + notification + ") // TODO");
NotificationData oldList = mHaps;
int oldIndex = oldList.findEntry(key);
if (oldIndex < 0) {
final NotificationData.Entry oldEntry = mHaps.findByKey(key);
if (oldEntry == null) {
Slog.w(TAG, "updateNotification for unknown key: " + key);
return;
}
final NotificationData.Entry oldEntry = oldList.getEntryAt(oldIndex);
final StatusBarNotification oldNotification = oldEntry.notification;
final RemoteViews oldContentView = oldNotification.notification.contentView;