Example usage for android.content ContentValues ContentValues

List of usage examples for android.content ContentValues ContentValues

Introduction

In this page you can find the example usage for android.content ContentValues ContentValues.

Prototype

public ContentValues() 

Source Link

Document

Creates an empty set of values using the default initial size

Usage

From source file:com.nicolacimmino.expensestracker.tracker.data_sync.ExpenseDataSyncAdapter.java

public void fetchExpensesFromServer() {

    try {//w ww. j a v  a2s  .  c  o  m
        ExpensesApiGetExpensesRequest request = new ExpensesApiGetExpensesRequest();

        if (!request.performRequest()) {
            Log.e(TAG, "ExpensesApiGetExpensesRequest failed");
            return;
        }
        JSONArray jsonObject = request.getExpenses();

        getContext().getContentResolver().delete(ExpensesDataContentProvider.Contract.Expense.CONTENT_URI,
                ExpensesDataContentProvider.Contract.Expense.COLUMN_NAME_SYNC + "=1", null);

        for (int ix = 0; ix < jsonObject.length(); ix++) {
            Log.i(TAG, "Expense: " + jsonObject.getJSONObject(ix).get("amount"));

            ContentValues values = new ContentValues();
            values.put(ExpensesDataContentProvider.Contract.Expense.COLUMN_NAME_SYNC, "1");
            values.put(ExpensesDataContentProvider.Contract.Expense.COLUMN_NAME_CURRENCY, "eur");
            values.put(ExpensesDataContentProvider.Contract.Expense.COLUMN_NAME_AMOUNT,
                    jsonObject.getJSONObject(ix).getString("amount"));
            values.put(ExpensesDataContentProvider.Contract.Expense.COLUMN_NAME_DESCRIPTION,
                    jsonObject.getJSONObject(ix).getString("notes"));
            values.put(ExpensesDataContentProvider.Contract.Expense.COLUMN_NAME_SOURCE,
                    jsonObject.getJSONObject(ix).getString("source"));
            values.put(ExpensesDataContentProvider.Contract.Expense.COLUMN_NAME_DESTINATION,
                    jsonObject.getJSONObject(ix).getString("destination"));
            if (jsonObject.getJSONObject(ix).has("timestamp")) {
                values.put(ExpensesDataContentProvider.Contract.Expense.COLUMN_NAME_TIMESTAMP,
                        jsonObject.getJSONObject(ix).getString("timestamp"));
            } else {
                values.put(ExpensesDataContentProvider.Contract.Expense.COLUMN_NAME_TIMESTAMP,
                        "19750620 16:00:00");
            }

            getContext().getContentResolver().insert(ExpensesDataContentProvider.Contract.Expense.CONTENT_URI,
                    values);
        }
    } catch (JSONException e) {
        Log.e(TAG, "Invalid JSON: " + e.toString());
        return;
    } finally {
    }

}

From source file:com.manning.androidhacks.hack023.dao.TodoDAO.java

public void modifyTodoFromServer(ContentResolver contentResolver, Todo list) {
    ContentValues cv = new ContentValues();
    cv.put(TodoContentProvider.COLUMN_TITLE, list.getTitle());
    cv.put(TodoContentProvider.COLUMN_STATUS_FLAG, StatusFlag.CLEAN);

    contentResolver.update(TodoContentProvider.CONTENT_URI, cv,
            TodoContentProvider.COLUMN_SERVER_ID + "=" + list.getId(), null);

}

From source file:com.amazonaws.mobileconnectors.s3.transferutility.TransferDBUtil.java

/**
 * Writes transfer status including transfer state, current transferred
 * bytes and total bytes into database.//from  w  w w.  j a v a 2s .  com
 *
 * @param transfer a TransferRecord object
 * @return Number of rows updated.
 */
public int updateTransferRecord(TransferRecord transfer) {
    final ContentValues cv = new ContentValues();
    cv.put(TransferTable.COLUMN_ID, transfer.id);
    cv.put(TransferTable.COLUMN_STATE, transfer.state.toString());
    cv.put(TransferTable.COLUMN_BYTES_TOTAL, transfer.bytesTotal);
    cv.put(TransferTable.COLUMN_BYTES_CURRENT, transfer.bytesCurrent);
    return transferDBBase.update(getRecordUri(transfer.id), cv, null, null);
}

From source file:com.android.unit_tests.CheckinProviderTest.java

@MediumTest
public void testPropertiesRestricted() throws Exception {
    ContentResolver r = getContext().getContentResolver();

    // The test app doesn't have the permission to access properties,
    // so any attempt to do so should fail.
    try {/*  ww w  .  j  a  v a 2 s  . c o m*/
        r.insert(Checkin.Properties.CONTENT_URI, new ContentValues());
        fail("SecurityException expected");
    } catch (SecurityException e) {
        // expected
    }

    try {
        r.query(Checkin.Properties.CONTENT_URI, null, null, null, null);
        fail("SecurityException expected");
    } catch (SecurityException e) {
        // expected
    }
}

From source file:com.adamhurwitz.android.popularmovies.service.MovieDataService.java

