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:de.lebenshilfe_muenster.uk_gebaerden_muensterland.database.SignDAO.java

/**
 * Persist a sign. For <strong>testing</strong> purposes only.
 *
 * @param sign a Sign, which has not been persisted yet.
 * @return the persisted sign, <code>null</code> if persisting failed.
 *///w  w w .  j  a  v a 2s.  c  o  m
public Sign create(Sign sign) {
    Log.d(TAG, "Creating sign: " + sign);
    this.database.beginTransaction();
    Sign createdSign = null;
    try {
        final ContentValues values = new ContentValues();
        values.put(DbContract.SignTable.COLUMN_NAME_SIGN_NAME, sign.getName());
        values.put(DbContract.SignTable.COLUMN_NAME_SIGN_NAME_DE, sign.getNameLocaleDe());
        values.put(DbContract.SignTable.COLUMN_NAME_MNEMONIC, sign.getMnemonic());
        if (sign.isStarred()) {
            values.put(DbContract.SignTable.COLUMN_NAME_STARRED, 1);
        } else {
            values.put(DbContract.SignTable.COLUMN_NAME_STARRED, 0);
        }
        values.put(DbContract.SignTable.COLUMN_NAME_LEARNING_PROGRESS, sign.getLearningProgress());
        final long insertId = this.database.insert(DbContract.SignTable.TABLE_NAME, null, values);
        if (-1 == insertId) {
            throw new IllegalStateException(
                    MessageFormat.format("Inserting sign: {0} failed due to" + " a database error!", sign));
        }
        createdSign = readSingleSign(insertId);
        this.database.setTransactionSuccessful();
        Log.d(TAG, "Created sign: " + createdSign);
    } finally {
        this.database.endTransaction();
    }
    return createdSign;
}

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

public Uri insertSession(String newTitle) {

    ContentValues values = new ContentValues();
    values.put(RhetologContract.SessionsColumns.TITLE, newTitle);
    values.put(RhetologContract.SessionsColumns.UUID, UUID.randomUUID().toString());

    Uri newSession = null;/*w w  w . j av a2 s. c  o m*/

    newSession = getContentResolver().insert(RhetologContract.SESSIONS_URI, values);

    return newSession;
}

From source file:com.girnarsoft.android.shunshine.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 ww .  j  ava2 s . co  m*/
 * @param lon the longitude of the city
 * @return the row ID of the added location.
 */
public long addLocation(String locationSetting, String cityName, double lat, double lon) {

    Cursor cursor = mContext.getContentResolver().query(WeatherContract.LocationEntry.CONTENT_URI, null,
            WeatherContract.LocationEntry.COLUMN_LOCATION_SETTING + "=?", new String[] { locationSetting },
            null);

    long location = 0;

    if (cursor.getCount() > 0) {
        cursor.moveToFirst();
        location = cursor.getLong(cursor.getColumnIndex(WeatherContract.LocationEntry._ID));
    } else {
        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 uri = mContext.getContentResolver().insert(WeatherContract.LocationEntry.CONTENT_URI, values);

        location = ContentUris.parseId(uri);
    }

    return location;
}

From source file:com.msrproduction.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 ww  w .  j av a2  s . 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) {
    long locationId;

    Cursor locationCursor = mContext.getContentResolver().query(WeatherContract.LocationEntry.CONTENT_URI,
            new String[] { WeatherContract.LocationEntry._ID },
            WeatherContract.LocationEntry.COLUMN_LOCATION_SETTING + " = ?", new String[] { locationSetting },
            null);
    if (locationCursor.moveToNext()) {
        int locationIdIndex = locationCursor.getColumnIndex(WeatherContract.LocationEntry._ID);
        locationId = locationCursor.getLong(locationIdIndex);
    } else {
        ContentValues locationValues = new ContentValues();

        locationValues.put(WeatherContract.LocationEntry.COLUMN_CITY_NAME, cityName);
        locationValues.put(WeatherContract.LocationEntry.COLUMN_LOCATION_SETTING, locationSetting);
        locationValues.put(WeatherContract.LocationEntry.COLUMN_COORD_LAT, lat);
        locationValues.put(WeatherContract.LocationEntry.COLUMN_COORD_LONG, lon);

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

        locationId = ContentUris.parseId(insertedUri);
    }
    locationCursor.close();
    return locationId;
}

From source file:org.blanco.techmun.android.MensajesActivity.java

