NotificationData.java revision 6a858c347f4d4e5db4c8f00d5e285967631b71ca
1/* 2 * Copyright (C) 2008 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package com.android.systemui.statusbar; 18 19import android.app.Notification; 20import android.os.IBinder; 21import android.view.View; 22import android.widget.ImageView; 23 24import com.android.internal.statusbar.StatusBarNotification; 25 26import java.util.Comparator; 27import java.util.ArrayList; 28 29/** 30 * The list of currently displaying notifications. 31 */ 32public class NotificationData { 33 public static final class Entry { 34 public IBinder key; 35 public StatusBarNotification notification; 36 public StatusBarIconView icon; 37 public View row; // the outer expanded view 38 public View content; // takes the click events and sends the PendingIntent 39 public View expanded; // the inflated RemoteViews 40 public ImageView largeIcon; 41 public View expandedLarge; 42 public Entry() {} 43 public Entry(IBinder key, StatusBarNotification n, StatusBarIconView ic) { 44 this.key = key; 45 this.notification = n; 46 this.icon = ic; 47 } 48 } 49 private final ArrayList<Entry> mEntries = new ArrayList<Entry>(); 50 private final Comparator<Entry> mEntryCmp = new Comparator<Entry>() { 51 // sort first by score, then by when 52 public int compare(Entry a, Entry b) { 53 final StatusBarNotification na = a.notification; 54 final StatusBarNotification nb = b.notification; 55 int d = na.score - nb.score; 56 return (d != 0) 57 ? d 58 : (int)(na.notification.when - nb.notification.when); 59 } 60 }; 61 62 public int size() { 63 return mEntries.size(); 64 } 65 66 public Entry get(int i) { 67 return mEntries.get(i); 68 } 69 70 public Entry findByKey(IBinder key) { 71 for (Entry e : mEntries) { 72 if (e.key == key) { 73 return e; 74 } 75 } 76 return null; 77 } 78 79 public int add(Entry entry) { 80 int i; 81 int N = mEntries.size(); 82 for (i=0; i<N; i++) { 83 if (mEntryCmp.compare(mEntries.get(i), entry) > 0) { 84 break; 85 } 86 } 87 mEntries.add(i, entry); 88 return i; 89 } 90 91 public int add(IBinder key, StatusBarNotification notification, View row, View content, 92 View expanded, StatusBarIconView icon) { 93 Entry entry = new Entry(); 94 entry.key = key; 95 entry.notification = notification; 96 entry.row = row; 97 entry.content = content; 98 entry.expanded = expanded; 99 entry.icon = icon; 100 entry.largeIcon = null; // TODO add support for large icons 101 return add(entry); 102 } 103 104 public Entry remove(IBinder key) { 105 Entry e = findByKey(key); 106 if (e != null) { 107 mEntries.remove(e); 108 } 109 return e; 110 } 111 112 /** 113 * Return whether there are any visible items (i.e. items without an error). 114 */ 115 public boolean hasVisibleItems() { 116 for (Entry e : mEntries) { 117 if (e.expanded != null) { // the view successfully inflated 118 return true; 119 } 120 } 121 return false; 122 } 123 124 /** 125 * Return whether there are any clearable items (that aren't errors). 126 */ 127 public boolean hasClearableItems() { 128 for (Entry e : mEntries) { 129 if (e.expanded != null) { // the view successfully inflated 130 if (e.notification.isClearable()) { 131 return true; 132 } 133 } 134 } 135 return false; 136 } 137} 138