Show "local only" account name for me profile

Bug 24988734

Change-Id: Ief827757e148d240ec74b46c1dfbb11c1c68a18c
diff --git a/src/com/android/contacts/editor/CompactRawContactsEditorView.java b/src/com/android/contacts/editor/CompactRawContactsEditorView.java
index e02e35a..900889e 100644
--- a/src/com/android/contacts/editor/CompactRawContactsEditorView.java
+++ b/src/com/android/contacts/editor/CompactRawContactsEditorView.java
@@ -781,9 +781,13 @@
         }
 
         // Get the account information for the primary raw contact delta
-        final Pair<String,String> accountInfo = EditorUiUtils.getAccountInfo(getContext(),
-                mIsUserProfile, mPrimaryRawContactDelta.getAccountName(),
-                mPrimaryRawContactDelta.getAccountType(mAccountTypeManager));
+        final Pair<String,String> accountInfo = mIsUserProfile
+                ? EditorUiUtils.getLocalAccountInfo(getContext(),
+                        mPrimaryRawContactDelta.getAccountName(),
+                        mPrimaryRawContactDelta.getAccountType(mAccountTypeManager))
+                : EditorUiUtils.getAccountInfo(getContext(),
+                        mPrimaryRawContactDelta.getAccountName(),
+                        mPrimaryRawContactDelta.getAccountType(mAccountTypeManager));
 
         // The account header and selector show the same information so both shouldn't be visible
         // at the same time
@@ -801,12 +805,39 @@
             mAccountSelectorContainer.setVisibility(View.GONE);
             addRawContactAccountSelector(rawContactDeltas);
         } else {
-            addAccountHeader(accountInfo);
+            if (mIsUserProfile) {
+                addLocalAccountHeader(accountInfo);
+            } else {
+                addAccountHeader(accountInfo);
+            }
             mAccountSelectorContainer.setVisibility(View.GONE);
         }
     }
 
+    private void addLocalAccountHeader(Pair<String,String> accountInfo) {
+        // Set the account name
+        final String accountName = TextUtils.isEmpty(accountInfo.first)
+                ? accountInfo.second : accountInfo.first;
+        mAccountHeaderName.setVisibility(View.VISIBLE);
+        mAccountHeaderName.setText(accountName);
+
+        // Set the account type
+        final String selectorTitle = getResources().getString(
+                R.string.compact_editor_account_selector_title);
+        mAccountHeaderType.setText(selectorTitle);
+
+        // Set the icon
+        final AccountType primaryAccountType =
+                mPrimaryRawContactDelta.getRawContactAccountType(getContext());
+        mAccountHeaderIcon.setImageDrawable(primaryAccountType.getDisplayIcon(getContext()));
+
+        // Set the content description
+        mAccountHeaderContainer.setContentDescription(
+                EditorUiUtils.getAccountInfoContentDescription(accountName, selectorTitle));
+    }
+
     private void addAccountHeader(Pair<String,String> accountInfo) {
+        // Set the account name
         if (TextUtils.isEmpty(accountInfo.first)) {
             // Hide this view so the other text view will be centered vertically
             mAccountHeaderName.setVisibility(View.GONE);
@@ -815,14 +846,17 @@
             mAccountHeaderName.setText(accountInfo.first);
         }
 
+        // Set the account type
         final String selectorTitle = getResources().getString(
                 R.string.compact_editor_account_selector_title);
         mAccountHeaderType.setText(selectorTitle);
 
+        // Set the icon
         final AccountType primaryAccountType = mPrimaryRawContactDelta.getRawContactAccountType(
                 getContext());
         mAccountHeaderIcon.setImageDrawable(primaryAccountType.getDisplayIcon(getContext()));
 
+        // Set the content description
         mAccountHeaderContainer.setContentDescription(
                 EditorUiUtils.getAccountInfoContentDescription(
                         accountInfo.first, selectorTitle));
diff --git a/src/com/android/contacts/editor/EditorUiUtils.java b/src/com/android/contacts/editor/EditorUiUtils.java
index 24ba7df..a513be5 100644
--- a/src/com/android/contacts/editor/EditorUiUtils.java
+++ b/src/com/android/contacts/editor/EditorUiUtils.java
@@ -112,25 +112,26 @@
     }
 
     /**
-     * Returns the account name and account type labels to display for the given account type.
-     *
-     * @param isProfile True to get the labels for the "me" profile or a phone only (local) contact
-     *         and false otherwise.
+     * Returns the account name and account type labels to display for local accounts.
      */
