]> www.average.org Git - YkNeoCR.git/blobdiff - src/org/average/nfcauthcr/Check.java
move swipeDialog to activity
[YkNeoCR.git] / src / org / average / nfcauthcr / Check.java
index c3738f7fc4f80dbe2c799925d522beaa0ea62153..6b6ec4f568f79e043ea47cef0888432bb38257b4 100644 (file)
@@ -14,12 +14,12 @@ import android.util.Log;
 import android.widget.Toast;
 
 import org.average.nfcauthcr.YkNeo;
+import org.average.nfcauthcr.CRException;
 
 public class Check extends Activity {
 
        private final String TAG = getClass().getName();
 
-       private AlertDialog swipeDialog;
        private PendingIntent tagIntent;
 
        @Override
@@ -29,14 +29,8 @@ public class Check extends Activity {
 
                Intent intent = getIntent();
                setResult(RESULT_CANCELED);
-               if (swipeDialog != null) {
-                       swipeDialog.dismiss();
-                       swipeDialog = null;
-               }
                int slot = intent.getIntExtra("slot", -1);
                if (slot > 0) {
-                       swipeDialog = makeDialog();
-                       swipeDialog.show();
                        enableDispatch(slot);
                }
        }
@@ -46,10 +40,6 @@ public class Check extends Activity {
                super.onPause();
                Log.v(TAG, "Finished the work");
 
-               if(swipeDialog != null) {
-                       swipeDialog.dismiss();
-                       swipeDialog = null;
-               }
                disableDispatch();
        }
 
@@ -61,28 +51,40 @@ public class Check extends Activity {
                Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
                if (tag == null) return;
                IsoDep isoTag = IsoDep.get(tag);
-               byte[] response = YkNeo.doChallengeYubiKey(
+               try {
+                       byte[] response = YkNeo.doChallengeYubiKey(
                                                isoTag, slot, challenge);
-               if (response != null) {
                        Intent data = getIntent();
                        data.putExtra("response", response);
                        setResult(RESULT_OK, data);
+               } catch (CRException e) {
+                       Log.v(TAG, e.getMessage());
+                       Toast.makeText(this, e.getMessage(),
+                                       Toast.LENGTH_LONG).show();
                }
                finish();
        }
 
-       private AlertDialog makeDialog() {
-               AlertDialog.Builder builder = new AlertDialog.Builder(this);
-               builder.setTitle(R.string.challenging);
-               builder.setMessage(R.string.swipe);
-               builder.setOnCancelListener(
-                               new DialogInterface.OnCancelListener() {
-                       public void onCancel(DialogInterface dialog) {
-                               finish();
-                       }
-               });
-               return builder.create();
-       }
+/*
+<receiver android:name=".IsoDepReceiver"
+          android:label="IsoDepReceiver">
+     <intent-filter>
+         <action android:name="android.nfc.action.TECH_DISCOVERED" />
+     </intent-filter>
+
+     <meta-data android:name="android.nfc.action.TECH_DISCOVERED"
+         android:resource="@xml/filter_nfc"
+     />
+ </receiver>
+
+<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
+     <!-- capture anything using IsoDep -->
+     <tech-list>
+         <tech>android.nfc.tech.IsoDep</tech>
+     </tech-list>
+ </resources>
+
+*/
 
        private void enableDispatch(int slot) {
                Intent intent = getIntent();
@@ -96,13 +98,11 @@ public class Check extends Activity {
                        Toast.makeText(this, R.string.no_nfc,
                                                Toast.LENGTH_LONG).show();
                        finish();
-                       return;
                }
                if (! adapter.isEnabled()) {
                        Toast.makeText(this, R.string.nfc_disabled,
                                                Toast.LENGTH_LONG).show();
                        finish();
-                       return;
                }
                adapter.enableForegroundDispatch(
                        this, tagIntent, new IntentFilter[] {iso},