am 12f3e97c: am e97e78a0: Make unittests work, new TagBroadcastReceiver
Merge commit '12f3e97c7a011cab7b13caeff308da380a62f6b8'
* commit '12f3e97c7a011cab7b13caeff308da380a62f6b8':
Make unittests work, new TagBroadcastReceiver
diff --git a/apps/Tag/AndroidManifest.xml b/apps/Tag/AndroidManifest.xml
index ae198a3..3388a30 100644
--- a/apps/Tag/AndroidManifest.xml
+++ b/apps/Tag/AndroidManifest.xml
@@ -31,6 +31,12 @@
<activity android:name="TagSelector"></activity>
<activity android:name="TagList"></activity>
+ <receiver android:name=".TagBroadcastReceiver">
+ <intent-filter>
+ <action android:name= "com.trustedlogic.trustednfc.android.action.NDEF_TAG_DISCOVERED"/>
+ </intent-filter>
+ </receiver>
+
</application>
<uses-permission android:name="com.trustedlogic.trustednfc.permission.NFC_NOTIFY"></uses-permission>
<uses-permission android:name="com.trustedlogic.trustednfc.permission.NFC_RAW"></uses-permission>
diff --git a/apps/Tag/src/com/android/apps/tag/TagBroadcastReceiver.java b/apps/Tag/src/com/android/apps/tag/TagBroadcastReceiver.java
new file mode 100644
index 0000000..015e897
--- /dev/null
+++ b/apps/Tag/src/com/android/apps/tag/TagBroadcastReceiver.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.apps.tag;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.widget.Toast;
+import com.trustedlogic.trustednfc.android.NdefMessage;
+import com.trustedlogic.trustednfc.android.NdefRecord;
+import com.trustedlogic.trustednfc.android.NfcManager;
+
+/**
+ * This class doesn't work. Sorry. Think of this class as pseudo
+ * code for now.
+ */
+public class TagBroadcastReceiver extends BroadcastReceiver {
+
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ if (intent.getAction().equals(NfcManager.NDEF_TAG_DISCOVERED_ACTION)) {
+ NdefMessage msg = intent.getParcelableExtra(NfcManager.NDEF_MESSAGE_EXTRA);
+ Toast.makeText(context, "got a new message", Toast.LENGTH_SHORT).show();
+ insertIntoDb(msg);
+ }
+ }
+
+ private void insertIntoDb(NdefMessage msg) {
+ for (NdefRecord record : msg.getRecords()) {
+ insertIntoRecordDb(record.getType(), record.getPayload());
+ }
+ }
+
+ private void insertIntoRecordDb(byte[] type, byte[] payload) {
+ // do something...
+ }
+
+}
diff --git a/apps/Tag/src/com/android/apps/tag/TagList.java b/apps/Tag/src/com/android/apps/tag/TagList.java
index aa9d8d3..f8a93e6 100644
--- a/apps/Tag/src/com/android/apps/tag/TagList.java
+++ b/apps/Tag/src/com/android/apps/tag/TagList.java
@@ -27,18 +27,17 @@
import android.view.View;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
-import com.trustedlogic.trustednfc.android.NfcManager;
+import android.widget.Toast;
/**
* @author nnk@google.com (Nick Kralevich)
*/
public class TagList extends ListActivity implements DialogInterface.OnClickListener {
- private NfcManager mManager;
-
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
+ Toast.makeText(getBaseContext(), "entered method", Toast.LENGTH_SHORT).show();
SQLiteDatabase db = new TagDBHelper(this.getBaseContext()).getReadableDatabase();
Cursor c = db.query("Tags", new String[] { "_id", "description" }, null, null, null, null, null);
@@ -51,6 +50,9 @@
setListAdapter(sca);
registerForContextMenu(getListView());
+ c.close();
+ db.close();
+ Toast.makeText(getBaseContext(), "exit method", Toast.LENGTH_SHORT).show();
}
@Override
diff --git a/apps/Tag/tests/AndroidManifest.xml b/apps/Tag/tests/AndroidManifest.xml
index f4e79ed..63ef9e3 100644
--- a/apps/Tag/tests/AndroidManifest.xml
+++ b/apps/Tag/tests/AndroidManifest.xml
@@ -15,7 +15,7 @@
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="com.android.apps.tag">
+ package="com.android.apps.tag.tests">
<!-- We add an application tag here just so that we can indicate that
this package needs to link against the android.test library,
@@ -25,8 +25,8 @@
</application>
<instrumentation android:name="android.test.InstrumentationTestRunner"
- android:targetPackage="com.example.android.helloactivity"
- android:label="HelloActivity sample tests">
+ android:targetPackage="com.android.apps.tag"
+ android:label="Tag tests">
</instrumentation>
</manifest>
diff --git a/apps/Tag/tests/src/com/android/apps/tag/TagBroadcastReceiverTest.java b/apps/Tag/tests/src/com/android/apps/tag/TagBroadcastReceiverTest.java
new file mode 100644
index 0000000..e030b6a
--- /dev/null
+++ b/apps/Tag/tests/src/com/android/apps/tag/TagBroadcastReceiverTest.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.apps.tag;
+
+import android.content.Intent;
+import android.test.ActivityInstrumentationTestCase2;
+
+/**
+ * @author nnk@google.com (Nick Kralevich)
+ */
+public class TagBroadcastReceiverTest extends ActivityInstrumentationTestCase2<Tags> {
+ /**
+ * Creates an {@link ActivityInstrumentationTestCase2} for the {@link Tags} activity.
+ */
+ public TagBroadcastReceiverTest() {
+ super(Tags.class);
+ }
+
+ public void testWrongMessage() {
+ TagBroadcastReceiver receiver = new TagBroadcastReceiver();
+ Intent i = new Intent().setAction("BOGUS");
+ receiver.onReceive(getActivity().getBaseContext(), i);
+ assertDatabaseNoChange(receiver);
+ }
+
+ private void assertDatabaseNoChange(TagBroadcastReceiver receiver) {
+ // TODO: implement
+ }
+
+}