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