Search in sources :

Example 11 with ValuesDelta

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();
}
Also used : ValuesDelta(com.android.contacts.common.model.ValuesDelta) Intent(android.content.Intent) RadioButton(android.widget.RadioButton)

Example 12 with ValuesDelta

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();
}
Also used : Bitmap(android.graphics.Bitmap) ValuesDelta(com.android.contacts.common.model.ValuesDelta) FileNotFoundException(java.io.FileNotFoundException) Intent(android.content.Intent) AccountType(com.android.contacts.common.model.account.AccountType)

Example 13 with ValuesDelta

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);
}
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 14 with ValuesDelta

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;
                    }
                }
            }
        }
    }
}
Also used : ValuesDelta(com.android.contacts.common.model.ValuesDelta) DataKind(com.android.contacts.common.model.dataitem.DataKind)

Example 15 with ValuesDelta

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

Aggregations

ValuesDelta (com.android.contacts.common.model.ValuesDelta)25 RawContactDelta (com.android.contacts.common.model.RawContactDelta)6 AccountType (com.android.contacts.common.model.account.AccountType)6 DataKind (com.android.contacts.common.model.dataitem.DataKind)5 Intent (android.content.Intent)3 View (android.view.View)3 AccountTypeManager (com.android.contacts.common.model.AccountTypeManager)3 Bitmap (android.graphics.Bitmap)2 Uri (android.net.Uri)2 Pair (android.util.Pair)2 ImageView (android.widget.ImageView)2 RadioButton (android.widget.RadioButton)2 AccountWithDataSet (com.android.contacts.common.model.account.AccountWithDataSet)2 FileNotFoundException (java.io.FileNotFoundException)2 Activity (android.app.Activity)1 ContentValues (android.content.ContentValues)1 Resources (android.content.res.Resources)1 Drawable (android.graphics.drawable.Drawable)1 Bundle (android.os.Bundle)1 Photo (android.provider.ContactsContract.CommonDataKinds.Photo)1