Merge "Show data entered in prefix, middle name and suffix in compact editor" into ub-contactsdialer-h-dev
diff --git a/res/layout/fragment_sim_import.xml b/res/layout/fragment_sim_import.xml
index 2da988e..b0eb280 100644
--- a/res/layout/fragment_sim_import.xml
+++ b/res/layout/fragment_sim_import.xml
@@ -63,8 +63,8 @@
                 android:id="@+id/list"
                 android:layout_width="match_parent"
                 android:layout_height="match_parent"
-                android:paddingTop="8dp"
-                android:clipToPadding="false"/>
+                android:clipToPadding="false"
+                android:paddingTop="8dp"/>
 
             <android.support.v4.widget.ContentLoadingProgressBar
                 android:id="@+id/loading_progress"
diff --git a/res/layout/item_read_only_field.xml b/res/layout/item_read_only_field.xml
index 3195b4c..e5444a4 100644
--- a/res/layout/item_read_only_field.xml
+++ b/res/layout/item_read_only_field.xml
@@ -31,6 +31,7 @@
         android:layout_width="0dp"
         android:layout_weight="1"
         android:layout_height="wrap_content"
+        android:layout_marginStart="@dimen/editor_account_left_margin"
         android:orientation="vertical">
 
         <TextView
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 29c92c2..b1e4762 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -720,6 +720,11 @@
          at a pre-determined text size. [CHAR LIMIT=20] -->
     <string name="contact_editor_title_existing_contact">Edit contact</string>
 
+    <!-- Title of the editor activity when viewing a read-only raw contact. The char
+         limit is short and cannot be increased, since this needs to be displayed in a single line
+         at a pre-determined text size. [CHAR LIMIT=20] -->
+    <string name="contact_editor_title_read_only_contact">View only</string>
+
     <!-- Dialog title when the user is selecting a raw contact to edit.  [CHAR LIMIT=128] -->
     <string name="contact_editor_pick_raw_contact_dialog_title">Choose linked contact</string>
 
@@ -832,8 +837,8 @@
     <!-- Label for the account selector to indicate which account a contact will be saved to. [CHAR LIMIT=30] -->
     <string name="editor_account_selector_title">Saving to</string>
 
-    <!-- Label for the account selector to indicate which read-only account is being viewed. [CHAR LIMIT=30] -->
-    <string name="editor_account_selector_read_only_title">Viewing</string>
+    <!-- Label for the account selector to indicate the current information comes from a read-only account. [CHAR LIMIT=50] -->
+    <string name="editor_account_selector_read_only_title">Contact info from <xliff:g id="account">%s</xliff:g> is not editable</string>
 
     <!-- Content description for the account selector to indicate which account a contact will be saved to. [CHAR LIMIT=NONE] -->
     <string name="editor_account_selector_description">Currently saving to <xliff:g id="account_name">%s</xliff:g>. Double-tap to pick a different account.</string>
@@ -920,13 +925,13 @@
     <!-- Content description of photo in photo picker indicating a photo from unknown account is selected. -->
     <string name="photo_view_description_checked_no_info">Photo from unknown account checked</string>
 
-    <!-- Left drawer menu item to open contacts assistant cards. [CHAR LIMIT=20]-->
-    <string name="menu_assistant">Assistant</string>
+    <!-- Left drawer menu item to open contacts assistant/suggestion cards. [CHAR LIMIT=20]-->
+    <string name="menu_assistant">Suggestions</string>
 
     <!-- The menu item to open the link/merge duplicates activity. [CHAR LIMIT=20]-->
     <string name="menu_duplicates">Duplicates</string>
 
-    <!-- Assistant 'NEW' badge text. Badge shown next to Assistant in left drawer menu when user has not visited it yet. [CHAR LIMIT=10] -->
+    <!-- Badge shown next to Suggestions in left drawer menu when user has not visited it yet. [CHAR LIMIT=10] -->
     <string name="menu_assistant_new_badge">New</string>
 
     <!-- Open drawer content descriptions [CHAR LIMIT=40] -->
diff --git a/src/com/android/contacts/SimImportFragment.java b/src/com/android/contacts/SimImportFragment.java
index c43caaa..2bd4bac 100644
--- a/src/com/android/contacts/SimImportFragment.java
+++ b/src/com/android/contacts/SimImportFragment.java
@@ -391,6 +391,12 @@
         private void setViewEnabled(ContactListItemView itemView, boolean enabled) {
             itemView.getCheckBox().setEnabled(enabled);
             itemView.getNameTextView().setEnabled(enabled);
+            // If the checkbox is left to default it's "unchecked" state will be announced when
+            // it is clicked on instead of the snackbar which is not useful.
+            int accessibilityMode = enabled ?
+                    View.IMPORTANT_FOR_ACCESSIBILITY_YES :
+                    View.IMPORTANT_FOR_ACCESSIBILITY_NO;
+            itemView.getCheckBox().setImportantForAccessibility(accessibilityMode);
         }
     }
 
