Merge "Initial integration of search into the two-pane activity"
diff --git a/res/layout/item_contact_editor.xml b/res/layout/item_contact_editor.xml
index f5e7bd3..57d641f 100644
--- a/res/layout/item_contact_editor.xml
+++ b/res/layout/item_contact_editor.xml
@@ -14,7 +14,7 @@
      limitations under the License.
 -->
 
-<!-- placed inside act_edit as tabcontent -->
+<!-- placed inside act_edit -->
 <com.android.contacts.ui.widget.ContactEditorView
     xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
@@ -22,14 +22,6 @@
     android:orientation="horizontal"
 >
 
-    <!-- Left side color bar -->
-    <ImageView
-        android:id="@+id/color_bar"
-        android:layout_width="4dip"
-        android:layout_height="match_parent"
-        android:visibility="gone"
-    />
-
     <!-- The content -->
     <LinearLayout
         android:layout_width="0dip"
@@ -116,65 +108,28 @@
             android:layout_marginBottom="4dip"
             layout="@layout/item_generic_editor" />
 
-        <TextView android:id="@+id/read_only_name"
-            android:layout_width="match_parent"
-            android:layout_height="wrap_content"
-            android:layout_marginTop="6dip"
-            android:layout_marginBottom="6dip"
-            android:layout_marginLeft="10dip"
-
-            android:textAppearance="?android:attr/textAppearanceLarge"
-        />
-
         <LinearLayout
-            android:id="@+id/sect_general"
+            android:id="@+id/sect_fields"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:orientation="vertical"
         />
 
-        <View android:id="@+id/head_secondary_divider"
+        <View
             android:layout_width="match_parent"
             android:layout_height="1px"
-            android:background="?android:attr/listDivider" />
-
-        <TextView
-            android:id="@+id/head_secondary"
-            android:layout_width="match_parent"
-            android:layout_height="wrap_content"
-
-            android:gravity="center_vertical"
-            android:minHeight="?android:attr/listPreferredItemHeight"
-            android:text="@string/edit_secondary_collapse"
-            android:textAppearance="?android:attr/textAppearanceMedium"
-            android:textColor="@color/kind_title"
-            android:singleLine="true"
-            android:ellipsize="marquee"
-            android:focusable="true"
-            android:clickable="true"
-            android:paddingLeft="10dip"
-            android:drawablePadding="10dip" />
-
-        <LinearLayout
-            android:id="@+id/sect_secondary"
-            android:layout_width="match_parent"
-            android:layout_height="wrap_content"
-            android:orientation="vertical" />
-
-        <TextView
-            android:id="@+id/edit_read_only"
-            android:layout_width="match_parent"
-            android:layout_height="wrap_content"
-            android:layout_marginTop="10dip"
-            android:layout_marginBottom="10dip"
-            android:layout_marginLeft="10dip"
-
-            android:textAppearance="?android:attr/textAppearanceSmall"
-            android:textColor="?android:attr/textColorPrimary"
-            android:drawableLeft="@android:drawable/ic_dialog_alert"
-            android:drawablePadding="10dip"
+            android:layout_alignParentBottom="true"
+            android:background="?android:attr/listDivider"
         />
 
+        <Button
+            android:id="@+id/button_add_field"
+            android:text="@string/add_field"
+            android:layout_width="wrap_content"
+            android:layout_height="wrap_content"
+            android:layout_gravity="right"
+            android:layout_marginTop="10dip"
+        />
     </LinearLayout>
 
 </com.android.contacts.ui.widget.ContactEditorView>
diff --git a/res/layout/item_kind_section.xml b/res/layout/item_kind_section.xml
index d1dec5e..a78896b 100644
--- a/res/layout/item_kind_section.xml
+++ b/res/layout/item_kind_section.xml
@@ -25,7 +25,7 @@
 
     <View
         android:layout_width="match_parent"
