1 package com.xtremelabs.robolectric.shadows; 2 3 import android.app.Notification; 4 import android.app.NotificationManager; 5 import com.xtremelabs.robolectric.internal.Implementation; 6 import com.xtremelabs.robolectric.internal.Implements; 7 8 import java.util.ArrayList; 9 import java.util.HashMap; 10 import java.util.List; 11 import java.util.Map; 12 13 @SuppressWarnings({"UnusedDeclaration"}) 14 @Implements(NotificationManager.class) 15 public class ShadowNotificationManager { 16 17 private Map<Integer, Notification> notifications = new HashMap<Integer, Notification>(); 18 private Map<String, Integer> idForTag = new HashMap<String, Integer>(); 19 20 @Implementation 21 public void notify(int id, Notification notification) 22 { 23 notify(null, id, notification); 24 } 25 26 @Implementation 27 public void notify(String tag, int id, Notification notification) { 28 if (tag != null) { 29 idForTag.put(tag, id); 30 } 31 notifications.put(id, notification); 32 } 33 34 @Implementation 35 public void cancel(int id) 36 { 37 cancel(null, id); 38 } 39 40 @Implementation 41 public void cancel(String tag, int id) { 42 // 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 43 Integer tagId = idForTag.remove(tag); 44 if (notifications.containsKey(id)) { 45 notifications.remove(id); 46 } else { 47 notifications.remove(tagId); 48 } 49 } 50 51 @Implementation 52 public void cancelAll() { 53 notifications.clear(); 54 idForTag.clear(); 55 } 56 57 public int size() { 58 return notifications.size(); 59 } 60 61 public Notification getNotification(int id) { 62 return notifications.get(id); 63 } 64 65 public Notification getNotification(String tag) { 66 Integer id = idForTag.get(tag); 67 return notifications.get(id); 68 } 69 70 public List<Notification> getAllNotifications() { 71 return new ArrayList<Notification>(notifications.values()); 72 } 73 } 74