• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
17 package com.android.systemui.statusbar;
18 
19 import android.app.Notification;
20 import android.os.IBinder;
21 import android.view.View;
22 import android.widget.ImageView;
23 
24 import com.android.internal.statusbar.StatusBarNotification;
25 
26 import java.util.Comparator;
27 import java.util.ArrayList;
28 
29 /**
30  * The list of currently displaying notifications.
31  */
32 public 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;
Entry()41         public Entry() {}
Entry(IBinder key, StatusBarNotification n, StatusBarIconView ic)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             final StatusBarNotification na = a.notification;
52             final StatusBarNotification nb = b.notification;
53             int priDiff = na.priority - nb.priority;
54             return (priDiff != 0)
55                 ? priDiff
56                 : (int)(na.notification.when - nb.notification.when);
57         }
58     };
59 
size()60     public int size() {
61         return mEntries.size();
62     }
63 
get(int i)64     public Entry get(int i) {
65         return mEntries.get(i);
66     }
67 
findByKey(IBinder key)68     public Entry findByKey(IBinder key) {
69         for (Entry e : mEntries) {
70             if (e.key == key) {
71                 return e;
72             }
73         }
74         return null;
75     }
76 
add(Entry entry)77     public int add(Entry entry) {
78         int i;
79         int N = mEntries.size();
80         for (i=0; i<N; i++) {
81             if (mEntryCmp.compare(mEntries.get(i), entry) > 0) {
82                 break;
83             }
84         }
85         mEntries.add(i, entry);
86         return i;
87     }
88 
add(IBinder key, StatusBarNotification notification, View row, View content, View expanded, StatusBarIconView icon)89     public int add(IBinder key, StatusBarNotification notification, View row, View content,
90             View expanded, StatusBarIconView icon) {
91         Entry entry = new Entry();
92         entry.key = key;
93         entry.notification = notification;
94         entry.row = row;
95         entry.content = content;
96         entry.expanded = expanded;
97         entry.icon = icon;
98         entry.largeIcon = null; // TODO add support for large icons
99         return add(entry);
100     }
101 
remove(IBinder key)102     public Entry remove(IBinder key) {
103         Entry e = findByKey(key);
104         if (e != null) {
105             mEntries.remove(e);
106         }
107         return e;
108     }
109 
110     /**
111      * Return whether there are any visible items (i.e. items without an error).
112      */
hasVisibleItems()113     public boolean hasVisibleItems() {
114         for (Entry e : mEntries) {
115             if (e.expanded != null) { // the view successfully inflated
116                 return true;
117             }
118         }
119         return false;
120     }
121 
122     /**
123      * Return whether there are any clearable items (that aren't errors).
124      */
hasClearableItems()125     public boolean hasClearableItems() {
126         for (Entry e : mEntries) {
127             if (e.expanded != null) { // the view successfully inflated
128                 if (e.notification.isClearable()) {
129                     return true;
130                 }
131             }
132         }
133         return false;
134     }
135 }
136