Java Code Examples for android.content.ContentProviderOperation.Builder.withValue()

The following are Jave code examples for showing how to use withValue() of the android.content.ContentProviderOperation.Builder class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: scrumchatter   File: DBImport.java   Source Code and License Vote up 6 votes
private static void buildInsertOperations(SQLiteDatabase dbImport, Uri uri, String table, ArrayList<ContentProviderOperation> operations) {
    Log.v(TAG, "buildInsertOperations: uri = " + uri + ", table=" + table);
    Cursor c = dbImport.query(false, table, null, null, null, null, null, null, null);
    if (c != null) {
        try {
            if (c.moveToFirst()) {
                int columnCount = c.getColumnCount();
                do {
                    Builder builder = ContentProviderOperation.newInsert(uri);
                    for (int i = 0; i < columnCount; i++) {
                        String columnName = c.getColumnName(i);
                        Object value = c.getString(i);
                        builder.withValue(columnName, value);
                    }
                    operations.add(builder.build());
                } while (c.moveToNext());
            }
        } finally {
            c.close();
        }
    }

}
 
Example 2
Project: CucumberSync   File: LocalCalendar.java   Source Code and License Vote up 5 votes
@SuppressLint("InlinedApi")
protected Builder buildAttendee(Builder builder, Attendee attendee) {
	String email = attendee.getEmail();
	
	String cn = attendee.getCommonName();
	if (cn != null)
		builder = builder.withValue(Attendees.ATTENDEE_NAME, cn);
	
	int type = Attendees.TYPE_NONE;
	if (attendee.getCalendarUserType() == CalendarUserType.RESOURCE)
		type = Attendees.TYPE_RESOURCE;
	else {
		int relationship;
		if (attendee.getRole() == Role.CHAIR)
			relationship = Attendees.RELATIONSHIP_ORGANIZER;
		else {
			relationship = Attendees.RELATIONSHIP_ATTENDEE;
		}
		builder = builder.withValue(Attendees.ATTENDEE_RELATIONSHIP, relationship);
	}
	
	int status = Attendees.ATTENDEE_STATUS_NONE;
	ParticipationStatus partStat = attendee.getParticipationStatus();
	if (partStat == null || partStat == ParticipationStatus.NEEDS_ACTION)
		status = Attendees.ATTENDEE_STATUS_INVITED;
	else if (partStat == ParticipationStatus.ACCEPTED)
		status = Attendees.ATTENDEE_STATUS_ACCEPTED;
	else if (partStat == ParticipationStatus.DECLINED)
		status = Attendees.ATTENDEE_STATUS_DECLINED;
	else if (partStat == ParticipationStatus.TENTATIVE)
		status = Attendees.ATTENDEE_STATUS_TENTATIVE;
	
	return builder
		.withValue(Attendees.ATTENDEE_EMAIL, email)
		.withValue(Attendees.ATTENDEE_TYPE, type)
		.withValue(Attendees.ATTENDEE_STATUS, status);
}
 
Example 3
Project: CucumberSync   File: LocalCollection.java   Source Code and License Vote up 5 votes
protected Builder newDataInsertBuilder(Uri dataUri, String refFieldName, long raw_ref_id, Integer backrefIdx) {
	Builder builder = ContentProviderOperation.newInsert(syncAdapterURI(dataUri));
	if (backrefIdx != -1)
		return builder.withValueBackReference(refFieldName, backrefIdx);
	else
		return builder.withValue(refFieldName, raw_ref_id);
}
 
