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 | |
Joe Onorato | e345fff | 2010-05-23 15:18:27 -0400 | [diff] [blame] | 24 | import java.util.ArrayList; |
John Spurlock | de84f0e | 2013-06-12 12:41:00 -0400 | [diff] [blame] | 25 | import java.util.Comparator; |
Joe Onorato | e345fff | 2010-05-23 15:18:27 -0400 | [diff] [blame] | 26 | |
| 27 | /** |
| 28 | * The list of currently displaying notifications. |
| 29 | */ |
Joe Onorato | 503007d | 2010-04-16 09:20:55 -0700 | [diff] [blame] | 30 | public class NotificationData { |
Joe Onorato | e345fff | 2010-05-23 15:18:27 -0400 | [diff] [blame] | 31 | public static final class Entry { |
| 32 | public IBinder key; |
| 33 | public StatusBarNotification notification; |
Joe Onorato | 66b4c5b | 2010-05-23 15:39:40 -0400 | [diff] [blame] | 34 | public StatusBarIconView icon; |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 35 | public ExpandableNotificationRow row; // the outer expanded view |
Joe Onorato | 9c1d823 | 2010-05-24 20:02:53 -0400 | [diff] [blame] | 36 | public View content; // takes the click events and sends the PendingIntent |
| 37 | public View expanded; // the inflated RemoteViews |
Dan Sandler | a5e0f41 | 2014-01-23 15:11:54 -0500 | [diff] [blame] | 38 | public View expandedPublic; // for insecure lockscreens |
Joe Onorato | 80a4440 | 2011-01-15 16:22:24 -0800 | [diff] [blame] | 39 | public ImageView largeIcon; |
Chris Wren | 574a55e | 2013-07-15 18:48:37 -0400 | [diff] [blame] | 40 | private View expandedBig; |
Chris Wren | f0048ce | 2013-08-07 16:43:43 -0400 | [diff] [blame] | 41 | private boolean interruption; |
Daniel Sandler | 3eebd1f | 2010-07-27 08:39:33 -0400 | [diff] [blame] | 42 | 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 Wren | 574a55e | 2013-07-15 18:48:37 -0400 | [diff] [blame] | 48 | public void setBigContentView(View bigContentView) { |
| 49 | this.expandedBig = bigContentView; |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 50 | row.setExpandable(bigContentView != null); |
Chris Wren | 8fd1265 | 2012-05-09 21:25:57 -0400 | [diff] [blame] | 51 | } |
Chris Wren | 574a55e | 2013-07-15 18:48:37 -0400 | [diff] [blame] | 52 | public View getBigContentView() { |
| 53 | return expandedBig; |
Chris Wren | 8fd1265 | 2012-05-09 21:25:57 -0400 | [diff] [blame] | 54 | } |
Dan Sandler | a5e0f41 | 2014-01-23 15:11:54 -0500 | [diff] [blame] | 55 | public View getPublicContentView() { return expandedPublic; } |
Chris Wren | 8fd1265 | 2012-05-09 21:25:57 -0400 | [diff] [blame] | 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 | |
Joe Onorato | 66b4c5b | 2010-05-23 15:39:40 -0400 | [diff] [blame] | 113 | public Entry remove(IBinder key) { |
Daniel Sandler | 379020a | 2010-07-29 16:20:06 -0400 | [diff] [blame] | 114 | Entry e = findByKey(key); |
| 115 | if (e != null) { |
| 116 | mEntries.remove(e); |
Joe Onorato | 66b4c5b | 2010-05-23 15:39:40 -0400 | [diff] [blame] | 117 | } |
Daniel Sandler | 379020a | 2010-07-29 16:20:06 -0400 | [diff] [blame] | 118 | return e; |
Joe Onorato | 503007d | 2010-04-16 09:20:55 -0700 | [diff] [blame] | 119 | } |
Joe Onorato | 20da8f8 | 2010-05-24 16:39:29 -0400 | [diff] [blame] | 120 | |
| 121 | /** |
| 122 | * Return whether there are any visible items (i.e. items without an error). |
| 123 | */ |
| 124 | public boolean hasVisibleItems() { |
Daniel Sandler | 379020a | 2010-07-29 16:20:06 -0400 | [diff] [blame] | 125 | for (Entry e : mEntries) { |
| 126 | if (e.expanded != null) { // the view successfully inflated |
Joe Onorato | 9c1d823 | 2010-05-24 20:02:53 -0400 | [diff] [blame] | 127 | return true; |
| 128 | } |
| 129 | } |
| 130 | return false; |
Joe Onorato | 20da8f8 | 2010-05-24 16:39:29 -0400 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | /** |
| 134 | * Return whether there are any clearable items (that aren't errors). |
| 135 | */ |
| 136 | public boolean hasClearableItems() { |
Daniel Sandler | 379020a | 2010-07-29 16:20:06 -0400 | [diff] [blame] | 137 | for (Entry e : mEntries) { |
| 138 | if (e.expanded != null) { // the view successfully inflated |
Joe Onorato | 5dd1169 | 2010-09-27 15:34:04 -0700 | [diff] [blame] | 139 | if (e.notification.isClearable()) { |
Joe Onorato | 9c1d823 | 2010-05-24 20:02:53 -0400 | [diff] [blame] | 140 | return true; |
| 141 | } |
Joe Onorato | 20da8f8 | 2010-05-24 16:39:29 -0400 | [diff] [blame] | 142 | } |
| 143 | } |
| 144 | return false; |
| 145 | } |
Joe Onorato | 503007d | 2010-04-16 09:20:55 -0700 | [diff] [blame] | 146 | } |