NotificationData.java revision 379020aec619c66d3e040de01f0726687fd2ad85
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 findByKey(IBinder key) { 58 for (Entry e : mEntries) { 59 if (e.key == key) { 60 return e; 61 } 62 } 63 return null; 64 } 65 66 public int add(Entry entry) { 67 int i; 68 int N = mEntries.size(); 69 for (i=0; i<N; i++) { 70 if (mEntryCmp.compare(mEntries.get(i), entry) > 0) { 71 break; 72 } 73 } 74 mEntries.add(i, entry); 75 return i; 76 } 77 78 public int add(IBinder key, StatusBarNotification notification, View row, View content, 79 View expanded, StatusBarIconView icon) { 80 Entry entry = new Entry(); 81 entry.key = key; 82 entry.notification = notification; 83 entry.row = row; 84 entry.content = content; 85 entry.expanded = expanded; 86 entry.icon = icon; 87 return add(entry); 88 } 89 90 public Entry remove(IBinder key) { 91 Entry e = findByKey(key); 92 if (e != null) { 93 mEntries.remove(e); 94 } 95 return e; 96 } 97 98 /** 99 * Return whether there are any visible items (i.e. items without an error). 100 */ 101 public boolean hasVisibleItems() { 102 for (Entry e : mEntries) { 103 if (e.expanded != null) { // the view successfully inflated 104 return true; 105 } 106 } 107 return false; 108 } 109 110 /** 111 * Return whether there are any clearable items (that aren't errors). 112 */ 113 public boolean hasClearableItems() { 114 for (Entry e : mEntries) { 115 if (e.expanded != null) { // the view successfully inflated 116 if ((e.notification.notification.flags & Notification.FLAG_NO_CLEAR) == 0) { 117 return true; 118 } 119 } 120 } 121 return false; 122 } 123} 124