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:edu.nd.darts.cimon.database.CimonDatabaseAdapter.java

/**
 * Insert new reading into Data table.//from w w  w. java2 s .c o m
 * 
 * @param metric       id of metric
 * @param monitor      id of monitor
 * @param timestamp    timestamp measured from uptime (milliseconds)
 * @param value        value of reading
 * @return    rowid of inserted row, -1 on failure
 * 
 * @see DataTable
 */
public synchronized long insertData(int metric, int monitor, long timestamp, float value) {
    if (DebugLog.DEBUG)
        Log.d(TAG, "CimonDatabaseAdapter.insertData - insert into Data table: metric-" + metric);
    ContentValues values = new ContentValues();
    values.put(DataTable.COLUMN_METRIC_ID, metric);
    values.put(DataTable.COLUMN_MONITOR_ID, monitor);
    values.put(DataTable.COLUMN_TIMESTAMP, timestamp);
    values.put(DataTable.COLUMN_VALUE, value);

    long rowid = database.insert(DataTable.TABLE_DATA, null, values);
    if (rowid >= 0) {
        Uri uri = Uri.withAppendedPath(CimonContentProvider.DATA_URI, String.valueOf(rowid));
        context.getContentResolver().notifyChange(uri, null);
    }

    return rowid;
}

From source file:com.markupartist.sthlmtraveling.FavoritesFragment.java

private void updateListPosition(long id, boolean increase) {
    Uri uri = ContentUris.withAppendedId(Journeys.CONTENT_URI, id);

    Cursor cursor = getActivity().managedQuery(uri, PROJECTION, null, null, null);
    cursor.moveToFirst();/*  w w  w .  java  2  s. c  o  m*/

    int position = cursor.getInt(COLUMN_INDEX_POSITION);
    if (increase) {
        position = position + 1;
    } else {
        position = position - 1;
    }

    ContentValues values = new ContentValues();
    values.put(Journeys.POSITION, position);
    getActivity().getContentResolver().update(uri, values, null, null);
}

From source file:com.stockita.popularmovie.utility.Utilities.java

/**
 * Parse trailer link and insert them into TrailerEntry table.
 *///www  .j a v a  2 s .  c om
public static void parseAndInsertTrailer(Context context, String jsonData, String movieId)
        throws JSONException {

    // Timestamp.
    final long currentTime = System.currentTimeMillis();

    // String to the root of JSONObject, the argument s is a String in JSON format.
    JSONObject rootObject = new JSONObject(jsonData);

    // call the rootObjet and get the key assign to String variable
    String rootObj = rootObject.get("results").toString();

    // Containers
    ContentValues lContentValuesTrailer = new ContentValues();

    // now the rootObj has the value of "result" which is a JSON Array
    // then assign it as argument into JSONArray object
    JSONArray ar = new JSONArray(rootObj);
    final int arSize = ar.length();

    // iterate for each element in the JSONArray
    for (int i = 0; i < arSize; i++) {
        // convert each element in ar into JSONOject
        // and pass the argument i which i is the index of each element
        JSONObject obj = ar.getJSONObject(i);

        // Packing to ContentValues object
        lContentValuesTrailer.put(ContractMovies.TrailerEntry.COLUMN_MOVIE_ID, movieId);
        lContentValuesTrailer.put(ContractMovies.TrailerEntry.COLUMN_TRAILER, obj.getString("key"));
        lContentValuesTrailer.put(ContractMovies.TrailerEntry.COLUMN_POSTING_TIME, currentTime);

        try {
            context.getContentResolver().insert(ContractMovies.TrailerEntry.CONTENT_URI, lContentValuesTrailer);
        } catch (Exception e) {
            Log.e(LOG_TAG, e.toString());
        }
    }
}

From source file:com.stockita.popularmovie.utility.Utilities.java

/**
 * Parse reviews link and insert them into ReviewEntry table.
 *
 *//*from   w  w  w . j av a  2s.  c  o m*/
