]> www.average.org Git - YkNeoCR.git/blob - src/org/average/nfcauthcr/NFCAuthCREnroll.java
front mostly functional
[YkNeoCR.git] / src / org / average / nfcauthcr / NFCAuthCREnroll.java
1 package org.average.nfcauthcr;
2
3 import android.os.Bundle;
4 import android.app.Activity;
5 import android.app.AlertDialog;
6 import android.preference.PreferenceManager;
7 import android.content.SharedPreferences;
8 import android.content.SharedPreferences.Editor;
9 import android.content.DialogInterface;
10 import android.util.Log;
11 import android.view.View;
12 import android.widget.TextView;
13 import android.widget.RadioButton;
14
15 public class NFCAuthCREnroll extends Activity
16 {
17         private final String TAG = getClass().getName();
18
19         private static boolean waitingForResult = false;
20         private static SharedPreferences prefs;
21         private static int slot;
22
23         @Override
24         protected void onCreate(Bundle savedInstanceState)
25         {
26                 super.onCreate(savedInstanceState);
27                 Log.v(TAG, "Starting");
28                 prefs = PreferenceManager.getDefaultSharedPreferences(this);
29         }
30
31         @Override
32         protected void onResume() {
33                 super.onResume();
34                 setContentView(R.layout.main);
35                 slot = prefs.getInt("slot_number", -1);
36                 Log.v(TAG, "found saved slot value " + slot);
37                 RadioButton btn = null;
38                 switch (slot) {
39                 case 1: btn = (RadioButton)findViewById(R.id.slot_1);
40                         break;
41                 case 2: btn = (RadioButton)findViewById(R.id.slot_2);
42                         break;
43                 }
44                 if (btn != null) btn.setChecked(true);
45         }
46
47         @Override
48         protected void onPause() {
49                 super.onPause();
50                 Log.v(TAG, "Going inactive, try to stop");
51                 if (!waitingForResult) { finish(); }
52         }
53
54         @Override
55         protected void onStop() {
56                 super.onStop();
57                 Log.v(TAG, "Stop requested");
58         }
59
60         public void onSlotSelectionClicked(View view) {
61                 Log.v(TAG, "Radio Button selected");
62                 if (! ((RadioButton) view).isChecked()) return;
63                 switch(view.getId()) {
64                 case R.id.slot_1: slot=1; break;
65                 case R.id.slot_2: slot=2; break;
66                 }
67                 Editor editor = prefs.edit();
68                 editor.putInt("slot_number", slot);
69                 editor.commit();
70                 Log.v(TAG, "stored slot number " + slot);
71         }
72
73         public void onEnrollClicked(View view) {
74                 Log.v(TAG, "Enroll clicked");
75                 if (slot > 0) {
76                         showEnrollResult("<FIXME> using slot" + slot);
77                 } else {
78                         showEnrollResult("Must specify which slot to use");
79                 }
80         }
81
82         private void showEnrollResult(final String msg) {
83                 Log.v(TAG, "Show result: \"" + msg + "\"");
84
85                 AlertDialog.Builder builder = new AlertDialog.Builder(this);
86                 builder.setTitle(R.string.enrollresult);
87                 builder.setMessage(msg);
88                 builder.setPositiveButton(android.R.string.ok,
89                                 new DialogInterface.OnClickListener() {
90                         public void onClick(DialogInterface dialog, int which) {
91                                 dialog.dismiss();
92                                 if (!waitingForResult) { finish(); }
93                         }
94                 });
95                 AlertDialog dialog = builder.create();
96                 dialog.show();
97         }
98 }