public void putDataIntoDb(
        //String id,
        Integer movie_id, String title, String image_url, String summary, Double vote_average,
        Double popularity, String release_date) {

    // Access database
    //CursorDbHelper mDbHelper = new CursorDbHelper(context);

    // Put Info into Database

    // Gets the data repository in write mode
    //SQLiteDatabase db = mDbHelper.getWritableDatabase();

    // Create a new map of values, where column names are the keys
    ContentValues values = new ContentValues();
    values.put(CursorContract.MovieData.COLUMN_NAME_MOVIEID, movie_id);
    values.put(CursorContract.MovieData.COLUMN_NAME_TITLE, title);
    values.put(CursorContract.MovieData.COLUMN_NAME_IMAGEURL, image_url);
    values.put(CursorContract.MovieData.COLUMN_NAME_SUMMARY, summary);
    values.put(CursorContract.MovieData.COLUMN_NAME_VOTEAVERAGE, vote_average);
    values.put(CursorContract.MovieData.COLUMN_NAME_POPULARITY, popularity);
    values.put(CursorContract.MovieData.COLUMN_NAME_RELEASEDATE, release_date);
    values.put(CursorContract.MovieData.COLUMN_NAME_FAVORITE, "1");

    // Insert the new row, returning the primary key value of the new row
    long thisRowID;

    Cursor cursor = this.getContentResolver().query(CursorContract.MovieData.CONTENT_URI, null,
            CursorContract.MovieData.COLUMN_NAME_TITLE + "= ?", new String[] { title },
            CursorContract.MovieData.COLUMN_NAME_POPULARITY + " DESC");
    if (cursor.getCount() == 0) {
        Uri uri;//from   www. j a  va2 s  .c o  m
        uri = this.getContentResolver().insert(CursorContract.MovieData.CONTENT_URI, values);
    }
}

From source file:com.openerp.addons.messages.MessageSyncHelper.java

private void updateMessageVotes(JSONObject vote_detail, BaseDBHelper db) {
    try {//  w ww . j  a v  a 2  s.  c  o m
        for (int j = 0; j < vote_detail.getJSONArray("records").length(); j++) {
            JSONObject obj_vote = vote_detail.getJSONArray("records").getJSONObject(j);
            JSONArray voted_user_ids = obj_vote.getJSONArray("vote_user_ids");
            ContentValues values = new ContentValues();
            for (int i = 0; i < voted_user_ids.length(); i++) {
                if (voted_user_ids.getString(i).equals(mUser.getUser_id())) {
                    values.put("has_voted", "true");
                    break;
                } else {
                    values.put("has_voted", "false");
                }
            }
            int total_votes = voted_user_ids.length();
            int message_id = obj_vote.getInt("id");
            values.put("vote_nb", total_votes);
            db.write(db, values, message_id, true);
        }
    } catch (Exception e) {
    }
}

From source file:grytsenko.coworkers.web.Employee.java

/**
 * Obtains data about Skype name for {@link ContentResolver}.
 * //w  ww .jav a  2  s  . c om
 * @return the set of values.
 */
public ContentValues getSkype() {
    ContentValues values = new ContentValues();
    values.put(Im.DATA, skype);
    values.put(Im.PROTOCOL, Im.PROTOCOL_SKYPE);
    values.put(Im.TYPE, Im.TYPE_OTHER);
    return values;
}

From source file:com.example.premiereappandroid.BloaActivity.java

private ContentValues parseVerifyUserJSONObject(JSONObject object) throws Exception {
    ContentValues values = new ContentValues();
    values.put(UserStatusRecord.USER_NAME, object.getString("name"));
    values.put(UserStatusRecord.RECORD_ID, object.getInt("id_str"));
    values.put(UserStatusRecord.USER_CREATED_DATE, object.getString("created_at"));
    JSONObject status = object.getJSONObject("status");
    values.put(UserStatusRecord.USER_TEXT, status.getString("text"));
    return values;
}

From source file:at.florian_lentsch.expirysync.net.JsonCaller.java

private String jsonToGetParams(JSONObject params) throws UnsupportedEncodingException, JSONException {
    ContentValues getParams = new ContentValues();

    Iterator<?> keys = params.keys();
    while (keys.hasNext()) {
        Object key = keys.next();
        if (!(key instanceof String)) {
            throw new UnsupportedOperationException("Encountered non-string key when parsing http get");
        }//from  w w  w .ja  v a2 s.c  o  m
        Object value = params.get((String) key);
        if (value instanceof String) {
            getParams.put((String) key, (String) value);
        } else if (value instanceof Date) {
            SimpleDateFormat format = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z", Locale.US);
            getParams.put((String) key, format.format((Date) value));
        } else {
            throw new UnsupportedOperationException("Encountered unsupported value-type when parsing http get");
        }
    }

    return getQuery(getParams);
}

From source file:com.rukman.emde.smsgroups.platform.GMSContactOperations.java

/**
 * When we first add a sync adapter to the system, the contacts from that
 * sync adapter will be hidden unless they're merged/grouped with an existing
 * contact.  But typically we want to actually show those contacts, so we
 * need to mess with the Settings table to get them to show up.
 *
 * @param context the Authenticator Activity context
 * @param account the Account who's visibility we're changing
 * @param visible true if we want the contacts visible, false for hidden
 *//*from  w  w  w .j a v  a2 s .  c o m*/
public static void setAccountContactsVisibility(Context context, Account account, boolean visible) {
    ContentValues values = new ContentValues();
    values.put(RawContacts.ACCOUNT_NAME, account.name);
    values.put(RawContacts.ACCOUNT_TYPE, GMSApplication.ACCOUNT_TYPE);
    values.put(Settings.UNGROUPED_VISIBLE, visible ? 1 : 0);
    context.getContentResolver().insert(Settings.CONTENT_URI, values);
}