Java Code Examples for android.content.ContentProviderOperation#Builder

The following examples show how to use android.content.ContentProviderOperation#Builder . These examples are extracted from open source projects. 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 Project: opentasks   File: NoTimeData.java    License: Apache License 2.0 6 votes vote down vote up
@NonNull
@Override
public ContentProviderOperation.Builder updatedBuilder(@NonNull TransactionContext transactionContext, @NonNull ContentProviderOperation.Builder builder)
{
    return builder
            .withValue(TaskContract.Tasks.DTSTART, null)
            .withValue(TaskContract.Tasks.DUE, null)
            .withValue(TaskContract.Tasks.DURATION, null)

            .withValue(TaskContract.Tasks.TZ, null)
            .withValue(TaskContract.Tasks.IS_ALLDAY, null)

            .withValue(TaskContract.Tasks.RDATE, null)
            .withValue(TaskContract.Tasks.RRULE, null)
            .withValue(TaskContract.Tasks.EXDATE, null);
}
 
Example 2
@Override
protected Exception doInBackground(Void... voids) {
    try {
        ArrayList<ContentProviderOperation> ops = new ArrayList<>();
        ContentProviderOperation.Builder contentBuilder =  ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI)
                .withSelection(ContactsContract.Data._ID + " =? AND " +
                                ContactsContract.Data.MIMETYPE + " =? AND " +
                                ContactsContract.CommonDataKinds.Event.START_DATE + " =? AND " +
                                ContactsContract.CommonDataKinds.Event.TYPE + " =?"
                        , new String[]{String.valueOf(dataId),
                                ContactsContract.CommonDataKinds.Event.CONTENT_ITEM_TYPE,
                                oldBirthday.toBackupString(),
                                String.valueOf(ContactsContract.CommonDataKinds.Event.TYPE_BIRTHDAY)})
                .withValue(ContactsContract.CommonDataKinds.Event.START_DATE, birthday.toBackupString());
        Log.d(getClass().getSimpleName(), "Update birthday " + oldBirthday + " to " + birthday);
        ops.add(contentBuilder.build());
        ContentProviderResult[] results = context.getContentResolver().applyBatch(ContactsContract.AUTHORITY, ops);
        if(results[0].count == 0)
            return new Exception("Unable to update birthday");
    } catch(Exception e) {
        return e;
    }
    return null;
}
 
Example 3
/**
 * Get a new ContentProviderOperation to insert an event
 */
public static ContentProviderOperation insert(Context context, long calendarId,
                                              CalendarEvent event, @Nullable Contact contact) {
    ContentProviderOperation.Builder builder;

    builder = ContentProviderOperation.newInsert(CalendarLoader.getBirthdayAdapterUri(context, CalendarContract.Events.CONTENT_URI));
    builder.withValue(CalendarContract.Events.CALENDAR_ID, calendarId);
    assignValuesInBuilder(builder, event);

    builder.withValue(CalendarContract.Events.STATUS, CalendarContract.Events.STATUS_CONFIRMED);

    /*
     * Enable reminders for this event
     * Note: Needs to be explicitly set on Android < 4 to enable reminders
     */
    builder.withValue(CalendarContract.Events.HAS_ALARM, 1);

    /*
     * Set availability to free.
     * Note: HTC calendar (4.0.3 Android + HTC Sense 4.0) will show a conflict with other events
     * if availability is not set to free!
     */
    if (Build.VERSION.SDK_INT >= 14) {
        builder.withValue(CalendarContract.Events.AVAILABILITY, CalendarContract.Events.AVAILABILITY_FREE);
    }

    // add button to open contact
    if (Build.VERSION.SDK_INT >= 16 && contact != null && contact.getLookUpKey() != null) {
        builder.withValue(CalendarContract.Events.CUSTOM_APP_PACKAGE, context.getPackageName());
        Uri contactLookupUri = Uri.withAppendedPath(
                ContactsContract.Contacts.CONTENT_LOOKUP_URI, contact.getLookUpKey());
        builder.withValue(CalendarContract.Events.CUSTOM_APP_URI, contactLookupUri.toString());
    }
    Log.d(TAG, "Build insert event : " + event);
    return builder.build();
}
 
Example 4
Source Project: react-native-paged-contacts   File: Note.java    License: MIT License 5 votes vote down vote up
@Override
public void addCreationOp(ArrayList<ContentProviderOperation> ops) {
    ContentProviderOperation.Builder op = ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
            .withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0)
            .withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Note.CONTENT_ITEM_TYPE)
            .withValue(ContactsContract.CommonDataKinds.Note.NOTE, note);
    ops.add(op.build());
}
 
