Gut the Tags app.
Bug: 5048185
Change-Id: I6f3ecd6d89b1146cf6b82733a56da7ce37fcf9b2
diff --git a/Android.mk b/Android.mk
index d054c0c..7b2447b 100644
--- a/Android.mk
+++ b/Android.mk
@@ -12,7 +12,4 @@
#LOCAL_SDK_VERSION := current
-include $(BUILD_PACKAGE)
-
-# Use the following include to make our test apk.
-include $(call all-makefiles-under,$(LOCAL_PATH))
+include $(BUILD_PACKAGE)
\ No newline at end of file
diff --git a/res/layout/edit_tag_activity.xml b/res/layout/edit_tag_activity.xml
deleted file mode 100644
index 703980d..0000000
--- a/res/layout/edit_tag_activity.xml
+++ /dev/null
@@ -1,55 +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:orientation="vertical"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
->
-
- <ScrollView
- android:id="@+id/content_parent"
- android:layout_weight="1.0"
- android:layout_width="match_parent"
- android:layout_height="0dip" />
-
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_alignParentBottom="true"
-
- android:orientation="horizontal"
- style="@android:style/ButtonBar"
- >
- <Button
- android:id="@+id/save"
- android:text="@string/button_save"
- android:layout_weight="1"
- android:layout_width="match_parent"
- android:layout_height="wrap_content" />
-
- <Button
- android:id="@+id/cancel"
- android:text="@string/button_cancel"
- android:layout_weight="1"
- android:layout_width="match_parent"
- android:layout_height="wrap_content" />
-
- </LinearLayout>
-
-</LinearLayout>
diff --git a/res/layout/intro_to_nfc.xml b/res/layout/intro_to_nfc.xml
deleted file mode 100644
index be893a4..0000000
--- a/res/layout/intro_to_nfc.xml
+++ /dev/null
@@ -1,116 +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:orientation="vertical"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
->
-
- <TextView
- android:text="@string/intro_title"
- android:padding="4dip"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:textAppearance="?android:attr/textAppearanceMedium"
- android:gravity="center"
- />
-
- <!-- TODO: make the layout more flexible instead of a fixed size. -->
- <ScrollView
- android:layout_weight="1"
- android:layout_width="280dip"
- android:layout_height="355dip"
- >
- <FrameLayout
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- >
- <LinearLayout
- android:id="@+id/page_1"
- style="@style/about_page"
- android:orientation="vertical"
- >
- <TextView
- android:text="@string/intro_text_about"
- style="@style/about_text"
- />
-
- <ImageView
- android:src="@drawable/tag_scan_illustration"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_gravity="center_horizontal"
- />
-
- <TextView
- android:text="@string/intro_text_usage"
- style="@style/about_text"
- />
- </LinearLayout>
-
- <LinearLayout
- android:id="@+id/page_2"
- style="@style/about_page"
- android:orientation="vertical"
- >
- <TextView
- android:text="@string/intro_text_contents"
- style="@style/about_text"
- android:layout_marginBottom="16dip"
- />
-
- <TextView
- android:text="@string/intro_text_more"
- style="@style/about_text"
- android:layout_marginBottom="16dip"
- />
-
- <TextView
- android:text="@string/intro_text_more2"
- style="@style/about_text"
- />
- </LinearLayout>
-
- </FrameLayout>
- </ScrollView>
-
- <LinearLayout
- android:padding="4dip"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- >
-
- <Button
- android:id="@+id/back"
- android:text="@string/back"
- android:layout_width="0dip"
- android:layout_height="match_parent"
- android:layout_weight="0.5"
- />
-
- <Button
- android:id="@+id/next"
- android:text="@string/next"
- android:layout_width="0dip"
- android:layout_height="match_parent"
- android:layout_weight="0.5"
- />
- </LinearLayout>
-
-</LinearLayout>
diff --git a/res/layout/main.xml b/res/layout/main.xml
deleted file mode 100644
index 3880a3a..0000000
--- a/res/layout/main.xml
+++ /dev/null
@@ -1,38 +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" />
- </LinearLayout>
-</TabHost>
diff --git a/res/layout/my_tag_activity.xml b/res/layout/my_tag_activity.xml
deleted file mode 100644
index d7e2800..0000000
--- a/res/layout/my_tag_activity.xml
+++ /dev/null
@@ -1,151 +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:orientation="vertical"
- android:layout_width="match_parent"
- android:layout_height="match_parent">
-
- <!-- The touch target for enabling/disabling "My Tag". -->
- <RelativeLayout
- android:id="@+id/toggle_enabled_target"
- android:padding="8dip"
- android:focusable="true"
- android:focusableInTouchMode="true"
- android:orientation="horizontal"
- android:layout_width="match_parent"
- android:layout_height="wrap_content">
-
- <!-- The checkbox simply presents state to the user - its parent
- is the real click target -->
- <CheckBox android:id="@+id/toggle_enabled_checkbox"
- android:layout_marginRight="4dip"
- android:focusable="false"
- android:focusableInTouchMode="false"
- android:clickable="false"
- android:layout_gravity="center_vertical"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content" />
-
- <TextView
- android:id="@+id/toggle_enabled_hint_title"
- android:text="@string/turn_on_my_tag"
- android:textAppearance="?android:attr/textAppearanceMedium"
- android:layout_toRightOf="@+id/toggle_enabled_checkbox"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content" />
-
- <TextView
- android:text="@string/turn_on_my_tag_subtitle"
- android:textAppearance="?android:attr/textAppearanceSmall"
- android:layout_toRightOf="@+id/toggle_enabled_checkbox"
- android:layout_below="@+id/toggle_enabled_hint_title"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content" />
- </RelativeLayout>
-
- <TextView
- android:text="@string/active_tag"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- style="?android:attr/listSeparatorTextViewStyle"
- />
-
- <!-- Currently selected tag -->
- <FrameLayout
- android:id="@+id/active_tag"
- android:padding="8dip"
- android:layout_width="match_parent"
- android:layout_height="wrap_content">
-
- <RelativeLayout
- android:id="@+id/active_tag_details"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- >
-
- <TextView
- android:id="@+id/active_tag_title"
- android:textAppearance="?android:attr/textAppearanceMedium"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content" />
-
- <TextView
- android:text="@string/choose_my_tag"
- android:textAppearance="?android:attr/textAppearanceSmall"
- android:layout_below="@+id/active_tag_title"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content" />
-
- </RelativeLayout>
-
- <TextView
- android:id="@+id/choose_my_tag"
- android:text="@string/choose_my_tag"
- android:textAppearance="?android:attr/textAppearanceMedium"
- android:layout_gravity="center_vertical"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- />
- </FrameLayout>
-
- <TextView
- android:text="@string/manage_my_tags"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- style="?android:attr/listSeparatorTextViewStyle"
- />
-
- <!-- Tag list. -->
- <ListView
- android:id="@android:id/list"
- android:layout_weight="1"
- android:layout_width="match_parent"
- android:layout_height="0dip"
- />
-
- <!-- Control to add new tag. -->
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:orientation="horizontal"
- style="@android:style/ButtonBar"
- >
-
- <View
- android:layout_height="0dip"
- android:layout_width="0dip"
- android:layout_weight="1"
- />
-
- <Button
- android:id="@+id/add_tag"
- android:layout_width="0dip"
- android:layout_height="wrap_content"
- android:layout_weight="2"
- android:text="@string/add_tag"
- />
-
- <View
- android:layout_height="0dip"
- android:layout_width="0dip"
- android:layout_weight="1"
- />
- </LinearLayout>
-</LinearLayout>
-
diff --git a/res/layout/tag_add_record_list_item.xml b/res/layout/tag_add_record_list_item.xml
deleted file mode 100644
index a900f30..0000000
--- a/res/layout/tag_add_record_list_item.xml
+++ /dev/null
@@ -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:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:minHeight="?android:attr/listPreferredItemHeight"
- android:padding="4dip"
- android:gravity="center" >
-
- <ImageView
- android:id="@+id/image"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginRight="12dip"
- />
-
- <TextView
- android:id="@+id/text"
- android:layout_weight="1"
- android:layout_width="0dip"
- android:layout_height="wrap_content"
- android:textAppearance="?android:attr/textAppearanceMedium"
- />
-
-</LinearLayout>
diff --git a/res/layout/tag_content_selector.xml b/res/layout/tag_content_selector.xml
deleted file mode 100644
index 0503417..0000000
--- a/res/layout/tag_content_selector.xml
+++ /dev/null
@@ -1,31 +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.
--->
-
-<!-- Main content selector list. Populated by code. -->
-<ScrollView
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="0dip"
- android:layout_weight="1">
-
- <LinearLayout android:id="@+id/list"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:orientation="vertical"
- />
-
-</ScrollView>
-
diff --git a/res/layout/tag_edit_image.xml b/res/layout/tag_edit_image.xml
deleted file mode 100644
index b924fc0..0000000
--- a/res/layout/tag_edit_image.xml
+++ /dev/null
@@ -1,36 +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.
--->
-
-<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:padding="8dip"
- android:layout_width="match_parent"
- android:layout_height="wrap_content">
-
- <TextView
- android:id="@+id/title"
- android:text="@string/photo"
- style="@style/record_title"
- android:layout_alignParentTop="true"
- />
-
- <ImageView
- android:id="@+id/image"
- android:layout_below="@+id/title"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- />
-</RelativeLayout>
diff --git a/res/layout/tag_edit_text.xml b/res/layout/tag_edit_text.xml
deleted file mode 100644
index c316e16..0000000
--- a/res/layout/tag_edit_text.xml
+++ /dev/null
@@ -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.
--->
-
-<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:padding="8dip"
- android:layout_width="match_parent"
- android:layout_height="wrap_content">
-
- <TextView
- android:id="@+id/title"
- android:text="@string/tag_text"
- style="@style/record_title"
- android:layout_alignParentTop="true"
- />
-
- <EditText
- android:id="@+id/value"
- android:inputType="textShortMessage|textCapSentences"
- android:layout_below="@+id/title"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- />
-</RelativeLayout>
-
-
diff --git a/res/layout/tag_edit_url.xml b/res/layout/tag_edit_url.xml
deleted file mode 100644
index 568735b..0000000
--- a/res/layout/tag_edit_url.xml
+++ /dev/null
@@ -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.
--->
-
-<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:padding="8dip"
- android:layout_width="match_parent"
- android:layout_height="wrap_content">
-
- <TextView
- android:id="@+id/title"
- android:text="@string/url"
- style="@style/record_title"
- android:layout_alignParentTop="true"
- />
-
- <EditText
- android:id="@+id/value"
- android:inputType="textUri"
- android:layout_below="@+id/title"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- />
-</RelativeLayout>
-
-
diff --git a/res/layout/tag_edit_vcard.xml b/res/layout/tag_edit_vcard.xml
deleted file mode 100644
index 90e8d86..0000000
--- a/res/layout/tag_edit_vcard.xml
+++ /dev/null
@@ -1,50 +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.
--->
-
-<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:padding="8dip"
- android:layout_width="match_parent"
- android:layout_height="wrap_content">
-
- <TextView
- android:id="@+id/title"
- android:text="@string/contact"
- style="@style/record_title"
- android:layout_alignParentTop="true"
- />
-
- <LinearLayout
- android:orientation="horizontal"
- android:gravity="center_vertical"
- android:layout_below="@+id/title"
- android:layout_width="match_parent"
- android:layout_height="wrap_content">
-
- <ImageView
- android:id="@+id/photo"
- android:layout_marginRight="8dip"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- />
-
- <TextView
- android:id="@+id/display_name"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- />
- </LinearLayout>
-</RelativeLayout>
diff --git a/res/layout/tag_list.xml b/res/layout/tag_list.xml
deleted file mode 100644
index 64e485d..0000000
--- a/res/layout/tag_list.xml
+++ /dev/null
@@ -1,55 +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.
--->
-
-<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
->
-
- <ListView android:id="@android:id/list"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- />
-
- <LinearLayout android:id="@android:id/empty"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_gravity="center"
-
- android:orientation="vertical"
- >
-
- <TextView android:id="@+id/text"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
-
- android:textAppearance="?android:attr/textAppearanceMedium"
- android:gravity="center"
- />
-
- <Button android:id="@+id/more_info"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_gravity="center_horizontal"
- android:layout_marginTop="16dip"
-
- android:text="@string/button_more_info"
- />
-
- </LinearLayout>
-
-</FrameLayout>
\ No newline at end of file
diff --git a/res/layout/tag_list_item.xml b/res/layout/tag_list_item.xml
deleted file mode 100644
index 4f5f559..0000000
--- a/res/layout/tag_list_item.xml
+++ /dev/null
@@ -1,57 +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">
-
- <RelativeLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content">
-
- <ImageView
- android:id="@+id/active_tag_icon"
- android:src="@drawable/active_tag_icon"
- android:padding="4dip"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_centerVertical="true"
- android:visibility="gone"
- />
-
- <TextView
- android:id="@+id/title"
- android:padding="4dip"
- android:textAppearance="?android:attr/textAppearanceMedium"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_toRightOf="@+id/active_tag_icon"
- android:singleLine="true"
- />
- </RelativeLayout>
-
- <TextView
- android:id="@+id/date"
- android:padding="4dip"
- android:textAppearance="?android:attr/textAppearanceSmall"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- />
-</LinearLayout>
-
diff --git a/res/layout/tag_viewer.xml b/res/layout/tag_viewer.xml
index 6ec7739..7a7f917 100644
--- a/res/layout/tag_viewer.xml
+++ b/res/layout/tag_viewer.xml
@@ -22,10 +22,11 @@
>
<!-- Title -->
- <RelativeLayout
+ <LinearLayout
android:layout_width="match_parent"
android:layout_height="65dip"
+ android:orientation="horizontal"
android:background="@drawable/title_bar_medium"
>
@@ -33,53 +34,26 @@
android:layout_width="32dip"
android:layout_height="32dip"
android:layout_centerVertical="true"
- android:layout_alignParentLeft="true"
android:layout_marginRight="4dip"
- />
- <CheckBox android:id="@+id/star"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_centerVertical="true"
- android:layout_alignParentRight="true"
-
- style="?android:attr/starStyle"
- />
-
- <TextView android:id="@+id/date"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_toRightOf="@id/icon"
- android:layout_toLeftOf="@id/star"
- android:layout_alignParentBottom="true"
- android:layout_marginBottom="8dip"
- android:layout_marginTop="-8dip"
-
- android:singleLine="true"
- android:textAppearance="?android:attr/textAppearanceSmall"
- android:shadowColor="#BB000000"
- android:shadowRadius="2.75"
+ android:src="@drawable/ic_launcher_nfc"
/>
<TextView android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:layout_toRightOf="@id/icon"
- android:layout_toLeftOf="@id/star"
- android:layout_above="@id/date"
- android:layout_alignParentTop="true"
- android:layout_alignWithParentIfMissing="true"
+ android:layout_centerVertical="true"
+ android:layout_marginLeft="8dip"
android:singleLine="true"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="bold"
android:shadowColor="#BB000000"
android:shadowRadius="2.75"
- android:gravity="center_vertical"
+
+ android:text="@string/title_scanned_tag"
/>
-
-
- </RelativeLayout>
+ </LinearLayout>
<!-- Content -->
@@ -116,14 +90,6 @@
android:text="@string/button_done"
/>
- <Button android:id="@+id/button_delete"
- android:layout_width="0dip"
- android:layout_height="wrap_content"
- android:layout_weight="1"
-
- android:text="@string/button_delete"
- />
-
</LinearLayout>
</LinearLayout>
\ No newline at end of file
diff --git a/res/layout/write_tag.xml b/res/layout/write_tag.xml
deleted file mode 100644
index fc4ea53..0000000
--- a/res/layout/write_tag.xml
+++ /dev/null
@@ -1,59 +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:orientation="vertical"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
->
- <TextView android:id="@+id/title"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_marginTop="8dip"
-
- android:gravity="center_horizontal"
- android:textAppearance="?android:attr/textAppearanceLarge"
- />
-
- <ImageView
- android:layout_width="match_parent"
- android:layout_height="0dip"
- android:layout_weight="1"
-
- android:src="@drawable/ic_launcher_nfc"
- android:gravity="center"
- android:scaleType="center"
- />
-
- <TextView android:id="@+id/count"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
-
- android:gravity="center_horizontal"
- android:textAppearance="?android:attr/textAppearanceMedium"
- />
-
- <TextView android:id="@+id/status"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_marginBottom="16dip"
-
- android:gravity="center_horizontal"
- android:textAppearance="?android:attr/textAppearanceMedium"
- />
-</LinearLayout>
-
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 5ef6a53..afca58c 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -19,21 +19,9 @@
<!-- The title of the NFC tag application -->
<string name="app_name">Tags</string>
- <!-- The title for the activity that shows a tag that was just scanned -->
- <string name="title_scanned_tag">New tag collected</string>
-
<!-- The title for the activity that shows a tag that was stored from a past scan -->
<string name="title_existing_tag">Tag</string>
- <!-- The title of the tab that displays all recently scanned NFC tags -->
- <string name="tab_tags">Tags</string>
-
- <!-- The title of the tab that displays all starred NFC tags -->
- <string name="tab_starred">Starred</string>
-
- <!-- The title of the tab that displays the editor for the device's local tag -->
- <string name="tab_my_tag">My tag</string>
-
<!-- The title displayed for unknown tag types -->
<string name="tag_unknown">Unknown tag type</string>
@@ -41,166 +29,24 @@
<string name="tag_empty">Empty tag</string>
<!-- Button label indicating that the user wants to delete a tag -->
- <string name="button_delete">Delete</string>
-
- <!-- Button label indicating that the user wants to delete a tag -->
<string name="button_done">Done</string>
- <!-- Button label indicating that the user wants to save a tag -->
- <string name="button_save">Save</string>
-
- <!-- Button label indicating that the user wants to cancel editing a tag -->
- <string name="button_cancel">Cancel</string>
-
- <!-- String describing that if the user doesn't want to save a tag they should touch the button labeled Cancel. The text for the cancel button comes from the system string button_done. -->
- <string name="cancel_help_text">To skip adding this tag to your collection, touch Done</string>
-
<!-- String displayed for an action to send a text message to a phone number -->
<string name="action_text">Text <xliff:g id="phone_number">%s</xliff:g></string>
<!-- String displayed for an action to call a phone number -->
<string name="action_call">Call <xliff:g id="phone_number">%s</xliff:g></string>
- <!-- Label for control which enables/disables the "my tag" feature. -->
- <string name="turn_on_my_tag">Share my tag</string>
-
- <!-- Label for activity which edits a tag to share/write [CHAR LIMIT=60] -->
- <string name="edit_tag">Edit tag</string>
-
- <!-- Description for the control which enables/disables the "my tag" feature. -->
- <string name="turn_on_my_tag_subtitle">Allow others to read my tag </string>
-
- <!-- Label for control which adds content to the "my tag" feature. -->
- <string name="add_content">More…</string>
-
- <!-- Heading for the title of the content in the "my tag" feature. -->
- <string name="tag_title">Title</string>
-
- <!-- Heading for the text of the content in the "my tag" feature. -->
- <string name="tag_text">Text</string>
-
- <!-- Heading for dialog presented for selecting content to write to tag -->
- <string name="select_type">Select type to add</string>
-
- <!-- Title for image type for writing content to a tag -->
- <string name="photo">Photo</string>
-
- <!-- Error message when a selected photo could not be loaded -->
- <string name="bad_photo">Could not open image.</string>
-
- <!-- Title for URL type for writing content to a tag -->
- <string name="url">URL</string>
-
- <!-- Title for contact type for writing content to a tag -->
- <string name="contact">Contact</string>
-
- <!-- Title for address type for writing content to a tag -->
- <string name="location">Location</string>
-
<!-- Message for prompting on an empty tag -->
<string name="empty_tag_prompt">This tag is empty.</string>
- <!-- Instructions for a prompt on an empty tag -->
- <string name="empty_tag_instructions">Touch <b>Write tag</b> to add content.</string>
-
- <!-- Affirmative button label for writing to an empty tag -->
- <string name="write">Write tag</string>
-
- <!-- Negative button label for writing to an empty tag -->
- <string name="cancel">Cancel</string>
-
- <!-- Menu label for help screen -->
- <string name="menu_help">Help</string>
-
<!-- Action description indicating the user can import a scanned vCard -->
<string name="import_vcard">Import ^1</string>
<!-- String describing MIME content when it's shared with other application -->
<string name="mime_display_name">Data from NFC tag</string>
- <!-- Title of a dialog presented to the user when they launch the Tag app with the NFC hardware disabled. -->
- <string name="dialog_title_nfc_off">NFC turned off</string>
-
- <!-- Dialog text telling the user they must turn on the NFC hardware to be able to scan tags -->
- <string name="dialog_text_nfc_off">You must turn on NFC to scan tags.</string>
-
- <!-- Button that takes the user to the settings panel so they can enable the NFC hardware -->
- <string name="button_settings">Settings</string>
-
- <!-- Text shown in the list view when there are no tags present -->
- <string name="empty_list">You have not scanned any tags.</string>
-
- <!-- Text shown in the list of starred tags when there are no starred tags present -->
- <string name="empty_list_starred">You have no starred tags.</string>
-
- <!-- Button taking the user to more information about tags and how they work -->
- <string name="button_more_info">More info</string>
-
- <!-- URL for the help topic that provides more info on tags -->
- <string name="more_info_url" translatable="false">http://www.google.com/support/mobile/bin/topic.py?hl=%locale%&topic=27236</string>
-
<!-- Description string for vCard messages -->
<string name="vcard_title">Contact info for ^1</string>
- <!-- Button label for going next in the introductory tutorial -->
- <string name="next">Next</string>
-
- <!-- Button label for going back in the introductory tutorial -->
- <string name="back">Back</string>
-
- <!-- Button label for going closing introductory tutorial -->
- <string name="close">Close</string>
-
- <!-- Title for the introductory dialog. -->
- <string name="intro_title">About Tags</string>
-
- <!-- Text blurb for describing the app in an introductory flow. [CHAR LIMIT=160] -->
- <string name="intro_text_about">Tags is for organizing and sharing Near Field Communication (NFC) tags.</string>
-
- <!-- Text blurb for describing usage of the app in an introductory flow. [CHAR LIMIT=120]-->
- <string name="intro_text_usage">You scan a tag by turning on your phone and placing it right next to a tag.</string>
-
- <!-- Text blurb for describing tag contents in an introductory flow. [CHAR LIMIT=240]-->
- <string name="intro_text_contents">NFC tags can contain text, URLs, pictures, and other kinds of information.</string>
-
- <!-- Text blurb for more information an introductory flow. [CHAR LIMIT=120]-->
- <string name="intro_text_more">To scan or share tags, you must have NFC turned on (in Settings, under Wireless &
-Networks).</string>
-
- <!-- Text blurb for more information an introductory flow. [CHAR LIMIT=120]-->
- <string name="intro_text_more2">For more information, press Menu and touch Help on any Tags screen.</string>
-
- <!-- Popup text for confirming the deletion of a tag -->
- <string name="tag_deleted">Tag deleted</string>
-
- <!-- Anchor text for touch target for creating a new My tag. [CHAR LIMIT=50] -->
- <string name="add_tag">Add new tag</string>
-
- <!-- Anchor text for touch target for selecting a tag to share as My tag. [CHAR LIMIT=50] -->
- <string name="choose_my_tag">Choose a tag to share</string>
-
- <!-- Active tag header for My tag [CHAR LIMIT=50] -->
- <string name="active_tag">Active tag</string>
-
- <!-- Header for list of tags that can be set as My tag. [CHAR LIMIT=50] -->
- <string name="manage_my_tags">Manage my tags</string>
-
- <!-- Menu item indicating that the user wants to delete a tag. [CHAR LIMIT=50] -->
- <string name="menu_delete">Delete tag</string>
-
- <!-- Menu item indicating that the user wants to edit a tag. [CHAR LIMIT=50] -->
- <string name="menu_edit">Edit tag</string>
-
- <!-- Menu item indicating that the user wants to set a tag
- as the active tag to share as the device's tag. [CHAR LIMIT=50] -->
- <string name="menu_set_as_active">Set as active tag</string>
-
- <!-- Error message displayed when attempting to enable sharing of a "My tag"
- with no tag selected. [CHAR LIMIT=80] -->
- <string name="no_tag_selected">You do not have a tag selected to share.</string>
-
- <!-- Error message displayed when attempting to select an active tag when
- none have been created. [CHAR LIMIT=80] -->
- <string name="no_tags_created">You have no tags created.</string>
-
</resources>
diff --git a/src/com/android/apps/tag/AboutActivity.java b/src/com/android/apps/tag/AboutActivity.java
deleted file mode 100644
index 468b77f..0000000
--- a/src/com/android/apps/tag/AboutActivity.java
+++ /dev/null
@@ -1,89 +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.os.Bundle;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.View.OnClickListener;
-import android.widget.Button;
-
-/**
- * Dialog with introductory text blurbs and pictures explaining NFC.
- */
-public class AboutActivity extends Activity implements OnClickListener {
-
- private int mPage;
- private View[] mPageContainers;
- private Button mBack;
- private Button mNext;
-
- @Override
- protected void onCreate(Bundle savedInstance) {
- super.onCreate(savedInstance);
-
- LayoutInflater inflater = LayoutInflater.from(this);
- setContentView(inflater.inflate(R.layout.intro_to_nfc, null));
-
- mPageContainers = new View[2];
- mPageContainers[0] = findViewById(R.id.page_1);
- mPageContainers[1] = findViewById(R.id.page_2);
-
- mBack = (Button) findViewById(R.id.back);
- mNext = (Button) findViewById(R.id.next);
-
- mBack.setOnClickListener(this);
- mNext.setOnClickListener(this);
-
- mPage = -1;
- navigate(0);
- }
-
- private void navigate(int page) {
- if (mPage == page) {
- return;
- }
-
- if (page >= mPageContainers.length) {
- finish();
- return;
- }
-
- mPage = page;
- for (int i = 0, len = mPageContainers.length; i < len; i++) {
- View view = mPageContainers[i];
- view.setVisibility((i == page) ? View.VISIBLE : View.GONE);
- }
-
- mBack.setEnabled((mPage == 0) ? false : true);
-
- if (mPage < mPageContainers.length - 1) {
- mNext.setText(getResources().getString(R.string.next));
- } else {
- mNext.setText(getResources().getString(R.string.close));
- }
- }
-
- @Override
- public void onClick(View view) {
- if (view == mBack) {
- navigate(mPage - 1);
- } else if (view == mNext) {
- navigate(mPage + 1);
- }
- }
-}
diff --git a/src/com/android/apps/tag/ContentSelectorAdapter.java b/src/com/android/apps/tag/ContentSelectorAdapter.java
deleted file mode 100644
index ac78a7c..0000000
--- a/src/com/android/apps/tag/ContentSelectorAdapter.java
+++ /dev/null
@@ -1,94 +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 com.android.apps.tag.record.TextRecord;
-import com.android.apps.tag.record.UriRecord;
-import com.android.apps.tag.record.VCardRecord;
-
-import android.content.Context;
-import android.nfc.NdefRecord;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.Adapter;
-import android.widget.BaseAdapter;
-import android.widget.ListView;
-
-/**
- * An {@link Adapter} that presents options to select data which can be written into a
- * {@link NdefRecord} for an NFC tag.
- */
-public class ContentSelectorAdapter extends BaseAdapter {
- private Context mContext;
- private final LayoutInflater mInflater;
- private String[] mSupportedTypes;
- private View[] mViews;
-
- public ContentSelectorAdapter(Context context, String[] supportedTypes) {
- mContext = context;
- mInflater = LayoutInflater.from(context);
- mSupportedTypes = supportedTypes;
- mViews = new View[supportedTypes.length];
- }
-
- public void setListView(ListView list) {
- int size = mSupportedTypes.length;
- for (int i = 0; i < size; i++) {
- String type = mSupportedTypes[i];
- if (UriRecord.RECORD_TYPE.equals(type)) {
- mViews[i] = UriRecord.getAddView(mContext, mInflater, list);
- } else if (VCardRecord.RECORD_TYPE.equals(type)) {
- mViews[i] = VCardRecord.getAddView(mContext, mInflater, list);
- } else if (TextRecord.RECORD_TYPE.equals(type)) {
- mViews[i] = TextRecord.getAddView(mContext, mInflater, list);
- } else {
- throw new IllegalArgumentException("Not a supported view type");
- }
- }
- }
-
- @Override
- public int getItemViewType(int position) {
- return IGNORE_ITEM_VIEW_TYPE;
- }
-
- @Override
- public boolean hasStableIds() {
- return false;
- }
-
- @Override
- public long getItemId(int pos) {
- return pos;
- }
-
- @Override
- public int getCount() {
- return mSupportedTypes.length;
- }
-
- @Override
- public View getView(int position, View recycle, ViewGroup parent) {
- return mViews[position];
- }
-
- @Override
- public Object getItem(int position) {
- return mViews[position].getTag();
- }
-}
\ No newline at end of file
diff --git a/src/com/android/apps/tag/EditTagActivity.java b/src/com/android/apps/tag/EditTagActivity.java
deleted file mode 100644
index 4755ea8..0000000
--- a/src/com/android/apps/tag/EditTagActivity.java
+++ /dev/null
@@ -1,373 +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 com.android.apps.tag.message.NdefMessageParser;
-import com.android.apps.tag.message.ParsedNdefMessage;
-import com.android.apps.tag.provider.TagContract.NdefMessages;
-import com.android.apps.tag.record.ParsedNdefRecord;
-import com.android.apps.tag.record.RecordEditInfo;
-import com.android.apps.tag.record.RecordEditInfo.EditCallbacks;
-import com.android.apps.tag.record.TextRecord;
-import com.android.apps.tag.record.TextRecord.TextRecordEditInfo;
-import com.android.apps.tag.record.UriRecord;
-import com.android.apps.tag.record.UriRecord.UriRecordEditInfo;
-import com.android.apps.tag.record.VCardRecord;
-import com.google.common.collect.ImmutableSet;
-
-import android.app.Activity;
-import android.content.Intent;
-import android.database.Cursor;
-import android.net.Uri;
-import android.nfc.FormatException;
-import android.nfc.NdefMessage;
-import android.nfc.NdefRecord;
-import android.os.AsyncTask;
-import android.os.Bundle;
-import android.util.Log;
-import android.view.LayoutInflater;
-import android.view.Menu;
-import android.view.MenuItem;
-import android.view.View;
-import android.view.View.OnClickListener;
-import android.view.ViewGroup;
-
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.List;
-import java.util.Set;
-
-/**
- * A base {@link Activity} class for an editor of an {@link NdefMessage} tag.
- *
- * The core of the editing is done by various a {@link View}s that differs based on
- * {@link ParsedNdefRecord} types. Each type of {@link ParsedNdefRecord} can build a to
- * pick/select a new piece of content, or edit an existing content for the {@link NdefMessage}.
- */
-public class EditTagActivity extends Activity implements OnClickListener, EditCallbacks {
-
- private static final String LOG_TAG = "Tags";
-
- protected static final String BUNDLE_KEY_RECORD = "outstanding-pick";
- public static final String EXTRA_RESULT_MSG = "com.android.apps.tag.msg";
- public static final String EXTRA_NEW_RECORD_INFO = "com.android.apps.tag.new_record";
-
- protected static final Set<String> SUPPORTED_RECORD_TYPES = ImmutableSet.of(
- VCardRecord.RECORD_TYPE,
- UriRecord.RECORD_TYPE,
- TextRecord.RECORD_TYPE
- );
-
- /**
- * The underlying record in the tag being edited.
- */
- private RecordEditInfo mRecord;
-
- /**
- * The container where the subviews for each record are housed.
- */
- private ViewGroup mContentRoot;
-
- /**
- * Whether or not data was already parsed from an {@link Intent}. This happens when the user
- * shares data via the My tag feature.
- */
- private boolean mParsedIntent = false;
-
- private LayoutInflater mInflater;
-
- @Override
- protected void onCreate(Bundle savedState) {
- super.onCreate(savedState);
-
- setContentView(R.layout.edit_tag_activity);
- setTitle(getResources().getString(R.string.edit_tag));
-
- mInflater = LayoutInflater.from(this);
- findViewById(R.id.save).setOnClickListener(this);
- findViewById(R.id.cancel).setOnClickListener(this);
-
- mContentRoot = (ViewGroup) findViewById(R.id.content_parent);
-
- if (savedState != null) {
- mRecord = savedState.getParcelable(BUNDLE_KEY_RECORD);
- if (mRecord != null) {
- refresh();
- } else {
- Log.w(LOG_TAG, "invalid instance state, loading from intent");
- resolveIntent();
- }
- } else {
- resolveIntent();
- }
- }
-
- /**
- * @return The list of {@link ParsedNdefRecord} types that this editor supports. Subclasses
- * may override to filter out specific types.
- */
- public Set<String> getSupportedTypes() {
- return SUPPORTED_RECORD_TYPES;
- }
-
- /**
- * Builds a snapshot of current value as held in the internal state of this editor.
- */
- public NdefRecord getValue() {
- return mRecord.getValue();
- }
-
- /**
- * Refreshes the UI with updated content from the record.
- * Typically used when the records require an external {@link Activity} to edit.
- */
- public void refresh() {
- ViewGroup root = mContentRoot;
- View editView = mRecord.getEditView(this, mInflater, root, this);
- root.removeAllViews();
- root.addView(editView);
- }
-
- @Override
- public void startPickForRecord(RecordEditInfo editInfo, Intent intent) {
- startActivityForResult(intent, 0);
- }
-
- @Override
- public void deleteRecord(RecordEditInfo editInfo) {
- }
-
- @Override
- protected void onActivityResult(int requestCode, int resultCode, Intent data) {
- if ((resultCode != RESULT_OK) || (data == null)) {
- // No valid data, close the editor.
- finish();
- return;
- }
-
- // Handles results from another Activity that picked content to write to a tag.
- try {
- mRecord.handlePickResult(this, data);
- } catch (IllegalArgumentException ex) {
- // No valid data, close the editor.
- finish();
- return;
- }
-
- // Update the title to indicate that we're adding a tag instead of editing.
- setTitle(R.string.add_tag);
-
- // Setup the tag views
- refresh();
- }
-
- @Override
- protected void onSaveInstanceState(Bundle outState) {
- super.onSaveInstanceState(outState);
- outState.putParcelable(BUNDLE_KEY_RECORD, mRecord);
- }
-
- interface GetTagQuery {
- final static String[] PROJECTION = new String[] {
- NdefMessages.BYTES
- };
-
- static final int COLUMN_BYTES = 0;
- }
-
- /**
- * Loads a tag from the database, parses it, and builds the views.
- */
- final class LoadTagTask extends AsyncTask<Uri, Void, Cursor> {
- @Override
- public Cursor doInBackground(Uri... args) {
- Cursor cursor = getContentResolver().query(args[0], GetTagQuery.PROJECTION,
- null, null, null);
-
- // Ensure the cursor loads its window.
- if (cursor != null) {
- cursor.getCount();
- }
- return cursor;
- }
-
- @Override
- public void onPostExecute(Cursor cursor) {
- NdefMessage msg = null;
- try {
- if (cursor != null && cursor.moveToFirst()) {
- msg = new NdefMessage(cursor.getBlob(GetTagQuery.COLUMN_BYTES));
- populateFromMessage(msg);
- }
- } catch (FormatException e) {
- Log.e(LOG_TAG, "Unable to parse tag for editing.", e);
- } finally {
- if (cursor != null) {
- cursor.close();
- }
- }
- }
- }
-
- protected void resolveIntent() {
- Intent intent = getIntent();
-
- if (Intent.ACTION_SEND.equals(intent.getAction()) && !mParsedIntent) {
- if (buildFromSendIntent(intent)) {
- return;
- }
-
- mParsedIntent = true;
- return;
- }
-
- Uri uri = intent.getData();
- if (uri != null) {
- // Edit existing tag.
- new LoadTagTask().execute(uri);
- } else {
- RecordEditInfo newRecord = intent.getParcelableExtra(EXTRA_NEW_RECORD_INFO);
- if (newRecord != null) {
- initializeForNewTag(newRecord);
- }
- }
- }
-
- private void initializeForNewTag(RecordEditInfo editInfo) {
- mRecord = editInfo;
-
- Intent pickIntent = editInfo.getPickIntent();
- if (pickIntent != null) {
- startPickForRecord(editInfo, pickIntent);
- } else {
- refresh();
- }
- }
-
- void populateFromMessage(NdefMessage refMessage) {
- // Locally stored message.
- ParsedNdefMessage parsed = NdefMessageParser.parse(refMessage);
- List<ParsedNdefRecord> records = parsed.getRecords();
-
- // TODO: loosen this restriction.
- // There is always a "Text" record for a My Tag.
- if (records.size() != 1) {
- Log.w(LOG_TAG, "Message not in expected format");
- return;
- }
- mRecord = records.get(0).getEditInfo(this);
- refresh();
- }
-
- /**
- * Populates the editor from extras in a given {@link Intent}
- * @param intent the {@link Intent} to parse.
- * @return whether or not the {@link Intent} could be handled.
- */
- private boolean buildFromSendIntent(final Intent intent) {
- String type = intent.getType();
-
- if ("text/plain".equals(type)) {
- String text = getIntent().getStringExtra(Intent.EXTRA_TEXT);
- try {
- URL parsed = new URL(text);
-
- // Valid URL.
- mRecord = new UriRecordEditInfo(text);
- refresh();
- return true;
-
- } catch (MalformedURLException ex) {
- // Random text
- mRecord = new TextRecordEditInfo(text);
- refresh();
- return true;
- }
-
- } else if ("text/x-vcard".equals(type)) {
- Uri stream = (Uri) getIntent().getParcelableExtra(Intent.EXTRA_STREAM);
- if (stream != null) {
- RecordEditInfo editInfo = VCardRecord.editInfoForUri(stream);
- if (editInfo != null) {
- mRecord = editInfo;
- refresh();
- return true;
- }
- }
- }
-
- return false;
- }
-
- /**
- * Saves the content of the tag.
- */
- private void saveAndFinish() {
- if (mRecord == null) {
- setResult(RESULT_CANCELED);
- finish();
- return;
- }
-
- NdefMessage msg = new NdefMessage(new NdefRecord[] { mRecord.getValue() });
-
- if (Intent.ACTION_SEND.equals(getIntent().getAction())) {
- // If opening directly from a different application via ACTION_SEND, save the tag and
- // open the MyTagList so they can enable it.
- Intent openMyTags = new Intent(this, MyTagList.class);
- openMyTags.putExtra(EXTRA_RESULT_MSG, msg);
- startActivity(openMyTags);
- finish();
-
- } else {
- Intent result = new Intent();
- result.putExtra(EXTRA_RESULT_MSG, msg);
- setResult(RESULT_OK, result);
- finish();
- }
- }
-
- @Override
- public void onClick(View target) {
- switch (target.getId()) {
- case R.id.save:
- saveAndFinish();
- break;
- case R.id.cancel:
- finish();
- break;
- }
- }
-
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- getMenuInflater().inflate(R.menu.menu, menu);
- return true;
- }
-
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- switch (item.getItemId()) {
- case R.id.help:
- HelpUtils.openHelp(this);
- return true;
-
- default:
- return super.onOptionsItemSelected(item);
- }
- }
-}
diff --git a/src/com/android/apps/tag/HelpUtils.java b/src/com/android/apps/tag/HelpUtils.java
deleted file mode 100644
index a21d9bf..0000000
--- a/src/com/android/apps/tag/HelpUtils.java
+++ /dev/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.content.Context;
-import android.content.Intent;
-import android.net.Uri;
-import android.provider.Browser;
-
-import java.util.Locale;
-
-/**
- * Utilities for building help content.
- */
-public class HelpUtils {
-
- // Non-instantiable.
- private HelpUtils() {}
-
- private static String replaceLocale(String str) {
- // Substitute locale if present in string
- if (str.contains("%locale%")) {
- Locale locale = Locale.getDefault();
- str = str.replace("%locale%", locale.getLanguage());
- }
- return str;
- }
-
- /**
- * Opens up the help page in a browser.
- */
- public static void openHelp(final Context context) {
- Uri uri = Uri.parse(replaceLocale(context.getString(R.string.more_info_url)));
- Intent intent = new Intent(Intent.ACTION_VIEW, uri);
- intent.putExtra(Browser.EXTRA_APPLICATION_ID, context.getPackageName());
- context.startActivity(intent);
- }
-}
diff --git a/src/com/android/apps/tag/MyTagList.java b/src/com/android/apps/tag/MyTagList.java
deleted file mode 100644
index 9186389..0000000
--- a/src/com/android/apps/tag/MyTagList.java
+++ /dev/null
@@ -1,661 +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 com.android.apps.tag.provider.TagContract.NdefMessages;
-import com.android.apps.tag.record.RecordEditInfo;
-import com.android.apps.tag.record.TextRecord;
-import com.android.apps.tag.record.UriRecord;
-import com.android.apps.tag.record.VCardRecord;
-import com.google.common.base.Preconditions;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Lists;
-
-import android.app.Activity;
-import android.app.AlertDialog;
-import android.app.Dialog;
-import android.content.ContentUris;
-import android.content.Context;
-import android.content.DialogInterface;
-import android.content.DialogInterface.OnClickListener;
-import android.content.Intent;
-import android.database.CharArrayBuffer;
-import android.database.Cursor;
-import android.net.Uri;
-import android.nfc.FormatException;
-import android.nfc.NdefMessage;
-import android.nfc.NfcAdapter;
-import android.os.AsyncTask;
-import android.os.Build;
-import android.os.Bundle;
-import android.util.Log;
-import android.view.ContextMenu;
-import android.view.ContextMenu.ContextMenuInfo;
-import android.view.ContextThemeWrapper;
-import android.view.LayoutInflater;
-import android.view.MenuInflater;
-import android.view.MenuItem;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.AdapterView;
-import android.widget.AdapterView.AdapterContextMenuInfo;
-import android.widget.AdapterView.OnItemClickListener;
-import android.widget.CheckBox;
-import android.widget.CursorAdapter;
-import android.widget.ImageView;
-import android.widget.ListView;
-import android.widget.SimpleAdapter;
-import android.widget.TextView;
-import android.widget.Toast;
-
-import java.lang.ref.WeakReference;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Set;
-
-/**
- * Displays the list of tags that can be set as "My tag", and allows the user to select the
- * active tag that the device shares.
- */
-public class MyTagList
- extends Activity
- implements OnItemClickListener, View.OnClickListener,
- TagService.SaveCallbacks,
- DialogInterface.OnClickListener {
-
- static final String TAG = "TagList";
-
- private static final int REQUEST_EDIT = 0;
- private static final int DIALOG_ID_SELECT_ACTIVE_TAG = 0;
- private static final int DIALOG_ID_ADD_NEW_TAG = 1;
-
- private static final String BUNDLE_KEY_TAG_ID_IN_EDIT = "tag-edit";
- private static final String PREF_KEY_ACTIVE_TAG = "active-my-tag";
- static final String PREF_KEY_TAG_TO_WRITE = "tag-to-write";
-
- static final String[] SUPPORTED_TYPES = new String[] {
- VCardRecord.RECORD_TYPE,
- UriRecord.RECORD_TYPE,
- TextRecord.RECORD_TYPE,
- };
-
- private View mSelectActiveTagAnchor;
- private View mActiveTagDetails;
- private CheckBox mEnabled;
- private ListView mList;
-
- private TagAdapter mAdapter;
- private long mActiveTagId;
- private Uri mTagBeingSaved;
- private NdefMessage mActiveTag;
-
- private WeakReference<SelectActiveTagDialog> mSelectActiveTagDialog;
- private long mTagIdInEdit = -1;
- private long mTagIdLongPressed;
-
- private boolean mWriteSupport = false;
-
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
-
- setContentView(R.layout.my_tag_activity);
-
- if (savedInstanceState != null) {
- mTagIdInEdit = savedInstanceState.getLong(BUNDLE_KEY_TAG_ID_IN_EDIT, -1);
- }
-
- // Set up the check box to toggle My tag sharing.
- mEnabled = (CheckBox) findViewById(R.id.toggle_enabled_checkbox);
- mEnabled.setChecked(false); // Set after initial data load completes.
- findViewById(R.id.toggle_enabled_target).setOnClickListener(this);
-
- // Setup the active tag selector.
- mActiveTagDetails = findViewById(R.id.active_tag_details);
- mSelectActiveTagAnchor = findViewById(R.id.choose_my_tag);
- findViewById(R.id.active_tag).setOnClickListener(this);
- updateActiveTagView(null); // Filled in after initial data load.
-
- mActiveTagId = getPreferences(Context.MODE_PRIVATE).getLong(PREF_KEY_ACTIVE_TAG, -1);
-
- // Setup the list.
- mAdapter = new TagAdapter(this);
- mList = (ListView) findViewById(android.R.id.list);
- mList.setAdapter(mAdapter);
- mList.setOnItemClickListener(this);
- findViewById(R.id.add_tag).setOnClickListener(this);
-
- // Don't setup the empty view until after the first load
- // so the empty text doesn't flash when first loading the
- // activity.
- mList.setEmptyView(null);
-
- // Kick off an async task to load the tags.
- new TagLoaderTask().execute((Void[]) null);
-
- // If we're not on a user build offer a back door for writing tags.
- // The UX is horrible so we don't want to ship it but need it for testing.
- if (!Build.TYPE.equalsIgnoreCase("user")) {
- mWriteSupport = true;
- }
- registerForContextMenu(mList);
-
- if (getIntent().hasExtra(EditTagActivity.EXTRA_RESULT_MSG)) {
- NdefMessage msg = (NdefMessage) Preconditions.checkNotNull(
- getIntent().getParcelableExtra(EditTagActivity.EXTRA_RESULT_MSG));
- saveNewMessage(msg);
- }
- }
-
- @Override
- protected void onRestart() {
- super.onRestart();
- mTagIdInEdit = -1;
- }
-
- @Override
- protected void onSaveInstanceState(Bundle outState) {
- super.onSaveInstanceState(outState);
- outState.putLong(BUNDLE_KEY_TAG_ID_IN_EDIT, mTagIdInEdit);
- }
-
- @Override
- protected void onDestroy() {
- if (mAdapter != null) {
- mAdapter.changeCursor(null);
- }
- super.onDestroy();
- }
-
- @Override
- public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
- editTag(id);
- }
-
- /**
- * Opens the tag editor for a particular tag.
- */
- private void editTag(long id) {
- // TODO: use implicit Intent?
- Intent intent = new Intent(this, EditTagActivity.class);
- intent.setData(ContentUris.withAppendedId(NdefMessages.CONTENT_URI, id));
- mTagIdInEdit = id;
- startActivityForResult(intent, REQUEST_EDIT);
- }
-
- public void setEmptyView() {
- // TODO: set empty view.
- }
-
- public interface TagQuery {
- static final String[] PROJECTION = new String[] {
- NdefMessages._ID, // 0
- NdefMessages.DATE, // 1
- NdefMessages.TITLE, // 2
- NdefMessages.BYTES, // 3
- };
-
- static final int COLUMN_ID = 0;
- static final int COLUMN_DATE = 1;
- static final int COLUMN_TITLE = 2;
- static final int COLUMN_BYTES = 3;
- }
-
- /**
- * Asynchronously loads the tags info from the database.
- */
- final class TagLoaderTask extends AsyncTask<Void, Void, Cursor> {
- @Override
- public Cursor doInBackground(Void... args) {
- Cursor cursor = getContentResolver().query(
- NdefMessages.CONTENT_URI,
- TagQuery.PROJECTION,
- NdefMessages.IS_MY_TAG + "=1",
- null, NdefMessages.DATE + " DESC");
-
- // Ensure the cursor executes and fills its window
- if (cursor != null) cursor.getCount();
- return cursor;
- }
-
- @Override
- protected void onPostExecute(Cursor cursor) {
- mAdapter.changeCursor(cursor);
-
- if (cursor == null || cursor.getCount() == 0) {
- setEmptyView();
- } else {
- // Find the active tag.
- if (mTagBeingSaved != null) {
- selectTagBeingSaved(mTagBeingSaved);
-
- } else if (mActiveTagId != -1) {
- cursor.moveToPosition(-1);
- while (cursor.moveToNext()) {
- if (mActiveTagId == cursor.getLong(TagQuery.COLUMN_ID)) {
- selectActiveTag(cursor.getPosition());
- break;
- }
- }
- }
- }
-
-
- SelectActiveTagDialog dialog = (mSelectActiveTagDialog == null)
- ? null : mSelectActiveTagDialog.get();
- if (dialog != null) {
- dialog.setData(cursor);
- }
- }
- }
-
- /**
- * Struct to hold pointers to views in the list items to save time at view binding time.
- */
- static final class ViewHolder {
- public CharArrayBuffer titleBuffer;
- public TextView mainLine;
- public ImageView activeIcon;
- }
-
- /**
- * Adapter to display the the My tag entries.
- */
- 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) {
- ViewHolder holder = (ViewHolder) view.getTag();
-
- CharArrayBuffer buf = holder.titleBuffer;
- cursor.copyStringToBuffer(TagQuery.COLUMN_TITLE, buf);
- holder.mainLine.setText(buf.data, 0, buf.sizeCopied);
-
- boolean isActive = cursor.getLong(TagQuery.COLUMN_ID) == mActiveTagId;
- holder.activeIcon.setVisibility(isActive ? View.VISIBLE : View.GONE);
- }
-
- @Override
- public View newView(Context context, Cursor cursor, ViewGroup parent) {
- View view = mInflater.inflate(R.layout.tag_list_item, null);
-
- // Cache items for the view
- ViewHolder holder = new ViewHolder();
- holder.titleBuffer = new CharArrayBuffer(64);
- holder.mainLine = (TextView) view.findViewById(R.id.title);
- holder.activeIcon = (ImageView) view.findViewById(R.id.active_tag_icon);
- view.findViewById(R.id.date).setVisibility(View.GONE);
- view.setTag(holder);
-
- return view;
- }
-
- @Override
- public void onContentChanged() {
- // Kick off an async query to refresh the list
- new TagLoaderTask().execute((Void[]) null);
- }
- }
-
- @Override
- public void onClick(View target) {
- switch (target.getId()) {
- case R.id.toggle_enabled_target:
- boolean enabled = !mEnabled.isChecked();
- if (enabled) {
- if (mActiveTag != null) {
- enableSharingAndStoreTag();
- return;
- }
- Toast.makeText(
- this,
- getResources().getString(R.string.no_tag_selected),
- Toast.LENGTH_SHORT).show();
- }
-
- disableSharing();
- break;
-
- case R.id.add_tag:
- showDialog(DIALOG_ID_ADD_NEW_TAG);
- break;
-
- case R.id.active_tag:
- if (mAdapter.getCursor() == null || mAdapter.getCursor().isClosed()) {
- // Hopefully shouldn't happen.
- return;
- }
-
- if (mAdapter.getCursor().getCount() == 0) {
- OnClickListener onAdd = new OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- if (which == AlertDialog.BUTTON_POSITIVE) {
- showDialog(DIALOG_ID_ADD_NEW_TAG);
- }
- }
- };
- new AlertDialog.Builder(this)
- .setNegativeButton(android.R.string.cancel, null)
- .setPositiveButton(R.string.add_tag, onAdd)
- .setMessage(R.string.no_tags_created)
- .show();
- return;
- }
- showDialog(DIALOG_ID_SELECT_ACTIVE_TAG);
- break;
- }
- }
-
- @Override
- public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo info) {
- Cursor cursor = mAdapter.getCursor();
- if (cursor == null
- || cursor.isClosed()
- || !cursor.moveToPosition(((AdapterContextMenuInfo) info).position)) {
- return;
- }
-
- menu.setHeaderTitle(cursor.getString(TagQuery.COLUMN_TITLE));
- long id = cursor.getLong(TagQuery.COLUMN_ID);
- MenuInflater inflater = getMenuInflater();
- inflater.inflate(R.menu.my_tag_list_context_menu, menu);
-
- // Prepare the menu for the item.
- menu.findItem(R.id.set_as_active).setVisible(id != mActiveTagId);
- mTagIdLongPressed = id;
-
- if (mWriteSupport) {
- menu.add(0, 1, 0, "Write to tag");
- }
- }
-
- @Override
- public boolean onContextItemSelected(MenuItem item) {
- long id = mTagIdLongPressed;
- switch (item.getItemId()) {
- case R.id.delete:
- deleteTag(id);
- return true;
-
- case R.id.set_as_active:
- Cursor cursor = mAdapter.getCursor();
- if (cursor == null || cursor.isClosed()) {
- break;
- }
-
- for (int position = 0; cursor.moveToPosition(position); position++) {
- if (cursor.getLong(TagQuery.COLUMN_ID) == id) {
- selectActiveTag(position);
- return true;
- }
- }
- break;
-
- case R.id.edit:
- editTag(id);
- return true;
-
- case 1:
- AdapterView.AdapterContextMenuInfo info;
- try {
- info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
- } catch (ClassCastException e) {
- Log.e(TAG, "bad menuInfo", e);
- break;
- }
-
- Intent intent = new Intent(this, WriteTagActivity.class);
- intent.putExtra("id", info.id);
- startActivity(intent);
- return true;
- }
- return false;
- }
-
- @Override
- protected void onActivityResult(int requestCode, int resultCode, Intent data) {
- if (requestCode == REQUEST_EDIT && resultCode == RESULT_OK) {
- NdefMessage msg = (NdefMessage) Preconditions.checkNotNull(
- data.getParcelableExtra(EditTagActivity.EXTRA_RESULT_MSG));
-
- if (mTagIdInEdit != -1) {
- TagService.updateMyMessage(this, mTagIdInEdit, msg);
- } else {
- saveNewMessage(msg);
- }
- }
- }
-
- private void saveNewMessage(NdefMessage msg) {
- TagService.saveMyMessage(this, msg, this);
- }
-
- @Override
- public void onSaveComplete(Uri newMsgUri) {
- if (isFinishing()) {
- // Callback came asynchronously and was after we finished - ignore.
- return;
- }
- mTagBeingSaved = newMsgUri;
- selectTagBeingSaved(newMsgUri);
- }
-
- @Override
- protected Dialog onCreateDialog(int id, Bundle args) {
- Context lightTheme = new ContextThemeWrapper(this, android.R.style.Theme_Light);
- if (id == DIALOG_ID_SELECT_ACTIVE_TAG) {
- SelectActiveTagDialog dialog = new SelectActiveTagDialog(lightTheme,
- mAdapter.getCursor());
- dialog.setInverseBackgroundForced(true);
- mSelectActiveTagDialog = new WeakReference<SelectActiveTagDialog>(dialog);
- return dialog;
- } else if (id == DIALOG_ID_ADD_NEW_TAG) {
- ContentSelectorAdapter adapter = new ContentSelectorAdapter(lightTheme,
- SUPPORTED_TYPES);
- AlertDialog dialog = new AlertDialog.Builder(lightTheme)
- .setTitle(R.string.select_type)
- .setIcon(0)
- .setNegativeButton(android.R.string.cancel, this)
- .setAdapter(adapter, this)
- .create();
- adapter.setListView(dialog.getListView());
- dialog.setInverseBackgroundForced(true);
- return dialog;
- }
- return super.onCreateDialog(id, args);
- }
-
- @Override
- public void onClick(DialogInterface dialog, int which) {
- if (which == DialogInterface.BUTTON_NEGATIVE) {
- dialog.cancel();
- } else {
- RecordEditInfo info = (RecordEditInfo) ((AlertDialog) dialog).getListView()
- .getAdapter().getItem(which);
- Intent intent = new Intent(this, EditTagActivity.class);
- intent.putExtra(EditTagActivity.EXTRA_NEW_RECORD_INFO, info);
- startActivityForResult(intent, REQUEST_EDIT);
- }
- }
-
- /**
- * Selects the tag to be used as the "My tag" shared tag.
- *
- * This does not necessarily persist the selection to the {@code NfcAdapter}. That must be done
- * via {@link #enableSharingAndStoreTag()}. However, it will call {@link #disableSharing()}
- * if the tag is invalid.
- */
- private void selectActiveTag(int position) {
- Cursor cursor = mAdapter.getCursor();
- if (cursor != null && cursor.moveToPosition(position)) {
- mActiveTagId = cursor.getLong(TagQuery.COLUMN_ID);
-
- try {
- mActiveTag = new NdefMessage(cursor.getBlob(TagQuery.COLUMN_BYTES));
-
- // Persist active tag info to preferences.
- getPreferences(Context.MODE_PRIVATE)
- .edit()
- .putLong(PREF_KEY_ACTIVE_TAG, mActiveTagId)
- .apply();
-
- updateActiveTagView(cursor.getString(TagQuery.COLUMN_TITLE));
- mAdapter.notifyDataSetChanged();
-
- // If there was an existing shared tag, we update the contents, since
- // the active tag contents may have been changed. This also forces the
- // active tag to be in sync with what the NfcAdapter.
- if (NfcAdapter.getDefaultAdapter(this).getLocalNdefMessage() != null) {
- enableSharingAndStoreTag();
- }
-
- } catch (FormatException e) {
- // TODO: handle.
- disableSharing();
- }
- } else {
- updateActiveTagView(null);
- disableSharing();
- }
- mTagBeingSaved = null;
- }
-
- /**
- * Selects the tag to be used as the "My tag" shared tag, if the specified URI is found.
- * If the URI is not found, the next load will attempt to look for a matching tag to select.
- *
- * Commonly used for new tags that was just added to the database, and may not yet be
- * reflected in the {@code Cursor}.
- */
- private void selectTagBeingSaved(Uri uri) {
- Cursor cursor = mAdapter.getCursor();
- if (cursor == null) {
- return;
- }
- cursor.moveToPosition(-1);
- while (cursor.moveToNext()) {
- Uri tagUri = ContentUris.withAppendedId(
- NdefMessages.CONTENT_URI,
- cursor.getLong(TagQuery.COLUMN_ID));
- if (tagUri.equals(uri)) {
- selectActiveTag(cursor.getPosition());
- return;
- }
- }
- }
-
- private void enableSharingAndStoreTag() {
- mEnabled.setChecked(true);
- NfcAdapter.getDefaultAdapter(this).setLocalNdefMessage(
- Preconditions.checkNotNull(mActiveTag));
- }
-
- private void disableSharing() {
- mEnabled.setChecked(false);
- NfcAdapter.getDefaultAdapter(this).setLocalNdefMessage(null);
- }
-
- private void updateActiveTagView(String title) {
- if (title == null) {
- mActiveTagDetails.setVisibility(View.GONE);
- mSelectActiveTagAnchor.setVisibility(View.VISIBLE);
- } else {
- mActiveTagDetails.setVisibility(View.VISIBLE);
- ((TextView) mActiveTagDetails.findViewById(R.id.active_tag_title)).setText(title);
- mSelectActiveTagAnchor.setVisibility(View.GONE);
- }
- }
-
- /**
- * Removes the tag from the "My tag" list.
- */
- private void deleteTag(long id) {
- if (id == mActiveTagId) {
- selectActiveTag(-1);
- }
- TagService.delete(this, ContentUris.withAppendedId(NdefMessages.CONTENT_URI, id));
- }
-
- class SelectActiveTagDialog extends AlertDialog
- implements DialogInterface.OnClickListener, OnItemClickListener {
-
- private final ArrayList<HashMap<String, String>> mData;
- private final SimpleAdapter mSelectAdapter;
-
- protected SelectActiveTagDialog(Context context, Cursor cursor) {
- super(context);
-
- setTitle(context.getResources().getString(R.string.choose_my_tag));
- ListView list = new ListView(context);
-
- mData = Lists.newArrayList();
- mSelectAdapter = new SimpleAdapter(
- context,
- mData,
- android.R.layout.simple_list_item_1,
- new String[] { "title" },
- new int[] { android.R.id.text1 });
-
- list.setAdapter(mSelectAdapter);
- list.setOnItemClickListener(this);
- setView(list);
- setIcon(0);
- setButton(
- DialogInterface.BUTTON_POSITIVE,
- context.getString(android.R.string.cancel),
- this);
-
- setData(cursor);
- }
-
- public void setData(final Cursor cursor) {
- if ((cursor == null) || (cursor.getCount() == 0)) {
- cancel();
- return;
- }
- mData.clear();
-
- cursor.moveToPosition(-1);
- while (cursor.moveToNext()) {
- mData.add(new HashMap<String, String>() {{
- put("title", cursor.getString(MyTagList.TagQuery.COLUMN_TITLE));
- }});
- }
-
- mSelectAdapter.notifyDataSetChanged();
- }
-
- @Override
- public void onClick(DialogInterface dialog, int which) {
- cancel();
- }
-
- @Override
- public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
- selectActiveTag(position);
- enableSharingAndStoreTag();
- cancel();
- }
- }
-}
diff --git a/src/com/android/apps/tag/TagBrowserActivity.java b/src/com/android/apps/tag/TagBrowserActivity.java
deleted file mode 100644
index cff0f90..0000000
--- a/src/com/android/apps/tag/TagBrowserActivity.java
+++ /dev/null
@@ -1,147 +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.TabActivity;
-import android.content.Context;
-import android.content.DialogInterface;
-import android.content.Intent;
-import android.content.SharedPreferences;
-import android.content.res.Resources;
-import android.nfc.NfcAdapter;
-import android.os.Bundle;
-import android.provider.Settings;
-import android.view.Menu;
-import android.view.MenuItem;
-import android.widget.TabHost;
-
-/**
- * A browsing {@link Activity} that displays the saved tags in categories under tabs.
- */
-public class TagBrowserActivity extends TabActivity implements DialogInterface.OnClickListener {
-
- private static final int DIALOG_NFC_OFF = 1;
- private static final String PREF_KEY_SHOW_INTRO = "showintro";
-
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
-
- setContentView(R.layout.main);
-
- Resources res = getResources();
- TabHost tabHost = getTabHost();
-
- tabHost.addTab(tabHost.newTabSpec("tags")
- .setIndicator(getText(R.string.tab_tags),
- res.getDrawable(R.drawable.ic_tab_all_tags))
- .setContent(new Intent().setClass(this, TagList.class)));
-
- tabHost.addTab(tabHost.newTabSpec("starred")
- .setIndicator(getText(R.string.tab_starred),
- res.getDrawable(R.drawable.ic_tab_starred))
- .setContent(new Intent().setClass(this, TagList.class)
- .putExtra(TagList.EXTRA_SHOW_STARRED_ONLY, true)));
-
- tabHost.addTab(tabHost.newTabSpec("mytag")
- .setIndicator(getText(R.string.tab_my_tag),
- res.getDrawable(R.drawable.ic_tab_my_tag))
- .setContent(new Intent().setClass(this, MyTagList.class)));
-
- SharedPreferences preferences = getPreferences(Context.MODE_PRIVATE);
- if (!preferences.getBoolean(PREF_KEY_SHOW_INTRO, false)) {
- preferences.edit().putBoolean(PREF_KEY_SHOW_INTRO, true).apply();
- Intent intent = new Intent(this, AboutActivity.class);
- startActivity(intent);
- }
- }
-
- @Override
- public void onStart() {
- super.onStart();
-
- // Restore the last active tab
- SharedPreferences prefs = getSharedPreferences("prefs", Context.MODE_PRIVATE);
- getTabHost().setCurrentTabByTag(prefs.getString("tab", "tags"));
- }
-
- @Override
- public void onResume() {
- super.onResume();
- // Check to see if NFC is on
- NfcAdapter nfc = NfcAdapter.getDefaultAdapter(this);
- if (nfc == null || !nfc.isEnabled()) {
- showDialog(DIALOG_NFC_OFF);
- }
- }
-
- @Override
- public void onStop() {
- super.onStop();
-
- // Save the active tab
- SharedPreferences.Editor edit = getSharedPreferences("prefs", Context.MODE_PRIVATE).edit();
- edit.putString("tab", getTabHost().getCurrentTabTag());
- edit.apply();
- }
-
- @Override
- public Dialog onCreateDialog(int dialogId, Bundle args) {
- if (dialogId == DIALOG_NFC_OFF) {
- return new AlertDialog.Builder(this)
- .setTitle(R.string.dialog_title_nfc_off)
- .setMessage(R.string.dialog_text_nfc_off)
- .setPositiveButton(R.string.button_settings, this)
- .setNegativeButton(android.R.string.cancel, this)
- .setCancelable(true)
- .create();
- }
-
- throw new IllegalArgumentException("Unknown dialog id " + dialogId);
- }
-
- @Override
- public void onClick(DialogInterface dialog, int which) {
- if (which == DialogInterface.BUTTON_POSITIVE) {
- // Thake the user to the wireless settings panel, where they can enable NFC
- Intent intent = new Intent(Settings.ACTION_WIRELESS_SETTINGS);
- startActivity(intent);
- }
- dialog.dismiss();
- }
-
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- getMenuInflater().inflate(R.menu.menu, menu);
- return true;
- }
-
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- switch (item.getItemId()) {
- case R.id.help:
- HelpUtils.openHelp(this);
- return true;
-
- default:
- return super.onOptionsItemSelected(item);
- }
- }
-}
diff --git a/src/com/android/apps/tag/TagList.java b/src/com/android/apps/tag/TagList.java
deleted file mode 100644
index 76f45a6..0000000
--- a/src/com/android/apps/tag/TagList.java
+++ /dev/null
@@ -1,198 +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 com.android.apps.tag.provider.TagContract.NdefMessages;
-import com.android.apps.tag.provider.TagProvider;
-
-import android.app.Activity;
-import android.app.ListActivity;
-import android.content.ContentUris;
-import android.content.Context;
-import android.content.Intent;
-import android.database.CharArrayBuffer;
-import android.database.Cursor;
-import android.os.AsyncTask;
-import android.os.Bundle;
-import android.text.Html;
-import android.text.format.DateUtils;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.View.OnClickListener;
-import android.view.ViewGroup;
-import android.widget.CursorAdapter;
-import android.widget.ListView;
-import android.widget.TextView;
-
-/**
- * An {@link Activity} that displays a flat list of tags that can be "opened".
- */
-public class TagList extends ListActivity implements OnClickListener {
- static final String TAG = "TagList";
-
- static final String EXTRA_SHOW_STARRED_ONLY = "show_starred_only";
-
- TagAdapter mAdapter;
- boolean mShowStarredOnly;
-
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
-
- setContentView(R.layout.tag_list);
- findViewById(R.id.more_info).setVisibility(View.GONE);
-
- mShowStarredOnly = getIntent().getBooleanExtra(EXTRA_SHOW_STARRED_ONLY, false);
-
- new TagLoaderTask().execute((Void[]) null);
- mAdapter = new TagAdapter(this);
- setListAdapter(mAdapter);
- }
-
- @Override
- protected void onDestroy() {
- if (mAdapter != null) {
- mAdapter.changeCursor(null);
- }
- super.onDestroy();
- }
-
- @Override
- protected void onListItemClick(ListView l, View v, int position, long id) {
- Intent intent = new Intent(Intent.ACTION_VIEW,
- ContentUris.withAppendedId(NdefMessages.CONTENT_URI, id));
- startActivity(intent);
- }
-
- public void setEmptyView() {
- TextView empty = (TextView) findViewById(R.id.text);
- View button = findViewById(R.id.more_info);
-
- if (mShowStarredOnly) {
- empty.setText(R.string.empty_list_starred);
- button.setVisibility(View.GONE);
- } else {
- empty.setText(Html.fromHtml(getString(R.string.empty_list)));
- button.setVisibility(View.VISIBLE);
- button.setOnClickListener(this);
- }
- }
-
- @Override
- public void onClick(View view) {
- HelpUtils.openHelp(this);
- }
-
- interface TagQuery {
- static final String[] PROJECTION = new String[] {
- NdefMessages._ID, // 0
- NdefMessages.DATE, // 1
- NdefMessages.TITLE, // 2
- NdefMessages.STARRED, // 3
- };
-
- static final int COLUMN_ID = 0;
- static final int COLUMN_DATE = 1;
- static final int COLUMN_TITLE = 2;
- static final int COLUMN_STARRED = 3;
- }
-
- /**
- * Asynchronously loads the tag info from the database.
- */
- final class TagLoaderTask extends AsyncTask<Void, Void, Cursor> {
- @Override
- public Cursor doInBackground(Void... args) {
- String starred = mShowStarredOnly ? NdefMessages.STARRED + "=1" : null;
- String notMyTag = NdefMessages.IS_MY_TAG + "!=1";
-
- Cursor cursor = getContentResolver().query(
- NdefMessages.CONTENT_URI,
- TagQuery.PROJECTION,
- TagProvider.concatenateWhere(starred, notMyTag),
- null, NdefMessages.DATE + " DESC");
-
- // Ensure the cursor executes and fills its window
- if (cursor != null) cursor.getCount();
- return cursor;
- }
-
- @Override
- protected void onPostExecute(Cursor cursor) {
- if (cursor == null || cursor.getCount() == 0) {
- // Don't setup the empty view until after the first load
- // so the empty text doesn't flash when first loading the
- // activity.
- setEmptyView();
- }
- mAdapter.changeCursor(cursor);
- }
- }
-
- /**
- * Struct to hold pointers to views in the list items to save time at view binding time.
- */
- static final class ViewHolder {
- public CharArrayBuffer titleBuffer;
- public TextView mainLine;
- public TextView dateLine;
- }
-
- /**
- * Adapter to display the tag entries.
- */
- 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) {
- ViewHolder holder = (ViewHolder) view.getTag();
-
- CharArrayBuffer buf = holder.titleBuffer;
- cursor.copyStringToBuffer(TagQuery.COLUMN_TITLE, buf);
- holder.mainLine.setText(buf.data, 0, buf.sizeCopied);
-
- holder.dateLine.setText(DateUtils.getRelativeTimeSpanString(
- context, cursor.getLong(TagQuery.COLUMN_DATE)));
- }
-
- @Override
- public View newView(Context context, Cursor cursor, ViewGroup parent) {
- View view = mInflater.inflate(R.layout.tag_list_item, null);
-
- // Cache items for the view
- ViewHolder holder = new ViewHolder();
- holder.titleBuffer = new CharArrayBuffer(64);
- holder.mainLine = (TextView) view.findViewById(R.id.title);
- holder.dateLine = (TextView) view.findViewById(R.id.date);
- view.setTag(holder);
-
- return view;
- }
-
- @Override
- public void onContentChanged() {
- // Kick off an async query to refresh the list
- new TagLoaderTask().execute((Void[]) null);
- }
- }
-}
diff --git a/src/com/android/apps/tag/TagService.java b/src/com/android/apps/tag/TagService.java
deleted file mode 100644
index bca13b6..0000000
--- a/src/com/android/apps/tag/TagService.java
+++ /dev/null
@@ -1,204 +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 com.android.apps.tag.provider.TagContract.NdefMessages;
-
-import android.app.IntentService;
-import android.app.PendingIntent;
-import android.app.PendingIntent.CanceledException;
-import android.app.Service;
-import android.content.ContentValues;
-import android.content.Context;
-import android.content.Intent;
-import android.net.Uri;
-import android.nfc.NdefMessage;
-import android.os.AsyncTask;
-import android.os.Handler;
-import android.os.IBinder;
-import android.os.Parcelable;
-import android.util.Log;
-
-public class TagService extends IntentService {
- private static final String TAG = "TagService";
-
- private static final String EXTRA_SAVE_MSGS = "msgs";
- private static final String EXTRA_DELETE_URI = "delete";
- private static final String EXTRA_STAR_URI = "set_star";
- private static final String EXTRA_UNSTAR_URI = "remove_star";
- private static final String EXTRA_STARRED = "starred";
- private static final String EXTRA_PENDING_INTENT = "pending";
- private static final String EXTRA_SAVE_IN_MY_TAGS = "my_tags";
- private static final String EXTRA_REPLACE_ID = "replace";
-
- private static final boolean DEBUG = true;
-
- public TagService() {
- super("SaveTagService");
- }
-
- public interface SaveCallbacks {
- void onSaveComplete(Uri uri);
- }
-
- private static final class EmptyService extends Service {
- @Override
- public IBinder onBind(Intent intent) {
- return null;
- }
- }
-
-
- @Override
- public void onHandleIntent(Intent intent) {
- if (intent.hasExtra(EXTRA_SAVE_MSGS)) {
- Parcelable[] msgs = intent.getParcelableArrayExtra(EXTRA_SAVE_MSGS);
- NdefMessage msg = (NdefMessage) msgs[0];
-
- ContentValues values = NdefMessages.toValues(
- this, msg,
- intent.getBooleanExtra(EXTRA_STARRED, false),
- intent.getBooleanExtra(EXTRA_SAVE_IN_MY_TAGS, false),
- System.currentTimeMillis());
-
- if (intent.hasExtra(EXTRA_REPLACE_ID)) {
- long id = intent.getLongExtra(EXTRA_REPLACE_ID, 0);
- String where = NdefMessages._ID + "=" + id;
- getContentResolver().update(NdefMessages.CONTENT_URI, values, where, null);
- } else {
- Uri uri = getContentResolver().insert(NdefMessages.CONTENT_URI, values);
-
- if (intent.hasExtra(EXTRA_PENDING_INTENT)) {
- Intent result = new Intent();
- result.setData(uri);
-
- PendingIntent pending = (PendingIntent) intent.getParcelableExtra(
- EXTRA_PENDING_INTENT);
- if (pending != null) {
- try {
- pending.send(this, 0, result);
- } catch (CanceledException e) {
- if (DEBUG) Log.d(TAG, "Pending intent was canceled.");
- }
- }
- }
- }
-
- return;
- }
-
- if (intent.hasExtra(EXTRA_DELETE_URI)) {
- Uri uri = (Uri) intent.getParcelableExtra(EXTRA_DELETE_URI);
- getContentResolver().delete(uri, null, null);
- return;
- }
-
- if (intent.hasExtra(EXTRA_STAR_URI)) {
- Uri uri = (Uri) intent.getParcelableExtra(EXTRA_STAR_URI);
- ContentValues values = new ContentValues();
- values.put(NdefMessages.STARRED, 1);
- getContentResolver().update(uri, values, null, null);
- }
-
- if (intent.hasExtra(EXTRA_UNSTAR_URI)) {
- Uri uri = (Uri) intent.getParcelableExtra(EXTRA_UNSTAR_URI);
- ContentValues values = new ContentValues();
- values.put(NdefMessages.STARRED, 0);
- getContentResolver().update(uri, values, null, null);
- }
- }
-
- public static void saveMessages(Context context, NdefMessage[] msgs, boolean starred,
- PendingIntent pending) {
- Intent intent = new Intent(context, TagService.class);
- intent.putExtra(TagService.EXTRA_SAVE_MSGS, msgs);
- intent.putExtra(TagService.EXTRA_STARRED, starred);
- intent.putExtra(TagService.EXTRA_PENDING_INTENT, pending);
- context.startService(intent);
- }
-
- public static void saveMyMessages(Context context, NdefMessage[] msgs, PendingIntent pending) {
- Intent intent = new Intent(context, TagService.class);
- intent.putExtra(TagService.EXTRA_SAVE_MSGS, msgs);
- intent.putExtra(TagService.EXTRA_SAVE_IN_MY_TAGS, true);
- if (pending != null) {
- intent.putExtra(TagService.EXTRA_PENDING_INTENT, pending);
- }
- context.startService(intent);
- }
-
- public static void saveMyMessage(
- final Context context, final NdefMessage msg, final SaveCallbacks callbacks) {
- final Handler handler = new Handler();
- Thread thread = new Thread() {
- @Override
- public void run() {
- // Start service to ensure the save completes in case this app gets thrown into the
- // background.
- context.startService(new Intent(context, EmptyService.class));
-
-
- ContentValues values = NdefMessages.toValues(
- context, msg,
- false /* starred */, true /* is one of "my tags" */,
- System.currentTimeMillis());
-
- // Start dummy service to ensure the save completes.
- context.startService(new Intent(context, EmptyService.class));
-
- final Uri result =
- context.getContentResolver().insert(NdefMessages.CONTENT_URI, values);
- handler.post(new Runnable() {
- @Override
- public void run() {
- callbacks.onSaveComplete(result);
- }
- });
-
- // Stop service so we can be killed.
- context.stopService(new Intent(context, EmptyService.class));
- }
- };
- thread.setPriority(Thread.MIN_PRIORITY);
- thread.start();
- }
-
-
- public static void updateMyMessage(Context context, long id, NdefMessage msg) {
- Intent intent = new Intent(context, TagService.class);
- intent.putExtra(TagService.EXTRA_SAVE_MSGS, new NdefMessage[] { msg });
- intent.putExtra(TagService.EXTRA_SAVE_IN_MY_TAGS, true);
- intent.putExtra(TagService.EXTRA_REPLACE_ID, id);
- context.startService(intent);
- }
-
- public static void delete(Context context, Uri uri) {
- Intent intent = new Intent(context, TagService.class);
- intent.putExtra(TagService.EXTRA_DELETE_URI, uri);
- context.startService(intent);
- }
-
- public static void setStar(Context context, Uri message, boolean star) {
- Intent intent = new Intent(context, TagService.class);
- if (star) {
- intent.putExtra(EXTRA_STAR_URI, message);
- } else {
- intent.putExtra(EXTRA_UNSTAR_URI, message);
- }
- context.startService(intent);
- }
-}
diff --git a/src/com/android/apps/tag/TagViewer.java b/src/com/android/apps/tag/TagViewer.java
index 4d4e870..14e58f8 100644
--- a/src/com/android/apps/tag/TagViewer.java
+++ b/src/com/android/apps/tag/TagViewer.java
@@ -18,171 +18,50 @@
import com.android.apps.tag.message.NdefMessageParser;
import com.android.apps.tag.message.ParsedNdefMessage;
-import com.android.apps.tag.provider.TagContract.NdefMessages;
import com.android.apps.tag.record.ParsedNdefRecord;
import android.app.Activity;
-import android.app.PendingIntent;
-import android.content.BroadcastReceiver;
-import android.content.ContentUris;
-import android.content.Context;
import android.content.Intent;
-import android.content.IntentFilter;
-import android.content.SharedPreferences;
-import android.content.res.AssetFileDescriptor;
-import android.database.Cursor;
-import android.media.AudioManager;
-import android.media.MediaPlayer;
import android.net.Uri;
-import android.nfc.FormatException;
import android.nfc.NdefMessage;
import android.nfc.NdefRecord;
import android.nfc.NfcAdapter;
-import android.nfc.Tag;
-import android.nfc.tech.Ndef;
-import android.nfc.tech.NdefFormatable;
-import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Parcelable;
-import android.os.PowerManager;
-import android.os.PowerManager.WakeLock;
-import android.text.format.DateUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
-import android.view.WindowManager;
import android.widget.Button;
-import android.widget.CheckBox;
-import android.widget.ImageView;
import android.widget.LinearLayout;
-import android.widget.TextView;
-import android.widget.Toast;
-import java.io.IOException;
import java.util.List;
/**
* An {@link Activity} which handles a broadcast of a new tag that the device just discovered.
*/
public class TagViewer extends Activity implements OnClickListener {
- static final String TAG = "SaveTag";
- static final String EXTRA_TAG_DB_ID = "db_id";
- static final String EXTRA_MESSAGE = "msg";
- static final String EXTRA_KEEP_TITLE = "keepTitle";
+ static final String TAG = "TagViewer";
- static final boolean SHOW_OVER_LOCK_SCREEN = false;
-
- /** This activity will finish itself in this amount of time if the user doesn't do anything. */
- static final int ACTIVITY_TIMEOUT_MS = 7 * 1000;
-
- Uri mTagUri;
- ImageView mIcon;
- TextView mTitle;
- TextView mDate;
- CheckBox mStar;
- Button mDeleteButton;
- Button mDoneButton;
LinearLayout mTagContent;
- BroadcastReceiver mReceiver;
-
- private class ScreenOffReceiver extends BroadcastReceiver {
- @Override
- public void onReceive(Context context, Intent intent) {
- if (Intent.ACTION_SCREEN_OFF.equals(intent.getAction())) {
- if (!isFinishing()) {
- finish();
- }
- }
- }
- }
-
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- if (SHOW_OVER_LOCK_SCREEN) {
- getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
- }
-
setContentView(R.layout.tag_viewer);
mTagContent = (LinearLayout) findViewById(R.id.list);
- mTitle = (TextView) findViewById(R.id.title);
- mDate = (TextView) findViewById(R.id.date);
- mIcon = (ImageView) findViewById(R.id.icon);
- mStar = (CheckBox) findViewById(R.id.star);
- mDeleteButton = (Button) findViewById(R.id.button_delete);
- mDoneButton = (Button) findViewById(R.id.button_done);
-
- mDeleteButton.setOnClickListener(this);
- mDoneButton.setOnClickListener(this);
- mStar.setOnClickListener(this);
- mIcon.setImageResource(R.drawable.ic_launcher_nfc);
+ findViewById(R.id.button_done).setOnClickListener(this);
resolveIntent(getIntent());
}
- @Override
- public void onRestart() {
- super.onRestart();
- if (mTagUri == null) {
- // Someone how the user was fast enough to navigate away from the activity
- // before the service was able to save the tag and call back onto this
- // activity with the pending intent. Since we don't know what do display here
- // just finish the activity.
- finish();
- }
- }
-
- @Override
- public void onStop() {
- super.onStop();
-
- PendingIntent pending = getPendingIntent();
- pending.cancel();
-
- if (mReceiver != null) {
- unregisterReceiver(mReceiver);
- mReceiver = null;
- }
- }
-
- private PendingIntent getPendingIntent() {
- Intent callback = new Intent();
- callback.setClass(this, TagViewer.class);
- callback.setAction(Intent.ACTION_VIEW);
- callback.setFlags(Intent. FLAG_ACTIVITY_CLEAR_TOP);
- callback.putExtra(EXTRA_KEEP_TITLE, true);
-
- return PendingIntent.getActivity(this, 0, callback, PendingIntent.FLAG_CANCEL_CURRENT);
- }
-
void resolveIntent(Intent intent) {
// Parse the intent
String action = intent.getAction();
if (NfcAdapter.ACTION_TAG_DISCOVERED.equals(action)
|| NfcAdapter.ACTION_TECH_DISCOVERED.equals(action)) {
- if (SHOW_OVER_LOCK_SCREEN) {
- // A tag was just scanned so poke the user activity wake lock to keep
- // the screen on a bit longer in the event that the activity has
- // hidden the lock screen.
- PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
- WakeLock wakeLock = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, TAG);
- // This lock CANNOT be manually released in onStop() since that may
- // cause a lock under run exception to be thrown when the timeout
- // hits.
- wakeLock.acquire(ACTIVITY_TIMEOUT_MS);
-
- if (mReceiver == null) {
- mReceiver = new ScreenOffReceiver();
- IntentFilter filter = new IntentFilter();
- filter.addAction(Intent.ACTION_SCREEN_OFF);
- registerReceiver(mReceiver, filter);
- }
- }
-
// When a tag is discovered we send it to the service to be save. We
// include a PendingIntent for the service to call back onto. This
// will cause this activity to be restarted with onNewIntent(). At
@@ -192,7 +71,7 @@
if (rawMsgs != null && rawMsgs.length > 0) {
// stupid java, need to cast one-by-one
msgs = new NdefMessage[rawMsgs.length];
- for (int i=0; i<rawMsgs.length; i++) {
+ for (int i = 0; i < rawMsgs.length; i++) {
msgs[i] = (NdefMessage) rawMsgs[i];
}
} else {
@@ -202,54 +81,6 @@
NdefMessage msg = new NdefMessage(new NdefRecord[] { record });
msgs = new NdefMessage[] { msg };
}
- TagService.saveMessages(this, msgs, false, getPendingIntent());
-
- // Setup the views
- setTitle(R.string.title_scanned_tag);
- mDate.setVisibility(View.GONE);
- mStar.setChecked(false);
- mStar.setEnabled(true);
-
- // Play notification.
- try {
- AssetFileDescriptor afd = getResources().openRawResourceFd(
- R.raw.discovered_tag_notification);
- if (afd != null) {
- MediaPlayer player = new MediaPlayer();
- player.setDataSource(
- afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength());
- afd.close();
- player.setAudioStreamType(AudioManager.STREAM_NOTIFICATION);
- player.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
- @Override
- public void onCompletion(MediaPlayer mp) {
- mp.release();
- }
- });
- player.prepare();
- player.start();
- }
- } catch (IOException ex) {
- Log.d(TAG, "Unable to play sound for tag discovery", ex);
- } catch (IllegalArgumentException ex) {
- Log.d(TAG, "Unable to play sound for tag discovery", ex);
- } catch (SecurityException ex) {
- Log.d(TAG, "Unable to play sound for tag discovery", ex);
- }
-
- } else if (Intent.ACTION_VIEW.equals(action)) {
- // Setup the views
- if (!intent.getBooleanExtra(EXTRA_KEEP_TITLE, false)) {
- setTitle(R.string.title_existing_tag);
- mDate.setVisibility(View.VISIBLE);
- }
-
- mStar.setVisibility(View.VISIBLE);
- mStar.setEnabled(false); // it's reenabled when the async load completes
-
- // Read the tag from the database asynchronously
- mTagUri = intent.getData();
- new LoadTagTask().execute(mTagUri);
} else {
Log.e(TAG, "Unknown intent " + intent);
finish();
@@ -257,8 +88,8 @@
}
}
- void buildTagViews(NdefMessage[] msgs) {
- if (msgs == null || msgs.length == 0) {
+ void buildTagViews(NdefMessage msg) {
+ if (msg == null) {
return;
}
@@ -270,13 +101,13 @@
// Parse the first message in the list
//TODO figure out what to do when/if we support multiple messages per tag
- ParsedNdefMessage parsedMsg = NdefMessageParser.parse(msgs[0]);
+ ParsedNdefMessage parsedMsg = NdefMessageParser.parse(msg);
// Build views for all of the sub records
List<ParsedNdefRecord> records = parsedMsg.getRecords();
final int size = records.size();
- for (int i = 0 ; i < size ; i++) {
+ for (int i = 0; i < size; i++) {
ParsedNdefRecord record = records.get(i);
content.addView(record.getView(this, inflater, content, i));
inflater.inflate(R.layout.tag_divider, content, true);
@@ -290,76 +121,7 @@
}
@Override
- public void setTitle(CharSequence title) {
- mTitle.setText(title);
- }
-
- @Override
public void onClick(View view) {
- if (view == mDeleteButton) {
- if (mTagUri == null) {
- finish();
- } else {
- // The tag came from the database, start a service to delete it
- TagService.delete(this, mTagUri);
- finish();
- }
- Toast.makeText(this, getResources().getString(R.string.tag_deleted), Toast.LENGTH_SHORT)
- .show();
- } else if (view == mDoneButton) {
- finish();
- } else if (view == mStar) {
- if (mTagUri != null) {
- TagService.setStar(this, mTagUri, mStar.isChecked());
- }
- }
- }
-
- interface ViewTagQuery {
- final static String[] PROJECTION = new String[] {
- NdefMessages.BYTES, // 0
- NdefMessages.STARRED, // 1
- NdefMessages.DATE, // 2
- };
-
- static final int COLUMN_BYTES = 0;
- static final int COLUMN_STARRED = 1;
- static final int COLUMN_DATE = 2;
- }
-
- /**
- * Loads a tag from the database, parses it, and builds the views
- */
- final class LoadTagTask extends AsyncTask<Uri, Void, Cursor> {
- @Override
- public Cursor doInBackground(Uri... args) {
- Cursor cursor = getContentResolver().query(args[0], ViewTagQuery.PROJECTION,
- null, null, null);
-
- // Ensure the cursor loads its window
- if (cursor != null) cursor.getCount();
- return cursor;
- }
-
- @Override
- public void onPostExecute(Cursor cursor) {
- NdefMessage msg = null;
- try {
- if (cursor != null && cursor.moveToFirst()) {
- msg = new NdefMessage(cursor.getBlob(ViewTagQuery.COLUMN_BYTES));
- if (msg != null) {
- mDate.setText(DateUtils.getRelativeTimeSpanString(TagViewer.this,
- cursor.getLong(ViewTagQuery.COLUMN_DATE)));
- mStar.setChecked(cursor.getInt(ViewTagQuery.COLUMN_STARRED) != 0);
- mStar.setEnabled(true);
- buildTagViews(new NdefMessage[] { msg });
- }
- }
- } catch (FormatException e) {
- Log.e(TAG, "invalid tag format", e);
- } finally {
- if (cursor != null) cursor.close();
- }
- }
+ finish();
}
}
diff --git a/src/com/android/apps/tag/WriteTagActivity.java b/src/com/android/apps/tag/WriteTagActivity.java
deleted file mode 100644
index 11ed9e1..0000000
--- a/src/com/android/apps/tag/WriteTagActivity.java
+++ /dev/null
@@ -1,188 +0,0 @@
-/*
- * Copyright (C) 2011 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 com.android.apps.tag.provider.TagContract.NdefMessages;
-
-import android.app.Activity;
-import android.app.PendingIntent;
-import android.content.Intent;
-import android.content.IntentFilter;
-import android.database.Cursor;
-import android.graphics.Color;
-import android.nfc.FormatException;
-import android.nfc.NdefMessage;
-import android.nfc.NfcAdapter;
-import android.nfc.Tag;
-import android.nfc.tech.Ndef;
-import android.nfc.tech.NdefFormatable;
-import android.os.AsyncTask;
-import android.os.Bundle;
-import android.util.Log;
-import android.widget.TextView;
-
-import java.io.IOException;
-
-public class WriteTagActivity extends Activity {
- static final String TAG = WriteTagActivity.class.getName();
-
- NfcAdapter mAdapter;
- PendingIntent mPendingIntent;
- TextView mTitle;
- TextView mStatus;
- TextView mCountView;
- NdefMessage mMessage;
- int mSize;
- int mCount = 1;
-
- final class MessageLoaderTask extends AsyncTask<String, Void, Cursor> {
- @Override
- public Cursor doInBackground(String... args) {
- Cursor cursor = getContentResolver().query(
- NdefMessages.CONTENT_URI,
- new String[] { NdefMessages.TITLE, NdefMessages.BYTES },
- NdefMessages._ID + "=?",
- new String[] { args[0] }, null);
-
- // Ensure the cursor executes and fills its window
- if (cursor != null) cursor.getCount();
- return cursor;
- }
-
- @Override
- protected void onPostExecute(Cursor cursor) {
- try {
- if (cursor == null || !cursor.moveToFirst()) {
- setStatus("Failed to load tag for writing.", false);
- return;
- }
- byte[] blob = cursor.getBlob(1);
- mSize = blob.length;
- mMessage = new NdefMessage(blob);
- mTitle.setText("Scan a tag to write\n" + cursor.getString(0));
- } catch (FormatException e) {
- setStatus("Invalid tag.", false);
- } finally {
- if (cursor != null) cursor.close();
- }
- }
- }
-
- @Override
- public void onCreate(Bundle savedState) {
- super.onCreate(savedState);
-
- setContentView(R.layout.write_tag);
- mTitle = (TextView) findViewById(R.id.title);
- mStatus = (TextView) findViewById(R.id.status);
- mCountView = (TextView) findViewById(R.id.count);
-
- Bundle extras = getIntent().getExtras();
- if (extras == null || !extras.containsKey("id")) {
- setStatus("Nothing to write.", true);
- return;
- }
-
- mTitle.setText("Loading tag.");
- long id = extras.getLong("id");
- new MessageLoaderTask().execute(Long.toString(id));
-
- mAdapter = NfcAdapter.getDefaultAdapter(this);
-
- // Create a generic PendingIntent that will be deliver to this activity. The NFC stack
- // will fill in the intent with the details of the discovered tag before delivering to
- // this activity.
- mPendingIntent = PendingIntent.getActivity(this, 0,
- new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);
- }
-
- @Override
- public void onResume() {
- super.onResume();
- mAdapter.enableForegroundDispatch(this, mPendingIntent, null, null);
- }
-
- @Override
- public void onNewIntent(Intent intent) {
- Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
- mCountView.setText("Tag " + mCount++);
- if (mMessage != null) {
- writeTag(tag);
- } else {
- setStatus("Not ready to write.", false);
- }
- }
-
- @Override
- public void onPause() {
- super.onPause();
- mAdapter.disableForegroundDispatch(this);
- }
-
- void setStatus(String message, boolean success) {
- mStatus.setText(message);
- if (!success) {
- mStatus.setTextColor(Color.RED);
- } else {
- mStatus.setTextColor(Color.GREEN);
- }
- }
-
- boolean writeTag(Tag tag) {
- try {
- Ndef ndef = Ndef.get(tag);
- if (ndef != null) {
- ndef.connect();
-
- if (!ndef.isWritable()) {
- setStatus("Tag is read-only.", false);
- return false;
- }
- if (ndef.getMaxSize() < mSize) {
- setStatus("Tag capacity is " + ndef.getMaxSize() + " bytes, message is " +
- mSize + " bytes.", false);
- return false;
- }
-
- ndef.writeNdefMessage(mMessage);
- setStatus("Wrote message to pre-formatted tag.", true);
- return true;
- } else {
- NdefFormatable format = NdefFormatable.get(tag);
- if (format != null) {
- try {
- format.connect();
- format.format(mMessage);
- setStatus("Formatted tag and wrote message.", true);
- return true;
- } catch (IOException e) {
- setStatus("Failed to format tag.", false);
- return false;
- }
- } else {
- setStatus("Tag doesn't support NDEF.", false);
- return false;
- }
- }
- } catch (Exception e) {
- Log.e(TAG, "Failed to write tag", e);
- }
-
- setStatus("Failed to write tag", false);
- return false;
- }
-}
diff --git a/src/com/android/apps/tag/provider/SQLiteContentProvider.java b/src/com/android/apps/tag/provider/SQLiteContentProvider.java
deleted file mode 100644
index ade9eaf..0000000
--- a/src/com/android/apps/tag/provider/SQLiteContentProvider.java
+++ /dev/null
@@ -1,251 +0,0 @@
-/*
- * Copyright (C) 2009 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.provider;
-
-import android.content.ContentProvider;
-import android.content.ContentProviderOperation;
-import android.content.ContentProviderResult;
-import android.content.ContentValues;
-import android.content.Context;
-import android.content.OperationApplicationException;
-import android.database.sqlite.SQLiteDatabase;
-import android.database.sqlite.SQLiteOpenHelper;
-import android.database.sqlite.SQLiteTransactionListener;
-import android.net.Uri;
-
-import java.util.ArrayList;
-
-/**
- * General purpose {@link ContentProvider} base class that uses SQLiteDatabase for storage.
- */
-public abstract class SQLiteContentProvider extends ContentProvider
- implements SQLiteTransactionListener {
-
- private static final String TAG = "SQLiteContentProvider";
-
- private SQLiteOpenHelper mOpenHelper;
- private volatile boolean mNotifyChange;
- protected SQLiteDatabase mDb;
-
- private final ThreadLocal<Boolean> mApplyingBatch = new ThreadLocal<Boolean>();
- private static final int SLEEP_AFTER_YIELD_DELAY = 4000;
-
- /**
- * Maximum number of operations allowed in a batch between yield points.
- */
- private static final int MAX_OPERATIONS_PER_YIELD_POINT = 500;
-
- @Override
- public boolean onCreate() {
- Context context = getContext();
- mOpenHelper = getDatabaseHelper(context);
- return true;
- }
-
- protected abstract SQLiteOpenHelper getDatabaseHelper(Context context);
-
- /**
- * The equivalent of the {@link #insert} method, but invoked within a transaction.
- */
- protected abstract Uri insertInTransaction(Uri uri, ContentValues values);
-
- /**
- * The equivalent of the {@link #update} method, but invoked within a transaction.
- */
- protected abstract int updateInTransaction(Uri uri, ContentValues values, String selection,
- String[] selectionArgs);
-
- /**
- * The equivalent of the {@link #delete} method, but invoked within a transaction.
- */
- protected abstract int deleteInTransaction(Uri uri, String selection, String[] selectionArgs);
-
- protected abstract void notifyChange();
-
- protected SQLiteOpenHelper getDatabaseHelper() {
- return mOpenHelper;
- }
-
- private boolean applyingBatch() {
- return mApplyingBatch.get() != null && mApplyingBatch.get();
- }
-
- @Override
- public Uri insert(Uri uri, ContentValues values) {
- Uri result = null;
- boolean applyingBatch = applyingBatch();
- if (!applyingBatch) {
- mDb = mOpenHelper.getWritableDatabase();
- mDb.beginTransactionWithListener(this);
- try {
- result = insertInTransaction(uri, values);
- if (result != null) {
- mNotifyChange = true;
- }
- mDb.setTransactionSuccessful();
- } finally {
- mDb.endTransaction();
- }
-
- onEndTransaction();
- } else {
- result = insertInTransaction(uri, values);
- if (result != null) {
- mNotifyChange = true;
- }
- }
- return result;
- }
-
- @Override
- public int bulkInsert(Uri uri, ContentValues[] values) {
- int numValues = values.length;
- mDb = mOpenHelper.getWritableDatabase();
- mDb.beginTransactionWithListener(this);
- try {
- for (int i = 0; i < numValues; i++) {
- Uri result = insertInTransaction(uri, values[i]);
- if (result != null) {
- mNotifyChange = true;
- }
- mDb.yieldIfContendedSafely();
- }
- mDb.setTransactionSuccessful();
- } finally {
- mDb.endTransaction();
- }
-
- onEndTransaction();
- return numValues;
- }
-
- @Override
- public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
- int count = 0;
- boolean applyingBatch = applyingBatch();
- if (!applyingBatch) {
- mDb = mOpenHelper.getWritableDatabase();
- mDb.beginTransactionWithListener(this);
- try {
- count = updateInTransaction(uri, values, selection, selectionArgs);
- if (count > 0) {
- mNotifyChange = true;
- }
- mDb.setTransactionSuccessful();
- } finally {
- mDb.endTransaction();
- }
-
- onEndTransaction();
- } else {
- count = updateInTransaction(uri, values, selection, selectionArgs);
- if (count > 0) {
- mNotifyChange = true;
- }
- }
-
- return count;
- }
-
- @Override
- public int delete(Uri uri, String selection, String[] selectionArgs) {
- int count = 0;
- boolean applyingBatch = applyingBatch();
- if (!applyingBatch) {
- mDb = mOpenHelper.getWritableDatabase();
- mDb.beginTransactionWithListener(this);
- try {
- count = deleteInTransaction(uri, selection, selectionArgs);
- if (count > 0) {
- mNotifyChange = true;
- }
- mDb.setTransactionSuccessful();
- } finally {
- mDb.endTransaction();
- }
-
- onEndTransaction();
- } else {
- count = deleteInTransaction(uri, selection, selectionArgs);
- if (count > 0) {
- mNotifyChange = true;
- }
- }
- return count;
- }
-
- @Override
- public ContentProviderResult[] applyBatch(ArrayList<ContentProviderOperation> operations)
- throws OperationApplicationException {
- int ypCount = 0;
- int opCount = 0;
- mDb = mOpenHelper.getWritableDatabase();
- mDb.beginTransactionWithListener(this);
- try {
- mApplyingBatch.set(true);
- final int numOperations = operations.size();
- final ContentProviderResult[] results = new ContentProviderResult[numOperations];
- for (int i = 0; i < numOperations; i++) {
- if (++opCount >= MAX_OPERATIONS_PER_YIELD_POINT) {
- throw new OperationApplicationException(
- "Too many content provider operations between yield points. "
- + "The maximum number of operations per yield point is "
- + MAX_OPERATIONS_PER_YIELD_POINT, ypCount);
- }
- final ContentProviderOperation operation = operations.get(i);
- if (i > 0 && operation.isYieldAllowed()) {
- opCount = 0;
- if (mDb.yieldIfContendedSafely(SLEEP_AFTER_YIELD_DELAY)) {
- ypCount++;
- }
- }
- results[i] = operation.apply(this, results, i);
- }
- mDb.setTransactionSuccessful();
- return results;
- } finally {
- mApplyingBatch.set(false);
- mDb.endTransaction();
- onEndTransaction();
- }
- }
-
- public void onBegin() {
- onBeginTransaction();
- }
-
- public void onCommit() {
- beforeTransactionCommit();
- }
-
- public void onRollback() {
- // not used
- }
-
- protected void onBeginTransaction() {
- }
-
- protected void beforeTransactionCommit() {
- }
-
- protected void onEndTransaction() {
- if (mNotifyChange) {
- mNotifyChange = false;
- notifyChange();
- }
- }
-}
diff --git a/src/com/android/apps/tag/provider/TagContract.java b/src/com/android/apps/tag/provider/TagContract.java
deleted file mode 100644
index 2d66c7f..0000000
--- a/src/com/android/apps/tag/provider/TagContract.java
+++ /dev/null
@@ -1,87 +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.provider;
-
-import com.android.apps.tag.message.NdefMessageParser;
-import com.android.apps.tag.message.ParsedNdefMessage;
-
-import android.content.ContentValues;
-import android.content.Context;
-import android.net.Uri;
-import android.nfc.NdefMessage;
-import android.provider.OpenableColumns;
-
-import java.util.Locale;
-
-public class TagContract {
- public static final String AUTHORITY = "com.android.apps.tag";
- public static final Uri AUTHORITY_URI = Uri.parse("content://" + AUTHORITY);
-
- public static final class NdefMessages {
- /**
- * Utility class, cannot be instantiated.
- */
- private NdefMessages() {}
-
- /**
- * The content:// style URL for this table
- */
- public static final Uri CONTENT_URI =
- AUTHORITY_URI.buildUpon().appendPath("ndef_msgs").build();
-
- /**
- * The MIME type of {@link #CONTENT_URI} providing a directory of
- * NDEF messages.
- */
- public static final String CONTENT_TYPE = "vnd.android.cursor.dir/ndef_msg";
-
- /**
- * The MIME type of a {@link #CONTENT_URI} subdirectory of a single
- * NDEF message.
- */
- public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/ndef_msg";
-
- // columns
- 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 STARRED = "starred";
- public static final String IS_MY_TAG = "mytag";
-
- public static class MIME implements OpenableColumns {
- public static final String CONTENT_DIRECTORY_MIME = "mime";
- public static final String _ID = "_id";
- }
-
-
- /**
- * Converts an NdefMessage to ContentValues that can be insrted into this table.
- */
- public static ContentValues toValues(Context context, NdefMessage msg, boolean isStarred,
- boolean isMyTag, long date) {
- ParsedNdefMessage parsedMsg = NdefMessageParser.parse(msg);
- ContentValues values = new ContentValues();
- values.put(BYTES, msg.toByteArray());
- values.put(DATE, date);
- values.put(STARRED, isStarred ? 1 : 0);
- values.put(IS_MY_TAG, isMyTag ? 1 : 0);
- values.put(TITLE, parsedMsg.getSnippet(context, Locale.getDefault()));
- return values;
- }
- }
-}
diff --git a/src/com/android/apps/tag/provider/TagDBHelper.java b/src/com/android/apps/tag/provider/TagDBHelper.java
deleted file mode 100644
index 3cc4523..0000000
--- a/src/com/android/apps/tag/provider/TagDBHelper.java
+++ /dev/null
@@ -1,84 +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.provider;
-
-import com.android.apps.tag.provider.TagContract.NdefMessages;
-import com.google.common.annotations.VisibleForTesting;
-
-import android.content.Context;
-import android.database.sqlite.SQLiteDatabase;
-import android.database.sqlite.SQLiteOpenHelper;
-
-/**
- * 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 = 16;
-
- public static final String TABLE_NAME_NDEF_MESSAGES = "ndef_msgs";
-
- 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 " + TABLE_NAME_NDEF_MESSAGES + " (" +
- NdefMessages._ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
- NdefMessages.DATE + " INTEGER NOT NULL, " +
- NdefMessages.TITLE + " TEXT NOT NULL DEFAULT ''," +
- NdefMessages.BYTES + " BLOB NOT NULL, " +
- NdefMessages.STARRED + " INTEGER NOT NULL DEFAULT 0," + // boolean
- NdefMessages.IS_MY_TAG + " INTEGER NOT NULL DEFAULT 0" + // boolean
- ");");
- }
-
- /**
- * Drop data and recreate everything.
- */
- private void recreate(SQLiteDatabase db) {
- db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME_NDEF_MESSAGES);
- onCreate(db);
- }
-
- @Override
- public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
- if (oldVersion < 14) {
- // Pre-release version.
- recreate(db);
- db.setVersion(newVersion);
- } else if (oldVersion == 14) {
- // GB release - does not have My tags yet.
- db.execSQL("ALTER TABLE " + TABLE_NAME_NDEF_MESSAGES + " ADD COLUMN "
- + NdefMessages.IS_MY_TAG + " INTEGER NOT NULL DEFAULT 0");
- db.setVersion(newVersion);
- } else if (oldVersion < DATABASE_VERSION) {
- // Unreleased version with improperly formatted tags.
- db.execSQL("DELETE FROM " + TABLE_NAME_NDEF_MESSAGES + " WHERE "
- + NdefMessages.IS_MY_TAG + "=1");
- db.setVersion(newVersion);
- }
- }
-}
diff --git a/src/com/android/apps/tag/provider/TagProvider.java b/src/com/android/apps/tag/provider/TagProvider.java
deleted file mode 100644
index 1fd9153..0000000
--- a/src/com/android/apps/tag/provider/TagProvider.java
+++ /dev/null
@@ -1,368 +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.provider;
-
-import com.android.apps.tag.R;
-import com.android.apps.tag.provider.TagContract.NdefMessages;
-import com.google.common.base.Charsets;
-import com.google.common.base.Preconditions;
-import com.google.common.collect.ImmutableMap;
-
-import android.content.ContentUris;
-import android.content.ContentValues;
-import android.content.Context;
-import android.content.UriMatcher;
-import android.database.Cursor;
-import android.database.sqlite.SQLiteDatabase;
-import android.database.sqlite.SQLiteOpenHelper;
-import android.database.sqlite.SQLiteQueryBuilder;
-import android.net.Uri;
-import android.nfc.FormatException;
-import android.nfc.NdefMessage;
-import android.nfc.NdefRecord;
-import android.os.AsyncTask;
-import android.os.ParcelFileDescriptor;
-import android.text.TextUtils;
-import android.util.Log;
-
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.util.Map;
-
-/**
- * Stores NFC tags in a database. The contract is defined in {@link TagContract}.
- */
-public class TagProvider extends SQLiteContentProvider implements TagProviderPipeDataWriter {
- private static final String TAG = "TagProvider";
-
- private static final int NDEF_MESSAGES = 1000;
- private static final int NDEF_MESSAGES_ID = 1001;
-
- private static final int NDEF_MESSAGES_ID_MIME = 2002;
-
- private static final UriMatcher MATCHER;
-
-
- private static final Map<String, String> NDEF_MESSAGES_PROJECTION_MAP =
- ImmutableMap.<String, String>builder()
- .put(NdefMessages._ID, NdefMessages._ID)
- .put(NdefMessages.TITLE, NdefMessages.TITLE)
- .put(NdefMessages.BYTES, NdefMessages.BYTES)
- .put(NdefMessages.DATE, NdefMessages.DATE)
- .put(NdefMessages.STARRED, NdefMessages.STARRED)
- .build();
-
- private Map<String, String> mNdefRecordsMimeProjectionMap;
-
- static {
- MATCHER = new UriMatcher(0);
- String auth = TagContract.AUTHORITY;
-
- MATCHER.addURI(auth, "ndef_msgs", NDEF_MESSAGES);
- MATCHER.addURI(auth, "ndef_msgs/#", NDEF_MESSAGES_ID);
- MATCHER.addURI(auth, "ndef_msgs/#/#/mime", NDEF_MESSAGES_ID_MIME);
- }
-
- @Override
- public boolean onCreate() {
- boolean result = super.onCreate();
-
- // Build the projection map for the MIME records using a localized display name
- mNdefRecordsMimeProjectionMap = ImmutableMap.<String, String>builder()
- .put(NdefMessages.MIME._ID, NdefMessages.MIME._ID)
- .put(NdefMessages.MIME.SIZE, NdefMessages.MIME.SIZE)
- .put(NdefMessages.MIME.DISPLAY_NAME,
- "'" + getContext().getString(R.string.mime_display_name) + "' AS "
- + NdefMessages.MIME.DISPLAY_NAME)
- .build();
-
- return result;
- }
-
- @Override
- protected SQLiteOpenHelper getDatabaseHelper(Context context) {
- return new TagDBHelper(context);
- }
-
- /**
- * Appends one set of selection args to another. This is useful when adding a selection
- * argument to a user provided set.
- */
- public static String[] appendSelectionArgs(String[] originalValues, String[] newValues) {
- if (originalValues == null || originalValues.length == 0) {
- return newValues;
- }
- String[] result = new String[originalValues.length + newValues.length ];
- System.arraycopy(originalValues, 0, result, 0, originalValues.length);
- System.arraycopy(newValues, 0, result, originalValues.length, newValues.length);
- return result;
- }
-
- /**
- * Concatenates two SQL WHERE clauses, handling empty or null values.
- */
- public static String concatenateWhere(String a, String b) {
- if (TextUtils.isEmpty(a)) {
- return b;
- }
- if (TextUtils.isEmpty(b)) {
- return a;
- }
-
- return "(" + a + ") AND (" + b + ")";
- }
-
- @Override
- public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs,
- String sortOrder) {
- SQLiteDatabase db = getDatabaseHelper().getReadableDatabase();
- SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
- int match = MATCHER.match(uri);
- switch (match) {
- case NDEF_MESSAGES_ID: {
- selection = concatenateWhere(selection,
- TagDBHelper.TABLE_NAME_NDEF_MESSAGES + "._id=?");
- selectionArgs = appendSelectionArgs(selectionArgs,
- new String[] { Long.toString(ContentUris.parseId(uri)) });
- // fall through
- }
- case NDEF_MESSAGES: {
- qb.setTables(TagDBHelper.TABLE_NAME_NDEF_MESSAGES);
- qb.setProjectionMap(NDEF_MESSAGES_PROJECTION_MAP);
- break;
- }
-
- case NDEF_MESSAGES_ID_MIME: {
- selection = concatenateWhere(selection,
- TagDBHelper.TABLE_NAME_NDEF_MESSAGES + "._id=?");
- selectionArgs = appendSelectionArgs(selectionArgs,
- new String[] { Long.toString(ContentUris.parseId(uri)) });
- qb.setTables(TagDBHelper.TABLE_NAME_NDEF_MESSAGES);
- qb.setProjectionMap(mNdefRecordsMimeProjectionMap);
- break;
- }
-
- default: {
- throw new IllegalArgumentException("unkown uri " + uri);
- }
- }
-
- Cursor cursor = qb.query(db, projection, selection, selectionArgs, null, null, sortOrder);
- if (cursor != null) {
- cursor.setNotificationUri(getContext().getContentResolver(), TagContract.AUTHORITY_URI);
- }
- return cursor;
- }
-
- @Override
- protected Uri insertInTransaction(Uri uri, ContentValues values) {
- SQLiteDatabase db = getDatabaseHelper().getWritableDatabase();
- int match = MATCHER.match(uri);
- long id = -1;
- switch (match) {
- case NDEF_MESSAGES: {
- id = db.insert(TagDBHelper.TABLE_NAME_NDEF_MESSAGES, NdefMessages.TITLE, values);
- break;
- }
-
- default: {
- throw new IllegalArgumentException("unkown uri " + uri);
- }
- }
-
- if (id >= 0) {
- return ContentUris.withAppendedId(uri, id);
- }
- return null;
- }
-
- @Override
- protected int updateInTransaction(Uri uri, ContentValues values, String selection,
- String[] selectionArgs) {
- SQLiteDatabase db = getDatabaseHelper().getWritableDatabase();
- int match = MATCHER.match(uri);
- int count = 0;
- switch (match) {
- case NDEF_MESSAGES_ID: {
- selection = concatenateWhere(selection,
- TagDBHelper.TABLE_NAME_NDEF_MESSAGES + "._id=?");
- selectionArgs = appendSelectionArgs(selectionArgs,
- new String[] { Long.toString(ContentUris.parseId(uri)) });
- // fall through
- }
- case NDEF_MESSAGES: {
- count = db.update(TagDBHelper.TABLE_NAME_NDEF_MESSAGES, values, selection,
- selectionArgs);
- break;
- }
-
- default: {
- throw new IllegalArgumentException("unkown uri " + uri);
- }
- }
-
- return count;
- }
-
- @Override
- protected int deleteInTransaction(Uri uri, String selection, String[] selectionArgs) {
- SQLiteDatabase db = getDatabaseHelper().getWritableDatabase();
- int match = MATCHER.match(uri);
- int count = 0;
- switch (match) {
- case NDEF_MESSAGES_ID: {
- selection = concatenateWhere(selection,
- TagDBHelper.TABLE_NAME_NDEF_MESSAGES + "._id=?");
- selectionArgs = appendSelectionArgs(selectionArgs,
- new String[] { Long.toString(ContentUris.parseId(uri)) });
- // fall through
- }
- case NDEF_MESSAGES: {
- count = db.delete(TagDBHelper.TABLE_NAME_NDEF_MESSAGES, selection, selectionArgs);
- break;
- }
-
- default: {
- throw new IllegalArgumentException("unkown uri " + uri);
- }
- }
-
- return count;
- }
-
- private NdefRecord getRecord(Uri uri) {
- NdefRecord record = null;
-
- Cursor cursor = null;
- try {
- SQLiteDatabase db = getDatabaseHelper().getReadableDatabase();
- cursor = db.query(TagDBHelper.TABLE_NAME_NDEF_MESSAGES,
- new String[] { NdefMessages.BYTES }, "_id=?",
- new String[] { uri.getPathSegments().get(1) }, null, null, null, null);
- if (cursor.moveToFirst()) {
- NdefMessage msg = new NdefMessage(cursor.getBlob(0));
- NdefRecord[] records = msg.getRecords();
-
- int offset = Integer.parseInt(uri.getPathSegments().get(2));
-
- if (records != null && offset < records.length) {
- record = records[offset];
- }
- }
- } catch (FormatException e) {
- Log.e(TAG, "Invalid NdefMessage format", e);
- } finally {
- if (cursor != null) cursor.close();
- }
-
- return record;
- }
-
-
- @Override
- public String getType(Uri uri) {
- int match = MATCHER.match(uri);
- switch (match) {
-
- case NDEF_MESSAGES_ID: {
- return NdefMessages.CONTENT_ITEM_TYPE;
- }
- case NDEF_MESSAGES: {
- return NdefMessages.CONTENT_TYPE;
- }
-
- case NDEF_MESSAGES_ID_MIME: {
- NdefRecord record = getRecord(uri);
- if (record != null) {
- return new String(record.getType(), Charsets.US_ASCII).toLowerCase();
- }
- return null;
- }
-
- default: {
- throw new IllegalArgumentException("unknown uri " + uri);
- }
- }
- }
-
- @Override
- protected void notifyChange() {
- getContext().getContentResolver().notifyChange(TagContract.AUTHORITY_URI, null, false);
- }
-
- @Override
- public void writeMimeDataToPipe(ParcelFileDescriptor output, Uri uri) {
- NdefRecord record = getRecord(uri);
- if (record == null) return;
-
- try {
- byte[] data = record.getPayload();
- FileOutputStream os = new FileOutputStream(output.getFileDescriptor());
- os.write(data);
- os.flush();
- } catch (IOException e) {
- Log.e(TAG, "failed to write MIME data to " + uri, e);
- }
- }
-
- /**
- * A helper function for implementing {@link #openFile}, for
- * creating a data pipe and background thread allowing you to stream
- * generated data back to the client. This function returns a new
- * ParcelFileDescriptor that should be returned to the caller (the caller
- * is responsible for closing it).
- *
- * @param uri The URI whose data is to be written.
- * @param func Interface implementing the function that will actually
- * stream the data.
- * @return Returns a new ParcelFileDescriptor holding the read side of
- * the pipe. This should be returned to the caller for reading; the caller
- * is responsible for closing it when done.
- */
- public ParcelFileDescriptor openMimePipe(final Uri uri,
- final TagProviderPipeDataWriter func) throws FileNotFoundException {
- try {
- final ParcelFileDescriptor[] fds = ParcelFileDescriptor.createPipe();
-
- AsyncTask<Object, Object, Object> task = new AsyncTask<Object, Object, Object>() {
- @Override
- protected Object doInBackground(Object... params) {
- func.writeMimeDataToPipe(fds[1], uri);
- try {
- fds[1].close();
- } catch (IOException e) {
- Log.w(TAG, "Failure closing pipe", e);
- }
- return null;
- }
- };
- task.execute((Object[])null);
-
- return fds[0];
- } catch (IOException e) {
- throw new FileNotFoundException("failure making pipe");
- }
- }
-
- @Override
- public ParcelFileDescriptor openFile(Uri uri, String mode) throws FileNotFoundException {
- Preconditions.checkArgument("r".equals(mode));
- Preconditions.checkArgument(MATCHER.match(uri) == NDEF_MESSAGES_ID_MIME);
- return openMimePipe(uri, this);
- }
-}
diff --git a/src/com/android/apps/tag/provider/TagProviderPipeDataWriter.java b/src/com/android/apps/tag/provider/TagProviderPipeDataWriter.java
deleted file mode 100644
index bdecde8..0000000
--- a/src/com/android/apps/tag/provider/TagProviderPipeDataWriter.java
+++ /dev/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.provider;
-
-import android.net.Uri;
-import android.os.ParcelFileDescriptor;
-
-/**
- * Interface to write a stream of data to a pipe.
- */
-interface TagProviderPipeDataWriter {
- /**
- * Called from a background thread to stream data out to a pipe.
- * Note that the pipe is blocking, so this thread can block on
- * writes for an arbitrary amount of time if the client is slow
- * at reading.
- *
- * @param output The pipe where data should be written. This will be
- * closed for you upon returning from this function.
- * @param uri The URI whose data is to be written.
- */
- public void writeMimeDataToPipe(ParcelFileDescriptor output, Uri uri);
-}
\ No newline at end of file
diff --git a/src/com/android/apps/tag/record/AbstractTextRecordEditInfo.java b/src/com/android/apps/tag/record/AbstractTextRecordEditInfo.java
deleted file mode 100644
index 235de72..0000000
--- a/src/com/android/apps/tag/record/AbstractTextRecordEditInfo.java
+++ /dev/null
@@ -1,97 +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 com.android.apps.tag.R;
-import com.google.common.base.Preconditions;
-
-import android.app.Activity;
-import android.content.Context;
-import android.content.Intent;
-import android.os.Parcel;
-import android.text.Editable;
-import android.text.TextWatcher;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewGroup;
-import android.widget.EditText;
-
-public abstract class AbstractTextRecordEditInfo extends RecordEditInfo implements TextWatcher {
- private String mCurrentValue;
- private EditText mEditText;
-
- public AbstractTextRecordEditInfo(String initialValue) {
- super(UriRecord.RECORD_TYPE);
- mCurrentValue = Preconditions.checkNotNull(initialValue);
- }
-
- public AbstractTextRecordEditInfo(Parcel parcel) {
- super(parcel);
- mCurrentValue = parcel.readString();
- }
-
- public String getCurrentText() {
- return mCurrentValue;
- }
-
- @Override
- public Intent getPickIntent() {
- return null;
- }
-
- @Override
- public void handlePickResult(Context context, Intent data) {
- // Not supported.
- }
-
- public abstract int getLayoutId();
-
- @Override
- public View getEditView(
- Activity activity, LayoutInflater inflater,
- ViewGroup parent, EditCallbacks callbacks) {
- View view = buildEditView(activity, inflater, getLayoutId(), parent, callbacks);
- mEditText = (EditText) view.findViewById(R.id.value);
- mEditText.setText(mCurrentValue);
- mEditText.addTextChangedListener(this);
- return view;
- }
-
- @Override
- public void writeToParcel(Parcel out, int flags) {
- super.writeToParcel(out, flags);
- out.writeString(mCurrentValue);
- }
-
- @Override
- public int describeContents() {
- return 0;
- }
-
- @Override
- public void afterTextChanged(Editable s) {
- mCurrentValue = s.toString();
- }
-
- @Override
- public void beforeTextChanged(CharSequence s, int start, int count, int after) {
- }
-
- @Override
- public void onTextChanged(CharSequence s, int start, int before, int count) {
- }
-}
\ No newline at end of file
diff --git a/src/com/android/apps/tag/record/ParsedNdefRecord.java b/src/com/android/apps/tag/record/ParsedNdefRecord.java
index 85cd4e3..1f0fa2f 100644
--- a/src/com/android/apps/tag/record/ParsedNdefRecord.java
+++ b/src/com/android/apps/tag/record/ParsedNdefRecord.java
@@ -37,14 +37,6 @@
public abstract View getView(Activity activity, LayoutInflater inflater, ViewGroup parent,
int offset);
- // TODO: make abstract.
- /**
- * Returns a {@link RecordEditInfo} for editing this record.
- */
- public RecordEditInfo getEditInfo(Activity activity) {
- return null;
- }
-
public String getSnippet(Context context, Locale locale) {
return context.getString(R.string.tag_unknown);
}
diff --git a/src/com/android/apps/tag/record/RecordEditInfo.java b/src/com/android/apps/tag/record/RecordEditInfo.java
deleted file mode 100644
index a5ecbbe..0000000
--- a/src/com/android/apps/tag/record/RecordEditInfo.java
+++ /dev/null
@@ -1,114 +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 com.android.apps.tag.R;
-
-import android.app.Activity;
-import android.content.Context;
-import android.content.Intent;
-import android.nfc.NdefRecord;
-import android.os.Parcel;
-import android.os.Parcelable;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewGroup;
-
-/**
- * A simple holder for information required for editing a {@code ParsedNdefRecord}.
- */
-public abstract class RecordEditInfo implements Parcelable, View.OnClickListener {
-
- public interface EditCallbacks {
- void startPickForRecord(RecordEditInfo info, Intent intent);
- void deleteRecord(RecordEditInfo info);
- }
-
- /**
- * The record type being edited.
- */
- private final String mType;
-
- protected EditCallbacks mCallbacks;
-
- public RecordEditInfo(String type) {
- mType = type;
- }
-
- protected RecordEditInfo(Parcel parcel) {
- mType = parcel.readString();
- }
-
- public String getType() {
- return mType;
- }
-
- /**
- * Returns the current value of the record in edit. Can be {@code null} if not fully inputted
- * by user, or the value is invalid for any reason.
- */
- public abstract NdefRecord getValue();
-
- /**
- * An {@link Intent} which can be fired to retrieve content for the {@code ParsedNdefRecord}.
- * Can be null, if no external {@link Activity} is required.
- */
- public abstract Intent getPickIntent();
-
- /**
- * Handles a pick {@link Intent}. Must be fully implemented if {@link #getPickIntent} returns
- * a non-null value.
- */
- public abstract void handlePickResult(Context context, Intent data);
-
- /**
- * Builds a {@link View} that can edit an underlying record, or launch a picker to change
- * the value of the record.
- * This {@code RecordEditInfo} will be set as the {@link View}'s tag.
- */
- public abstract View getEditView(
- Activity activity, LayoutInflater inflater, ViewGroup parent, EditCallbacks callbacks);
-
- /**
- * Does the work of building a {@link View} and binding common controls.
- */
- protected View buildEditView(
- Activity activity, LayoutInflater inflater, int resourceId,
- ViewGroup parent, EditCallbacks callbacks) {
- View result = inflater.inflate(resourceId, parent, false);
- result.setTag(this);
-
- View deleteButton = result.findViewById(R.id.delete);
- if (deleteButton != null) {
- deleteButton.setOnClickListener(this);
- }
- mCallbacks = callbacks;
- return result;
- }
-
- @Override
- public void writeToParcel(Parcel out, int flags) {
- out.writeString(mType);
- }
-
- @Override
- public void onClick(View target) {
- if (target.getId() == R.id.delete) {
- mCallbacks.deleteRecord(this);
- }
- }
-}
diff --git a/src/com/android/apps/tag/record/TextRecord.java b/src/com/android/apps/tag/record/TextRecord.java
index 519c221..1ecdec3 100644
--- a/src/com/android/apps/tag/record/TextRecord.java
+++ b/src/com/android/apps/tag/record/TextRecord.java
@@ -17,7 +17,6 @@
package com.android.apps.tag.record;
import com.android.apps.tag.R;
-import com.android.apps.tag.record.UriRecord.UriRecordEditInfo;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
import com.google.common.primitives.Bytes;
@@ -86,24 +85,6 @@
return mLanguageCode;
}
- @Override
- public RecordEditInfo getEditInfo(Activity host) {
- return new TextRecordEditInfo(mText);
- }
-
- /**
- * Returns a view in a list of record types for adding new records to a message.
- */
- public static View getAddView(Context context, LayoutInflater inflater, ViewGroup parent) {
- ViewGroup root = (ViewGroup) inflater.inflate(
- R.layout.tag_add_record_list_item, parent, false);
- ((ImageView) root.findViewById(R.id.image)).setImageResource(R.drawable.ic_launcher_nfc);
- ((TextView) root.findViewById(R.id.text)).setText(context.getString(R.string.tag_text));
-
- root.setTag(new TextRecordEditInfo(""));
- return root;
- }
-
// TODO: deal with text fields which span multiple NdefRecords
public static TextRecord parse(NdefRecord record) {
Preconditions.checkArgument(record.getTnf() == NdefRecord.TNF_WELL_KNOWN);
@@ -178,39 +159,4 @@
return new NdefRecord(NdefRecord.TNF_WELL_KNOWN, NdefRecord.RTD_TEXT, new byte[0], data);
}
-
- public static class TextRecordEditInfo extends AbstractTextRecordEditInfo {
- public TextRecordEditInfo(String text) {
- super(text);
- }
-
- public TextRecordEditInfo(Parcel in) {
- super(in);
- }
-
- @Override
- public int getLayoutId() {
- return R.layout.tag_edit_text;
- }
-
- @Override
- public NdefRecord getValue() {
- String text = getCurrentText();
- if (TextUtils.isEmpty(text)) text = "";
- return TextRecord.newTextRecord(text, Locale.getDefault(), true);
- }
-
- public static final Parcelable.Creator<TextRecordEditInfo> CREATOR =
- new Parcelable.Creator<TextRecordEditInfo>() {
- @Override
- public TextRecordEditInfo createFromParcel(Parcel in) {
- return new TextRecordEditInfo(in);
- }
-
- @Override
- public TextRecordEditInfo[] newArray(int size) {
- return new TextRecordEditInfo[size];
- }
- };
- }
}
diff --git a/src/com/android/apps/tag/record/UriRecord.java b/src/com/android/apps/tag/record/UriRecord.java
index cf0f23d..f7e152f 100644
--- a/src/com/android/apps/tag/record/UriRecord.java
+++ b/src/com/android/apps/tag/record/UriRecord.java
@@ -145,11 +145,6 @@
}
@Override
- public RecordEditInfo getEditInfo(Activity host) {
- return new UriRecordEditInfo(mUri.toString());
- }
-
- @Override
public String getSnippet(Context context, Locale locale) {
return getPrettyUriString(context);
}
@@ -166,29 +161,6 @@
}
}
- /**
- * Returns a view in a list of record types for adding new records to a message.
- */
- public static View getAddView(Context context, LayoutInflater inflater, ViewGroup parent) {
- ViewGroup root = (ViewGroup) inflater.inflate(
- R.layout.tag_add_record_list_item, parent, false);
-
- // Determine which Activity can open up normal URL's.
- Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.google.com"));
- PackageManager pm = context.getPackageManager();
- List<ResolveInfo> activities = pm.queryIntentActivities(intent, 0);
- if (activities.isEmpty()) {
- return null;
- }
-
- ResolveInfo info = activities.get(0);
- ((ImageView) root.findViewById(R.id.image)).setImageDrawable(info.loadIcon(pm));
- ((TextView) root.findViewById(R.id.text)).setText(context.getString(R.string.url));
-
- root.setTag(new UriRecordEditInfo(""));
- return root;
- }
-
@VisibleForTesting
public Uri getUri() {
return mUri;
@@ -276,40 +248,4 @@
return new NdefRecord(NdefRecord.TNF_WELL_KNOWN,
NdefRecord.RTD_URI, EMPTY, payload);
}
-
- public static class UriRecordEditInfo extends AbstractTextRecordEditInfo {
- public UriRecordEditInfo(String uri) {
- super(uri);
- }
-
- public UriRecordEditInfo(Parcel in) {
- super(in);
- }
-
- @Override
- public int getLayoutId() {
- return R.layout.tag_edit_url;
- }
-
- @Override
- public NdefRecord getValue() {
- String text = getCurrentText();
- if (TextUtils.isEmpty(text)) text = "";
- return UriRecord.newUriRecord(Uri.parse(text));
- }
-
- @SuppressWarnings("unused")
- public static final Parcelable.Creator<UriRecordEditInfo> CREATOR =
- new Parcelable.Creator<UriRecordEditInfo>() {
- @Override
- public UriRecordEditInfo createFromParcel(Parcel in) {
- return new UriRecordEditInfo(in);
- }
-
- @Override
- public UriRecordEditInfo[] newArray(int size) {
- return new UriRecordEditInfo[size];
- }
- };
- }
}
diff --git a/src/com/android/apps/tag/record/VCardRecord.java b/src/com/android/apps/tag/record/VCardRecord.java
index 4a6adbc..9b96807 100644
--- a/src/com/android/apps/tag/record/VCardRecord.java
+++ b/src/com/android/apps/tag/record/VCardRecord.java
@@ -149,33 +149,6 @@
return intent;
}
- /**
- * Returns a view in a list of record types for adding new records to a message.
- */
- public static View getAddView(Context context, LayoutInflater inflater, ViewGroup parent) {
- ViewGroup root = (ViewGroup) inflater.inflate(
- R.layout.tag_add_record_list_item, parent, false);
-
- Intent intent = getPickContactIntent();
- PackageManager pm = context.getPackageManager();
- List<ResolveInfo> activities = pm.queryIntentActivities(intent, 0);
- if (activities.isEmpty()) {
- return null;
- }
-
- ResolveInfo info = activities.get(0);
- ((ImageView) root.findViewById(R.id.image)).setImageDrawable(info.loadIcon(pm));
- ((TextView) root.findViewById(R.id.text)).setText(context.getString(R.string.contact));
-
- root.setTag(new VCardRecordEditInfo());
- return root;
- }
-
- @Override
- public RecordEditInfo getEditInfo(Activity host) {
- return new VCardRecordEditInfo(mVCard);
- }
-
public static VCardRecord parse(NdefRecord record) {
MimeRecord underlyingRecord = MimeRecord.parse(record);
@@ -208,275 +181,4 @@
return false;
}
}
-
- public static VCardRecordEditInfo editInfoForUri(Uri vcardUri) {
- if (vcardUri.toString().startsWith(
- ContactsContract.Contacts.CONTENT_VCARD_URI.toString())) {
- String lookupKey = vcardUri.getLastPathSegment();
- Uri lookupUri = Uri.withAppendedPath(
- ContactsContract.Contacts.CONTENT_LOOKUP_URI, lookupKey);
- return new VCardRecord.VCardRecordEditInfo(lookupUri);
- }
- return null;
- }
-
- private static class VCardRecordEditInfo extends RecordEditInfo {
- /**
- * The lookup {@link Uri} if the data is to be pulled from the contact provider.
- * Can be null if {@link #mValue} is filled in by other means externally.
- * @see ContactsContract
- */
- private Uri mLookupUri;
-
- /**
- * The raw VCard bytes.
- */
- private byte[] mValue;
-
- private WeakReference<View> mActiveView = null;
-
- private String mCachedName = null;
- private Drawable mCachedPhoto = null;
-
- /**
- * Data
- */
- private static final class CacheData {
- public String mName;
- public Drawable mPhoto;
- public byte[] mVcard;
- }
-
- public VCardRecordEditInfo() {
- super(RECORD_TYPE);
- }
-
- public VCardRecordEditInfo(Uri lookupUri) {
- super(RECORD_TYPE);
- mLookupUri = lookupUri;
- mValue = null;
- }
-
- public VCardRecordEditInfo(byte[] value) {
- super(RECORD_TYPE);
- mLookupUri = null;
- mValue = Preconditions.checkNotNull(value);
- }
-
- protected VCardRecordEditInfo(Parcel parcel) {
- super(parcel);
- mLookupUri = parcel.readParcelable(null);
- int valueLength = parcel.readInt();
- if (valueLength > 0) {
- mValue = new byte[valueLength];
- parcel.readByteArray(mValue);
- }
- }
-
- @Override
- public Intent getPickIntent() {
- return getPickContactIntent();
- }
-
- private void extractValuesFromBytes(final Context context) {
- byte[] bytes = Preconditions.checkNotNull(mValue);
-
- final int type = VCardConfig.VCARD_TYPE_UNKNOWN;
- final VCardEntryConstructor constructor = new VCardEntryConstructor(type);
- constructor.addEntryHandler(new VCardEntryHandler() {
- @Override public void onStart() {}
- @Override public void onEnd() {}
-
- @Override
- public void onEntryCreated(VCardEntry entry) {
- mCachedName = entry.getDisplayName();
- List<VCardEntry.PhotoData> photoList = entry.getPhotoList();
- if (photoList != null && !photoList.isEmpty()) {
- byte[] rawData = photoList.get(0).getBytes();
- mCachedPhoto = new BitmapDrawable(
- context.getResources(),
- BitmapFactory.decodeByteArray(rawData, 0, rawData.length));
- }
- bindView();
- }
- });
-
- VCardParser parser = new VCardParser_V21(type);
- try {
- parser.parse(new ByteArrayInputStream(bytes), constructor);
- } catch (IOException e) {
- } catch (VCardException e) {
- }
- }
-
- private void fetchValuesFromProvider(final Context context) {
- if (mValue != null) {
- bindView();
- return;
- }
-
- new AsyncTask<Uri, Void, CacheData>() {
- @Override
- protected CacheData doInBackground(Uri... params) {
- Cursor cursor = null;
- long id;
- String lookupKey = null;
- Uri lookupUri = params[0];
- CacheData result = new CacheData();
- try {
- String[] projection = {
- ContactsContract.Contacts._ID,
- ContactsContract.Contacts.LOOKUP_KEY,
- ContactsContract.Contacts.DISPLAY_NAME
- };
- cursor = context.getContentResolver().query(
- lookupUri, projection, null, null, null);
- cursor.moveToFirst();
- id = cursor.getLong(0);
- lookupKey = cursor.getString(1);
- result.mName = cursor.getString(2);
-
- } finally {
- if (cursor != null) {
- cursor.close();
- cursor = null;
- }
- }
-
- if (lookupKey == null) {
- // TODO: handle errors.
- return null;
- }
-
- // Note: the lookup key should already encoded.
- Uri vcardUri = Uri.withAppendedPath(
- ContactsContract.Contacts.CONTENT_VCARD_URI,
- lookupKey);
-
- AssetFileDescriptor descriptor;
- FileInputStream in = null;
- try {
- descriptor = context.getContentResolver().openAssetFileDescriptor(
- vcardUri, "r");
- result.mVcard = new byte[(int) descriptor.getLength()];
-
- in = descriptor.createInputStream();
- in.read(result.mVcard);
- in.close();
- } catch (FileNotFoundException e) {
- return null;
- } catch (IOException e) {
- return null;
- }
-
- Uri contactUri = ContentUris.withAppendedId(
- ContactsContract.Contacts.CONTENT_URI, id);
- InputStream photoIn = ContactsContract.Contacts.openContactPhotoInputStream(
- context.getContentResolver(), contactUri);
- if (photoIn != null) {
- result.mPhoto = Drawable.createFromStream(photoIn, contactUri.toString());
- }
- return result;
- }
-
- @Override
- protected void onPostExecute(CacheData data) {
- if (data == null) {
- return;
- }
-
- mCachedName = data.mName;
- mValue = data.mVcard;
- mCachedPhoto = data.mPhoto;
- bindView();
- }
- }.execute(mLookupUri);
- }
-
- @Override
- public NdefRecord getValue() {
- return (mValue == null) ? null : VCardRecord.newVCardRecord(mValue);
- }
-
- @Override
- public void handlePickResult(Context context, Intent data) {
- mLookupUri = data.getData();
- mValue = null;
- mCachedName = null;
- mCachedPhoto = null;
- }
-
- private void bindView() {
- View view = (mActiveView == null) ? null : mActiveView.get();
- if (view == null) {
- return;
- }
-
- if (mCachedPhoto != null) {
- ((ImageView) view.findViewById(R.id.photo)).setImageDrawable(mCachedPhoto);
- }
-
- if (mCachedName != null) {
- ((TextView) view.findViewById(R.id.display_name)).setText(mCachedName);
- }
- }
-
- @Override
- public View getEditView(
- Activity activity, LayoutInflater inflater,
- ViewGroup parent, EditCallbacks callbacks) {
- View result = buildEditView(
- activity, inflater, R.layout.tag_edit_vcard, parent, callbacks);
-
- mActiveView = new WeakReference<View>(result);
- result.setOnClickListener(this);
-
- // Show default contact photo until the data loads.
- ((ImageView) result.findViewById(R.id.photo)).setImageDrawable(
- activity.getResources().getDrawable(R.drawable.default_contact_photo));
-
- if (mLookupUri != null) {
- fetchValuesFromProvider(activity);
- } else if (mValue != null) {
- extractValuesFromBytes(activity);
- }
- return result;
- }
-
- @Override
- public void writeToParcel(Parcel out, int flags) {
- super.writeToParcel(out, flags);
- out.writeParcelable(mLookupUri, flags);
- out.writeInt(mValue == null ? 0 : mValue.length);
- out.writeByteArray(mValue);
- }
-
- @SuppressWarnings("unused")
- public static final Parcelable.Creator<VCardRecordEditInfo> CREATOR =
- new Parcelable.Creator<VCardRecordEditInfo>() {
- @Override
- public VCardRecordEditInfo createFromParcel(Parcel in) {
- return new VCardRecordEditInfo(in);
- }
-
- @Override
- public VCardRecordEditInfo[] newArray(int size) {
- return new VCardRecordEditInfo[size];
- }
- };
-
- @Override
- public int describeContents() {
- return 0;
- }
-
- @Override
- public void onClick(View target) {
- if (this == target.getTag()) {
- mCallbacks.startPickForRecord(this, getPickIntent());
- } else {
- super.onClick(target);
- }
- }
- }
}
diff --git a/tests/Android.mk b/tests/Android.mk
deleted file mode 100644
index 4ea20c6..0000000
--- a/tests/Android.mk
+++ /dev/null
@@ -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 := TagTests
-
-LOCAL_MODULE_TAGS := tests
-
-LOCAL_INSTRUMENTATION_FOR := Tag
-
-include $(BUILD_PACKAGE)
diff --git a/tests/AndroidManifest.xml b/tests/AndroidManifest.xml
deleted file mode 100644
index 63ef9e3..0000000
--- a/tests/AndroidManifest.xml
+++ /dev/null
@@ -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>
diff --git a/tests/build.properties b/tests/build.properties
deleted file mode 100644
index e0c39de..0000000
--- a/tests/build.properties
+++ /dev/null
@@ -1 +0,0 @@
-tested.project.dir=..
diff --git a/tests/src/com/android/apps/tag/MockNdefMessages.java b/tests/src/com/android/apps/tag/MockNdefMessages.java
deleted file mode 100644
index 90329a3..0000000
--- a/tests/src/com/android/apps/tag/MockNdefMessages.java
+++ /dev/null
@@ -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.
- */
- public 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.
- */
- public 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.
- */
- public 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.
- */
- public 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.
- */
- public 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.
- */
- public 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.
- */
- public 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
- };
-
-}
diff --git a/tests/src/com/android/apps/tag/SmartPosterTest.java b/tests/src/com/android/apps/tag/SmartPosterTest.java
deleted file mode 100644
index 9a5e644..0000000
--- a/tests/src/com/android/apps/tag/SmartPosterTest.java
+++ /dev/null
@@ -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());
- }
-}
diff --git a/tests/src/com/android/apps/tag/TagsTest.java b/tests/src/com/android/apps/tag/TagsTest.java
deleted file mode 100644
index 368df91..0000000
--- a/tests/src/com/android/apps/tag/TagsTest.java
+++ /dev/null
@@ -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());
- }
-}
diff --git a/tests/src/com/android/apps/tag/record/MimeRecordTest.java b/tests/src/com/android/apps/tag/record/MimeRecordTest.java
deleted file mode 100644
index 13194c0..0000000
--- a/tests/src/com/android/apps/tag/record/MimeRecordTest.java
+++ /dev/null
@@ -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.record;
-
-import android.nfc.NdefMessage;
-import android.test.AndroidTestCase;
-
-import com.android.apps.tag.MockNdefMessages;
-
-/**
- * Unittests for {@link MimeRecord}.
- */
-public class MimeRecordTest extends AndroidTestCase {
-
- public void testVCardMimeEntry() throws Exception {
- NdefMessage msg = new NdefMessage(MockNdefMessages.VCARD);
- MimeRecord record = MimeRecord.parse(msg.getRecords()[0]);
- assertEquals("text/x-vCard", record.getMimeType());
- String expectedRecord = "BEGIN:VCARD\r\n"
- + "VERSION:3.0\r\n"
- + "FN:Joe Google Employee\r\n"
- + "ADR;TYPE=WORK:;;1600 Amphitheatre Parkway;94043 Mountain View\r\n"
- + "TEL;TYPE=PREF,WORK:650-253-0000\r\n"
- + "EMAIL;TYPE=INTERNET:support@google.com\r\n"
- + "TITLE:Software Engineer\r\n"
- + "ORG:Google\r\n"
- + "URL:http://www.google.com\r\n"
- + "END:VCARD\r\n";
- assertEquals(expectedRecord, new String(record.getContent(), "UTF-8"));
- }
-
- public void testIsMime() throws Exception {
- NdefMessage msg = new NdefMessage(MockNdefMessages.VCARD);
- assertTrue(MimeRecord.isMime(msg.getRecords()[0]));
- }
-
- public void testIsNotMime() throws Exception {
- NdefMessage msg = new NdefMessage(MockNdefMessages.REAL_NFC_MSG);
- assertFalse(MimeRecord.isMime(msg.getRecords()[0]));
- }
-}
diff --git a/tests/src/com/android/apps/tag/record/TextRecordTest.java b/tests/src/com/android/apps/tag/record/TextRecordTest.java
deleted file mode 100644
index 1fd5a95..0000000
--- a/tests/src/com/android/apps/tag/record/TextRecordTest.java
+++ /dev/null
@@ -1,71 +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.NdefMessage;
-import android.nfc.NdefRecord;
-import android.test.AndroidTestCase;
-
-import com.android.apps.tag.MockNdefMessages;
-
-import java.util.Locale;
-
-/**
- * Tests for {@link TextRecord}
- */
-public class TextRecordTest extends AndroidTestCase {
-
- // Îñţérñåţîöñåļîžåţîờñ
- private static final String I18N = "\\u00ce\\u00f1\\u0163\\u00e9r\\u00f1\\u00e5"
- + "\\u0163\\u00ee\\u00f6\\u00f1\\u00e5\\u013c\\u00ee\\u017e\\u00e5"
- + "\\u0163\\u00ee\\u1edd\\u00f1";
-
- public void testSimpleText() throws Exception {
- NdefMessage msg = new NdefMessage(MockNdefMessages.ENGLISH_PLAIN_TEXT);
- TextRecord record = TextRecord.parse(msg.getRecords()[0]);
- assertEquals("Some random english text.", record.getText());
- assertEquals("en", record.getLanguageCode());
- }
-
- public void testNewNdefMsg() throws Exception {
- NdefRecord record = TextRecord.newTextRecord("hello", Locale.US);
- TextRecord textRecord = TextRecord.parse(record);
- assertEquals("hello", textRecord.getText());
- assertEquals("en", textRecord.getLanguageCode());
- }
-
- public void testToText2() throws Exception {
- NdefRecord record = TextRecord.newTextRecord("Hello", Locale.US, false);
- TextRecord textRecord = TextRecord.parse(record);
- assertEquals("Hello", textRecord.getText());
- assertEquals("en", textRecord.getLanguageCode());
- }
-
- public void testToText3() throws Exception {
- NdefRecord record = TextRecord.newTextRecord(I18N, Locale.CHINA, true);
- TextRecord textRecord = TextRecord.parse(record);
- assertEquals(I18N, textRecord.getText());
- assertEquals("zh", textRecord.getLanguageCode());
- }
-
- public void testToText4() throws Exception {
- NdefRecord record = TextRecord.newTextRecord(I18N, Locale.CHINA, false);
- TextRecord textRecord = TextRecord.parse(record);
- assertEquals(I18N, textRecord.getText());
- assertEquals("zh", textRecord.getLanguageCode());
- }
-}