From 50ec5ec0b8b3ab9cf697c8e3925e3fdd837f5e7d Mon Sep 17 00:00:00 2001 From: Joe Onorato Date: Sun, 28 Nov 2010 17:15:26 -0800 Subject: [PATCH] Deal with re-posting tickers. Change-Id: If3c6e8ad57eb6682145cf8ed0f3755f176f117d0 --- .../statusbar/tablet/TabletStatusBar.java | 34 +++++--- .../statusbar/tablet/TabletTicker.java | 81 ++++++++++++++----- 2 files changed, 85 insertions(+), 30 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/tablet/TabletStatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/tablet/TabletStatusBar.java index 3b27992836370..b0c73c0974218 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/tablet/TabletStatusBar.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/tablet/TabletStatusBar.java @@ -388,6 +388,7 @@ public class TabletStatusBar extends StatusBar { mNotificationPanel.setVisibility(View.VISIBLE); // synchronize with current shadow state mShadowController.hideElement(mNotificationArea); + mTicker.halt(); } break; case MSG_CLOSE_NOTIFICATION_PANEL: @@ -458,12 +459,7 @@ public class TabletStatusBar extends StatusBar { if (DEBUG) Slog.d(TAG, "addNotification(" + key + " -> " + notification + ")"); addNotificationViews(key, notification); - boolean immersive = false; - try { - immersive = ActivityManagerNative.getDefault().isTopActivityImmersive(); - //Slog.d(TAG, "Top activity is " + (immersive?"immersive":"not immersive")); - } catch (RemoteException ex) { - } + final boolean immersive = isImmersive(); if (false && immersive) { // TODO: immersive mode popups for tablet } else if (notification.notification.fullScreenIntent != null) { @@ -475,7 +471,7 @@ public class TabletStatusBar extends StatusBar { } catch (PendingIntent.CanceledException e) { } } else { - tick(notification); + tick(key, notification); } setAreThereNotifications(); @@ -549,7 +545,14 @@ public class TabletStatusBar extends StatusBar { removeNotificationViews(key); addNotificationViews(key, notification); } - // TODO: ticker; immersive mode + // fullScreenIntent doesn't happen on updates. You need to clear & repost a new + // notification. + final boolean immersive = isImmersive(); + if (false && immersive) { + // TODO: immersive mode + } else { + tick(key, notification); + } setAreThereNotifications(); } @@ -557,6 +560,7 @@ public class TabletStatusBar extends StatusBar { public void removeNotification(IBinder key) { if (DEBUG) Slog.d(TAG, "removeNotification(" + key + ") // TODO"); removeNotificationViews(key); + mTicker.remove(key); setAreThereNotifications(); } @@ -603,7 +607,7 @@ public class TabletStatusBar extends StatusBar { return n.tickerView != null || !TextUtils.isEmpty(n.tickerText); } - private void tick(StatusBarNotification n) { + private void tick(IBinder key, StatusBarNotification n) { // Don't show the ticker when the windowshade is open. if (mNotificationPanel.getVisibility() == View.VISIBLE) { return; @@ -615,7 +619,7 @@ public class TabletStatusBar extends StatusBar { if (hasTicker(n.notification) && mStatusBarView.getWindowToken() != null) { if (0 == (mDisabled & (StatusBarManager.DISABLE_NOTIFICATION_ICONS | StatusBarManager.DISABLE_NOTIFICATION_TICKER))) { - mTicker.add(n); + mTicker.add(key, n); } } } @@ -655,6 +659,16 @@ public class TabletStatusBar extends StatusBar { mInputMethodShortcutButton.setIMEButtonVisible(token, visible); } + private boolean isImmersive() { + try { + return ActivityManagerNative.getDefault().isTopActivityImmersive(); + //Slog.d(TAG, "Top activity is " + (immersive?"immersive":"not immersive")); + } catch (RemoteException ex) { + // the end is nigh + return false; + } + } + private void setAreThereNotifications() { final boolean hasClearable = mNotns.hasClearableItems(); diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/tablet/TabletTicker.java b/packages/SystemUI/src/com/android/systemui/statusbar/tablet/TabletTicker.java index 4d0afce703898..b3aed03a3440c 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/tablet/TabletTicker.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/tablet/TabletTicker.java @@ -25,6 +25,7 @@ import android.graphics.Bitmap; import android.graphics.PixelFormat; import android.graphics.drawable.Drawable; import android.os.Handler; +import android.os.IBinder; import android.os.Message; import android.util.Slog; import android.view.Gravity; @@ -47,6 +48,9 @@ import com.android.systemui.statusbar.StatusBarIconView; public class TabletTicker extends Handler { private static final String TAG = "StatusBar.TabletTicker"; + // 3 is enough to let us see most cases, but not get so far behind that it's too annoying. + private static final int QUEUE_LENGTH = 3; + private static final int MSG_ADVANCE = 1; private static final int ADVANCE_DELAY = 5000; // 5 seconds @@ -54,42 +58,77 @@ public class TabletTicker extends Handler { private Context mContext; private ViewGroup mWindow; + private IBinder mCurrentKey; private StatusBarNotification mCurrentNotification; private View mCurrentView; - private StatusBarNotification[] mQueue; + private IBinder[] mKeys = new IBinder[QUEUE_LENGTH]; + private StatusBarNotification[] mQueue = new StatusBarNotification[QUEUE_LENGTH]; private int mQueuePos; public TabletTicker(Context context) { mContext = context; - - // TODO: Make this a configuration value. - // 3 is enough to let us see most cases, but not get so far behind that it's annoying. - mQueue = new StatusBarNotification[3]; } - public void add(StatusBarNotification notification) { + public void add(IBinder key, StatusBarNotification notification) { if (false) { - Slog.d(TAG, "add mCurrentNotification=" + mCurrentNotification + Slog.d(TAG, "add 1 mCurrentNotification=" + mCurrentNotification + " mQueuePos=" + mQueuePos + " mQueue=" + Arrays.toString(mQueue)); } + + // If it's already in here, remove whatever's in there and put the new one at the end. + remove(key, false); + + mKeys[mQueuePos] = key; mQueue[mQueuePos] = notification; - // If nothing is running now, start the next one - if (mQueuePos == 0) { + // If nothing is running now, start the next one. + if (mQueuePos == 0 && mCurrentNotification == null) { sendEmptyMessage(MSG_ADVANCE); } - if (mQueuePos < mQueue.length - 1) { + if (mQueuePos < QUEUE_LENGTH - 1) { mQueuePos++; } } + public void remove(IBinder key) { + remove(key, true); + } + + public void remove(IBinder key, boolean advance) { + if (mCurrentKey == key) { + Slog.d(TAG, "removed current"); + // Showing now + if (advance) { + removeMessages(MSG_ADVANCE); + sendEmptyMessage(MSG_ADVANCE); + } + } else { + // In the queue + for (int i=0; i 0) { + mQueuePos--; + } + break; + } + } + } + } + public void halt() { removeMessages(MSG_ADVANCE); if (mCurrentView != null || mQueuePos != 0) { - final int N = mQueue.length; - for (int i=0; i