Code example for ContentValues

Methods: clearput, withValues

0
	public ContactOperations addAvatar(String avatarUrl) {
		if (avatarUrl != null) {
			byte[] avatarBuffer = NetworkUtilities.downloadAvatar(avatarUrl);
			if (avatarBuffer != null) {
				Log.e("DownloadPhoto", "image downloaded; addinf");
				mValues.clear();
				mValues.put(Photo.DATA1, avatarUrl);
				mValues.put(Photo.PHOTO, avatarBuffer);
				mValues.put(Photo.MIMETYPE, Photo.CONTENT_ITEM_TYPE);
				addInsertOp(); 
			} else { 
				Log.e("DownloadPhoto", "failed, buffer null");
			} 
		} 
		return this;
	} 
	 
	public ContactOperations addProfileAction(String userId) {
		mValues.clear();
		if (userId != null) {
			mValues.put(SyncAdapterColumns.DATA_PID, userId);
			mValues.put(SyncAdapterColumns.DATA_SUMMARY, mContext.getString(R.string.profile_action));
			mValues.put(SyncAdapterColumns.DATA_DETAIL, mContext.getString(R.string.view_profile));
			mValues.put(Data.MIMETYPE, SyncAdapterColumns.MIME_PROFILE);
			addInsertOp(); 
		} 
		return this;
	} 
	 
	public ContactOperations updateServerId(String serverId, Uri uri) {
		mValues.clear();
		mValues.put(RawContacts.SOURCE_ID, serverId);
		addUpdateOp(uri);
		return this;
	} 
	 
	public ContactOperations updateEmail(String email, String existingEmail,
			Uri uri) {
		if (!TextUtils.equals(existingEmail, email)) {
			mValues.clear();
			mValues.put(Email.DATA, email);
			addUpdateOp(uri);
		} 
		return this;
	} 
	 
	public ContactOperations updateBirthday(String birthday, String existingBirthday,
			Uri uri) {
		if (!TextUtils.equals(existingBirthday, birthday)) {
			mValues.clear();
			mValues.put(Event.START_DATE, birthday);
			addUpdateOp(uri);
		} 
		return this;
	} 
	 
	public ContactOperations updateName(Uri uri, String existingFirstName,
			String existingLastName, String firstName, String lastName) {
		 
		mValues.clear();
		if (!TextUtils.equals(existingFirstName, firstName)) {
			mValues.put(StructuredName.GIVEN_NAME, firstName);
		} 
		if (!TextUtils.equals(existingLastName, lastName)) {
			mValues.put(StructuredName.FAMILY_NAME, lastName);
		} 
		if (mValues.size() > 0) {
			addUpdateOp(uri);
		} 
		return this;
	} 
	 
	public ContactOperations updateDirtyFlag(boolean isDirty, Uri uri) {
		int isDirtyValue = isDirty ? 1 : 0;
		mValues.clear();
		mValues.put(RawContacts.DIRTY, isDirtyValue);
		addUpdateOp(uri);
		return this;
	} 
	 
	public ContactOperations updateSyncTimestamp(long checkTimestamp, long photoTimestamp, Uri uri) {
		mValues.clear();
		mValues.put(RawContacts.SYNC1, checkTimestamp);
		mValues.put(RawContacts.SYNC2, photoTimestamp);
		addUpdateOp(uri);
		return this;
	} 
	 
	public ContactOperations updatePhone(String existingNumber, String phone, Uri uri) {
		if (!TextUtils.equals(phone, existingNumber)) {
			mValues.clear();
			mValues.put(Phone.NUMBER, phone);
			addUpdateOp(uri);
		} 
		return this;
	} 
	 
	public ContactOperations updateAvatar(String existingAvatarUrl, String avatarUrl, Uri uri) {
		if (avatarUrl != null && !TextUtils.equals(existingAvatarUrl, avatarUrl)) {
			byte[] avatarBuffer = NetworkUtilities.downloadAvatar(avatarUrl);
			if (avatarBuffer != null) {
				Log.e("DownloadPhoto", "image downloaded; updating");
				mValues.clear();
				mValues.put(Photo.DATA1, avatarUrl);
				mValues.put(Photo.PHOTO, avatarBuffer);
				mValues.put(Photo.MIMETYPE, Photo.CONTENT_ITEM_TYPE);
				addUpdateOp(uri);
			} else { 
				Log.e("DownloadPhoto", "failed, buffer null");
			} 
		} else { 
			Log.e("DownloadPhoto", "not doing it");
		} 
		return this;
	} 
	 
	public ContactOperations updateProfileAction(Integer userId, Uri uri) {
		mValues.clear();
		mValues.put(SyncAdapterColumns.DATA_PID, userId);
		addUpdateOp(uri);
		return this;
	} 
	 
	private void addInsertOp() { 
		if (!mIsNewContact) {
			mValues.put(Phone.RAW_CONTACT_ID, mRawContactId);
		} 
		ContentProviderOperation.Builder builder = newInsertCpo(
				Data.CONTENT_URI, mIsSyncOperation, mIsYieldAllowed);
		builder.withValues(mValues);
		if (mIsNewContact) {
			builder.withValueBackReference(Data.RAW_CONTACT_ID, mBackReference);
		} 
		mIsYieldAllowed = false;
		mBatchOperation.add(builder.build());