Joe Onorato | 503007d | 2010-04-16 09:20:55 -0700 | [diff] [blame] | 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 | |
Joe Onorato | 79de0c5 | 2010-05-26 17:03:26 -0400 | [diff] [blame] | 17 | package com.android.systemui.statusbar; |
Joe Onorato | 503007d | 2010-04-16 09:20:55 -0700 | [diff] [blame] | 18 | |
Joe Onorato | e345fff | 2010-05-23 15:18:27 -0400 | [diff] [blame] | 19 | import android.os.IBinder; |
John Spurlock | de84f0e | 2013-06-12 12:41:00 -0400 | [diff] [blame] | 20 | import android.service.notification.StatusBarNotification; |
Joe Onorato | e345fff | 2010-05-23 15:18:27 -0400 | [diff] [blame] | 21 | import android.view.View; |
Joe Onorato | 80a4440 | 2011-01-15 16:22:24 -0800 | [diff] [blame] | 22 | import android.widget.ImageView; |
Joe Onorato | 503007d | 2010-04-16 09:20:55 -0700 | [diff] [blame] | 23 | |
Chris Wren | 8fd1265 | 2012-05-09 21:25:57 -0400 | [diff] [blame] | 24 | import com.android.systemui.R; |
Joe Onorato | e345fff | 2010-05-23 15:18:27 -0400 | [diff] [blame] | 25 | |
| 26 | import java.util.ArrayList; |
John Spurlock | de84f0e | 2013-06-12 12:41:00 -0400 | [diff] [blame] | 27 | import java.util.Comparator; |
Joe Onorato | e345fff | 2010-05-23 15:18:27 -0400 | [diff] [blame] | 28 | |
| 29 | /** |
| 30 | * The list of currently displaying notifications. |
| 31 | */ |
Joe Onorato | 503007d | 2010-04-16 09:20:55 -0700 | [diff] [blame] | 32 | public class NotificationData { |
Joe Onorato | e345fff | 2010-05-23 15:18:27 -0400 | [diff] [blame] | 33 | public static final class Entry { |
| 34 | public IBinder key; |
| 35 | public StatusBarNotification notification; |
Joe Onorato | 66b4c5b | 2010-05-23 15:39:40 -0400 | [diff] [blame] | 36 | public StatusBarIconView icon; |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 37 | public ExpandableNotificationRow row; // the outer expanded view |
Joe Onorato | 9c1d823 | 2010-05-24 20:02:53 -0400 | [diff] [blame] | 38 | public View content; // takes the click events and sends the PendingIntent |
| 39 | public View expanded; // the inflated RemoteViews |
Joe Onorato | 80a4440 | 2011-01-15 16:22:24 -0800 | [diff] [blame] | 40 | public ImageView largeIcon; |
Chris Wren | 574a55e | 2013-07-15 18:48:37 -0400 | [diff] [blame] | 41 | private View expandedBig; |
Chris Wren | f0048ce | 2013-08-07 16:43:43 -0400 | [diff] [blame] | 42 | private boolean interruption; |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 43 | public Entry() {} |
| 44 | public Entry(IBinder key, StatusBarNotification n, StatusBarIconView ic) { |
| 45 | this.key = key; |
| 46 | this.notification = n; |
| 47 | this.icon = ic; |
| 48 | } |
Chris Wren | 574a55e | 2013-07-15 18:48:37 -0400 | [diff] [blame] | 49 | public void setBigContentView(View bigContentView) { |
| 50 | this.expandedBig = bigContentView; |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 51 | row.setExpandable(bigContentView != null); |
Chris Wren | 8fd1265 | 2012-05-09 21:25:57 -0400 | [diff] [blame] | 52 | } |
Chris Wren | 574a55e | 2013-07-15 18:48:37 -0400 | [diff] [blame] | 53 | public View getBigContentView() { |
| 54 | return expandedBig; |
Chris Wren | 8fd1265 | 2012-05-09 21:25:57 -0400 | [diff] [blame] | 55 | } |
| 56 | /** |
Chris Wren | 3ddab0d | 2012-08-02 16:52:21 -0400 | [diff] [blame] | 57 | * Set the flag indicating that this is being touched by the user. |
| 58 | */ |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 59 | public void setUserLocked(boolean userLocked) { |
| 60 | row.setUserLocked(userLocked); |
Chris Wren | 3ddab0d | 2012-08-02 16:52:21 -0400 | [diff] [blame] | 61 | } |
Chris Wren | f0048ce | 2013-08-07 16:43:43 -0400 | [diff] [blame] | 62 | |
| 63 | public void setInterruption() { |
| 64 | interruption = true; |
| 65 | } |
Joe Onorato | e345fff | 2010-05-23 15:18:27 -0400 | [diff] [blame] | 66 | } |
| 67 | private final ArrayList<Entry> mEntries = new ArrayList<Entry>(); |
Daniel Sandler | 379020a | 2010-07-29 16:20:06 -0400 | [diff] [blame] | 68 | private final Comparator<Entry> mEntryCmp = new Comparator<Entry>() { |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 69 | // sort first by score, then by when |
Daniel Sandler | 379020a | 2010-07-29 16:20:06 -0400 | [diff] [blame] | 70 | public int compare(Entry a, Entry b) { |
Daniel Sandler | a31e419 | 2011-02-02 22:00:28 -0500 | [diff] [blame] | 71 | final StatusBarNotification na = a.notification; |
| 72 | final StatusBarNotification nb = b.notification; |
Daniel Sandler | e6f7f2e | 2013-04-25 15:44:16 -0400 | [diff] [blame] | 73 | int d = na.getScore() - nb.getScore(); |
Chris Wren | f0048ce | 2013-08-07 16:43:43 -0400 | [diff] [blame] | 74 | if (a.interruption != b.interruption) { |
| 75 | return a.interruption ? 1 : -1; |
| 76 | } else if (d != 0) { |
| 77 | return d; |
| 78 | } else { |
| 79 | return (int) (na.getNotification().when - nb.getNotification().when); |
| 80 | } |
Daniel Sandler | 379020a | 2010-07-29 16:20:06 -0400 | [diff] [blame] | 81 | } |
| 82 | }; |
Joe Onorato | 503007d | 2010-04-16 09:20:55 -0700 | [diff] [blame] | 83 | |
Joe Onorato | e345fff | 2010-05-23 15:18:27 -0400 | [diff] [blame] | 84 | public int size() { |
| 85 | return mEntries.size(); |
| 86 | } |
Joe Onorato | 503007d | 2010-04-16 09:20:55 -0700 | [diff] [blame] | 87 | |
Daniel Sandler | 0f0b11c | 2010-08-04 15:54:58 -0400 | [diff] [blame] | 88 | public Entry get(int i) { |
| 89 | return mEntries.get(i); |
| 90 | } |
| 91 | |
Daniel Sandler | 379020a | 2010-07-29 16:20:06 -0400 | [diff] [blame] | 92 | public Entry findByKey(IBinder key) { |
| 93 | for (Entry e : mEntries) { |
| 94 | if (e.key == key) { |
| 95 | return e; |
Joe Onorato | 0e26dff | 2010-05-24 16:17:02 -0400 | [diff] [blame] | 96 | } |
| 97 | } |
Daniel Sandler | 379020a | 2010-07-29 16:20:06 -0400 | [diff] [blame] | 98 | return null; |
Joe Onorato | 0e26dff | 2010-05-24 16:17:02 -0400 | [diff] [blame] | 99 | } |
| 100 | |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 101 | public int add(Entry entry) { |
Daniel Sandler | 379020a | 2010-07-29 16:20:06 -0400 | [diff] [blame] | 102 | int i; |
| 103 | int N = mEntries.size(); |
| 104 | for (i=0; i<N; i++) { |
| 105 | if (mEntryCmp.compare(mEntries.get(i), entry) > 0) { |
| 106 | break; |
| 107 | } |
| 108 | } |
| 109 | mEntries.add(i, entry); |
| 110 | return i; |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 111 | } |
| 112 | |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 113 | public int add(IBinder key, StatusBarNotification notification, ExpandableNotificationRow row, |
| 114 | View content, View expanded, StatusBarIconView icon) { |
Joe Onorato | e345fff | 2010-05-23 15:18:27 -0400 | [diff] [blame] | 115 | Entry entry = new Entry(); |
| 116 | entry.key = key; |
| 117 | entry.notification = notification; |
Joe Onorato | 9c1d823 | 2010-05-24 20:02:53 -0400 | [diff] [blame] | 118 | entry.row = row; |
| 119 | entry.content = content; |
Joe Onorato | e345fff | 2010-05-23 15:18:27 -0400 | [diff] [blame] | 120 | entry.expanded = expanded; |
Joe Onorato | 66b4c5b | 2010-05-23 15:39:40 -0400 | [diff] [blame] | 121 | entry.icon = icon; |
Joe Onorato | 80a4440 | 2011-01-15 16:22:24 -0800 | [diff] [blame] | 122 | entry.largeIcon = null; // TODO add support for large icons |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 123 | return add(entry); |
Joe Onorato | e345fff | 2010-05-23 15:18:27 -0400 | [diff] [blame] | 124 | } |
Joe Onorato | 503007d | 2010-04-16 09:20:55 -0700 | [diff] [blame] | 125 | |
Joe Onorato | 66b4c5b | 2010-05-23 15:39:40 -0400 | [diff] [blame] | 126 | public Entry remove(IBinder key) { |
Daniel Sandler | 379020a | 2010-07-29 16:20:06 -0400 | [diff] [blame] | 127 | Entry e = findByKey(key); |
| 128 | if (e != null) { |
| 129 | mEntries.remove(e); |
Joe Onorato | 66b4c5b | 2010-05-23 15:39:40 -0400 | [diff] [blame] | 130 | } |
Daniel Sandler | 379020a | 2010-07-29 16:20:06 -0400 | [diff] [blame] | 131 | return e; |
Joe Onorato | 503007d | 2010-04-16 09:20:55 -0700 | [diff] [blame] | 132 | } |
Joe Onorato | 20da8f8 | 2010-05-24 16:39:29 -0400 | [diff] [blame] | 133 | |
| 134 | /** |
| 135 | * Return whether there are any visible items (i.e. items without an error). |
| 136 | */ |
| 137 | public boolean hasVisibleItems() { |
Daniel Sandler | 379020a | 2010-07-29 16:20:06 -0400 | [diff] [blame] | 138 | for (Entry e : mEntries) { |
| 139 | if (e.expanded != null) { // the view successfully inflated |
Joe Onorato | 9c1d823 | 2010-05-24 20:02:53 -0400 | [diff] [blame] | 140 | return true; |
| 141 | } |
| 142 | } |
| 143 | return false; |
Joe Onorato | 20da8f8 | 2010-05-24 16:39:29 -0400 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | /** |
| 147 | * Return whether there are any clearable items (that aren't errors). |
| 148 | */ |
| 149 | public boolean hasClearableItems() { |
Daniel Sandler | 379020a | 2010-07-29 16:20:06 -0400 | [diff] [blame] | 150 | for (Entry e : mEntries) { |
| 151 | if (e.expanded != null) { // the view successfully inflated |
Joe Onorato | 5dd1169 | 2010-09-27 15:34:04 -0700 | [diff] [blame] | 152 | if (e.notification.isClearable()) { |
Joe Onorato | 9c1d823 | 2010-05-24 20:02:53 -0400 | [diff] [blame] | 153 | return true; |
| 154 | } |
Joe Onorato | 20da8f8 | 2010-05-24 16:39:29 -0400 | [diff] [blame] | 155 | } |
| 156 | } |
| 157 | return false; |
| 158 | } |
Joe Onorato | 503007d | 2010-04-16 09:20:55 -0700 | [diff] [blame] | 159 | } |