diff --git a/src/com/android/contacts/common/preference/ContactsPreferences.java b/src/com/android/contacts/common/preference/ContactsPreferences.java
index 8865e91..ac7b0e0 100644
--- a/src/com/android/contacts/common/preference/ContactsPreferences.java
+++ b/src/com/android/contacts/common/preference/ContactsPreferences.java
@@ -16,13 +16,10 @@
 
 package com.android.contacts.common.preference;
 
-import android.content.ContentResolver;
 import android.content.Context;
 import android.content.SharedPreferences;
 import android.content.SharedPreferences.Editor;
 import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
-import android.net.Uri;
-import android.os.Bundle;
 import android.os.Handler;
 import android.os.Looper;
 import android.preference.PreferenceManager;
@@ -219,7 +216,8 @@
             return defaultAccount == null || !defaultAccount.isNullAccount();
         }
 
-        if (currentWritableAccounts.size() == 1) {
+        if (currentWritableAccounts.size() == 1
+                && !currentWritableAccounts.get(0).isNullAccount()) {
             return false;
         }
 
diff --git a/src/com/android/contacts/editor/ContactEditorFragment.java b/src/com/android/contacts/editor/ContactEditorFragment.java
index 65c30e8..54465fd 100644
--- a/src/com/android/contacts/editor/ContactEditorFragment.java
+++ b/src/com/android/contacts/editor/ContactEditorFragment.java
@@ -17,6 +17,7 @@
 package com.android.contacts.editor;
 
 import android.accounts.Account;
+import android.app.ActionBar;
 import android.app.Activity;
 import android.app.Fragment;
 import android.app.LoaderManager;
@@ -987,6 +988,9 @@
             mStatus = Status.SUB_ACTIVITY;
             startActivityForResult(intent, REQUEST_CODE_ACCOUNTS_CHANGED);
         } else {
+            // Make sure the default account is automatically set if there is only one non-device
+            // account.
+            mEditorUtils.maybeUpdateDefaultAccount();
             // Otherwise, there should be a default account. Then either create a local contact
             // (if default account is null) or create a contact with the specified account.
             AccountWithDataSet defaultAccount = mEditorUtils.getOnlyOrDefaultAccount();
@@ -1237,6 +1241,13 @@
         editorView.setState(mState, mMaterialPalette, mViewIdGenerator,
                 mHasNewContact, mIsUserProfile, mAccountWithDataSet,
                 mRawContactIdToDisplayAlone);
+        if (isEditingReadOnlyRawContact()) {
+            final ActionBar actionBar = getEditorActivity().getActionBar();
+            if (actionBar != null) {
+                actionBar.setTitle(R.string.contact_editor_title_read_only_contact);
+                actionBar.setHomeAsUpIndicator(R.drawable.ic_back_arrow);
+            }
+        }
 
         // Set up the photo widget
         editorView.setPhotoListener(this);
diff --git a/src/com/android/contacts/editor/ContactEditorUtils.java b/src/com/android/contacts/editor/ContactEditorUtils.java
index fc1a887..5b80b04 100644
--- a/src/com/android/contacts/editor/ContactEditorUtils.java
+++ b/src/com/android/contacts/editor/ContactEditorUtils.java
@@ -132,6 +132,20 @@
         return mContactsPrefs.shouldShowAccountChangedNotification(getWritableAccounts());
     }
 
