Don't parse phonetic name just show show all the parts fully expanded.
Test:
Tested the following editor scenarios:
1) goto create new contact/edit existing contact
2) notice that phonetic name field is not visible
3) tap on the more fields at the bottom of the list
a) phonetic name fields are visible below name fields
4) enter value in one of these fields and tap on save
5) go back to the same contact and notice that phonetic name fields are
visible.
Bug: 34468427
Change-Id: Idba3f3915350c2bbe49dcda89e30cd756f7f7642
diff --git a/res/layout/phonetic_name_editor_view.xml b/res/layout/phonetic_name_editor_view.xml
deleted file mode 100644
index efaf644..0000000
--- a/res/layout/phonetic_name_editor_view.xml
+++ /dev/null
@@ -1,48 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
- Copyright (C) 2011 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.
- -->
-
-<com.android.contacts.editor.PhoneticNameEditorView
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:minHeight="@dimen/editor_min_line_item_height"
- android:layout_marginStart="@dimen/editor_kind_icon_total_width">
-
- <!-- This isn't used in PhoneticNameEditorView. It is only included so that
- StructuredNameEditorView's base classes don't need extra null checks. -->
- <include
- android:id="@+id/spinner"
- layout="@layout/edit_spinner"
- android:visibility="gone" />
-
- <include
- android:id="@+id/editors"
- layout="@layout/edit_field_list" />
-
- <include
- android:id="@+id/expansion_view_container"
- layout="@layout/name_edit_expansion_view"
- android:visibility="visible" />
-
- <!-- This isn't used in PhoneticNameEditorView. It is only included so that
- StructuredNameEditorView's base classes don't need extra null checks. -->
- <include
- android:id="@+id/delete_button_container"
- layout="@layout/edit_delete_button"
- android:visibility="gone" />
-
-</com.android.contacts.editor.PhoneticNameEditorView>
diff --git a/src/com/android/contacts/editor/EditorUiUtils.java b/src/com/android/contacts/editor/EditorUiUtils.java
index a500eae..9aa5c8e 100644
--- a/src/com/android/contacts/editor/EditorUiUtils.java
+++ b/src/com/android/contacts/editor/EditorUiUtils.java
@@ -88,9 +88,6 @@
// Relation.CONTENT_ITEM_TYPE
//
// Un-supported mime types need to mapped with -1.
-
- mimetypeLayoutMap.put(DataKind.PSEUDO_MIME_TYPE_PHONETIC_NAME,
- R.layout.phonetic_name_editor_view);
mimetypeLayoutMap.put(StructuredName.CONTENT_ITEM_TYPE,
R.layout.structured_name_editor_view);
mimetypeLayoutMap.put(GroupMembership.CONTENT_ITEM_TYPE, -1);
diff --git a/src/com/android/contacts/editor/KindSectionView.java b/src/com/android/contacts/editor/KindSectionView.java
index 02eae11..7e9d53e 100644
--- a/src/com/android/contacts/editor/KindSectionView.java
+++ b/src/com/android/contacts/editor/KindSectionView.java
@@ -362,8 +362,8 @@
// The account type doesn't support phonetic name.
if (phoneticNameKind == null) return;
- final PhoneticNameEditorView phoneticNameView = (PhoneticNameEditorView) mLayoutInflater
- .inflate(R.layout.phonetic_name_editor_view, mEditors, /* attachToRoot =*/ false);
+ final TextFieldsEditorView phoneticNameView = (TextFieldsEditorView) mLayoutInflater
+ .inflate(R.layout.text_fields_editor_view, mEditors, /* attachToRoot =*/ false);
phoneticNameView.setEditorListener(new OtherNameKindEditorListener());
phoneticNameView.setDeletable(false);
phoneticNameView.setValues(
diff --git a/src/com/android/contacts/editor/PhoneticNameEditorView.java b/src/com/android/contacts/editor/PhoneticNameEditorView.java
deleted file mode 100644
index c96548c..0000000
--- a/src/com/android/contacts/editor/PhoneticNameEditorView.java
+++ /dev/null
@@ -1,166 +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.contacts.editor;
-
-import android.content.Context;
-import android.content.res.Resources;
-import android.text.TextUtils;
-import android.util.AttributeSet;
-
-import com.android.contacts.R;
-import com.android.contacts.model.RawContactDelta;
-import com.android.contacts.model.ValuesDelta;
-import com.android.contacts.model.dataitem.DataKind;
-import com.android.contacts.model.dataitem.StructuredNameDataItem;
-import com.android.contacts.util.NameConverter;
-
-/**
- * A dedicated editor for phonetic name. It is similar to {@link StructuredNameEditorView}.
- */
-public class PhoneticNameEditorView extends TextFieldsEditorView {
-
- private static class PhoneticValuesDelta extends ValuesDelta {
- private ValuesDelta mValues;
- private String mPhoneticName;
-
- public PhoneticValuesDelta(ValuesDelta values) {
- mValues = values;
- buildPhoneticName();
- }
-
- @Override
- public void put(String key, String value) {
- if (key.equals(DataKind.PSEUDO_COLUMN_PHONETIC_NAME)) {
- mPhoneticName = value;
- parsePhoneticName(value);
- } else {
- mValues.put(key, value);
- buildPhoneticName();
- }
- }
-
- @Override
- public String getAsString(String key) {
- if (key.equals(DataKind.PSEUDO_COLUMN_PHONETIC_NAME)) {
- return mPhoneticName;
- } else {
- return mValues.getAsString(key);
- }
- }
-
- private void parsePhoneticName(String value) {
- StructuredNameDataItem dataItem = NameConverter.parsePhoneticName(value, null);
- mValues.setPhoneticFamilyName(dataItem.getPhoneticFamilyName());
- mValues.setPhoneticMiddleName(dataItem.getPhoneticMiddleName());
- mValues.setPhoneticGivenName(dataItem.getPhoneticGivenName());
- }
-
- private void buildPhoneticName() {
- String family = mValues.getPhoneticFamilyName();
- String middle = mValues.getPhoneticMiddleName();
- String given = mValues.getPhoneticGivenName();
- mPhoneticName = NameConverter.buildPhoneticName(family, middle, given);
- }
-
- @Override
- public Long getId() {
- return mValues.getId();
- }
-
- @Override
- public boolean isVisible() {
- return mValues.isVisible();
- }
- }
-
- public static boolean isUnstructuredPhoneticNameColumn(String column) {
- return DataKind.PSEUDO_COLUMN_PHONETIC_NAME.equals(column);
- }
-
- public PhoneticNameEditorView(Context context) {
- super(context);
- }
-
- public PhoneticNameEditorView(Context context, AttributeSet attrs) {
- super(context, attrs);
- }
-
- public PhoneticNameEditorView(Context context, AttributeSet attrs, int defStyle) {
- super(context, attrs, defStyle);
- }
-
- @Override
- protected void onFinishInflate() {
- super.onFinishInflate();
- final Resources res = getResources();
- mCollapseButtonDescription = res
- .getString(R.string.collapse_phonetic_name_fields_description);
- mExpandButtonDescription = res
- .getString(R.string.expand_phonetic_name_fields_description);
- }
-
- @Override
- public void setValues(DataKind kind, ValuesDelta entry, RawContactDelta state, boolean readOnly,
- ViewIdGenerator vig) {
- if (!(entry instanceof PhoneticValuesDelta)) {
- entry = new PhoneticValuesDelta(entry);
- }
- super.setValues(kind, entry, state, readOnly, vig);
- updateEmptiness();
- }
-
- @Override
- public void onFieldChanged(String column, String value) {
- if (!isFieldChanged(column, value)) {
- return;
- }
-
- if (hasShortAndLongForms()) {
- PhoneticValuesDelta entry = (PhoneticValuesDelta) getEntry();
-
- // Determine whether the user is modifying the structured or unstructured phonetic
- // name field. See a similar approach in {@link StructuredNameEditor#onFieldChanged}.
- // This is because on device rotation, a hidden TextView's onRestoreInstanceState() will
- // be called and incorrectly restore a null value for the hidden field, which ultimately
- // modifies the underlying phonetic name. Hence, ignore onFieldChanged() update requests
- // from fields that aren't visible.
- boolean isEditingUnstructuredPhoneticName = !areOptionalFieldsVisible();
-
- if (isEditingUnstructuredPhoneticName == isUnstructuredPhoneticNameColumn(column)) {
- // Call into the superclass to update the field and rebuild the underlying
- // phonetic name.
- super.onFieldChanged(column, value);
- }
- } else {
- // All fields are always visible, so we don't have to worry about blocking updates
- // from onRestoreInstanceState() from hidden fields. Always call into the superclass
- // to update the field and rebuild the underlying phonetic name.
- super.onFieldChanged(column, value);
- }
- }
-
- public boolean hasData() {
- ValuesDelta entry = getEntry();
-
- String family = entry.getPhoneticFamilyName();
- String middle = entry.getPhoneticMiddleName();
- String given = entry.getPhoneticGivenName();
-
- return !TextUtils.isEmpty(family) || !TextUtils.isEmpty(middle)
- || !TextUtils.isEmpty(given);
- }
-}
diff --git a/src/com/android/contacts/model/RawContactModifier.java b/src/com/android/contacts/model/RawContactModifier.java
index 0252567..789bd10 100644
--- a/src/com/android/contacts/model/RawContactModifier.java
+++ b/src/com/android/contacts/model/RawContactModifier.java
@@ -1038,14 +1038,10 @@
return;
}
- boolean supportPhoneticFullName = false;
boolean supportPhoneticFamilyName = false;
boolean supportPhoneticMiddleName = false;
boolean supportPhoneticGivenName = false;
for (EditField editField : newDataKind.fieldList) {
- if (DataKind.PSEUDO_COLUMN_PHONETIC_NAME.equals(editField.column)) {
- supportPhoneticFullName = true;
- }
if (StructuredName.PHONETIC_FAMILY_NAME.equals(editField.column)) {
supportPhoneticFamilyName = true;
}
@@ -1057,52 +1053,14 @@
}
}
-
- // Phonetic (full) name <-> PHONETIC_FAMILY_NAME, PHONETIC_MIDDLE_NAME, PHONETIC_GIVEN_NAME
- final String phoneticFullName = values.getAsString(DataKind.PSEUDO_COLUMN_PHONETIC_NAME);
- if (!TextUtils.isEmpty(phoneticFullName)) {
- if (!supportPhoneticFullName) {
- // Old data has a phonetic (full) name, while the new account doesn't allow it.
- final StructuredNameDataItem tmpItem =
- NameConverter.parsePhoneticName(phoneticFullName, null);
- values.remove(DataKind.PSEUDO_COLUMN_PHONETIC_NAME);
- if (supportPhoneticFamilyName) {
- values.put(StructuredName.PHONETIC_FAMILY_NAME,
- tmpItem.getPhoneticFamilyName());
- } else {
- values.remove(StructuredName.PHONETIC_FAMILY_NAME);
- }
- if (supportPhoneticMiddleName) {
- values.put(StructuredName.PHONETIC_MIDDLE_NAME,
- tmpItem.getPhoneticMiddleName());
- } else {
- values.remove(StructuredName.PHONETIC_MIDDLE_NAME);
- }
- if (supportPhoneticGivenName) {
- values.put(StructuredName.PHONETIC_GIVEN_NAME,
- tmpItem.getPhoneticGivenName());
- } else {
- values.remove(StructuredName.PHONETIC_GIVEN_NAME);
- }
- }
- } else {
- if (supportPhoneticFullName) {
- // Old data does not have a phonetic (full) name, while the new account requires it.
- values.put(DataKind.PSEUDO_COLUMN_PHONETIC_NAME,
- NameConverter.buildPhoneticName(
- values.getAsString(StructuredName.PHONETIC_FAMILY_NAME),
- values.getAsString(StructuredName.PHONETIC_MIDDLE_NAME),
- values.getAsString(StructuredName.PHONETIC_GIVEN_NAME)));
- }
- if (!supportPhoneticFamilyName) {
- values.remove(StructuredName.PHONETIC_FAMILY_NAME);
- }
- if (!supportPhoneticMiddleName) {
- values.remove(StructuredName.PHONETIC_MIDDLE_NAME);
- }
- if (!supportPhoneticGivenName) {
- values.remove(StructuredName.PHONETIC_GIVEN_NAME);
- }
+ if (!supportPhoneticFamilyName) {
+ values.remove(StructuredName.PHONETIC_FAMILY_NAME);
+ }
+ if (!supportPhoneticMiddleName) {
+ values.remove(StructuredName.PHONETIC_MIDDLE_NAME);
+ }
+ if (!supportPhoneticGivenName) {
+ values.remove(StructuredName.PHONETIC_GIVEN_NAME);
}
newState.addEntry(ValuesDelta.fromAfter(values));
diff --git a/src/com/android/contacts/model/account/BaseAccountType.java b/src/com/android/contacts/model/account/BaseAccountType.java
index a62f353..50f623a 100644
--- a/src/com/android/contacts/model/account/BaseAccountType.java
+++ b/src/com/android/contacts/model/account/BaseAccountType.java
@@ -218,14 +218,13 @@
kind.typeOverallMax = 1;
kind.fieldList = Lists.newArrayList();
- kind.fieldList.add(new EditField(DataKind.PSEUDO_COLUMN_PHONETIC_NAME,
- R.string.name_phonetic, FLAGS_PHONETIC).setShortForm(true));
+
kind.fieldList.add(new EditField(StructuredName.PHONETIC_FAMILY_NAME,
- R.string.name_phonetic_family, FLAGS_PHONETIC).setLongForm(true));
+ R.string.name_phonetic_family, FLAGS_PHONETIC));
kind.fieldList.add(new EditField(StructuredName.PHONETIC_MIDDLE_NAME,
- R.string.name_phonetic_middle, FLAGS_PHONETIC).setLongForm(true));
+ R.string.name_phonetic_middle, FLAGS_PHONETIC));
kind.fieldList.add(new EditField(StructuredName.PHONETIC_GIVEN_NAME,
- R.string.name_phonetic_given, FLAGS_PHONETIC).setLongForm(true));
+ R.string.name_phonetic_given, FLAGS_PHONETIC));
return kind;
}
@@ -977,14 +976,12 @@
kinds.add(kp);
// We may want to change the order depending on displayOrderPrimary too.
- kp.fieldList.add(new EditField(DataKind.PSEUDO_COLUMN_PHONETIC_NAME,
- R.string.name_phonetic, FLAGS_PHONETIC).setShortForm(true));
kp.fieldList.add(new EditField(StructuredName.PHONETIC_FAMILY_NAME,
- R.string.name_phonetic_family, FLAGS_PHONETIC).setLongForm(true));
+ R.string.name_phonetic_family, FLAGS_PHONETIC));
kp.fieldList.add(new EditField(StructuredName.PHONETIC_MIDDLE_NAME,
- R.string.name_phonetic_middle, FLAGS_PHONETIC).setLongForm(true));
+ R.string.name_phonetic_middle, FLAGS_PHONETIC));
kp.fieldList.add(new EditField(StructuredName.PHONETIC_GIVEN_NAME,
- R.string.name_phonetic_given, FLAGS_PHONETIC).setLongForm(true));
+ R.string.name_phonetic_given, FLAGS_PHONETIC));
return kinds;
}
}
diff --git a/src/com/android/contacts/model/dataitem/DataKind.java b/src/com/android/contacts/model/dataitem/DataKind.java
index 993e6cc..f31e21c 100644
--- a/src/com/android/contacts/model/dataitem/DataKind.java
+++ b/src/com/android/contacts/model/dataitem/DataKind.java
@@ -39,7 +39,6 @@
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";
public String resourcePackageName;
public String mimeType;