blob: 569624678953624857d092c24e3363cd7c8d07df [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
John Spurlockde84f0e2013-06-12 12:41:00 -040019import android.service.notification.StatusBarNotification;
Joe Onoratoe345fff2010-05-23 15:18:27 -040020import android.view.View;
Joe Onorato80a44402011-01-15 16:22:24 -080021import android.widget.ImageView;
Joe Onorato503007d2010-04-16 09:20:55 -070022
Joe Onoratoe345fff2010-05-23 15:18:27 -040023import java.util.ArrayList;
John Spurlockde84f0e2013-06-12 12:41:00 -040024import java.util.Comparator;
Joe Onoratoe345fff2010-05-23 15:18:27 -040025
26/**
27 * The list of currently displaying notifications.
28 */
Joe Onorato503007d2010-04-16 09:20:55 -070029public class NotificationData {
Joe Onoratoe345fff2010-05-23 15:18:27 -040030 public static final class Entry {
Christoph Studer71f18fd2014-05-20 17:02:04 +020031 public String key;
Joe Onoratoe345fff2010-05-23 15:18:27 -040032 public StatusBarNotification notification;
Joe Onorato66b4c5b2010-05-23 15:39:40 -040033 public StatusBarIconView icon;
Chris Wren51c75102013-07-16 20:49:17 -040034 public ExpandableNotificationRow row; // the outer expanded view
Joe Onorato9c1d8232010-05-24 20:02:53 -040035 public View expanded; // the inflated RemoteViews
Dan Sandlera5e0f412014-01-23 15:11:54 -050036 public View expandedPublic; // for insecure lockscreens
Joe Onorato80a44402011-01-15 16:22:24 -080037 public ImageView largeIcon;
Dan Sandler842dd772014-05-15 09:36:47 -040038 public View expandedBig;
Chris Wrenf0048ce2013-08-07 16:43:43 -040039 private boolean interruption;
Daniel Sandler3eebd1f2010-07-27 08:39:33 -040040 public Entry() {}
Christoph Studer71f18fd2014-05-20 17:02:04 +020041 public Entry(StatusBarNotification n, StatusBarIconView ic) {
42 this.key = n.getKey();
Daniel Sandler3eebd1f2010-07-27 08:39:33 -040043 this.notification = n;
44 this.icon = ic;
45 }
Chris Wren574a55e2013-07-15 18:48:37 -040046 public void setBigContentView(View bigContentView) {
47 this.expandedBig = bigContentView;
Chris Wren51c75102013-07-16 20:49:17 -040048 row.setExpandable(bigContentView != null);
Chris Wren8fd12652012-05-09 21:25:57 -040049 }
Chris Wren574a55e2013-07-15 18:48:37 -040050 public View getBigContentView() {
51 return expandedBig;
Chris Wren8fd12652012-05-09 21:25:57 -040052 }
Dan Sandlera5e0f412014-01-23 15:11:54 -050053 public View getPublicContentView() { return expandedPublic; }
Chris Wren8fd12652012-05-09 21:25:57 -040054 /**
Chris Wren3ddab0d2012-08-02 16:52:21 -040055 * Set the flag indicating that this is being touched by the user.
56 */
Chris Wren51c75102013-07-16 20:49:17 -040057 public void setUserLocked(boolean userLocked) {
58 row.setUserLocked(userLocked);
Chris Wren3ddab0d2012-08-02 16:52:21 -040059 }
Chris Wrenf0048ce2013-08-07 16:43:43 -040060
61 public void setInterruption() {
62 interruption = true;
63 }
Joe Onoratoe345fff2010-05-23 15:18:27 -040064 }
Christoph Studer71f18fd2014-05-20 17:02:04 +020065
Joe Onoratoe345fff2010-05-23 15:18:27 -040066 private final ArrayList<Entry> mEntries = new ArrayList<Entry>();
Daniel Sandler379020a2010-07-29 16:20:06 -040067 private final Comparator<Entry> mEntryCmp = new Comparator<Entry>() {
Daniel Sandler2561b0b2012-02-13 21:04:12 -050068 // sort first by score, then by when
Daniel Sandler379020a2010-07-29 16:20:06 -040069 public int compare(Entry a, Entry b) {
Daniel Sandlera31e4192011-02-02 22:00:28 -050070 final StatusBarNotification na = a.notification;
71 final StatusBarNotification nb = b.notification;
Daniel Sandlere6f7f2e2013-04-25 15:44:16 -040072 int d = na.getScore() - nb.getScore();
John Spurlock362fafe2014-02-24 16:56:42 -050073 if (a.interruption != b.interruption) {
74 return a.interruption ? 1 : -1;
75 } else if (d != 0) {
Chris Wrenf0048ce2013-08-07 16:43:43 -040076 return d;
77 } else {
78 return (int) (na.getNotification().when - nb.getNotification().when);
79 }
Daniel Sandler379020a2010-07-29 16:20:06 -040080 }
81 };
Joe Onorato503007d2010-04-16 09:20:55 -070082
Joe Onoratoe345fff2010-05-23 15:18:27 -040083 public int size() {
84 return mEntries.size();
85 }
Joe Onorato503007d2010-04-16 09:20:55 -070086
Daniel Sandler0f0b11c2010-08-04 15:54:58 -040087 public Entry get(int i) {
88 return mEntries.get(i);
89 }
90
Christoph Studer71f18fd2014-05-20 17:02:04 +020091 public Entry findByKey(String key) {
Daniel Sandler379020a2010-07-29 16:20:06 -040092 for (Entry e : mEntries) {
Christoph Studer71f18fd2014-05-20 17:02:04 +020093 if (e.key.equals(key)) {
Daniel Sandler379020a2010-07-29 16:20:06 -040094 return e;
Joe Onorato0e26dff2010-05-24 16:17:02 -040095 }
96 }
Daniel Sandler379020a2010-07-29 16:20:06 -040097 return null;
Joe Onorato0e26dff2010-05-24 16:17:02 -040098 }
99
Daniel Sandler3eebd1f2010-07-27 08:39:33 -0400100 public int add(Entry entry) {
Daniel Sandler379020a2010-07-29 16:20:06 -0400101 int i;
102 int N = mEntries.size();
Christoph Studer71f18fd2014-05-20 17:02:04 +0200103 for (i = 0; i < N; i++) {
Daniel Sandler379020a2010-07-29 16:20:06 -0400104 if (mEntryCmp.compare(mEntries.get(i), entry) > 0) {
105 break;
106 }
107 }
108 mEntries.add(i, entry);
109 return i;
Daniel Sandler3eebd1f2010-07-27 08:39:33 -0400110 }
111
Christoph Studer71f18fd2014-05-20 17:02:04 +0200112 public Entry remove(String key) {
Daniel Sandler379020a2010-07-29 16:20:06 -0400113 Entry e = findByKey(key);
114 if (e != null) {
115 mEntries.remove(e);
Joe Onorato66b4c5b2010-05-23 15:39:40 -0400116 }
Daniel Sandler379020a2010-07-29 16:20:06 -0400117 return e;
Joe Onorato503007d2010-04-16 09:20:55 -0700118 }
Joe Onorato20da8f82010-05-24 16:39:29 -0400119
120 /**
121 * Return whether there are any visible items (i.e. items without an error).
122 */
123 public boolean hasVisibleItems() {
Daniel Sandler379020a2010-07-29 16:20:06 -0400124 for (Entry e : mEntries) {
125 if (e.expanded != null) { // the view successfully inflated
Joe Onorato9c1d8232010-05-24 20:02:53 -0400126 return true;
127 }
128 }
129 return false;
Joe Onorato20da8f82010-05-24 16:39:29 -0400130 }
131
132 /**
133 * Return whether there are any clearable items (that aren't errors).
134 */
135 public boolean hasClearableItems() {
Daniel Sandler379020a2010-07-29 16:20:06 -0400136 for (Entry e : mEntries) {
137 if (e.expanded != null) { // the view successfully inflated
Joe Onorato5dd11692010-09-27 15:34:04 -0700138 if (e.notification.isClearable()) {
Joe Onorato9c1d8232010-05-24 20:02:53 -0400139 return true;
140 }
Joe Onorato20da8f82010-05-24 16:39:29 -0400141 }
142 }
143 return false;
144 }
Joe Onorato503007d2010-04-16 09:20:55 -0700145}