Search in sources :

Example 6 with RawContactDelta

use of com.android.contacts.common.model.RawContactDelta in project packages_apps_Contacts by AOKP.

the class ContactEditorBaseFragment method setStateForExistingContact.

/**
 * Prepare {@link #mState} for an existing contact.
 */
protected void setStateForExistingContact(String readOnlyDisplayName, boolean isUserProfile, ImmutableList<RawContact> rawContacts) {
    setEnabled(true);
    mReadOnlyDisplayName = readOnlyDisplayName;
    mState.addAll(rawContacts.iterator());
    setIntentExtras(mIntentExtras);
    mIntentExtras = null;
    // For user profile, change the contacts query URI
    mIsUserProfile = isUserProfile;
    boolean localProfileExists = false;
    if (mIsUserProfile) {
        for (RawContactDelta rawContactDelta : mState) {
            // For profile contacts, we need a different query URI
            rawContactDelta.setProfileQueryUri();
            // Try to find a local profile contact
            if (rawContactDelta.getValues().getAsString(RawContacts.ACCOUNT_TYPE) == null || rawContactDelta.getValues().getAsString(RawContacts.ACCOUNT_TYPE).equals(SimContactsConstants.ACCOUNT_TYPE_PHONE)) {
                localProfileExists = true;
            }
        }
        // Editor should always present a local profile for editing
        if (!localProfileExists) {
            mState.add(createLocalRawContactDelta());
        }
    }
    mExistingContactDataReady = true;
    bindEditors();
}
Also used : RawContactDelta(com.android.contacts.common.model.RawContactDelta)

Example 7 with RawContactDelta

use of com.android.contacts.common.model.RawContactDelta in project packages_apps_Contacts by AOKP.

the class ContactEditorFragment method hasMoreThanOnePhoto.

/**
 * Returns true if there is currently more than one photo on screen.
 */
private boolean hasMoreThanOnePhoto() {
    int countWithPicture = 0;
    final int numEntities = mState.size();
    for (int i = 0; i < numEntities; i++) {
        final RawContactDelta entity = mState.get(i);
        if (entity.isVisible()) {
            final ValuesDelta primary = entity.getPrimaryEntry(Photo.CONTENT_ITEM_TYPE);
            if (primary != null && primary.getPhoto() != null) {
                countWithPicture++;
            } else {
                final long rawContactId = entity.getRawContactId();
                final Uri uri = mUpdatedPhotos.getParcelable(String.valueOf(rawContactId));
                if (uri != null) {
                    try {
                        mContext.getContentResolver().openInputStream(uri);
                        countWithPicture++;
                    } catch (FileNotFoundException e) {
                    }
                }
            }
            if (countWithPicture > 1) {
                return true;
            }
        }
    }
    return false;
}
Also used : ValuesDelta(com.android.contacts.common.model.ValuesDelta) FileNotFoundException(java.io.FileNotFoundException) RawContactDelta(com.android.contacts.common.model.RawContactDelta) Uri(android.net.Uri)

Example 8 with RawContactDelta

use of com.android.contacts.common.model.RawContactDelta in project packages_apps_Contacts by AOKP.

the class PhotoSelectionHandler method getDeltaForAttachingPhotoToContact.

/**
 * Utility method to retrieve the entity delta for attaching the given bitmap to the contact.
 * This will attach the photo to the first contact-writable account that provided data to the
 * contact.  It is the caller's responsibility to apply the delta.
 * @return An entity delta list that can be applied to associate the bitmap with the contact,
 *     or null if the photo could not be parsed or none of the accounts associated with the
 *     contact are writable.
 */
public RawContactDeltaList getDeltaForAttachingPhotoToContact() {
    // Find the first writable entity.
    int writableEntityIndex = getWritableEntityIndex();
    if (writableEntityIndex != -1) {
        // We are guaranteed to have contact data if we have a writable entity index.
        final RawContactDelta delta = mState.get(writableEntityIndex);
        // Need to find the right account so that EntityModifier knows which fields to add
        final ContentValues entityValues = delta.getValues().getCompleteValues();
        final String type = entityValues.getAsString(RawContacts.ACCOUNT_TYPE);
        final String dataSet = entityValues.getAsString(RawContacts.DATA_SET);
        final AccountType accountType = AccountTypeManager.getInstance(mContext).getAccountType(type, dataSet);
        final ValuesDelta child = RawContactModifier.ensureKindExists(delta, accountType, Photo.CONTENT_ITEM_TYPE);
        child.setFromTemplate(false);
        child.setSuperPrimary(true);
        return mState;
    }
    return null;
}
Also used : ContentValues(android.content.ContentValues) ValuesDelta(com.android.contacts.common.model.ValuesDelta) RawContactDelta(com.android.contacts.common.model.RawContactDelta) AccountType(com.android.contacts.common.model.account.AccountType)