-        android:layout_height="wrap_content"
+        android:layout_height="1px"
         android:background="?android:attr/listDivider" />
 
     <LinearLayout
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 32bada1..e95dc3c 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -1171,4 +1171,6 @@
     <!-- The text displayed when the contacts list is empty while displaying only selected contacts in multiple picker -->
     <string name="no_contacts_selected">"No contacts selected."</string>
 
+    <!-- The add field button shown in the editor under each editable Raw Contact -->
+    <string name="add_field">Add information</string>
 </resources>
diff --git a/src/com/android/contacts/ui/widget/ContactEditorView.java b/src/com/android/contacts/ui/widget/ContactEditorView.java
index 83bf2fb..0916bc0 100644
--- a/src/com/android/contacts/ui/widget/ContactEditorView.java
+++ b/src/com/android/contacts/ui/widget/ContactEditorView.java
@@ -25,13 +25,15 @@
 import com.android.contacts.model.Editor.EditorListener;
 import com.android.contacts.model.EntityDelta.ValuesDelta;
 import com.android.contacts.ui.ViewIdGenerator;
+import com.android.contacts.util.DialogManager;
+import com.android.contacts.util.DialogManager.DialogShowingView;
 
+import android.app.AlertDialog;
+import android.app.Dialog;
 import android.content.Context;
+import android.content.DialogInterface;
 import android.content.Entity;
-import android.content.res.Resources;
-import android.graphics.drawable.Drawable;
-import android.os.Parcel;
-import android.os.Parcelable;
+import android.os.Bundle;
 import android.provider.ContactsContract.Contacts;
 import android.provider.ContactsContract.Data;
 import android.provider.ContactsContract.RawContacts;
@@ -39,49 +41,46 @@
 import android.provider.ContactsContract.CommonDataKinds.StructuredName;
 import android.text.TextUtils;
 import android.util.AttributeSet;
+import android.util.Log;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
-import android.view.View.OnClickListener;
+import android.widget.Button;
 import android.widget.ImageView;
 import android.widget.TextView;
 
+import java.util.ArrayList;
+
 /**
  * Custom view that provides all the editor interaction for a specific
  * {@link Contacts} represented through an {@link EntityDelta}. Callers can
  * reuse this view and quickly rebuild its contents through
- * {@link #setState(EntityDelta, ContactsSource)}.
+ * {@link #setState(EntityDelta, ContactsSource, ViewIdGenerator)}.
  * <p>
  * Internal updates are performed against {@link ValuesDelta} so that the
  * source {@link Entity} can be swapped out. Any state-based changes, such as
  * adding {@link Data} rows or changing {@link EditType}, are performed through
  * {@link EntityModifier} to ensure that {@link ContactsSource} are enforced.
  */