public static void parseAndInsertReview(Context context, String jsonData, String id) throws JSONException {

    // Timestamp.
    final long currentTime = System.currentTimeMillis();

    // String to the root of JSONObject, the argument s is a String in JSON format.
    JSONObject rootObject = new JSONObject(jsonData);

    // call the rootObjet and get the key assign to String variable
    String rootObj = rootObject.get("results").toString();

    // Containers
    ContentValues lContentValueReview = new ContentValues();

    // now the rootObj has the value of "result" which is a JSON Array
    // then assign it as argument into JSONArray object
    JSONArray ar = new JSONArray(rootObj);
    final int arSize = ar.length();

    // iterate for each element in the JSONArray
    for (int i = 0; i < arSize; i++) {
        // convert each element in ar into JSONOject
        // and pass the argument i which i is the index of each element
        JSONObject obj = ar.getJSONObject(i);

        // Packing into ContentValues object
        lContentValueReview.put(ContractMovies.ReviewEntry.COLUMN_MOVIE_ID, String.valueOf(id));
        lContentValueReview.put(ContractMovies.ReviewEntry.COLUMN_USER_NAME, obj.getString("author"));
        lContentValueReview.put(ContractMovies.ReviewEntry.COLUMN_USER_COMMENT, obj.getString("content"));
        lContentValueReview.put(ContractMovies.ReviewEntry.COLUMN_POSTING_TIME, currentTime);

        try {
            context.getContentResolver().insert(ContractMovies.ReviewEntry.CONTENT_URI, lContentValueReview);
        } catch (Exception e) {
            Log.e(LOG_TAG, e.toString());
        }
    }
}

From source file:com.tcm.sunshine.app.FetchWeatherTask.java

/**
 * Helper method to handle insertion of a new location in the weather database.
 *
 * @param locationSetting The location string used to request updates from the server.
 * @param cityName A human-readable city name, e.g "Mountain View"
 * @param lat the latitude of the city/*w w w .ja  v a 2s.  c  o  m*/
 * @param lon the longitude of the city
 * @return the row ID of the added location.
 */
long addLocation(String locationSetting, String cityName, double lat, double lon) {
    // Students: First, check if the location with this city name exists in the db
    // If it exists, return the current ID
    // Otherwise, insert it using the content resolver and the base URI

    ContentResolver contentResolver = mContext.getContentResolver();
    Cursor cursor = contentResolver.query(LocationEntry.CONTENT_URI, new String[] { LocationEntry._ID },
            LocationEntry.COLUMN_CITY_NAME + " = ?", new String[] { cityName }, null);
    try {
        if (cursor.moveToFirst()) {
            return cursor.getInt(cursor.getColumnIndex(LocationEntry._ID));
        }
    } finally {
        cursor.close();
    }

    ContentValues contentValues = new ContentValues();
    contentValues.put(LocationEntry.COLUMN_LOCATION_SETTING, locationSetting);
    contentValues.put(LocationEntry.COLUMN_CITY_NAME, cityName);
    contentValues.put(LocationEntry.COLUMN_COORD_LAT, lat);
    contentValues.put(LocationEntry.COLUMN_COORD_LONG, lon);
    Uri insertUri = contentResolver.insert(LocationEntry.CONTENT_URI, contentValues);

    return ContentUris.parseId(insertUri);
}

From source file:de.lebenshilfe_muenster.uk_gebaerden_muensterland.database.SignDAO.java

public Sign update(Sign sign) {
    Log.d(TAG, "Updating sign: " + sign);
    this.database.beginTransaction();
    Sign updatedSign = null;/*from  www .  ja v  a  2 s .c o m*/
    try {
        final ContentValues values = new ContentValues();
        values.put(DbContract.SignTable.COLUMN_NAME_LEARNING_PROGRESS, sign.getLearningProgress());
        values.put(DbContract.SignTable.COLUMN_NAME_STARRED, sign.isStarred());
        final String selection = DbContract.SignTable._ID + DbContract.LIKE;
        final String[] selectionArgs = { String.valueOf(sign.getId()) };
        int rowsUpdated = this.database.update(DbContract.SignTable.TABLE_NAME, values, selection,
                selectionArgs);
        if (0 == rowsUpdated) {
            throw new IllegalStateException(MessageFormat.format("Updating sign {0} updated no rows!", sign));
        }
        if (1 > rowsUpdated) {
            throw new IllegalStateException(MessageFormat.format(
                    "Updating sign {0} updated more than " + "one row. {1} rows were updated.", sign,
                    rowsUpdated));
        }
        updatedSign = readSingleSign(sign.getId());
        this.database.setTransactionSuccessful();
    } finally {
        this.database.endTransaction();
    }
    return updatedSign;
}

From source file:com.example.riteden.sunshine.app.FetchWeatherTask.java

