blob: 5499cc4f65bdd53332413a86708e0cee73fe369c [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
17package com.android.policy.statusbar.phone;
18
Joe Onorato20da8f82010-05-24 16:39:29 -040019import android.app.Notification;
Joe Onoratoe345fff2010-05-23 15:18:27 -040020import android.os.IBinder;
21import android.view.View;
Joe Onorato503007d2010-04-16 09:20:55 -070022
Joe Onoratoe345fff2010-05-23 15:18:27 -040023import com.android.internal.statusbar.StatusBarNotification;
24
25import java.util.ArrayList;
26
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;
Joe Onorato0e26dff2010-05-24 16:17:02 -040035 public View expanded; // the outer expanded view
36 public View contents; // the inflated RemoteViews
Joe Onoratoe345fff2010-05-23 15:18:27 -040037 }
38 private final ArrayList<Entry> mEntries = new ArrayList<Entry>();
Joe Onorato503007d2010-04-16 09:20:55 -070039
Joe Onoratoe345fff2010-05-23 15:18:27 -040040 public int size() {
41 return mEntries.size();
42 }
Joe Onorato503007d2010-04-16 09:20:55 -070043
Joe Onoratoe345fff2010-05-23 15:18:27 -040044 public Entry getEntryAt(int index) {
45 return mEntries.get(index);
46 }
Joe Onorato503007d2010-04-16 09:20:55 -070047
Joe Onorato0e26dff2010-05-24 16:17:02 -040048 public int findEntry(IBinder key) {
49 final int N = mEntries.size();
50 for (int i=0; i<N; i++) {
51 Entry entry = mEntries.get(i);
52 if (entry.key == key) {
53 return i;
54 }
55 }
56 return -1;
57 }
58
Joe Onorato66b4c5b2010-05-23 15:39:40 -040059 public int add(IBinder key, StatusBarNotification notification, View expanded,
60 StatusBarIconView icon) {
Joe Onoratoe345fff2010-05-23 15:18:27 -040061 Entry entry = new Entry();
62 entry.key = key;
63 entry.notification = notification;
64 entry.expanded = expanded;
Joe Onorato66b4c5b2010-05-23 15:39:40 -040065 entry.icon = icon;
Joe Onoratoe345fff2010-05-23 15:18:27 -040066 final int index = chooseIndex(notification.notification.when);
67 mEntries.add(index, entry);
68 return index;
69 }
Joe Onorato503007d2010-04-16 09:20:55 -070070
Joe Onorato66b4c5b2010-05-23 15:39:40 -040071 public Entry remove(IBinder key) {
72 final int N = mEntries.size();
73 for (int i=0; i<N; i++) {
74 Entry entry = mEntries.get(i);
75 if (entry.key == key) {
76 mEntries.remove(i);
77 return entry;
78 }
79 }
80 return null;
81 }
82
Joe Onoratoe345fff2010-05-23 15:18:27 -040083 private int chooseIndex(final long when) {
84 final int N = mEntries.size();
85 for (int i=0; i<N; i++) {
86 Entry entry = mEntries.get(i);
87 if (entry.notification.notification.when > when) {
88 return i;
89 }
90 }
91 return N;
Joe Onorato503007d2010-04-16 09:20:55 -070092 }
Joe Onorato20da8f82010-05-24 16:39:29 -040093
94 /**
95 * Return whether there are any visible items (i.e. items without an error).
96 */
97 public boolean hasVisibleItems() {
98 return mEntries.size() != 0; // TODO
99 }
100
101 /**
102 * Return whether there are any clearable items (that aren't errors).
103 */
104 public boolean hasClearableItems() {
105 final int N = mEntries.size();
106 for (int i=0; i<N; i++) {
107 Entry entry = mEntries.get(i);
108 // TODO: if (!entry.error)
109 if ((entry.notification.notification.flags & Notification.FLAG_NO_CLEAR) == 0) {
110 return true;
111 }
112 }
113 return false;
114 }
Joe Onorato503007d2010-04-16 09:20:55 -0700115}