use of com.android.contacts.common.model.account.AccountType in project packages_apps_Contacts by AOKP.
the class ContactMultiDeletionInteraction method onLoadFinished.
@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
if (mDialog != null) {
mDialog.dismiss();
mDialog = null;
}
if (!mIsLoaderActive) {
return;
}
if (cursor == null || cursor.isClosed()) {
Log.e(TAG, "Failed to load contacts");
return;
}
// This cursor may contain duplicate raw contacts, so we need to de-dupe them first
final HashSet<Long> readOnlyRawContacts = Sets.newHashSet();
final HashSet<Long> writableRawContacts = Sets.newHashSet();
final HashSet<Long> contactIds = Sets.newHashSet();
AccountTypeManager accountTypes = AccountTypeManager.getInstance(getActivity());
cursor.moveToPosition(-1);
while (cursor.moveToNext()) {
final long rawContactId = cursor.getLong(COLUMN_INDEX_RAW_CONTACT_ID);
final String accountType = cursor.getString(COLUMN_INDEX_ACCOUNT_TYPE);
final String dataSet = cursor.getString(COLUMN_INDEX_DATA_SET);
final long contactId = cursor.getLong(COLUMN_INDEX_CONTACT_ID);
contactIds.add(contactId);
final AccountType type = accountTypes.getAccountType(accountType, dataSet);
boolean writable = type == null || type.areContactsWritable();
if (writable) {
writableRawContacts.add(rawContactId);
} else {
readOnlyRawContacts.add(rawContactId);
}
}
final int readOnlyCount = readOnlyRawContacts.size();
final int writableCount = writableRawContacts.size();
final int messageId;
int positiveButtonId = android.R.string.ok;
if (readOnlyCount > 0 && writableCount > 0) {
messageId = R.string.batch_delete_multiple_accounts_confirmation;
} else if (readOnlyCount > 0 && writableCount == 0) {
messageId = R.string.batch_delete_read_only_contact_confirmation;
positiveButtonId = R.string.readOnlyContactWarning_positive_button;
} else if (writableCount == 1) {
messageId = R.string.single_delete_confirmation;
positiveButtonId = R.string.deleteConfirmation_positive_button;
} else {
messageId = R.string.batch_delete_confirmation;
positiveButtonId = R.string.deleteConfirmation_positive_button;
}
// Convert set of contact ids into a format that is easily parcellable and iterated upon
// for the sake of ContactSaveService.
final Long[] contactIdObjectArray = contactIds.toArray(new Long[contactIds.size()]);
final long[] contactIdArray = new long[contactIds.size()];
for (int i = 0; i < contactIds.size(); i++) {
contactIdArray[i] = contactIdObjectArray[i];
}
showDialog(messageId, positiveButtonId, contactIdArray);
// We don't want onLoadFinished() calls any more, which may come when the database is
// updating.
getLoaderManager().destroyLoader(R.id.dialog_delete_multiple_contact_loader_id);
}
use of com.android.contacts.common.model.account.AccountType in project android_packages_apps_Dialer by LineageOS.
the class AccountTypeManagerImpl method getAccountTypes.
@Override
public List<AccountType> getAccountTypes(boolean contactWritableOnly) {
ensureAccountsLoaded();
final List<AccountType> accountTypes = new ArrayList<>();
synchronized (this) {
for (AccountType type : mAccountTypesWithDataSets.values()) {
if (!contactWritableOnly || type.areContactsWritable()) {
accountTypes.add(type);
}
}
}
return accountTypes;
}
use of com.android.contacts.common.model.account.AccountType in project android_packages_apps_Dialer by LineageOS.
the class AccountTypeManagerImpl method findAllInvitableAccountTypes.
/**
* Return all {@link AccountType}s with at least one account which supports "invite", i.e. its
* {@link AccountType#getInviteContactActivityClassName()} is not empty.
*/
@VisibleForTesting
static Map<AccountTypeWithDataSet, AccountType> findAllInvitableAccountTypes(Context context, Collection<AccountWithDataSet> accounts, Map<AccountTypeWithDataSet, AccountType> accountTypesByTypeAndDataSet) {
Map<AccountTypeWithDataSet, AccountType> result = new ArrayMap<>();
for (AccountWithDataSet account : accounts) {
AccountTypeWithDataSet accountTypeWithDataSet = account.getAccountTypeWithDataSet();
AccountType type = accountTypesByTypeAndDataSet.get(accountTypeWithDataSet);
if (type == null) {
// just in case
continue;
}
if (result.containsKey(accountTypeWithDataSet)) {
continue;
}
if (Log.isLoggable(TAG, Log.DEBUG)) {
Log.d(TAG, "Type " + accountTypeWithDataSet + " inviteClass=" + type.getInviteContactActivityClassName());
}
if (!TextUtils.isEmpty(type.getInviteContactActivityClassName())) {
result.put(accountTypeWithDataSet, type);
}
}
return Collections.unmodifiableMap(result);
}
use of com.android.contacts.common.model.account.AccountType in project android_packages_apps_Dialer by LineageOS.
the class AccountTypeManagerImpl method findUsableInvitableAccountTypes.
/**
* Return all usable {@link AccountType}s that support the "invite" feature from the list of all
* potential invitable account types (retrieved from {@link #getAllInvitableAccountTypes}). A
* usable invitable account type means: (1) there is at least 1 raw contact in the database with
* that account type, and (2) the app contributing the account type is not disabled.
*
* <p>Warning: Don't use on the UI thread because this can scan the database.
*/
private Map<AccountTypeWithDataSet, AccountType> findUsableInvitableAccountTypes(Context context) {
Map<AccountTypeWithDataSet, AccountType> allInvitables = getAllInvitableAccountTypes();
if (allInvitables.isEmpty()) {
return EMPTY_UNMODIFIABLE_ACCOUNT_TYPE_MAP;
}
final Map<AccountTypeWithDataSet, AccountType> result = new ArrayMap<>();
result.putAll(allInvitables);
final PackageManager packageManager = context.getPackageManager();
for (AccountTypeWithDataSet accountTypeWithDataSet : allInvitables.keySet()) {
AccountType accountType = allInvitables.get(accountTypeWithDataSet);
// Make sure that account types don't come from apps that are disabled.
Intent invitableIntent = MoreContactUtils.getInvitableIntent(accountType, SAMPLE_CONTACT_URI);
if (invitableIntent == null) {
result.remove(accountTypeWithDataSet);
continue;
}
ResolveInfo resolveInfo = packageManager.resolveActivity(invitableIntent, PackageManager.MATCH_DEFAULT_ONLY);
if (resolveInfo == null) {
// If we can't find an activity to start for this intent, then there's no point in
// showing this option to the user.
result.remove(accountTypeWithDataSet);
continue;
}
// is non-trivial and should not be done on the UI thread.
if (!accountTypeWithDataSet.hasData(context)) {
result.remove(accountTypeWithDataSet);
}
}
return Collections.unmodifiableMap(result);
}
Aggregations