-public class ContactEditorView extends BaseContactEditorView implements OnClickListener {
-    private TextView mReadOnly;
-    private TextView mReadOnlyName;
-
+public class ContactEditorView extends BaseContactEditorView implements DialogShowingView {
     private View mPhotoStub;
     private GenericEditorView mName;
 
-    private boolean mIsSourceReadOnly;
-    private ViewGroup mGeneral;
-    private ViewGroup mSecondary;
-    private boolean mSecondaryVisible;
+    private ViewGroup mFields;
 
-    private TextView mSecondaryHeader;
-
-    private Drawable mSecondaryOpen;
-    private Drawable mSecondaryClosed;
-
-    private View mHeaderColorBar;
-    private View mSideBar;
     private ImageView mHeaderIcon;
     private TextView mHeaderAccountType;
     private TextView mHeaderAccountName;
 
+    private Button mAddFieldButton;
+
     private long mRawContactId = -1;
 
+    private DialogManager mDialogManager = null;
+
+    private static final String DIALOG_ID_KEY = "dialog_id";
+    private static final int DIALOG_ID_FIELD_SELECTOR = 1;
+
     public ContactEditorView(Context context) {
         super(context);
     }
@@ -95,66 +94,29 @@
     protected void onFinishInflate() {
         super.onFinishInflate();
 
-        mInflater = (LayoutInflater)getContext().getSystemService(
-                Context.LAYOUT_INFLATER_SERVICE);
+        mInflater = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
 
         mPhoto = (PhotoEditorView)findViewById(R.id.edit_photo);
         mPhotoStub = findViewById(R.id.stub_photo);
 
         final int photoSize = getResources().getDimensionPixelSize(R.dimen.edit_photo_size);
 
-        mReadOnly = (TextView)findViewById(R.id.edit_read_only);
-
         mName = (GenericEditorView)findViewById(R.id.edit_name);
         mName.setMinimumHeight(photoSize);
         mName.setDeletable(false);
 
-        mReadOnlyName = (TextView) findViewById(R.id.read_only_name);
+        mFields = (ViewGroup)findViewById(R.id.sect_fields);
 
-        mGeneral = (ViewGroup)findViewById(R.id.sect_general);
-        mSecondary = (ViewGroup)findViewById(R.id.sect_secondary);
-
-        mHeaderColorBar = findViewById(R.id.header_color_bar);
-        mSideBar = findViewById(R.id.color_bar);
         mHeaderIcon = (ImageView) findViewById(R.id.header_icon);
         mHeaderAccountType = (TextView) findViewById(R.id.header_account_type);
         mHeaderAccountName = (TextView) findViewById(R.id.header_account_name);
 
-        mSecondaryHeader = (TextView)findViewById(R.id.head_secondary);
-        mSecondaryHeader.setOnClickListener(this);
-
-        final Resources res = getResources();
-        mSecondaryOpen = res.getDrawable(com.android.internal.R.drawable.expander_ic_maximized);
-        mSecondaryClosed = res.getDrawable(com.android.internal.R.drawable.expander_ic_minimized);
-
-        this.setSecondaryVisible(false);
-    }
-
-    /** {@inheritDoc} */
-    public void onClick(View v) {
-        // Toggle visibility of secondary kinds
-        final boolean makeVisible = mSecondary.getVisibility() != View.VISIBLE;
-        this.setSecondaryVisible(makeVisible);
-    }
-
-    /**
-     * Set the visibility of secondary sections, along with header icon.
-     *
-     * <p>If the source is read-only and there's no secondary fields, the entire secondary section
-     * will be hidden.
-     */
-    private void setSecondaryVisible(boolean makeVisible) {
-        mSecondaryVisible = makeVisible;
-
-        if (!mIsSourceReadOnly && mSecondary.getChildCount() > 0) {
-            mSecondaryHeader.setVisibility(View.VISIBLE);
-            mSecondaryHeader.setCompoundDrawablesWithIntrinsicBounds(
-                    makeVisible ? mSecondaryOpen : mSecondaryClosed, null, null, null);
-            mSecondary.setVisibility(makeVisible ? View.VISIBLE : View.GONE);
-        } else {
-            mSecondaryHeader.setVisibility(View.GONE);
-            mSecondary.setVisibility(View.GONE);
-        }
+        mAddFieldButton = (Button) findViewById(R.id.button_add_field);
+        mAddFieldButton.setOnClickListener(new OnClickListener() {
+            public void onClick(View v) {
+                showDialog(DIALOG_ID_FIELD_SELECTOR);
+            }
+        });
     }
 
     /**
@@ -165,16 +127,13 @@
     @Override
     public void setState(EntityDelta state, ContactsSource source, ViewIdGenerator vig) {
         // Remove any existing sections
-        mGeneral.removeAllViews();
-        mSecondary.removeAllViews();
+        mFields.removeAllViews();
 
         // Bail if invalid state or source
         if (state == null || source == null) return;
 
         setId(vig.getId(state, null, null, ViewIdGenerator.NO_VIEW_INDEX));
 
-        mIsSourceReadOnly = source.readOnly;
-
         // Make sure we have StructuredName
         EntityModifier.ensureKindExists(state, source, StructuredName.CONTENT_ITEM_TYPE);
 
@@ -198,24 +157,13 @@
         EntityModifier.ensureKindExists(state, source, Photo.CONTENT_ITEM_TYPE);
         mHasPhotoEditor = (source.getKindForMimetype(Photo.CONTENT_ITEM_TYPE) != null);
         mPhoto.setVisibility(mHasPhotoEditor ? View.VISIBLE : View.GONE);
-        mPhoto.setEnabled(!mIsSourceReadOnly);
-        mName.setEnabled(!mIsSourceReadOnly);
+        mPhoto.setEnabled(true);
+        mName.setEnabled(true);
 
         // Show and hide the appropriate views
-        if (mIsSourceReadOnly) {
-            mGeneral.setVisibility(View.GONE);
-            mName.setVisibility(View.GONE);
-            mReadOnly.setVisibility(View.VISIBLE);
-            mReadOnly.setText(mContext.getString(R.string.contact_read_only, accountType));
-            mReadOnlyName.setVisibility(View.VISIBLE);
-        } else {
-            mGeneral.setVisibility(View.VISIBLE);
-            mName.setVisibility(View.VISIBLE);
-            mReadOnly.setVisibility(View.GONE);
-            mReadOnlyName.setVisibility(View.GONE);
-        }
+        mFields.setVisibility(View.VISIBLE);
+        mName.setVisibility(View.VISIBLE);
 
-        boolean anySecondaryFieldFilled = false;
         // Create editor sections for each possible data kind
         for (DataKind kind : source.getSortedDataKinds()) {
             // Skip kind of not editable
@@ -225,36 +173,21 @@
             if (StructuredName.CONTENT_ITEM_TYPE.equals(mimeType)) {
                 // Handle special case editor for structured name
                 final ValuesDelta primary = state.getPrimaryEntry(mimeType);
-                if (!mIsSourceReadOnly) {
-                    mName.setValues(kind, primary, state, mIsSourceReadOnly, vig);
-                } else {
-                    String displayName = primary.getAsString(StructuredName.DISPLAY_NAME);
-                    mReadOnlyName.setText(displayName);
-                }
+                mName.setValues(kind, primary, state, false, vig);
             } else if (Photo.CONTENT_ITEM_TYPE.equals(mimeType)) {
                 // Handle special case editor for photos
                 final ValuesDelta primary = state.getPrimaryEntry(mimeType);
-                mPhoto.setValues(kind, primary, state, mIsSourceReadOnly, vig);
-                if (mIsSourceReadOnly && !mPhoto.hasSetPhoto()) {
-                    mPhotoStub.setVisibility(View.GONE);
-                } else {
-                    mPhotoStub.setVisibility(View.VISIBLE);
-                }
-            } else if (!mIsSourceReadOnly) {
+                mPhoto.setValues(kind, primary, state, false, vig);
+                mPhotoStub.setVisibility(View.VISIBLE);
+            } else {
                 // Otherwise use generic section-based editors
                 if (kind.fieldList == null) continue;
-                final ViewGroup parent = kind.secondary ? mSecondary : mGeneral;
                 final KindSectionView section = (KindSectionView)mInflater.inflate(
-                        R.layout.item_kind_section, parent, false);
-                section.setState(kind, state, mIsSourceReadOnly, vig);
-                if (kind.secondary && section.isAnyEditorFilledOut()) {
-                    anySecondaryFieldFilled = true;
-                }
-                parent.addView(section);
+                        R.layout.item_kind_section, mFields, false);
+                section.setState(kind, state, false, vig);
+                mFields.addView(section);
             }
         }
-
-        setSecondaryVisible(anySecondaryFieldFilled);
     }
 
     /**
@@ -270,56 +203,53 @@
         return mRawContactId;
     }
 
-    private static class SavedState extends BaseSavedState {
-        public boolean mSecondaryVisible;
-
-        SavedState(Parcelable superState) {
-            super(superState);
-        }
-
-        private SavedState(Parcel in) {
-            super(in);
-            mSecondaryVisible = (in.readInt() == 0 ? false : true);
-        }
-
-        @Override
-        public void writeToParcel(Parcel out, int flags) {
-            super.writeToParcel(out, flags);
-            out.writeInt(mSecondaryVisible ? 1 : 0);
-        }
-
-        public static final Parcelable.Creator<SavedState> CREATOR
-                = new Parcelable.Creator<SavedState>() {
-            public SavedState createFromParcel(Parcel in) {
-                return new SavedState(in);
-            }
-
-            public SavedState[] newArray(int size) {
-                return new SavedState[size];
-            }
-        };
+    /* package */
+    void showDialog(int bundleDialogId) {
+        final Bundle bundle = new Bundle();
+        bundle.putInt(DIALOG_ID_KEY, bundleDialogId);
+        getDialogManager().showDialogInView(this, bundle);
     }
 
-    /**
-     * Saves the visibility of the secondary field.
-     */
-    @Override
-    protected Parcelable onSaveInstanceState() {
-        Parcelable superState = super.onSaveInstanceState();
-        SavedState ss = new SavedState(superState);
-
-        ss.mSecondaryVisible = mSecondaryVisible;
-        return ss;
+    private DialogManager getDialogManager() {
+        if (mDialogManager == null) {
+            Context context = getContext();
+            if (!(context instanceof DialogManager.DialogShowingViewActivity)) {
+                throw new IllegalStateException(
+                        "View must be hosted in an Activity that implements " +
+                        "DialogManager.DialogShowingViewActivity");
+            }
+            mDialogManager = ((DialogManager.DialogShowingViewActivity)context).getDialogManager();
+        }
+        return mDialogManager;
     }
 
-    /**
-     * Restores the visibility of the secondary field.
-     */
-    @Override
-    protected void onRestoreInstanceState(Parcelable state) {
-        SavedState ss = (SavedState) state;
-        super.onRestoreInstanceState(ss.getSuperState());
-
-        setSecondaryVisible(ss.mSecondaryVisible);
+    public Dialog createDialog(Bundle bundle) {
+        if (bundle == null) throw new IllegalArgumentException("bundle must not be null");
+        int dialogId = bundle.getInt(DIALOG_ID_KEY);
+        switch (dialogId) {
+            case DIALOG_ID_FIELD_SELECTOR:
+                final ArrayList<CharSequence> items =
+                        new ArrayList<CharSequence>(mFields.getChildCount());
+                for (int i = 0; i < mFields.getChildCount(); i++) {
+                    final KindSectionView sectionView = (KindSectionView) mFields.getChildAt(i);
+                    // not a list and already exists? ignore
+                    if (!sectionView.getKind().isList && sectionView.getEditorCount() != 0) {
+                        continue;
+                    }
+                    items.add(sectionView.getTitle());
+                }
+                final DialogInterface.OnClickListener itemClickListener =
+                        new DialogInterface.OnClickListener() {
+                    public void onClick(DialogInterface dialog, int which) {
+                        final KindSectionView view = (KindSectionView) mFields.getChildAt(which);
+                        view.addItem();
+                    }
+                };
+                return new AlertDialog.Builder(getContext())
+                        .setItems(items.toArray(new CharSequence[0]), itemClickListener)
+                        .create();
+            default:
+                throw new IllegalArgumentException("Invalid dialogId: " + dialogId);
+        }
     }
 }
diff --git a/src/com/android/contacts/ui/widget/GenericEditorView.java b/src/com/android/contacts/ui/widget/GenericEditorView.java
index de4dfae..5c2f9b7 100644
--- a/src/com/android/contacts/ui/widget/GenericEditorView.java
+++ b/src/com/android/contacts/ui/widget/GenericEditorView.java
@@ -388,16 +388,17 @@
                 // Keep around in model, but mark as deleted
                 mEntry.markDeleted();
 
-                final ViewGroupAnimator animator = ViewGroupAnimator.captureView(getRootView());
+//                final ViewGroupAnimator animator = ViewGroupAnimator.captureView(getRootView());
 
-                animator.removeView(this);
+//                animator.removeView(this);
+                ((ViewGroup) getParent()).removeView(this);
 
                 if (mListener != null) {
                     // Notify listener when present
                     mListener.onDeleted(this);
                 }
 
-                animator.animate();
+//                animator.animate();
                 break;
             }
             case R.id.edit_more_or_less: {
@@ -406,7 +407,7 @@
                 final int focusedViewId = focusedChild == null ? -1 : focusedChild.getId();
 
                 // Snapshot for animation
-                final ViewGroupAnimator animator = ViewGroupAnimator.captureView(getRootView());
+//                final ViewGroupAnimator animator = ViewGroupAnimator.captureView(getRootView());
 
                 // Reconfigure GUI
                 mHideOptional = !mHideOptional;
@@ -423,7 +424,7 @@
                 }
 
                 // Animate
-                animator.animate();
+//                animator.animate();
                 break;
             }
         }
