aboutsummaryrefslogtreecommitdiff
path: root/v1/src/main/java/com/xtremelabs/robolectric/shadows/ShadowNfcAdapter.java
blob: 6ff7a524cd685a8b1f8dbdd187e04545387aa237 (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
package com.xtremelabs.robolectric.shadows;

import android.app.Activity;
import android.app.PendingIntent;
import android.content.Context;
import android.content.IntentFilter;
import android.nfc.NfcAdapter;
import com.xtremelabs.robolectric.internal.Implementation;
import com.xtremelabs.robolectric.internal.Implements;
import com.xtremelabs.robolectric.internal.RealObject;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

@Implements(NfcAdapter.class)
public class ShadowNfcAdapter {
    @RealObject NfcAdapter nfcAdapter;
    private Activity enabledActivity;
    private PendingIntent intent;
    private IntentFilter[] filters;
    private String[][] techLists;
    private Activity disabledActivity;

    @Implementation
    public static NfcAdapter getDefaultAdapter(Context context) {
        try {
            Constructor<NfcAdapter> constructor = NfcAdapter.class.getDeclaredConstructor();
            constructor.setAccessible(true);
            return constructor.newInstance();
        } catch (InstantiationException e) {
            throw new RuntimeException(e);
        } catch (IllegalAccessException e) {
            throw new RuntimeException(e);
        } catch (InvocationTargetException e) {
            throw new RuntimeException(e);
        } catch (NoSuchMethodException e) {
            throw new RuntimeException(e);
        }
    }

    @Implementation
    public void enableForegroundDispatch(Activity activity, PendingIntent intent, IntentFilter[] filters, String[][] techLists) {
        this.enabledActivity = activity;
        this.intent = intent;
        this.filters = filters;
        this.techLists = techLists;
    }

    @Implementation
    public void disableForegroundDispatch(Activity activity) {
        disabledActivity = activity;
    }

    public Activity getEnabledActivity() {
        return enabledActivity;
    }

    public PendingIntent getIntent() {
        return intent;
    }

    public IntentFilter[] getFilters() {
        return filters;
    }

    public String[][] getTechLists() {
        return techLists;
    }

    public Activity getDisabledActivity() {
        return disabledActivity;
    }
}