/**
   * Prepare this editor using the given {@link DataKind} for defining structure and {@link
   * ValuesDelta} describing the content to edit.
   */
  @Override
  public void setValues(
      DataKind kind,
      ValuesDelta entry,
      RawContactDelta state,
      boolean readOnly,
      ViewIdGenerator vig) {
    mKind = kind;
    mEntry = entry;
    mState = state;
    mReadOnly = readOnly;
    mViewIdGenerator = vig;
    setId(vig.getId(state, kind, entry, ViewIdGenerator.NO_VIEW_INDEX));

    if (!entry.isVisible()) {
      // Hide ourselves entirely if deleted
      setVisibility(View.GONE);
      return;
    }
    setVisibility(View.VISIBLE);

    // Display label selector if multiple types available
    final boolean hasTypes = RawContactModifier.hasEditTypes(kind);
    setupLabelButton(hasTypes);
    mLabel.setEnabled(!readOnly && isEnabled());
    if (hasTypes) {
      mType = RawContactModifier.getCurrentType(entry, kind);
      rebuildLabel();
    }
  }
    public EditTypeAdapter(Context context) {
      super(context, 0);
      mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
      mTextColor = context.getResources().getColor(R.color.secondary_text_color);

      if (mType != null && mType.customColumn != null) {

        // Use custom label string when present
        final String customText = mEntry.getAsString(mType.customColumn);
        if (customText != null) {
          add(CUSTOM_SELECTION);
          mHasCustomSelection = true;
        }
      }

      addAll(RawContactModifier.getValidTypes(mState, mKind, mType));
    }
 protected void updateAddFooterVisible(boolean animate) {
   if (!mReadOnly && (mKind.typeOverallMax != 1)) {
     // First determine whether there are any existing empty editors.
     updateEmptyEditors();
     // If there are no existing empty editors and it's possible to add
     // another field, then make the "add footer" field visible.
     if (!hasEmptyEditor() && RawContactModifier.canInsert(mState, mKind)) {
       if (animate) {
         EditorAnimator.getInstance().showAddFieldFooter(mAddFieldFooter);
       } else {
         mAddFieldFooter.setVisibility(View.VISIBLE);
       }
       return;
     }
   }
   if (animate) {
     EditorAnimator.getInstance().hideAddFieldFooter(mAddFieldFooter);
   } else {
     mAddFieldFooter.setVisibility(View.GONE);
   }
 }
  public void addItem() {
    ValuesDelta values = null;
    // If this is a list, we can freely add. If not, only allow adding the first.
    if (mKind.typeOverallMax == 1) {
      if (getEditorCount() == 1) {
        return;
      }

      // If we already have an item, just make it visible
      ArrayList<ValuesDelta> entries = mState.getMimeEntries(mKind.mimeType);
      if (entries != null && entries.size() > 0) {
        values = entries.get(0);
      }
    }

    // Insert a new child, create its view and set its focus
    if (values == null) {
      values = RawContactModifier.insertChild(mState, mKind);
    }

    final View newField = createEditorView(values);
    if (newField instanceof Editor) {
      postWhenWindowFocused(
          new Runnable() {
            @Override
            public void run() {
              newField.requestFocus();
              ((Editor) newField).editNewlyAddedField();
            }
          });
    }

    // Hide the "add field" footer because there is now a blank field.
    mAddFieldFooter.setVisibility(View.GONE);

    // Ensure we are visible
    updateSectionVisible();
  }