reorg, separate roles
[YkNeoCR.git] / src / org / average / nfcauthcr / TagEvent.java
1 package org.average.nfcauthcr;
2
3 import android.app.Activity;
4 import android.app.AlertDialog;
5 import android.app.PendingIntent;
6 import android.content.DialogInterface;
7 import android.content.Intent;
8 import android.content.IntentFilter;
9 import android.nfc.NfcAdapter;
10 import android.nfc.Tag;
11 import android.nfc.TagLostException;
12 import android.nfc.tech.IsoDep;
13 import android.util.Log;
14 import android.widget.Toast;
15
16 import org.average.nfcauthcr.NfcCRdispatch;
17
18 public class TagEvent extends Activity {
19
20         private final String TAG = getClass().getName();
21
22         private NfcCRdispatch dispatch = new NfcCRdispatch((Activity)this);
23
24         @Override
25         protected void onResume() {
26                 super.onResume();
27                 Log.v(TAG, "Starting the work");
28
29                 new AlertDialog.Builder(this)
30                         .setTitle(R.string.challenging)
31                         .setMessage(R.string.swipe)
32                         .setOnCancelListener(
33                                 new DialogInterface.OnCancelListener() {
34                                 public void onCancel(DialogInterface dialog) {
35                                         Log.v(TAG, "Cancel");
36                                         finish();
37                                 }
38                         })
39                         .create().show();
40
41                 Intent intent = getIntent();
42                 setResult(RESULT_CANCELED);
43                 byte[] challenge = intent.getByteArrayExtra("challenge");
44                 dispatch.onResume(challenge);
45         }
46
47         @Override
48         protected void onPause() {
49                 super.onPause();
50                 Log.v(TAG, "Finished the work");
51
52                 dispatch.onPause();
53         }
54
55         public void onNewIntent(Intent newintent) {
56                 Log.v(TAG, "NFC Intent arrived");
57
58                 byte[] response = dispatch.onNewIntent(newintent);
59                 if (response != null) {
60                         Intent masterintent = getIntent();
61                         masterintent.putExtra("response", response);
62                         setResult(RESULT_OK, masterintent);
63                         finish();
64                 }
65         }
66 }