Example 5
Source Project: opentasks   File: DueData.java    License: Apache License 2.0 5 votes vote down vote up
@NonNull
@Override
public ContentProviderOperation.Builder updatedBuilder(@NonNull TransactionContext transactionContext, @NonNull ContentProviderOperation.Builder builder)
{
    return builder
            .withValue(TaskContract.Tasks.DUE, mDue.getTimestamp())
            .withValue(TaskContract.Tasks.TZ, mDue.isAllDay() ? "UTC" : mDue.getTimeZone().getID())
            .withValue(TaskContract.Tasks.IS_ALLDAY, mDue.isAllDay() ? 1 : 0)
            .withValue(TaskContract.Tasks.DTSTART, null)
            .withValue(TaskContract.Tasks.DURATION, null);
}
 
Example 6
public static ContentProviderOperation insert(Context context, Reminder reminder, int backref) {
    ContentProviderOperation.Builder builder = ContentProviderOperation
            .newInsert(CalendarLoader.getBirthdayAdapterUri(context, CalendarContract.Reminders.CONTENT_URI));
    /*
     * add reminder to last added event identified by backRef
     * see http://stackoverflow.com/questions/4655291/semantics-of-
     * withvaluebackreference
     */
    builder.withValueBackReference(CalendarContract.Reminders.EVENT_ID, backref);
    return insert(builder, reminder);
}
 
Example 7
Source Project: v2ex   File: MembersHandler.java    License: Apache License 2.0 5 votes vote down vote up
private void buildMember(boolean isInsert, Member member,
                        ArrayList<ContentProviderOperation> list) {
    Uri uri = V2exContract.Members.buildMemberUsernameUri(member.username);

    ContentProviderOperation.Builder builder;
    if (isInsert) {
        builder = ContentProviderOperation.newInsert(uri);
    } else {
        builder = ContentProviderOperation.newUpdate(uri);
    }

    list.add(builder.withValue(V2exContract.Members.MEMBER_ID, member.id)
            .withValue(V2exContract.Members.MEMBER_URL, member.url)
            .withValue(V2exContract.Members.MEMBER_USERNAME, member.username)
            .withValue(V2exContract.Members.MEMBER_WEBSITE, member.website)
            .withValue(V2exContract.Members.MEMBER_TWITTER, member.twitter)
            .withValue(V2exContract.Members.MEMBER_PSN, member.psn)
            .withValue(V2exContract.Members.MEMBER_GITHUB, member.github)
            .withValue(V2exContract.Members.MEMBER_BTC, member.btc)
            .withValue(V2exContract.Members.MEMBER_LOCATION, member.location)
            .withValue(V2exContract.Members.MEMBER_TAGLINE, member.tagline)
            .withValue(V2exContract.Members.MEMBER_BIO, member.bio)
            .withValue(V2exContract.Members.MEMBER_AVATAR_MINI, member.avatar_mini)
            .withValue(V2exContract.Members.MEMBER_AVATAR_NORMAL, member.avatar_normal)
            .withValue(V2exContract.Members.MEMBER_AVATAR_LARGE, member.avatar_large)
            .withValue(V2exContract.Members.MEMBER_CREATED, member.created)
            .withValue(V2exContract.Members.MEMBER_IMPORT_HASHCODE, member.getImportHashcode())
            .build());
}
 
Example 8
Source Project: react-native-paged-contacts   File: UrlAddress.java    License: MIT License 5 votes vote down vote up
@Override
public void addCreationOp(ArrayList<ContentProviderOperation> ops) {
    ContentProviderOperation.Builder op = ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
            .withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0)
            .withValue(ContactsContract.Data.MIMETYPE, ContactsContract.CommonDataKinds.Website.CONTENT_ITEM_TYPE)
            .withValue(ContactsContract.CommonDataKinds.Website.URL, url);
    ops.add(op.build());
}
 
Example 9
Source Project: react-native-paged-contacts   File: Name.java    License: MIT License 5 votes vote down vote up
public void addCreationOp(ArrayList<ContentProviderOperation> ops) {
    ContentProviderOperation.Builder op = ContentProviderOperation.newInsert(ContactsContract.Data.CONTENT_URI)
            .withValueBackReference(ContactsContract.Data.RAW_CONTACT_ID, 0)
            .withValue(ContactsContract.Data.MIMETYPE, StructuredName.CONTENT_ITEM_TYPE)
            .withValue(StructuredName.GIVEN_NAME, givenName)
            .withValue(StructuredName.MIDDLE_NAME, middleName)
            .withValue(StructuredName.FAMILY_NAME, familyName)
            .withValue(StructuredName.PREFIX, namePrefix)
            .withValue(StructuredName.SUFFIX, nameSuffix)
            .withValue(StructuredName.PHONETIC_GIVEN_NAME, phoneticGivenName)
            .withValue(StructuredName.PHONETIC_FAMILY_NAME, phoneticFamilyName)
            .withValue(StructuredName.PHONETIC_MIDDLE_NAME, phoneticMiddleName);

    ops.add(op.build());
}
 
