NotificationData.java revision 80a44401a22344f7eabce6976372ab144ef22893
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 Entry() {} 42 public Entry(IBinder key, StatusBarNotification n, StatusBarIconView ic) { 43 this.key = key; 44 this.notification = n; 45 this.icon = ic; 46 } 47 } 48 private final ArrayList<Entry> mEntries = new ArrayList<Entry>(); 49 private final Comparator<Entry> mEntryCmp = new Comparator<Entry>() { 50 public int compare(Entry a, Entry b) { 51 return (int)(a.notification.notification.when - b.notification.notification.when); 52 } 53 }; 54 55 public int size() { 56 return mEntries.size(); 57 } 58 59 public Entry get(int i) { 60 return mEntries.get(i); 61 } 62 63 public Entry findByKey(IBinder key) { 64 for (Entry e : mEntries) { 65 if (e.key == key) { 66 return e; 67 } 68 } 69 return null; 70 } 71 72 public int add(Entry entry) { 73 int i; 74 int N = mEntries.size(); 75 for (i=0; i<N; i++) { 76 if (mEntryCmp.compare(mEntries.get(i), entry) > 0) { 77 break; 78 } 79 } 80 mEntries.add(i, entry); 81 return i; 82 } 83 84 public int add(IBinder key, StatusBarNotification notification, View row, View content, 85 View expanded, StatusBarIconView icon) { 86 Entry entry = new Entry(); 87 entry.key = key; 88 entry.notification = notification; 89 entry.row = row; 90 entry.content = content; 91 entry.expanded = expanded; 92 entry.icon = icon; 93 entry.largeIcon = null; // TODO add support for large icons 94 return add(entry); 95 } 96 97 public Entry remove(IBinder key) { 98 Entry e = findByKey(key); 99 if (e != null) { 100 mEntries.remove(e); 101 } 102 return e; 103 } 104 105 /** 106 * Return whether there are any visible items (i.e. items without an error). 107 */ 108 public boolean hasVisibleItems() { 109 for (Entry e : mEntries) { 110 if (e.expanded != null) { // the view successfully inflated 111 return true; 112 } 113 } 114 return false; 115 } 116 117 /** 118 * Return whether there are any clearable items (that aren't errors). 119 */ 120 public boolean hasClearableItems() { 121 for (Entry e : mEntries) { 122 if (e.expanded != null) { // the view successfully inflated 123 if (e.notification.isClearable()) { 124 return true; 125 } 126 } 127 } 128 return false; 129 } 130} 131