Kill MyTagActivity and merge it into EditTagActivity.
(making way for a new MyTagActivity that is the list and
 manager for MyTag)

Change-Id: I86a6580b7210549eb6fc60c00daf0aa6ea6e6bdc
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 8410b20..54a9bc9 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -59,7 +59,7 @@
             </intent-filter>
         </activity>
 
-        <activity android:name="MyTagActivity" android:label="@string/tab_my_tag">
+        <activity android:name="EditTagActivity" android:label="@string/tab_my_tag">
             <intent-filter>
                 <action android:name="android.intent.action.SEND"/>
                 <category android:name="android.intent.category.DEFAULT"/>
diff --git a/res/layout/my_tag_activity.xml b/res/layout/edit_tag_activity.xml
similarity index 100%
rename from res/layout/my_tag_activity.xml
rename to res/layout/edit_tag_activity.xml
diff --git a/src/com/android/apps/tag/EditTagActivity.java b/src/com/android/apps/tag/EditTagActivity.java
index 50c4df9..b6d9cde 100644
--- a/src/com/android/apps/tag/EditTagActivity.java
+++ b/src/com/android/apps/tag/EditTagActivity.java
@@ -16,12 +16,15 @@
 
 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.ImageRecord;
 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.UriRecord;
 import com.android.apps.tag.record.VCardRecord;
+import com.android.apps.tag.record.RecordEditInfo.EditCallbacks;
 import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.Lists;
@@ -29,14 +32,26 @@
 import android.app.Activity;
 import android.app.Dialog;
 import android.content.Intent;
+import android.net.Uri;
 import android.nfc.NdefMessage;
 import android.nfc.NdefRecord;
+import android.nfc.NfcAdapter;
 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 android.view.View.OnClickListener;
+import android.widget.CheckBox;
+import android.widget.EditText;
+
+import java.net.MalformedURLException;
+import java.net.URL;
 import java.util.ArrayList;
+import java.util.List;
+import java.util.Locale;
 import java.util.Set;
 
 /**
@@ -46,10 +61,11 @@
  * {@link ParsedNdefRecord} types. Each type of {@link ParsedNdefRecord} can build views to
  * pick/select a new piece of content, or edit an existing content for the {@link NdefMessage}.
  */