-    public static Pair<String,String> getAccountInfo(Context context,
-            boolean isProfile, String accountName, AccountType accountType) {
-        if (isProfile) {
-            if (TextUtils.isEmpty(accountName)) {
-                return new Pair<>(
-                        /* accountName =*/ null,
-                        context.getString(R.string.local_profile_title));
-            }
+    public static Pair<String,String> getLocalAccountInfo(Context context,
+            String accountName, AccountType accountType) {
+        if (TextUtils.isEmpty(accountName)) {
             return new Pair<>(
-                    accountName,
-                    context.getString(R.string.external_profile_title,
-                            accountType.getDisplayLabel(context)));
+                    /* accountName =*/ null,
+                    context.getString(R.string.local_profile_title));
         }
+        return new Pair<>(
+                accountName,
+                context.getString(R.string.external_profile_title,
+                        accountType.getDisplayLabel(context)));
+    }
 
+    /**
+     * Returns the account name and account type labels to display for the given account type.
+     */
+    public static Pair<String,String> getAccountInfo(Context context, String accountName,
+            AccountType accountType) {
         CharSequence accountTypeDisplayLabel = accountType.getDisplayLabel(context);
         if (TextUtils.isEmpty(accountTypeDisplayLabel)) {
             accountTypeDisplayLabel = context.getString(R.string.account_phone);
@@ -167,7 +168,7 @@
             builder.append(accountType).append('\n');
         }
         if (!TextUtils.isEmpty(accountName)) {
-            builder.append(accountName).append('\n');
+            builder.append(accountName);
         }
         return builder.toString();
     }
diff --git a/src/com/android/contacts/editor/RawContactEditorView.java b/src/com/android/contacts/editor/RawContactEditorView.java
index 1832ce2..b6320e9 100644
--- a/src/com/android/contacts/editor/RawContactEditorView.java
+++ b/src/com/android/contacts/editor/RawContactEditorView.java
@@ -189,8 +189,9 @@
         mRawContactId = state.getRawContactId();
 
         // Fill in the account info
-        final Pair<String,String> accountInfo = EditorUiUtils.getAccountInfo(getContext(),
-                isProfile, state.getAccountName(), type);
+        final Pair<String,String> accountInfo = isProfile
+                ? EditorUiUtils.getLocalAccountInfo(getContext(), state.getAccountName(), type)
+                : EditorUiUtils.getAccountInfo(getContext(), state.getAccountName(), type);
         if (accountInfo.first == null) {
             // Hide this view so the other text view will be centered vertically
             mAccountHeaderNameTextView.setVisibility(View.GONE);
diff --git a/src/com/android/contacts/editor/RawContactReadOnlyEditorView.java b/src/com/android/contacts/editor/RawContactReadOnlyEditorView.java
index 76fa097..ad2e013 100644
--- a/src/com/android/contacts/editor/RawContactReadOnlyEditorView.java
+++ b/src/com/android/contacts/editor/RawContactReadOnlyEditorView.java
@@ -115,8 +115,9 @@
         mAccountType = state.getAccountType();
         mDataSet = state.getDataSet();
 
-        final Pair<String,String> accountInfo = EditorUiUtils.getAccountInfo(getContext(),
-                isProfile, state.getAccountName(), type);
+        final Pair<String,String> accountInfo = isProfile
+                ? EditorUiUtils.getLocalAccountInfo(getContext(), state.getAccountName(), type)
+                : EditorUiUtils.getAccountInfo(getContext(), state.getAccountName(), type);
         if (accountInfo.first == null) {
             // Hide this view so the other text view will be centered vertically
             mAccountHeaderNameTextView.setVisibility(View.GONE);