Fix header when editing a profile

Bug: 5179920 Google+ profile should say "My Google+ profile"

Added a case to change the header name when editing a profile.
The editor now gets a boolean indicating if the contact edited is a profile.
If it is a profile, the editor sets the header with "My X profile" according
to the account name.

Change-Id: I62af5011061f61a6d1d3c60845a1746c99cda04a
diff --git a/src/com/android/contacts/editor/BaseRawContactEditorView.java b/src/com/android/contacts/editor/BaseRawContactEditorView.java
index 38636f7..b2d7186 100644
--- a/src/com/android/contacts/editor/BaseRawContactEditorView.java
+++ b/src/com/android/contacts/editor/BaseRawContactEditorView.java
@@ -118,7 +118,8 @@
      * {@link EntityDelta} state and the {@link AccountType} that
      * apply to that state.
      */
-    public abstract void setState(EntityDelta state, AccountType source, ViewIdGenerator vig);
+    public abstract void setState(EntityDelta state, AccountType source, ViewIdGenerator vig,
+            boolean isProfile);
 
     /* package */ void setExpanded(boolean value) {
         // only allow collapsing if we are one of several children
diff --git a/src/com/android/contacts/editor/ContactEditorFragment.java b/src/com/android/contacts/editor/ContactEditorFragment.java
index 124cd86..87fcfe0 100644
--- a/src/com/android/contacts/editor/ContactEditorFragment.java
+++ b/src/com/android/contacts/editor/ContactEditorFragment.java
@@ -676,7 +676,7 @@
 
             mContent.addView(editor);
 
-            editor.setState(entity, type, mViewIdGenerator);
+            editor.setState(entity, type, mViewIdGenerator, isEditingUserProfile());
 
             editor.getPhotoEditor().setEditorListener(
                     new PhotoEditorListener(editor, type.readOnly));
diff --git a/src/com/android/contacts/editor/ExternalRawContactEditorView.java b/src/com/android/contacts/editor/ExternalRawContactEditorView.java
index eb496f2..8a18114 100644
--- a/src/com/android/contacts/editor/ExternalRawContactEditorView.java
+++ b/src/com/android/contacts/editor/ExternalRawContactEditorView.java
@@ -114,7 +114,8 @@
      * apply to that state.
      */
     @Override
-    public void setState(EntityDelta state, AccountType type, ViewIdGenerator vig) {
+    public void setState(EntityDelta state, AccountType type, ViewIdGenerator vig,
+            boolean isProfile) {
         // Remove any existing sections
         mGeneral.removeAllViews();
 
@@ -129,15 +130,27 @@
         mAccountName = values.getAsString(RawContacts.ACCOUNT_NAME);
         mAccountType = values.getAsString(RawContacts.ACCOUNT_TYPE);
         mDataSet = values.getAsString(RawContacts.DATA_SET);
-        CharSequence accountType = type.getDisplayLabel(mContext);
-        if (TextUtils.isEmpty(accountType)) {
-            accountType = mContext.getString(R.string.account_phone);
+
+        if (isProfile) {
+            mAccountNameTextView.setVisibility(View.GONE);
+            if (TextUtils.isEmpty(mAccountName)) {
+                mAccountTypeTextView.setText(R.string.local_profile_title);
+            } else {
+                mAccountTypeTextView.setText(
+                        mContext.getString(R.string.external_profile_title, mAccountName));
+            }
+        } else {
+            CharSequence accountType = type.getDisplayLabel(mContext);
+            if (TextUtils.isEmpty(accountType)) {
+                accountType = mContext.getString(R.string.account_phone);
+            }
+            if (!TextUtils.isEmpty(mAccountName)) {
+                mAccountNameTextView.setText(
+                        mContext.getString(R.string.from_account_format, mAccountName));
+            }
+            mAccountTypeTextView.setText(mContext.getString(R.string.account_type_format,
+                    accountType));
         }
-        if (!TextUtils.isEmpty(mAccountName)) {
-            mAccountNameTextView.setText(
-                    mContext.getString(R.string.from_account_format, mAccountName));
-        }
-        mAccountTypeTextView.setText(mContext.getString(R.string.account_type_format, accountType));
         mAccountTypeTextView.setTextColor(mContext.getResources().getColor(
                 R.color.secondary_text_color));
 
diff --git a/src/com/android/contacts/editor/RawContactEditorView.java b/src/com/android/contacts/editor/RawContactEditorView.java
index dd3c15a..bac6217 100644
--- a/src/com/android/contacts/editor/RawContactEditorView.java
+++ b/src/com/android/contacts/editor/RawContactEditorView.java
@@ -156,7 +156,8 @@
      * apply to that state.
      */
     @Override
-    public void setState(EntityDelta state, AccountType type, ViewIdGenerator vig) {
+    public void setState(EntityDelta state, AccountType type, ViewIdGenerator vig,
+            boolean isProfile) {
 
         mState = state;
 
@@ -176,17 +177,28 @@
         mRawContactId = values.getAsLong(RawContacts._ID);
 
         // Fill in the account info
-        String accountName = values.getAsString(RawContacts.ACCOUNT_NAME);
-        CharSequence accountType = type.getDisplayLabel(mContext);
-        if (TextUtils.isEmpty(accountType)) {
-            accountType = mContext.getString(R.string.account_phone);
+        if (isProfile) {
+            mAccountNameTextView.setVisibility(View.GONE);
+            String accountName = values.getAsString(RawContacts.ACCOUNT_NAME);
+            if (TextUtils.isEmpty(accountName)) {
+                mAccountTypeTextView.setText(R.string.local_profile_title);
+            } else {
+                mAccountTypeTextView.setText(
+                        mContext.getString(R.string.external_profile_title, accountName));
+            }
+        } else {
+            String accountName = values.getAsString(RawContacts.ACCOUNT_NAME);
+            CharSequence accountType = type.getDisplayLabel(mContext);
+            if (TextUtils.isEmpty(accountType)) {
+                accountType = mContext.getString(R.string.account_phone);
+            }
+            if (!TextUtils.isEmpty(accountName)) {
+                mAccountNameTextView.setText(
+                        mContext.getString(R.string.from_account_format, accountName));
+            }
+            mAccountTypeTextView.setText(
+                    mContext.getString(R.string.account_type_format, accountType));
         }
-        if (!TextUtils.isEmpty(accountName)) {
-            mAccountNameTextView.setText(
-                    mContext.getString(R.string.from_account_format, accountName));
-        }
-        mAccountTypeTextView.setText(
-                mContext.getString(R.string.account_type_format, accountType));
         mAccountIcon.setImageDrawable(type.getDisplayIcon(mContext));
 
         // Show photo editor when supported