/**
 * Helper method to handle insertion of a new location in the weather database.
 *
 * @param locationSetting The location string used to request updates from the server.
 * @param cityName A human-readable city name, e.g "Mountain View"
 * @param lat the latitude of the city//from w  w w . j  a  v a2s .c o m
 * @param lon the longitude of the city
 * @return the row ID of the added location.
 */
long addLocation(String locationSetting, String cityName, double lat, double lon) {
    // Students: First, check if the location with this city name exists in the db
    //WeatherProvider.query()
    Cursor cur = mContext.getContentResolver().query(WeatherContract.LocationEntry.CONTENT_URI,
            new String[] { WeatherContract.LocationEntry._ID },
            WeatherContract.LocationEntry.COLUMN_LOCATION_SETTING + " = ?", new String[] { locationSetting },
            null);
    if (cur.moveToFirst()) {
        return cur.getLong(cur.getColumnIndex(WeatherContract.LocationEntry._ID));
    }

    ContentValues values = new ContentValues();
    values.put(WeatherContract.LocationEntry.COLUMN_LOCATION_SETTING, locationSetting);
    values.put(WeatherContract.LocationEntry.COLUMN_CITY_NAME, cityName);
    values.put(WeatherContract.LocationEntry.COLUMN_COORD_LAT, lat);
    values.put(WeatherContract.LocationEntry.COLUMN_COORD_LONG, lon);
    Uri return_rowID = mContext.getContentResolver().insert(WeatherContract.LocationEntry.CONTENT_URI, values);
    // If it exists, return the current ID
    // Otherwise, insert it using the content resolver and the base URI
    return ContentUris.parseId(return_rowID);
}

From source file:me.vancexu.sunshine.FetchWeatherTask.java

/**
 * Helper method to handle insertion of a new location in the weather database.
 *
 * @param locationSetting The location string used to request updates from the server.
 * @param cityName A human-readable city name, e.g "Mountain View"
 * @param lat the latitude of the city//  w  ww . ja v a 2s .  c  om
 * @param lon the longitude of the city
 * @return the row ID of the added location.
 */
private long addLocation(String locationSetting, String cityName, double lat, double lon) {

    long rowId;

    Log.v(LOG_TAG, "inserting " + cityName + ", with coord: " + lat + ", " + lon);

    // First, check if the location with this city name exists in the db
    Cursor cursor = mContext.getContentResolver().query(LocationEntry.CONTENT_URI,
            new String[] { LocationEntry._ID }, LocationEntry.COLUMN_LOCATION_SETTING + " = ?",
            new String[] { locationSetting }, null);

    if (cursor.moveToFirst()) {
        Log.v(LOG_TAG, "Found it in the database!");
        int locationIdIndex = cursor.getColumnIndex(LocationEntry._ID);
        rowId = cursor.getLong(locationIdIndex);
        cursor.close();
        return rowId;
    } else {
        Log.v(LOG_TAG, "Didn't find it in the database, inserting now!");
        cursor.close();
        ContentValues locationValues = new ContentValues();
        locationValues.put(LocationEntry.COLUMN_LOCATION_SETTING, locationSetting);
        locationValues.put(LocationEntry.COLUMN_CITY_NAME, cityName);
        locationValues.put(LocationEntry.COLUMN_COORD_LAT, lat);
        locationValues.put(LocationEntry.COLUMN_COORD_LONG, lon);

        Uri locationInsertUri = mContext.getContentResolver().insert(LocationEntry.CONTENT_URI, locationValues);

        return ContentUris.parseId(locationInsertUri);
    }

}

From source file:name.zurell.kirk.apps.android.rhetolog.RhetologApplication.java

public Uri insertEventByParticipantInSession(String fallacyName, int participant, Uri session, long timestamp) {

    ContentValues values = new ContentValues();
    values.put(RhetologContract.EventsColumns.FALLACY, fallacyName);
    values.put(RhetologContract.EventsColumns.PARTICIPANT, participant);
    values.put(RhetologContract.EventsColumns.TIMESTAMP, timestamp);

    Uri newEvent = getContentResolver().insert(session, values);
    return newEvent;
}

From source file:name.zurell.kirk.apps.android.rhetolog.RhetologApplication.java

@Override
public void onSessionRename(Context context, Uri session, String newName) {
    ContentResolver cr = getContentResolver();

    ContentValues values = new ContentValues();
    values.put(RhetologContract.SessionsColumns.TITLE, newName);

    cr.update(session, values, null, null);

}