Example 4
Project: CucumberSync   File: LocalAddressBook.java   Source Code and License Vote up 5 votes
protected Builder buildEmail(Builder builder, ezvcard.property.Email email) {
	int typeCode = 0;
	String typeLabel = null;
	boolean is_primary = false;
	
	for (EmailType type : email.getTypes())
		if (type == EmailType.PREF)
			is_primary = true;
		else if (type == EmailType.HOME)
			typeCode = Email.TYPE_HOME;
		else if (type == EmailType.WORK)
			typeCode = Email.TYPE_WORK;
		else if (type == Contact.EMAIL_TYPE_MOBILE)
			typeCode = Email.TYPE_MOBILE;
	if (typeCode == 0) {
		if (email.getTypes().isEmpty())
			typeCode = Email.TYPE_OTHER;
		else {
			typeCode = Email.TYPE_CUSTOM;
			typeLabel = xNameToLabel(email.getTypes().iterator().next().getValue());
		}
	}
	
	builder = builder
			.withValue(Data.MIMETYPE, Email.CONTENT_ITEM_TYPE)
			.withValue(Email.ADDRESS, email.getValue())
			.withValue(Email.TYPE, typeCode)
			.withValue(Email.IS_PRIMARY, is_primary ? 1 : 0)
			.withValue(Phone.IS_SUPER_PRIMARY, is_primary ? 1 : 0);;
	if (typeLabel != null)
		builder = builder.withValue(Email.LABEL, typeLabel);
	return builder;
}
 
Example 5
Project: mobile-client   File: NewsHandler.java   Source Code and License Vote up 5 votes
/**
 * Parse a given {@link News} entry, building
 * {@link ContentProviderOperation} to define it locally.
 */
private static void parseMessage(JsonParser parser,
		ArrayList<ContentProviderOperation> batch, ContentResolver resolver)
		throws JsonParseException, IOException {
	Builder builder = ContentProviderOperation.newInsert(News.CONTENT_URI);

	builder.withValue(News.NEWS_NEW, 1);

	String fieldName = null;
	JsonToken token;
	while ((token = parser.nextToken()) != END_OBJECT) {
		if (token == FIELD_NAME) {
			fieldName = parser.getCurrentName();
		} else if (token == VALUE_STRING) {
			final String text = parser.getText();
			if (Fields.DATE.equals(fieldName)) {
				final String id = News.generateNewsId(text);
				builder.withValue(News.NEWS_ID, id);
				builder.withValue(News.NEWS_DATE, text);
			} else if (Fields.MESSAGE.equals(fieldName)) {
				builder.withValue(News.NEWS_TEXT, text);
			}
		}
	}

	batch.add(builder.build());
}
 
Example 6
Project: aos-MediaLib   File: EpisodeTags.java   Source Code and License Vote up 4 votes
public void addSaveOperation(ArrayList<ContentProviderOperation> list, Map<String, Long> poster2IdMap) {
    if (list == null) return;

    // create ContentValues for this episode
    ContentValues values = new ContentValues();
    values.put(ScraperStore.Episode.VIDEO_ID, Long.valueOf(mVideoId));
    values.put(ScraperStore.Episode.NAME, mTitle);
    if(mAired != null) {
        values.put(ScraperStore.Episode.AIRED, Long.valueOf(mAired.getTime()));
    }
    values.put(ScraperStore.Episode.RATING, Float.valueOf(mRating));
    values.put(ScraperStore.Episode.PLOT, mPlot);
    values.put(ScraperStore.Episode.SEASON, Integer.valueOf(mSeason));
    values.put(ScraperStore.Episode.NUMBER, Integer.valueOf(mEpisode));
    values.put(ScraperStore.Episode.SHOW, Long.valueOf(mShowId));
    values.put(ScraperStore.Episode.IMDB_ID, mImdbId);
    values.put(ScraperStore.Episode.ONLINE_ID, Long.valueOf(mOnlineId));

    values.put(ScraperStore.Episode.ACTORS_FORMATTED, getActorsFormatted());
    values.put(ScraperStore.Episode.DIRECTORS_FORMATTED, getDirectorsFormatted());

    ScraperImage pic = getEpisodePicture();
    if(pic!=null && pic.getLargeFile()!=null)
        values.put(ScraperStore.Episode.PICTURE, pic.getLargeFile());
    
    File cover = getCover();
    String coverPath = (cover != null) ? cover.getPath() : null;
    if (coverPath != null && !coverPath.isEmpty())
        values.put(ScraperStore.Episode.COVER, coverPath);

    // need to find the poster id in the database
    ScraperImage poster = getDefaultPoster();

    if (poster != null) {
        Long posterId = poster2IdMap.get(poster.getLargeFile());
        values.put(ScraperStore.Episode.POSTER_ID, posterId);
    }

    // build list of operations
    Builder cop = null;

    int firstIndex = list.size();
    // first insert the episode base info - item 0 for backreferences
    cop = ContentProviderOperation.newInsert(ScraperStore.Episode.URI.BASE);
    cop.withValues(values);
    list.add(cop.build());

    // then directors etc
    for(String director: mDirectors) {
        cop = ContentProviderOperation.newInsert(ScraperStore.Director.URI.EPISODE);
        cop.withValue(ScraperStore.Episode.Director.NAME, director);
        cop.withValueBackReference(ScraperStore.Episode.Director.EPISODE, firstIndex);
        list.add(cop.build());
    }

    for(String actorName: mActors.keySet()) {
        cop = ContentProviderOperation.newInsert(ScraperStore.Actor.URI.EPISODE);
        cop.withValue(ScraperStore.Episode.Actor.NAME, actorName);
        cop.withValueBackReference(ScraperStore.Episode.Actor.EPISODE, firstIndex);
        cop.withValue(ScraperStore.Episode.Actor.ROLE, mActors.get(actorName));
        list.add(cop.build());
    }
}
 
