Merge "Allow line wrap in "Add new account" buttton" into mnc-dev
diff --git a/src/com/android/contacts/editor/CompactContactEditorFragment.java b/src/com/android/contacts/editor/CompactContactEditorFragment.java
index 2bffc6a..3c0e6dd 100644
--- a/src/com/android/contacts/editor/CompactContactEditorFragment.java
+++ b/src/com/android/contacts/editor/CompactContactEditorFragment.java
@@ -355,7 +355,8 @@
 
         // Prepare an Intent to start the expanded editor
         final Intent intent = isInsert
-                ? EditorIntents.createInsertContactIntent(mState, getDisplayName(), mUpdatedPhotos)
+                ? EditorIntents.createInsertContactIntent(
+                        mState, getDisplayName(), getPhoneticName(), mUpdatedPhotos)
                 : EditorIntents.createEditContactIntent(mLookupUri, getMaterialPalette());
         ImplicitIntentsUtil.startActivityInApp(getActivity(), intent);
 
@@ -381,6 +382,14 @@
                 ? null : structuredNameEditorView.getDisplayName();
     }
 
+    @Override
+    public String getPhoneticName() {
+        final PhoneticNameEditorView phoneticNameEditorView =
+                getContent().getFirstPhoneticNameEditorView();
+        return phoneticNameEditorView == null
+                ? null : phoneticNameEditorView.getPhoneticName();
+    }
+
     private CompactRawContactsEditorView getContent() {
         return (CompactRawContactsEditorView) mContent;
     }
diff --git a/src/com/android/contacts/editor/CompactRawContactsEditorView.java b/src/com/android/contacts/editor/CompactRawContactsEditorView.java
index 704fe9d..36502e2 100644
--- a/src/com/android/contacts/editor/CompactRawContactsEditorView.java
+++ b/src/com/android/contacts/editor/CompactRawContactsEditorView.java
@@ -246,6 +246,12 @@
                 ? null : (StructuredNameEditorView) mNames.getChildAt(0);
     }
 
+    public PhoneticNameEditorView getFirstPhoneticNameEditorView() {
+        // There should only ever be one phonetic name
+        return mPhoneticNames.getChildCount() == 0
+                ? null : (PhoneticNameEditorView) mPhoneticNames.getChildAt(0);
+    }
+
     public View getAggregationAnchorView() {
         // Since there is only one structured name we can just return it as the anchor for
         // the aggregation suggestions popup
@@ -274,6 +280,7 @@
                 /* valuesDelta =*/ null, ViewIdGenerator.NO_VIEW_INDEX));
         mMaterialPalette = materialPalette;
 
+        vlog("Setting compact editor state from " + rawContactDeltas);
         addPhotoView(rawContactDeltas, viewIdGenerator);
         addStructuredNameView(rawContactDeltas);
         addEditorViews(rawContactDeltas);
@@ -424,7 +431,7 @@
                     continue;
                 }
                 final String mimeType = dataKind.mimeType;
