Deal with re-posting tickers.

Change-Id: If3c6e8ad57eb6682145cf8ed0f3755f176f117d0
This commit is contained in:
Joe Onorato
2010-11-28 17:15:26 -08:00
parent 5a6b4f8265
commit 50ec5ec0b8
2 changed files with 85 additions and 30 deletions

View File

@@ -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();

View File

@@ -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<QUEUE_LENGTH; i++) {
if (mKeys[i] == key) {
Slog.d(TAG, "removed from queue: " + i);
for (; i<QUEUE_LENGTH-1; i++) {
mKeys[i] = mKeys[i+1];
mQueue[i] = mQueue[i+1];
}
mKeys[QUEUE_LENGTH-1] = null;
mQueue[QUEUE_LENGTH-1] = null;
if (mQueuePos > 0) {
mQueuePos--;
}
break;
}
}
}
}
public void halt() {
removeMessages(MSG_ADVANCE);
if (mCurrentView != null || mQueuePos != 0) {
final int N = mQueue.length;
for (int i=0; i<N; i++) {
for (int i=0; i<QUEUE_LENGTH; i++) {
mKeys[i] = null;
mQueue[i] = null;
}
mQueuePos = 0;
@@ -110,14 +149,14 @@ public class TabletTicker extends Handler {
if (mCurrentView != null) {
mWindow.removeView(mCurrentView);
mCurrentView = null;
mCurrentKey = null;
mCurrentNotification = null;
}
// In with the new...
StatusBarNotification next = dequeue();
while (next != null) {
mCurrentNotification = next;
mCurrentView = makeTickerView(next);
dequeue();
while (mCurrentNotification != null) {
mCurrentView = makeTickerView(mCurrentNotification);
if (mCurrentView != null) {
if (mWindow == null) {
mWindow = makeWindow();
@@ -127,7 +166,7 @@ public class TabletTicker extends Handler {
sendEmptyMessageDelayed(MSG_ADVANCE, ADVANCE_DELAY);
break;
}
next = dequeue();
dequeue();
}
// if there's nothing left, close the window
@@ -138,20 +177,22 @@ public class TabletTicker extends Handler {
}
}
private StatusBarNotification dequeue() {
StatusBarNotification notification = mQueue[0];
private void dequeue() {
mCurrentKey = mKeys[0];
mCurrentNotification = mQueue[0];
if (false) {
Slog.d(TAG, "dequeue mQueuePos=" + mQueuePos + " mQueue=" + Arrays.toString(mQueue));
}
final int N = mQueuePos;
for (int i=0; i<N; i++) {
mKeys[i] = mKeys[i+1];
mQueue[i] = mQueue[i+1];
}
mKeys[N] = null;
mQueue[N] = null;
if (mQueuePos > 0) {
mQueuePos--;
}
return notification;
}
private ViewGroup makeWindow() {