Java Code Examples for android.content.ContentProviderOperation#newDelete()

The following examples show how to use android.content.ContentProviderOperation#newDelete() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EventProvider.java    From RememBirthday with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Delete the specific event, id must be specified
 * @param event Event to deleteById
 * @return ContentProviderOperation to apply or null if no id
 */
public static ContentProviderOperation delete(CalendarEvent event) {
    if(event.hasId()) {
        ContentProviderOperation.Builder builder;
        builder = ContentProviderOperation.newDelete(
                ContentUris.withAppendedId(CalendarContract.Events.CONTENT_URI, event.getId()));
        Log.d(TAG, "Build deleteById event : " + event);
        return builder.build();
    } else {
        Log.e(TAG, "Can't deleteById the event, there is no id");
        return null;
    }
}
 
Example 2
Source File: ContactUtil.java    From haxsync with GNU General Public License v2.0 5 votes vote down vote up
public static void updateContactPhoto(ContentResolver c, long rawContactId, Photo pic, boolean primary){
	ArrayList<ContentProviderOperation> operationList = new ArrayList<ContentProviderOperation>();
	

	
	//insert new picture
	try {
		if(pic.data != null) {
               //delete old picture
               String where = ContactsContract.Data.RAW_CONTACT_ID + " = '" + rawContactId
                       + "' AND " + ContactsContract.Data.MIMETYPE + " = '" + ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE + "'";
               Log.i(TAG, "Deleting picture: "+where);

               ContentProviderOperation.Builder builder = ContentProviderOperation.newDelete(ContactsContract.Data.CONTENT_URI);
               builder.withSelection(where, null);
               operationList.add(builder.build());
			builder = ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI);
			builder.withValue(ContactsContract.CommonDataKinds.Photo.RAW_CONTACT_ID, rawContactId);
			builder.withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Photo.CONTENT_ITEM_TYPE);
			builder.withValue(ContactsContract.CommonDataKinds.Photo.PHOTO, pic.data);
			builder.withValue(ContactsContract.Data.SYNC2, String.valueOf(pic.timestamp));
			builder.withValue(ContactsContract.Data.SYNC3, pic.url);
               if (primary)
			    builder.withValue(ContactsContract.Data.IS_SUPER_PRIMARY, 1);
			operationList.add(builder.build());

			
		}
		c.applyBatch(ContactsContract.AUTHORITY,	operationList);

	} catch (Exception e) {
		// TODO Auto-generated catch block
		Log.e("ERROR:" , e.toString());
	}


}
 
Example 3
Source File: ContactDataMapper.java    From ContactMerger with Apache License 2.0 5 votes vote down vote up
/**
 * Append all operations needed to store the current contact to a set of
 * operations.
 * @param contact The current contact with metadata.
 * @param operations A set of operations to be extended.
 */
public void persist(RawContact contact, ArrayList<ContentProviderOperation> operations) {
    int operationsStart = operations.size();
    Builder operation;
    if (contact.getID() == -1) {
        operation = ContentProviderOperation.newInsert(RawContacts.CONTENT_URI);
    } else {
        operation = ContentProviderOperation.newUpdate(RawContacts.CONTENT_URI);
        operation.withSelection(RawContacts._ID + "=?", new String[]{Long.toString(contact.getID())});
    }
    ContentValues values = new ContentValues();
    put(values, contact);
    operation.withValues(values);
    operations.add(operation.build());
    for (Metadata data: contact.getMetadata().values()) {
        values.clear();
        put(values, data);
        if (data instanceof DeletedMetadata) {
            operation = ContentProviderOperation.newDelete(Data.CONTENT_URI);
            operation.withValues(values);
            operation.withSelection(Data._ID + "=?", new String[]{Long.toString(contact.getID())});
            operations.add(operation.build());
            continue;
        }
        if (data.getID() == -1) {
            operation = ContentProviderOperation.newInsert(Data.CONTENT_URI);
        } else {
            operation = ContentProviderOperation.newUpdate(Data.CONTENT_URI);
            operation.withSelection(Data._ID + "=?", new String[]{Long.toString(data.getID())});
        }
        if (contact.getID() == -1) {
            operation.withValueBackReference(Data.RAW_CONTACT_ID, operationsStart);
            values.remove(Data.RAW_CONTACT_ID);
        } else {
            values.put(Data.RAW_CONTACT_ID, contact.getID());
        }
        operation.withValues(values);
        operations.add(operation.build());
    }
}