public void buildCapsuleInsert(Capsule capsule, boolean withYield) { // Build the INSERT operation ContentProviderOperation.Builder builder = ContentProviderOperation.newInsert(CapsuleContract.Capsules.CONTENT_URI); builder.withValues(Capsules.buildContentValues(capsule)); builder.withYieldAllowed(withYield); // Add it to the collection this.mOperations.add(builder.build()); }
public void buildCapsuleUpdate(Capsule capsule, boolean withYield) { // URI for updating a Capsule Uri uri = ContentUris.withAppendedId(CapsuleContract.Capsules.CONTENT_URI, capsule.getId()); // Build the UPDATE operation ContentProviderOperation.Builder builder = ContentProviderOperation.newUpdate(uri); builder.withValues(Capsules.buildContentValues(capsule)); builder.withYieldAllowed(withYield); // Add it to the collection this.mOperations.add(builder.build()); }
public void buildOwnershipInsert( CapsuleOwnership ownership, boolean withYield, CapsuleContract.SyncStateAction syncAction) { // Build the URI Uri uri = CapsuleOperations.appendDirtyQueryParam(syncAction, CapsuleContract.Ownerships.CONTENT_URI); // Build the INSERT operation ContentProviderOperation.Builder builder = ContentProviderOperation.newInsert(uri); builder.withValues(Ownerships.buildContentValues(ownership)); builder.withYieldAllowed(withYield); // Add it to the collection this.mOperations.add(builder.build()); }
public void buildDiscoveryUpdate( CapsuleDiscovery discovery, boolean withYield, CapsuleContract.SyncStateAction syncAction) { // Build the URI Uri uri = CapsuleOperations.appendDirtyQueryParam( syncAction, ContentUris.withAppendedId( CapsuleContract.Discoveries.CONTENT_URI, discovery.getDiscoveryId())); // Build the UPDATE operation ContentProviderOperation.Builder builder = ContentProviderOperation.newUpdate(uri); builder.withValues(Discoveries.buildContentValues(discovery)); builder.withYieldAllowed(withYield); // Add it to the collection this.mOperations.add(builder.build()); }
public void buildOwnershipInsert( CapsuleOwnership ownership, boolean withYield, int capsuleIdBackRefIndex, CapsuleContract.SyncStateAction syncAction) { // Build the URI Uri uri = CapsuleOperations.appendDirtyQueryParam(syncAction, CapsuleContract.Ownerships.CONTENT_URI); // Build the INSERT operation ContentProviderOperation.Builder builder = ContentProviderOperation.newInsert(uri); builder.withValues(Ownerships.buildContentValues(ownership)); builder.withYieldAllowed(withYield); // Add the back value reference index for the Capsule ID if (capsuleIdBackRefIndex >= 0) { builder.withValueBackReference(CapsuleContract.Ownerships.CAPSULE_ID, capsuleIdBackRefIndex); } // Add it to the collection this.mOperations.add(builder.build()); }
public void buildDiscoveryUpdate( CapsuleDiscovery discovery, boolean withYield, int capsuleIdBackRefIndex, CapsuleContract.SyncStateAction syncAction) { // Build the URI Uri uri = CapsuleOperations.appendDirtyQueryParam( syncAction, ContentUris.withAppendedId( CapsuleContract.Discoveries.CONTENT_URI, discovery.getDiscoveryId())); // Build the UPDATE operation ContentProviderOperation.Builder builder = ContentProviderOperation.newUpdate(uri); builder.withValues(Discoveries.buildContentValues(discovery)); builder.withYieldAllowed(withYield); // Add the back value reference for the Capsule ID if (capsuleIdBackRefIndex >= 0) { builder.withValueBackReference(CapsuleContract.Discoveries.CAPSULE_ID, capsuleIdBackRefIndex); } // Add it to the collection this.mOperations.add(builder.build()); }
private static void importOneSimContact( final Cursor cursor, final ContentResolver resolver, Account account) { final NamePhoneTypePair namePhoneTypePair = new NamePhoneTypePair( cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME))); final String name = namePhoneTypePair.name; final int phoneType = namePhoneTypePair.phoneType; final String phoneNumber = cursor.getString(cursor.getColumnIndex(ContactsContract.Data.DATA1)); final String emailAddresses = null; final String[] emailAddressArray; if (!TextUtils.isEmpty(emailAddresses)) { emailAddressArray = emailAddresses.split(","); } else { emailAddressArray = null; } final ArrayList<ContentProviderOperation> operationList = new ArrayList<ContentProviderOperation>(); ContentProviderOperation.Builder builder = ContentProviderOperation.newInsert(RawContacts.CONTENT_URI); if (account != null) { builder.withValue(RawContacts.ACCOUNT_NAME, account.name); builder.withValue(RawContacts.ACCOUNT_TYPE, account.type); } else { builder.withValues(sEmptyContentValues); } operationList.add(builder.build()); builder = ContentProviderOperation.newInsert(Data.CONTENT_URI); builder.withValueBackReference(StructuredName.RAW_CONTACT_ID, 0); builder.withValue(Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE); builder.withValue(StructuredName.DISPLAY_NAME, name); operationList.add(builder.build()); builder = ContentProviderOperation.newInsert(Data.CONTENT_URI); builder.withValueBackReference(Phone.RAW_CONTACT_ID, 0); builder.withValue(Data.MIMETYPE, Phone.CONTENT_ITEM_TYPE); builder.withValue(Phone.TYPE, phoneType); builder.withValue(Phone.NUMBER, phoneNumber); builder.withValue(Data.IS_PRIMARY, 1); operationList.add(builder.build()); if (emailAddresses != null) { for (String emailAddress : emailAddressArray) { builder = ContentProviderOperation.newInsert(Data.CONTENT_URI); builder.withValueBackReference(Email.RAW_CONTACT_ID, 0); builder.withValue(Data.MIMETYPE, Email.CONTENT_ITEM_TYPE); builder.withValue(Email.TYPE, Email.TYPE_MOBILE); builder.withValue(Email.DATA, emailAddress); operationList.add(builder.build()); } } try { resolver.applyBatch(ContactsContract.AUTHORITY, operationList); } catch (RemoteException e) { Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage())); } catch (OperationApplicationException e) { Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage())); } }