blob: 2c7a2a89907a6e6ff5b2c416f7be62417b62b113 [file] [log] [blame]
Joe Onorato503007d2010-04-16 09:20:55 -07001/*
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
Joe Onorato79de0c52010-05-26 17:03:26 -040017package com.android.systemui.statusbar;
Joe Onorato503007d2010-04-16 09:20:55 -070018
Daniel Sandler5feceeb2013-03-22 18:29:23 -070019import android.service.notification.StatusBarNotification;
Joe Onoratoe345fff2010-05-23 15:18:27 -040020import android.os.IBinder;
21import android.view.View;
Joe Onorato80a44402011-01-15 16:22:24 -080022import android.widget.ImageView;
Joe Onorato503007d2010-04-16 09:20:55 -070023
Chris Wren8fd12652012-05-09 21:25:57 -040024import com.android.systemui.R;
Joe Onoratoe345fff2010-05-23 15:18:27 -040025
Daniel Sandler379020a2010-07-29 16:20:06 -040026import java.util.Comparator;
Joe Onoratoe345fff2010-05-23 15:18:27 -040027import java.util.ArrayList;
28
29/**
30 * The list of currently displaying notifications.
31 */
Joe Onorato503007d2010-04-16 09:20:55 -070032public class NotificationData {
Joe Onoratoe345fff2010-05-23 15:18:27 -040033 public static final class Entry {
34 public IBinder key;
35 public StatusBarNotification notification;
Joe Onorato66b4c5b2010-05-23 15:39:40 -040036 public StatusBarIconView icon;
Joe Onorato9c1d8232010-05-24 20:02:53 -040037 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
Joe Onorato80a44402011-01-15 16:22:24 -080040 public ImageView largeIcon;
Chris Wren8fd12652012-05-09 21:25:57 -040041 protected View expandedLarge;
Daniel Sandler3eebd1f2010-07-27 08:39:33 -040042 public Entry() {}
43 public Entry(IBinder key, StatusBarNotification n, StatusBarIconView ic) {
44 this.key = key;
45 this.notification = n;
46 this.icon = ic;
47 }
Chris Wren8fd12652012-05-09 21:25:57 -040048 public void setLargeView(View expandedLarge) {
49 this.expandedLarge = expandedLarge;
50 writeBooleanTag(row, R.id.expandable_tag, expandedLarge != null);
51 }
52 public View getLargeView() {
53 return expandedLarge;
54 }
55 /**
56 * Return whether the entry can be expanded.
57 */
58 public boolean expandable() {
59 return NotificationData.getIsExpandable(row);
60 }
61 /**
62 * Return whether the entry has been manually expanded by the user.
63 */
64 public boolean userExpanded() {
65 return NotificationData.getUserExpanded(row);
66 }
Chris Wren5ae1ea82012-06-28 14:35:43 -040067 /**
68 * Set the flag indicating that this was manually expanded by the user.
69 */
70 public boolean setUserExpanded(boolean userExpanded) {
71 return NotificationData.setUserExpanded(row, userExpanded);
72 }
Chris Wren3ddab0d2012-08-02 16:52:21 -040073 /**
74 * Return whether the entry is being touched by the user.
75 */
76 public boolean userLocked() {
77 return NotificationData.getUserLocked(row);
78 }
79 /**
80 * Set the flag indicating that this is being touched by the user.
81 */
82 public boolean setUserLocked(boolean userLocked) {
83 return NotificationData.setUserLocked(row, userLocked);
84 }
Joe Onoratoe345fff2010-05-23 15:18:27 -040085 }
86 private final ArrayList<Entry> mEntries = new ArrayList<Entry>();
Daniel Sandler379020a2010-07-29 16:20:06 -040087 private final Comparator<Entry> mEntryCmp = new Comparator<Entry>() {
Daniel Sandler2561b0b2012-02-13 21:04:12 -050088 // sort first by score, then by when
Daniel Sandler379020a2010-07-29 16:20:06 -040089 public int compare(Entry a, Entry b) {
Daniel Sandlera31e4192011-02-02 22:00:28 -050090 final StatusBarNotification na = a.notification;
91 final StatusBarNotification nb = b.notification;
Daniel Sandlere6f7f2e2013-04-25 15:44:16 -040092 int d = na.getScore() - nb.getScore();
Daniel Sandler2561b0b2012-02-13 21:04:12 -050093 return (d != 0)
94 ? d
Daniel Sandlere6f7f2e2013-04-25 15:44:16 -040095 : (int)(na.getNotification().when - nb.getNotification().when);
Daniel Sandler379020a2010-07-29 16:20:06 -040096 }
97 };
Joe Onorato503007d2010-04-16 09:20:55 -070098
Joe Onoratoe345fff2010-05-23 15:18:27 -040099 public int size() {
100 return mEntries.size();
101 }
Joe Onorato503007d2010-04-16 09:20:55 -0700102
Daniel Sandler0f0b11c2010-08-04 15:54:58 -0400103 public Entry get(int i) {
104 return mEntries.get(i);
105 }
106
Daniel Sandler379020a2010-07-29 16:20:06 -0400107 public Entry findByKey(IBinder key) {
108 for (Entry e : mEntries) {
109 if (e.key == key) {
110 return e;
Joe Onorato0e26dff2010-05-24 16:17:02 -0400111 }
112 }
Daniel Sandler379020a2010-07-29 16:20:06 -0400113 return null;
Joe Onorato0e26dff2010-05-24 16:17:02 -0400114 }
115
Daniel Sandler3eebd1f2010-07-27 08:39:33 -0400116 public int add(Entry entry) {
Daniel Sandler379020a2010-07-29 16:20:06 -0400117 int i;
118 int N = mEntries.size();
119 for (i=0; i<N; i++) {
120 if (mEntryCmp.compare(mEntries.get(i), entry) > 0) {
121 break;
122 }
123 }
124 mEntries.add(i, entry);
125 return i;
Daniel Sandler3eebd1f2010-07-27 08:39:33 -0400126 }
127
Joe Onorato9c1d8232010-05-24 20:02:53 -0400128 public int add(IBinder key, StatusBarNotification notification, View row, View content,
129 View expanded, StatusBarIconView icon) {
Joe Onoratoe345fff2010-05-23 15:18:27 -0400130 Entry entry = new Entry();
131 entry.key = key;
132 entry.notification = notification;
Joe Onorato9c1d8232010-05-24 20:02:53 -0400133 entry.row = row;
134 entry.content = content;
Joe Onoratoe345fff2010-05-23 15:18:27 -0400135 entry.expanded = expanded;
Joe Onorato66b4c5b2010-05-23 15:39:40 -0400136 entry.icon = icon;
Joe Onorato80a44402011-01-15 16:22:24 -0800137 entry.largeIcon = null; // TODO add support for large icons
Daniel Sandler3eebd1f2010-07-27 08:39:33 -0400138 return add(entry);
Joe Onoratoe345fff2010-05-23 15:18:27 -0400139 }
Joe Onorato503007d2010-04-16 09:20:55 -0700140
Joe Onorato66b4c5b2010-05-23 15:39:40 -0400141 public Entry remove(IBinder key) {
Daniel Sandler379020a2010-07-29 16:20:06 -0400142 Entry e = findByKey(key);
143 if (e != null) {
144 mEntries.remove(e);
Joe Onorato66b4c5b2010-05-23 15:39:40 -0400145 }
Daniel Sandler379020a2010-07-29 16:20:06 -0400146 return e;
Joe Onorato503007d2010-04-16 09:20:55 -0700147 }
Joe Onorato20da8f82010-05-24 16:39:29 -0400148
149 /**
150 * Return whether there are any visible items (i.e. items without an error).
151 */
152 public boolean hasVisibleItems() {
Daniel Sandler379020a2010-07-29 16:20:06 -0400153 for (Entry e : mEntries) {
154 if (e.expanded != null) { // the view successfully inflated
Joe Onorato9c1d8232010-05-24 20:02:53 -0400155 return true;
156 }
157 }
158 return false;
Joe Onorato20da8f82010-05-24 16:39:29 -0400159 }
160
161 /**
162 * Return whether there are any clearable items (that aren't errors).
163 */
164 public boolean hasClearableItems() {
Daniel Sandler379020a2010-07-29 16:20:06 -0400165 for (Entry e : mEntries) {
166 if (e.expanded != null) { // the view successfully inflated
Joe Onorato5dd11692010-09-27 15:34:04 -0700167 if (e.notification.isClearable()) {
Joe Onorato9c1d8232010-05-24 20:02:53 -0400168 return true;
169 }
Joe Onorato20da8f82010-05-24 16:39:29 -0400170 }
171 }
172 return false;
173 }
Chris Wren8fd12652012-05-09 21:25:57 -0400174
175 protected static boolean readBooleanTag(View view, int id) {
176 if (view != null) {
177 Object value = view.getTag(id);
178 return value != null && value instanceof Boolean && ((Boolean) value).booleanValue();
179 }
180 return false;
181 }
182
183 protected static boolean writeBooleanTag(View view, int id, boolean value) {
184 if (view != null) {
185 view.setTag(id, Boolean.valueOf(value));
186 return value;
187 }
188 return false;
189 }
190
191 /**
192 * Return whether the entry can be expanded.
193 */
194 public static boolean getIsExpandable(View row) {
195 return readBooleanTag(row, R.id.expandable_tag);
196 }
197
198 /**
199 * Return whether the entry has been manually expanded by the user.
200 */
201 public static boolean getUserExpanded(View row) {
202 return readBooleanTag(row, R.id.user_expanded_tag);
203 }
204
205 /**
206 * Set whether the entry has been manually expanded by the user.
207 */
208 public static boolean setUserExpanded(View row, boolean userExpanded) {
209 return writeBooleanTag(row, R.id.user_expanded_tag, userExpanded);
210 }
Chris Wren3ddab0d2012-08-02 16:52:21 -0400211
212 /**
213 * Return whether the entry is being touched by the user.
214 */
215 public static boolean getUserLocked(View row) {
216 return readBooleanTag(row, R.id.user_lock_tag);
217 }
218
219 /**
220 * Set whether the entry is being touched by the user.
221 */
222 public static boolean setUserLocked(View row, boolean userLocked) {
223 return writeBooleanTag(row, R.id.user_lock_tag, userLocked);
224 }
Joe Onorato503007d2010-04-16 09:20:55 -0700225}