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();
}
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;
}
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;
}
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);
}
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;
}
}
Aggregations