private void sendMensaje() {
    Toast.makeText(getBaseContext(), getString(R.string.mensaje_sending), Toast.LENGTH_SHORT).show();
    ContentValues values = new ContentValues();
    values.put("nombre", "alex");
    values.put("mensaje", edtMensaje.getText().toString());
    if (attachImage != null) {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        attachImage.compress(CompressFormat.PNG, 50, baos);
        values.put("foto", baos.toByteArray());
        values.put("foto-format", "png");
    }/*from w w w.j  a v  a2 s.c  o m*/
    MensajeSender sender = new MensajeSender();
    sender.execute(values);
    animate();
}

From source file:com.prashantpal.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 a2 s. 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
    long locationId;
    ContentResolver resolver = mContext.getContentResolver();
    Cursor cursor = resolver.query(WeatherContract.LocationEntry.CONTENT_URI,
            new String[] { WeatherContract.LocationEntry._ID },
            WeatherContract.LocationEntry.COLUMN_LOCATION_SETTING + "= ?", new String[] { locationSetting },
            null);
    if (cursor.moveToFirst()) {
        int locationIdIndex = cursor.getColumnIndex(WeatherContract.LocationEntry._ID);
        locationId = cursor.getLong(locationIdIndex);
    } else {
        ContentValues contentValues = new ContentValues();
        contentValues.put(WeatherContract.LocationEntry.COLUMN_CITY_NAME, cityName);
        contentValues.put(WeatherContract.LocationEntry.COLUMN_COORD_LAT, lat);
        contentValues.put(WeatherContract.LocationEntry.COLUMN_COORD_LONG, lon);
        contentValues.put(WeatherContract.LocationEntry.COLUMN_LOCATION_SETTING, locationSetting);
        Uri uri = resolver.insert(WeatherContract.LocationEntry.CONTENT_URI, contentValues);
        locationId = ContentUris.parseId(uri);
    }
    cursor.close();
    // Otherwise, insert it using the content resolver and the base URI
    return locationId;
}

From source file:emroxriprap.com.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  ww  w .  java  2 s .  co m
 * @param lon the longitude of the city
 * @return the row ID of the added location.
 */
public long addLocation(String locationSetting, String cityName, double lat, double lon) {
    long locationId;
    //check to see if this location already exists
    Cursor locationCursor = mContext.getContentResolver().query(WeatherContract.LocationEntry.CONTENT_URI,
            new String[] { WeatherContract.LocationEntry._ID },
            WeatherContract.LocationEntry.COLUMN_LOCATION_SETTING + " = ?", new String[] { locationSetting },
            null);
    if (locationCursor.moveToFirst()) {
        int locationIndex = locationCursor.getColumnIndex(WeatherContract.LocationEntry._ID);
        locationId = locationCursor.getLong(locationIndex);
    } else {
        ContentValues locationValues = new ContentValues();
        locationValues.put(WeatherContract.LocationEntry.COLUMN_CITY_NAME, cityName);
        locationValues.put(WeatherContract.LocationEntry.COLUMN_LOCATION_SETTING, locationSetting);
        locationValues.put(WeatherContract.LocationEntry.COLUMN_COORD_LAT, lat);
        locationValues.put(WeatherContract.LocationEntry.COLUMN_COORD_LONG, lon);

        Uri insertedUri = mContext.getContentResolver().insert(WeatherContract.LocationEntry.CONTENT_URI,
                locationValues);
        locationId = ContentUris.parseId(insertedUri);
    }
    locationCursor.close();
    return locationId;
}

From source file:edu.nd.darts.cimon.database.CimonDatabaseAdapter.java

/**
 * Insert new metric group into MetricInfo table, or replace if the id already exist.
 * //w ww  .j av a2 s  .  co m
 * @param id             id which identifies metric group to insert
 * @param title          name of metric group
 * @param description    short description of metric
 * @param supported      metric support status on system [1-supported/0-not supported]
 * @param power          power used to monitor this metric (milliAmps)
 * @param mininterval    minimum possible interval between readings (milliseconds)
 * @param maxrange       maximum range measurable by metric, including units
 * @param resolution     resolution of measurements, including units
 * @param type           value representing metric type [system/sensor/user]
 * @return    rowid of inserted row, -1 on failure
 * 
 * @see MetricInfoTable
 */
