• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package com.xtremelabs.robolectric.shadows;
2 
3 import android.app.PendingIntent;
4 import android.telephony.SmsManager;
5 import android.text.TextUtils;
6 
7 import com.xtremelabs.robolectric.Robolectric;
8 import com.xtremelabs.robolectric.internal.Implementation;
9 import com.xtremelabs.robolectric.internal.Implements;
10 import com.xtremelabs.robolectric.internal.RealObject;
11 
12 @Implements(SmsManager.class)
13 public class ShadowSmsManager {
14 
15 	@RealObject
16 	private static SmsManager realManager = Robolectric.newInstanceOf(SmsManager.class);
17 
18 	private TextSmsParams lastTextSmsParams = null;
19 
20 	@Implementation
getDefault()21 	public static SmsManager getDefault() {
22 		return realManager;
23 	}
24 
25 	@Implementation
sendTextMessage( String destinationAddress, String scAddress, String text, PendingIntent sentIntent, PendingIntent deliveryIntent)26 	public void sendTextMessage(
27 			String destinationAddress, String scAddress, String text,
28             PendingIntent sentIntent, PendingIntent deliveryIntent) {
29 
30 		if (TextUtils.isEmpty(destinationAddress))
31             throw new IllegalArgumentException("Invalid destinationAddress");
32 
33         if (TextUtils.isEmpty(text))
34             throw new IllegalArgumentException("Invalid message body");
35 
36 		lastTextSmsParams = new TextSmsParams(
37 			destinationAddress,
38 			scAddress,
39 			text,
40 			sentIntent,
41 			deliveryIntent );
42 	}
43 
getLastSentTextMessageParams()44 	public TextSmsParams getLastSentTextMessageParams() {
45 		return lastTextSmsParams;
46 	}
47 
clearLastSentTextMessageParams()48     public void clearLastSentTextMessageParams() {
49         lastTextSmsParams = null;
50     }
51 
52 	public class TextSmsParams {
53 		private String destinationAddress;
54 		private String scAddress;
55 		private String text;
56 		private PendingIntent sentIntent;
57 		private PendingIntent deliveryIntent;
58 
TextSmsParams( String destinationAddress, String scAddress, String text, PendingIntent sentIntent, PendingIntent deliveryIntent)59 		public TextSmsParams(
60 			String destinationAddress, String scAddress, String text,
61             PendingIntent sentIntent, PendingIntent deliveryIntent) {
62 			this.destinationAddress = destinationAddress;
63 			this.scAddress = scAddress;
64 			this.text = text;
65 			this.sentIntent = sentIntent;
66 			this.deliveryIntent = deliveryIntent;
67 		}
68 
getDestinationAddress()69 		public String getDestinationAddress() {
70 			return destinationAddress;
71 		}
72 
getScAddress()73 		public String getScAddress() {
74 			return scAddress;
75 		}
76 
getText()77 		public String getText() {
78 			return text;
79 		}
80 
getSentIntent()81 		public PendingIntent getSentIntent() {
82 			return sentIntent;
83 		}
84 
getDeliveryIntent()85 		public PendingIntent getDeliveryIntent() {
86 			return deliveryIntent;
87 		}
88 	}
89 }
90