+    /**
+     * Sets the only non-device account to be default if it is not already.
+     */
+    public void maybeUpdateDefaultAccount() {
+        final List<AccountWithDataSet> currentWritableAccounts = getWritableAccounts();
+        if (currentWritableAccounts.size() == 1) {
+            final AccountWithDataSet onlyAccount = currentWritableAccounts.get(0);
+            if (!onlyAccount.isNullAccount()
+                    && !onlyAccount.equals(mContactsPrefs.getDefaultAccount())) {
+                mContactsPrefs.setDefaultAccount(onlyAccount);
+            }
+        }
+    }
+
     @VisibleForTesting
     String[] getWritableAccountTypeStrings() {
         final Set<String> types = Sets.newHashSet();
diff --git a/src/com/android/contacts/editor/RawContactEditorView.java b/src/com/android/contacts/editor/RawContactEditorView.java
index fe7894a..8df7c37 100644
--- a/src/com/android/contacts/editor/RawContactEditorView.java
+++ b/src/com/android/contacts/editor/RawContactEditorView.java
@@ -212,8 +212,8 @@
 
     // Account header
     private View mAccountHeaderContainer;
-    private TextView mAccountHeaderType;
-    private TextView mAccountHeaderName;
+    private TextView mAccountHeaderPrimaryText;
+    private TextView mAccountHeaderSecondaryText;
     private ImageView mAccountHeaderIcon;
     private ImageView mAccountHeaderExpanderIcon;
 
@@ -254,8 +254,8 @@
 
         // Account header
         mAccountHeaderContainer = findViewById(R.id.account_header_container);
-        mAccountHeaderType = (TextView) findViewById(R.id.account_type);
-        mAccountHeaderName = (TextView) findViewById(R.id.account_name);
+        mAccountHeaderPrimaryText = (TextView) findViewById(R.id.account_type);
+        mAccountHeaderSecondaryText = (TextView) findViewById(R.id.account_name);
         mAccountHeaderIcon = (ImageView) findViewById(R.id.account_type_icon);
         mAccountHeaderExpanderIcon = (ImageView) findViewById(R.id.account_expander_icon);
 
@@ -489,6 +489,7 @@
 
         // Setup the view
         addPhotoView();
+        setAccountInfo();
         if (isReadOnlyRawContact()) {
             // We're want to display the inputs fields for a single read only raw contact
             addReadOnlyRawContactEditorViews();
@@ -499,7 +500,6 @@
     }
 
     private void setupEditorNormally() {
-        addAccountInfo();
         addKindSectionViews();
 
         mMoreFields.setVisibility(hasMoreFields() ? View.VISIBLE : View.GONE);
@@ -600,7 +600,6 @@
 
     private void addReadOnlyRawContactEditorViews() {
         mKindSectionViews.removeAllViews();
-        addAccountInfo();
         final AccountTypeManager accountTypes = AccountTypeManager.getInstance(
                 getContext());
         final AccountType type = mCurrentRawContactDelta.getAccountType(accountTypes);
@@ -713,18 +712,23 @@
         mKindSectionViews.addView(field);
     }
 
-    private void addAccountInfo() {
-        mAccountHeaderContainer.setVisibility(View.GONE);
-
+    private void setAccountInfo() {
         final AccountDisplayInfo account =
                 mAccountDisplayInfoFactory.getAccountDisplayInfoFor(mCurrentRawContactDelta);
 
         // Get the account information for the primary raw contact delta
-        final String accountLabel = mIsUserProfile
-                ? EditorUiUtils.getAccountHeaderLabelForMyProfile(getContext(), account)
-                : account.getNameLabel().toString();
-
-        addAccountHeader(accountLabel);
+        if (isReadOnlyRawContact()) {
+            final String accountType = account.getTypeLabel().toString();
+            setAccountHeader(accountType,
+                    getResources().getString(
+                            R.string.editor_account_selector_read_only_title, accountType));
+        } else {
+            final String accountLabel = mIsUserProfile
+                    ? EditorUiUtils.getAccountHeaderLabelForMyProfile(getContext(), account)
+                    : account.getNameLabel().toString();
+            setAccountHeader(getResources().getString(R.string.editor_account_selector_title),
+                    accountLabel);
+        }
 
         // If we're saving a new contact and there are multiple accounts, add the account selector.
         final List<AccountWithDataSet> accounts =
@@ -734,18 +738,9 @@
         }
     }
 
-    private void addAccountHeader(String accountLabel) {
-        mAccountHeaderContainer.setVisibility(View.VISIBLE);
-
-        // Set the account name
-        mAccountHeaderName.setVisibility(View.VISIBLE);
-        mAccountHeaderName.setText(accountLabel);
-
-        // Set the account type
-        final String selectorTitle = getResources().getString(isReadOnlyRawContact() ?
-                R.string.editor_account_selector_read_only_title :
-                R.string.editor_account_selector_title);
-        mAccountHeaderType.setText(selectorTitle);
+    private void setAccountHeader(String primaryText, String secondaryText) {
+        mAccountHeaderPrimaryText.setText(primaryText);
+        mAccountHeaderSecondaryText.setText(secondaryText);
 
         // Set the icon
         final AccountType accountType =
@@ -754,8 +749,8 @@
 
         // Set the content description
         mAccountHeaderContainer.setContentDescription(
-                EditorUiUtils.getAccountInfoContentDescription(accountLabel,
-                        selectorTitle));
+                EditorUiUtils.getAccountInfoContentDescription(primaryText,
+                        secondaryText));
     }
 
     private void addAccountSelector(final RawContactDelta rawContactDelta) {
diff --git a/tests/src/com/android/contacts/RunMethodInstrumentation.java b/tests/src/com/android/contacts/RunMethodInstrumentation.java
index f7e3970..d7ffee9 100644
--- a/tests/src/com/android/contacts/RunMethodInstrumentation.java
+++ b/tests/src/com/android/contacts/RunMethodInstrumentation.java
@@ -19,6 +19,7 @@
 import android.app.Instrumentation;
 import android.content.Context;
 import android.os.Bundle;
+import android.os.Debug;
 import android.support.test.InstrumentationRegistry;
 import android.util.Log;
 
@@ -62,6 +63,9 @@
         Log.d(TAG, "Running " + className + "." + methodName);
         Log.d(TAG, "args=" + args);
 
+        if (arguments.containsKey("debug") && Boolean.parseBoolean(arguments.getString("debug"))) {
+            Debug.waitForDebugger();
+        }
         start();
     }