Merge "Fixed the issue "set default" is not shown"
diff --git a/res/layout/select_dialog_item.xml b/res/layout/select_dialog_item.xml
index 1215aa9..05f2ae5 100644
--- a/res/layout/select_dialog_item.xml
+++ b/res/layout/select_dialog_item.xml
@@ -22,7 +22,8 @@
 <LinearLayout
     xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
-    android:layout_height="56dp"
+    android:layout_height="wrap_content"
+    android:minHeight="56dp"
     android:orientation="vertical"
     android:paddingBottom="8dp"
     android:paddingEnd="24dp"
diff --git a/src/com/android/contacts/preference/ContactsPreferenceActivity.java b/src/com/android/contacts/preference/ContactsPreferenceActivity.java
index 2d83bf1..1c7469f 100644
--- a/src/com/android/contacts/preference/ContactsPreferenceActivity.java
+++ b/src/com/android/contacts/preference/ContactsPreferenceActivity.java
@@ -20,6 +20,7 @@
 import android.database.Cursor;
 import android.os.Bundle;
 import android.preference.PreferenceActivity;
+import android.provider.ContactsContract.DisplayNameSources;
 import android.provider.ContactsContract.ProviderStatus;
 import android.support.annotation.LayoutRes;
 import android.support.annotation.NonNull;
@@ -202,17 +203,19 @@
         boolean hasProfile = false;
         String displayName = null;
         long contactId = -1;
+        int displayNameSource = DisplayNameSources.UNDEFINED;
         if (cursor != null && cursor.moveToFirst()) {
             hasProfile = cursor.getInt(ProfileQuery.CONTACT_IS_USER_PROFILE) == 1;
             displayName = cursor.getString(ProfileQuery.CONTACT_DISPLAY_NAME);
             contactId = cursor.getLong(ProfileQuery.CONTACT_ID);
+            displayNameSource = cursor.getInt(ProfileQuery.DISPLAY_NAME_SOURCE);
         }
         if (hasProfile && TextUtils.isEmpty(displayName)) {
             displayName = getString(R.string.missing_name);
         }
         final DisplayOptionsPreferenceFragment fragment = (DisplayOptionsPreferenceFragment)
                 getFragmentManager().findFragmentByTag(TAG_DISPLAY_OPTIONS);
-        fragment.updateMyInfoPreference(hasProfile, displayName, contactId);
+        fragment.updateMyInfoPreference(hasProfile, displayName, contactId, displayNameSource);
     }
 
     @Override
diff --git a/src/com/android/contacts/preference/DisplayOptionsPreferenceFragment.java b/src/com/android/contacts/preference/DisplayOptionsPreferenceFragment.java
index 22a6683..82e90b3 100644
--- a/src/com/android/contacts/preference/DisplayOptionsPreferenceFragment.java
+++ b/src/com/android/contacts/preference/DisplayOptionsPreferenceFragment.java
@@ -33,11 +33,14 @@
 import android.preference.PreferenceFragment;
 import android.provider.BlockedNumberContract;
 import android.provider.ContactsContract.Contacts;
+import android.provider.ContactsContract.DisplayNameSources;
 import android.provider.ContactsContract.Profile;
 import android.support.design.widget.Snackbar;
 import android.support.v4.content.LocalBroadcastManager;
 import android.telecom.TelecomManager;
 import android.telephony.TelephonyManager;
+import android.text.BidiFormatter;
+import android.text.TextDirectionHeuristics;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
@@ -111,17 +114,20 @@
                 Contacts._ID,                           // 0
                 Contacts.DISPLAY_NAME_PRIMARY,          // 1
                 Contacts.IS_USER_PROFILE,               // 2
+                Contacts.DISPLAY_NAME_SOURCE,           // 3
         };
 
         private static final String[] PROFILE_PROJECTION_ALTERNATIVE = new String[] {
                 Contacts._ID,                           // 0
                 Contacts.DISPLAY_NAME_ALTERNATIVE,      // 1
                 Contacts.IS_USER_PROFILE,               // 2
+                Contacts.DISPLAY_NAME_SOURCE,           // 3
         };
 
         public static final int CONTACT_ID               = 0;
         public static final int CONTACT_DISPLAY_NAME     = 1;
         public static final int CONTACT_IS_USER_PROFILE  = 2;
+        public static final int DISPLAY_NAME_SOURCE      = 3;
     }
 
     private String mNewLocalProfileExtra;
@@ -255,8 +261,13 @@
         mRootView = null;
     }
 
-    public void updateMyInfoPreference(boolean hasProfile, String displayName, long contactId) {
-        final CharSequence summary = hasProfile ? displayName : getString(R.string.set_up_profile);
+    public void updateMyInfoPreference(boolean hasProfile, String displayName, long contactId,
+            int displayNameSource) {
+        final CharSequence summary = !hasProfile ?
+                getString(R.string.set_up_profile) :
+                displayNameSource == DisplayNameSources.PHONE ?
+                BidiFormatter.getInstance().unicodeWrap(displayName, TextDirectionHeuristics.LTR) :
+                displayName;
         mMyInfoPreference.setSummary(summary);
         mHasProfile = hasProfile;
         mProfileContactId = contactId;