Example 7
Project: CucumberSync   File: LocalAddressBook.java   Source Code and License Vote up 4 votes
protected Builder buildPhoneNumber(Builder builder, Telephone number) {
	int typeCode = Phone.TYPE_OTHER;
	String typeLabel = null;
	boolean is_primary = false;
	
	Set<TelephoneType> types = number.getTypes();
	// preferred number?
	if (types.contains(TelephoneType.PREF))
		is_primary = true;
	
	// 1 Android type <-> 2 VCard types: fax, cell, pager
	if (types.contains(TelephoneType.FAX)) {
		if (types.contains(TelephoneType.HOME))
			typeCode = Phone.TYPE_FAX_HOME;
		else if (types.contains(TelephoneType.WORK))
			typeCode = Phone.TYPE_FAX_WORK;
		else
			typeCode = Phone.TYPE_OTHER_FAX;
	} else if (types.contains(TelephoneType.CELL)) {
		if (types.contains(TelephoneType.WORK))
			typeCode = Phone.TYPE_WORK_MOBILE;
		else
			typeCode = Phone.TYPE_MOBILE;
	} else if (types.contains(TelephoneType.PAGER)) {
		if (types.contains(TelephoneType.WORK))
			typeCode = Phone.TYPE_WORK_PAGER;
		else
			typeCode = Phone.TYPE_PAGER;
	// types with 1:1 translation
	} else if (types.contains(TelephoneType.HOME)) {
		typeCode = Phone.TYPE_HOME;
	} else if (types.contains(TelephoneType.WORK)) {
		typeCode = Phone.TYPE_WORK;
	} else if (types.contains(Contact.PHONE_TYPE_CALLBACK)) {
		typeCode = Phone.TYPE_CALLBACK;
	} else if (types.contains(TelephoneType.CAR)) {
		typeCode = Phone.TYPE_CAR;
	} else if (types.contains(Contact.PHONE_TYPE_COMPANY_MAIN)) {
		typeCode = Phone.TYPE_COMPANY_MAIN;
	} else if (types.contains(TelephoneType.ISDN)) {
		typeCode = Phone.TYPE_ISDN;
	} else if (types.contains(TelephoneType.PREF)) {
		typeCode = Phone.TYPE_MAIN;
	} else if (types.contains(Contact.PHONE_TYPE_RADIO)) {
		typeCode = Phone.TYPE_RADIO;
	} else if (types.contains(TelephoneType.TEXTPHONE)) {
		typeCode = Phone.TYPE_TELEX;
	} else if (types.contains(TelephoneType.TEXT)) {
		typeCode = Phone.TYPE_TTY_TDD;
	} else if (types.contains(Contact.PHONE_TYPE_ASSISTANT)) {
		typeCode = Phone.TYPE_ASSISTANT;
	} else if (types.contains(Contact.PHONE_TYPE_MMS)) {
		typeCode = Phone.TYPE_MMS;
	} else if (!types.isEmpty()) {
		TelephoneType type = types.iterator().next();
		typeCode = Phone.TYPE_CUSTOM;
		typeLabel = xNameToLabel(type.getValue());
	}
	
	builder = builder
		.withValue(Data.MIMETYPE, Phone.CONTENT_ITEM_TYPE)
		.withValue(Phone.NUMBER, number.getText())
		.withValue(Phone.TYPE, typeCode)
		.withValue(Phone.IS_PRIMARY, is_primary ? 1 : 0)
		.withValue(Phone.IS_SUPER_PRIMARY, is_primary ? 1 : 0);
	if (typeLabel != null)
		builder = builder.withValue(Phone.LABEL, typeLabel);
	return builder;
}
 
