Home | History | Annotate | Download | only in statusbar
      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.systemui.statusbar;
     18 
     19 import android.app.Notification;
     20 import android.os.IBinder;
     21 import android.view.View;
     22 
     23 import com.android.internal.statusbar.StatusBarNotification;
     24 
     25 import java.util.ArrayList;
     26 
     27 /**
     28  * The list of currently displaying notifications.
     29  */
     30 public class NotificationData {
     31     public static final class Entry {
     32         public IBinder key;
     33         public StatusBarNotification notification;
     34         public StatusBarIconView icon;
     35         public View row; // the outer expanded view
     36         public View content; // takes the click events and sends the PendingIntent
     37         public View expanded; // the inflated RemoteViews
     38     }
     39     private final ArrayList<Entry> mEntries = new ArrayList<Entry>();
     40 
     41     public int size() {
     42         return mEntries.size();
     43     }
     44 
     45     public Entry getEntryAt(int index) {
     46         return mEntries.get(index);
     47     }
     48 
     49     public int findEntry(IBinder key) {
     50         final int N = mEntries.size();
     51         for (int i=0; i<N; i++) {
     52             Entry entry = mEntries.get(i);
     53             if (entry.key == key) {
     54                 return i;
     55             }
     56         }
     57         return -1;
     58     }
     59 
     60     public int add(IBinder key, StatusBarNotification notification, View row, View content,
     61             View expanded, StatusBarIconView icon) {
     62         Entry entry = new Entry();
     63         entry.key = key;
     64         entry.notification = notification;
     65         entry.row = row;
     66         entry.content = content;
     67         entry.expanded = expanded;
     68         entry.icon = icon;
     69         final int index = chooseIndex(notification.notification.when);
     70         mEntries.add(index, entry);
     71         return index;
     72     }
     73 
     74     public Entry remove(IBinder key) {
     75         final int N = mEntries.size();
     76         for (int i=0; i<N; i++) {
     77             Entry entry = mEntries.get(i);
     78             if (entry.key == key) {
     79                 mEntries.remove(i);
     80                 return entry;
     81             }
     82         }
     83         return null;
     84     }
     85 
     86     private int chooseIndex(final long when) {
     87         final int N = mEntries.size();
     88         for (int i=0; i<N; i++) {
     89             Entry entry = mEntries.get(i);
     90             if (entry.notification.notification.when > when) {
     91                 return i;
     92             }
     93         }
     94         return N;
     95     }
     96 
     97     /**
     98      * Return whether there are any visible items (i.e. items without an error).
     99      */
    100     public boolean hasVisibleItems() {
    101         final int N = mEntries.size();
    102         for (int i=0; i<N; i++) {
    103             Entry entry = mEntries.get(i);
    104             if (entry.expanded != null) { // the view successfully inflated
    105                 return true;
    106             }
    107         }
    108         return false;
    109     }
    110 
    111     /**
    112      * Return whether there are any clearable items (that aren't errors).
    113      */
    114     public boolean hasClearableItems() {
    115         final int N = mEntries.size();
    116         for (int i=0; i<N; i++) {
    117             Entry entry = mEntries.get(i);
    118             if (entry.expanded != null) { // the view successfully inflated
    119                 if ((entry.notification.notification.flags & Notification.FLAG_NO_CLEAR) == 0) {
    120                     return true;
    121                 }
    122             }
    123         }
    124         return false;
    125     }
    126 }
    127