Example 9 with RawContactDelta

use of com.android.contacts.common.model.RawContactDelta in project packages_apps_Contacts by AOKP.

the class InvisibleContactUtil method addToDefaultGroup.

public static void addToDefaultGroup(Contact contactData, Context context) {
    final long defaultGroupId = getDefaultGroupId(contactData.getGroupMetaData());
    // but let's be safe here
    if (defaultGroupId == -1)
        return;
    // add the group membership to the current state
    final RawContactDeltaList contactDeltaList = contactData.createRawContactDeltaList();
    final RawContactDelta rawContactEntityDelta = contactDeltaList.get(0);
    final AccountTypeManager accountTypes = AccountTypeManager.getInstance(context);
    final AccountType type = rawContactEntityDelta.getAccountType(accountTypes);
    final DataKind groupMembershipKind = type.getKindForMimetype(GroupMembership.CONTENT_ITEM_TYPE);
    final ValuesDelta entry = RawContactModifier.insertChild(rawContactEntityDelta, groupMembershipKind);
    if (entry == null)
        return;
    entry.setGroupRowId(defaultGroupId);
    // and fire off the intent. we don't need a callback, as the database listener
    // should update the ui
    final Intent intent = ContactSaveService.createSaveContactIntent(context, contactDeltaList, "", 0, false, QuickContactActivity.class, Intent.ACTION_VIEW, null, /* joinContactIdExtraKey =*/
    null, /* joinContactId =*/
    null);
    ContactSaveService.startService(context, intent);
}
Also used : ValuesDelta(com.android.contacts.common.model.ValuesDelta) DataKind(com.android.contacts.common.model.dataitem.DataKind) RawContactDeltaList(com.android.contacts.common.model.RawContactDeltaList) Intent(android.content.Intent) AccountTypeManager(com.android.contacts.common.model.AccountTypeManager) RawContactDelta(com.android.contacts.common.model.RawContactDelta) AccountType(com.android.contacts.common.model.account.AccountType)

Example 10 with RawContactDelta

use of com.android.contacts.common.model.RawContactDelta in project packages_apps_Contacts by AOKP.

the class QuickContactActivity method hasPhoneOrEmailDate.

private boolean hasPhoneOrEmailDate(Contact contact) {
    int phoneCount = 0;
    int emailCount = 0;
    ImmutableList<RawContact> rawContacts = contact.getRawContacts();
    for (RawContact rawContact : rawContacts) {
        RawContactDelta rawContactDelta = RawContactDelta.fromBefore(rawContact);
        phoneCount += rawContactDelta.getMimeEntriesCount(Phone.CONTENT_ITEM_TYPE, true);
        emailCount += rawContactDelta.getMimeEntriesCount(Email.CONTENT_ITEM_TYPE, true);
    }
    if (phoneCount > 0 || emailCount > 0) {
        return true;
    } else {
        return false;
    }
}
Also used : RawContact(com.android.contacts.common.model.RawContact) RawContactDelta(com.android.contacts.common.model.RawContactDelta)

Aggregations

RawContactDelta (com.android.contacts.common.model.RawContactDelta)20 AccountType (com.android.contacts.common.model.account.AccountType)7 ValuesDelta (com.android.contacts.common.model.ValuesDelta)6 AccountTypeManager (com.android.contacts.common.model.AccountTypeManager)5 Uri (android.net.Uri)4 RawContact (com.android.contacts.common.model.RawContact)4 RawContactDeltaList (com.android.contacts.common.model.RawContactDeltaList)4 AccountWithDataSet (com.android.contacts.common.model.account.AccountWithDataSet)3 DataKind (com.android.contacts.common.model.dataitem.DataKind)3 Intent (android.content.Intent)2 View (android.view.View)2 ImageView (android.widget.ImageView)2 TextView (android.widget.TextView)2 Activity (android.app.Activity)1 ContentProviderOperation (android.content.ContentProviderOperation)1 ContentProviderResult (android.content.ContentProviderResult)1 ContentResolver (android.content.ContentResolver)1 ContentValues (android.content.ContentValues)1 OperationApplicationException (android.content.OperationApplicationException)1 Cursor (android.database.Cursor)1