Add device and SIM to AccountTypeManager
This makes these account types available throughout the app rather than
just the Nav drawer.
Test:
Added unit tests for new classes; run with:
$ adb shell am instrument -w \
com.google.android.tests/android.test.InstrumentationTestRunner
Manually on Nexus 6, LG G5 and Samsung S7 with device and SIM contacts
in CP2 by verifying "Device" and "SIM" options were available in
* nav drawer
* account list accessed by Pressing FAB without default account set
* editor account dropdown for new contact
* editor account label when editing existing contact
* picker for default account in settings
* settings customize screen account list
Bug 30867780
Change-Id: I329381ccc58d59f2e27f65a3d9dc0164fb20c971
diff --git a/src/com/android/contacts/editor/CompactRawContactsEditorView.java b/src/com/android/contacts/editor/CompactRawContactsEditorView.java
index d9cc58d..884cc51 100644
--- a/src/com/android/contacts/editor/CompactRawContactsEditorView.java
+++ b/src/com/android/contacts/editor/CompactRawContactsEditorView.java
@@ -16,6 +16,8 @@
package com.android.contacts.editor;
+import com.android.contacts.common.model.account.AccountDisplayInfo;
+import com.android.contacts.common.model.account.AccountDisplayInfoFactory;
import com.android.contacts.R;
import com.android.contacts.common.model.AccountTypeManager;
import com.android.contacts.common.model.RawContactDelta;
@@ -319,6 +321,7 @@
private CompactRawContactsEditorView.Listener mListener;
private AccountTypeManager mAccountTypeManager;
+ private AccountDisplayInfoFactory mAccountDisplayInfoFactory;
private LayoutInflater mLayoutInflater;
private ViewIdGenerator mViewIdGenerator;
@@ -372,6 +375,7 @@
super.onFinishInflate();
mAccountTypeManager = AccountTypeManager.getInstance(getContext());
+ mAccountDisplayInfoFactory = AccountDisplayInfoFactory.forWritableAccounts(getContext());
mLayoutInflater = (LayoutInflater)
getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
@@ -727,26 +731,25 @@
final RawContactDelta rawContactDelta =
mPrimaryNameKindSectionData.first.getRawContactDelta();
+ final AccountDisplayInfo account =
+ mAccountDisplayInfoFactory.getAccountDisplayInfoFor(rawContactDelta);
+
// Get the account information for the primary raw contact delta
- final Pair<String,String> accountInfo = mIsUserProfile
- ? EditorUiUtils.getLocalAccountInfo(getContext(),
- rawContactDelta.getAccountName(),
- rawContactDelta.getAccountType(mAccountTypeManager))
- : EditorUiUtils.getAccountInfo(getContext(),
- rawContactDelta.getAccountName(),
- rawContactDelta.getAccountType(mAccountTypeManager));
+ final String accountLabel = mIsUserProfile
+ ? EditorUiUtils.getAccountHeaderLabelForMyProfile(getContext(), account)
+ : account.getNameLabel().toString();
// Either the account header or selector should be shown, not both.
final List<AccountWithDataSet> accounts =
AccountTypeManager.getInstance(getContext()).getAccounts(true);
if (mHasNewContact && !mIsUserProfile) {
if (accounts.size() > 1) {
- addAccountSelector(accountInfo, rawContactDelta);
+ addAccountSelector(rawContactDelta, accountLabel);
} else {
- addAccountHeader(accountInfo);
+ addAccountHeader(accountLabel);
}
} else if (mIsUserProfile || !shouldHideAccountContainer(rawContactDeltas)) {
- addAccountHeader(accountInfo);
+ addAccountHeader(accountLabel);
}
// The raw contact selector should only display linked raw contacts that can be edited in
@@ -800,14 +803,12 @@
return (writable > 1 || (writable > 0 && readonly > 0));
}
- private void addAccountHeader(Pair<String,String> accountInfo) {
+ private void addAccountHeader(String accountLabel) {
mAccountHeaderContainer.setVisibility(View.VISIBLE);
// Set the account name
- final String accountName = TextUtils.isEmpty(accountInfo.first)
- ? accountInfo.second : accountInfo.first;
mAccountHeaderName.setVisibility(View.VISIBLE);
- mAccountHeaderName.setText(accountName);
+ mAccountHeaderName.setText(accountLabel);
// Set the account type
final String selectorTitle = getResources().getString(
@@ -827,13 +828,13 @@
// Set the content description
mAccountHeaderContainer.setContentDescription(
- EditorUiUtils.getAccountInfoContentDescription(accountName, selectorTitle));
+ EditorUiUtils.getAccountInfoContentDescription(accountLabel,
+ selectorTitle));
}
- private void addAccountSelector(Pair<String,String> accountInfo,
- final RawContactDelta rawContactDelta) {
+ private void addAccountSelector(final RawContactDelta rawContactDelta, CharSequence nameLabel) {
// Show save to default account.
- addAccountHeader(accountInfo);
+ addAccountHeader(nameLabel.toString());
// Add handlers for choosing another account to save to.
mAccountHeaderExpanderIcon.setVisibility(View.VISIBLE);
mAccountHeaderContainer.setOnClickListener(new View.OnClickListener() {