summaryrefslogtreecommitdiffstats
path: root/packages
diff options
context:
space:
mode:
authorJoe Onorato <joeo@android.com>2010-05-24 16:17:02 -0400
committerJoe Onorato <joeo@android.com>2010-06-02 14:48:44 -0700
commit0e26dffd6cfcb09b08a94a857b891fdef7fe2b1e (patch)
tree4d558b0f54053f69b942cce90d4950f4d34ee92f /packages
parent66b4c5bb36f57a9d83bb7f34288235b82f9be407 (diff)
downloadframeworks_base-0e26dffd6cfcb09b08a94a857b891fdef7fe2b1e.zip
frameworks_base-0e26dffd6cfcb09b08a94a857b891fdef7fe2b1e.tar.gz
frameworks_base-0e26dffd6cfcb09b08a94a857b891fdef7fe2b1e.tar.bz2
updateNotifications works.
Change-Id: I924763a2d42ca1967719f3eb72c57d1cbb912dd7
Diffstat (limited to 'packages')
-rw-r--r--packages/StatusBarPhone/src/com/android/policy/statusbar/phone/NotificationData.java14
-rw-r--r--packages/StatusBarPhone/src/com/android/policy/statusbar/phone/PhoneStatusBarService.java331
2 files changed, 174 insertions, 171 deletions
diff --git a/packages/StatusBarPhone/src/com/android/policy/statusbar/phone/NotificationData.java b/packages/StatusBarPhone/src/com/android/policy/statusbar/phone/NotificationData.java
index 5c7a90c..3c93021 100644
--- a/packages/StatusBarPhone/src/com/android/policy/statusbar/phone/NotificationData.java
+++ b/packages/StatusBarPhone/src/com/android/policy/statusbar/phone/NotificationData.java
@@ -30,8 +30,9 @@ public class NotificationData {
public static final class Entry {
public IBinder key;
public StatusBarNotification notification;
- public View expanded;
public StatusBarIconView icon;
+ public View expanded; // the outer expanded view
+ public View contents; // the inflated RemoteViews
}
private final ArrayList<Entry> mEntries = new ArrayList<Entry>();
@@ -43,6 +44,17 @@ public class NotificationData {
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;
+ }
+ }
+ return -1;
+ }
+
public int add(IBinder key, StatusBarNotification notification, View expanded,
StatusBarIconView icon) {
Entry entry = new Entry();
diff --git a/packages/StatusBarPhone/src/com/android/policy/statusbar/phone/PhoneStatusBarService.java b/packages/StatusBarPhone/src/com/android/policy/statusbar/phone/PhoneStatusBarService.java
index bd9ecb6..397dd47 100644
--- a/packages/StatusBarPhone/src/com/android/policy/statusbar/phone/PhoneStatusBarService.java
+++ b/packages/StatusBarPhone/src/com/android/policy/statusbar/phone/PhoneStatusBarService.java
@@ -297,10 +297,6 @@ public class PhoneStatusBarService extends StatusBarService {
WindowManagerImpl.getDefault().addView(view, lp);
}
- // ================================================================================
- // Always called from the UI thread.
- // ================================================================================
-
public void addIcon(String slot, int index, int viewIndex, StatusBarIcon icon) {
Slog.d(TAG, "addIcon slot=" + slot + " index=" + index + " viewIndex=" + viewIndex
+ " icon=" + icon);
@@ -323,30 +319,7 @@ public class PhoneStatusBarService extends StatusBarService {
}
public void addNotification(IBinder key, StatusBarNotification notification) {
- NotificationData list;
- ViewGroup parent;
- final boolean isOngoing = notification.isOngoing();
- if (isOngoing) {
- list = mOngoing;
- parent = mOngoingItems;
- } else {
- list = mLatest;
- parent = mLatestItems;
- }
- // Construct the expanded view.
- final View view = makeNotificationView(notification, parent);
- // Construct the icon.
- StatusBarIconView iconView = new StatusBarIconView(this,
- notification.pkg + "/" + notification.id);
- iconView.set(new StatusBarIcon(notification.pkg, notification.notification.icon,
- notification.notification.iconLevel));
- // Add the expanded view.
- final int viewIndex = list.add(key, notification, view, iconView);
- parent.addView(view, viewIndex);
- // Add the icon.
- final int iconIndex = chooseIconIndex(isOngoing, viewIndex);
- mNotificationIcons.addView(iconView, iconIndex,
- new LinearLayout.LayoutParams(mIconWidth, mHeight));
+ addNotificationViews(key, notification);
// show the ticker
// TODO
@@ -356,24 +329,66 @@ public class PhoneStatusBarService extends StatusBarService {
}
public void updateNotification(IBinder key, StatusBarNotification notification) {
- }
+ Slog.d(TAG, "updateNotification key=" + key + " notification=" + notification);
- public void removeNotification(IBinder key) {
- Slog.d(TAG, "removeNotification key=" + key);
- NotificationData.Entry entry = mOngoing.remove(key);
- if (entry == null) {
- entry = mLatest.remove(key);
- if (entry == null) {
- Slog.w(TAG, "removeNotification for nonexistent key: " + key);
+ NotificationData oldList;
+ int oldIndex = mOngoing.findEntry(key);
+ if (oldIndex >= 0) {
+ oldList = mOngoing;
+ } else {
+ oldIndex = mLatest.findEntry(key);
+ if (oldIndex < 0) {
+ 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;
+
+ final RemoteViews contentView = notification.notification.contentView;
+
+ // Can we just reapply the RemoteViews in place? If when didn't change, the order
+ // didn't change.
+ if (notification.notification.when == oldNotification.notification.when
+ && notification.isOngoing() == oldNotification.isOngoing()
+ && oldEntry.contents != null
+ && contentView != null && oldContentView != null
+ && contentView.getPackage() != null
+ && oldContentView.getPackage() != null
+ && oldContentView.getPackage().equals(contentView.getPackage())
+ && oldContentView.getLayoutId() == contentView.getLayoutId()) {
+ Slog.d(TAG, "reusing notification");
+ oldEntry.notification = notification;
+ try {
+ // Reapply the RemoteViews
+ contentView.reapply(this, oldEntry.contents);
+ // update the contentIntent
+ ViewGroup clickView = (ViewGroup)oldEntry.expanded.findViewById(
+ com.android.internal.R.id.content);
+ final PendingIntent contentIntent = notification.notification.contentIntent;
+ if (contentIntent != null) {
+ clickView.setOnClickListener(new Launcher(contentIntent, notification.pkg,
+ notification.tag, notification.id));
+ }
+ }
+ catch (RuntimeException e) {
+ // It failed to add cleanly. Log, and remove the view from the panel.
+ Slog.w(TAG, "couldn't reapply views for package " + contentView.getPackage(), e);
+ removeNotificationViews(key);
+ addNotificationViews(key, notification);
+ }
+ // Update the icon.
+ oldEntry.icon.set(new StatusBarIcon(notification.pkg, notification.notification.icon,
+ notification.notification.iconLevel, notification.notification.number));
+ } else {
+ Slog.d(TAG, "not reusing notification");
+ removeNotificationViews(key);
+ addNotificationViews(key, notification);
}
- // Remove the expanded view.
- ((ViewGroup)entry.expanded.getParent()).removeView(entry.expanded);
- // Remove the icon.
- ((ViewGroup)entry.icon.getParent()).removeView(entry.icon);
- // Cancel the ticker if it's still running
+ // Restart the ticker if it's still running
// TODO
// Recalculate the position of the sliding windows and the titles.
@@ -381,66 +396,18 @@ public class PhoneStatusBarService extends StatusBarService {
updateExpandedViewPos(EXPANDED_LEAVE_ALONE);
}
- /**
- * State is one or more of the DISABLE constants from StatusBarManager.
- */
- public void disable(int state) {
- final int old = mDisabled;
- final int diff = state ^ old;
- mDisabled = state;
+ public void removeNotification(IBinder key) {
+ Slog.d(TAG, "removeNotification key=" + key);
+ removeNotificationViews(key);
- if ((diff & StatusBarManager.DISABLE_EXPAND) != 0) {
- if ((state & StatusBarManager.DISABLE_EXPAND) != 0) {
- Slog.d(TAG, "DISABLE_EXPAND: yes");
- animateCollapse();
- }
- }
- if ((diff & StatusBarManager.DISABLE_NOTIFICATION_ICONS) != 0) {
- if ((state & StatusBarManager.DISABLE_NOTIFICATION_ICONS) != 0) {
- Slog.d(TAG, "DISABLE_NOTIFICATION_ICONS: yes");
- if (mTicking) {
- mTicker.halt();
- } else {
- setNotificationIconVisibility(false, com.android.internal.R.anim.fade_out);
- }
- } else {
- Slog.d(TAG, "DISABLE_NOTIFICATION_ICONS: no");
- if (!mExpandedVisible) {
- setNotificationIconVisibility(true, com.android.internal.R.anim.fade_in);
- }
- }
- } else if ((diff & StatusBarManager.DISABLE_NOTIFICATION_TICKER) != 0) {
- if (mTicking && (state & StatusBarManager.DISABLE_NOTIFICATION_TICKER) != 0) {
- Slog.d(TAG, "DISABLE_NOTIFICATION_TICKER: yes");
- mTicker.halt();
- }
- }
- }
+ // Cancel the ticker if it's still running
+ // TODO
- /**
- * All changes to the status bar and notifications funnel through here and are batched.
- */
- private class H extends Handler {
- public void handleMessage(Message m) {
- switch (m.what) {
- case MSG_ANIMATE:
- doAnimation();
- break;
- case MSG_ANIMATE_REVEAL:
- doRevealAnimation();
- break;
- }
- }
+ // Recalculate the position of the sliding windows and the titles.
+ setAreThereNotifications();
+ updateExpandedViewPos(EXPANDED_LEAVE_ALONE);
}
- View.OnFocusChangeListener mFocusChangeListener = new View.OnFocusChangeListener() {
- public void onFocusChange(View v, boolean hasFocus) {
- // Because 'v' is a ViewGroup, all its children will be (un)selected
- // too, which allows marqueeing to work.
- v.setSelected(hasFocus);
- }
- };
-
private int chooseIconIndex(boolean isOngoing, int index) {
final int ongoingSize = mOngoing.size();
final int latestSize = mLatest.size();
@@ -449,7 +416,7 @@ public class PhoneStatusBarService extends StatusBarService {
}
return (ongoingSize + latestSize) - index - 1;
}
-
+
View makeNotificationView(StatusBarNotification notification, ViewGroup parent) {
Notification n = notification.notification;
RemoteViews remoteViews = n.contentView;
@@ -488,88 +455,51 @@ public class PhoneStatusBarService extends StatusBarService {
row.setDrawingCacheEnabled(true);
- /*
- notification.view = row;
- notification.contentView = child;
- */
-
return row;
}
- /*
- StatusBarIcon icon = new StatusBarIcon(pkg, notification.icon,
- notification.iconLevel);
- icon.number = notification.number;
- */
- /*
- void addNotificationView(StatusBarNotification notification) {
- if (notification.view != null) {
- throw new RuntimeException("Assertion failed: notification.view="
- + notification.view);
- }
-
- LinearLayout parent = notification.data.ongoingEvent ? mOngoingItems : mLatestItems;
-
- View child = makeNotificationView(notification, parent);
- if (child == null) {
- return ;
+ void addNotificationViews(IBinder key, StatusBarNotification notification) {
+ NotificationData list;
+ ViewGroup parent;
+ final boolean isOngoing = notification.isOngoing();
+ if (isOngoing) {
+ list = mOngoing;
+ parent = mOngoingItems;
+ } else {
+ list = mLatest;
+ parent = mLatestItems;
}
+ // Construct the expanded view.
+ final View view = makeNotificationView(notification, parent);
+ // Construct the icon.
+ StatusBarIconView iconView = new StatusBarIconView(this,
+ notification.pkg + "/" + notification.id);
+ iconView.set(new StatusBarIcon(notification.pkg, notification.notification.icon,
+ notification.notification.iconLevel, notification.notification.number));
+ // Add the expanded view.
+ final int viewIndex = list.add(key, notification, view, iconView);
+ parent.addView(view, viewIndex);
+ // Add the icon.
+ final int iconIndex = chooseIconIndex(isOngoing, viewIndex);
+ mNotificationIcons.addView(iconView, iconIndex,
+ new LinearLayout.LayoutParams(mIconWidth, mHeight));
- int index = mNotificationData.getExpandedIndex(notification);
- parent.addView(child, index);
}
- */
- /**
- * Remove the old one and put the new one in its place.
- * @param notification the notification
- */
- /*
- void updateNotificationView(StatusBarNotification notification, NotificationData oldData) {
- NotificationData n = notification.data;
- if (oldData != null && n != null
- && n.when == oldData.when
- && n.ongoingEvent == oldData.ongoingEvent
- && n.contentView != null && oldData.contentView != null
- && n.contentView.getPackage() != null
- && oldData.contentView.getPackage() != null
- && oldData.contentView.getPackage().equals(n.contentView.getPackage())
- && oldData.contentView.getLayoutId() == n.contentView.getLayoutId()
- && notification.view != null) {
- mNotificationData.update(notification);
- try {
- n.contentView.reapply(this, notification.contentView);
-
- // update the contentIntent
- ViewGroup content = (ViewGroup)notification.view.findViewById(
- com.android.internal.R.id.content);
- PendingIntent contentIntent = n.contentIntent;
- if (contentIntent != null) {
- content.setOnClickListener(new Launcher(contentIntent, n.pkg, n.tag, n.id));
- }
- }
- catch (RuntimeException e) {
- // It failed to add cleanly. Log, and remove the view from the panel.
- Slog.w(TAG, "couldn't reapply views for package " + n.contentView.getPackage(), e);
- removeNotificationView(notification);
+ void removeNotificationViews(IBinder key) {
+ NotificationData.Entry entry = mOngoing.remove(key);
+ if (entry == null) {
+ entry = mLatest.remove(key);
+ if (entry == null) {
+ Slog.w(TAG, "removeNotification for unknown key: " + key);
+ return;
}
- } else {
- mNotificationData.update(notification);
- removeNotificationView(notification);
- addNotificationView(notification);
- }
- setAreThereNotifications();
- }
-
- void removeNotificationView(StatusBarNotification notification) {
- View v = notification.view;
- if (v != null) {
- ViewGroup parent = (ViewGroup)v.getParent();
- parent.removeView(v);
- notification.view = null;
}
+ // Remove the expanded view.
+ ((ViewGroup)entry.expanded.getParent()).removeView(entry.expanded);
+ // Remove the icon.
+ ((ViewGroup)entry.icon.getParent()).removeView(entry.icon);
}
- */
private void setAreThereNotifications() {
/*
@@ -593,6 +523,67 @@ public class PhoneStatusBarService extends StatusBarService {
*/
}
+
+ /**
+ * State is one or more of the DISABLE constants from StatusBarManager.
+ */
+ public void disable(int state) {
+ final int old = mDisabled;
+ final int diff = state ^ old;
+ mDisabled = state;
+
+ if ((diff & StatusBarManager.DISABLE_EXPAND) != 0) {
+ if ((state & StatusBarManager.DISABLE_EXPAND) != 0) {
+ Slog.d(TAG, "DISABLE_EXPAND: yes");
+ animateCollapse();
+ }
+ }
+ if ((diff & StatusBarManager.DISABLE_NOTIFICATION_ICONS) != 0) {
+ if ((state & StatusBarManager.DISABLE_NOTIFICATION_ICONS) != 0) {
+ Slog.d(TAG, "DISABLE_NOTIFICATION_ICONS: yes");
+ if (mTicking) {
+ mTicker.halt();
+ } else {
+ setNotificationIconVisibility(false, com.android.internal.R.anim.fade_out);
+ }
+ } else {
+ Slog.d(TAG, "DISABLE_NOTIFICATION_ICONS: no");
+ if (!mExpandedVisible) {
+ setNotificationIconVisibility(true, com.android.internal.R.anim.fade_in);
+ }
+ }
+ } else if ((diff & StatusBarManager.DISABLE_NOTIFICATION_TICKER) != 0) {
+ if (mTicking && (state & StatusBarManager.DISABLE_NOTIFICATION_TICKER) != 0) {
+ Slog.d(TAG, "DISABLE_NOTIFICATION_TICKER: yes");
+ mTicker.halt();
+ }
+ }
+ }
+
+ /**
+ * All changes to the status bar and notifications funnel through here and are batched.
+ */
+ private class H extends Handler {
+ public void handleMessage(Message m) {
+ switch (m.what) {
+ case MSG_ANIMATE:
+ doAnimation();
+ break;
+ case MSG_ANIMATE_REVEAL:
+ doRevealAnimation();
+ break;
+ }
+ }
+ }
+
+ View.OnFocusChangeListener mFocusChangeListener = new View.OnFocusChangeListener() {
+ public void onFocusChange(View v, boolean hasFocus) {
+ // Because 'v' is a ViewGroup, all its children will be (un)selected
+ // too, which allows marqueeing to work.
+ v.setSelected(hasFocus);
+ }
+ };
+
private void makeExpandedVisible() {
if (SPEW) Slog.d(TAG, "Make expanded visible: expanded visible=" + mExpandedVisible);
if (mExpandedVisible) {