Example 8
Project: CucumberSync   File: LocalAddressBook.java   Source Code and License Vote up 4 votes
protected Builder buildIMPP(Builder builder, Impp impp) {
	int typeCode = 0;
	String typeLabel = null;
	for (ImppType type : impp.getTypes())
		if (type == ImppType.HOME)
			typeCode = Im.TYPE_HOME;
		else if (type == ImppType.WORK || type == ImppType.BUSINESS)
			typeCode = Im.TYPE_WORK;
	if (typeCode == 0)
		if (impp.getTypes().isEmpty())
			typeCode = Im.TYPE_OTHER;
		else {
			typeCode = Im.TYPE_CUSTOM;
			typeLabel = xNameToLabel(impp.getTypes().iterator().next().getValue());
		}
	
	int protocolCode = 0;
	String protocolLabel = null;
	
	String protocol = impp.getProtocol();
	if (protocol == null) {
		Log.w(TAG, "Ignoring IMPP address without protocol");
		return null;
	}
	
	// SIP addresses are IMPP entries in the VCard but locally stored in SipAddress rather than Im
	boolean sipAddress = false;
	
	if (impp.isAim())
		protocolCode = Im.PROTOCOL_AIM;
	else if (impp.isMsn())
		protocolCode = Im.PROTOCOL_MSN;
	else if (impp.isYahoo())
		protocolCode = Im.PROTOCOL_YAHOO;
	else if (impp.isSkype())
		protocolCode = Im.PROTOCOL_SKYPE;
	else if (protocol.equalsIgnoreCase("qq"))
		protocolCode = Im.PROTOCOL_QQ;
	else if (protocol.equalsIgnoreCase("google-talk"))
		protocolCode = Im.PROTOCOL_GOOGLE_TALK;
	else if (impp.isIcq())
		protocolCode = Im.PROTOCOL_ICQ;
	else if (impp.isXmpp() || protocol.equalsIgnoreCase("jabber"))
		protocolCode = Im.PROTOCOL_JABBER;
	else if (protocol.equalsIgnoreCase("netmeeting"))
		protocolCode = Im.PROTOCOL_NETMEETING;
	else if (protocol.equalsIgnoreCase("sip"))
		sipAddress = true;
	else {
		protocolCode = Im.PROTOCOL_CUSTOM;
		protocolLabel = protocol;
	}
	
	if (sipAddress)
		// save as SIP address
		builder = builder
			.withValue(Data.MIMETYPE, SipAddress.CONTENT_ITEM_TYPE)
			.withValue(Im.DATA, impp.getHandle())
			.withValue(Im.TYPE, typeCode);
	else {
		// save as IM address
		builder = builder
			.withValue(Data.MIMETYPE, Im.CONTENT_ITEM_TYPE)
			.withValue(Im.DATA, impp.getHandle())
			.withValue(Im.TYPE, typeCode)
			.withValue(Im.PROTOCOL, protocolCode);
		if (protocolLabel != null)
			builder = builder.withValue(Im.CUSTOM_PROTOCOL, protocolLabel);
	}
	if (typeLabel != null)
		builder = builder.withValue(Im.LABEL, typeLabel);
	return builder;
}
 
