NotificationData.java revision e345fff2f80947b0a821f6674c197a02b7bff08e
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
17package com.android.policy.statusbar.phone;
18
19import android.os.IBinder;
20import android.view.View;
21
22import com.android.internal.statusbar.StatusBarNotification;
23
24import java.util.ArrayList;
25
26/**
27 * The list of currently displaying notifications.
28 */
29public class NotificationData {
30    public static final class Entry {
31        public IBinder key;
32        public StatusBarNotification notification;
33        public StatusBarIconView icon;
34        public View expanded;
35    }
36    private final ArrayList<Entry> mEntries = new ArrayList<Entry>();
37
38    public int size() {
39        return mEntries.size();
40    }
41
42    public Entry getEntryAt(int index) {
43        return mEntries.get(index);
44    }
45
46    public int add(IBinder key, StatusBarNotification notification, View expanded) {
47        Entry entry = new Entry();
48        entry.key = key;
49        entry.notification = notification;
50        entry.expanded = expanded;
51        final int index = chooseIndex(notification.notification.when);
52        mEntries.add(index, entry);
53        return index;
54    }
55
56    private int chooseIndex(final long when) {
57        final int N = mEntries.size();
58        for (int i=0; i<N; i++) {
59            Entry entry = mEntries.get(i);
60            if (entry.notification.notification.when > when) {
61                return i;
62            }
63        }
64        return N;
65    }
66}
67