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 | |
| 17 | package com.android.policy.statusbar.phone; |
| 18 | |
Joe Onorato | 20da8f8 | 2010-05-24 16:39:29 -0400 | [diff] [blame^] | 19 | import android.app.Notification; |
Joe Onorato | e345fff | 2010-05-23 15:18:27 -0400 | [diff] [blame] | 20 | import android.os.IBinder; |
| 21 | import android.view.View; |
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 com.android.internal.statusbar.StatusBarNotification; |
| 24 | |
| 25 | import java.util.ArrayList; |
| 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; |
Joe Onorato | 0e26dff | 2010-05-24 16:17:02 -0400 | [diff] [blame] | 35 | public View expanded; // the outer expanded view |
| 36 | public View contents; // the inflated RemoteViews |
Joe Onorato | e345fff | 2010-05-23 15:18:27 -0400 | [diff] [blame] | 37 | } |
| 38 | private final ArrayList<Entry> mEntries = new ArrayList<Entry>(); |
Joe Onorato | 503007d | 2010-04-16 09:20:55 -0700 | [diff] [blame] | 39 | |
Joe Onorato | e345fff | 2010-05-23 15:18:27 -0400 | [diff] [blame] | 40 | public int size() { |
| 41 | return mEntries.size(); |
| 42 | } |
Joe Onorato | 503007d | 2010-04-16 09:20:55 -0700 | [diff] [blame] | 43 | |
Joe Onorato | e345fff | 2010-05-23 15:18:27 -0400 | [diff] [blame] | 44 | public Entry getEntryAt(int index) { |
| 45 | return mEntries.get(index); |
| 46 | } |
Joe Onorato | 503007d | 2010-04-16 09:20:55 -0700 | [diff] [blame] | 47 | |
Joe Onorato | 0e26dff | 2010-05-24 16:17:02 -0400 | [diff] [blame] | 48 | 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 Onorato | 66b4c5b | 2010-05-23 15:39:40 -0400 | [diff] [blame] | 59 | public int add(IBinder key, StatusBarNotification notification, View expanded, |
| 60 | StatusBarIconView icon) { |
Joe Onorato | e345fff | 2010-05-23 15:18:27 -0400 | [diff] [blame] | 61 | Entry entry = new Entry(); |
| 62 | entry.key = key; |
| 63 | entry.notification = notification; |
| 64 | entry.expanded = expanded; |
Joe Onorato | 66b4c5b | 2010-05-23 15:39:40 -0400 | [diff] [blame] | 65 | entry.icon = icon; |
Joe Onorato | e345fff | 2010-05-23 15:18:27 -0400 | [diff] [blame] | 66 | final int index = chooseIndex(notification.notification.when); |
| 67 | mEntries.add(index, entry); |
| 68 | return index; |
| 69 | } |
Joe Onorato | 503007d | 2010-04-16 09:20:55 -0700 | [diff] [blame] | 70 | |
Joe Onorato | 66b4c5b | 2010-05-23 15:39:40 -0400 | [diff] [blame] | 71 | 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 Onorato | e345fff | 2010-05-23 15:18:27 -0400 | [diff] [blame] | 83 | 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 Onorato | 503007d | 2010-04-16 09:20:55 -0700 | [diff] [blame] | 92 | } |
Joe Onorato | 20da8f8 | 2010-05-24 16:39:29 -0400 | [diff] [blame^] | 93 | |
| 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 Onorato | 503007d | 2010-04-16 09:20:55 -0700 | [diff] [blame] | 115 | } |