• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package com.xtremelabs.robolectric.shadows;
2 
3 import android.app.Activity;
4 import android.app.PendingIntent;
5 import android.content.Context;
6 import android.content.IntentFilter;
7 import android.nfc.NfcAdapter;
8 import com.xtremelabs.robolectric.internal.Implementation;
9 import com.xtremelabs.robolectric.internal.Implements;
10 import com.xtremelabs.robolectric.internal.RealObject;
11 
12 import java.lang.reflect.Constructor;
13 import java.lang.reflect.InvocationTargetException;
14 
15 @Implements(NfcAdapter.class)
16 public class ShadowNfcAdapter {
17     @RealObject NfcAdapter nfcAdapter;
18     private Activity enabledActivity;
19     private PendingIntent intent;
20     private IntentFilter[] filters;
21     private String[][] techLists;
22     private Activity disabledActivity;
23 
24     @Implementation
getDefaultAdapter(Context context)25     public static NfcAdapter getDefaultAdapter(Context context) {
26         try {
27             Constructor<NfcAdapter> constructor = NfcAdapter.class.getDeclaredConstructor();
28             constructor.setAccessible(true);
29             return constructor.newInstance();
30         } catch (InstantiationException e) {
31             throw new RuntimeException(e);
32         } catch (IllegalAccessException e) {
33             throw new RuntimeException(e);
34         } catch (InvocationTargetException e) {
35             throw new RuntimeException(e);
36         } catch (NoSuchMethodException e) {
37             throw new RuntimeException(e);
38         }
39     }
40 
41     @Implementation
enableForegroundDispatch(Activity activity, PendingIntent intent, IntentFilter[] filters, String[][] techLists)42     public void enableForegroundDispatch(Activity activity, PendingIntent intent, IntentFilter[] filters, String[][] techLists) {
43         this.enabledActivity = activity;
44         this.intent = intent;
45         this.filters = filters;
46         this.techLists = techLists;
47     }
48 
49     @Implementation
disableForegroundDispatch(Activity activity)50     public void disableForegroundDispatch(Activity activity) {
51         disabledActivity = activity;
52     }
53 
getEnabledActivity()54     public Activity getEnabledActivity() {
55         return enabledActivity;
56     }
57 
getIntent()58     public PendingIntent getIntent() {
59         return intent;
60     }
61 
getFilters()62     public IntentFilter[] getFilters() {
63         return filters;
64     }
65 
getTechLists()66     public String[][] getTechLists() {
67         return techLists;
68     }
69 
getDisabledActivity()70     public Activity getDisabledActivity() {
71         return disabledActivity;
72     }
73 }
74