Code example for ContentValues

Methods: clearputsize, withValues

0
     * @param name Name of contact 
     * @param nameType type of name: family name, given name, etc. 
     * @return instance of ContactOperations 
     */ 
    public ContactOperations addName(String firstName) {
        mValues.clear();
        if (!TextUtils.isEmpty(firstName)) {
            mValues.put(StructuredName.GIVEN_NAME, firstName);
            mValues.put(StructuredName.MIMETYPE,
                StructuredName.CONTENT_ITEM_TYPE);
        } 
        if (mValues.size() > 0) {
            addInsertOp(); 
        } 
        return this;
    } 
 
    /** 
     * Adds an email 
     *  
     * @param new email for user 
     * @return instance of ContactOperations 
     */ 
    public ContactOperations addEmail(String email) {
        mValues.clear();
        if (!TextUtils.isEmpty(email)) {
            mValues.put(Email.DATA, email);
            mValues.put(Email.TYPE, Email.TYPE_OTHER);
            mValues.put(Email.MIMETYPE, Email.CONTENT_ITEM_TYPE);
            addInsertOp(); 
        } 
        return this;
    } 
 
    /** 
     * Adds a phone number 
     *  
     * @param phone new phone number for the contact 
     * @param phoneType the type: cell, home, etc. 
     * @return instance of ContactOperations 
     */ 
    public ContactOperations addPhone(String phone, int phoneType) {
        mValues.clear();
        if (!TextUtils.isEmpty(phone)) {
            mValues.put(Phone.NUMBER, phone);
            mValues.put(Phone.TYPE, phoneType);
            mValues.put(Phone.MIMETYPE, Phone.CONTENT_ITEM_TYPE);
            addInsertOp(); 
        } 
        return this;
    } 
 
    /** 
     * Adds a profile action 
     *  
     * @param userId the userId of the sample SyncAdapter user object 
     * @return instance of ContactOperations 
     */ 
    public ContactOperations addProfileAction(String userName) {
        mValues.clear();
        if (userName != "") {
            mValues.put(ContactSyncAdapterColumns.DATA_PID, userName);
            mValues.put(ContactSyncAdapterColumns.DATA_SUMMARY, mContext
                .getString(R.string.profile_action));
            mValues.put(ContactSyncAdapterColumns.DATA_DETAIL, mContext
                .getString(R.string.view_profile));
            mValues.put(Data.MIMETYPE, ContactSyncAdapterColumns.MIME_PROFILE);
            addInsertOp(); 
            Log.d("addProfileAction", "Adding Profile for " + userName);
        } 
        return this;
    } 
 
    /** 
     * Updates contact's email 
     *  
     * @param email email id of the sample SyncAdapter user 
     * @param uri Uri for the existing raw contact to be updated 
     * @return instance of ContactOperations 
     */ 
    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;
    } 
 
    /** 
     * Updates contact's name 
     *  
     * @param name Name of contact 
     * @param existingName Name of contact stored in provider 
     * @param nameType type of name: family name, given name, etc. 
     * @param uri Uri for the existing raw contact to be updated 
     * @return instance of ContactOperations 
     */ 
    public ContactOperations updateName(Uri uri, String existingFirstName,
        String existingLastName, String firstName, String lastName) {
        Log.i("ContactOperations", "ef=" + existingFirstName + "el="
            + existingLastName + "f=" + firstName + "l=" + 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;
    } 
 
    /** 
     * Updates contact's phone 
     *  
     * @param existingNumber phone number stored in contacts provider 
     * @param phone new phone number for the contact 
     * @param uri Uri for the existing raw contact to be updated 
     * @return instance of ContactOperations 
     */ 
    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;
    } 
 
    /** 
     * Updates contact's profile action 
     *  
     * @param userId sample SyncAdapter user id 
     * @param uri Uri for the existing raw contact to be updated 
     * @return instance of ContactOperations 
     */ 
    public ContactOperations updateProfileAction(Integer userId, Uri uri) {
        mValues.clear();
        mValues.put(ContactSyncAdapterColumns.DATA_PID, userId);
        addUpdateOp(uri);
        return this;
    } 
 
    /** 
     * Adds an insert operation into the batch 
     */ 
    private void addInsertOp() { 
        if (!mIsNewContact) {
            mValues.put(Phone.RAW_CONTACT_ID, mRawContactId);
        } 
        mBuilder =
            newInsertCpo(addCallerIsSyncAdapterParameter(Data.CONTENT_URI),
                mYield);
        mBuilder.withValues(mValues);
        if (mIsNewContact) {
            mBuilder
                .withValueBackReference(Data.RAW_CONTACT_ID, mBackReference);
        } 
        mYield = false;
Contextual code suggestions in your IDE  Get Codota for Java