]> www.average.org Git - YkNeoCR.git/blobdiff - src/org/average/nfcauthcr/NFCAuthCREnroll.java
intents work
[YkNeoCR.git] / src / org / average / nfcauthcr / NFCAuthCREnroll.java
index 098011a558537164450c2846b6ea751a7ed567bb..bb6b4f0357118db644ce4e7aace211823aa5be34 100644 (file)
@@ -2,15 +2,21 @@ package org.average.nfcauthcr;
 
 import android.os.Bundle;
 import android.app.Activity;
+import android.app.AlertDialog;
 import android.preference.PreferenceManager;
+import android.content.Intent;
 import android.content.SharedPreferences;
 import android.content.SharedPreferences.Editor;
+import android.content.DialogInterface;
 import android.util.Log;
 import android.view.View;
+import android.widget.TextView;
 import android.widget.RadioButton;
 
-public class NFCAuthCREnroll extends Activity
-{
+import org.average.nfcauthcr.NFCAuthCRCheck;
+
+public class NFCAuthCREnroll extends Activity {
+
        private final String TAG = getClass().getName();
 
        private static boolean waitingForResult = false;
@@ -69,6 +75,47 @@ public class NFCAuthCREnroll extends Activity
 
        public void onEnrollClicked(View view) {
                Log.v(TAG, "Enroll clicked");
-               if (!waitingForResult) { finish(); }
+               if (slot > 0) {
+                       runChallenge(slot);
+               } else {
+                       showEnrollResult("Must specify which slot to use");
+               }
+       }
+
+       public void onActivityResult(int requestCode, int resultCode,
+                                       Intent intent) {
+               Log.v(TAG, "Got activity result");
+               waitingForResult = false;
+               if (resultCode == RESULT_OK) {
+                       String res = intent.getStringExtra("response");
+                       Log.v(TAG, "Response is \"" + res + "\"");
+               } else {
+                       Log.v(TAG, "Error result code " + resultCode);
+               }
+       }
+
+       private void showEnrollResult(final String msg) {
+               Log.v(TAG, "Show result: \"" + msg + "\"");
+
+               AlertDialog.Builder builder = new AlertDialog.Builder(this);
+               builder.setTitle(R.string.enrollresult);
+               builder.setMessage(msg);
+               builder.setPositiveButton(android.R.string.ok,
+                               new DialogInterface.OnClickListener() {
+                       public void onClick(DialogInterface dialog, int which) {
+                               dialog.dismiss();
+                               if (!waitingForResult) { finish(); }
+                       }
+               });
+               AlertDialog dialog = builder.create();
+               dialog.show();
+       }
+
+       private void runChallenge(int slot) {
+               Log.v(TAG, "Launching challenging activity");
+               Intent crIntent = new Intent(this, NFCAuthCRCheck.class);
+               crIntent.putExtra("slot", slot);
+               this.startActivityForResult(crIntent, 0);
+               waitingForResult = true;
        }
 }