Show google account types on editor as "account" instead of "contact"

Also, missed the copy of the account type display lable setting
logic for read-only contacts in ag/712716 so replacing that with
the static utility method.

Bug 18719390
Bug 21637149

Change-Id: I112b32a25d4d3682ca8e58ef327660bd163cb273
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 9e76bd3..936f093 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -397,6 +397,9 @@
     <!-- String describing which account type a contact came from when editing it -->
     <string name="account_type_format"><xliff:g id="source" example="Gmail">%1$s</xliff:g> contact</string>
 
+    <!-- String describing that a contact came from the google account type when editing it.  -->
+    <string name="google_account_type_format"><xliff:g id="source" example="Google">%1$s</xliff:g> account</string>
+
     <!-- String describing which account a contact came from when editing it -->
     <string name="from_account_format"><xliff:g id="source" example="user@gmail.com">%1$s</xliff:g></string>
 
diff --git a/src/com/android/contacts/editor/CompactRawContactsEditorView.java b/src/com/android/contacts/editor/CompactRawContactsEditorView.java
index ca2aa93..e2ecbd6 100644
--- a/src/com/android/contacts/editor/CompactRawContactsEditorView.java
+++ b/src/com/android/contacts/editor/CompactRawContactsEditorView.java
@@ -345,8 +345,7 @@
 
         // Get the account information for the default account RawContactDelta
         final Pair<String,String> accountInfo = EditorUiUtils.getAccountInfo(getContext(),
-                isUserProfile, defaultAccountRawContactDelta.getAccountName(),
-                accountType.getDisplayLabel(getContext()));
+                isUserProfile, defaultAccountRawContactDelta.getAccountName(), accountType);
 
         // Set the account information already
         if (accountInfo == null) {
diff --git a/src/com/android/contacts/editor/EditorUiUtils.java b/src/com/android/contacts/editor/EditorUiUtils.java
index 301ce35..78f7a42 100644
--- a/src/com/android/contacts/editor/EditorUiUtils.java
+++ b/src/com/android/contacts/editor/EditorUiUtils.java
@@ -25,6 +25,8 @@
 import android.text.TextUtils;
 import android.util.Pair;
 import com.android.contacts.R;
+import com.android.contacts.common.model.account.AccountType;
+import com.android.contacts.common.model.account.GoogleAccountType;
 import com.android.contacts.common.model.dataitem.DataKind;
 import com.google.common.collect.Maps;
 
@@ -85,24 +87,37 @@
      * in no account information should be displayed. The account name may also be null.
      */
     public static Pair<String,String> getAccountInfo(Context context, boolean isProfile,
-            String accountName, CharSequence accountType) {
+            String accountName, AccountType accountType) {
+        CharSequence accountTypeDisplayLabel = accountType.getDisplayLabel(context);
+
         if (isProfile) {
             if (TextUtils.isEmpty(accountName)) {
                 return new Pair<>(
                         /* accountName =*/ null,
                         context.getString(R.string.local_profile_title));
-            } else {
-                return new Pair<>(
-                        accountName,
-                        context.getString(R.string.external_profile_title, accountType));
-            }
-        } else if (!TextUtils.isEmpty(accountName)) {
-            if (TextUtils.isEmpty(accountType)) {
-                accountType = context.getString(R.string.account_phone);
             }
             return new Pair<>(
-                    context.getString(R.string.from_account_format, accountName),
-                    context.getString(R.string.account_type_format, accountType));
+                    accountName,
+                    context.getString(R.string.external_profile_title, accountTypeDisplayLabel));
+        }
+        if (!TextUtils.isEmpty(accountName)) {
+            final String accountNameDisplayLabel =
+                    context.getString(R.string.from_account_format, accountName);
+
+            if (TextUtils.isEmpty(accountTypeDisplayLabel)) {
+                accountTypeDisplayLabel = context.getString(R.string.account_phone);
+            }
+
+            if (GoogleAccountType.ACCOUNT_TYPE.equals(accountType.accountType)
+                    && accountType.dataSet == null) {
+                return new Pair<>(
+                        accountNameDisplayLabel,
+                        context.getString(R.string.google_account_type_format,
+                                accountTypeDisplayLabel));
+            }
+            return new Pair<>(
+                    accountNameDisplayLabel,
+                    context.getString(R.string.account_type_format, accountTypeDisplayLabel));
         }
         return null;
     }
diff --git a/src/com/android/contacts/editor/RawContactEditorView.java b/src/com/android/contacts/editor/RawContactEditorView.java
index 11f0c1e..6c55854 100644
--- a/src/com/android/contacts/editor/RawContactEditorView.java
+++ b/src/com/android/contacts/editor/RawContactEditorView.java
@@ -191,7 +191,7 @@
 
         // Fill in the account info
         final Pair<String,String> accountInfo = EditorUiUtils.getAccountInfo(getContext(),
-                isProfile, state.getAccountName(), type.getDisplayLabel(getContext()));
+                isProfile, state.getAccountName(), type);
         if (accountInfo == 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 7ae6aa7..d7b3dd0 100644
--- a/src/com/android/contacts/editor/RawContactReadOnlyEditorView.java
+++ b/src/com/android/contacts/editor/RawContactReadOnlyEditorView.java
@@ -28,6 +28,7 @@
 import android.telephony.PhoneNumberUtils;
 import android.text.TextUtils;
 import android.util.AttributeSet;
+import android.util.Pair;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.View.OnClickListener;
@@ -114,32 +115,19 @@
         mAccountType = state.getAccountType();
         mDataSet = state.getDataSet();
 
-        if (isProfile) {
-            if (TextUtils.isEmpty(mAccountName)) {
-                mAccountHeaderNameTextView.setVisibility(View.GONE);
-                mAccountHeaderTypeTextView.setText(R.string.local_profile_title);
-            } else {
-                CharSequence accountType = type.getDisplayLabel(getContext());
-                mAccountHeaderTypeTextView.setText(getContext().getString(
-                        R.string.external_profile_title,
-                        accountType));
-                mAccountHeaderNameTextView.setText(mAccountName);
-            }
+        final Pair<String,String> accountInfo = EditorUiUtils.getAccountInfo(getContext(),
+                isProfile, state.getAccountName(), type);
+        if (accountInfo == null) {
+            // Hide this view so the other text view will be centered vertically
+            mAccountHeaderNameTextView.setVisibility(View.GONE);
         } else {
-            CharSequence accountType = type.getDisplayLabel(getContext());
-            if (TextUtils.isEmpty(accountType)) {
-                accountType = getContext().getString(R.string.account_phone);
-            }
-            if (!TextUtils.isEmpty(mAccountName)) {
-                mAccountHeaderNameTextView.setVisibility(View.VISIBLE);
-                mAccountHeaderNameTextView.setText(
-                        getContext().getString(R.string.from_account_format, mAccountName));
-            } else {
-                // Hide this view so the other text view will be centered vertically
+            if (accountInfo.first == null) {
                 mAccountHeaderNameTextView.setVisibility(View.GONE);
+            } else {
+                mAccountHeaderNameTextView.setVisibility(View.VISIBLE);
+                mAccountHeaderNameTextView.setText(accountInfo.first);
             }
-            mAccountHeaderTypeTextView.setText(getContext().getString(R.string.account_type_format,
-                    accountType));
+            mAccountHeaderTypeTextView.setText(accountInfo.second);
         }
         updateAccountHeaderContentDescription();