Reintroduce pseudo mimetype for name
In order to have a separate edit DataKind for phonetic name
we need a pseudo mimetype for just the name as well. The pseudo
DataKinds are used to render the actual text fields while the
StructuredName mimetype DataKind is used for checking if any
thing was changed.
Test:
Unit tests
Save a new contact while entering only the phonetic name
Bug: 32023197
Bug: 21758689
Change-Id: I151b37b7be091705974e3f36770e4bb0e150a64d
diff --git a/src/com/android/contacts/common/model/RawContactModifier.java b/src/com/android/contacts/common/model/RawContactModifier.java
index 5e8941d..b24f877 100644
--- a/src/com/android/contacts/common/model/RawContactModifier.java
+++ b/src/com/android/contacts/common/model/RawContactModifier.java
@@ -47,11 +47,6 @@
import android.util.SparseIntArray;
import com.android.contacts.common.ContactsUtils;
-import com.android.contacts.common.model.AccountTypeManager;
-import com.android.contacts.common.model.ValuesDelta;
-import com.android.contacts.common.util.CommonDateUtils;
-import com.android.contacts.common.util.DateUtils;
-import com.android.contacts.common.util.NameConverter;
import com.android.contacts.common.model.account.AccountType;
import com.android.contacts.common.model.account.AccountType.EditField;
import com.android.contacts.common.model.account.AccountType.EditType;
@@ -60,6 +55,9 @@
import com.android.contacts.common.model.dataitem.DataKind;
import com.android.contacts.common.model.dataitem.PhoneDataItem;
import com.android.contacts.common.model.dataitem.StructuredNameDataItem;
+import com.android.contacts.common.util.CommonDateUtils;
+import com.android.contacts.common.util.DateUtils;
+import com.android.contacts.common.util.NameConverter;
import java.text.ParsePosition;
import java.util.ArrayList;
@@ -988,7 +986,8 @@
for (DataKind kind : newAccountType.getSortedDataKinds()) {
if (!kind.editable) continue;
final String mimeType = kind.mimeType;
- if (DataKind.PSEUDO_MIME_TYPE_PHONETIC_NAME.equals(mimeType)) {
+ if (DataKind.PSEUDO_MIME_TYPE_PHONETIC_NAME.equals(mimeType) ||
+ DataKind.PSEUDO_MIME_TYPE_NAME.equals(mimeType)) {
// Ignore pseudo data.
continue;
} else if (StructuredName.CONTENT_ITEM_TYPE.equals(mimeType)) {
diff --git a/src/com/android/contacts/common/model/account/BaseAccountType.java b/src/com/android/contacts/common/model/account/BaseAccountType.java
index c57fa0e..5ed79ef 100644
--- a/src/com/android/contacts/common/model/account/BaseAccountType.java
+++ b/src/com/android/contacts/common/model/account/BaseAccountType.java
@@ -155,6 +155,34 @@
kind.typeOverallMax = 1;
kind.fieldList = Lists.newArrayList();
+ kind.fieldList.add(new EditField(StructuredName.PREFIX, R.string.name_prefix,
+ FLAGS_PERSON_NAME).setLongForm(true));
+ kind.fieldList.add(new EditField(StructuredName.GIVEN_NAME, R.string.name_given,
+ FLAGS_PERSON_NAME));
+ kind.fieldList.add(new EditField(StructuredName.MIDDLE_NAME, R.string.name_middle,
+ FLAGS_PERSON_NAME).setLongForm(true));
+ kind.fieldList.add(new EditField(StructuredName.FAMILY_NAME, R.string.name_family,
+ FLAGS_PERSON_NAME));
+ kind.fieldList.add(new EditField(StructuredName.SUFFIX, R.string.name_suffix,
+ FLAGS_PERSON_NAME).setLongForm(true));
+ kind.fieldList.add(new EditField(StructuredName.PHONETIC_FAMILY_NAME,
+ R.string.name_phonetic_family, FLAGS_PHONETIC));
+ kind.fieldList.add(new EditField(StructuredName.PHONETIC_MIDDLE_NAME,
+ R.string.name_phonetic_middle, FLAGS_PHONETIC));
+ kind.fieldList.add(new EditField(StructuredName.PHONETIC_GIVEN_NAME,
+ R.string.name_phonetic_given, FLAGS_PHONETIC));
+
+ return kind;
+ }
+
+ protected DataKind addDataKindName(Context context) throws DefinitionException {
+ final DataKind kind = addKind(new DataKind(DataKind.PSEUDO_MIME_TYPE_NAME,
+ R.string.nameLabelsGroup, Weight.NONE, true));
+ kind.actionHeader = new SimpleInflater(R.string.nameLabelsGroup);
+ kind.actionBody = new SimpleInflater(Nickname.NAME);
+ kind.typeOverallMax = 1;
+
+ kind.fieldList = Lists.newArrayList();
final boolean displayOrderPrimary =
context.getResources().getBoolean(R.bool.config_editor_field_order_primary);
@@ -178,7 +206,6 @@
kind.fieldList.add(new EditField(StructuredName.SUFFIX, R.string.name_suffix,
FLAGS_PERSON_NAME).setLongForm(true));
-
return kind;
}
@@ -855,8 +882,9 @@
AttributeSet attrs) throws DefinitionException, XmlPullParserException,
IOException {
- // Build 2 data kinds:
+ // Build 3 data kinds:
// - StructuredName.CONTENT_ITEM_TYPE
+ // - DataKind.PSEUDO_MIME_TYPE_NAME
// - DataKind.PSEUDO_MIME_TYPE_PHONETIC_NAME
final boolean displayOrderPrimary =
@@ -872,7 +900,7 @@
final boolean supportsPhoneticGivenName =
getAttr(attrs, "supportsPhoneticGivenName", false);
- // For now, every things must be supported.
+ // For now, every thing must be supported.
checkAttributeTrue(supportsPrefix, "supportsPrefix");
checkAttributeTrue(supportsMiddleName, "supportsMiddleName");
checkAttributeTrue(supportsSuffix, "supportsSuffix");
@@ -890,27 +918,54 @@
ks.fieldList.add(new EditField(StructuredName.PREFIX, R.string.name_prefix,
FLAGS_PERSON_NAME).setLongForm(true));
- if (!displayOrderPrimary) {
- ks.fieldList.add(new EditField(StructuredName.FAMILY_NAME, R.string.name_family,
- FLAGS_PERSON_NAME));
- ks.fieldList.add(new EditField(StructuredName.MIDDLE_NAME, R.string.name_middle,
- FLAGS_PERSON_NAME).setLongForm(true));
- ks.fieldList.add(new EditField(StructuredName.GIVEN_NAME, R.string.name_given,
- FLAGS_PERSON_NAME));
- } else {
- ks.fieldList.add(new EditField(StructuredName.GIVEN_NAME, R.string.name_given,
- FLAGS_PERSON_NAME));
- ks.fieldList.add(new EditField(StructuredName.MIDDLE_NAME, R.string.name_middle,
- FLAGS_PERSON_NAME).setLongForm(true));
- ks.fieldList.add(new EditField(StructuredName.FAMILY_NAME, R.string.name_family,
- FLAGS_PERSON_NAME));
- }
+ ks.fieldList.add(new EditField(StructuredName.GIVEN_NAME, R.string.name_given,
+ FLAGS_PERSON_NAME));
+ ks.fieldList.add(new EditField(StructuredName.MIDDLE_NAME, R.string.name_middle,
+ FLAGS_PERSON_NAME).setLongForm(true));
+ ks.fieldList.add(new EditField(StructuredName.FAMILY_NAME, R.string.name_family,
+ FLAGS_PERSON_NAME));
ks.fieldList.add(new EditField(StructuredName.SUFFIX, R.string.name_suffix,
FLAGS_PERSON_NAME).setLongForm(true));
+ ks.fieldList.add(new EditField(StructuredName.PHONETIC_FAMILY_NAME,
+ R.string.name_phonetic_family, FLAGS_PHONETIC));
+ ks.fieldList.add(new EditField(StructuredName.PHONETIC_MIDDLE_NAME,
+ R.string.name_phonetic_middle, FLAGS_PHONETIC));
+ ks.fieldList.add(new EditField(StructuredName.PHONETIC_GIVEN_NAME,
+ R.string.name_phonetic_given, FLAGS_PHONETIC));
throwIfList(ks);
kinds.add(ks);
+ // Name
+ final DataKind kn = newDataKind(context, parser, attrs, true,
+ DataKind.PSEUDO_MIME_TYPE_NAME, null,
+ R.string.nameLabelsGroup, Weight.NONE,
+ new SimpleInflater(R.string.nameLabelsGroup),
+ new SimpleInflater(Nickname.NAME));
+ kn.typeOverallMax = 1;
+ throwIfList(kn);
+ kinds.add(kn);
+
+ kn.fieldList.add(new EditField(StructuredName.PREFIX, R.string.name_prefix,
+ FLAGS_PERSON_NAME).setLongForm(true));
+ if (!displayOrderPrimary) {
+ kn.fieldList.add(new EditField(StructuredName.FAMILY_NAME, R.string.name_family,
+ FLAGS_PERSON_NAME));
+ kn.fieldList.add(new EditField(StructuredName.MIDDLE_NAME, R.string.name_middle,
+ FLAGS_PERSON_NAME).setLongForm(true));
+ kn.fieldList.add(new EditField(StructuredName.GIVEN_NAME, R.string.name_given,
+ FLAGS_PERSON_NAME));
+ } else {
+ kn.fieldList.add(new EditField(StructuredName.GIVEN_NAME, R.string.name_given,
+ FLAGS_PERSON_NAME));
+ kn.fieldList.add(new EditField(StructuredName.MIDDLE_NAME, R.string.name_middle,
+ FLAGS_PERSON_NAME).setLongForm(true));
+ kn.fieldList.add(new EditField(StructuredName.FAMILY_NAME, R.string.name_family,
+ FLAGS_PERSON_NAME));
+ }
+ kn.fieldList.add(new EditField(StructuredName.SUFFIX, R.string.name_suffix,
+ FLAGS_PERSON_NAME).setLongForm(true));
+
// Phonetic name
final DataKind kp = newDataKind(context, parser, attrs, true,
DataKind.PSEUDO_MIME_TYPE_PHONETIC_NAME, null,
diff --git a/src/com/android/contacts/common/model/account/ExchangeAccountType.java b/src/com/android/contacts/common/model/account/ExchangeAccountType.java
index 339564b..8529e9f 100644
--- a/src/com/android/contacts/common/model/account/ExchangeAccountType.java
+++ b/src/com/android/contacts/common/model/account/ExchangeAccountType.java
@@ -52,6 +52,7 @@
try {
addDataKindStructuredName(context);
+ addDataKindName(context);
addDataKindPhoneticName(context);
addDataKindNickname(context);
addDataKindPhone(context);
diff --git a/src/com/android/contacts/common/model/account/ExternalAccountType.java b/src/com/android/contacts/common/model/account/ExternalAccountType.java
index 685322a..e70232b 100644
--- a/src/com/android/contacts/common/model/account/ExternalAccountType.java
+++ b/src/com/android/contacts/common/model/account/ExternalAccountType.java
@@ -132,11 +132,13 @@
needLineNumberInErrorLog = false;
if (mHasEditSchema) {
checkKindExists(StructuredName.CONTENT_ITEM_TYPE);
+ checkKindExists(DataKind.PSEUDO_MIME_TYPE_NAME);
checkKindExists(DataKind.PSEUDO_MIME_TYPE_PHONETIC_NAME);
checkKindExists(Photo.CONTENT_ITEM_TYPE);
} else {
// Bring in name and photo from fallback source, which are non-optional
addDataKindStructuredName(context);
+ addDataKindName(context);
addDataKindPhoneticName(context);
addDataKindPhoto(context);
}
diff --git a/src/com/android/contacts/common/model/account/FallbackAccountType.java b/src/com/android/contacts/common/model/account/FallbackAccountType.java
index 5a75c8e..6fd99c4 100644
--- a/src/com/android/contacts/common/model/account/FallbackAccountType.java
+++ b/src/com/android/contacts/common/model/account/FallbackAccountType.java
@@ -38,6 +38,7 @@
try {
addDataKindStructuredName(context);
+ addDataKindName(context);
addDataKindPhoneticName(context);
addDataKindNickname(context);
addDataKindPhone(context);
diff --git a/src/com/android/contacts/common/model/account/GoogleAccountType.java b/src/com/android/contacts/common/model/account/GoogleAccountType.java
index 3cfb44a..a94bcff 100644
--- a/src/com/android/contacts/common/model/account/GoogleAccountType.java
+++ b/src/com/android/contacts/common/model/account/GoogleAccountType.java
@@ -53,6 +53,7 @@
try {
addDataKindStructuredName(context);
+ addDataKindName(context);
addDataKindPhoneticName(context);
addDataKindNickname(context);
addDataKindPhone(context);
diff --git a/src/com/android/contacts/common/model/account/SamsungAccountType.java b/src/com/android/contacts/common/model/account/SamsungAccountType.java
index 00f6687..c35a5a6 100644
--- a/src/com/android/contacts/common/model/account/SamsungAccountType.java
+++ b/src/com/android/contacts/common/model/account/SamsungAccountType.java
@@ -54,6 +54,7 @@
try {
addDataKindStructuredName(context);
+ addDataKindName(context);
addDataKindPhoneticName(context);
addDataKindNickname(context);
addDataKindPhone(context);
diff --git a/src/com/android/contacts/common/model/account/SimAccountType.java b/src/com/android/contacts/common/model/account/SimAccountType.java
index e7d7ee2..cecc9c7 100644
--- a/src/com/android/contacts/common/model/account/SimAccountType.java
+++ b/src/com/android/contacts/common/model/account/SimAccountType.java
@@ -38,6 +38,7 @@
try {
addDataKindStructuredName(context);
+ addDataKindName(context);
final DataKind phoneKind = addDataKindPhone(context);
phoneKind.typeOverallMax = 1;
// SIM card contacts don't necessarily support separate types (based on data exposed
@@ -75,6 +76,24 @@
kind.actionBody = new SimpleInflater(Nickname.NAME);
kind.typeOverallMax = 1;
+
+ kind.fieldList = Lists.newArrayList();
+ kind.fieldList.add(new EditField(StructuredName.GIVEN_NAME, R.string.name_given,
+ FLAGS_PERSON_NAME));
+ kind.fieldList.add(new EditField(StructuredName.FAMILY_NAME, R.string.name_family,
+ FLAGS_PERSON_NAME));
+
+ return kind;
+ }
+
+ @Override
+ protected DataKind addDataKindName(Context context) throws DefinitionException {
+ final DataKind kind = addKind(new DataKind(DataKind.PSEUDO_MIME_TYPE_NAME,
+ R.string.nameLabelsGroup, Weight.NONE, true));
+ kind.actionHeader = new SimpleInflater(R.string.nameLabelsGroup);
+ kind.actionBody = new SimpleInflater(Nickname.NAME);
+ kind.typeOverallMax = 1;
+
final boolean displayOrderPrimary =
context.getResources().getBoolean(R.bool.config_editor_field_order_primary);
diff --git a/src/com/android/contacts/common/model/dataitem/DataKind.java b/src/com/android/contacts/common/model/dataitem/DataKind.java
index e4b6aea..98ad40a 100644
--- a/src/com/android/contacts/common/model/dataitem/DataKind.java
+++ b/src/com/android/contacts/common/model/dataitem/DataKind.java
@@ -36,7 +36,7 @@
*/
public final class DataKind {
- public static final String PSEUDO_MIME_TYPE_DISPLAY_NAME = "#displayName";
+ public static final String PSEUDO_MIME_TYPE_NAME = "#name";
public static final String PSEUDO_MIME_TYPE_PHONETIC_NAME = "#phoneticName";
public static final String PSEUDO_COLUMN_PHONETIC_NAME = "#phoneticName";
diff --git a/src/com/android/contacts/editor/KindSectionView.java b/src/com/android/contacts/editor/KindSectionView.java
index 4380af9..125a307 100644
--- a/src/com/android/contacts/editor/KindSectionView.java
+++ b/src/com/android/contacts/editor/KindSectionView.java
@@ -349,7 +349,7 @@
}
nameView.setDeletable(false);
nameView.setValues(
- accountType.getKindForMimetype(StructuredName.CONTENT_ITEM_TYPE),
+ accountType.getKindForMimetype(DataKind.PSEUDO_MIME_TYPE_NAME),
nameValuesDelta, rawContactDelta, /* readOnly =*/ false, mViewIdGenerator);
// Correct start margin since there is a second icon in the structured name layout
diff --git a/tests/src/com/android/contacts/common/model/account/ExternalAccountTypeTest.java b/tests/src/com/android/contacts/common/model/account/ExternalAccountTypeTest.java
index 684a379..96e776f 100644
--- a/tests/src/com/android/contacts/common/model/account/ExternalAccountTypeTest.java
+++ b/tests/src/com/android/contacts/common/model/account/ExternalAccountTypeTest.java
@@ -31,12 +31,14 @@
import android.test.InstrumentationTestCase;
import android.test.suitebuilder.annotation.SmallTest;
import android.test.suitebuilder.annotation.Suppress;
-import android.util.Log;
import com.android.contacts.common.model.dataitem.DataKind;
import com.android.contacts.common.tests.R;
+
import com.google.common.base.Objects;
+import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
/**
@@ -47,6 +49,12 @@
*/
@SmallTest
public class ExternalAccountTypeTest extends InstrumentationTestCase {
+ private static ArrayList<String> mDefaultMimetypes = new ArrayList<>(Arrays.asList(
+ StructuredName.CONTENT_ITEM_TYPE,
+ DataKind.PSEUDO_MIME_TYPE_NAME,
+ DataKind.PSEUDO_MIME_TYPE_PHONETIC_NAME,
+ Photo.CONTENT_ITEM_TYPE
+ ));
@Suppress
public void testResolveExternalResId() {
@@ -92,6 +100,7 @@
// Let's just check if the DataKinds are registered.
assertNotNull(type.getKindForMimetype(StructuredName.CONTENT_ITEM_TYPE));
+ assertNotNull(type.getKindForMimetype(DataKind.PSEUDO_MIME_TYPE_NAME));
assertNotNull(type.getKindForMimetype(DataKind.PSEUDO_MIME_TYPE_PHONETIC_NAME));
assertNotNull(type.getKindForMimetype(Email.CONTENT_ITEM_TYPE));
assertNotNull(type.getKindForMimetype(StructuredPostal.CONTENT_ITEM_TYPE));
@@ -159,13 +168,13 @@
// Shouldn't have a "null" mimetype.
assertTrue(type.getKindForMimetype(null) == null);
- // 3 kinds are defined in XML and 3 are added by default.
- assertEquals(3 + 3, type.getSortedDataKinds().size());
+ // 3 kinds are defined in XML and the rest are added by default.
+ assertEquals(3 + mDefaultMimetypes.size(), type.getSortedDataKinds().size());
// Check for the default kinds.
- assertNotNull(type.getKindForMimetype(StructuredName.CONTENT_ITEM_TYPE));
- assertNotNull(type.getKindForMimetype(DataKind.PSEUDO_MIME_TYPE_PHONETIC_NAME));
- assertNotNull(type.getKindForMimetype(Photo.CONTENT_ITEM_TYPE));
+ for (String mimetype : mDefaultMimetypes) {
+ assertNotNull(type.getKindForMimetype(mimetype));
+ }
// Check for type specific kinds.
DataKind kind = type.getKindForMimetype("vnd.android.cursor.item/a.b.c");