Example usage for android.content ContentValues put

List of usage examples for android.content ContentValues put

Introduction

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

Prototype

public void put(String key, byte[] value) 

Source Link

Document

Adds a value to the set.

Usage

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

/**
 * Obtains data about position for {@link ContentResolver}.
 * /*from  w  w  w  .  j  a  v  a 2 s  .c  o  m*/
 * @return the set of values.
 */
public ContentValues getPosition() {
    ContentValues values = new ContentValues();
    values.put(Organization.TITLE, position);
    values.put(Organization.TYPE, Organization.TYPE_WORK);
    return values;
}

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

/**
 * Obtains data about email address for {@link ContentResolver}.
 * //w w  w .  j  a v  a2 s. c  o m
 * @return the set of values.
 */
public ContentValues getEmail() {
    ContentValues values = new ContentValues();
    values.put(Email.DATA, email);
    values.put(Email.TYPE, Email.TYPE_WORK);
    return values;
}

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

/**
 * Obtains data about mobile phone number for {@link ContentResolver}.
 * /*from   w w w .  j  a v a  2  s  .c om*/
 * @return the set of values.
 */
public ContentValues getMobile() {
    ContentValues values = new ContentValues();
    values.put(Phone.NUMBER, mobile);
    values.put(Phone.TYPE, Phone.TYPE_MOBILE);
    return values;
}

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

/**
 * Obtains data about Skype name for {@link ContentResolver}.
 * //from ww w.j av a2  s .  co  m
 * @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.liferay.alerts.database.DatabaseHelper.java

private void _convertMessageToJSONObject(SQLiteDatabase database) {
    StringBuilder select = new StringBuilder();

    select.append("SELECT ");
    select.append(Alert.ID);/*from  w  ww.  j a  v a 2  s .  c  om*/
    select.append(", ");
    select.append(Alert.PAYLOAD);
    select.append(" FROM ");
    select.append(AlertDAO.TABLE_NAME);

    Cursor cursor = database.rawQuery(select.toString(), null);

    while (cursor.moveToNext()) {
        try {
            long id = cursor.getLong(cursor.getColumnIndex(Alert.ID));
            String payload = cursor.getString(cursor.getColumnIndex(Alert.PAYLOAD));

            JSONObject jsonObject = new JSONObject();
            jsonObject.put(Alert.MESSAGE, payload);

            ContentValues values = new ContentValues();
            values.put(Alert.PAYLOAD, jsonObject.toString());

            StringBuilder sb = new StringBuilder();

            sb.append(Alert.ID);
            sb.append(CharPool.SPACE);
            sb.append("= ?");

            String whereClause = sb.toString();

            String[] whereArgs = { String.valueOf(id) };

            database.update(AlertDAO.TABLE_NAME, values, whereClause, whereArgs);
        } catch (JSONException je) {
            Log.e(_TAG, "Couldn't convert message.", je);
        }
    }
}

From source file:com.google.android.apps.iosched.ui.VendorDetailActivity.java

/** Handle toggling of starred checkbox. */
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
    final ContentValues values = new ContentValues();
    values.put(Vendors.STARRED, isChecked ? 1 : 0);
    mHandler.startUpdate(mVendorUri, values);
}

From source file:com.getmarco.weatherstationviewer.gcm.StationGcmListenerService.java

/**
 * Helper method to handle insertion of a station in the database if it doesn't already exist.
 *
 * @param stationTag the station//from  w w  w  . j  ava  2s  .  co m
 * @return the row ID of the station (new or existing)
 */
long addStation(String stationTag) {
    long stationId;

    // First, check if a station with this tag exists in the db
    Cursor stationCursor = getContentResolver().query(StationContract.StationEntry.CONTENT_URI,
            new String[] { StationContract.StationEntry._ID }, StationContract.StationEntry.COLUMN_TAG + " = ?",
            new String[] { stationTag }, null);

    if (stationCursor.moveToFirst()) {
        int stationIdIndex = stationCursor.getColumnIndex(StationContract.StationEntry._ID);
        stationId = stationCursor.getLong(stationIdIndex);
    } else {
        ContentValues locationValues = new ContentValues();
        locationValues.put(StationContract.StationEntry.COLUMN_TAG, stationTag);
        locationValues.put(StationContract.StationEntry.COLUMN_NAME, stationTag);
        locationValues.put(StationContract.StationEntry.COLUMN_TEMP_HIGH, 0.0);
        locationValues.put(StationContract.StationEntry.COLUMN_TEMP_LOW, 0.0);
        locationValues.put(StationContract.StationEntry.COLUMN_HUMIDITY_HIGH, 0.0);
        locationValues.put(StationContract.StationEntry.COLUMN_HUMIDITY_LOW, 0.0);

        // Finally, insert location data into the database.
        Uri insertedUri = getContentResolver().insert(StationContract.StationEntry.CONTENT_URI, locationValues);

        // The resulting URI contains the ID for the row.  Extract the stationId from the Uri.
        stationId = ContentUris.parseId(insertedUri);
    }

    stationCursor.close();
    return stationId;
}

From source file:com.liferay.alerts.model.Alert.java

public ContentValues toContentValues() {
    ContentValues values = new ContentValues();

    values.put(USER_ID, _userId);
    values.put(PAYLOAD, _payload.toString());
    values.put(READ, (_read ? 1 : 0));// www  . ja  v  a 2s  .  co  m
    values.put(TIMESTAMP, _timestamp);

    return values;
}

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

public void putDataIntoDb(String[] reviews, String title) {

    // Create a new map of values, where column names are the keys
    ContentValues values = new ContentValues();

    if (reviews.length == 1) {
        values.put(CursorContract.MovieData.COLUMN_NAME_REVIEW_1, reviews[0]);
    } else if (reviews.length == 2) {
        values.put(CursorContract.MovieData.COLUMN_NAME_REVIEW_1, reviews[0]);
        values.put(CursorContract.MovieData.COLUMN_NAME_REVIEW_2, reviews[1]);
    } else if (reviews.length == 3) {
        values.put(CursorContract.MovieData.COLUMN_NAME_REVIEW_1, reviews[0]);
        values.put(CursorContract.MovieData.COLUMN_NAME_REVIEW_2, reviews[1]);
        values.put(CursorContract.MovieData.COLUMN_NAME_REVIEW_3, reviews[2]);
    } else if (reviews.length > 3) {
        values.put(CursorContract.MovieData.COLUMN_NAME_REVIEW_1, reviews[0]);
        values.put(CursorContract.MovieData.COLUMN_NAME_REVIEW_2, reviews[1]);
        values.put(CursorContract.MovieData.COLUMN_NAME_REVIEW_3, reviews[2]);
    }//from   w ww  .j av  a2  s .  com

    mRowsUpdated = this.getContentResolver().update(CursorContract.MovieData.CONTENT_URI, values,
            CursorContract.MovieData.COLUMN_NAME_TITLE + "= ?", new String[] { title });
}

From source file:android.database.DatabaseUtils.java

/**
 * Reads a Integer out of a field in a Cursor and writes it to a Map.
 *
 * @param cursor The cursor to read from
 * @param field The INTEGER field to read
 * @param values The {@link ContentValues} to put the value into, with the field as the key
 * @param key The key to store the value with in the map
 *///from   www  . jav a2s. co  m
public static void cursorIntToContentValues(Cursor cursor, String field, ContentValues values, String key) {
    int colIndex = cursor.getColumnIndex(field);
    if (!cursor.isNull(colIndex)) {
        values.put(key, cursor.getInt(colIndex));
    } else {
        values.put(key, (Integer) null);
    }
}