diff --git a/src/com/android/contacts/ui/widget/KindSectionView.java b/src/com/android/contacts/ui/widget/KindSectionView.java
index 56ffc8c..88f88c7 100644
--- a/src/com/android/contacts/ui/widget/KindSectionView.java
+++ b/src/com/android/contacts/ui/widget/KindSectionView.java
@@ -24,7 +24,6 @@
 import com.android.contacts.model.Editor.EditorListener;
 import com.android.contacts.model.EntityDelta.ValuesDelta;
 import com.android.contacts.ui.ViewIdGenerator;
-import com.android.contacts.util.ViewGroupAnimator;
 
 import android.content.Context;
 import android.provider.ContactsContract.Data;
@@ -32,7 +31,6 @@
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
-import android.view.View.OnClickListener;
 import android.widget.ImageView;
 import android.widget.LinearLayout;
 import android.widget.TextView;
@@ -42,7 +40,7 @@
  * {@link DataKind} around a {@link Data#MIMETYPE}. This view shows a
  * section header and a trigger for adding new {@link Data} rows.
  */
-public class KindSectionView extends LinearLayout implements OnClickListener, EditorListener {
+public class KindSectionView extends LinearLayout implements EditorListener {
     private static final String TAG = "KindSectionView";
 
     private LayoutInflater mInflater;
@@ -78,7 +76,11 @@
         mEditors = (ViewGroup)findViewById(R.id.kind_editors);
 
         mAdd = findViewById(R.id.kind_header);
-        mAdd.setOnClickListener(this);
+        mAdd.setOnClickListener(new OnClickListener() {
+            public void onClick(View v) {
+                addItem();
+            }
+        });
 
         mAddPlusButton = (ImageView) findViewById(R.id.kind_plus);
 
@@ -87,8 +89,9 @@
 
     /** {@inheritDoc} */
     public void onDeleted(Editor editor) {
-        this.updateAddEnabled();
-        this.updateEditorsVisible();
+        updateAddEnabled();
+        updateEditorsVisible();
+        updateVisible();
     }
 
     /** {@inheritDoc} */
@@ -110,12 +113,17 @@
         // Only show the add button if this is a list
         mAddPlusButton.setVisibility(mKind.isList ? View.VISIBLE : View.GONE);
 
-        this.rebuildFromState();
-        this.updateAddEnabled();
-        this.updateEditorsVisible();
+        rebuildFromState();
+        updateAddEnabled();
+        updateEditorsVisible();
+        updateVisible();
     }
 
-    public boolean isAnyEditorFilledOut() {
+    public CharSequence getTitle() {
+        return mTitle.getText();
+    }
+
+    public boolean getFieldCount() {
         if (mState == null) {
             return false;
         }
@@ -124,7 +132,7 @@
             return false;
         }
 
-        int editorCount = mEditors.getChildCount();
+        int editorCount = getEditorCount();
         for (int i = 0; i < editorCount; i++) {
             GenericEditorView editorView = (GenericEditorView) mEditors.getChildAt(i);
             if (editorView.isAnyFieldFilledOut()) {
@@ -145,23 +153,6 @@
         // Check if we are displaying anything here
         boolean hasEntries = mState.hasMimeEntries(mKind.mimeType);
 
-        if (!mKind.isList) {
-            if (hasEntries) {
-                // we might have no visible entries. check that, too
-                for (ValuesDelta entry : mState.getMimeEntries(mKind.mimeType)) {
-                    if (!entry.isVisible()) {
-                        hasEntries = false;
-                        break;
-                    }
-                }
-            }
-
-            if (!hasEntries) {
-                EntityModifier.insertChild(mState, mKind);
-                hasEntries = true;
-            }
-        }
-
         if (hasEntries) {
             int entryIndex = 0;
             for (ValuesDelta entry : mState.getMimeEntries(mKind.mimeType)) {
@@ -171,11 +162,6 @@
                 final GenericEditorView editor = (GenericEditorView)mInflater.inflate(
                         R.layout.item_generic_editor, mEditors, false);
                 editor.setValues(mKind, entry, mState, mReadOnly, mViewIdGenerator);
-                // older versions of android had lists where we now have a single value
-                // in these cases we should show the remove button for all but the first value
-                // to ensure that nothing is removed
-                editor.mDelete.setVisibility((mKind.isList || (entryIndex != 0))
-                        ? View.VISIBLE : View.GONE);
                 editor.setEditorListener(this);
                 mEditors.addView(editor);
                 entryIndex++;
@@ -184,10 +170,15 @@
     }
 
     protected void updateEditorsVisible() {
-        final boolean hasChildren = mEditors.getChildCount() > 0;
+        final boolean hasChildren = getEditorCount() > 0;
         mEditors.setVisibility(hasChildren ? View.VISIBLE : View.GONE);
     }
 
+    private void updateVisible() {
+        setVisibility(getEditorCount() != 0 ? VISIBLE : GONE);
+    }
+
+
     protected void updateAddEnabled() {
         // Set enabled state on the "add" view
         final boolean canInsert = EntityModifier.canInsert(mState, mKind);
@@ -195,20 +186,18 @@
         mAdd.setEnabled(isEnabled);
     }
 
-    /** {@inheritDoc} */
-    public void onClick(View v) {
-        // if this is not a list the plus button is not visible but the user might have clicked
-        // the text.
-        if (!mKind.isList)
+    public void addItem() {
+        // if this is a list, we can freely add. if not, only allow adding the first
+        if (!mKind.isList && getEditorCount() == 1)
             return;
 
-        final ViewGroupAnimator animator = ViewGroupAnimator.captureView(getRootView());
+//        final ViewGroupAnimator animator = ViewGroupAnimator.captureView(getRootView());
 
         // Insert a new child and rebuild
         final ValuesDelta newValues = EntityModifier.insertChild(mState, mKind);
-        this.rebuildFromState();
-        this.updateAddEnabled();
-        this.updateEditorsVisible();
+        rebuildFromState();
+        updateAddEnabled();
+        updateEditorsVisible();
 
         // Find the newly added EditView and set focus.
         final int newFieldId = mViewIdGenerator.getId(mState, mKind, newValues, 0);
@@ -217,6 +206,16 @@
             newField.requestFocus();
         }
 
-        animator.animate();
+        updateVisible();
+
+//        animator.animate();
+    }
+
+    public int getEditorCount() {
+        return mEditors.getChildCount();
+    }
+
+    public DataKind getKind() {
+        return mKind;
     }
 }