1503007dd023668b1e45de948d3673e594d7f5a82Joe Onorato/* 2503007dd023668b1e45de948d3673e594d7f5a82Joe Onorato * Copyright (C) 2008 The Android Open Source Project 3503007dd023668b1e45de948d3673e594d7f5a82Joe Onorato * 4503007dd023668b1e45de948d3673e594d7f5a82Joe Onorato * Licensed under the Apache License, Version 2.0 (the "License"); 5503007dd023668b1e45de948d3673e594d7f5a82Joe Onorato * you may not use this file except in compliance with the License. 6503007dd023668b1e45de948d3673e594d7f5a82Joe Onorato * You may obtain a copy of the License at 7503007dd023668b1e45de948d3673e594d7f5a82Joe Onorato * 8503007dd023668b1e45de948d3673e594d7f5a82Joe Onorato * http://www.apache.org/licenses/LICENSE-2.0 9503007dd023668b1e45de948d3673e594d7f5a82Joe Onorato * 10503007dd023668b1e45de948d3673e594d7f5a82Joe Onorato * Unless required by applicable law or agreed to in writing, software 11503007dd023668b1e45de948d3673e594d7f5a82Joe Onorato * distributed under the License is distributed on an "AS IS" BASIS, 12503007dd023668b1e45de948d3673e594d7f5a82Joe Onorato * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13503007dd023668b1e45de948d3673e594d7f5a82Joe Onorato * See the License for the specific language governing permissions and 14503007dd023668b1e45de948d3673e594d7f5a82Joe Onorato * limitations under the License. 15503007dd023668b1e45de948d3673e594d7f5a82Joe Onorato */ 16503007dd023668b1e45de948d3673e594d7f5a82Joe Onorato 1779de0c550037a5328bbc7f4fddaf02f192a5c283Joe Onoratopackage com.android.systemui.statusbar; 18503007dd023668b1e45de948d3673e594d7f5a82Joe Onorato 19e345fff2f80947b0a821f6674c197a02b7bff08eJoe Onoratoimport android.os.IBinder; 20de84f0e77ea2bf713d15c290264059a413c2486aJohn Spurlockimport android.service.notification.StatusBarNotification; 21e345fff2f80947b0a821f6674c197a02b7bff08eJoe Onoratoimport android.view.View; 2280a44401a22344f7eabce6976372ab144ef22893Joe Onoratoimport android.widget.ImageView; 23503007dd023668b1e45de948d3673e594d7f5a82Joe Onorato 248fd12657e353a4a6f6d875a0d86850426fec00e8Chris Wrenimport com.android.systemui.R; 25e345fff2f80947b0a821f6674c197a02b7bff08eJoe Onorato 26e345fff2f80947b0a821f6674c197a02b7bff08eJoe Onoratoimport java.util.ArrayList; 27de84f0e77ea2bf713d15c290264059a413c2486aJohn Spurlockimport java.util.Comparator; 28e345fff2f80947b0a821f6674c197a02b7bff08eJoe Onorato 29e345fff2f80947b0a821f6674c197a02b7bff08eJoe Onorato/** 30e345fff2f80947b0a821f6674c197a02b7bff08eJoe Onorato * The list of currently displaying notifications. 31e345fff2f80947b0a821f6674c197a02b7bff08eJoe Onorato */ 32503007dd023668b1e45de948d3673e594d7f5a82Joe Onoratopublic class NotificationData { 33e345fff2f80947b0a821f6674c197a02b7bff08eJoe Onorato public static final class Entry { 34e345fff2f80947b0a821f6674c197a02b7bff08eJoe Onorato public IBinder key; 35e345fff2f80947b0a821f6674c197a02b7bff08eJoe Onorato public StatusBarNotification notification; 3666b4c5bb36f57a9d83bb7f34288235b82f9be407Joe Onorato public StatusBarIconView icon; 3751c7510e493680b4aca1ed7695b35c52d2cd63ffChris Wren public ExpandableNotificationRow row; // the outer expanded view 389c1d823465fa0bd782b2ea4afc518835b4bfecceJoe Onorato public View content; // takes the click events and sends the PendingIntent 399c1d823465fa0bd782b2ea4afc518835b4bfecceJoe Onorato public View expanded; // the inflated RemoteViews 4080a44401a22344f7eabce6976372ab144ef22893Joe Onorato public ImageView largeIcon; 41574a55e9eec37f49a80b75b28a401a18f1433fe7Chris Wren private View expandedBig; 42f0048ce66fa7b4859b44badc8e58ea8b27e2356bChris Wren private boolean interruption; 433eebd1ffbf4583270e6926e9c74ff088a2113e07Daniel Sandler public Entry() {} 443eebd1ffbf4583270e6926e9c74ff088a2113e07Daniel Sandler public Entry(IBinder key, StatusBarNotification n, StatusBarIconView ic) { 453eebd1ffbf4583270e6926e9c74ff088a2113e07Daniel Sandler this.key = key; 463eebd1ffbf4583270e6926e9c74ff088a2113e07Daniel Sandler this.notification = n; 473eebd1ffbf4583270e6926e9c74ff088a2113e07Daniel Sandler this.icon = ic; 483eebd1ffbf4583270e6926e9c74ff088a2113e07Daniel Sandler } 49574a55e9eec37f49a80b75b28a401a18f1433fe7Chris Wren public void setBigContentView(View bigContentView) { 50574a55e9eec37f49a80b75b28a401a18f1433fe7Chris Wren this.expandedBig = bigContentView; 5151c7510e493680b4aca1ed7695b35c52d2cd63ffChris Wren row.setExpandable(bigContentView != null); 528fd12657e353a4a6f6d875a0d86850426fec00e8Chris Wren } 53574a55e9eec37f49a80b75b28a401a18f1433fe7Chris Wren public View getBigContentView() { 54574a55e9eec37f49a80b75b28a401a18f1433fe7Chris Wren return expandedBig; 558fd12657e353a4a6f6d875a0d86850426fec00e8Chris Wren } 568fd12657e353a4a6f6d875a0d86850426fec00e8Chris Wren /** 573ddab0dcc1039137f05a28ff86477601a223a0faChris Wren * Set the flag indicating that this is being touched by the user. 583ddab0dcc1039137f05a28ff86477601a223a0faChris Wren */ 5951c7510e493680b4aca1ed7695b35c52d2cd63ffChris Wren public void setUserLocked(boolean userLocked) { 6051c7510e493680b4aca1ed7695b35c52d2cd63ffChris Wren row.setUserLocked(userLocked); 613ddab0dcc1039137f05a28ff86477601a223a0faChris Wren } 62f0048ce66fa7b4859b44badc8e58ea8b27e2356bChris Wren 63f0048ce66fa7b4859b44badc8e58ea8b27e2356bChris Wren public void setInterruption() { 64f0048ce66fa7b4859b44badc8e58ea8b27e2356bChris Wren interruption = true; 65f0048ce66fa7b4859b44badc8e58ea8b27e2356bChris Wren } 66e345fff2f80947b0a821f6674c197a02b7bff08eJoe Onorato } 67e345fff2f80947b0a821f6674c197a02b7bff08eJoe Onorato private final ArrayList<Entry> mEntries = new ArrayList<Entry>(); 68379020aec619c66d3e040de01f0726687fd2ad85Daniel Sandler private final Comparator<Entry> mEntryCmp = new Comparator<Entry>() { 692561b0b10a55841a08e0e1d467e73e10b1bf256dDaniel Sandler // sort first by score, then by when 70379020aec619c66d3e040de01f0726687fd2ad85Daniel Sandler public int compare(Entry a, Entry b) { 71a31e4190cb44eaa51bb8dee7d715fcd72d6c0b03Daniel Sandler final StatusBarNotification na = a.notification; 72a31e4190cb44eaa51bb8dee7d715fcd72d6c0b03Daniel Sandler final StatusBarNotification nb = b.notification; 73e6f7f2e3a01b8deb00e03ccfa93751c315f14ef0Daniel Sandler int d = na.getScore() - nb.getScore(); 74f0048ce66fa7b4859b44badc8e58ea8b27e2356bChris Wren if (a.interruption != b.interruption) { 75f0048ce66fa7b4859b44badc8e58ea8b27e2356bChris Wren return a.interruption ? 1 : -1; 76f0048ce66fa7b4859b44badc8e58ea8b27e2356bChris Wren } else if (d != 0) { 77f0048ce66fa7b4859b44badc8e58ea8b27e2356bChris Wren return d; 78f0048ce66fa7b4859b44badc8e58ea8b27e2356bChris Wren } else { 79f0048ce66fa7b4859b44badc8e58ea8b27e2356bChris Wren return (int) (na.getNotification().when - nb.getNotification().when); 80f0048ce66fa7b4859b44badc8e58ea8b27e2356bChris Wren } 81379020aec619c66d3e040de01f0726687fd2ad85Daniel Sandler } 82379020aec619c66d3e040de01f0726687fd2ad85Daniel Sandler }; 83e345fff2f80947b0a821f6674c197a02b7bff08eJoe Onorato 84e345fff2f80947b0a821f6674c197a02b7bff08eJoe Onorato public int size() { 85e345fff2f80947b0a821f6674c197a02b7bff08eJoe Onorato return mEntries.size(); 86e345fff2f80947b0a821f6674c197a02b7bff08eJoe Onorato } 87e345fff2f80947b0a821f6674c197a02b7bff08eJoe Onorato 880f0b11c8719495ce559b93366fe9cd79782d791cDaniel Sandler public Entry get(int i) { 890f0b11c8719495ce559b93366fe9cd79782d791cDaniel Sandler return mEntries.get(i); 900f0b11c8719495ce559b93366fe9cd79782d791cDaniel Sandler } 910f0b11c8719495ce559b93366fe9cd79782d791cDaniel Sandler 92379020aec619c66d3e040de01f0726687fd2ad85Daniel Sandler public Entry findByKey(IBinder key) { 93379020aec619c66d3e040de01f0726687fd2ad85Daniel Sandler for (Entry e : mEntries) { 94379020aec619c66d3e040de01f0726687fd2ad85Daniel Sandler if (e.key == key) { 95379020aec619c66d3e040de01f0726687fd2ad85Daniel Sandler return e; 960e26dffd6cfcb09b08a94a857b891fdef7fe2b1eJoe Onorato } 970e26dffd6cfcb09b08a94a857b891fdef7fe2b1eJoe Onorato } 98379020aec619c66d3e040de01f0726687fd2ad85Daniel Sandler return null; 990e26dffd6cfcb09b08a94a857b891fdef7fe2b1eJoe Onorato } 1000e26dffd6cfcb09b08a94a857b891fdef7fe2b1eJoe Onorato 1013eebd1ffbf4583270e6926e9c74ff088a2113e07Daniel Sandler public int add(Entry entry) { 102379020aec619c66d3e040de01f0726687fd2ad85Daniel Sandler int i; 103379020aec619c66d3e040de01f0726687fd2ad85Daniel Sandler int N = mEntries.size(); 104379020aec619c66d3e040de01f0726687fd2ad85Daniel Sandler for (i=0; i<N; i++) { 105379020aec619c66d3e040de01f0726687fd2ad85Daniel Sandler if (mEntryCmp.compare(mEntries.get(i), entry) > 0) { 106379020aec619c66d3e040de01f0726687fd2ad85Daniel Sandler break; 107379020aec619c66d3e040de01f0726687fd2ad85Daniel Sandler } 108379020aec619c66d3e040de01f0726687fd2ad85Daniel Sandler } 109379020aec619c66d3e040de01f0726687fd2ad85Daniel Sandler mEntries.add(i, entry); 110379020aec619c66d3e040de01f0726687fd2ad85Daniel Sandler return i; 1113eebd1ffbf4583270e6926e9c74ff088a2113e07Daniel Sandler } 1123eebd1ffbf4583270e6926e9c74ff088a2113e07Daniel Sandler 11351c7510e493680b4aca1ed7695b35c52d2cd63ffChris Wren public int add(IBinder key, StatusBarNotification notification, ExpandableNotificationRow row, 11451c7510e493680b4aca1ed7695b35c52d2cd63ffChris Wren View content, View expanded, StatusBarIconView icon) { 115e345fff2f80947b0a821f6674c197a02b7bff08eJoe Onorato Entry entry = new Entry(); 116e345fff2f80947b0a821f6674c197a02b7bff08eJoe Onorato entry.key = key; 117e345fff2f80947b0a821f6674c197a02b7bff08eJoe Onorato entry.notification = notification; 1189c1d823465fa0bd782b2ea4afc518835b4bfecceJoe Onorato entry.row = row; 1199c1d823465fa0bd782b2ea4afc518835b4bfecceJoe Onorato entry.content = content; 120e345fff2f80947b0a821f6674c197a02b7bff08eJoe Onorato entry.expanded = expanded; 12166b4c5bb36f57a9d83bb7f34288235b82f9be407Joe Onorato entry.icon = icon; 12280a44401a22344f7eabce6976372ab144ef22893Joe Onorato entry.largeIcon = null; // TODO add support for large icons 1233eebd1ffbf4583270e6926e9c74ff088a2113e07Daniel Sandler return add(entry); 124e345fff2f80947b0a821f6674c197a02b7bff08eJoe Onorato } 125e345fff2f80947b0a821f6674c197a02b7bff08eJoe Onorato 12666b4c5bb36f57a9d83bb7f34288235b82f9be407Joe Onorato public Entry remove(IBinder key) { 127379020aec619c66d3e040de01f0726687fd2ad85Daniel Sandler Entry e = findByKey(key); 128379020aec619c66d3e040de01f0726687fd2ad85Daniel Sandler if (e != null) { 129379020aec619c66d3e040de01f0726687fd2ad85Daniel Sandler mEntries.remove(e); 130e345fff2f80947b0a821f6674c197a02b7bff08eJoe Onorato } 131379020aec619c66d3e040de01f0726687fd2ad85Daniel Sandler return e; 132503007dd023668b1e45de948d3673e594d7f5a82Joe Onorato } 13320da8f8ac9cfc8b845231c6b93f5b64a764ab39aJoe Onorato 13420da8f8ac9cfc8b845231c6b93f5b64a764ab39aJoe Onorato /** 13520da8f8ac9cfc8b845231c6b93f5b64a764ab39aJoe Onorato * Return whether there are any visible items (i.e. items without an error). 13620da8f8ac9cfc8b845231c6b93f5b64a764ab39aJoe Onorato */ 13720da8f8ac9cfc8b845231c6b93f5b64a764ab39aJoe Onorato public boolean hasVisibleItems() { 138379020aec619c66d3e040de01f0726687fd2ad85Daniel Sandler for (Entry e : mEntries) { 139379020aec619c66d3e040de01f0726687fd2ad85Daniel Sandler if (e.expanded != null) { // the view successfully inflated 1409c1d823465fa0bd782b2ea4afc518835b4bfecceJoe Onorato return true; 1419c1d823465fa0bd782b2ea4afc518835b4bfecceJoe Onorato } 1429c1d823465fa0bd782b2ea4afc518835b4bfecceJoe Onorato } 1439c1d823465fa0bd782b2ea4afc518835b4bfecceJoe Onorato return false; 14420da8f8ac9cfc8b845231c6b93f5b64a764ab39aJoe Onorato } 14520da8f8ac9cfc8b845231c6b93f5b64a764ab39aJoe Onorato 14620da8f8ac9cfc8b845231c6b93f5b64a764ab39aJoe Onorato /** 14720da8f8ac9cfc8b845231c6b93f5b64a764ab39aJoe Onorato * Return whether there are any clearable items (that aren't errors). 14820da8f8ac9cfc8b845231c6b93f5b64a764ab39aJoe Onorato */ 14920da8f8ac9cfc8b845231c6b93f5b64a764ab39aJoe Onorato public boolean hasClearableItems() { 150379020aec619c66d3e040de01f0726687fd2ad85Daniel Sandler for (Entry e : mEntries) { 151379020aec619c66d3e040de01f0726687fd2ad85Daniel Sandler if (e.expanded != null) { // the view successfully inflated 1525dd1169ae95162383acf00d1e9a1886e0ac99a70Joe Onorato if (e.notification.isClearable()) { 1539c1d823465fa0bd782b2ea4afc518835b4bfecceJoe Onorato return true; 1549c1d823465fa0bd782b2ea4afc518835b4bfecceJoe Onorato } 15520da8f8ac9cfc8b845231c6b93f5b64a764ab39aJoe Onorato } 15620da8f8ac9cfc8b845231c6b93f5b64a764ab39aJoe Onorato } 15720da8f8ac9cfc8b845231c6b93f5b64a764ab39aJoe Onorato return false; 15820da8f8ac9cfc8b845231c6b93f5b64a764ab39aJoe Onorato } 159503007dd023668b1e45de948d3673e594d7f5a82Joe Onorato} 160