Loading src/com/android/contacts/editor/CompactRawContactsEditorView.java +38 −4 Original line number Diff line number Diff line Loading @@ -781,8 +781,12 @@ public class CompactRawContactsEditorView extends LinearLayout implements View.O } // Get the account information for the primary raw contact delta final Pair<String,String> accountInfo = EditorUiUtils.getAccountInfo(getContext(), mIsUserProfile, mPrimaryRawContactDelta.getAccountName(), 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 Loading @@ -800,13 +804,40 @@ public class CompactRawContactsEditorView extends LinearLayout implements View.O mAccountHeaderContainer.setVisibility(View.GONE); mAccountSelectorContainer.setVisibility(View.GONE); addRawContactAccountSelector(rawContactDeltas); } else { 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); Loading @@ -815,14 +846,17 @@ public class CompactRawContactsEditorView extends LinearLayout implements View.O 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)); Loading src/com/android/contacts/editor/EditorUiUtils.java +17 −16 Original line number Diff line number Diff line Loading @@ -112,14 +112,10 @@ public class EditorUiUtils { } /** * 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) { public static Pair<String,String> getLocalAccountInfo(Context context, String accountName, AccountType accountType) { if (TextUtils.isEmpty(accountName)) { return new Pair<>( /* accountName =*/ null, Loading @@ -131,6 +127,11 @@ public class EditorUiUtils { 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); Loading Loading @@ -167,7 +168,7 @@ public class EditorUiUtils { builder.append(accountType).append('\n'); } if (!TextUtils.isEmpty(accountName)) { builder.append(accountName).append('\n'); builder.append(accountName); } return builder.toString(); } Loading src/com/android/contacts/editor/RawContactEditorView.java +3 −2 Original line number Diff line number Diff line Loading @@ -189,8 +189,9 @@ public class RawContactEditorView extends BaseRawContactEditorView { 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); Loading src/com/android/contacts/editor/RawContactReadOnlyEditorView.java +3 −2 Original line number Diff line number Diff line Loading @@ -115,8 +115,9 @@ public class RawContactReadOnlyEditorView extends BaseRawContactEditorView 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); Loading tests/src/com/android/contacts/editor/EditorUiUtilsTest.java +7 −7 Original line number Diff line number Diff line Loading @@ -68,7 +68,7 @@ public class EditorUiUtilsTest extends AndroidTestCase { } public void testGetProfileAccountInfo_AccountName() { final Pair pair = EditorUiUtils.getAccountInfo(getContext(), /* isProfile =*/ true, final Pair pair = EditorUiUtils.getLocalAccountInfo(getContext(), ACCOUNT_NAME, new MockAccountType(DISPLAY_LABEL)); assertNotNull(pair); Loading @@ -78,7 +78,7 @@ public class EditorUiUtilsTest extends AndroidTestCase { } public void testGetProfileAccountInfo_NoAccountName() { final Pair pair = EditorUiUtils.getAccountInfo(getContext(), /* isProfile =*/ true, final Pair pair = EditorUiUtils.getLocalAccountInfo(getContext(), /* accountName =*/ null, new MockAccountType(DISPLAY_LABEL)); assertNotNull(pair); Loading @@ -88,7 +88,7 @@ public class EditorUiUtilsTest extends AndroidTestCase { } public void testGetAccountInfo_AccountName_DisplayLabel() { final Pair pair = EditorUiUtils.getAccountInfo(getContext(), /* isProfile =*/ false, final Pair pair = EditorUiUtils.getAccountInfo(getContext(), ACCOUNT_NAME, new MockAccountType(DISPLAY_LABEL)); assertNotNull(pair); Loading @@ -101,7 +101,7 @@ public class EditorUiUtilsTest extends AndroidTestCase { public void testGetAccountInfo_AccountName_DisplayLabel_GoogleAccountType() { final AccountType accountType = new MockAccountType(GOOGLE_DISPLAY_LABEL); accountType.accountType = GoogleAccountType.ACCOUNT_TYPE; final Pair pair = EditorUiUtils.getAccountInfo(getContext(), /* isProfile =*/ false, final Pair pair = EditorUiUtils.getAccountInfo(getContext(), GOOGLE_ACCOUNT_NAME, accountType); assertNotNull(pair); Loading @@ -113,7 +113,7 @@ public class EditorUiUtilsTest extends AndroidTestCase { } public void testGetAccountInfo_AccountName_NoDisplayLabel() { final Pair pair = EditorUiUtils.getAccountInfo(getContext(), /* isProfile =*/ false, final Pair pair = EditorUiUtils.getAccountInfo(getContext(), ACCOUNT_NAME, new MockAccountType(/* displayLabel =*/ null)); assertNotNull(pair); Loading @@ -126,7 +126,7 @@ public class EditorUiUtilsTest extends AndroidTestCase { } public void testGetAccountInfo_NoAccountName_DisplayLabel() { final Pair pair = EditorUiUtils.getAccountInfo(getContext(), /* isProfile =*/ false, final Pair pair = EditorUiUtils.getAccountInfo(getContext(), /* accountName =*/ null, new MockAccountType(DISPLAY_LABEL)); assertNotNull(pair); Loading @@ -136,7 +136,7 @@ public class EditorUiUtilsTest extends AndroidTestCase { } public void testGetAccountInfo_NoAccountName_NoDisplayLabel() { final Pair pair = EditorUiUtils.getAccountInfo(getContext(), /* isProfile =*/ false, final Pair pair = EditorUiUtils.getAccountInfo(getContext(), /* accountName =*/ null, new MockAccountType(/* displayLabel =*/ null)); assertNotNull(pair); Loading Loading
src/com/android/contacts/editor/CompactRawContactsEditorView.java +38 −4 Original line number Diff line number Diff line Loading @@ -781,8 +781,12 @@ public class CompactRawContactsEditorView extends LinearLayout implements View.O } // Get the account information for the primary raw contact delta final Pair<String,String> accountInfo = EditorUiUtils.getAccountInfo(getContext(), mIsUserProfile, mPrimaryRawContactDelta.getAccountName(), 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 Loading @@ -800,13 +804,40 @@ public class CompactRawContactsEditorView extends LinearLayout implements View.O mAccountHeaderContainer.setVisibility(View.GONE); mAccountSelectorContainer.setVisibility(View.GONE); addRawContactAccountSelector(rawContactDeltas); } else { 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); Loading @@ -815,14 +846,17 @@ public class CompactRawContactsEditorView extends LinearLayout implements View.O 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)); Loading
src/com/android/contacts/editor/EditorUiUtils.java +17 −16 Original line number Diff line number Diff line Loading @@ -112,14 +112,10 @@ public class EditorUiUtils { } /** * 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) { public static Pair<String,String> getLocalAccountInfo(Context context, String accountName, AccountType accountType) { if (TextUtils.isEmpty(accountName)) { return new Pair<>( /* accountName =*/ null, Loading @@ -131,6 +127,11 @@ public class EditorUiUtils { 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); Loading Loading @@ -167,7 +168,7 @@ public class EditorUiUtils { builder.append(accountType).append('\n'); } if (!TextUtils.isEmpty(accountName)) { builder.append(accountName).append('\n'); builder.append(accountName); } return builder.toString(); } Loading
src/com/android/contacts/editor/RawContactEditorView.java +3 −2 Original line number Diff line number Diff line Loading @@ -189,8 +189,9 @@ public class RawContactEditorView extends BaseRawContactEditorView { 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); Loading
src/com/android/contacts/editor/RawContactReadOnlyEditorView.java +3 −2 Original line number Diff line number Diff line Loading @@ -115,8 +115,9 @@ public class RawContactReadOnlyEditorView extends BaseRawContactEditorView 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); Loading
tests/src/com/android/contacts/editor/EditorUiUtilsTest.java +7 −7 Original line number Diff line number Diff line Loading @@ -68,7 +68,7 @@ public class EditorUiUtilsTest extends AndroidTestCase { } public void testGetProfileAccountInfo_AccountName() { final Pair pair = EditorUiUtils.getAccountInfo(getContext(), /* isProfile =*/ true, final Pair pair = EditorUiUtils.getLocalAccountInfo(getContext(), ACCOUNT_NAME, new MockAccountType(DISPLAY_LABEL)); assertNotNull(pair); Loading @@ -78,7 +78,7 @@ public class EditorUiUtilsTest extends AndroidTestCase { } public void testGetProfileAccountInfo_NoAccountName() { final Pair pair = EditorUiUtils.getAccountInfo(getContext(), /* isProfile =*/ true, final Pair pair = EditorUiUtils.getLocalAccountInfo(getContext(), /* accountName =*/ null, new MockAccountType(DISPLAY_LABEL)); assertNotNull(pair); Loading @@ -88,7 +88,7 @@ public class EditorUiUtilsTest extends AndroidTestCase { } public void testGetAccountInfo_AccountName_DisplayLabel() { final Pair pair = EditorUiUtils.getAccountInfo(getContext(), /* isProfile =*/ false, final Pair pair = EditorUiUtils.getAccountInfo(getContext(), ACCOUNT_NAME, new MockAccountType(DISPLAY_LABEL)); assertNotNull(pair); Loading @@ -101,7 +101,7 @@ public class EditorUiUtilsTest extends AndroidTestCase { public void testGetAccountInfo_AccountName_DisplayLabel_GoogleAccountType() { final AccountType accountType = new MockAccountType(GOOGLE_DISPLAY_LABEL); accountType.accountType = GoogleAccountType.ACCOUNT_TYPE; final Pair pair = EditorUiUtils.getAccountInfo(getContext(), /* isProfile =*/ false, final Pair pair = EditorUiUtils.getAccountInfo(getContext(), GOOGLE_ACCOUNT_NAME, accountType); assertNotNull(pair); Loading @@ -113,7 +113,7 @@ public class EditorUiUtilsTest extends AndroidTestCase { } public void testGetAccountInfo_AccountName_NoDisplayLabel() { final Pair pair = EditorUiUtils.getAccountInfo(getContext(), /* isProfile =*/ false, final Pair pair = EditorUiUtils.getAccountInfo(getContext(), ACCOUNT_NAME, new MockAccountType(/* displayLabel =*/ null)); assertNotNull(pair); Loading @@ -126,7 +126,7 @@ public class EditorUiUtilsTest extends AndroidTestCase { } public void testGetAccountInfo_NoAccountName_DisplayLabel() { final Pair pair = EditorUiUtils.getAccountInfo(getContext(), /* isProfile =*/ false, final Pair pair = EditorUiUtils.getAccountInfo(getContext(), /* accountName =*/ null, new MockAccountType(DISPLAY_LABEL)); assertNotNull(pair); Loading @@ -136,7 +136,7 @@ public class EditorUiUtilsTest extends AndroidTestCase { } public void testGetAccountInfo_NoAccountName_NoDisplayLabel() { final Pair pair = EditorUiUtils.getAccountInfo(getContext(), /* isProfile =*/ false, final Pair pair = EditorUiUtils.getAccountInfo(getContext(), /* accountName =*/ null, new MockAccountType(/* displayLabel =*/ null)); assertNotNull(pair); Loading