]> www.average.org Git - YkNeoCR.git/commitdiff
rename Check to TagEvent
authorEugene Crosser <crosser@average.org>
Sat, 4 May 2013 07:26:45 +0000 (11:26 +0400)
committerEugene Crosser <crosser@average.org>
Sat, 4 May 2013 07:26:45 +0000 (11:26 +0400)
src/org/average/nfcauthcr/Autostart.java
src/org/average/nfcauthcr/Autostop.java
src/org/average/nfcauthcr/Check.java [deleted file]
src/org/average/nfcauthcr/Enroll.java
src/org/average/nfcauthcr/TagEvent.java [new file with mode: 0644]

index 755fe04098db436393dc97833b2a3a27c378ca33..ac247031d8c5311f1a343352443171db7e2ed8e8 100644 (file)
@@ -5,7 +5,7 @@ import android.content.Context;
 import android.content.Intent;
 import android.util.Log;
 
-import org.average.nfcauthcr.Check;
+import org.average.nfcauthcr.TagEvent;
 
 public class Autostart extends BroadcastReceiver {
 
@@ -14,7 +14,7 @@ public class Autostart extends BroadcastReceiver {
        @Override
        public void onReceive(Context context, Intent intent) {
                Log.v(TAG, "Autostart called");
-               Intent i = new Intent(context, Check.class);
+               Intent i = new Intent(context, TagEvent.class);
                i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                context.startService(i);
        }
index 238104ffb88c306638d4859878d76ca45262c2e6..e845a42890adc343186ebaa47a1fe96089db0fc7 100644 (file)
@@ -5,7 +5,7 @@ import android.content.Context;
 import android.content.Intent;
 import android.util.Log;
 
-import org.average.nfcauthcr.Check;
+import org.average.nfcauthcr.TagEvent;
 
 public class Autostop extends BroadcastReceiver {
 
@@ -14,7 +14,7 @@ public class Autostop extends BroadcastReceiver {
        @Override
        public void onReceive(Context context, Intent intent) {
                Log.v(TAG, "Autostop called");
-               Intent i = new Intent(context, Check.class);
+               Intent i = new Intent(context, TagEvent.class);
                context.stopService(i);
        }
 }
diff --git a/src/org/average/nfcauthcr/Check.java b/src/org/average/nfcauthcr/Check.java
deleted file mode 100644 (file)
index 6b6ec4f..0000000
+++ /dev/null
@@ -1,122 +0,0 @@
-package org.average.nfcauthcr;
-
-import android.app.Activity;
-import android.app.AlertDialog;
-import android.app.PendingIntent;
-import android.content.DialogInterface;
-import android.content.Intent;
-import android.content.IntentFilter;
-import android.nfc.NfcAdapter;
-import android.nfc.Tag;
-import android.nfc.TagLostException;
-import android.nfc.tech.IsoDep;
-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 PendingIntent tagIntent;
-
-       @Override
-       protected void onResume() {
-               super.onResume();
-               Log.v(TAG, "Starting the work");
-
-               Intent intent = getIntent();
-               setResult(RESULT_CANCELED);
-               int slot = intent.getIntExtra("slot", -1);
-               if (slot > 0) {
-                       enableDispatch(slot);
-               }
-       }
-
-       @Override
-       protected void onPause() {
-               super.onPause();
-               Log.v(TAG, "Finished the work");
-
-               disableDispatch();
-       }
-
-       public void onNewIntent(Intent intent) {
-               Log.v(TAG, "NFC Intent arrived");
-               int slot = intent.getIntExtra("slot", -1);
-               byte[] challenge = intent.getByteArrayExtra("challenge");
-               if (slot <= 0) return;
-               Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
-               if (tag == null) return;
-               IsoDep isoTag = IsoDep.get(tag);
-               try {
-                       byte[] response = YkNeo.doChallengeYubiKey(
-                                               isoTag, slot, challenge);
-                       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();
-       }
-
-/*
-<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();
-               intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
-               intent.putExtra("slot", slot);
-               tagIntent = PendingIntent.getActivity(this, 0, intent, 0);
-               IntentFilter iso =
-                       new IntentFilter(NfcAdapter.ACTION_TECH_DISCOVERED);
-               NfcAdapter adapter = NfcAdapter.getDefaultAdapter(this);
-               if (adapter == null) {
-                       Toast.makeText(this, R.string.no_nfc,
-                                               Toast.LENGTH_LONG).show();
-                       finish();
-               }
-               if (! adapter.isEnabled()) {
-                       Toast.makeText(this, R.string.nfc_disabled,
-                                               Toast.LENGTH_LONG).show();
-                       finish();
-               }
-               adapter.enableForegroundDispatch(
-                       this, tagIntent, new IntentFilter[] {iso},
-                       new String[][] {new String[] {IsoDep.class.getName()}});
-       }
-
-       private void disableDispatch() {
-               if (tagIntent != null) {
-                       tagIntent.cancel();
-                       tagIntent = null;
-               }
-               NfcAdapter adapter = NfcAdapter.getDefaultAdapter(this);
-               if (adapter != null) {
-                       adapter.disableForegroundDispatch(this);
-               }
-       }
-}
index 8d90488dbc41e34e665aea4e9c84a76b71b93211..12533e7bf8c469fb9bd719696d5215fa898b3826 100644 (file)
@@ -15,7 +15,7 @@ import android.view.View;
 import android.widget.TextView;
 import android.widget.RadioButton;
 
-import org.average.nfcauthcr.Check;
+import org.average.nfcauthcr.TagEvent;
 
 public class Enroll extends Activity {
 
@@ -130,7 +130,7 @@ public class Enroll extends Activity {
                byte[] challenge = new byte[63];
                rng.nextBytes(challenge);
                Log.v(TAG, "Random challenge: " + hex(challenge));
-               Intent crIntent = new Intent(this, Check.class);
+               Intent crIntent = new Intent(this, TagEvent.class);
                crIntent.putExtra("slot", slot);
                crIntent.putExtra("challenge", challenge);
                this.startActivityForResult(crIntent, 0);
diff --git a/src/org/average/nfcauthcr/TagEvent.java b/src/org/average/nfcauthcr/TagEvent.java
new file mode 100644 (file)
index 0000000..7ef6943
--- /dev/null
@@ -0,0 +1,122 @@
+package org.average.nfcauthcr;
+
+import android.app.Activity;
+import android.app.AlertDialog;
+import android.app.PendingIntent;
+import android.content.DialogInterface;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.nfc.NfcAdapter;
+import android.nfc.Tag;
+import android.nfc.TagLostException;
+import android.nfc.tech.IsoDep;
+import android.util.Log;
+import android.widget.Toast;
+
+import org.average.nfcauthcr.YkNeo;
+import org.average.nfcauthcr.CRException;
+
+public class TagEvent extends Activity {
+
+       private final String TAG = getClass().getName();
+
+       private PendingIntent tagIntent;
+
+       @Override
+       protected void onResume() {
+               super.onResume();
+               Log.v(TAG, "Starting the work");
+
+               Intent intent = getIntent();
+               setResult(RESULT_CANCELED);
+               int slot = intent.getIntExtra("slot", -1);
+               if (slot > 0) {
+                       enableDispatch(slot);
+               }
+       }
+
+       @Override
+       protected void onPause() {
+               super.onPause();
+               Log.v(TAG, "Finished the work");
+
+               disableDispatch();
+       }
+
+       public void onNewIntent(Intent intent) {
+               Log.v(TAG, "NFC Intent arrived");
+               int slot = intent.getIntExtra("slot", -1);
+               byte[] challenge = intent.getByteArrayExtra("challenge");
+               if (slot <= 0) return;
+               Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
+               if (tag == null) return;
+               IsoDep isoTag = IsoDep.get(tag);
+               try {
+                       byte[] response = YkNeo.doChallengeYubiKey(
+                                               isoTag, slot, challenge);
+                       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();
+       }
+
+/*
+<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();
+               intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
+               intent.putExtra("slot", slot);
+               tagIntent = PendingIntent.getActivity(this, 0, intent, 0);
+               IntentFilter iso =
+                       new IntentFilter(NfcAdapter.ACTION_TECH_DISCOVERED);
+               NfcAdapter adapter = NfcAdapter.getDefaultAdapter(this);
+               if (adapter == null) {
+                       Toast.makeText(this, R.string.no_nfc,
+                                               Toast.LENGTH_LONG).show();
+                       finish();
+               }
+               if (! adapter.isEnabled()) {
+                       Toast.makeText(this, R.string.nfc_disabled,
+                                               Toast.LENGTH_LONG).show();
+                       finish();
+               }
+               adapter.enableForegroundDispatch(
+                       this, tagIntent, new IntentFilter[] {iso},
+                       new String[][] {new String[] {IsoDep.class.getName()}});
+       }
+
+       private void disableDispatch() {
+               if (tagIntent != null) {
+                       tagIntent.cancel();
+                       tagIntent = null;
+               }
+               NfcAdapter adapter = NfcAdapter.getDefaultAdapter(this);
+               if (adapter != null) {
+                       adapter.disableForegroundDispatch(this);
+               }
+       }
+}