From f55105405578bfd8315584e69faa655800edef77 Mon Sep 17 00:00:00 2001 From: Joe Onorato Date: Tue, 1 Jun 2010 07:46:41 -0700 Subject: Get the ticker working again. Change-Id: Idb7e456bc302578c3866448334eb0ebf0ba235d4 --- .../systemui/statusbar/PhoneStatusBarService.java | 38 +++++++++---- .../systemui/statusbar/StatusBarIconView.java | 9 ++-- .../src/com/android/systemui/statusbar/Ticker.java | 63 +++++++++++++++------- 3 files changed, 78 insertions(+), 32 deletions(-) (limited to 'packages') diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/PhoneStatusBarService.java b/packages/SystemUI/src/com/android/systemui/statusbar/PhoneStatusBarService.java index 1dc16b0..2657ea1 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/PhoneStatusBarService.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/PhoneStatusBarService.java @@ -16,7 +16,6 @@ package com.android.systemui.statusbar; -import com.android.internal.util.CharSequences; import com.android.internal.statusbar.IStatusBar; import com.android.internal.statusbar.IStatusBarService; import com.android.internal.statusbar.StatusBarIcon; @@ -334,7 +333,7 @@ public class PhoneStatusBarService extends StatusBarService { addNotificationViews(key, notification); // show the ticker - // TODO + tick(notification); // Recalculate the position of the sliding windows and the titles. setAreThereNotifications(); @@ -400,7 +399,7 @@ public class PhoneStatusBarService extends StatusBarService { } // Restart the ticker if it's still running - // TODO + tick(notification); // Recalculate the position of the sliding windows and the titles. setAreThereNotifications(); @@ -409,14 +408,16 @@ public class PhoneStatusBarService extends StatusBarService { public void removeNotification(IBinder key) { Slog.d(TAG, "removeNotification key=" + key); - removeNotificationViews(key); + StatusBarNotification old = removeNotificationViews(key); - // Cancel the ticker if it's still running - // TODO + if (old != null) { + // Cancel the ticker if it's still running + mTicker.removeEntry(old); - // Recalculate the position of the sliding windows and the titles. - setAreThereNotifications(); - updateExpandedViewPos(EXPANDED_LEAVE_ALONE); + // Recalculate the position of the sliding windows and the titles. + setAreThereNotifications(); + updateExpandedViewPos(EXPANDED_LEAVE_ALONE); + } } private int chooseIconIndex(boolean isOngoing, int viewIndex) { @@ -499,19 +500,21 @@ public class PhoneStatusBarService extends StatusBarService { new LinearLayout.LayoutParams(mIconWidth, mHeight)); } - void removeNotificationViews(IBinder key) { + StatusBarNotification 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; + return null; } } // Remove the expanded view. ((ViewGroup)entry.row.getParent()).removeView(entry.row); // Remove the icon. ((ViewGroup)entry.icon.getParent()).removeView(entry.icon); + + return entry.notification; } private void setAreThereNotifications() { @@ -960,6 +963,19 @@ public class PhoneStatusBarService extends StatusBarService { } } + private void tick(StatusBarNotification n) { + // Show the ticker if one is requested. Also don't do this + // until status bar window is attached to the window manager, + // because... well, what's the point otherwise? And trying to + // run a ticker without being attached will crash! + if (n.notification.tickerText != null && mStatusBarView.getWindowToken() != null) { + if (0 == (mDisabled & (StatusBarManager.DISABLE_NOTIFICATION_ICONS + | StatusBarManager.DISABLE_NOTIFICATION_TICKER))) { + mTicker.addEntry(n); + } + } + } + private class MyTicker extends Ticker { MyTicker(Context context, StatusBarView sb) { super(context, sb); diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/StatusBarIconView.java b/packages/SystemUI/src/com/android/systemui/statusbar/StatusBarIconView.java index ca5db88..5eb0d68 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/StatusBarIconView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/StatusBarIconView.java @@ -69,6 +69,7 @@ public class StatusBarIconView extends AnimatedImageView { Drawable drawable = getIcon(icon); if (drawable == null) { mError = true; + Slog.w(PhoneStatusBarService.TAG, "No icon ID for slot " + mSlot); break error; } setImageDrawable(drawable); @@ -86,6 +87,10 @@ public class StatusBarIconView extends AnimatedImageView { } } + private Drawable getIcon(StatusBarIcon icon) { + return getIcon(getContext(), icon); + } + /** * Returns the right icon to use for this item, respecting the iconId and * iconPackage (if set) @@ -94,8 +99,7 @@ public class StatusBarIconView extends AnimatedImageView { * @return Drawable for this item, or null if the package or item could not * be found */ - private Drawable getIcon(StatusBarIcon icon) { - Context context = getContext(); + public static Drawable getIcon(Context context, StatusBarIcon icon) { Resources r = null; if (icon.iconPackage != null) { @@ -110,7 +114,6 @@ public class StatusBarIconView extends AnimatedImageView { } if (icon.iconId == 0) { - Slog.w(PhoneStatusBarService.TAG, "No icon ID for slot " + mSlot); return null; } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/Ticker.java b/packages/SystemUI/src/com/android/systemui/statusbar/Ticker.java index c3647cb..07e8653 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/Ticker.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/Ticker.java @@ -33,14 +33,24 @@ import android.widget.ImageSwitcher; import java.util.ArrayList; +import com.android.internal.statusbar.StatusBarIcon; import com.android.internal.statusbar.StatusBarNotification; +import com.android.internal.util.CharSequences; import com.android.systemui.R; public abstract class Ticker { private static final int TICKER_SEGMENT_DELAY = 3000; + private Context mContext; + private Handler mHandler = new Handler(); + private ArrayList mSegments = new ArrayList(); + private TextPaint mPaint; + private View mTickerView; + private ImageSwitcher mIconSwitcher; + private TextSwitcher mTextSwitcher; + private final class Segment { - StatusBarNotification notificationData; + StatusBarNotification notification; Drawable icon; CharSequence text; int current; @@ -117,7 +127,7 @@ public abstract class Ticker { } Segment(StatusBarNotification n, Drawable icon, CharSequence text) { - this.notificationData = n; + this.notification = n; this.icon = icon; this.text = text; int index = 0; @@ -131,14 +141,8 @@ public abstract class Ticker { } }; - private Handler mHandler = new Handler(); - private ArrayList mSegments = new ArrayList(); - private TextPaint mPaint; - private View mTickerView; - private ImageSwitcher mIconSwitcher; - private TextSwitcher mTextSwitcher; - Ticker(Context context, StatusBarView sb) { + mContext = context; mTickerView = sb.findViewById(R.id.ticker); mIconSwitcher = (ImageSwitcher)sb.findViewById(R.id.tickerIcon); @@ -158,20 +162,34 @@ public abstract class Ticker { mPaint = text.getPaint(); } - void addEntry(StatusBarNotification n, Drawable icon, CharSequence text) { + + void addEntry(StatusBarNotification n) { int initialCount = mSegments.size(); - Segment newSegment = new Segment(n, icon, text); + // If what's being displayed has the same text and icon, just drop it + // (which will let the current one finish, this happens when apps do + // a notification storm). + if (initialCount > 0) { + final Segment seg = mSegments.get(0); + if (n.pkg.equals(seg.notification.pkg) + && n.notification.icon == seg.notification.notification.icon + && n.notification.iconLevel == seg.notification.notification.iconLevel + && CharSequences.equals(seg.notification.notification.tickerText, + n.notification.tickerText)) { + return; + } + } + + final Drawable icon = StatusBarIconView.getIcon(mContext, + new StatusBarIcon(n.pkg, n.notification.icon, n.notification.iconLevel, 0)); + final Segment newSegment = new Segment(n, icon, n.notification.tickerText); - // prune out any preexisting ones for this notification, but not the current one. - // let that finish, even if it's the same id - for (int i=1; i=0; i--) { + Segment seg = mSegments.get(i); + if (n.id == seg.notification.id && n.pkg.equals(seg.notification.pkg)) { + mSegments.remove(i); + } + } + } + void halt() { mHandler.removeCallbacks(mAdvanceTicker); mSegments.clear(); -- cgit v1.1