use of com.android.contacts.common.model.account.AccountType in project packages_apps_Contacts by AOKP.
the class ConfirmAddDetailActivity method addEditableRawContact.
/**
* Create an {@link RawContactDelta} for a raw_contact on the first editable account found, and add
* to the list. Also copy the structured name from an existing (read-only) raw_contact to the
* new one, if any of the read-only contacts has a name.
*/
private static RawContactDelta addEditableRawContact(Context context, RawContactDeltaList entityDeltaList) {
// First, see if there's an editable account.
final AccountTypeManager accounts = AccountTypeManager.getInstance(context);
final List<AccountWithDataSet> editableAccounts = accounts.getAccounts(true);
if (editableAccounts.size() == 0) {
// No editable account type found. The dialog will be read-only mode.
return null;
}
final AccountWithDataSet editableAccount = editableAccounts.get(0);
final AccountType accountType = accounts.getAccountType(editableAccount.type, editableAccount.dataSet);
// Create a new RawContactDelta for the new raw_contact.
final RawContact rawContact = new RawContact();
rawContact.setAccount(editableAccount);
final RawContactDelta entityDelta = new RawContactDelta(ValuesDelta.fromAfter(rawContact.getValues()));
// Then, copy the structure name from an existing (read-only) raw_contact.
for (RawContactDelta entity : entityDeltaList) {
final ArrayList<ValuesDelta> readOnlyNames = entity.getMimeEntries(StructuredName.CONTENT_ITEM_TYPE);
if ((readOnlyNames != null) && (readOnlyNames.size() > 0)) {
final ValuesDelta readOnlyName = readOnlyNames.get(0);
final ValuesDelta newName = RawContactModifier.ensureKindExists(entityDelta, accountType, StructuredName.CONTENT_ITEM_TYPE);
// Copy all the data fields.
newName.copyStructuredNameFieldsFrom(readOnlyName);
break;
}
}
// Add the new RawContactDelta to the list.
entityDeltaList.add(entityDelta);
return entityDelta;
}
use of com.android.contacts.common.model.account.AccountType in project packages_apps_Contacts by AOKP.
the class GroupDetailActivity method onPrepareOptionsMenu.
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
if (!mShowGroupSourceInActionBar) {
return false;
}
MenuItem groupSourceMenuItem = menu.findItem(R.id.menu_group_source);
if (groupSourceMenuItem == null) {
return false;
}
final AccountTypeManager manager = AccountTypeManager.getInstance(this);
final AccountType accountType = manager.getAccountType(mAccountTypeString, mDataSet);
if (TextUtils.isEmpty(mAccountTypeString) || TextUtils.isEmpty(accountType.getViewGroupActivity())) {
groupSourceMenuItem.setVisible(false);
return false;
}
View groupSourceView = GroupDetailDisplayUtils.getNewGroupSourceView(this);
GroupDetailDisplayUtils.bindGroupSourceView(this, groupSourceView, mAccountTypeString, mDataSet);
groupSourceView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
final Uri uri = ContentUris.withAppendedId(Groups.CONTENT_URI, mFragment.getGroupId());
final Intent intent = new Intent(Intent.ACTION_VIEW, uri);
intent.setClassName(accountType.syncAdapterPackageName, accountType.getViewGroupActivity());
ImplicitIntentsUtil.startActivityInApp(GroupDetailActivity.this, intent);
}
});
groupSourceMenuItem.setActionView(groupSourceView);
groupSourceMenuItem.setVisible(true);
return true;
}
use of com.android.contacts.common.model.account.AccountType in project packages_apps_Contacts by AOKP.
the class InvisibleContactUtil method isInvisibleAndAddable.
public static boolean isInvisibleAndAddable(Contact contactData, Context context) {
// Only local contacts
if (contactData == null || contactData.isDirectoryEntry())
return false;
// User profile cannot be added to contacts
if (contactData.isUserProfile())
return false;
// Only if exactly one raw contact
if (contactData.getRawContacts().size() != 1)
return false;
// test if the default group is assigned
final List<GroupMetaData> groups = contactData.getGroupMetaData();
// For accounts without group support, groups is null
if (groups == null)
return false;
// remember the default group id. no default group? bail out early
final long defaultGroupId = getDefaultGroupId(groups);
if (defaultGroupId == -1)
return false;
final RawContact rawContact = (RawContact) contactData.getRawContacts().get(0);
final AccountType type = rawContact.getAccountType(context);
// Offline or non-writeable account? Nothing to fix
if (type == null || !type.areContactsWritable())
return false;
// Check whether the contact is in the default group
boolean isInDefaultGroup = false;
for (DataItem dataItem : Iterables.filter(rawContact.getDataItems(), GroupMembershipDataItem.class)) {
GroupMembershipDataItem groupMembership = (GroupMembershipDataItem) dataItem;
final Long groupId = groupMembership.getGroupRowId();
if (groupId != null && groupId == defaultGroupId) {
isInDefaultGroup = true;
break;
}
}
return !isInDefaultGroup;
}
use of com.android.contacts.common.model.account.AccountType in project packages_apps_Contacts by AOKP.
the class QuickContactActivity method generateDataModelFromContact.
/**
* Builds the {@link DataItem}s Map out of the Contact.
* @param data The contact to build the data from.
* @return A pair containing a list of data items sorted within mimetype and sorted
* amongst mimetype. The map goes from mimetype string to the sorted list of data items within
* mimetype
*/
private Cp2DataCardModel generateDataModelFromContact(Contact data) {
Trace.beginSection("Build data items map");
final Map<String, List<DataItem>> dataItemsMap = new HashMap<>();
final ResolveCache cache = ResolveCache.getInstance(this);
for (RawContact rawContact : data.getRawContacts()) {
for (DataItem dataItem : rawContact.getDataItems()) {
dataItem.setRawContactId(rawContact.getId());
final String mimeType = dataItem.getMimeType();
if (mimeType == null)
continue;
final AccountType accountType = rawContact.getAccountType(this);
final DataKind dataKind = AccountTypeManager.getInstance(this).getKindOrFallback(accountType, mimeType);
if (dataKind == null)
continue;
dataItem.setDataKind(dataKind);
final boolean hasData = !TextUtils.isEmpty(dataItem.buildDataString(this, dataKind));
if (isMimeExcluded(mimeType) || !hasData)
continue;
List<DataItem> dataItemListByType = dataItemsMap.get(mimeType);
if (dataItemListByType == null) {
dataItemListByType = new ArrayList<>();
dataItemsMap.put(mimeType, dataItemListByType);
}
dataItemListByType.add(dataItem);
}
}
Trace.endSection();
Trace.beginSection("sort within mimetypes");
/*
* Sorting is a multi part step. The end result is to a have a sorted list of the most
* used data items, one per mimetype. Then, within each mimetype, the list of data items
* for that type is also sorted, based off of {super primary, primary, times used} in that
* order.
*/
final List<List<DataItem>> dataItemsList = new ArrayList<>();
for (List<DataItem> mimeTypeDataItems : dataItemsMap.values()) {
// Remove duplicate data items
Collapser.collapseList(mimeTypeDataItems, this);
// Sort within mimetype
Collections.sort(mimeTypeDataItems, mWithinMimeTypeDataItemComparator);
// Add to the list of data item lists
dataItemsList.add(mimeTypeDataItems);
}
Trace.endSection();
Trace.beginSection("sort amongst mimetypes");
// Sort amongst mimetypes to bubble up the top data items for the contact card
Collections.sort(dataItemsList, mAmongstMimeTypeDataItemComparator);
Trace.endSection();
Trace.beginSection("cp2 data items to entries");
final List<List<Entry>> contactCardEntries = new ArrayList<>();
final List<List<Entry>> aboutCardEntries = buildAboutCardEntries(dataItemsMap);
final MutableString aboutCardName = new MutableString();
for (int i = 0; i < dataItemsList.size(); ++i) {
final List<DataItem> dataItemsByMimeType = dataItemsList.get(i);
final DataItem topDataItem = dataItemsByMimeType.get(0);
if (SORTED_ABOUT_CARD_MIMETYPES.contains(topDataItem.getMimeType())) {
// About card mimetypes are built in buildAboutCardEntries, skip here
continue;
} else {
List<Entry> contactEntries = dataItemsToEntries(dataItemsList.get(i), aboutCardName);
if (contactEntries.size() > 0) {
contactCardEntries.add(contactEntries);
}
}
}
Trace.endSection();
final Cp2DataCardModel dataModel = new Cp2DataCardModel();
dataModel.customAboutCardName = aboutCardName.value;
dataModel.aboutCardEntries = aboutCardEntries;
dataModel.contactCardEntries = contactCardEntries;
dataModel.dataItemsMap = dataItemsMap;
return dataModel;
}
use of com.android.contacts.common.model.account.AccountType in project packages_apps_Contacts by AOKP.
the class EditorUiUtilsTest method testGetAccountInfo_AccountName_DisplayLabel_GoogleAccountType.
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(), GOOGLE_ACCOUNT_NAME, accountType);
assertNotNull(pair);
assertEquals(getContext().getString(R.string.from_account_format, GOOGLE_ACCOUNT_NAME), // somebody@gmail.com
pair.first);
assertEquals(getContext().getString(R.string.google_account_type_format, GOOGLE_DISPLAY_LABEL), // Google Account
pair.second);
}
Aggregations