1 package org.average.nfcauthcr;
3 import android.os.Bundle;
4 import android.app.Activity;
5 import android.app.AlertDialog;
6 import android.preference.PreferenceManager;
7 import android.content.Intent;
8 import android.content.SharedPreferences;
9 import android.content.SharedPreferences.Editor;
10 import android.content.DialogInterface;
11 import android.util.Log;
12 import android.view.View;
13 import android.widget.TextView;
14 import android.widget.RadioButton;
16 import org.average.nfcauthcr.NFCAuthCRCheck;
18 public class NFCAuthCREnroll extends Activity {
20 private final String TAG = getClass().getName();
22 private static boolean waitingForResult = false;
23 private static SharedPreferences prefs;
24 private static int slot;
27 protected void onCreate(Bundle savedInstanceState)
29 super.onCreate(savedInstanceState);
30 Log.v(TAG, "Starting");
31 prefs = PreferenceManager.getDefaultSharedPreferences(this);
35 protected void onResume() {
37 setContentView(R.layout.main);
38 slot = prefs.getInt("slot_number", -1);
39 Log.v(TAG, "found saved slot value " + slot);
40 RadioButton btn = null;
42 case 1: btn = (RadioButton)findViewById(R.id.slot_1);
44 case 2: btn = (RadioButton)findViewById(R.id.slot_2);
47 if (btn != null) btn.setChecked(true);
51 protected void onPause() {
53 Log.v(TAG, "Going inactive, try to stop");
54 if (!waitingForResult) { finish(); }
58 protected void onStop() {
60 Log.v(TAG, "Stop requested");
63 public void onSlotSelectionClicked(View view) {
64 Log.v(TAG, "Radio Button selected");
65 if (! ((RadioButton) view).isChecked()) return;
66 switch(view.getId()) {
67 case R.id.slot_1: slot=1; break;
68 case R.id.slot_2: slot=2; break;
70 Editor editor = prefs.edit();
71 editor.putInt("slot_number", slot);
73 Log.v(TAG, "stored slot number " + slot);
76 public void onEnrollClicked(View view) {
77 Log.v(TAG, "Enroll clicked");
81 showEnrollResult("Must specify which slot to use");
85 public void onActivityResult(int requestCode, int resultCode,
87 Log.v(TAG, "Got activity result");
88 waitingForResult = false;
89 if (resultCode == RESULT_OK) {
90 String res = intent.getStringExtra("response");
91 Log.v(TAG, "Response is \"" + res + "\"");
93 Log.v(TAG, "Error result code " + resultCode);
97 private void showEnrollResult(final String msg) {
98 Log.v(TAG, "Show result: \"" + msg + "\"");
100 AlertDialog.Builder builder = new AlertDialog.Builder(this);
101 builder.setTitle(R.string.enrollresult);
102 builder.setMessage(msg);
103 builder.setPositiveButton(android.R.string.ok,
104 new DialogInterface.OnClickListener() {
105 public void onClick(DialogInterface dialog, int which) {
107 if (!waitingForResult) { finish(); }
110 AlertDialog dialog = builder.create();
114 private void runChallenge(int slot) {
115 Log.v(TAG, "Launching challenging activity");
116 Intent crIntent = new Intent(this, NFCAuthCRCheck.class);
117 crIntent.putExtra("slot", slot);
118 this.startActivityForResult(crIntent, 0);
119 waitingForResult = true;