android:fadingEdge="horizontal" />
<ImageView
+ android:id="@+id/kind_plus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:duplicateParentState="true"
abstract public int getHeaderColor(Context context);
abstract public int getSideBarColor(Context context);
-
+
/**
* {@link Comparator} to sort by {@link DataKind#weight}.
*/
public boolean secondary;
public boolean editable;
+ /**
+ * If this is true (default), the user can add and remove values.
+ * If false, the editor will always show a single field (which might be empty).
+ */
+ public boolean isList;
+
public StringInflater actionHeader;
public StringInflater actionAltHeader;
public StringInflater actionBody;
public boolean actionBodySocial = false;
public String typeColumn;
+
+ /**
+ * Maximum number of values allowed in the list. -1 represents infinity.
+ * If {@link DataKind#isList} is false, this value is ignored.
+ */
public int typeOverallMax;
public List<EditType> typeList;
this.iconRes = iconRes;
this.weight = weight;
this.editable = editable;
+ this.isList = true;
this.typeOverallMax = -1;
}
}
final DataKind kind = super.inflateNickname(ContactsSource.LEVEL_MIMETYPES);
if (inflateLevel >= ContactsSource.LEVEL_CONSTRAINTS) {
- kind.typeOverallMax = 1;
+ kind.isList = false;
kind.fieldList = Lists.newArrayList();
kind.fieldList.add(new EditField(Nickname.NAME, R.string.nicknameLabelsGroup,
final DataKind kind = super.inflateOrganization(ContactsSource.LEVEL_MIMETYPES);
if (inflateLevel >= ContactsSource.LEVEL_CONSTRAINTS) {
- kind.typeOverallMax = 1;
-
+ kind.isList = false;
kind.typeColumn = Organization.TYPE;
kind.typeList = Lists.newArrayList();
kind.typeList.add(buildOrgType(Organization.TYPE_WORK).setSpecificMax(1));
final DataKind kind = super.inflateNote(ContactsSource.LEVEL_MIMETYPES);
if (inflateLevel >= ContactsSource.LEVEL_CONSTRAINTS) {
- kind.typeOverallMax = 1;
-
kind.fieldList = Lists.newArrayList();
kind.fieldList.add(new EditField(Note.NOTE, R.string.label_notes, FLAGS_NOTE));
}
final DataKind kind = super.inflateWebsite(ContactsSource.LEVEL_MIMETYPES);
if (inflateLevel >= ContactsSource.LEVEL_CONSTRAINTS) {
- kind.typeOverallMax = 1;
+ kind.isList = false;
kind.fieldList = Lists.newArrayList();
kind.fieldList.add(new EditField(Website.URL, R.string.websiteLabelsGroup, FLAGS_WEBSITE));
package com.android.contacts.model;
+import com.android.contacts.R;
+import com.google.android.collect.Lists;
+
import android.content.ContentValues;
import android.content.Context;
import android.content.res.Resources;
import android.provider.ContactsContract.CommonDataKinds.StructuredName;
import android.provider.ContactsContract.CommonDataKinds.StructuredPostal;
import android.provider.ContactsContract.CommonDataKinds.Website;
-import android.util.Log;
import android.view.inputmethod.EditorInfo;
-import com.google.android.collect.Lists;
-
-import com.android.contacts.R;
-
import java.util.Locale;
public class FallbackSource extends ContactsSource {
kind = addKind(new DataKind(Nickname.CONTENT_ITEM_TYPE,
R.string.nicknameLabelsGroup, -1, 115, true));
kind.secondary = true;
+ kind.isList = false;
kind.actionHeader = new SimpleInflater(R.string.nicknameLabelsGroup);
kind.actionBody = new SimpleInflater(Nickname.NAME);
}
if (kind == null) {
kind = addKind(new DataKind(Note.CONTENT_ITEM_TYPE,
R.string.label_notes, R.drawable.sym_note, 110, true));
+ kind.isList = false;
kind.secondary = true;
kind.actionHeader = new SimpleInflater(R.string.label_notes);
kind.actionBody = new SimpleInflater(Note.NOTE);
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;
private ViewGroup mEditors;
private View mAdd;
+ private ImageView mAddPlusButton;
private TextView mTitle;
private DataKind mKind;
mAdd = findViewById(R.id.kind_header);
mAdd.setOnClickListener(this);
+ mAddPlusButton = (ImageView) findViewById(R.id.kind_plus);
+
mTitle = (TextView)findViewById(R.id.kind_title);
}
// TODO: handle resources from remote packages
mTitle.setText(kind.titleRes);
+ // Only show the add button if this is a list
+ mAddPlusButton.setVisibility(mKind.isList ? View.VISIBLE : View.GONE);
+
this.rebuildFromState();
this.updateAddEnabled();
this.updateEditorsVisible();
// Remove any existing editors
mEditors.removeAllViews();
- // Build individual editors for each entry
- if (!mState.hasMimeEntries(mKind.mimeType)) return;
- for (ValuesDelta entry : mState.getMimeEntries(mKind.mimeType)) {
- // Skip entries that aren't visible
- if (!entry.isVisible()) continue;
-
- final GenericEditorView editor = (GenericEditorView)mInflater.inflate(
- R.layout.item_generic_editor, mEditors, false);
- editor.setValues(mKind, entry, mState, mReadOnly, mViewIdGenerator);
- editor.setEditorListener(this);
- mEditors.addView(editor);
+ // 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)) {
+ // Skip entries that aren't visible
+ if (!entry.isVisible()) continue;
+
+ 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++;
+ }
}
}
protected void updateAddEnabled() {
// Set enabled state on the "add" view
final boolean canInsert = EntityModifier.canInsert(mState, mKind);
- final boolean isEnabled = !mReadOnly && canInsert;
+ final boolean isEnabled = !mReadOnly && canInsert;
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)
+ return;
+
// Insert a new child and rebuild
final ValuesDelta newValues = EntityModifier.insertChild(mState, mKind);
this.rebuildFromState();