Merge branch 'gingerbread' into gingerbread-release
This commit is contained in:
2
apps/Tag/.gitignore
vendored
2
apps/Tag/.gitignore
vendored
@@ -1,2 +0,0 @@
|
|||||||
*.swp
|
|
||||||
|
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
LOCAL_PATH:= $(call my-dir)
|
|
||||||
include $(CLEAR_VARS)
|
|
||||||
|
|
||||||
LOCAL_MODULE_TAGS := optional
|
|
||||||
|
|
||||||
LOCAL_STATIC_JAVA_LIBRARIES := guava
|
|
||||||
|
|
||||||
# Only compile source java files in this apk.
|
|
||||||
LOCAL_SRC_FILES := $(call all-java-files-under, src)
|
|
||||||
|
|
||||||
LOCAL_PACKAGE_NAME := TagApp
|
|
||||||
|
|
||||||
# LOCAL_SDK_VERSION := current
|
|
||||||
|
|
||||||
LOCAL_PROGUARD_ENABLED := disabled
|
|
||||||
|
|
||||||
include $(BUILD_PACKAGE)
|
|
||||||
|
|
||||||
# Use the following include to make our test apk.
|
|
||||||
include $(call all-makefiles-under,$(LOCAL_PATH))
|
|
||||||
@@ -1,52 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<!-- 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.
|
|
||||||
-->
|
|
||||||
|
|
||||||
<!-- Declare the contents of this Android application. The namespace
|
|
||||||
attribute brings in the Android platform namespace, and the package
|
|
||||||
supplies a unique name for the application. When writing your
|
|
||||||
own application, the package name must be changed from "com.example.*"
|
|
||||||
to come from a domain that you own or have control over. -->
|
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
package="com.android.apps.tag"
|
|
||||||
>
|
|
||||||
|
|
||||||
<uses-permission android:name="com.trustedlogic.trustednfc.permission.NFC_NOTIFY" />
|
|
||||||
<uses-permission android:name="com.trustedlogic.trustednfc.permission.NFC_RAW" />
|
|
||||||
|
|
||||||
<application android:label="Tags">
|
|
||||||
<activity android:name="TagBrowserActivity"
|
|
||||||
android:icon="@drawable/ic_launcher_nfc"
|
|
||||||
android:theme="@android:style/Theme.NoTitleBar"
|
|
||||||
>
|
|
||||||
<intent-filter>
|
|
||||||
<action android:name="android.intent.action.MAIN"/>
|
|
||||||
<category android:name="android.intent.category.LAUNCHER"/>
|
|
||||||
</intent-filter>
|
|
||||||
</activity>
|
|
||||||
|
|
||||||
<activity android:name="TagList" />
|
|
||||||
|
|
||||||
<activity android:name="TagViewer"
|
|
||||||
android:theme="@android:style/Theme.Dialog"
|
|
||||||
>
|
|
||||||
<intent-filter>
|
|
||||||
<action android:name="android.nfc.action.NDEF_TAG_DISCOVERED"/>
|
|
||||||
<category android:name="android.intent.category.DEFAULT"/>
|
|
||||||
</intent-filter>
|
|
||||||
</activity>
|
|
||||||
|
|
||||||
</application>
|
|
||||||
</manifest>
|
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 4.8 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 4.9 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 4.2 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 2.7 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 1.4 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 2.5 KiB |
@@ -1,39 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<!--
|
|
||||||
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.
|
|
||||||
-->
|
|
||||||
|
|
||||||
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:id="@android:id/tabhost"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent">
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:orientation="vertical"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent">
|
|
||||||
|
|
||||||
<TabWidget
|
|
||||||
android:id="@android:id/tabs"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content" />
|
|
||||||
|
|
||||||
<FrameLayout
|
|
||||||
android:id="@android:id/tabcontent"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:padding="5dp" />
|
|
||||||
</LinearLayout>
|
|
||||||
</TabHost>
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<!--
|
|
||||||
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.
|
|
||||||
-->
|
|
||||||
|
|
||||||
<View xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:background="?android:attr/listDivider"
|
|
||||||
/>
|
|
||||||
@@ -1,40 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<!--
|
|
||||||
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.
|
|
||||||
-->
|
|
||||||
|
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:padding="4dip"
|
|
||||||
android:orientation="vertical"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content">
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/title"
|
|
||||||
android:padding="4dip"
|
|
||||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/date"
|
|
||||||
android:padding="4dip"
|
|
||||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
/>
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<!--
|
|
||||||
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.
|
|
||||||
-->
|
|
||||||
|
|
||||||
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:id="@+id/text"
|
|
||||||
android:padding="4dip"
|
|
||||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="?android:attr/listPreferredItemHeight"
|
|
||||||
android:singleLine="true"
|
|
||||||
android:gravity="center_vertical"
|
|
||||||
/>
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<!-- 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.
|
|
||||||
-->
|
|
||||||
|
|
||||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/list"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:orientation="vertical"
|
|
||||||
/>
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<!-- 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.
|
|
||||||
-->
|
|
||||||
|
|
||||||
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
|
||||||
<item
|
|
||||||
android:id="@+id/help_info_menu_item"
|
|
||||||
android:icon="@android:drawable/ic_menu_help"
|
|
||||||
android:title="@string/help_and_info" />
|
|
||||||
</menu>
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<!-- 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.
|
|
||||||
-->
|
|
||||||
|
|
||||||
<resources>
|
|
||||||
|
|
||||||
<string name="hello_activity_text_text">Hello, World!</string>
|
|
||||||
<string name="help_and_info">help and info</string>
|
|
||||||
<string name="saved">Saved</string>
|
|
||||||
|
|
||||||
<!-- The title of the tab that displays all recently scanned NFC tags -->
|
|
||||||
<string name="tab_recent">Recent</string>
|
|
||||||
|
|
||||||
<!-- The title of the tab that displays all saved NFC tags -->
|
|
||||||
<string name="tab_saved">Saved</string>
|
|
||||||
|
|
||||||
</resources>
|
|
||||||
@@ -1,224 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tags that we've seen in the field, for testing purposes.
|
|
||||||
*/
|
|
||||||
public class MockNdefMessages {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A real NFC tag containing an NFC "smart poster". This smart poster
|
|
||||||
* consists of the text "NFC Forum Type 4 Tag" in english combined with
|
|
||||||
* the URL "http://www.nxp.com/nfc"
|
|
||||||
*/
|
|
||||||
public static final byte[] REAL_NFC_MSG = new byte[] {
|
|
||||||
(byte) 0xd1, // MB=1 ME=1 CF=0 SR=1 IL=0 TNF=001
|
|
||||||
(byte) 0x02, // Type Length = 2
|
|
||||||
(byte) 0x2b, // Payload Length = 43
|
|
||||||
(byte) 0x53, (byte) 0x70, // Type = {'S', 'p'} (smart poster)
|
|
||||||
|
|
||||||
// begin smart poster payload
|
|
||||||
// begin smart poster record #1
|
|
||||||
(byte) 0x91, // MB=1 ME=0 CF=0 SR=1 IL=0 TNF=001
|
|
||||||
(byte) 0x01, // Type Length = 1
|
|
||||||
(byte) 0x17, // Payload Length = 23
|
|
||||||
(byte) 0x54, // Type = {'T'} (Text data)
|
|
||||||
(byte) 0x02, // UTF-8 encoding, language code length = 2
|
|
||||||
(byte) 0x65, (byte) 0x6e, // language = {'e', 'n'} (english)
|
|
||||||
|
|
||||||
// Begin text data within smart poster record #1
|
|
||||||
(byte) 0x4e, // 'N'
|
|
||||||
(byte) 0x46, // 'F'
|
|
||||||
(byte) 0x43, // 'C'
|
|
||||||
(byte) 0x20, // ' '
|
|
||||||
(byte) 0x46, // 'F'
|
|
||||||
(byte) 0x6f, // 'o'
|
|
||||||
(byte) 0x72, // 'r'
|
|
||||||
(byte) 0x75, // 'u'
|
|
||||||
(byte) 0x6d, // 'm'
|
|
||||||
(byte) 0x20, // ' '
|
|
||||||
(byte) 0x54, // 'T'
|
|
||||||
(byte) 0x79, // 'y'
|
|
||||||
(byte) 0x70, // 'p'
|
|
||||||
(byte) 0x65, // 'e'
|
|
||||||
(byte) 0x20, // ' '
|
|
||||||
(byte) 0x34, // '4'
|
|
||||||
(byte) 0x20, // ' '
|
|
||||||
(byte) 0x54, // 'T'
|
|
||||||
(byte) 0x61, // 'a'
|
|
||||||
(byte) 0x67, // 'g'
|
|
||||||
// end Text data within smart poster record #1
|
|
||||||
// end smart poster record #1
|
|
||||||
|
|
||||||
// begin smart poster record #2
|
|
||||||
(byte) 0x51, // MB=0 ME=1 CF=0 SR=1 IL=0 TNF=001
|
|
||||||
(byte) 0x01, // Type Length = 1
|
|
||||||
(byte) 0x0c, // Payload Length = 12
|
|
||||||
(byte) 0x55, // Type = { 'U' } (URI)
|
|
||||||
|
|
||||||
// begin URI data within smart poster record #2
|
|
||||||
(byte) 0x01, // URI Prefix = 1 ("http://www.")
|
|
||||||
(byte) 0x6e, // 'n'
|
|
||||||
(byte) 0x78, // 'x'
|
|
||||||
(byte) 0x70, // 'p'
|
|
||||||
(byte) 0x2e, // '.'
|
|
||||||
(byte) 0x63, // 'c'
|
|
||||||
(byte) 0x6f, // 'o'
|
|
||||||
(byte) 0x6d, // 'm'
|
|
||||||
(byte) 0x2f, // '/'
|
|
||||||
(byte) 0x6e, // 'n'
|
|
||||||
(byte) 0x66, // 'f'
|
|
||||||
(byte) 0x63 // 'c'
|
|
||||||
// end URI data within smart poster record #2
|
|
||||||
// end smart poster record #2
|
|
||||||
// end smart poster payload
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A Smart Poster containing a URL and no text. This message was created
|
|
||||||
* using the NXP reference phone.
|
|
||||||
*/
|
|
||||||
private static final byte[] SMART_POSTER_URL_NO_TEXT = new byte[] {
|
|
||||||
(byte) 0xd1, (byte) 0x02, (byte) 0x0f, (byte) 0x53, (byte) 0x70, (byte) 0xd1,
|
|
||||||
(byte) 0x01, (byte) 0x0b, (byte) 0x55, (byte) 0x01, (byte) 0x67, (byte) 0x6f,
|
|
||||||
(byte) 0x6f, (byte) 0x67, (byte) 0x6c, (byte) 0x65, (byte) 0x2e, (byte) 0x63,
|
|
||||||
(byte) 0x6f, (byte) 0x6d
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A plain text tag in english. Generated using the NXP evaluation tool.
|
|
||||||
*/
|
|
||||||
private static final byte[] ENGLISH_PLAIN_TEXT = new byte[] {
|
|
||||||
(byte) 0xd1, (byte) 0x01, (byte) 0x1c, (byte) 0x54, (byte) 0x02, (byte) 0x65,
|
|
||||||
(byte) 0x6e, (byte) 0x53, (byte) 0x6f, (byte) 0x6d, (byte) 0x65, (byte) 0x20,
|
|
||||||
(byte) 0x72, (byte) 0x61, (byte) 0x6e, (byte) 0x64, (byte) 0x6f, (byte) 0x6d,
|
|
||||||
(byte) 0x20, (byte) 0x65, (byte) 0x6e, (byte) 0x67, (byte) 0x6c, (byte) 0x69,
|
|
||||||
(byte) 0x73, (byte) 0x68, (byte) 0x20, (byte) 0x74, (byte) 0x65, (byte) 0x78,
|
|
||||||
(byte) 0x74, (byte) 0x2e
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Smart Poster containing a URL and Text. Generated using the NXP
|
|
||||||
* evaluation tool.
|
|
||||||
*/
|
|
||||||
private static final byte[] SMART_POSTER_URL_AND_TEXT = new byte[] {
|
|
||||||
(byte) 0xd1, (byte) 0x02, (byte) 0x1c, (byte) 0x53, (byte) 0x70, (byte) 0x91,
|
|
||||||
(byte) 0x01, (byte) 0x09, (byte) 0x54, (byte) 0x02, (byte) 0x65, (byte) 0x6e,
|
|
||||||
(byte) 0x47, (byte) 0x6f, (byte) 0x6f, (byte) 0x67, (byte) 0x6c, (byte) 0x65,
|
|
||||||
(byte) 0x51, (byte) 0x01, (byte) 0x0b, (byte) 0x55, (byte) 0x01, (byte) 0x67,
|
|
||||||
(byte) 0x6f, (byte) 0x6f, (byte) 0x67, (byte) 0x6c, (byte) 0x65, (byte) 0x2e,
|
|
||||||
(byte) 0x63, (byte) 0x6f, (byte) 0x6d
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A plain URI. Generated using the NXP evaluation tool.
|
|
||||||
*/
|
|
||||||
private static final byte[] URI = new byte[] {
|
|
||||||
(byte) 0xd1, (byte) 0x01, (byte) 0x0b, (byte) 0x55, (byte) 0x01, (byte) 0x67,
|
|
||||||
(byte) 0x6f, (byte) 0x6f, (byte) 0x67, (byte) 0x6c, (byte) 0x65, (byte) 0x2e,
|
|
||||||
(byte) 0x63, (byte) 0x6f, (byte) 0x6d
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A vcard. Generated using the NXP evaluation tool.
|
|
||||||
*/
|
|
||||||
private static final byte[] VCARD = new byte[] {
|
|
||||||
(byte) 0xc2, (byte) 0x0c, (byte) 0x00, (byte) 0x00, (byte) 0x01, (byte) 0x05,
|
|
||||||
(byte) 0x74, (byte) 0x65, (byte) 0x78, (byte) 0x74, (byte) 0x2f, (byte) 0x78,
|
|
||||||
(byte) 0x2d, (byte) 0x76, (byte) 0x43, (byte) 0x61, (byte) 0x72, (byte) 0x64,
|
|
||||||
(byte) 0x42, (byte) 0x45, (byte) 0x47, (byte) 0x49, (byte) 0x4e, (byte) 0x3a,
|
|
||||||
(byte) 0x56, (byte) 0x43, (byte) 0x41, (byte) 0x52, (byte) 0x44, (byte) 0x0d,
|
|
||||||
(byte) 0x0a, (byte) 0x56, (byte) 0x45, (byte) 0x52, (byte) 0x53, (byte) 0x49,
|
|
||||||
(byte) 0x4f, (byte) 0x4e, (byte) 0x3a, (byte) 0x33, (byte) 0x2e, (byte) 0x30,
|
|
||||||
(byte) 0x0d, (byte) 0x0a, (byte) 0x46, (byte) 0x4e, (byte) 0x3a, (byte) 0x4a,
|
|
||||||
(byte) 0x6f, (byte) 0x65, (byte) 0x20, (byte) 0x47, (byte) 0x6f, (byte) 0x6f,
|
|
||||||
(byte) 0x67, (byte) 0x6c, (byte) 0x65, (byte) 0x20, (byte) 0x45, (byte) 0x6d,
|
|
||||||
(byte) 0x70, (byte) 0x6c, (byte) 0x6f, (byte) 0x79, (byte) 0x65, (byte) 0x65,
|
|
||||||
(byte) 0x0d, (byte) 0x0a, (byte) 0x41, (byte) 0x44, (byte) 0x52, (byte) 0x3b,
|
|
||||||
(byte) 0x54, (byte) 0x59, (byte) 0x50, (byte) 0x45, (byte) 0x3d, (byte) 0x57,
|
|
||||||
(byte) 0x4f, (byte) 0x52, (byte) 0x4b, (byte) 0x3a, (byte) 0x3b, (byte) 0x3b,
|
|
||||||
(byte) 0x31, (byte) 0x36, (byte) 0x30, (byte) 0x30, (byte) 0x20, (byte) 0x41,
|
|
||||||
(byte) 0x6d, (byte) 0x70, (byte) 0x68, (byte) 0x69, (byte) 0x74, (byte) 0x68,
|
|
||||||
(byte) 0x65, (byte) 0x61, (byte) 0x74, (byte) 0x72, (byte) 0x65, (byte) 0x20,
|
|
||||||
(byte) 0x50, (byte) 0x61, (byte) 0x72, (byte) 0x6b, (byte) 0x77, (byte) 0x61,
|
|
||||||
(byte) 0x79, (byte) 0x3b, (byte) 0x39, (byte) 0x34, (byte) 0x30, (byte) 0x34,
|
|
||||||
(byte) 0x33, (byte) 0x20, (byte) 0x4d, (byte) 0x6f, (byte) 0x75, (byte) 0x6e,
|
|
||||||
(byte) 0x74, (byte) 0x61, (byte) 0x69, (byte) 0x6e, (byte) 0x20, (byte) 0x56,
|
|
||||||
(byte) 0x69, (byte) 0x65, (byte) 0x77, (byte) 0x0d, (byte) 0x0a, (byte) 0x54,
|
|
||||||
(byte) 0x45, (byte) 0x4c, (byte) 0x3b, (byte) 0x54, (byte) 0x59, (byte) 0x50,
|
|
||||||
(byte) 0x45, (byte) 0x3d, (byte) 0x50, (byte) 0x52, (byte) 0x45, (byte) 0x46,
|
|
||||||
(byte) 0x2c, (byte) 0x57, (byte) 0x4f, (byte) 0x52, (byte) 0x4b, (byte) 0x3a,
|
|
||||||
(byte) 0x36, (byte) 0x35, (byte) 0x30, (byte) 0x2d, (byte) 0x32, (byte) 0x35,
|
|
||||||
(byte) 0x33, (byte) 0x2d, (byte) 0x30, (byte) 0x30, (byte) 0x30, (byte) 0x30,
|
|
||||||
(byte) 0x0d, (byte) 0x0a, (byte) 0x45, (byte) 0x4d, (byte) 0x41, (byte) 0x49,
|
|
||||||
(byte) 0x4c, (byte) 0x3b, (byte) 0x54, (byte) 0x59, (byte) 0x50, (byte) 0x45,
|
|
||||||
(byte) 0x3d, (byte) 0x49, (byte) 0x4e, (byte) 0x54, (byte) 0x45, (byte) 0x52,
|
|
||||||
(byte) 0x4e, (byte) 0x45, (byte) 0x54, (byte) 0x3a, (byte) 0x73, (byte) 0x75,
|
|
||||||
(byte) 0x70, (byte) 0x70, (byte) 0x6f, (byte) 0x72, (byte) 0x74, (byte) 0x40,
|
|
||||||
(byte) 0x67, (byte) 0x6f, (byte) 0x6f, (byte) 0x67, (byte) 0x6c, (byte) 0x65,
|
|
||||||
(byte) 0x2e, (byte) 0x63, (byte) 0x6f, (byte) 0x6d, (byte) 0x0d, (byte) 0x0a,
|
|
||||||
(byte) 0x54, (byte) 0x49, (byte) 0x54, (byte) 0x4c, (byte) 0x45, (byte) 0x3a,
|
|
||||||
(byte) 0x53, (byte) 0x6f, (byte) 0x66, (byte) 0x74, (byte) 0x77, (byte) 0x61,
|
|
||||||
(byte) 0x72, (byte) 0x65, (byte) 0x20, (byte) 0x45, (byte) 0x6e, (byte) 0x67,
|
|
||||||
(byte) 0x69, (byte) 0x6e, (byte) 0x65, (byte) 0x65, (byte) 0x72, (byte) 0x0d,
|
|
||||||
(byte) 0x0a, (byte) 0x4f, (byte) 0x52, (byte) 0x47, (byte) 0x3a, (byte) 0x47,
|
|
||||||
(byte) 0x6f, (byte) 0x6f, (byte) 0x67, (byte) 0x6c, (byte) 0x65, (byte) 0x0d,
|
|
||||||
(byte) 0x0a, (byte) 0x55, (byte) 0x52, (byte) 0x4c, (byte) 0x3a, (byte) 0x68,
|
|
||||||
(byte) 0x74, (byte) 0x74, (byte) 0x70, (byte) 0x3a, (byte) 0x2f, (byte) 0x2f,
|
|
||||||
(byte) 0x77, (byte) 0x77, (byte) 0x77, (byte) 0x2e, (byte) 0x67, (byte) 0x6f,
|
|
||||||
(byte) 0x6f, (byte) 0x67, (byte) 0x6c, (byte) 0x65, (byte) 0x2e, (byte) 0x63,
|
|
||||||
(byte) 0x6f, (byte) 0x6d, (byte) 0x0d, (byte) 0x0a, (byte) 0x45, (byte) 0x4e,
|
|
||||||
(byte) 0x44, (byte) 0x3a, (byte) 0x56, (byte) 0x43, (byte) 0x41, (byte) 0x52,
|
|
||||||
(byte) 0x44, (byte) 0x0d, (byte) 0x0a
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Send the text message "hello world" to a phone number. This was generated using
|
|
||||||
* the NXP reference phone.
|
|
||||||
*/
|
|
||||||
private static final byte[] SEND_TEXT_MESSAGE = new byte[] {
|
|
||||||
(byte) 0xd1, (byte) 0x02, (byte) 0x25, (byte) 0x53, (byte) 0x70, (byte) 0xd1,
|
|
||||||
(byte) 0x01, (byte) 0x21, (byte) 0x55, (byte) 0x00, (byte) 0x73, (byte) 0x6d,
|
|
||||||
(byte) 0x73, (byte) 0x3a, (byte) 0x31, (byte) 0x36, (byte) 0x35, (byte) 0x30,
|
|
||||||
(byte) 0x32, (byte) 0x35, (byte) 0x33, (byte) 0x30, (byte) 0x30, (byte) 0x30,
|
|
||||||
(byte) 0x30, (byte) 0x3f, (byte) 0x62, (byte) 0x6f, (byte) 0x64, (byte) 0x79,
|
|
||||||
(byte) 0x3d, (byte) 0x48, (byte) 0x65, (byte) 0x6c, (byte) 0x6c, (byte) 0x6f,
|
|
||||||
(byte) 0x20, (byte) 0x77, (byte) 0x6f, (byte) 0x72, (byte) 0x6c, (byte) 0x64
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Call Google. Generated using the NXP reference phone.
|
|
||||||
*/
|
|
||||||
private static final byte[] CALL_GOOGLE = new byte[] {
|
|
||||||
(byte) 0xd1, (byte) 0x02, (byte) 0x10, (byte) 0x53, (byte) 0x70, (byte) 0xd1,
|
|
||||||
(byte) 0x01, (byte) 0x0c, (byte) 0x55, (byte) 0x05, (byte) 0x31, (byte) 0x36,
|
|
||||||
(byte) 0x35, (byte) 0x30, (byte) 0x32, (byte) 0x35, (byte) 0x33, (byte) 0x30,
|
|
||||||
(byte) 0x30, (byte) 0x30, (byte) 0x30
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* All the real ndef messages we've seen in the field.
|
|
||||||
*/
|
|
||||||
public static final byte[][] ALL_MOCK_MESSAGES = new byte[][] {
|
|
||||||
REAL_NFC_MSG, SMART_POSTER_URL_NO_TEXT, ENGLISH_PLAIN_TEXT,
|
|
||||||
SMART_POSTER_URL_AND_TEXT, URI, VCARD, SEND_TEXT_MESSAGE,
|
|
||||||
CALL_GOOGLE
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,55 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.net.Uri;
|
|
||||||
import android.nfc.NdefRecord;
|
|
||||||
|
|
||||||
import com.google.common.primitives.Bytes;
|
|
||||||
|
|
||||||
import java.nio.charset.Charsets;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Utilities for dealing with conversions to and from NdefRecords.
|
|
||||||
*
|
|
||||||
* TODO: Possibly move this class into core Android.
|
|
||||||
*/
|
|
||||||
public class NdefUtil {
|
|
||||||
private static final byte[] EMPTY = new byte[0];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new {@link NdefRecord} containing the supplied {@link Uri}.
|
|
||||||
*/
|
|
||||||
public static NdefRecord toUriRecord(Uri uri) {
|
|
||||||
byte[] uriBytes = uri.toString().getBytes(Charsets.UTF_8);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* We prepend 0x00 to the bytes of the URI to indicate that this
|
|
||||||
* is the entire URI, and we are not taking advantage of the
|
|
||||||
* URI shortening rules in the NFC Forum URI spec section 3.2.2.
|
|
||||||
* This produces a NdefRecord which is slightly larger than
|
|
||||||
* necessary.
|
|
||||||
*
|
|
||||||
* In the future, we should use the URI shortening rules in 3.2.2
|
|
||||||
* to create a smaller NdefRecord.
|
|
||||||
*/
|
|
||||||
byte[] payload = Bytes.concat(new byte[] { 0x00 }, uriBytes);
|
|
||||||
|
|
||||||
return new NdefRecord(NdefRecord.TNF_WELL_KNOWN,
|
|
||||||
NdefRecord.RTD_URI, EMPTY, payload);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,76 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.Context;
|
|
||||||
import android.database.Cursor;
|
|
||||||
import android.nfc.FormatException;
|
|
||||||
import android.nfc.NdefMessage;
|
|
||||||
import android.text.format.DateUtils;
|
|
||||||
import android.util.Log;
|
|
||||||
import android.view.LayoutInflater;
|
|
||||||
import android.view.View;
|
|
||||||
import android.view.ViewGroup;
|
|
||||||
import android.widget.Adapter;
|
|
||||||
import android.widget.CursorAdapter;
|
|
||||||
import android.widget.TextView;
|
|
||||||
|
|
||||||
import com.android.apps.tag.TagDBHelper.NdefMessagesTable;
|
|
||||||
import com.android.apps.tag.message.NdefMessageParser;
|
|
||||||
import com.android.apps.tag.message.ParsedNdefMessage;
|
|
||||||
|
|
||||||
import java.util.Locale;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A custom {@link Adapter} that renders tag entries for a list.
|
|
||||||
*/
|
|
||||||
public class TagAdapter extends CursorAdapter {
|
|
||||||
|
|
||||||
private final LayoutInflater mInflater;
|
|
||||||
|
|
||||||
public TagAdapter(Context context) {
|
|
||||||
super(context, null, false);
|
|
||||||
mInflater = LayoutInflater.from(context);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void bindView(View view, Context context, Cursor cursor) {
|
|
||||||
TextView mainLine = (TextView) view.findViewById(R.id.title);
|
|
||||||
TextView dateLine = (TextView) view.findViewById(R.id.date);
|
|
||||||
|
|
||||||
NdefMessage msg = null;
|
|
||||||
try {
|
|
||||||
msg = new NdefMessage(cursor.getBlob(cursor.getColumnIndex(NdefMessagesTable.BYTES)));
|
|
||||||
} catch (FormatException e) {
|
|
||||||
Log.e("foo", "poorly formatted message", e);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (msg == null) {
|
|
||||||
mainLine.setText("Invalid tag");
|
|
||||||
} else {
|
|
||||||
ParsedNdefMessage parsedMsg = NdefMessageParser.parse(msg);
|
|
||||||
mainLine.setText(parsedMsg.getSnippet(Locale.getDefault()));
|
|
||||||
}
|
|
||||||
dateLine.setText(DateUtils.getRelativeTimeSpanString(
|
|
||||||
context, cursor.getLong(cursor.getColumnIndex(NdefMessagesTable.DATE))));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public View newView(Context context, Cursor cursor, ViewGroup parent) {
|
|
||||||
return mInflater.inflate(R.layout.tag_list_item, null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,51 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.app.Activity;
|
|
||||||
import android.app.TabActivity;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.content.res.Resources;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.widget.TabHost;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A browsing {@link Activity} that displays the saved tags in categories under tabs.
|
|
||||||
*/
|
|
||||||
public class TagBrowserActivity extends TabActivity {
|
|
||||||
@Override
|
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
|
|
||||||
setContentView(R.layout.main);
|
|
||||||
|
|
||||||
Resources res = getResources();
|
|
||||||
TabHost tabHost = getTabHost();
|
|
||||||
|
|
||||||
TabHost.TabSpec spec1 = tabHost.newTabSpec("saved")
|
|
||||||
.setIndicator(getText(R.string.tab_saved), res.getDrawable(R.drawable.ic_menu_tag))
|
|
||||||
.setContent(new Intent().setClass(this, TagList.class)
|
|
||||||
.putExtra(TagList.EXTRA_SHOW_SAVED_ONLY, true));
|
|
||||||
tabHost.addTab(spec1);
|
|
||||||
|
|
||||||
TabHost.TabSpec spec2 = tabHost.newTabSpec("recent")
|
|
||||||
.setIndicator(getText(R.string.tab_recent), res.getDrawable(R.drawable.ic_menu_desk_clock))
|
|
||||||
.setContent(new Intent().setClass(this, TagList.class));
|
|
||||||
tabHost.addTab(spec2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,131 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.Context;
|
|
||||||
import android.database.sqlite.SQLiteDatabase;
|
|
||||||
import android.database.sqlite.SQLiteOpenHelper;
|
|
||||||
import android.database.sqlite.SQLiteStatement;
|
|
||||||
import android.net.Uri;
|
|
||||||
import android.nfc.FormatException;
|
|
||||||
import android.nfc.NdefMessage;
|
|
||||||
import android.nfc.NdefRecord;
|
|
||||||
|
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Database utilities for the saved tags.
|
|
||||||
*/
|
|
||||||
public class TagDBHelper extends SQLiteOpenHelper {
|
|
||||||
|
|
||||||
private static final String DATABASE_NAME = "tags.db";
|
|
||||||
private static final int DATABASE_VERSION = 3;
|
|
||||||
|
|
||||||
public interface NdefMessagesTable {
|
|
||||||
public static final String TABLE_NAME = "nedf_msg";
|
|
||||||
|
|
||||||
public static final String _ID = "_id";
|
|
||||||
public static final String TITLE = "title";
|
|
||||||
public static final String BYTES = "bytes";
|
|
||||||
public static final String DATE = "date";
|
|
||||||
public static final String SAVED = "saved";
|
|
||||||
}
|
|
||||||
|
|
||||||
private static TagDBHelper sInstance;
|
|
||||||
|
|
||||||
public static synchronized TagDBHelper getInstance(Context context) {
|
|
||||||
if (sInstance == null) {
|
|
||||||
sInstance = new TagDBHelper(context.getApplicationContext());
|
|
||||||
}
|
|
||||||
return sInstance;
|
|
||||||
}
|
|
||||||
|
|
||||||
private TagDBHelper(Context context) {
|
|
||||||
this(context, DATABASE_NAME);
|
|
||||||
}
|
|
||||||
|
|
||||||
@VisibleForTesting
|
|
||||||
TagDBHelper(Context context, String dbFile) {
|
|
||||||
super(context, dbFile, null, DATABASE_VERSION);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCreate(SQLiteDatabase db) {
|
|
||||||
db.execSQL("CREATE TABLE " + NdefMessagesTable.TABLE_NAME + " (" +
|
|
||||||
NdefMessagesTable._ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
|
|
||||||
NdefMessagesTable.TITLE + " TEXT NOT NULL DEFAULT ''," +
|
|
||||||
NdefMessagesTable.BYTES + " BLOB NOT NULL, " +
|
|
||||||
NdefMessagesTable.DATE + " INTEGER NOT NULL, " +
|
|
||||||
NdefMessagesTable.SAVED + " INTEGER NOT NULL DEFAULT 0" + // boolean
|
|
||||||
");");
|
|
||||||
|
|
||||||
db.execSQL("CREATE INDEX msgIndex ON " + NdefMessagesTable.TABLE_NAME + " (" +
|
|
||||||
NdefMessagesTable.DATE + " DESC, " +
|
|
||||||
NdefMessagesTable.SAVED + " ASC" +
|
|
||||||
")");
|
|
||||||
|
|
||||||
addTestData(db);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
|
|
||||||
// Drop everything and recreate it for now
|
|
||||||
db.execSQL("DROP TABLE IF EXISTS " + NdefMessagesTable.TABLE_NAME);
|
|
||||||
onCreate(db);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void addTestData(SQLiteDatabase db) {
|
|
||||||
// A fake message containing 1 URL
|
|
||||||
NdefMessage msg1 = new NdefMessage(new NdefRecord[] {
|
|
||||||
NdefUtil.toUriRecord(Uri.parse("http://www.google.com"))
|
|
||||||
});
|
|
||||||
|
|
||||||
// A fake message containing 2 URLs
|
|
||||||
NdefMessage msg2 = new NdefMessage(new NdefRecord[] {
|
|
||||||
NdefUtil.toUriRecord(Uri.parse("http://www.youtube.com")),
|
|
||||||
NdefUtil.toUriRecord(Uri.parse("http://www.android.com"))
|
|
||||||
});
|
|
||||||
|
|
||||||
insertNdefMessage(db, msg1, false);
|
|
||||||
insertNdefMessage(db, msg2, true);
|
|
||||||
|
|
||||||
try {
|
|
||||||
// insert some real messages we found in the field.
|
|
||||||
for (byte[] msg : MockNdefMessages.ALL_MOCK_MESSAGES) {
|
|
||||||
NdefMessage msg3 = new NdefMessage(msg);
|
|
||||||
insertNdefMessage(db, msg3, false);
|
|
||||||
}
|
|
||||||
} catch (FormatException e) {
|
|
||||||
throw new RuntimeException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void insertNdefMessage(SQLiteDatabase db, NdefMessage msg, boolean isSaved) {
|
|
||||||
SQLiteStatement stmt = null;
|
|
||||||
try {
|
|
||||||
stmt = db.compileStatement("INSERT INTO " + NdefMessagesTable.TABLE_NAME +
|
|
||||||
"(" + NdefMessagesTable.BYTES + ", " + NdefMessagesTable.DATE + ", " +
|
|
||||||
NdefMessagesTable.SAVED + ") values (?, ?, ?)");
|
|
||||||
stmt.bindBlob(1, msg.toByteArray());
|
|
||||||
stmt.bindLong(2, System.currentTimeMillis());
|
|
||||||
stmt.bindLong(3, isSaved ? 1 : 0);
|
|
||||||
stmt.executeInsert();
|
|
||||||
} finally {
|
|
||||||
if (stmt != null) stmt.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,132 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.app.Activity;
|
|
||||||
import android.app.AlertDialog;
|
|
||||||
import android.app.Dialog;
|
|
||||||
import android.app.ListActivity;
|
|
||||||
import android.content.DialogInterface;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.database.Cursor;
|
|
||||||
import android.database.sqlite.SQLiteDatabase;
|
|
||||||
import android.nfc.FormatException;
|
|
||||||
import android.nfc.NdefMessage;
|
|
||||||
import android.os.AsyncTask;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.util.Log;
|
|
||||||
import android.view.Menu;
|
|
||||||
import android.view.View;
|
|
||||||
import android.widget.ListView;
|
|
||||||
|
|
||||||
import com.android.apps.tag.TagDBHelper.NdefMessagesTable;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* An {@link Activity} that displays a flat list of tags that can be "opened".
|
|
||||||
*/
|
|
||||||
public class TagList extends ListActivity implements DialogInterface.OnClickListener {
|
|
||||||
static final String TAG = "TagList";
|
|
||||||
|
|
||||||
static final String EXTRA_SHOW_SAVED_ONLY = "show_saved_only";
|
|
||||||
|
|
||||||
SQLiteDatabase mDatabase;
|
|
||||||
TagAdapter mAdapter;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
|
|
||||||
boolean showSavedOnly = getIntent().getBooleanExtra(EXTRA_SHOW_SAVED_ONLY, false);
|
|
||||||
mDatabase = TagDBHelper.getInstance(this).getReadableDatabase();
|
|
||||||
String selection = showSavedOnly ? NdefMessagesTable.SAVED + "=1" : null;
|
|
||||||
|
|
||||||
new TagLoaderTask().execute(selection);
|
|
||||||
mAdapter = new TagAdapter(this);
|
|
||||||
setListAdapter(mAdapter);
|
|
||||||
registerForContextMenu(getListView());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onCreateOptionsMenu(Menu menu) {
|
|
||||||
super.onCreateOptionsMenu(menu);
|
|
||||||
menu.add("hello world");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Dialog onCreateDialog(int id, Bundle args) {
|
|
||||||
String[] stuff = new String[] { "a", "b" };
|
|
||||||
return new AlertDialog.Builder(this)
|
|
||||||
.setTitle("blah")
|
|
||||||
.setItems(stuff, this)
|
|
||||||
.setPositiveButton("Delete", null)
|
|
||||||
.setNegativeButton("Cancel", null)
|
|
||||||
.create();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onDestroy() {
|
|
||||||
if (mAdapter != null) {
|
|
||||||
mAdapter.changeCursor(null);
|
|
||||||
}
|
|
||||||
super.onDestroy();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onListItemClick(ListView l, View v, int position, long id) {
|
|
||||||
Cursor cursor = mAdapter.getCursor();
|
|
||||||
cursor.moveToPosition(position);
|
|
||||||
byte[] tagBytes = cursor.getBlob(cursor.getColumnIndexOrThrow(NdefMessagesTable.BYTES));
|
|
||||||
try {
|
|
||||||
NdefMessage msg = new NdefMessage(tagBytes);
|
|
||||||
Intent intent = new Intent(this, TagViewer.class);
|
|
||||||
intent.putExtra(TagViewer.EXTRA_MESSAGE, msg);
|
|
||||||
intent.putExtra(TagViewer.EXTRA_TAG_DB_ID, id);
|
|
||||||
startActivity(intent);
|
|
||||||
} catch (FormatException e) {
|
|
||||||
Log.e(TAG, "bad format for tag " + id + ": " + tagBytes, e);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
|
||||||
}
|
|
||||||
|
|
||||||
final class TagLoaderTask extends AsyncTask<String, Void, Cursor> {
|
|
||||||
@Override
|
|
||||||
public Cursor doInBackground(String... args) {
|
|
||||||
String selection = args[0];
|
|
||||||
Cursor cursor = mDatabase.query(
|
|
||||||
NdefMessagesTable.TABLE_NAME,
|
|
||||||
new String[] {
|
|
||||||
NdefMessagesTable._ID,
|
|
||||||
NdefMessagesTable.BYTES,
|
|
||||||
NdefMessagesTable.DATE,
|
|
||||||
NdefMessagesTable.TITLE },
|
|
||||||
selection,
|
|
||||||
null, null, null, null);
|
|
||||||
cursor.getCount();
|
|
||||||
return cursor;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onPostExecute(Cursor cursor) {
|
|
||||||
mAdapter.changeCursor(cursor);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,122 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.app.Activity;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.database.sqlite.SQLiteDatabase;
|
|
||||||
import android.graphics.Color;
|
|
||||||
import android.nfc.NdefMessage;
|
|
||||||
import android.nfc.NdefTag;
|
|
||||||
import android.nfc.NfcAdapter;
|
|
||||||
import android.os.AsyncTask;
|
|
||||||
import android.util.Log;
|
|
||||||
import android.view.ContextThemeWrapper;
|
|
||||||
import android.view.LayoutInflater;
|
|
||||||
import android.view.WindowManager;
|
|
||||||
import android.widget.LinearLayout;
|
|
||||||
import android.widget.TextView;
|
|
||||||
|
|
||||||
import com.android.apps.tag.message.NdefMessageParser;
|
|
||||||
import com.android.apps.tag.message.ParsedNdefMessage;
|
|
||||||
|
|
||||||
import java.util.Locale;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* An {@link Activity} which handles a broadcast of a new tag that the device just discovered.
|
|
||||||
*/
|
|
||||||
public class TagViewer extends Activity {
|
|
||||||
static final String TAG = "SaveTag";
|
|
||||||
static final String EXTRA_TAG_DB_ID = "db_id";
|
|
||||||
static final String EXTRA_MESSAGE = "msg";
|
|
||||||
|
|
||||||
long mTagDatabaseId;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onStart() {
|
|
||||||
super.onStart();
|
|
||||||
|
|
||||||
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
|
|
||||||
| WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
|
|
||||||
| WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
|
|
||||||
| WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
|
|
||||||
| WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON
|
|
||||||
| WindowManager.LayoutParams.FLAG_DIM_BEHIND
|
|
||||||
);
|
|
||||||
|
|
||||||
Intent intent = getIntent();
|
|
||||||
NdefMessage[] msgs = null;
|
|
||||||
NdefTag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
|
|
||||||
if (tag == null) {
|
|
||||||
// Maybe it came from the database?
|
|
||||||
mTagDatabaseId = intent.getLongExtra(EXTRA_TAG_DB_ID, -1);
|
|
||||||
NdefMessage msg = intent.getParcelableExtra(EXTRA_MESSAGE);
|
|
||||||
if (msg != null) {
|
|
||||||
msgs = new NdefMessage[] { msg };
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
msgs = tag.getNdefMessages();
|
|
||||||
// TODO use a service to avoid the process getting reaped during saving
|
|
||||||
new SaveTagTask().execute(msgs);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (msgs == null || msgs.length == 0) {
|
|
||||||
Log.e(TAG, "No NDEF messages");
|
|
||||||
finish();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
LayoutInflater inflater = LayoutInflater.from(
|
|
||||||
new ContextThemeWrapper(this, android.R.style.Theme_Light));
|
|
||||||
LinearLayout list = (LinearLayout) inflater.inflate(R.layout.tag_viewer_list, null, false);
|
|
||||||
// TODO figure out why the background isn't white, the CTW should force that...
|
|
||||||
list.setBackgroundColor(Color.WHITE);
|
|
||||||
setContentView(list);
|
|
||||||
buildTagViews(list, inflater, msgs);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void buildTagViews(LinearLayout list, LayoutInflater inflater, NdefMessage[] msgs) {
|
|
||||||
// The body of the dialog should use the light theme
|
|
||||||
|
|
||||||
// Build the views from the logical records in the messages
|
|
||||||
for (NdefMessage msg : msgs) {
|
|
||||||
ParsedNdefMessage parsedMsg = NdefMessageParser.parse(msg);
|
|
||||||
TextView text = (TextView) inflater.inflate(R.layout.tag_text, list, false);
|
|
||||||
text.setText(parsedMsg.getSnippet(Locale.getDefault()));
|
|
||||||
list.addView(text);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final class SaveTagTask extends AsyncTask<NdefMessage, Void, Void> {
|
|
||||||
@Override
|
|
||||||
public Void doInBackground(NdefMessage... msgs) {
|
|
||||||
TagDBHelper helper = TagDBHelper.getInstance(TagViewer.this);
|
|
||||||
SQLiteDatabase db = helper.getWritableDatabase();
|
|
||||||
db.beginTransaction();
|
|
||||||
try {
|
|
||||||
for (NdefMessage msg : msgs) {
|
|
||||||
helper.insertNdefMessage(db, msg, false);
|
|
||||||
}
|
|
||||||
db.setTransactionSuccessful();
|
|
||||||
} finally {
|
|
||||||
db.endTransaction();
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,37 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.message;
|
|
||||||
|
|
||||||
import java.util.Locale;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A parsed message containing no elements.
|
|
||||||
*/
|
|
||||||
class EmptyMessage implements ParsedNdefMessage {
|
|
||||||
|
|
||||||
/* package private */ EmptyMessage() { }
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getSnippet(Locale locale) {
|
|
||||||
return "Empty Tag"; // TODO: localize
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isStarred() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,76 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.message;
|
|
||||||
|
|
||||||
import android.nfc.NdefMessage;
|
|
||||||
import android.nfc.NdefRecord;
|
|
||||||
|
|
||||||
import com.android.apps.tag.record.ParsedNdefRecord;
|
|
||||||
import com.android.apps.tag.record.SmartPoster;
|
|
||||||
import com.android.apps.tag.record.TextRecord;
|
|
||||||
import com.android.apps.tag.record.UriRecord;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Utility class for creating {@link ParsedNdefMessage}s.
|
|
||||||
*/
|
|
||||||
public class NdefMessageParser {
|
|
||||||
|
|
||||||
// Utility class
|
|
||||||
private NdefMessageParser() { }
|
|
||||||
|
|
||||||
/** Parse an NdefMessage */
|
|
||||||
public static ParsedNdefMessage parse(NdefMessage message) {
|
|
||||||
List<ParsedNdefRecord> elements = getRecords(message);
|
|
||||||
|
|
||||||
if (elements.isEmpty()) {
|
|
||||||
return new EmptyMessage();
|
|
||||||
}
|
|
||||||
|
|
||||||
ParsedNdefRecord first = elements.get(0);
|
|
||||||
|
|
||||||
if (elements.size() == 1) {
|
|
||||||
if (first instanceof SmartPoster) {
|
|
||||||
return new SmartPosterMessage((SmartPoster) first);
|
|
||||||
}
|
|
||||||
if (first instanceof TextRecord) {
|
|
||||||
return new TextMessage((TextRecord) first);
|
|
||||||
}
|
|
||||||
if (first instanceof UriRecord) {
|
|
||||||
return new UriMessage((UriRecord) first);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return new UnknownMessage(elements);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<ParsedNdefRecord> getRecords(NdefMessage message) {
|
|
||||||
List<ParsedNdefRecord> elements = new ArrayList<ParsedNdefRecord>();
|
|
||||||
for (NdefRecord record : message.getRecords()) {
|
|
||||||
if (UriRecord.isUri(record)) {
|
|
||||||
elements.add(UriRecord.parse(record));
|
|
||||||
} else if (TextRecord.isText(record)) {
|
|
||||||
elements.add(TextRecord.parse(record));
|
|
||||||
} else if (SmartPoster.isPoster(record)) {
|
|
||||||
elements.add(SmartPoster.parse(record));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return elements;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.message;
|
|
||||||
|
|
||||||
import java.util.Locale;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A parsed version of an {@link android.nfc.NdefMessage}
|
|
||||||
*/
|
|
||||||
public interface ParsedNdefMessage {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the snippet information associated with the NdefMessage
|
|
||||||
* most appropriate for the given {@code locale}.
|
|
||||||
*/
|
|
||||||
public String getSnippet(Locale locale);
|
|
||||||
|
|
||||||
// TODO: Determine if this is the best place for holding whether
|
|
||||||
// the user has starred this parsed message.
|
|
||||||
public boolean isStarred();
|
|
||||||
}
|
|
||||||
@@ -1,48 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.message;
|
|
||||||
|
|
||||||
import com.android.apps.tag.record.SmartPoster;
|
|
||||||
import com.android.apps.tag.record.TextRecord;
|
|
||||||
import com.google.common.base.Preconditions;
|
|
||||||
|
|
||||||
import java.util.Locale;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A message consisting of one {@link SmartPoster} object.
|
|
||||||
*/
|
|
||||||
class SmartPosterMessage implements ParsedNdefMessage {
|
|
||||||
private final SmartPoster mPoster;
|
|
||||||
|
|
||||||
SmartPosterMessage(SmartPoster poster) {
|
|
||||||
mPoster = Preconditions.checkNotNull(poster);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getSnippet(Locale locale) {
|
|
||||||
TextRecord title = mPoster.getTitle();
|
|
||||||
if (title == null) {
|
|
||||||
return mPoster.getUriRecord().getUri().toString();
|
|
||||||
}
|
|
||||||
return title.getText();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isStarred() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,43 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.message;
|
|
||||||
|
|
||||||
import com.android.apps.tag.record.TextRecord;
|
|
||||||
import com.google.common.base.Preconditions;
|
|
||||||
|
|
||||||
import java.util.Locale;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A message containing one text element
|
|
||||||
*/
|
|
||||||
class TextMessage implements ParsedNdefMessage {
|
|
||||||
private final TextRecord mRecord;
|
|
||||||
|
|
||||||
TextMessage(TextRecord record) {
|
|
||||||
mRecord = Preconditions.checkNotNull(record);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getSnippet(Locale locale) {
|
|
||||||
return mRecord.getText();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isStarred() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,45 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.message;
|
|
||||||
|
|
||||||
import com.android.apps.tag.record.ParsedNdefRecord;
|
|
||||||
import com.google.common.collect.ImmutableList;
|
|
||||||
|
|
||||||
import java.util.Locale;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The catchall parsed message format for when nothing else better applies.
|
|
||||||
*/
|
|
||||||
class UnknownMessage implements ParsedNdefMessage {
|
|
||||||
|
|
||||||
private final ImmutableList<ParsedNdefRecord> mRecords;
|
|
||||||
|
|
||||||
UnknownMessage(Iterable<ParsedNdefRecord> records) {
|
|
||||||
mRecords = ImmutableList.copyOf(records);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getSnippet(Locale locale) {
|
|
||||||
// TODO: localize
|
|
||||||
return "Unknown record type with " + mRecords.size() + " elements.";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isStarred() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,45 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.message;
|
|
||||||
|
|
||||||
import com.android.apps.tag.record.UriRecord;
|
|
||||||
import com.google.common.base.Preconditions;
|
|
||||||
|
|
||||||
import java.util.Locale;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A {@link ParsedNdefMessage} consisting of one {@link UriRecord}.
|
|
||||||
*/
|
|
||||||
class UriMessage implements ParsedNdefMessage {
|
|
||||||
|
|
||||||
private final UriRecord mRecord;
|
|
||||||
|
|
||||||
UriMessage(UriRecord record) {
|
|
||||||
mRecord = Preconditions.checkNotNull(record);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getSnippet(Locale locale) {
|
|
||||||
// URIs cannot be localized
|
|
||||||
return mRecord.getUri().toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isStarred() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.record;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* TODO: come up with a better name.
|
|
||||||
*/
|
|
||||||
public interface ParsedNdefRecord {
|
|
||||||
|
|
||||||
// Just a placeholder for now. Probably not needed nor desired.
|
|
||||||
public String getRecordType();
|
|
||||||
}
|
|
||||||
@@ -1,108 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.record;
|
|
||||||
|
|
||||||
import android.nfc.FormatException;
|
|
||||||
import android.nfc.NdefMessage;
|
|
||||||
import android.nfc.NdefRecord;
|
|
||||||
|
|
||||||
import com.android.apps.tag.message.NdefMessageParser;
|
|
||||||
import com.google.common.base.Preconditions;
|
|
||||||
import com.google.common.collect.Iterables;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.NoSuchElementException;
|
|
||||||
import javax.annotation.Nullable;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A representation of an NFC Forum "Smart Poster".
|
|
||||||
*/
|
|
||||||
public class SmartPoster implements ParsedNdefRecord {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* NFC Forum Smart Poster Record Type Definition section 3.2.1.
|
|
||||||
*
|
|
||||||
* "The Title record for the service (there can be many of these in
|
|
||||||
* different languages, but a language MUST NOT be repeated).
|
|
||||||
* This record is optional."
|
|
||||||
|
|
||||||
*/
|
|
||||||
private final TextRecord mTitleRecord;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* NFC Forum Smart Poster Record Type Definition section 3.2.1.
|
|
||||||
*
|
|
||||||
* "The URI record. This is the core of the Smart Poster, and all other
|
|
||||||
* records are just metadata about this record. There MUST be one URI
|
|
||||||
* record and there MUST NOT be more than one."
|
|
||||||
*/
|
|
||||||
private final UriRecord mUriRecord;
|
|
||||||
|
|
||||||
private SmartPoster(UriRecord uri, @Nullable TextRecord title) {
|
|
||||||
mUriRecord = Preconditions.checkNotNull(uri);
|
|
||||||
mTitleRecord = title;
|
|
||||||
}
|
|
||||||
|
|
||||||
public UriRecord getUriRecord() {
|
|
||||||
return mUriRecord;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the title of the smart poster. This may be {@code null}.
|
|
||||||
*/
|
|
||||||
public TextRecord getTitle() {
|
|
||||||
return mTitleRecord;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static SmartPoster parse(NdefRecord record) {
|
|
||||||
Preconditions.checkArgument(record.getTnf() == NdefRecord.TNF_WELL_KNOWN);
|
|
||||||
Preconditions.checkArgument(Arrays.equals(record.getType(), NdefRecord.RTD_SMART_POSTER));
|
|
||||||
try {
|
|
||||||
NdefMessage subRecords = new NdefMessage(record.getPayload());
|
|
||||||
|
|
||||||
Iterable<ParsedNdefRecord> records = NdefMessageParser.getRecords(subRecords);
|
|
||||||
|
|
||||||
UriRecord uri = Iterables.getOnlyElement(Iterables.filter(records, UriRecord.class));
|
|
||||||
Iterable<TextRecord> textFields = Iterables.filter(records, TextRecord.class);
|
|
||||||
|
|
||||||
TextRecord title = null;
|
|
||||||
if (!Iterables.isEmpty(textFields)) {
|
|
||||||
title = Iterables.get(textFields, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new SmartPoster(uri, title);
|
|
||||||
} catch (FormatException e) {
|
|
||||||
throw new IllegalArgumentException(e);
|
|
||||||
} catch (NoSuchElementException e) {
|
|
||||||
throw new IllegalArgumentException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isPoster(NdefRecord record) {
|
|
||||||
try {
|
|
||||||
parse(record);
|
|
||||||
return true;
|
|
||||||
} catch (IllegalArgumentException e) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getRecordType() {
|
|
||||||
return "SmartPoster";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,104 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.record;
|
|
||||||
|
|
||||||
import android.nfc.NdefRecord;
|
|
||||||
|
|
||||||
import com.google.common.base.Preconditions;
|
|
||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* An NFC Text Record
|
|
||||||
*/
|
|
||||||
public class TextRecord implements ParsedNdefRecord {
|
|
||||||
|
|
||||||
/** ISO/IANA language code */
|
|
||||||
private final String mLanguageCode;
|
|
||||||
private final String mText;
|
|
||||||
|
|
||||||
private TextRecord(String languageCode, String text) {
|
|
||||||
mLanguageCode = Preconditions.checkNotNull(languageCode);
|
|
||||||
mText = Preconditions.checkNotNull(text);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getRecordType() {
|
|
||||||
return "Text";
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getText() {
|
|
||||||
return mText;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the ISO/IANA language code associated with this text element.
|
|
||||||
*
|
|
||||||
* TODO: this should return a {@link java.util.Locale}
|
|
||||||
*/
|
|
||||||
public String getLanguageCode() {
|
|
||||||
return mLanguageCode;
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: deal with text fields which span multiple NdefRecords
|
|
||||||
public static TextRecord parse(NdefRecord record) {
|
|
||||||
Preconditions.checkArgument(record.getTnf() == NdefRecord.TNF_WELL_KNOWN);
|
|
||||||
Preconditions.checkArgument(Arrays.equals(record.getType(), NdefRecord.RTD_TEXT));
|
|
||||||
try {
|
|
||||||
|
|
||||||
byte[] payload = record.getPayload();
|
|
||||||
|
|
||||||
/*
|
|
||||||
* payload[0] contains the "Status Byte Encodings" field, per
|
|
||||||
* the NFC Forum "Text Record Type Definition" section 3.2.1.
|
|
||||||
*
|
|
||||||
* bit7 is the Text Encoding Field.
|
|
||||||
*
|
|
||||||
* if (Bit_7 == 0): The text is encoded in UTF-8
|
|
||||||
* if (Bit_7 == 1): The text is encoded in UTF16
|
|
||||||
*
|
|
||||||
* Bit_6 is reserved for future use and must be set to zero.
|
|
||||||
*
|
|
||||||
* Bits 5 to 0 are the length of the IANA language code.
|
|
||||||
*/
|
|
||||||
|
|
||||||
String textEncoding = ((payload[0] & 0200) == 0) ? "UTF-8" : "UTF-16";
|
|
||||||
int languageCodeLength = payload[0] & 0077;
|
|
||||||
|
|
||||||
String languageCode = new String(payload, 1, languageCodeLength, "US-ASCII");
|
|
||||||
String text = new String(payload,
|
|
||||||
languageCodeLength + 1,
|
|
||||||
payload.length - languageCodeLength - 1,
|
|
||||||
textEncoding);
|
|
||||||
return new TextRecord(languageCode, text);
|
|
||||||
|
|
||||||
} catch (UnsupportedEncodingException e) {
|
|
||||||
// should never happen unless we get a malformed tag.
|
|
||||||
throw new IllegalArgumentException(e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isText(NdefRecord record) {
|
|
||||||
try {
|
|
||||||
parse(record);
|
|
||||||
return true;
|
|
||||||
} catch (IllegalArgumentException e) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,136 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.record;
|
|
||||||
|
|
||||||
import android.net.Uri;
|
|
||||||
import android.nfc.NdefRecord;
|
|
||||||
|
|
||||||
import com.google.common.base.Preconditions;
|
|
||||||
import com.google.common.collect.BiMap;
|
|
||||||
import com.google.common.collect.ImmutableBiMap;
|
|
||||||
import com.google.common.primitives.Bytes;
|
|
||||||
|
|
||||||
import java.nio.charset.Charsets;
|
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A parsed record containing a Uri.
|
|
||||||
*/
|
|
||||||
public class UriRecord implements ParsedNdefRecord {
|
|
||||||
private static final byte[] EMPTY = new byte[0];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* NFC Forum "URI Record Type Definition"
|
|
||||||
*
|
|
||||||
* This is a mapping of "URI Identifier Codes" to URI string prefixes,
|
|
||||||
* per section 3.2.2 of the NFC Forum URI Record Type Definition document.
|
|
||||||
*/
|
|
||||||
private static final BiMap<Byte, String> URI_PREFIX_MAP = ImmutableBiMap.<Byte, String>builder()
|
|
||||||
.put((byte) 0x00, "")
|
|
||||||
.put((byte) 0x01, "http://www.")
|
|
||||||
.put((byte) 0x02, "https://www.")
|
|
||||||
.put((byte) 0x03, "http://")
|
|
||||||
.put((byte) 0x04, "https://")
|
|
||||||
.put((byte) 0x05, "tel:")
|
|
||||||
.put((byte) 0x06, "mailto:")
|
|
||||||
.put((byte) 0x07, "ftp://anonymous:anonymous@")
|
|
||||||
.put((byte) 0x08, "ftp://ftp.")
|
|
||||||
.put((byte) 0x09, "ftps://")
|
|
||||||
.put((byte) 0x0A, "sftp://")
|
|
||||||
.put((byte) 0x0B, "smb://")
|
|
||||||
.put((byte) 0x0C, "nfs://")
|
|
||||||
.put((byte) 0x0D, "ftp://")
|
|
||||||
.put((byte) 0x0E, "dav://")
|
|
||||||
.put((byte) 0x0F, "news:")
|
|
||||||
.put((byte) 0x10, "telnet://")
|
|
||||||
.put((byte) 0x11, "imap:")
|
|
||||||
.put((byte) 0x12, "rtsp://")
|
|
||||||
.put((byte) 0x13, "urn:")
|
|
||||||
.put((byte) 0x14, "pop:")
|
|
||||||
.put((byte) 0x15, "sip:")
|
|
||||||
.put((byte) 0x16, "sips:")
|
|
||||||
.put((byte) 0x17, "tftp:")
|
|
||||||
.put((byte) 0x18, "btspp://")
|
|
||||||
.put((byte) 0x19, "btl2cap://")
|
|
||||||
.put((byte) 0x1A, "btgoep://")
|
|
||||||
.put((byte) 0x1B, "tcpobex://")
|
|
||||||
.put((byte) 0x1C, "irdaobex://")
|
|
||||||
.put((byte) 0x1D, "file://")
|
|
||||||
.put((byte) 0x1E, "urn:epc:id:")
|
|
||||||
.put((byte) 0x1F, "urn:epc:tag:")
|
|
||||||
.put((byte) 0x20, "urn:epc:pat:")
|
|
||||||
.put((byte) 0x21, "urn:epc:raw:")
|
|
||||||
.put((byte) 0x22, "urn:epc:")
|
|
||||||
.put((byte) 0x23, "urn:nfc:")
|
|
||||||
.build();
|
|
||||||
|
|
||||||
private final Uri mUri;
|
|
||||||
|
|
||||||
private UriRecord(Uri uri) {
|
|
||||||
this.mUri = Preconditions.checkNotNull(uri);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getRecordType() {
|
|
||||||
return "Uri";
|
|
||||||
}
|
|
||||||
|
|
||||||
public Uri getUri() {
|
|
||||||
return mUri;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Convert {@link android.nfc.NdefRecord} into a {@link android.net.Uri}.
|
|
||||||
*
|
|
||||||
* TODO: This class does not handle NdefRecords where the TNF
|
|
||||||
* (Type Name Format) of the class is {@link android.nfc.NdefRecord#TNF_ABSOLUTE_URI}.
|
|
||||||
* This should be fixed.
|
|
||||||
*
|
|
||||||
* @throws IllegalArgumentException if the NdefRecord is not a
|
|
||||||
* record containing a URI.
|
|
||||||
*/
|
|
||||||
public static UriRecord parse(NdefRecord record) {
|
|
||||||
Preconditions.checkArgument(record.getTnf() == NdefRecord.TNF_WELL_KNOWN);
|
|
||||||
Preconditions.checkArgument(Arrays.equals(record.getType(), NdefRecord.RTD_URI));
|
|
||||||
|
|
||||||
byte[] payload = record.getPayload();
|
|
||||||
|
|
||||||
/*
|
|
||||||
* payload[0] contains the URI Identifier Code, per the
|
|
||||||
* NFC Forum "URI Record Type Definition" section 3.2.2.
|
|
||||||
*
|
|
||||||
* payload[1]...payload[payload.length - 1] contains the rest of
|
|
||||||
* the URI.
|
|
||||||
*/
|
|
||||||
|
|
||||||
String prefix = URI_PREFIX_MAP.get(payload[0]);
|
|
||||||
byte[] fullUri = Bytes.concat(
|
|
||||||
prefix.getBytes(Charsets.UTF_8),
|
|
||||||
Arrays.copyOfRange(payload, 1, payload.length));
|
|
||||||
|
|
||||||
return new UriRecord(Uri.parse(new String(fullUri, Charsets.UTF_8)));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isUri(NdefRecord record) {
|
|
||||||
try {
|
|
||||||
parse(record);
|
|
||||||
return true;
|
|
||||||
} catch (IllegalArgumentException e) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
LOCAL_PATH:= $(call my-dir)
|
|
||||||
include $(CLEAR_VARS)
|
|
||||||
|
|
||||||
LOCAL_SRC_FILES := $(call all-subdir-java-files)
|
|
||||||
|
|
||||||
LOCAL_JAVA_LIBRARIES := android.test.runner
|
|
||||||
|
|
||||||
LOCAL_PACKAGE_NAME := TagAppTests
|
|
||||||
|
|
||||||
LOCAL_MODULE_TAGS := tests
|
|
||||||
|
|
||||||
LOCAL_INSTRUMENTATION_FOR := TagApp
|
|
||||||
|
|
||||||
include $(BUILD_PACKAGE)
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<!-- 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.
|
|
||||||
-->
|
|
||||||
|
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
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,
|
|
||||||
which is needed when building test cases. -->
|
|
||||||
<application>
|
|
||||||
<uses-library android:name="android.test.runner" />
|
|
||||||
</application>
|
|
||||||
|
|
||||||
<instrumentation android:name="android.test.InstrumentationTestRunner"
|
|
||||||
android:targetPackage="com.android.apps.tag"
|
|
||||||
android:label="Tag tests">
|
|
||||||
</instrumentation>
|
|
||||||
|
|
||||||
</manifest>
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
tested.project.dir=..
|
|
||||||
@@ -1,53 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.nfc.NdefRecord;
|
|
||||||
import android.test.AndroidTestCase;
|
|
||||||
|
|
||||||
import com.android.apps.tag.record.TextRecord;
|
|
||||||
import com.google.common.primitives.Bytes;
|
|
||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
|
|
||||||
public class NdefUtilTest extends AndroidTestCase {
|
|
||||||
public void testToText() throws UnsupportedEncodingException {
|
|
||||||
checkWord("Hello", "en-US", true);
|
|
||||||
checkWord("Hello", "en-US", false);
|
|
||||||
checkWord("abc\\u5639\\u563b", "cp1251", true);
|
|
||||||
checkWord("abc\\u5639\\u563b", "cp1251", false);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void checkWord(String word, String encoding, boolean isUtf8) throws UnsupportedEncodingException {
|
|
||||||
String utfEncoding = isUtf8 ? "UTF-8" : "UTF-16";
|
|
||||||
|
|
||||||
byte[] encodingBytes = encoding.getBytes("US-ASCII");
|
|
||||||
byte[] text = word.getBytes(utfEncoding);
|
|
||||||
|
|
||||||
int utfBit = isUtf8 ? 0 : (1 << 7);
|
|
||||||
char status = (char) (utfBit + encodingBytes.length);
|
|
||||||
|
|
||||||
byte[] data = Bytes.concat(
|
|
||||||
new byte[] { (byte) status },
|
|
||||||
encodingBytes,
|
|
||||||
text
|
|
||||||
);
|
|
||||||
|
|
||||||
NdefRecord record = new NdefRecord(NdefRecord.TNF_WELL_KNOWN, NdefRecord.RTD_TEXT, new byte[0], data);
|
|
||||||
assertEquals(word, TextRecord.parse(record).getText());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.nfc.NdefMessage;
|
|
||||||
import android.test.AndroidTestCase;
|
|
||||||
|
|
||||||
import com.android.apps.tag.record.SmartPoster;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests for {@link SmartPoster}.
|
|
||||||
*/
|
|
||||||
public class SmartPosterTest extends AndroidTestCase {
|
|
||||||
public void testSmartPoster() throws Exception {
|
|
||||||
NdefMessage msg = new NdefMessage(MockNdefMessages.REAL_NFC_MSG);
|
|
||||||
|
|
||||||
SmartPoster poster = SmartPoster.parse(msg.getRecords()[0]);
|
|
||||||
assertEquals("NFC Forum Type 4 Tag", poster.getTitle().getText());
|
|
||||||
assertEquals("http://www.nxp.com/nfc", poster.getUriRecord().getUri().toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,41 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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.test.ActivityInstrumentationTestCase2;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Make sure that the main launcher activity opens up properly, which will be
|
|
||||||
* verified by {@link #testActivityTestCaseSetUpProperly}.
|
|
||||||
*/
|
|
||||||
public class TagsTest extends ActivityInstrumentationTestCase2<TagBrowserActivity> {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates an {@link ActivityInstrumentationTestCase2} for the
|
|
||||||
* {@link TagBrowserActivity} activity.
|
|
||||||
*/
|
|
||||||
public TagsTest() {
|
|
||||||
super(TagBrowserActivity.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Verifies that the activity under test can be launched.
|
|
||||||
*/
|
|
||||||
public void testActivityTestCaseSetUpProperly() {
|
|
||||||
assertNotNull("activity should be launched successfully", getActivity());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user