2 * Copyright (C) 2008 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.android.systemui.statusbar;
19 import android.app.Notification;
20 import android.os.IBinder;
21 import android.view.View;
22 import android.widget.ImageView;
24 import com.android.internal.statusbar.StatusBarNotification;
25 import com.android.systemui.R;
27 import java.util.Comparator;
28 import java.util.ArrayList;
31 * The list of currently displaying notifications.
33 public class NotificationData {
34 public static final class Entry {
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;
44 public Entry(IBinder key, StatusBarNotification n, StatusBarIconView ic) {
46 this.notification = n;
49 public void setLargeView(View expandedLarge) {
50 this.expandedLarge = expandedLarge;
51 writeBooleanTag(row, R.id.expandable_tag, expandedLarge != null);
53 public View getLargeView() {
57 * Return whether the entry can be expanded.
59 public boolean expandable() {
60 return NotificationData.getIsExpandable(row);
63 * Return whether the entry has been manually expanded by the user.
65 public boolean userExpanded() {
66 return NotificationData.getUserExpanded(row);
69 * Set the flag indicating that this was manually expanded by the user.
71 public boolean setUserExpanded(boolean userExpanded) {
72 return NotificationData.setUserExpanded(row, userExpanded);
75 * Return whether the entry is being touched by the user.
77 public boolean userLocked() {
78 return NotificationData.getUserLocked(row);
81 * Set the flag indicating that this is being touched by the user.
83 public boolean setUserLocked(boolean userLocked) {
84 return NotificationData.setUserLocked(row, userLocked);
87 private final ArrayList<Entry> mEntries = new ArrayList<Entry>();
88 private final Comparator<Entry> mEntryCmp = new Comparator<Entry>() {
89 // sort first by score, then by when
90 public int compare(Entry a, Entry b) {
91 final StatusBarNotification na = a.notification;
92 final StatusBarNotification nb = b.notification;
93 int d = na.score - nb.score;
96 : (int)(na.notification.when - nb.notification.when);
101 return mEntries.size();
104 public Entry get(int i) {
105 return mEntries.get(i);
108 public Entry findByKey(IBinder key) {
109 for (Entry e : mEntries) {
117 public int add(Entry entry) {
119 int N = mEntries.size();
120 for (i=0; i<N; i++) {
121 if (mEntryCmp.compare(mEntries.get(i), entry) > 0) {
125 mEntries.add(i, entry);
129 public int add(IBinder key, StatusBarNotification notification, View row, View content,
130 View expanded, StatusBarIconView icon) {
131 Entry entry = new Entry();
133 entry.notification = notification;
135 entry.content = content;
136 entry.expanded = expanded;
138 entry.largeIcon = null; // TODO add support for large icons
142 public Entry remove(IBinder key) {
143 Entry e = findByKey(key);
151 * Return whether there are any visible items (i.e. items without an error).
153 public boolean hasVisibleItems() {
154 for (Entry e : mEntries) {
155 if (e.expanded != null) { // the view successfully inflated
163 * Return whether there are any clearable items (that aren't errors).
165 public boolean hasClearableItems() {
166 for (Entry e : mEntries) {
167 if (e.expanded != null) { // the view successfully inflated
168 if (e.notification.isClearable()) {
176 protected static boolean readBooleanTag(View view, int id) {
178 Object value = view.getTag(id);
179 return value != null && value instanceof Boolean && ((Boolean) value).booleanValue();
184 protected static boolean writeBooleanTag(View view, int id, boolean value) {
186 view.setTag(id, Boolean.valueOf(value));
193 * Return whether the entry can be expanded.
195 public static boolean getIsExpandable(View row) {
196 return readBooleanTag(row, R.id.expandable_tag);
200 * Return whether the entry has been manually expanded by the user.
202 public static boolean getUserExpanded(View row) {
203 return readBooleanTag(row, R.id.user_expanded_tag);
207 * Set whether the entry has been manually expanded by the user.
209 public static boolean setUserExpanded(View row, boolean userExpanded) {
210 return writeBooleanTag(row, R.id.user_expanded_tag, userExpanded);
214 * Return whether the entry is being touched by the user.
216 public static boolean getUserLocked(View row) {
217 return readBooleanTag(row, R.id.user_lock_tag);
221 * Set whether the entry is being touched by the user.
223 public static boolean setUserLocked(View row, boolean userLocked) {
224 return writeBooleanTag(row, R.id.user_lock_tag, userLocked);