Optimizations in the notification list:
- sort notifications by timestamp - deal with notification bursts better by waiting to refresh the list until things settle down Change-Id: Ie41051afcb0a7a917f2a97a3311628b34626c125
This commit is contained in:
@@ -30,6 +30,7 @@ import android.content.res.Resources;
|
|||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.os.Handler;
|
||||||
import android.os.RemoteException;
|
import android.os.RemoteException;
|
||||||
import android.os.ServiceManager;
|
import android.os.ServiceManager;
|
||||||
import android.os.UserHandle;
|
import android.os.UserHandle;
|
||||||
@@ -46,6 +47,7 @@ import android.widget.TextView;
|
|||||||
import com.android.internal.statusbar.StatusBarNotification;
|
import com.android.internal.statusbar.StatusBarNotification;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class NotificationStation extends SettingsPreferenceFragment {
|
public class NotificationStation extends SettingsPreferenceFragment {
|
||||||
@@ -57,23 +59,43 @@ public class NotificationStation extends SettingsPreferenceFragment {
|
|||||||
private final PackageReceiver mPackageReceiver = new PackageReceiver();
|
private final PackageReceiver mPackageReceiver = new PackageReceiver();
|
||||||
|
|
||||||
private INotificationManager mNoMan;
|
private INotificationManager mNoMan;
|
||||||
|
|
||||||
|
private Runnable mRefreshListRunnable = new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
refreshList();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
private INotificationListener.Stub mListener = new INotificationListener.Stub() {
|
private INotificationListener.Stub mListener = new INotificationListener.Stub() {
|
||||||
@Override
|
@Override
|
||||||
public void onNotificationPosted(StatusBarNotification notification) throws RemoteException {
|
public void onNotificationPosted(StatusBarNotification notification) throws RemoteException {
|
||||||
Log.v(TAG, "onNotificationPosted: " + notification);
|
Log.v(TAG, "onNotificationPosted: " + notification);
|
||||||
getListView().post(new Runnable() { public void run() { refreshList(); }});
|
final Handler h = getListView().getHandler();
|
||||||
|
h.removeCallbacks(mRefreshListRunnable);
|
||||||
|
h.postDelayed(mRefreshListRunnable, 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onNotificationRemoved(StatusBarNotification notification) throws RemoteException {
|
public void onNotificationRemoved(StatusBarNotification notification) throws RemoteException {
|
||||||
Log.v(TAG, "onNotificationRemoved: " + notification);
|
final Handler h = getListView().getHandler();
|
||||||
getListView().post(new Runnable() { public void run() { refreshList(); }});
|
h.removeCallbacks(mRefreshListRunnable);
|
||||||
|
h.postDelayed(mRefreshListRunnable, 100);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private NotificationHistoryAdapter mAdapter;
|
private NotificationHistoryAdapter mAdapter;
|
||||||
private Context mContext;
|
private Context mContext;
|
||||||
|
|
||||||
|
private final Comparator<HistoricalNotificationInfo> mNotificationSorter
|
||||||
|
= new Comparator<HistoricalNotificationInfo>() {
|
||||||
|
@Override
|
||||||
|
public int compare(HistoricalNotificationInfo lhs,
|
||||||
|
HistoricalNotificationInfo rhs) {
|
||||||
|
return (int)(rhs.timestamp - lhs.timestamp);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAttach(Activity activity) {
|
public void onAttach(Activity activity) {
|
||||||
logd("onAttach(%s)", activity.getClass().getSimpleName());
|
logd("onAttach(%s)", activity.getClass().getSimpleName());
|
||||||
@@ -146,6 +168,7 @@ public class NotificationStation extends SettingsPreferenceFragment {
|
|||||||
logd("adding %d infos", infos.size());
|
logd("adding %d infos", infos.size());
|
||||||
mAdapter.clear();
|
mAdapter.clear();
|
||||||
mAdapter.addAll(infos);
|
mAdapter.addAll(infos);
|
||||||
|
mAdapter.sort(mNotificationSorter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user