-                log(Log.VERBOSE, mimeType + " " + dataKind.fieldList.size() + " field(s)");
+                vlog(mimeType + " " + dataKind.fieldList.size() + " field(s)");
                 if (Photo.CONTENT_ITEM_TYPE.equals(mimeType)
                         || StructuredName.CONTENT_ITEM_TYPE.equals(mimeType)
                         || GroupMembership.CONTENT_ITEM_TYPE.equals(mimeType)) {
@@ -521,11 +528,11 @@
             String mimeType, DataKind dataKind) {
         final List<ValuesDelta> result = new ArrayList<>();
         if (rawContactDelta == null) {
-            log(Log.VERBOSE, "Null RawContactDelta");
+            vlog("Null RawContactDelta");
             return result;
         }
         if (!rawContactDelta.hasMimeEntries(mimeType)) {
-            log(Log.VERBOSE, "No ValueDeltas");
+            vlog("No ValueDeltas");
             return result;
         }
         for (ValuesDelta valuesDelta : rawContactDelta.getMimeEntries(mimeType)) {
@@ -538,14 +545,13 @@
 
     private static boolean hasNonEmptyValue(DataKind dataKind, ValuesDelta valuesDelta) {
         if (valuesDelta == null) {
-            log(Log.VERBOSE, "Null valuesDelta");
+            vlog("Null valuesDelta");
             return false;
         }
         for (EditField editField : dataKind.fieldList) {
             final String column = editField.column;
             final String value = valuesDelta == null ? null : valuesDelta.getAsString(column);
-            log(Log.VERBOSE, "Field " + column + " empty=" + TextUtils.isEmpty(value) +
-                    " value=" + value);
+            vlog("Field " + column + " empty=" + TextUtils.isEmpty(value) + " value=" + value);
             if (!TextUtils.isEmpty(value)) {
                 return true;
             }
@@ -598,32 +604,9 @@
         return result;
     }
 
-    private static void log(int level, String message) {
-        log(TAG, level, message);
-    }
-
-    private static void log(String tag, int level, String message) {
-        if (Log.isLoggable(tag, level)) {
-            switch (level) {
-                case Log.VERBOSE:
-                    Log.v(tag, message);
-                    break;
-                case Log.DEBUG:
-                    Log.d(tag, message);
-                    break;
-                case Log.INFO:
-                    Log.i(tag, message);
-                    break;
-                case Log.WARN:
-                    Log.w(tag, message);
-                    break;
-                case Log.ERROR:
-                    Log.e(tag, message);
-                    break;
-                default:
-                    Log.v(tag, message);
-                    break;
-            }
+    private static void vlog(String message) {
+        if (Log.isLoggable(TAG, Log.VERBOSE)) {
+            Log.v(TAG, message);
         }
     }
 }
diff --git a/src/com/android/contacts/editor/ContactEditorBaseFragment.java b/src/com/android/contacts/editor/ContactEditorBaseFragment.java
index a7686ae..529bc4e 100644
--- a/src/com/android/contacts/editor/ContactEditorBaseFragment.java
+++ b/src/com/android/contacts/editor/ContactEditorBaseFragment.java
@@ -922,7 +922,7 @@
             // If we're coming back from the fully expanded editor and this is an insert, just
             // pass any values entered by the user back to the compact editor without doing a save
             final Intent resultIntent = EditorIntents.createCompactInsertContactIntent(
-                    mState, getDisplayName(), mUpdatedPhotos);
+                    mState, getDisplayName(), getPhoneticName(), mUpdatedPhotos);
             mListener.onSaveFinished(resultIntent);
             return true;
         }
@@ -979,6 +979,11 @@
      */
     abstract protected String getDisplayName();
 
+    /**
+     * Returns the currently displayed phonetic name;
+     */
+    abstract protected String getPhoneticName();
+
     //
     // Account creation
     //
@@ -1343,7 +1348,7 @@
                 if (!saveSucceeded || contactLookupUri == null) {
                     resultIntent = saveMode == SaveMode.COMPACT
                             ? EditorIntents.createCompactInsertContactIntent(
-                                    mState, getDisplayName(), updatedPhotos)
+                                    mState, getDisplayName(), getPhoneticName(), updatedPhotos)
                             : null;
                 } else {
                     final Uri lookupUri = maybeConvertToLegacyLookupUri(
@@ -1354,7 +1359,7 @@
                     } else if (saveMode == SaveMode.COMPACT) {
                         resultIntent = isInsert(getActivity().getIntent())
                                 ? EditorIntents.createCompactInsertContactIntent(
-                                        mState, getDisplayName(), updatedPhotos)
+                                        mState, getDisplayName(), getPhoneticName(), updatedPhotos)
                                 : EditorIntents.createCompactEditContactIntent(
                                         lookupUri, getMaterialPalette(), updatedPhotos);
                     } else {
diff --git a/src/com/android/contacts/editor/ContactEditorFragment.java b/src/com/android/contacts/editor/ContactEditorFragment.java
index 4949729..4cda73d 100644
--- a/src/com/android/contacts/editor/ContactEditorFragment.java
+++ b/src/com/android/contacts/editor/ContactEditorFragment.java
@@ -382,12 +382,9 @@
                 final StructuredNameEditorView nameEditorView =
                         rawContactEditorView.getNameEditor();
                 if (nameEditorView != null) {
-                    final ValuesDelta valuesDelta = nameEditorView.getValues();
-                    if (valuesDelta != null && valuesDelta.isSuperPrimary()) {
-                        final String displayName = valuesDelta.getDisplayName();
-                        if (!TextUtils.isEmpty(displayName)) {
-                            return displayName;
-                        }
+                    final String displayName = nameEditorView.getDisplayName();
+                    if (!TextUtils.isEmpty(displayName)) {
+                        return displayName;
                     }
                 }
             }
@@ -400,12 +397,28 @@
                 final StructuredNameEditorView nameEditorView =
                         rawContactEditorView.getNameEditor();
                 if (nameEditorView != null) {
-                    final ValuesDelta valuesDelta = nameEditorView.getValues();
-                    if (valuesDelta != null) {
-                        final String displayName = valuesDelta.getDisplayName();
-                        if (!TextUtils.isEmpty(displayName)) {
-                            return displayName;
-                        }
+                    final String displayName = nameEditorView.getDisplayName();
+                    if (!TextUtils.isEmpty(displayName)) {
+                        return displayName;
+                    }
+                }
+            }
+        }
+        return null;
+    }
+
+    @Override
+    public String getPhoneticName() {
+        for (int i = 0; i < mContent.getChildCount(); i++) {
+            final View view = mContent.getChildAt(i);
+            if (view instanceof RawContactEditorView) {
+                final RawContactEditorView rawContactEditorView = (RawContactEditorView) view;
+                final PhoneticNameEditorView phoneticNameEditorView =
+                        (PhoneticNameEditorView) rawContactEditorView.getPhoneticNameEditor();
+                if (phoneticNameEditorView != null) {
+                    final String phoneticName = phoneticNameEditorView.getPhoneticName();
+                    if (!TextUtils.isEmpty(phoneticName)) {
+                        return phoneticName;
                     }
                 }
             }
diff --git a/src/com/android/contacts/editor/EditorIntents.java b/src/com/android/contacts/editor/EditorIntents.java
index 3fb2145..5d7edd3 100644
--- a/src/com/android/contacts/editor/EditorIntents.java
+++ b/src/com/android/contacts/editor/EditorIntents.java
@@ -56,7 +56,7 @@
      */
     public static Intent createCompactInsertContactIntent() {
         return createCompactInsertContactIntent(/* rawContactDeltaList =*/ null,
-                /* displayName =*/ null, /* updatedPhotos =*/ null);
+                /* displayName =*/ null, /* phoneticName =*/ null, /* updatedPhotos =*/ null);
     }
 
     /**
@@ -64,10 +64,10 @@
      * the field values specified by rawContactDeltaList pre-populate in the form.
      */
     public static Intent createCompactInsertContactIntent(RawContactDeltaList rawContactDeltaList,
-            String displayName, Bundle updatedPhotos) {
+            String displayName, String phoneticName, Bundle updatedPhotos) {
         final Intent intent = new Intent(Intent.ACTION_INSERT, Contacts.CONTENT_URI);
-        if (rawContactDeltaList != null || displayName != null) {
-            putRawContactDeltaValues(intent, rawContactDeltaList, displayName);
+        if (rawContactDeltaList != null || displayName != null || phoneticName != null) {
+            putRawContactDeltaValues(intent, rawContactDeltaList, displayName, phoneticName);
         }
         putUpdatedPhotos(intent, updatedPhotos);
         return intent;
@@ -108,11 +108,11 @@
      * existing contact.
      */
     public static Intent createInsertContactIntent(RawContactDeltaList rawContactDeltaList,
-            String displayName, Bundle updatedPhotos) {
+            String displayName, String phoneticName, Bundle updatedPhotos) {
         final Intent intent = new Intent(ContactEditorBaseActivity.ACTION_INSERT,
                 Contacts.CONTENT_URI);
         addContactIntentFlags(intent);
-        putRawContactDeltaValues(intent, rawContactDeltaList, displayName);
+        putRawContactDeltaValues(intent, rawContactDeltaList, displayName, phoneticName);
         putUpdatedPhotos(intent, updatedPhotos);
         return intent;
     }
@@ -137,7 +137,7 @@
     }
 
     private static void putRawContactDeltaValues(Intent intent,
-            RawContactDeltaList rawContactDeltaList, String displayName) {
+            RawContactDeltaList rawContactDeltaList, String displayName, String phoneticName) {
         // Pass on all the data that has been entered so far
         if (rawContactDeltaList != null && !rawContactDeltaList.isEmpty()) {
             ArrayList<ContentValues> contentValues = rawContactDeltaList.get(0).getContentValues();
@@ -146,9 +146,12 @@
                         ContactsContract.Intents.Insert.DATA, contentValues);
             }
         }
-        // Name must be passed separately since it is skipped in RawContactModifier.parseValues
+        // Names must be passed separately since they are skipped in RawContactModifier.parseValues
         if (!TextUtils.isEmpty(displayName)) {
             intent.putExtra(ContactsContract.Intents.Insert.NAME, displayName);
         }
+        if (!TextUtils.isEmpty(phoneticName)) {
+            intent.putExtra(ContactsContract.Intents.Insert.PHONETIC_NAME, phoneticName);
+        }
     }
 }
diff --git a/src/com/android/contacts/editor/PhoneticNameEditorView.java b/src/com/android/contacts/editor/PhoneticNameEditorView.java
index 420575c..f094d55 100644
--- a/src/com/android/contacts/editor/PhoneticNameEditorView.java
+++ b/src/com/android/contacts/editor/PhoneticNameEditorView.java
@@ -151,4 +151,8 @@
         return !TextUtils.isEmpty(family) || !TextUtils.isEmpty(middle)
                 || !TextUtils.isEmpty(given);
     }
+
+    public String getPhoneticName() {
+        return getEntry().getAsString(DataKind.PSEUDO_COLUMN_PHONETIC_NAME);
+    }
 }