A skeletal, non-functional UI for the "My Tag" editor.
Ben Komalo [Tue, 19 Oct 2010 05:15:27 +0000 (22:15 -0700)]
Does not persist any actual data to the local NdefMessage, nor
read it yet.

Change-Id: Ie4c5d0900a0c2ba24c34a5ef19c2ae7b668bb176

AndroidManifest.xml
res/drawable-hdpi/ic_tab_my_tag.png [new file with mode: 0644]
res/drawable-mdpi/ic_tab_my_tag.png [new file with mode: 0644]
res/layout/my_tag_activity.xml [new file with mode: 0644]
res/values/strings.xml
src/com/android/apps/tag/MyTagActivity.java [new file with mode: 0644]
src/com/android/apps/tag/TagBrowserActivity.java

index 168d415..6bebe3e 100644 (file)
@@ -56,6 +56,8 @@
             </intent-filter>
         </activity>
 
+        <activity android:name="MyTagActivity" />
+
         <service android:name="TagService" />
 
         <provider android:name=".provider.TagProvider"
diff --git a/res/drawable-hdpi/ic_tab_my_tag.png b/res/drawable-hdpi/ic_tab_my_tag.png
new file mode 100644 (file)
index 0000000..15fbdfc
Binary files /dev/null and b/res/drawable-hdpi/ic_tab_my_tag.png differ
diff --git a/res/drawable-mdpi/ic_tab_my_tag.png b/res/drawable-mdpi/ic_tab_my_tag.png
new file mode 100644 (file)
index 0000000..342a1f0
Binary files /dev/null and b/res/drawable-mdpi/ic_tab_my_tag.png differ
diff --git a/res/layout/my_tag_activity.xml b/res/layout/my_tag_activity.xml
new file mode 100644 (file)
index 0000000..d9f67bb
--- /dev/null
@@ -0,0 +1,135 @@
+<?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="4dip"
+        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:padding="12dip"
+            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>
+
+    <View
+        android:layout_width="match_parent"
+        android:layout_height="1dip"
+        android:background="?android:attr/listDivider" />
+
+    <!-- Tag title -->
+    <LinearLayout
+        android:padding="8dip"
+        android:orientation="vertical"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content" >
+
+        <TextView
+            android:text="@string/tag_title"
+            android:textAppearance="?android:attr/textAppearanceMedium"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content" />
+
+        <EditText
+            android:id="@+id/input_tag_title"
+            android:inputType="textMultiLine"
+            android:lines="1"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content" />
+
+    </LinearLayout>
+
+    <View
+        android:layout_width="match_parent"
+        android:layout_height="1dip"
+        android:background="?android:attr/listDivider" />
+
+    <!-- Tag text -->
+    <LinearLayout
+        android:padding="8dip"
+        android:orientation="vertical"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content" >
+
+        <TextView
+            android:text="@string/tag_text"
+            android:id="@+id/input_tag_text"
+            android:textAppearance="?android:attr/textAppearanceMedium"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content" />
+
+        <EditText
+            android:inputType="textMultiLine"
+            android:lines="2"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content" />
+
+    </LinearLayout>
+
+    <View
+        android:layout_width="match_parent"
+        android:layout_height="1dip"
+        android:background="?android:attr/listDivider" />
+
+    <!-- Control to add content. -->
+    <TextView
+        android:id="@+id/add_content_target"
+        android:text="@string/add_content"
+        android:textAppearance="?android:attr/textAppearanceMedium"
+        android:padding="16dip"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content" />
+
+    <View
+        android:layout_width="match_parent"
+        android:layout_height="1dip"
+        android:background="?android:attr/listDivider" />
+
+</LinearLayout>
index 6264252..cb77fd4 100644 (file)
@@ -31,6 +31,9 @@
     <!-- 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>
 
 
     <!-- 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">Turn on my tag</string>
+
+    <!-- Description for the control which enables/disables the "my tag" feature. -->
+    <string name="turn_on_my_tag_subtitle">Display tag content to other devices</string>
+
+    <!-- Label for control which adds content to the "my tag" feature. -->
+    <string name="add_content">Add other content&#8230;</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>
 </resources>
diff --git a/src/com/android/apps/tag/MyTagActivity.java b/src/com/android/apps/tag/MyTagActivity.java
new file mode 100644 (file)
index 0000000..9fba324
--- /dev/null
@@ -0,0 +1,113 @@
+/*
+ * 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.record.ParsedNdefRecord;
+import com.android.apps.tag.record.TextRecord;
+
+import android.app.Activity;
+import android.nfc.NdefMessage;
+import android.nfc.NfcAdapter;
+import android.os.Bundle;
+import android.util.Log;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.widget.CheckBox;
+import android.widget.EditText;
+import android.widget.Toast;
+
+import java.util.List;
+
+/**
+ * Editor {@link Activity} for the tag that can be programmed into the device.
+ */
+public class MyTagActivity extends Activity implements OnClickListener {
+
+    private static final String LOG_TAG = "TagEditor";
+
+    @Override
+    protected void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+
+        setContentView(R.layout.my_tag_activity);
+
+        findViewById(R.id.toggle_enabled_target).setOnClickListener(this);
+        findViewById(R.id.add_content_target).setOnClickListener(this);
+    }
+
+    @Override
+    public void onStart() {
+        super.onStart();
+
+        // Populate tag editor from stored tag info.
+        NdefMessage localMessage = NfcAdapter.getDefaultAdapter().getLocalNdefMessage();
+        if (localMessage == null) {
+            return;
+        }
+
+        ParsedNdefMessage parsed = NdefMessageParser.parse(localMessage);
+
+        // There is always a "Title" and a "Text" record for the local message, if it exists.
+        List<ParsedNdefRecord> records = parsed.getRecords();
+        if (records.size() < 2) {
+            Log.w(LOG_TAG, "Local record not in expected format");
+            return;
+        }
+        TextRecord titleRecord = (TextRecord) records.get(0);
+        TextRecord textRecord = (TextRecord) records.get(1);
+
+        ((EditText) findViewById(R.id.input_tag_title)).setText(titleRecord.getText());
+        ((EditText) findViewById(R.id.input_tag_text)).setText(textRecord.getText());
+    }
+
+    /**
+     * Persists content to store.
+     */
+    private void onSave() {
+        // TODO: persist to NfcAdapter.setLocalNdefMessage(NdefMessage message);
+    }
+
+    @Override
+    public void onPause() {
+        super.onPause();
+        onSave();
+    }
+
+    @Override
+    public void onClick(View target) {
+        switch (target.getId()) {
+            case R.id.toggle_enabled_target:
+                CheckBox checkbox = ((CheckBox) target.findViewById(R.id.toggle_enabled_checkbox));
+                boolean enabled = !checkbox.isChecked();
+                checkbox.setChecked(enabled);
+
+                // TODO: Persist to some store.
+                Toast.makeText(this,
+                        "Just " + (enabled ? "enabled" : "disabled") + " NFC MyTag",
+                        Toast.LENGTH_SHORT).show();
+                break;
+
+            case R.id.add_content_target:
+                Toast.makeText(this,
+                        "Adding content coming real soon...",
+                        Toast.LENGTH_SHORT).show();
+                break;
+        }
+    }
+}
index eb21113..03c91b2 100644 (file)
@@ -48,6 +48,11 @@ public class TagBrowserActivity extends TabActivity {
                         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, MyTagActivity.class)));
     }
 
     @Override