NotificationData.java revision 5dd1169ae95162383acf00d1e9a1886e0ac99a70
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; 22 23import com.android.internal.statusbar.StatusBarNotification; 24 25import java.util.Comparator; 26import java.util.ArrayList; 27 28/** 29 * The list of currently displaying notifications. 30 */ 31public class NotificationData { 32 public static final class Entry { 33 public IBinder key; 34 public StatusBarNotification notification; 35 public StatusBarIconView icon; 36 public View row; // the outer expanded view 37 public View content; // takes the click events and sends the PendingIntent 38 public View expanded; // the inflated RemoteViews 39 public Entry() {} 40 public Entry(IBinder key, StatusBarNotification n, StatusBarIconView ic) { 41 this.key = key; 42 this.notification = n; 43 this.icon = ic; 44 } 45 } 46 private final ArrayList<Entry> mEntries = new ArrayList<Entry>(); 47 private final Comparator<Entry> mEntryCmp = new Comparator<Entry>() { 48 public int compare(Entry a, Entry b) { 49 return (int)(a.notification.notification.when - b.notification.notification.when); 50 } 51 }; 52 53 public int size() { 54 return mEntries.size(); 55 } 56 57 public Entry get(int i) { 58 return mEntries.get(i); 59 } 60 61 public Entry findByKey(IBinder key) { 62 for (Entry e : mEntries) { 63 if (e.key == key) { 64 return e; 65 } 66 } 67 return null; 68 } 69 70 public int add(Entry entry) { 71 int i; 72 int N = mEntries.size(); 73 for (i=0; i<N; i++) { 74 if (mEntryCmp.compare(mEntries.get(i), entry) > 0) { 75 break; 76 } 77 } 78 mEntries.add(i, entry); 79 return i; 80 } 81 82 public int add(IBinder key, StatusBarNotification notification, View row, View content, 83 View expanded, StatusBarIconView icon) { 84 Entry entry = new Entry(); 85 entry.key = key; 86 entry.notification = notification; 87 entry.row = row; 88 entry.content = content; 89 entry.expanded = expanded; 90 entry.icon = icon; 91 return add(entry); 92 } 93 94 public Entry remove(IBinder key) { 95 Entry e = findByKey(key); 96 if (e != null) { 97 mEntries.remove(e); 98 } 99 return e; 100 } 101 102 /** 103 * Return whether there are any visible items (i.e. items without an error). 104 */ 105 public boolean hasVisibleItems() { 106 for (Entry e : mEntries) { 107 if (e.expanded != null) { // the view successfully inflated 108 return true; 109 } 110 } 111 return false; 112 } 113 114 /** 115 * Return whether there are any clearable items (that aren't errors). 116 */ 117 public boolean hasClearableItems() { 118 for (Entry e : mEntries) { 119 if (e.expanded != null) { // the view successfully inflated 120 if (e.notification.isClearable()) { 121 return true; 122 } 123 } 124 } 125 return false; 126 } 127} 128