Search in sources :

Example 16 with AccountType

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;
}
Also used : ValuesDelta(com.android.contacts.common.model.ValuesDelta) AccountWithDataSet(com.android.contacts.common.model.account.AccountWithDataSet) RawContact(com.android.contacts.common.model.RawContact) AccountTypeManager(com.android.contacts.common.model.AccountTypeManager) AccountType(com.android.contacts.common.model.account.AccountType) RawContactDelta(com.android.contacts.common.model.RawContactDelta)

Example 17 with AccountType

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;
}
Also used : OnClickListener(android.view.View.OnClickListener) MenuItem(android.view.MenuItem) Intent(android.content.Intent) AccountTypeManager(com.android.contacts.common.model.AccountTypeManager) AccountType(com.android.contacts.common.model.account.AccountType) View(android.view.View) Uri(android.net.Uri)

Example 18 with AccountType

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;
}
Also used : DataItem(com.android.contacts.common.model.dataitem.DataItem) GroupMembershipDataItem(com.android.contacts.common.model.dataitem.GroupMembershipDataItem) RawContact(com.android.contacts.common.model.RawContact) GroupMetaData(com.android.contacts.common.GroupMetaData) GroupMembershipDataItem(com.android.contacts.common.model.dataitem.GroupMembershipDataItem) AccountType(com.android.contacts.common.model.account.AccountType)

Example 19 with AccountType

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;
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) PhoneDataItem(com.android.contacts.common.model.dataitem.PhoneDataItem) EventDataItem(com.android.contacts.common.model.dataitem.EventDataItem) OrganizationDataItem(com.android.contacts.common.model.dataitem.OrganizationDataItem) RelationDataItem(com.android.contacts.common.model.dataitem.RelationDataItem) StructuredNameDataItem(com.android.contacts.common.model.dataitem.StructuredNameDataItem) NoteDataItem(com.android.contacts.common.model.dataitem.NoteDataItem) DataItem(com.android.contacts.common.model.dataitem.DataItem) SipAddressDataItem(com.android.contacts.common.model.dataitem.SipAddressDataItem) EmailDataItem(com.android.contacts.common.model.dataitem.EmailDataItem) NicknameDataItem(com.android.contacts.common.model.dataitem.NicknameDataItem) StructuredPostalDataItem(com.android.contacts.common.model.dataitem.StructuredPostalDataItem) WebsiteDataItem(com.android.contacts.common.model.dataitem.WebsiteDataItem) GroupMembershipDataItem(com.android.contacts.common.model.dataitem.GroupMembershipDataItem) ImDataItem(com.android.contacts.common.model.dataitem.ImDataItem) DataKind(com.android.contacts.common.model.dataitem.DataKind) ArrayList(java.util.ArrayList) SpannableString(android.text.SpannableString) AccountType(com.android.contacts.common.model.account.AccountType) Entry(com.android.contacts.quickcontact.ExpandingEntryCardView.Entry) RawContact(com.android.contacts.common.model.RawContact) ColorStateList(android.content.res.ColorStateList) ArrayList(java.util.ArrayList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList)

Example 20 with AccountType

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);
}
Also used : AccountType(com.android.contacts.common.model.account.AccountType) GoogleAccountType(com.android.contacts.common.model.account.GoogleAccountType) Pair(android.util.Pair)

Aggregations

AccountType (com.android.contacts.common.model.account.AccountType)34 AccountTypeManager (com.android.contacts.common.model.AccountTypeManager)13 Intent (android.content.Intent)7 RawContactDelta (com.android.contacts.common.model.RawContactDelta)7 AccountWithDataSet (com.android.contacts.common.model.account.AccountWithDataSet)7 Uri (android.net.Uri)6 ValuesDelta (com.android.contacts.common.model.ValuesDelta)6 GoogleAccountType (com.android.contacts.common.model.account.GoogleAccountType)6 View (android.view.View)4 TextView (android.widget.TextView)4 RawContact (com.android.contacts.common.model.RawContact)4 AccountTypeWithDataSet (com.android.contacts.common.model.account.AccountTypeWithDataSet)4 ExchangeAccountType (com.android.contacts.common.model.account.ExchangeAccountType)4 ExternalAccountType (com.android.contacts.common.model.account.ExternalAccountType)4 FallbackAccountType (com.android.contacts.common.model.account.FallbackAccountType)4 SamsungAccountType (com.android.contacts.common.model.account.SamsungAccountType)4 ArrayMap (android.util.ArrayMap)3 OnClickListener (android.view.View.OnClickListener)3 ImageView (android.widget.ImageView)3 DataKind (com.android.contacts.common.model.dataitem.DataKind)3