1package com.xtremelabs.robolectric.shadows;
2
3import android.app.PendingIntent;
4import android.telephony.SmsManager;
5import android.text.TextUtils;
6
7import com.xtremelabs.robolectric.Robolectric;
8import com.xtremelabs.robolectric.internal.Implementation;
9import com.xtremelabs.robolectric.internal.Implements;
10import com.xtremelabs.robolectric.internal.RealObject;
11
12@Implements(SmsManager.class)
13public class ShadowSmsManager {
14
15	@RealObject
16	private static SmsManager realManager = Robolectric.newInstanceOf(SmsManager.class);
17
18	private TextSmsParams lastTextSmsParams = null;
19
20	@Implementation
21	public static SmsManager getDefault() {
22		return realManager;
23	}
24
25	@Implementation
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
44	public TextSmsParams getLastSentTextMessageParams() {
45		return lastTextSmsParams;
46	}
47
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
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
69		public String getDestinationAddress() {
70			return destinationAddress;
71		}
72
73		public String getScAddress() {
74			return scAddress;
75		}
76
77		public String getText() {
78			return text;
79		}
80
81		public PendingIntent getSentIntent() {
82			return sentIntent;
83		}
84
85		public PendingIntent getDeliveryIntent() {
86			return deliveryIntent;
87		}
88	}
89}
90