use of com.android.contacts.common.model.ValuesDelta in project packages_apps_Contacts by AOKP.
the class ConfirmReplaceDetailActivity method doReplaceAction.
private void doReplaceAction() {
String oldNumber = null;
if (mList.size() == 1) {
oldNumber = mList.get(0);
} else {
int radioButtonId = radioGroup.getCheckedRadioButtonId();
oldNumber = ((RadioButton) findViewById(radioButtonId)).getText().toString();
}
int position = mList.indexOf(oldNumber);
ValuesDelta valuesDelta = mRawContactDelta.getMimeEntries(mMimeType).get(position);
String newNumber = null;
if (mMimeType.equals(Phone.CONTENT_ITEM_TYPE)) {
newNumber = extras.getString(Insert.PHONE);
valuesDelta.getAfter().put(Phone.NUMBER, newNumber);
} else {
newNumber = extras.getString(Insert.EMAIL);
valuesDelta.getAfter().put(Email.ADDRESS, newNumber);
}
Intent intent = new Intent();
intent.putExtra(ConfirmAddDetailActivity.RAWCONTACTS_DELTA_LIST, (Parcelable) mEntityDeltaList);
setResult(RESULT_OK, intent);
finish();
}
use of com.android.contacts.common.model.ValuesDelta in project packages_apps_Contacts by AOKP.
the class AttachPhotoActivity method saveToContact.
private void saveToContact(Contact contact, RawContactDeltaList deltaList, RawContactDelta raw) {
// Create a scaled, compressed bitmap to add to the entity-delta list.
final int size = ContactsUtils.getThumbnailSize(this);
Bitmap bitmap;
try {
bitmap = ContactPhotoUtils.getBitmapFromUri(this, mCroppedPhotoUri);
} catch (FileNotFoundException e) {
Log.w(TAG, "Could not find bitmap");
finish();
return;
}
if (bitmap == null) {
Log.w(TAG, "Could not decode bitmap");
finish();
return;
}
final Bitmap scaled = Bitmap.createScaledBitmap(bitmap, size, size, false);
final byte[] compressed = ContactPhotoUtils.compressBitmap(scaled);
if (compressed == null) {
Log.w(TAG, "could not create scaled and compressed Bitmap");
finish();
return;
}
// Add compressed bitmap to entity-delta... this allows us to save to
// a new contact; otherwise the entity-delta-list would be empty, and
// the ContactSaveService would not create the new contact, and the
// full-res photo would fail to be saved to the non-existent contact.
AccountType account = raw.getRawContactAccountType(this);
ValuesDelta values = RawContactModifier.ensureKindExists(raw, account, Photo.CONTENT_ITEM_TYPE);
if (values == null) {
Log.w(TAG, "cannot attach photo to this account type");
finish();
return;
}
values.setPhoto(compressed);
// Finally, invoke the ContactSaveService.
Log.v(TAG, "all prerequisites met, about to save photo to contact");
Intent intent = ContactSaveService.createSaveContactIntent(this, deltaList, "", 0, contact.isUserProfile(), null, null, raw.getRawContactId() != null ? raw.getRawContactId() : -1, mCroppedPhotoUri);
ContactSaveService.startService(this, intent);
finish();
}
use of com.android.contacts.common.model.ValuesDelta 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.ValuesDelta in project packages_apps_Contacts by AOKP.
the class ConfirmAddDetailActivity method bindEditor.
/**
* Rebuild the editor to match our underlying {@link #mEntityDeltaList} object.
*/
private void bindEditor() {
if (mEntityDeltaList == null) {
throw new IllegalStateException();
}
// account type to use. In this case, display an error message and hide the "OK" button.
if (mIsReadOnly) {
mReadOnlyWarningView.setText(getString(R.string.contact_read_only));
mReadOnlyWarningView.setVisibility(View.VISIBLE);
mEditorContainerView.setVisibility(View.GONE);
findViewById(R.id.btn_done).setVisibility(View.GONE);
// Nothing more to be done, just show the UI
return;
}
// Otherwise display an editor that allows the user to add the data to this raw contact.
for (DataKind kind : mEditableAccountType.getSortedDataKinds()) {
// Skip kind that are not editable
if (!kind.editable)
continue;
if (mMimetype.equals(kind.mimeType)) {
final ArrayList<ValuesDelta> deltas = mRawContactDelta.getMimeEntries(mMimetype);
if (deltas != null) {
for (ValuesDelta valuesDelta : deltas) {
// Skip entries that aren't visible
if (!valuesDelta.isVisible())
continue;
if (valuesDelta.isInsert()) {
inflateEditorView(kind, valuesDelta, mRawContactDelta);
return;
}
}
}
}
}
}
use of com.android.contacts.common.model.ValuesDelta 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;
}
Aggregations