• 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 import com.android.systemui.R;
26 
27 import java.util.Comparator;
28 import java.util.ArrayList;
29 
30 /**
31  * The list of currently displaying notifications.
32  */
33 public class NotificationData {
34     public static final class Entry {
35         public IBinder key;
36         public StatusBarNotification notification;
37         public StatusBarIconView icon;
38         public View row; // the outer expanded view
39         public View content; // takes the click events and sends the PendingIntent
40         public View expanded; // the inflated RemoteViews
41         public ImageView largeIcon;
42         protected View expandedLarge;
Entry()43         public Entry() {}
Entry(IBinder key, StatusBarNotification n, StatusBarIconView ic)44         public Entry(IBinder key, StatusBarNotification n, StatusBarIconView ic) {
45             this.key = key;
46             this.notification = n;
47             this.icon = ic;
48         }
setLargeView(View expandedLarge)49         public void setLargeView(View expandedLarge) {
50             this.expandedLarge = expandedLarge;
51             writeBooleanTag(row, R.id.expandable_tag, expandedLarge != null);
52         }
getLargeView()53         public View getLargeView() {
54             return expandedLarge;
55         }
56         /**
57          * Return whether the entry can be expanded.
58          */
expandable()59         public boolean expandable() {
60             return NotificationData.getIsExpandable(row);
61         }
62         /**
63          * Return whether the entry has been manually expanded by the user.
64          */
userExpanded()65         public boolean userExpanded() {
66             return NotificationData.getUserExpanded(row);
67         }
68         /**
69          * Set the flag indicating that this was manually expanded by the user.
70          */
setUserExpanded(boolean userExpanded)71         public boolean setUserExpanded(boolean userExpanded) {
72             return NotificationData.setUserExpanded(row, userExpanded);
73         }
74     }
75     private final ArrayList<Entry> mEntries = new ArrayList<Entry>();
76     private final Comparator<Entry> mEntryCmp = new Comparator<Entry>() {
77         // sort first by score, then by when
78         public int compare(Entry a, Entry b) {
79             final StatusBarNotification na = a.notification;
80             final StatusBarNotification nb = b.notification;
81             int d = na.score - nb.score;
82             return (d != 0)
83                 ? d
84                 : (int)(na.notification.when - nb.notification.when);
85         }
86     };
87 
size()88     public int size() {
89         return mEntries.size();
90     }
91 
get(int i)92     public Entry get(int i) {
93         return mEntries.get(i);
94     }
95 
findByKey(IBinder key)96     public Entry findByKey(IBinder key) {
97         for (Entry e : mEntries) {
98             if (e.key == key) {
99                 return e;
100             }
101         }
102         return null;
103     }
104 
add(Entry entry)105     public int add(Entry entry) {
106         int i;
107         int N = mEntries.size();
108         for (i=0; i<N; i++) {
109             if (mEntryCmp.compare(mEntries.get(i), entry) > 0) {
110                 break;
111             }
112         }
113         mEntries.add(i, entry);
114         return i;
115     }
116 
add(IBinder key, StatusBarNotification notification, View row, View content, View expanded, StatusBarIconView icon)117     public int add(IBinder key, StatusBarNotification notification, View row, View content,
118             View expanded, StatusBarIconView icon) {
119         Entry entry = new Entry();
120         entry.key = key;
121         entry.notification = notification;
122         entry.row = row;
123         entry.content = content;
124         entry.expanded = expanded;
125         entry.icon = icon;
126         entry.largeIcon = null; // TODO add support for large icons
127         return add(entry);
128     }
129 
remove(IBinder key)130     public Entry remove(IBinder key) {
131         Entry e = findByKey(key);
132         if (e != null) {
133             mEntries.remove(e);
134         }
135         return e;
136     }
137 
138     /**
139      * Return whether there are any visible items (i.e. items without an error).
140      */
hasVisibleItems()141     public boolean hasVisibleItems() {
142         for (Entry e : mEntries) {
143             if (e.expanded != null) { // the view successfully inflated
144                 return true;
145             }
146         }
147         return false;
148     }
149 
150     /**
151      * Return whether there are any clearable items (that aren't errors).
152      */
hasClearableItems()153     public boolean hasClearableItems() {
154         for (Entry e : mEntries) {
155             if (e.expanded != null) { // the view successfully inflated
156                 if (e.notification.isClearable()) {
157                     return true;
158                 }
159             }
160         }
161         return false;
162     }
163 
readBooleanTag(View view, int id)164     protected static boolean readBooleanTag(View view, int id)  {
165         if (view != null) {
166             Object value = view.getTag(id);
167             return value != null && value instanceof Boolean && ((Boolean) value).booleanValue();
168         }
169         return false;
170     }
171 
writeBooleanTag(View view, int id, boolean value)172     protected static boolean writeBooleanTag(View view, int id, boolean value)  {
173         if (view != null) {
174             view.setTag(id, Boolean.valueOf(value));
175             return value;
176         }
177         return false;
178     }
179 
180     /**
181      * Return whether the entry can be expanded.
182      */
getIsExpandable(View row)183     public static boolean getIsExpandable(View row) {
184         return readBooleanTag(row, R.id.expandable_tag);
185     }
186 
187     /**
188      * Return whether the entry has been manually expanded by the user.
189      */
getUserExpanded(View row)190     public static boolean getUserExpanded(View row) {
191         return readBooleanTag(row, R.id.user_expanded_tag);
192     }
193 
194     /**
195      * Set whether the entry has been manually expanded by the user.
196      */
setUserExpanded(View row, boolean userExpanded)197     public static boolean setUserExpanded(View row, boolean userExpanded) {
198         return writeBooleanTag(row, R.id.user_expanded_tag, userExpanded);
199     }
200 }
201