Example 9
Project: CucumberSync   File: LocalAddressBook.java   Source Code and License Vote up 4 votes
protected Builder buildAddress(Builder builder, Address address) {
	/*	street po.box (extended)
	 *	region
	 *	postal code city
	 *	country
	 */
	String formattedAddress = address.getLabel();
	if (StringUtils.isEmpty(formattedAddress)) {
		String	lineStreet = StringUtils.join(new String[] { address.getStreetAddress(), address.getPoBox(), address.getExtendedAddress() }, " "),
				lineLocality = StringUtils.join(new String[] { address.getPostalCode(), address.getLocality() }, " ");
		
		List<String> lines = new LinkedList<String>();
		if (lineStreet != null)
			lines.add(lineStreet);
		if (address.getRegion() != null && !address.getRegion().isEmpty())
			lines.add(address.getRegion());
		if (lineLocality != null)
			lines.add(lineLocality);
		
		formattedAddress = StringUtils.join(lines, "\n");
	}
		
	int typeCode = 0;
	String typeLabel = null;
	for (AddressType type : address.getTypes())
		if (type == AddressType.HOME)
			typeCode = StructuredPostal.TYPE_HOME;
		else if (type == AddressType.WORK)
			typeCode = StructuredPostal.TYPE_WORK;
	if (typeCode == 0)
		if (address.getTypes().isEmpty())
			typeCode = StructuredPostal.TYPE_OTHER;
		else {
			typeCode = StructuredPostal.TYPE_CUSTOM;
			typeLabel = xNameToLabel(address.getTypes().iterator().next().getValue());
		}
	
	builder = builder
		.withValue(Data.MIMETYPE, StructuredPostal.CONTENT_ITEM_TYPE)
		.withValue(StructuredPostal.FORMATTED_ADDRESS, formattedAddress)
		.withValue(StructuredPostal.TYPE, typeCode)
		.withValue(StructuredPostal.STREET, address.getStreetAddress())
		.withValue(StructuredPostal.POBOX, address.getPoBox())
		.withValue(StructuredPostal.NEIGHBORHOOD, address.getExtendedAddress())
		.withValue(StructuredPostal.CITY, address.getLocality())
		.withValue(StructuredPostal.REGION, address.getRegion())
		.withValue(StructuredPostal.POSTCODE, address.getPostalCode())
		.withValue(StructuredPostal.COUNTRY, address.getCountry());
	if (typeLabel != null)
		builder = builder.withValue(StructuredPostal.LABEL, typeLabel);
	return builder;
}
 
Example 10
Project: silent-contacts-android   File: RawContactDelta.java   Source Code and License Vote up 4 votes
/**
 * Build a list of {@link ContentProviderOperation} that will transform the
 * current "before" {link Entity} state into the modified state which this
 * {@link RawContactDelta} represents.
 */
public void buildDiff(ArrayList<ContentProviderOperation> buildInto) {
    final int firstIndex = buildInto.size();

    final boolean isContactInsert = mValues.isInsert();
    final boolean isContactDelete = mValues.isDelete();
    final boolean isContactUpdate = !isContactInsert && !isContactDelete;

    final Long beforeId = mValues.getId();

    Builder builder;

    // Build possible operation at Contact level
    builder = mValues.buildDiff(mContactsQueryUri);
    possibleAdd(buildInto, builder);

    // Build operations for all children
    for (ArrayList<ValuesDelta> mimeEntries : mEntries.values()) {
        for (ValuesDelta child : mimeEntries) {
            // Ignore children if parent was deleted
            if (isContactDelete)
                continue;

                builder = child.buildDiff(Data.CONTENT_URI);

            if (child.isInsert()) {
                if (isContactInsert) {
                    // Parent is brand new insert, so back-reference _id
                    builder.withValueBackReference(Data.RAW_CONTACT_ID, firstIndex);
                } else {
                    // Inserting under existing, so fill with known _id
                    builder.withValue(Data.RAW_CONTACT_ID, beforeId);
                }
            } else if (isContactInsert && builder != null) {
                // Child must be insert when Contact insert
                throw new IllegalArgumentException("When parent insert, child must be also");
            }
            possibleAdd(buildInto, builder);
        }
    }

}
 
Example 11
Project: scrumchatter   File: Meeting.java   Source Code and License Vote up 4 votes
/**
 * Stop the chronometers of all team members who are still talking. Update
 * the duration for these team members.
 */
