Implement setAreThereNotifications.

Change-Id: I8b69330c35d613ce808a472748dd2651adb5efa3
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 3c93021..5499cc4 100644
--- a/packages/StatusBarPhone/src/com/android/policy/statusbar/phone/NotificationData.java
+++ b/packages/StatusBarPhone/src/com/android/policy/statusbar/phone/NotificationData.java
@@ -16,6 +16,7 @@
 
 package com.android.policy.statusbar.phone;
 
+import android.app.Notification;
 import android.os.IBinder;
 import android.view.View;
 
@@ -89,4 +90,26 @@
         }
         return N;
     }
+
+    /**
+     * Return whether there are any visible items (i.e. items without an error).
+     */
+    public boolean hasVisibleItems() {
+        return mEntries.size() != 0; // TODO
+    }
+
+    /**
+     * Return whether there are any clearable items (that aren't errors).
+     */
+    public boolean hasClearableItems() {
+        final int N = mEntries.size();
+        for (int i=0; i<N; i++) {
+            Entry entry = mEntries.get(i);
+            // TODO: if (!entry.error)
+            if ((entry.notification.notification.flags & Notification.FLAG_NO_CLEAR) == 0) {
+                return true;
+            }
+        }
+        return false;
+    }
 }
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 397dd47..4acd57c 100644
--- a/packages/StatusBarPhone/src/com/android/policy/statusbar/phone/PhoneStatusBarService.java
+++ b/packages/StatusBarPhone/src/com/android/policy/statusbar/phone/PhoneStatusBarService.java
@@ -324,7 +324,8 @@
         // show the ticker
         // TODO
 
-        // recalculate the position of the sliding windows
+        // Recalculate the position of the sliding windows and the titles.
+        setAreThereNotifications();
         updateExpandedViewPos(EXPANDED_LEAVE_ALONE);
     }
 
@@ -483,7 +484,6 @@
         final int iconIndex = chooseIconIndex(isOngoing, viewIndex);
         mNotificationIcons.addView(iconView, iconIndex,
                 new LinearLayout.LayoutParams(mIconWidth, mHeight));
-
     }
 
     void removeNotificationViews(IBinder key) {
@@ -502,11 +502,11 @@
     }
 
     private void setAreThereNotifications() {
-    /*
-        boolean ongoing = mOngoingItems.getChildCount() != 0;
-        boolean latest = mLatestItems.getChildCount() != 0;
+        boolean ongoing = mOngoing.hasVisibleItems();
+        boolean latest = mLatest.hasVisibleItems();
 
-        if (mNotificationData.hasClearableItems()) {
+        // (no ongoing notifications are clearable)
+        if (mLatest.hasClearableItems()) {
             mClearButton.setVisibility(View.VISIBLE);
         } else {
             mClearButton.setVisibility(View.INVISIBLE);
@@ -520,7 +520,6 @@
         } else {
             mNoNotificationsTitle.setVisibility(View.VISIBLE);
         }
-    */
     }