-public abstract class EditTagActivity extends Activity implements OnClickListener, EditCallbacks {
+public class EditTagActivity extends Activity implements OnClickListener, EditCallbacks {
 
     private static final String BUNDLE_KEY_OUTSTANDING_PICK = "outstanding-pick";
     protected static final int DIALOG_ID_ADD_CONTENT = 0;
+    private static final String LOG_TAG = "Tags";
 
     private static final Set<String> SUPPORTED_RECORD_TYPES = ImmutableSet.of(
         ImageRecord.RECORD_TYPE,
@@ -72,23 +88,35 @@
      */
     private RecordEditInfo mRecordWithOutstandingPick;
 
+    /**
+     * 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 EditText mTextView;
+    private CheckBox mEnabled;
+
     private LayoutInflater mInflater;
 
     @Override
     protected void onCreate(Bundle savedState) {
         super.onCreate(savedState);
+        setContentView(R.layout.edit_tag_activity);
 
         if (savedState != null) {
             mRecordWithOutstandingPick = savedState.getParcelable(BUNDLE_KEY_OUTSTANDING_PICK);
         }
         mInflater = LayoutInflater.from(this);
-    }
 
-    protected ViewGroup getContentRoot() {
-        if (mContentRoot == null) {
-            mContentRoot = (ViewGroup) findViewById(R.id.content_parent);
-        }
-        return mContentRoot;
+        findViewById(R.id.toggle_enabled_target).setOnClickListener(this);
+        findViewById(R.id.add_content_target).setOnClickListener(this);
+
+        mTextView = (EditText) findViewById(R.id.input_tag_text);
+        mEnabled = (CheckBox) findViewById(R.id.toggle_enabled_checkbox);
+        mContentRoot = (ViewGroup) findViewById(R.id.content_parent);
+
+        populateEditor();
     }
 
     /**
@@ -137,14 +165,14 @@
      * Adds a child editor view for a record.
      */
     public void addViewForRecord(RecordEditInfo editInfo) {
-        ViewGroup root = getContentRoot();
+        ViewGroup root = mContentRoot;
         View editView = editInfo.getEditView(this, mInflater, root, this);
         root.addView(mInflater.inflate(R.layout.tag_divider, root, false));
         root.addView(editView);
     }
 
     protected void rebuildChildViews() {
-        ViewGroup root = getContentRoot();
+        ViewGroup root = mContentRoot;
         root.removeAllViews();
         for (RecordEditInfo editInfo : mRecords) {
             addViewForRecord(editInfo);
@@ -247,4 +275,160 @@
             outState.putParcelable(BUNDLE_KEY_OUTSTANDING_PICK, mRecordWithOutstandingPick);
         }
     }
+
+    private void populateEditor() {
+        NdefMessage localMessage = NfcAdapter.getDefaultAdapter().getLocalNdefMessage();
+
+        if (Intent.ACTION_SEND.equals(getIntent().getAction()) && !mParsedIntent) {
+            if (localMessage != null) {
+                // TODO: prompt user for confirmation about wiping their old tag.
+            }
+
+            if (buildFromIntent(getIntent())) {
+                return;
+            }
+
+            mParsedIntent = true;
+
+        } else if (localMessage == null) {
+            mEnabled.setChecked(false);
+            return;
+
+        } else {
+            // Locally stored message.
+            ParsedNdefMessage parsed = NdefMessageParser.parse(localMessage);
+            List<ParsedNdefRecord> records = parsed.getRecords();
+
+            // There is always a "Text" record for a My Tag.
+            if (records.size() < 1) {
+                Log.w(LOG_TAG, "Local record not in expected format");
+                return;
+            }
+            mEnabled.setChecked(true);
+            mTextView.setText(((TextRecord) records.get(0)).getText());
+
+            mRecords.clear();
+            for (int i = 1, len = records.size(); i < len; i++) {
+                RecordEditInfo editInfo = records.get(i).getEditInfo(this);
+                if (editInfo != null) {
+                    addRecord(editInfo);
+                }
+            }
+            rebuildChildViews();
+        }
+    }
+
+    /**
+     * 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 buildFromIntent(final Intent intent) {
+        String type = intent.getType();
+
+        if ("text/plain".equals(type)) {
+            String title = getIntent().getStringExtra(Intent.EXTRA_SUBJECT);
+            mTextView.setText((title == null) ? "" : title);
+
+            String text = getIntent().getStringExtra(Intent.EXTRA_TEXT);
+            try {
+                URL parsed = new URL(text);
+
+                // Valid URL.
+                mTextView.setText("");
+                mRecords.add(new UriRecord.UriRecordEditInfo(text));
+                rebuildChildViews();
+
+            } catch (MalformedURLException ex) {
+                // Ignore. Just treat as plain text.
+                mTextView.setText((text == null) ? "" : text);
+            }
+
+            mEnabled.setChecked(true);
+            onSave();
+            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) {
+                    mRecords.add(editInfo);
+                    rebuildChildViews();
+                    onSave();
+                    return true;
+                }
+            }
+        }
+
+        // TODO: handle vcards and images.
+        return false;
+    }
+
+    /**
+     * Persists content to store.
+     */
+    private void onSave() {
+        String text = mTextView.getText().toString();
+        NfcAdapter nfc = NfcAdapter.getDefaultAdapter();
+
+        if (!mEnabled.isChecked()) {
+            nfc.setLocalNdefMessage(null);
+            return;
+        }
+
+        Locale locale = getResources().getConfiguration().locale;
+        ArrayList<NdefRecord> values = Lists.newArrayList(
+                TextRecord.newTextRecord(text, locale)
+        );
+
+        values.addAll(getValues());
+
+        Log.d(LOG_TAG, "Writing local NdefMessage from tag app....");
+        nfc.setLocalNdefMessage(new NdefMessage(values.toArray(new NdefRecord[values.size()])));
+    }
+
+    @Override
+    public void onPause() {
+        super.onPause();
+        onSave();
+    }
+
+    @Override
+    public void onClick(View target) {
+        switch (target.getId()) {
+            case R.id.toggle_enabled_target:
+                boolean enabled = !mEnabled.isChecked();
+                mEnabled.setChecked(enabled);
+
+                // TODO: Persist to some store.
+                if (enabled) {
+                    onSave();
+                } else {
+                    NfcAdapter.getDefaultAdapter().setLocalNdefMessage(null);
+                }
+                break;
+
+            case R.id.add_content_target:
+                showAddContentDialog();
+                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/MyTagActivity.java b/src/com/android/apps/tag/MyTagActivity.java
deleted file mode 100644
index 96bf0d2..0000000
--- a/src/com/android/apps/tag/MyTagActivity.java
+++ /dev/null
@@ -1,233 +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.record.ParsedNdefRecord;
-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.collect.Lists;
-
-import android.app.Activity;
-import android.content.Intent;
-import android.net.Uri;
-import android.nfc.NdefMessage;
-import android.nfc.NdefRecord;
-import android.nfc.NfcAdapter;
-import android.os.Bundle;
-import android.util.Log;
-import android.view.Menu;
-import android.view.MenuItem;
-import android.view.View;
-import android.view.View.OnClickListener;
-import android.widget.CheckBox;
-import android.widget.EditText;
-
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Locale;
-
-/**
- * Editor {@link Activity} for the tag that can be programmed into the device.
- */
-public class MyTagActivity extends EditTagActivity implements OnClickListener {
-
-    private static final String LOG_TAG = "TagEditor";
-
-    private EditText mTextView;
-    private CheckBox mEnabled;
-
-    /**
-     * 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;
-
-    @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);
-
-        mTextView = (EditText) findViewById(R.id.input_tag_text);
-        mEnabled = (CheckBox) findViewById(R.id.toggle_enabled_checkbox);
-
-        populateEditor();
-    }
-
-    private void populateEditor() {
-        NdefMessage localMessage = NfcAdapter.getDefaultAdapter().getLocalNdefMessage();
-
-        if (Intent.ACTION_SEND.equals(getIntent().getAction()) && !mParsedIntent) {
-            if (localMessage != null) {
-                // TODO: prompt user for confirmation about wiping their old tag.
-            }
-
-            if (buildFromIntent(getIntent())) {
-                return;
-            }
-
-            mParsedIntent = true;
-
-        } else if (localMessage == null) {
-            mEnabled.setChecked(false);
-            return;
-
-        } else {
-            // Locally stored message.
-            ParsedNdefMessage parsed = NdefMessageParser.parse(localMessage);
-            List<ParsedNdefRecord> records = parsed.getRecords();
-
-            // There is always a "Text" record for a My Tag.
-            if (records.size() < 1) {
-                Log.w(LOG_TAG, "Local record not in expected format");
-                return;
-            }
-            mEnabled.setChecked(true);
-            mTextView.setText(((TextRecord) records.get(0)).getText());
-
-            mRecords.clear();
-            for (int i = 1, len = records.size(); i < len; i++) {
-                RecordEditInfo editInfo = records.get(i).getEditInfo(this);
-                if (editInfo != null) {
-                    addRecord(editInfo);
-                }
-            }
-            rebuildChildViews();
-        }
-    }
-
-    /**
-     * 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 buildFromIntent(final Intent intent) {
-        String type = intent.getType();
-
-        if ("text/plain".equals(type)) {
-            String title = getIntent().getStringExtra(Intent.EXTRA_SUBJECT);
-            mTextView.setText((title == null) ? "" : title);
-
-            String text = getIntent().getStringExtra(Intent.EXTRA_TEXT);
-            try {
-                URL parsed = new URL(text);
-
-                // Valid URL.
-                mTextView.setText("");
-                mRecords.add(new UriRecord.UriRecordEditInfo(text));
-                rebuildChildViews();
-
-            } catch (MalformedURLException ex) {
-                // Ignore. Just treat as plain text.
-                mTextView.setText((text == null) ? "" : text);
-            }
-
-            mEnabled.setChecked(true);
-            onSave();
-            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) {
-                    mRecords.add(editInfo);
-                    rebuildChildViews();
-                }
-            }
-        }
-        // TODO: handle images.
-        return false;
-    }
-
-    /**
-     * Persists content to store.
-     */
-    private void onSave() {
-        String text = mTextView.getText().toString();
-        NfcAdapter nfc = NfcAdapter.getDefaultAdapter();
-
-        if (!mEnabled.isChecked()) {
-            nfc.setLocalNdefMessage(null);
-            return;
-        }
-
-        Locale locale = getResources().getConfiguration().locale;
-        ArrayList<NdefRecord> values = Lists.newArrayList(
-                TextRecord.newTextRecord(text, locale)
-        );
-
-        values.addAll(getValues());
-
-        Log.d(LOG_TAG, "Writing local NdefMessage from tag app....");
-        nfc.setLocalNdefMessage(new NdefMessage(values.toArray(new NdefRecord[values.size()])));
-    }
-
-    @Override
-    public void onPause() {
-        super.onPause();
-        onSave();
-    }
-
-    @Override
-    public void onClick(View target) {
-        switch (target.getId()) {
-            case R.id.toggle_enabled_target:
-                boolean enabled = !mEnabled.isChecked();
-                mEnabled.setChecked(enabled);
-
-                // TODO: Persist to some store.
-                if (enabled) {
-                    onSave();
-                } else {
-                    NfcAdapter.getDefaultAdapter().setLocalNdefMessage(null);
-                }
-                break;
-
-            case R.id.add_content_target:
-                showAddContentDialog();
-                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/TagBrowserActivity.java b/src/com/android/apps/tag/TagBrowserActivity.java
index 6df1567..f0e8bda 100644
--- a/src/com/android/apps/tag/TagBrowserActivity.java
+++ b/src/com/android/apps/tag/TagBrowserActivity.java
@@ -63,7 +63,7 @@
         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)));
+                .setContent(new Intent().setClass(this, EditTagActivity.class)));
 
         SharedPreferences preferences = getPreferences(Context.MODE_PRIVATE);
         if (!preferences.getBoolean(PREF_KEY_SHOW_INTRO, false)) {