Example 10
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 11
Source Project: tindroid   File: ContactOperations.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Adds an insert operation into the batch
 */
private void addInsertOp() {
    if (!mIsNewContact) {
        mValues.put(Phone.RAW_CONTACT_ID, mRawContactId);
    }
    ContentProviderOperation.Builder builder = newInsertCpo(Data.CONTENT_URI, mIsSyncContext).withValues(mValues);
    if (mIsNewContact) {
        builder.withValueBackReference(Data.RAW_CONTACT_ID, mBackReference);
    }

    mBatchOperation.add(builder.build());
}
 
Example 12
public static ContentProviderOperation updateWithUnknownId(Context context, long eventId, Reminder reminder, int newMinutes) {
    // TODO update
    ContentProviderOperation.Builder builder = ContentProviderOperation
            .newUpdate(CalendarLoader.getBirthdayAdapterUri(context, CalendarContract.Reminders.CONTENT_URI))
            .withSelection(CalendarContract.Reminders.EVENT_ID + " =?"
                            + " AND " + CalendarContract.Reminders.MINUTES + " =?"
                    , new String[]{String.valueOf(eventId),
                            String.valueOf(reminder.getMinutesBeforeEvent())})
            .withValue(CalendarContract.Reminders.MINUTES, newMinutes);
    return  builder.build();
}
 
Example 13
Source Project: CPOrm   File: TransactionHelper.java    License: MIT License 5 votes vote down vote up
private static void applyReferences(TableDetails tableDetails, ContentProviderOperation.Builder source, Map<Class, Integer> referenceMap){

        for (TableDetails.ColumnDetails columnDetails : tableDetails.getColumns()) {

            if(columnDetails.getColumnField().isAnnotationPresent(References.class)) {
                backReferenceFromReferenceAnnotation(source, referenceMap, columnDetails);
            }
        }
    }
 
Example 14
Source Project: v2ex   File: FeedsHandler.java    License: Apache License 2.0 5 votes vote down vote up
private void buildFeed(boolean isInsert, Feed feed,
                        ArrayList<ContentProviderOperation> list) {
    Uri allVideosUri = V2exContract.addCallerIsSyncAdapterParameter(
            V2exContract.Feeds.CONTENT_URI);
    Uri thisVideoUri = V2exContract.addCallerIsSyncAdapterParameter(
            V2exContract.Feeds.buildFeedUri(String.valueOf(feed.id)));

    ContentProviderOperation.Builder builder;
    if (isInsert) {
        builder = ContentProviderOperation.newInsert(allVideosUri);
    } else {
        builder = ContentProviderOperation.newUpdate(thisVideoUri);
    }

    if (TextUtils.isEmpty(String.valueOf(feed.id))) {
        LOGW(TAG, "Ignoring feed with missing feed ID.");
        return;
    }

    list.add(builder.withValue(V2exContract.Feeds.FEED_ID, feed.id)
            .withValue(V2exContract.Feeds.FEED_TITLE, feed.title)
            .withValue(V2exContract.Feeds.FEED_URL, feed.url)
            .withValue(V2exContract.Feeds.FEED_CONTENT, feed.content)
            .withValue(V2exContract.Feeds.FEED_CONTENT_RENDERED, feed.content_rendered)
            .withValue(V2exContract.Feeds.FEED_REPLIES, feed.replies)
            .withValue(V2exContract.Feeds.FEED_MEMBER, ModelUtils.serializeMember(feed.member))
            .withValue(V2exContract.Feeds.FEED_NODE, ModelUtils.serializeNode(feed.node))
            .withValue(V2exContract.Feeds.FEED_CREATED, feed.created)
            .withValue(V2exContract.Feeds.FEED_LAST_MODIFIED, feed.last_modified)
            .withValue(V2exContract.Feeds.FEED_LAST_TOUCHED, feed.last_touched)
            .withValue(V2exContract.Feeds.FEED_IMPORT_HASHCODE, feed.getImportHashcode())
            .build());
}
 
Example 15
/**
 * Update the specific event, id must be specified
 * @param event Event to update
 * @return ContentProviderOperation to apply or null if no id
 */
