NotificationData.java revision a5e0f415d351ad1a9c0ffde8d93df91a2384591f
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.systemui.statusbar; 18 19import android.os.IBinder; 20import android.service.notification.StatusBarNotification; 21import android.view.View; 22import android.widget.ImageView; 23 24import java.util.ArrayList; 25import java.util.Comparator; 26 27/** 28 * The list of currently displaying notifications. 29 */ 30public class NotificationData { 31 public static final class Entry { 32 public IBinder key; 33 public StatusBarNotification notification; 34 public StatusBarIconView icon; 35 public ExpandableNotificationRow 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 public View expandedPublic; // for insecure lockscreens 39 public ImageView largeIcon; 40 private View expandedBig; 41 private boolean interruption; 42 public Entry() {} 43 public Entry(IBinder key, StatusBarNotification n, StatusBarIconView ic) { 44 this.key = key; 45 this.notification = n; 46 this.icon = ic; 47 } 48 public void setBigContentView(View bigContentView) { 49 this.expandedBig = bigContentView; 50 row.setExpandable(bigContentView != null); 51 } 52 public View getBigContentView() { 53 return expandedBig; 54 } 55 public View getPublicContentView() { return expandedPublic; } 56 /** 57 * Set the flag indicating that this is being touched by the user. 58 */ 59 public void setUserLocked(boolean userLocked) { 60 row.setUserLocked(userLocked); 61 } 62 63 public void setInterruption() { 64 interruption = true; 65 } 66 } 67 private final ArrayList<Entry> mEntries = new ArrayList<Entry>(); 68 private final Comparator<Entry> mEntryCmp = new Comparator<Entry>() { 69 // sort first by score, then by when 70 public int compare(Entry a, Entry b) { 71 final StatusBarNotification na = a.notification; 72 final StatusBarNotification nb = b.notification; 73 int d = na.getScore() - nb.getScore(); 74 if (a.interruption != b.interruption) { 75 return a.interruption ? 1 : -1; 76 } else if (d != 0) { 77 return d; 78 } else { 79 return (int) (na.getNotification().when - nb.getNotification().when); 80 } 81 } 82 }; 83 84 public int size() { 85 return mEntries.size(); 86 } 87 88 public Entry get(int i) { 89 return mEntries.get(i); 90 } 91 92 public Entry findByKey(IBinder key) { 93 for (Entry e : mEntries) { 94 if (e.key == key) { 95 return e; 96 } 97 } 98 return null; 99 } 100 101 public int add(Entry entry) { 102 int i; 103 int N = mEntries.size(); 104 for (i=0; i<N; i++) { 105 if (mEntryCmp.compare(mEntries.get(i), entry) > 0) { 106 break; 107 } 108 } 109 mEntries.add(i, entry); 110 return i; 111 } 112 113 public Entry remove(IBinder key) { 114 Entry e = findByKey(key); 115 if (e != null) { 116 mEntries.remove(e); 117 } 118 return e; 119 } 120 121 /** 122 * Return whether there are any visible items (i.e. items without an error). 123 */ 124 public boolean hasVisibleItems() { 125 for (Entry e : mEntries) { 126 if (e.expanded != null) { // the view successfully inflated 127 return true; 128 } 129 } 130 return false; 131 } 132 133 /** 134 * Return whether there are any clearable items (that aren't errors). 135 */ 136 public boolean hasClearableItems() { 137 for (Entry e : mEntries) { 138 if (e.expanded != null) { // the view successfully inflated 139 if (e.notification.isClearable()) { 140 return true; 141 } 142 } 143 } 144 return false; 145 } 146} 147