diff options
6 files changed, 21 insertions, 136 deletions
diff --git a/src/com/android/contacts/editor/ContactEditorUtils.java b/src/com/android/contacts/editor/ContactEditorUtils.java index 24d5ce009..4bb075cc6 100644 --- a/src/com/android/contacts/editor/ContactEditorUtils.java +++ b/src/com/android/contacts/editor/ContactEditorUtils.java @@ -23,6 +23,7 @@ import android.content.ContentUris; import android.content.Context; import android.content.Intent; import android.net.Uri; +import android.os.Bundle; import android.provider.ContactsContract; import android.text.TextUtils; @@ -147,46 +148,20 @@ public class ContactEditorUtils { } } - @VisibleForTesting - String[] getWritableAccountTypeStrings() { - final Set<String> types = Sets.newHashSet(); - for (AccountType type : mAccountTypes.getAccountTypes(true)) { - types.add(type.accountType); - } - return types.toArray(new String[types.size()]); - } - /** - * Create an {@link Intent} to start "add new account" setup wizard. Selectable account - * types will be limited to ones that supports editing contacts. + * Parses a result from {@link AccountManager#newChooseAccountIntent(Account, List, String[], + * String, String, String[], Bundle)} and returns the created {@link Account}, or null if + * the user has canceled the wizard. * - * Use {@link Activity#startActivityForResult} or - * {@link android.app.Fragment#startActivityForResult} to start the wizard, and - * {@link Activity#onActivityResult} or {@link android.app.Fragment#onActivityResult} to - * get the result. - */ - public Intent createAddWritableAccountIntent() { - return AccountManager.newChooseAccountIntent( - null, // selectedAccount - new ArrayList<Account>(), // allowableAccounts - getWritableAccountTypeStrings(), // allowableAccountTypes - false, // alwaysPromptForAccount - null, // descriptionOverrideText - null, // addAccountAuthTokenType - null, // addAccountRequiredFeatures - null // addAccountOptions - ); - } - - /** - * Parses a result from {@link #createAddWritableAccountIntent} and returns the created - * {@link Account}, or null if the user has canceled the wizard. Pass the {@code resultCode} - * and {@code data} parameters passed to {@link Activity#onActivityResult} or - * {@link android.app.Fragment#onActivityResult}. + * <p>Pass the {@code resultCode} and {@code data} parameters passed to + * {@link Activity#onActivityResult} or {@link android.app.Fragment#onActivityResult}. + * </p> * + * <p> * Note although the return type is {@link AccountWithDataSet}, return values from this method * will never have {@link AccountWithDataSet#dataSet} set, as there's no way to create an * extension package account from setup wizard. + * </p> */ public AccountWithDataSet getCreatedAccount(int resultCode, Intent resultData) { // Javadoc doesn't say anything about resultCode but that the data intent will be non null diff --git a/src/com/android/contacts/model/AccountTypeManager.java b/src/com/android/contacts/model/AccountTypeManager.java index b0b3173a9..6360c7ee9 100644 --- a/src/com/android/contacts/model/AccountTypeManager.java +++ b/src/com/android/contacts/model/AccountTypeManager.java @@ -150,12 +150,6 @@ public abstract class AccountTypeManager { } @Override - public List<AccountWithDataSet> getSortedAccounts(AccountWithDataSet defaultAccount, - boolean contactWritableOnly) { - return Collections.emptyList(); - } - - @Override public AccountType getAccountType(AccountTypeWithDataSet accountTypeWithDataSet) { return null; } @@ -165,10 +159,6 @@ public abstract class AccountTypeManager { return null; } - @Override - public List<AccountType> getAccountTypes(boolean contactWritableOnly) { - return Collections.emptyList(); - } }; /** @@ -180,9 +170,6 @@ public abstract class AccountTypeManager { public abstract List<AccountWithDataSet> getAccounts(Predicate<AccountWithDataSet> filter); - public abstract List<AccountWithDataSet> getSortedAccounts(AccountWithDataSet defaultAccount, - boolean contactWritableOnly); - /** * Returns the list of accounts that are group writable. */ @@ -259,13 +246,6 @@ public abstract class AccountTypeManager { } /** - * Returns all registered {@link AccountType}s, including extension ones. - * - * @param contactWritableOnly if true, it only returns ones that support writing contacts. - */ - public abstract List<AccountType> getAccountTypes(boolean contactWritableOnly); - - /** * @param contactWritableOnly if true, it only returns ones that support writing contacts. * @return true when this instance contains the given account. */ @@ -282,6 +262,15 @@ public abstract class AccountTypeManager { return getDefaultGoogleAccount() != null; } + /** + * Sorts the accounts in-place such that defaultAccount is first in the list and the rest + * of the accounts are ordered in manner that is useful for display purposes + */ + public static void sortAccounts(AccountWithDataSet defaultAccount, + List<AccountWithDataSet> accounts) { + Collections.sort(accounts, new AccountComparator(defaultAccount)); + } + private static boolean hasRequiredPermissions(Context context) { final boolean canGetAccounts = ContextCompat.checkSelfPermission(context, android.Manifest.permission.GET_ACCOUNTS) == PackageManager.PERMISSION_GRANTED; @@ -789,21 +778,6 @@ class AccountTypeManagerImpl extends AccountTypeManager } /** - * Return list of all known or contact writable {@link AccountWithDataSet}'s sorted by - * {@code defaultAccount}. - * {@param defaultAccount} account to sort by - * {@param contactWritableOnly} whether to restrict to contact writable accounts only - */ - @Override - public List<AccountWithDataSet> getSortedAccounts(AccountWithDataSet defaultAccount, - boolean contactWritableOnly) { - final AccountComparator comparator = new AccountComparator(defaultAccount); - final List<AccountWithDataSet> accounts = getAccounts(contactWritableOnly); - Collections.sort(accounts, comparator); - return accounts; - } - - /** * Return the list of all known, group writable {@link AccountWithDataSet}'s. */ public List<AccountWithDataSet> getGroupWritableAccounts() { @@ -983,20 +957,6 @@ class AccountTypeManagerImpl extends AccountTypeManager return Collections.unmodifiableMap(result); } - @Override - public List<AccountType> getAccountTypes(boolean contactWritableOnly) { - ensureAccountsLoaded(); - final List<AccountType> accountTypes = Lists.newArrayList(); - synchronized (this) { - for (AccountType type : mAccountTypesWithDataSets.values()) { - if (!contactWritableOnly || type.areContactsWritable()) { - accountTypes.add(type); - } - } - } - return accountTypes; - } - /** * Background task to find all usable {@link AccountType}s that support the "invite" feature * from the list of all potential invitable account types. Once the work is completed, diff --git a/src/com/android/contacts/model/account/AccountWithDataSet.java b/src/com/android/contacts/model/account/AccountWithDataSet.java index b0bb84d35..0f36918b6 100644 --- a/src/com/android/contacts/model/account/AccountWithDataSet.java +++ b/src/com/android/contacts/model/account/AccountWithDataSet.java @@ -30,7 +30,6 @@ import android.text.TextUtils; import com.android.contacts.model.AccountTypeManager; import com.android.contacts.preference.ContactsPreferences; - import com.google.common.base.Objects; import com.google.common.collect.Lists; @@ -281,3 +280,4 @@ public class AccountWithDataSet implements Parcelable { return accounts.get(0); } } + diff --git a/src/com/android/contacts/util/AccountFilterUtil.java b/src/com/android/contacts/util/AccountFilterUtil.java index 0c36f5e80..3a6d49e4e 100644 --- a/src/com/android/contacts/util/AccountFilterUtil.java +++ b/src/com/android/contacts/util/AccountFilterUtil.java @@ -133,8 +133,8 @@ public class AccountFilterUtil { DeviceLocalAccountTypeFactory deviceAccountTypeFactory) { final ArrayList<ContactListFilter> accountFilters = Lists.newArrayList(); final AccountTypeManager accountTypeManager = AccountTypeManager.getInstance(context); - final List<AccountWithDataSet> accounts = accountTypeManager.getSortedAccounts( - /* defaultAccount */ getDefaultAccount(context), /* contactWritableOnly */ true); + final List<AccountWithDataSet> accounts = accountTypeManager.getAccounts(true); + AccountTypeManager.sortAccounts(getDefaultAccount(context), accounts); for (AccountWithDataSet account : accounts) { final AccountType accountType = diff --git a/tests/src/com/android/contacts/editor/ContactEditorUtilsTest.java b/tests/src/com/android/contacts/editor/ContactEditorUtilsTest.java index f6c2d1b1c..9756a0c50 100644 --- a/tests/src/com/android/contacts/editor/ContactEditorUtilsTest.java +++ b/tests/src/com/android/contacts/editor/ContactEditorUtilsTest.java @@ -79,37 +79,6 @@ public class ContactEditorUtilsTest extends AndroidTestCase { mAccountTypes.mAccounts = accounts; } - public void testGetWritableAccountTypeStrings() { - String[] types; - - // 0 writable types - setAccountTypes(); - - types = mTarget.getWritableAccountTypeStrings(); - MoreAsserts.assertEquals(types, new String[0]); - - // 1 writable type - setAccountTypes(TYPE1); - - types = mTarget.getWritableAccountTypeStrings(); - MoreAsserts.assertEquals(Sets.newHashSet(TYPE1.accountType), Sets.newHashSet(types)); - - // 2 writable types - setAccountTypes(TYPE1, TYPE2EX); - - types = mTarget.getWritableAccountTypeStrings(); - MoreAsserts.assertEquals(Sets.newHashSet(TYPE1.accountType, TYPE2EX.accountType), - Sets.newHashSet(types)); - - // 3 writable types + 1 readonly type - setAccountTypes(TYPE1, TYPE2, TYPE2EX, TYPE3); - - types = mTarget.getWritableAccountTypeStrings(); - MoreAsserts.assertEquals( - Sets.newHashSet(TYPE1.accountType, TYPE2.accountType, TYPE2EX.accountType), - Sets.newHashSet(types)); - } - /** * Test for * - {@link ContactEditorUtils#saveDefaultAccount} diff --git a/tests/src/com/android/contacts/test/mocks/MockAccountTypeManager.java b/tests/src/com/android/contacts/test/mocks/MockAccountTypeManager.java index 00686aa15..16804c93d 100644 --- a/tests/src/com/android/contacts/test/mocks/MockAccountTypeManager.java +++ b/tests/src/com/android/contacts/test/mocks/MockAccountTypeManager.java @@ -76,12 +76,6 @@ public class MockAccountTypeManager extends AccountTypeManager { } @Override - public List<AccountWithDataSet> getSortedAccounts(AccountWithDataSet account, - boolean writableOnly) { - return Arrays.asList(mAccounts); - } - - @Override public List<AccountWithDataSet> getGroupWritableAccounts() { return Arrays.asList(mAccounts); } @@ -95,17 +89,4 @@ public class MockAccountTypeManager extends AccountTypeManager { public Map<AccountTypeWithDataSet, AccountType> getUsableInvitableAccountTypes() { return Maps.newHashMap(); // Always returns empty } - - @Override - public List<AccountType> getAccountTypes(boolean writableOnly) { - final List<AccountType> ret = Lists.newArrayList(); - synchronized (this) { - for (AccountType type : mTypes) { - if (!writableOnly || type.areContactsWritable()) { - ret.add(type); - } - } - } - return ret; - } } |