107a3254138fdfe62b70c194b458879c51bea72b4Phil Goodwinpackage com.xtremelabs.robolectric.shadows; 207a3254138fdfe62b70c194b458879c51bea72b4Phil Goodwin 307a3254138fdfe62b70c194b458879c51bea72b4Phil Goodwinimport android.app.Notification; 407a3254138fdfe62b70c194b458879c51bea72b4Phil Goodwinimport android.app.NotificationManager; 507a3254138fdfe62b70c194b458879c51bea72b4Phil Goodwinimport com.xtremelabs.robolectric.internal.Implementation; 607a3254138fdfe62b70c194b458879c51bea72b4Phil Goodwinimport com.xtremelabs.robolectric.internal.Implements; 707a3254138fdfe62b70c194b458879c51bea72b4Phil Goodwin 81047b8740177c264e807a91bd6beeb09a502f6feDavid Farber & Lowell Kirshimport java.util.ArrayList; 907a3254138fdfe62b70c194b458879c51bea72b4Phil Goodwinimport java.util.HashMap; 101047b8740177c264e807a91bd6beeb09a502f6feDavid Farber & Lowell Kirshimport java.util.List; 1107a3254138fdfe62b70c194b458879c51bea72b4Phil Goodwinimport java.util.Map; 1207a3254138fdfe62b70c194b458879c51bea72b4Phil Goodwin 1307a3254138fdfe62b70c194b458879c51bea72b4Phil Goodwin@SuppressWarnings({"UnusedDeclaration"}) 1407a3254138fdfe62b70c194b458879c51bea72b4Phil Goodwin@Implements(NotificationManager.class) 1507a3254138fdfe62b70c194b458879c51bea72b4Phil Goodwinpublic class ShadowNotificationManager { 1607a3254138fdfe62b70c194b458879c51bea72b4Phil Goodwin 1707a3254138fdfe62b70c194b458879c51bea72b4Phil Goodwin private Map<Integer, Notification> notifications = new HashMap<Integer, Notification>(); 1807a3254138fdfe62b70c194b458879c51bea72b4Phil Goodwin private Map<String, Integer> idForTag = new HashMap<String, Integer>(); 1907a3254138fdfe62b70c194b458879c51bea72b4Phil Goodwin 2007a3254138fdfe62b70c194b458879c51bea72b4Phil Goodwin @Implementation 2107a3254138fdfe62b70c194b458879c51bea72b4Phil Goodwin public void notify(int id, Notification notification) 2207a3254138fdfe62b70c194b458879c51bea72b4Phil Goodwin { 2307a3254138fdfe62b70c194b458879c51bea72b4Phil Goodwin notify(null, id, notification); 2407a3254138fdfe62b70c194b458879c51bea72b4Phil Goodwin } 2507a3254138fdfe62b70c194b458879c51bea72b4Phil Goodwin 2607a3254138fdfe62b70c194b458879c51bea72b4Phil Goodwin @Implementation 2707a3254138fdfe62b70c194b458879c51bea72b4Phil Goodwin public void notify(String tag, int id, Notification notification) { 2807a3254138fdfe62b70c194b458879c51bea72b4Phil Goodwin if (tag != null) { 2907a3254138fdfe62b70c194b458879c51bea72b4Phil Goodwin idForTag.put(tag, id); 3007a3254138fdfe62b70c194b458879c51bea72b4Phil Goodwin } 3107a3254138fdfe62b70c194b458879c51bea72b4Phil Goodwin notifications.put(id, notification); 3207a3254138fdfe62b70c194b458879c51bea72b4Phil Goodwin } 3307a3254138fdfe62b70c194b458879c51bea72b4Phil Goodwin 3407a3254138fdfe62b70c194b458879c51bea72b4Phil Goodwin @Implementation 3507a3254138fdfe62b70c194b458879c51bea72b4Phil Goodwin public void cancel(int id) 3607a3254138fdfe62b70c194b458879c51bea72b4Phil Goodwin { 3707a3254138fdfe62b70c194b458879c51bea72b4Phil Goodwin cancel(null, id); 3807a3254138fdfe62b70c194b458879c51bea72b4Phil Goodwin } 3907a3254138fdfe62b70c194b458879c51bea72b4Phil Goodwin 4007a3254138fdfe62b70c194b458879c51bea72b4Phil Goodwin @Implementation 4107a3254138fdfe62b70c194b458879c51bea72b4Phil Goodwin public void cancel(String tag, int id) { 4207a3254138fdfe62b70c194b458879c51bea72b4Phil Goodwin // I can't make sense of this method signature. I'm guessing that the id is optional and if it's bogus you are supposed to use the tag instead, but that references to both should be gone. PG 4307a3254138fdfe62b70c194b458879c51bea72b4Phil Goodwin Integer tagId = idForTag.remove(tag); 4407a3254138fdfe62b70c194b458879c51bea72b4Phil Goodwin if (notifications.containsKey(id)) { 4507a3254138fdfe62b70c194b458879c51bea72b4Phil Goodwin notifications.remove(id); 4607a3254138fdfe62b70c194b458879c51bea72b4Phil Goodwin } else { 4707a3254138fdfe62b70c194b458879c51bea72b4Phil Goodwin notifications.remove(tagId); 4807a3254138fdfe62b70c194b458879c51bea72b4Phil Goodwin } 4907a3254138fdfe62b70c194b458879c51bea72b4Phil Goodwin } 5007a3254138fdfe62b70c194b458879c51bea72b4Phil Goodwin 5107a3254138fdfe62b70c194b458879c51bea72b4Phil Goodwin @Implementation 5207a3254138fdfe62b70c194b458879c51bea72b4Phil Goodwin public void cancelAll() { 5307a3254138fdfe62b70c194b458879c51bea72b4Phil Goodwin notifications.clear(); 5407a3254138fdfe62b70c194b458879c51bea72b4Phil Goodwin idForTag.clear(); 5507a3254138fdfe62b70c194b458879c51bea72b4Phil Goodwin } 5607a3254138fdfe62b70c194b458879c51bea72b4Phil Goodwin 5707a3254138fdfe62b70c194b458879c51bea72b4Phil Goodwin public int size() { 5807a3254138fdfe62b70c194b458879c51bea72b4Phil Goodwin return notifications.size(); 5907a3254138fdfe62b70c194b458879c51bea72b4Phil Goodwin } 6007a3254138fdfe62b70c194b458879c51bea72b4Phil Goodwin 6107a3254138fdfe62b70c194b458879c51bea72b4Phil Goodwin public Notification getNotification(int id) { 6207a3254138fdfe62b70c194b458879c51bea72b4Phil Goodwin return notifications.get(id); 6307a3254138fdfe62b70c194b458879c51bea72b4Phil Goodwin } 6407a3254138fdfe62b70c194b458879c51bea72b4Phil Goodwin 6507a3254138fdfe62b70c194b458879c51bea72b4Phil Goodwin public Notification getNotification(String tag) { 6607a3254138fdfe62b70c194b458879c51bea72b4Phil Goodwin Integer id = idForTag.get(tag); 6707a3254138fdfe62b70c194b458879c51bea72b4Phil Goodwin return notifications.get(id); 6807a3254138fdfe62b70c194b458879c51bea72b4Phil Goodwin } 691047b8740177c264e807a91bd6beeb09a502f6feDavid Farber & Lowell Kirsh 701047b8740177c264e807a91bd6beeb09a502f6feDavid Farber & Lowell Kirsh public List<Notification> getAllNotifications() { 711047b8740177c264e807a91bd6beeb09a502f6feDavid Farber & Lowell Kirsh return new ArrayList<Notification>(notifications.values()); 721047b8740177c264e807a91bd6beeb09a502f6feDavid Farber & Lowell Kirsh } 7307a3254138fdfe62b70c194b458879c51bea72b4Phil Goodwin} 74