public synchronized long insertOrReplaceMetricInfo(int id, String title, String description, int supported,
        float power, int mininterval, String maxrange, String resolution, int type) {
    if (DebugLog.DEBUG)
        Log.d(TAG, "CimonDatabaseAdapter.insertOrReplaceMetricInfo - insert into MetricInfo table: metric-"
                + title);
    ContentValues values = new ContentValues();
    values.put(MetricInfoTable.COLUMN_ID, id);
    values.put(MetricInfoTable.COLUMN_TITLE, title);
    values.put(MetricInfoTable.COLUMN_DESCRIPTION, description);
    values.put(MetricInfoTable.COLUMN_SUPPORTED, supported);
    values.put(MetricInfoTable.COLUMN_POWER, power);
    values.put(MetricInfoTable.COLUMN_MININTERVAL, mininterval);
    values.put(MetricInfoTable.COLUMN_MAXRANGE, maxrange);
    values.put(MetricInfoTable.COLUMN_RESOLUTION, resolution);
    values.put(MetricInfoTable.COLUMN_TYPE, type);
    //      SQLiteDatabase sqlDB = database.getWritableDatabase();
    long rowid = database.replace(MetricInfoTable.TABLE_METRICINFO, null, values);
    if (rowid >= 0) {
        Uri uri = Uri.withAppendedPath(CimonContentProvider.INFO_URI, String.valueOf(id));
        context.getContentResolver().notifyChange(uri, null);
        uri = Uri.withAppendedPath(CimonContentProvider.CATEGORY_URI, String.valueOf(type));
        context.getContentResolver().notifyChange(uri, null);
    }
    return rowid;
}

From source file:com.example.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 ww.  j  av  a 2 s  . co  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
    long locationId;

    Cursor locationCursor = mContext.getContentResolver().query(WeatherContract.LocationEntry.CONTENT_URI,
            new String[] { WeatherContract.LocationEntry._ID },
            WeatherContract.LocationEntry.COLUMN_LOCATION_SETTING + " = ?", new String[] { locationSetting },
            null);

    if (locationCursor.moveToFirst()) {
        int columnIndex = locationCursor.getColumnIndex(WeatherContract.LocationEntry._ID);
        locationId = locationCursor.getLong(columnIndex);
    } else {
        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 insertedUri = mContext.getContentResolver().insert(WeatherContract.LocationEntry.CONTENT_URI,
                values);

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

    return locationId;
}

From source file:com.beesham.popularmovies.sync.MoviesSyncAdapter.java

/**
 * Parses the movie data from a JSON string
 * and saves it in the database//from  w w  w .ja v a 2  s  .  com
 * @param moviesJsonStr
 */
private void getMovieDataFromJson(String moviesJsonStr) throws JSONException {
    final String BASE_IMAGE_URL = getContext().getString(R.string.movies_base_image_url);

    JSONObject moviesJSON = new JSONObject(moviesJsonStr);
    JSONArray moviesListJSON = moviesJSON.getJSONArray("results");

    Vector<ContentValues> contentValuesVector = new Vector<>(moviesListJSON.length());

    for (int i = 0; i < moviesListJSON.length(); i++) {
        String title;
        String id;
        String overview;
        String posterPath;
        double rating;
        String release_date;
        String trailers;
        String reviews;

        JSONObject movieJSON = moviesListJSON.getJSONObject(i);

        title = movieJSON.getString("title");
        id = movieJSON.getString("id");
        overview = movieJSON.getString("overview");
        posterPath = movieJSON.getString("poster_path");
        rating = movieJSON.getDouble("vote_average");
        release_date = movieJSON.getString("release_date");
        trailers = getTrailersOrReviews(id, 0);
        reviews = getTrailersOrReviews(id, 1);

        ContentValues movieValues = new ContentValues();

        movieValues.put(MoviesEntry.COLUMN_MOVIE_ID, id);
        movieValues.put(MoviesEntry.COLUMN_MOVIE_TITLE, title);
        movieValues.put(MoviesEntry.COLUMN_MOVIE_SYNOPSIS, overview);
        movieValues.put(MoviesEntry.COLUMN_MOVIE_POSTER, BASE_IMAGE_URL + posterPath);
        movieValues.put(MoviesEntry.COLUMN_MOVIE_USER_RATING, rating);
        movieValues.put(MoviesEntry.COLUMN_MOVIE_RELEASE_DATE, release_date);
        movieValues.put(MoviesEntry.COLUMN_MOVIE_TRAILERS, trailers);
        movieValues.put(MoviesEntry.COLUMN_MOVIE_REVIEWS, reviews);

        contentValuesVector.add(movieValues);
    }

    int inserted = 0;
    if (contentValuesVector.size() > 0) {
        ContentValues[] contentValuesArray = new ContentValues[contentValuesVector.size()];
        contentValuesVector.toArray(contentValuesArray);

        getContext().getContentResolver().delete(MoviesEntry.CONTENT_URI, null, null);
        inserted = getContext().getContentResolver().bulkInsert(MoviesEntry.CONTENT_URI, contentValuesArray);
    }

}