aboutsummaryrefslogtreecommitdiffstats
path: root/wpadebug
diff options
context:
space:
mode:
authorJouni Malinen <j@w1.fi>2013-05-04 17:29:47 (GMT)
committerJouni Malinen <j@w1.fi>2013-05-04 17:29:47 (GMT)
commit3b4832fefefb0f75170d9d28c0bb769791543db4 (patch)
tree16cefd6dd56f022d67800d9a005e92fdaac89d16 /wpadebug
parentabfc3ad9afb6f0130afbfa60fdc8c98a68dfc527 (diff)
downloadhostap-3b4832fefefb0f75170d9d28c0bb769791543db4.zip
hostap-3b4832fefefb0f75170d9d28c0bb769791543db4.tar.gz
hostap-3b4832fefefb0f75170d9d28c0bb769791543db4.tar.bz2
wpadebug: Move NFC intent activity into a separate class
This simplifies both activities by making the DisplayMessageActity simple text message displaying operation and the NFC activity as something that is started only through NFC intent triggers. Signed-hostap: Jouni Malinen <j@w1.fi>
Diffstat (limited to 'wpadebug')
-rw-r--r--wpadebug/AndroidManifest.xml4
-rw-r--r--wpadebug/src/w1/fi/wpadebug/DisplayMessageActivity.java39
-rw-r--r--wpadebug/src/w1/fi/wpadebug/WpaNfcActivity.java74
3 files changed, 78 insertions, 39 deletions
diff --git a/wpadebug/AndroidManifest.xml b/wpadebug/AndroidManifest.xml
index 95ac726..535e3d2 100644
--- a/wpadebug/AndroidManifest.xml
+++ b/wpadebug/AndroidManifest.xml
@@ -18,6 +18,10 @@
<activity android:name="w1.fi.wpadebug.DisplayMessageActivity"
android:label="Operation result"
android:parentActivityName="w1.fi.wpadebug.MainActivity">
+ </activity>
+ <activity android:name="w1.fi.wpadebug.WpaNfcActivity"
+ android:label="wpa_supplicant NFC operation"
+ android:parentActivityName="w1.fi.wpadebug.MainActivity">
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED"/>
<category android:name="android.intent.category.DEFAULT"/>
diff --git a/wpadebug/src/w1/fi/wpadebug/DisplayMessageActivity.java b/wpadebug/src/w1/fi/wpadebug/DisplayMessageActivity.java
index 19cb14b..28ef85f 100644
--- a/wpadebug/src/w1/fi/wpadebug/DisplayMessageActivity.java
+++ b/wpadebug/src/w1/fi/wpadebug/DisplayMessageActivity.java
@@ -16,9 +16,6 @@ import android.content.Intent;
import android.widget.TextView;
import android.text.method.ScrollingMovementMethod;
import android.util.Log;
-import android.nfc.NdefMessage;
-import android.nfc.NdefRecord;
-import android.nfc.NfcAdapter;
public class DisplayMessageActivity extends Activity
{
@@ -41,8 +38,6 @@ public class DisplayMessageActivity extends Activity
Intent intent = getIntent();
String action = intent.getAction();
Log.d(TAG, "onCreate: action=" + action);
- if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(intent.getAction()))
- return; // handled in onResume()
String message = intent.getStringExtra(MainActivity.EXTRA_MESSAGE);
@@ -51,38 +46,4 @@ public class DisplayMessageActivity extends Activity
textView.setMovementMethod(new ScrollingMovementMethod());
setContentView(textView);
}
-
- @Override
- public void onResume()
- {
- super.onResume();
-
- Intent intent = getIntent();
- String action = intent.getAction();
- Log.d(TAG, "onResume: action=" + action);
-
- if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(action)) {
- Log.d(TAG, "onResume - NDEF discovered");
- Parcelable[] raw = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES);
- if (raw != null) {
- String txt = "NDEF message count: " + raw.length;
- Log.d(TAG, txt);
- NdefMessage[] msgs = new NdefMessage[raw.length];
- for (int i = 0; i < raw.length; i++) {
- msgs[i] = (NdefMessage) raw[i];
- NdefRecord rec = msgs[i].getRecords()[0];
- Log.d(TAG, "MIME type: " + rec.toMimeType());
- byte[] a = rec.getPayload();
- Log.d(TAG, "NDEF record: " + byteArrayHex(a));
- txt += "\nMessage[" + rec.toMimeType() + "]: " +
- byteArrayHex(a);
- }
-
- TextView textView = new TextView(this);
- textView.setText(txt);
- textView.setMovementMethod(new ScrollingMovementMethod());
- setContentView(textView);
- }
- }
- }
}
diff --git a/wpadebug/src/w1/fi/wpadebug/WpaNfcActivity.java b/wpadebug/src/w1/fi/wpadebug/WpaNfcActivity.java
new file mode 100644
index 0000000..2fcbb46
--- /dev/null
+++ b/wpadebug/src/w1/fi/wpadebug/WpaNfcActivity.java
@@ -0,0 +1,74 @@
+/*
+ * wpadebug - wpa_supplicant and Wi-Fi debugging app for Android
+ * Copyright (c) 2013, Jouni Malinen <j@w1.fi>
+ *
+ * This software may be distributed under the terms of the BSD license.
+ * See README for more details.
+ */
+
+package w1.fi.wpadebug;
+
+import android.app.Activity;
+import android.os.Bundle;
+import android.os.Parcelable;
+import android.view.MenuItem;
+import android.content.Intent;
+import android.widget.TextView;
+import android.text.method.ScrollingMovementMethod;
+import android.util.Log;
+import android.nfc.NdefMessage;
+import android.nfc.NdefRecord;
+import android.nfc.NfcAdapter;
+
+public class WpaNfcActivity extends Activity
+{
+ private static final String TAG = "wpadebug";
+
+ String byteArrayHex(byte[] a) {
+ StringBuilder sb = new StringBuilder();
+ for (byte b: a)
+ sb.append(String.format("%02x", b));
+ return sb.toString();
+ }
+
+ @Override
+ public void onCreate(Bundle savedInstanceState)
+ {
+ Log.d(TAG, "onCreate");
+ super.onCreate(savedInstanceState);
+ }
+
+ @Override
+ public void onResume()
+ {
+ super.onResume();
+
+ Intent intent = getIntent();
+ String action = intent.getAction();
+ Log.d(TAG, "onResume: action=" + action);
+
+ if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(action)) {
+ Log.d(TAG, "onResume - NDEF discovered");
+ Parcelable[] raw = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES);
+ if (raw != null) {
+ String txt = "NDEF message count: " + raw.length;
+ Log.d(TAG, txt);
+ NdefMessage[] msgs = new NdefMessage[raw.length];
+ for (int i = 0; i < raw.length; i++) {
+ msgs[i] = (NdefMessage) raw[i];
+ NdefRecord rec = msgs[i].getRecords()[0];
+ Log.d(TAG, "MIME type: " + rec.toMimeType());
+ byte[] a = rec.getPayload();
+ Log.d(TAG, "NDEF record: " + byteArrayHex(a));
+ txt += "\nMessage[" + rec.toMimeType() + "]: " +
+ byteArrayHex(a);
+ }
+
+ TextView textView = new TextView(this);
+ textView.setText(txt);
+ textView.setMovementMethod(new ScrollingMovementMethod());
+ setContentView(textView);
+ }
+ }
+ }
+}