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