blob: 4427466a45a413d831dfab573e2f47e681727489 [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
Joe Onoratoe345fff2010-05-23 15:18:27 -040019import android.os.IBinder;
John Spurlockde84f0e2013-06-12 12:41:00 -040020import android.service.notification.StatusBarNotification;
Joe Onoratoe345fff2010-05-23 15:18:27 -040021import android.view.View;
Joe Onorato80a44402011-01-15 16:22:24 -080022import android.widget.ImageView;
Joe Onorato503007d2010-04-16 09:20:55 -070023
Joe Onoratoe345fff2010-05-23 15:18:27 -040024import java.util.ArrayList;
John Spurlockde84f0e2013-06-12 12:41:00 -040025import java.util.Comparator;
Joe Onoratoe345fff2010-05-23 15:18:27 -040026
27/**
28 * The list of currently displaying notifications.
29 */
Joe Onorato503007d2010-04-16 09:20:55 -070030public class NotificationData {
Joe Onoratoe345fff2010-05-23 15:18:27 -040031 public static final class Entry {
32 public IBinder key;
33 public StatusBarNotification notification;
Joe Onorato66b4c5b2010-05-23 15:39:40 -040034 public StatusBarIconView icon;
Chris Wren51c75102013-07-16 20:49:17 -040035 public ExpandableNotificationRow row; // the outer expanded view
Joe Onorato9c1d8232010-05-24 20:02:53 -040036 public View content; // takes the click events and sends the PendingIntent
37 public View expanded; // the inflated RemoteViews
Dan Sandlera5e0f412014-01-23 15:11:54 -050038 public View expandedPublic; // for insecure lockscreens
Joe Onorato80a44402011-01-15 16:22:24 -080039 public ImageView largeIcon;
Chris Wren574a55e2013-07-15 18:48:37 -040040 private View expandedBig;
Chris Wrenf0048ce2013-08-07 16:43:43 -040041 private boolean interruption;
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 Wren574a55e2013-07-15 18:48:37 -040048 public void setBigContentView(View bigContentView) {
49 this.expandedBig = bigContentView;
Chris Wren51c75102013-07-16 20:49:17 -040050 row.setExpandable(bigContentView != null);
Chris Wren8fd12652012-05-09 21:25:57 -040051 }
Chris Wren574a55e2013-07-15 18:48:37 -040052 public View getBigContentView() {
53 return expandedBig;
Chris Wren8fd12652012-05-09 21:25:57 -040054 }
Dan Sandlera5e0f412014-01-23 15:11:54 -050055 public View getPublicContentView() { return expandedPublic; }
Chris Wren8fd12652012-05-09 21:25:57 -040056 /**
Chris Wren3ddab0d2012-08-02 16:52:21 -040057 * Set the flag indicating that this is being touched by the user.
58 */
Chris Wren51c75102013-07-16 20:49:17 -040059 public void setUserLocked(boolean userLocked) {
60 row.setUserLocked(userLocked);
Chris Wren3ddab0d2012-08-02 16:52:21 -040061 }
Chris Wrenf0048ce2013-08-07 16:43:43 -040062
63 public void setInterruption() {
64 interruption = true;
65 }
Joe Onoratoe345fff2010-05-23 15:18:27 -040066 }
67 private final ArrayList<Entry> mEntries = new ArrayList<Entry>();
Daniel Sandler379020a2010-07-29 16:20:06 -040068 private final Comparator<Entry> mEntryCmp = new Comparator<Entry>() {
Daniel Sandler2561b0b2012-02-13 21:04:12 -050069 // sort first by score, then by when
Daniel Sandler379020a2010-07-29 16:20:06 -040070 public int compare(Entry a, Entry b) {
Daniel Sandlera31e4192011-02-02 22:00:28 -050071 final StatusBarNotification na = a.notification;
72 final StatusBarNotification nb = b.notification;
Daniel Sandlere6f7f2e2013-04-25 15:44:16 -040073 int d = na.getScore() - nb.getScore();
Chris Wrenf0048ce2013-08-07 16:43:43 -040074 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 Sandler379020a2010-07-29 16:20:06 -040081 }
82 };
Joe Onorato503007d2010-04-16 09:20:55 -070083
Joe Onoratoe345fff2010-05-23 15:18:27 -040084 public int size() {
85 return mEntries.size();
86 }
Joe Onorato503007d2010-04-16 09:20:55 -070087
Daniel Sandler0f0b11c2010-08-04 15:54:58 -040088 public Entry get(int i) {
89 return mEntries.get(i);
90 }
91
Daniel Sandler379020a2010-07-29 16:20:06 -040092 public Entry findByKey(IBinder key) {
93 for (Entry e : mEntries) {
94 if (e.key == key) {
95 return e;
Joe Onorato0e26dff2010-05-24 16:17:02 -040096 }
97 }
Daniel Sandler379020a2010-07-29 16:20:06 -040098 return null;
Joe Onorato0e26dff2010-05-24 16:17:02 -040099 }
100
Daniel Sandler3eebd1f2010-07-27 08:39:33 -0400101 public int add(Entry entry) {
Daniel Sandler379020a2010-07-29 16:20:06 -0400102 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 Sandler3eebd1f2010-07-27 08:39:33 -0400111 }
112
Joe Onorato66b4c5b2010-05-23 15:39:40 -0400113 public Entry remove(IBinder key) {
Daniel Sandler379020a2010-07-29 16:20:06 -0400114 Entry e = findByKey(key);
115 if (e != null) {
116 mEntries.remove(e);
Joe Onorato66b4c5b2010-05-23 15:39:40 -0400117 }
Daniel Sandler379020a2010-07-29 16:20:06 -0400118 return e;
Joe Onorato503007d2010-04-16 09:20:55 -0700119 }
Joe Onorato20da8f82010-05-24 16:39:29 -0400120
121 /**
122 * Return whether there are any visible items (i.e. items without an error).
123 */
124 public boolean hasVisibleItems() {
Daniel Sandler379020a2010-07-29 16:20:06 -0400125 for (Entry e : mEntries) {
126 if (e.expanded != null) { // the view successfully inflated
Joe Onorato9c1d8232010-05-24 20:02:53 -0400127 return true;
128 }
129 }
130 return false;
Joe Onorato20da8f82010-05-24 16:39:29 -0400131 }
132
133 /**
134 * Return whether there are any clearable items (that aren't errors).
135 */
136 public boolean hasClearableItems() {
Daniel Sandler379020a2010-07-29 16:20:06 -0400137 for (Entry e : mEntries) {
138 if (e.expanded != null) { // the view successfully inflated
Joe Onorato5dd11692010-09-27 15:34:04 -0700139 if (e.notification.isClearable()) {
Joe Onorato9c1d8232010-05-24 20:02:53 -0400140 return true;
141 }
Joe Onorato20da8f82010-05-24 16:39:29 -0400142 }
143 }
144 return false;
145 }
Joe Onorato503007d2010-04-16 09:20:55 -0700146}