private void shutEverybodyUp() {
    Log.v(TAG, "shutEverybodyUp");
    // Query all team members who are still talking in this meeting.
    Uri uri = Uri.withAppendedPath(MeetingMemberColumns.CONTENT_URI, String.valueOf(mId));
    // Closing the cursorWrapper also closes the cursor
    @SuppressLint("Recycle")
    Cursor cursor = mContext.getContentResolver().query(uri,
            new String[] { MeetingMemberColumns.MEMBER_ID, MeetingMemberColumns.DURATION, MeetingMemberColumns.TALK_START_TIME },
            MeetingMemberColumns.TALK_START_TIME + ">0", null, null);
    if (cursor != null) {
        // Prepare some update statements to set the duration and reset the
        // talk_start_time, for these members.
        ArrayList<ContentProviderOperation> operations = new ArrayList<>();
        MeetingMemberCursorWrapper cursorWrapper = new MeetingMemberCursorWrapper(cursor);
        if (cursorWrapper.moveToFirst()) {
            do {
                // Prepare an update operation for one of these members.
                Builder builder = ContentProviderOperation.newUpdate(MeetingMemberColumns.CONTENT_URI);
                long memberId = cursorWrapper.getMemberId();
                // Calculate the total duration the team member talked
                // during this meeting.
                long duration = cursorWrapper.getDuration();
                long talkStartTime = cursorWrapper.getTalkStartTime();
                long newDuration = duration + (System.currentTimeMillis() - talkStartTime) / 1000;
                builder.withValue(MeetingMemberColumns.DURATION, newDuration);
                builder.withValue(MeetingMemberColumns.TALK_START_TIME, 0);
                builder.withSelection(MeetingMemberColumns.MEMBER_ID + "=? AND " + MeetingMemberColumns.MEETING_ID + "=?",
                        new String[] { String.valueOf(memberId), String.valueOf(mId) });
                operations.add(builder.build());
            } while (cursorWrapper.moveToNext());
        }
        cursorWrapper.close();
        try {
            // Batch update these team members.
            mContext.getContentResolver().applyBatch(ScrumChatterProvider.AUTHORITY, operations);
        } catch (Exception e) {
            Log.v(TAG, "Couldn't close off meeting: " + e.getMessage(), e);
        }
    }
}
 
Example 12
Project: bikey   File: DatabaseImporter.java   Source Code and License Vote up 4 votes
/**
 * Read all cells from the given table from the dbImport database, and add corresponding insert operations to the operations parameter.
 */
private static void buildInsertOperations(Context context, SQLiteDatabase dbImport, Uri uri, String table, ArrayList<ContentProviderOperation> operations)
        throws RemoteException, OperationApplicationException {
    Log.d();
    Cursor c = dbImport.query(false, table, null, null, null, null, null, null, null);
    if (c != null) {
        try {
            if (c.moveToFirst()) {
                int columnCount = c.getColumnCount();
                do {
                    Builder builder = ContentProviderOperation.newInsert(uri);
                    for (int i = 0; i < columnCount; i++) {
                        String columnName = c.getColumnName(i);
                        Object value = c.getString(i);
                        // The distance and duration columns of the log table
                        // were renamed to log_distance and log_duration,
                        // in DB version 5.
                        if (LogColumns.TABLE_NAME.equals(table)) {
                            if ("distance".equals(columnName)) columnName = LogColumns.LOG_DISTANCE;
                            else if ("duration".equals(columnName)) columnName = LogColumns.LOG_DURATION;
                        }
                        builder.withValue(columnName, value);
                    }

                    if (RideColumns.TABLE_NAME.equals(table) && c.getColumnIndex(RideColumns.UUID) == -1) {
                        // The ride has no UUID column, but it became mandatory (not null constraint) in DB version 6.
                        // Add one now.
                        builder.withValue(RideColumns.UUID, UUID.randomUUID().toString());
                    }

                    operations.add(builder.build());
                    if (operations.size() >= 100) {
                        context.getContentResolver().applyBatch(BikeyProvider.AUTHORITY, operations);
                        operations.clear();
                    }

                } while (c.moveToNext());
                if (operations.size() > 0) context.getContentResolver().applyBatch(BikeyProvider.AUTHORITY, operations);

            }
        } finally {
            c.close();
        }
    }
}