public static ContentProviderOperation update(CalendarEvent event) {
    if(event.hasId()) {
        ContentProviderOperation.Builder builder;
        builder = ContentProviderOperation.newUpdate(
                ContentUris.withAppendedId(CalendarContract.Events.CONTENT_URI, event.getId()));
        // Push values
        assignValuesInBuilder(builder, event);
        Log.d(TAG, "Build update event : " + event);
        return builder.build();
    } else {
        Log.e(TAG, "Can't update the event, there is no id");
        return null;
    }
}
 
Example 16
Source Project: opentasks   File: VersionData.java    License: Apache License 2.0 4 votes vote down vote up
@NonNull
@Override
public ContentProviderOperation.Builder updatedBuilder(@NonNull TransactionContext transactionContext, @NonNull ContentProviderOperation.Builder builder)
{
    return builder.withValue(TaskContract.Tasks.VERSION, mVersion);
}
 
Example 17
private static long getCalendar(Context context) {

        ContentResolver contentResolver = context.getContentResolver();

        // Find the calendar if we've got one
        Uri calenderUri = CalendarContract.Calendars.CONTENT_URI.buildUpon().appendQueryParameter(CalendarContract.CALLER_IS_SYNCADAPTER, "true")
                .appendQueryParameter(CalendarContract.Calendars.ACCOUNT_NAME, ACCOUNT_NAME)
                .appendQueryParameter(CalendarContract.Calendars.ACCOUNT_TYPE, ACCOUNT_TYPE).build();


        Cursor cursor = contentResolver.query(calenderUri, new String[]{BaseColumns._ID},
                CalendarContract.Calendars.ACCOUNT_NAME + " = ? AND " + CalendarContract.Calendars.ACCOUNT_TYPE + " = ?",
                new String[]{ACCOUNT_NAME, ACCOUNT_TYPE}, null);

        try {
            if (cursor != null && cursor.moveToNext()) {
                return cursor.getLong(0);
            } else {
                ArrayList<ContentProviderOperation> operationList = new ArrayList<>();

                ContentProviderOperation.Builder builder = ContentProviderOperation
                        .newInsert(calenderUri);
                builder.withValue(CalendarContract.Calendars.ACCOUNT_NAME, ACCOUNT_NAME);
                builder.withValue(CalendarContract.Calendars.ACCOUNT_TYPE, ACCOUNT_TYPE);
                builder.withValue(CalendarContract.Calendars.NAME, CALENDAR_COLUMN_NAME);
                builder.withValue(CalendarContract.Calendars.CALENDAR_DISPLAY_NAME,
                        context.getString(R.string.appName));
                builder.withValue(CalendarContract.Calendars.CALENDAR_COLOR, context.getResources().getColor(R.color.colorPrimary));
                builder.withValue(CalendarContract.Calendars.CALENDAR_ACCESS_LEVEL, CalendarContract.Calendars.CAL_ACCESS_READ);
                builder.withValue(CalendarContract.Calendars.SYNC_EVENTS, 0);
                builder.withValue(CalendarContract.Calendars.VISIBLE, 1);

                operationList.add(builder.build());
                try {
                    contentResolver.applyBatch(CalendarContract.AUTHORITY, operationList);
                } catch (Exception e) {
                    e.printStackTrace();
                    return -1;
                }
                return getCalendar(context);
            }
        } finally {
            if (cursor != null && !cursor.isClosed())
                cursor.close();
        }
    }
 
Example 18
Source Project: tindroid   File: ContactOperations.java    License: Apache License 2.0 4 votes vote down vote up
private static ContentProviderOperation.Builder newInsertCpo(Uri uri, boolean isSyncContext) {
    return ContentProviderOperation
            .newInsert(addCallerIsSyncAdapterParameter(uri, isSyncContext))
            .withYieldAllowed(false);
}
 
Example 19
public static ContentProviderOperation insert(Context context, long eventId, Reminder reminder) {
    ContentProviderOperation.Builder builder = ContentProviderOperation
            .newInsert(CalendarLoader.getBirthdayAdapterUri(context, CalendarContract.Reminders.CONTENT_URI));
    builder.withValue(CalendarContract.Reminders.EVENT_ID, eventId);
    return insert(builder, reminder);
}
 
Example 20
Source Project: CPOrm   File: TransactionHelper.java    License: MIT License 3 votes vote down vote up
private static void backReferenceFromReferenceAnnotation(ContentProviderOperation.Builder source, Map<Class, Integer> referenceMap, TableDetails.ColumnDetails columnDetails) {
    References reference = columnDetails.getColumnField().getAnnotation(References.class);

    if(!referenceMap.containsKey(reference.value()))
        return;

    String columnName = columnDetails.getColumnName();

    source.withValueBackReference(columnName, referenceMap.get(reference.value()));
}