aboutsummaryrefslogtreecommitdiff
path: root/v1/src/main/java/com/xtremelabs/robolectric/shadows/ShadowSmsManager.java
blob: 3c4cca7635a268a71b388e43d4f0b114ab8d5130 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package com.xtremelabs.robolectric.shadows;

import android.app.PendingIntent;
import android.telephony.SmsManager;
import android.text.TextUtils;

import com.xtremelabs.robolectric.Robolectric;
import com.xtremelabs.robolectric.internal.Implementation;
import com.xtremelabs.robolectric.internal.Implements;
import com.xtremelabs.robolectric.internal.RealObject;

@Implements(SmsManager.class)
public class ShadowSmsManager {

	@RealObject
	private static SmsManager realManager = Robolectric.newInstanceOf(SmsManager.class);
	
	private TextSmsParams lastTextSmsParams = null;
	
	@Implementation
	public static SmsManager getDefault() {
		return realManager;
	}
	
	@Implementation
	public void sendTextMessage(
			String destinationAddress, String scAddress, String text,
            PendingIntent sentIntent, PendingIntent deliveryIntent) {

		if (TextUtils.isEmpty(destinationAddress))
            throw new IllegalArgumentException("Invalid destinationAddress");

        if (TextUtils.isEmpty(text))
            throw new IllegalArgumentException("Invalid message body");
		
		lastTextSmsParams = new TextSmsParams(
			destinationAddress,
			scAddress,
			text,
			sentIntent,
			deliveryIntent );
	}

	public TextSmsParams getLastSentTextMessageParams() {
		return lastTextSmsParams;
	}

    public void clearLastSentTextMessageParams() {
        lastTextSmsParams = null;
    }
	
	public class TextSmsParams {
		private String destinationAddress;
		private String scAddress;
		private String text;
		private PendingIntent sentIntent;
		private PendingIntent deliveryIntent;
		
		public TextSmsParams(
			String destinationAddress, String scAddress, String text,
            PendingIntent sentIntent, PendingIntent deliveryIntent) {
			this.destinationAddress = destinationAddress;
			this.scAddress = scAddress;
			this.text = text;
			this.sentIntent = sentIntent;
			this.deliveryIntent = deliveryIntent;
		}

		public String getDestinationAddress() {
			return destinationAddress;
		}

		public String getScAddress() {
			return scAddress;
		}

		public String getText() {
			return text;
		}

		public PendingIntent getSentIntent() {
			return sentIntent;
		}

		public PendingIntent getDeliveryIntent() {
			return deliveryIntent;
		}
	}
}