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.cwru.apo.Directory.java

public void onRestRequestComplete(Methods method, JSONObject result) {
    if (method == Methods.phone) {
        if (result != null) {
            try {
                String requestStatus = result.getString("requestStatus");
                if (requestStatus.compareTo("success") == 0) {
                    SharedPreferences.Editor editor = getSharedPreferences(APO.PREF_FILE_NAME, MODE_PRIVATE)
                            .edit();//from  w  w w .j  a v  a2s . co m
                    editor.putLong("updateTime", result.getLong("updateTime"));
                    editor.commit();
                    int numbros = result.getInt("numBros");
                    JSONArray caseID = result.getJSONArray("caseID");
                    JSONArray first = result.getJSONArray("first");
                    JSONArray last = result.getJSONArray("last");
                    JSONArray phone = result.getJSONArray("phone");
                    JSONArray family = result.getJSONArray("family");
                    ContentValues values;
                    for (int i = 0; i < numbros; i++) {
                        values = new ContentValues();
                        values.put("_id", caseID.getString(i));
                        values.put("first", first.getString(i));
                        values.put("last", last.getString(i));
                        values.put("phone", phone.getString(i));
                        values.put("family", family.getString(i));
                        database.replace("phoneDB", null, values);
                    }
                    loadTable();
                } else if (requestStatus.compareTo("timestamp invalid") == 0) {
                    Toast msg = Toast.makeText(this, "Invalid timestamp.  Please try again.",
                            Toast.LENGTH_LONG);
                    msg.show();
                } else if (requestStatus.compareTo("HMAC invalid") == 0) {
                    Auth.loggedIn = false;
                    Toast msg = Toast.makeText(this,
                            "You have been logged out by the server.  Please log in again.", Toast.LENGTH_LONG);
                    msg.show();
                    finish();
                } else {
                    Toast msg = Toast.makeText(this, "Invalid requestStatus", Toast.LENGTH_LONG);
                    msg.show();
                }
            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }
}

From source file:com.seneca.android.senfitbeta.DbHelper.java

public void insertMuscles(int id, String name) {
    Log.d("INSERT DB", "Inserting muscles...");

    SQLiteDatabase db = this.getWritableDatabase();
    ContentValues values = new ContentValues();

    values.put(RIP_ID, id);
    values.put(RIP_NAME, name);//w ww  .j a va  2  s.c  om
    long info = db.insert(RIP_TABLE, null, values);

}

From source file:net.naonedbus.manager.impl.FavoriManager.java

/**
 * getContentValues for ArretItem/*from  ww w.ja  v  a  2s.c om*/
 * 
 * @param item
 * @return a ContentValue filled with ArretItem values, for a FavoriTable
 *         structure
 */
private ContentValues getContentValues(final Arret item) {
    final ContentValues values = new ContentValues();
    values.put(FavoriTable._ID, item.getId());
    values.put(FavoriTable.CODE_LIGNE, item.getCodeLigne());
    values.put(FavoriTable.CODE_SENS, item.getCodeSens());
    values.put(FavoriTable.CODE_ARRET, item.getCodeArret());
    return values;
}

From source file:com.example.cmput301.model.DatabaseManager.java

/**
 * Post a task to the "remote" table of the database.
 *
 * @param task The task to be added.//from  ww  w .  jav a 2 s.  c om
 * @return The task that was added along with it's id.
 */
public Task postRemote(Task task) {
    ContentValues cv = new ContentValues();
    cv.put(StringRes.COL_ID, task.getId());
    try {
        cv.put(StringRes.COL_CONTENT, task.toJson().toString());
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    db.insert(StringRes.REMOTE_TASK_TABLE_NAME, StringRes.COL_ID, cv);
    return task;
}

From source file:com.mobeelizer.mobile.android.types.FileFieldTypeHelper.java

@Override
protected void setNotNullValueFromMapToDatabase(final ContentValues values, final String value,
        final MobeelizerFieldAccessor field, final Map<String, String> options,
        final MobeelizerErrorsBuilder errors) {
    try {//ww  w  .j  a  va  2s  .co  m
        JSONObject json = new JSONObject(value);
        values.put(field.getName() + _GUID, json.getString(JSON_GUID));
        values.put(field.getName() + _NAME, json.getString(JSON_NAME));
    } catch (JSONException e) {
        throw new IllegalStateException(e.getMessage(), e);
    }
}

From source file:com.example.cmput301.model.DatabaseManager.java

public void hideTask(String taskid) {
    Task task = this.getLocalTask(taskid);
    task.setStatus(5);/*from   w w  w.  j  a va  2s.co m*/
    ContentValues cv = new ContentValues();
    cv.put(StringRes.COL_ID, task.getId());
    try {
        cv.put(StringRes.COL_CONTENT, task.toJson().toString());
        db.delete(StringRes.LOCAL_TASK_TABLE_NAME, StringRes.COL_ID + "=?", new String[] { taskid, });
        db.insert(StringRes.LOCAL_TASK_TABLE_NAME, StringRes.COL_ID, cv);
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:com.vrj.udacity.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 .  jav 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
    long retID = -1L;

    Cursor cursor = mContext.getContentResolver().query(WeatherContract.LocationEntry.CONTENT_URI, // location db
            new String[] { WeatherContract.LocationEntry._ID }, // We want the ID column  
            WeatherContract.LocationEntry.COLUMN_LOCATION_SETTING + "= ?", // Must add = ? param or will not match up
            new String[] { locationSetting }, null);

    if (true == cursor.moveToFirst()) { // If we got something back look for id
        // retID = cursor.getLong(0);       // Return the ID
        int location_index = cursor.getColumnIndex(WeatherContract.LocationEntry._ID);
        retID = cursor.getLong(location_index);
    } else { // Do an insert of the parameter values

        // Creation of ContentValues for insert
        // TODO: Fixup, order is different, if causes trouble
        ContentValues cValues = new ContentValues();
        cValues.put(WeatherContract.LocationEntry.COLUMN_LOCATION_SETTING, locationSetting);
        cValues.put(WeatherContract.LocationEntry.COLUMN_CITY_NAME, cityName);
        cValues.put(WeatherContract.LocationEntry.COLUMN_COORD_LAT, lat);
        cValues.put(WeatherContract.LocationEntry.COLUMN_COORD_LONG, lon);

        // Insert new location in db
        Uri insertedUri = mContext.getContentResolver().insert(WeatherContract.LocationEntry.CONTENT_URI,
                cValues);

        // Extract the locationId from the Uri you got back from .insert().
        retID = ContentUris.parseId(insertedUri);

    }

    cursor.close(); // REMEMEBER to close your cursors.

    return retID;
}

From source file:net.naonedbus.manager.impl.FavoriManager.java

@Override
protected ContentValues getContentValues(final Favori item) {
    final ContentValues values = new ContentValues();
    values.put(FavoriTable._ID, item.getId());
    values.put(FavoriTable.CODE_LIGNE, item.getCodeLigne());
    values.put(FavoriTable.CODE_SENS, item.getCodeSens());
    values.put(FavoriTable.CODE_ARRET, item.getCodeArret());
    values.put(FavoriTable.NOM, item.getNomFavori());

    return values;
}

From source file:com.ubikod.urbantag.model.TagManager.java

/**
 * Insert tag on db//from ww  w .ja  v a2 s .c o  m
 * @param t
 */
private void dbInsert(Tag t) {
    this.open();
    ContentValues values = new ContentValues();
    values.put(DatabaseHelper.TAG_COL_ID, t.getId());
    values.put(DatabaseHelper.TAG_COL_NAME, t.getValue());
    values.put(DatabaseHelper.TAG_COL_COLOR, t.getColor());
    values.put(DatabaseHelper.TAG_COL_NOTIFY, t.isSelected() ? 1 : 0);

    mDB.insert(DatabaseHelper.TABLE_TAGS, DatabaseHelper.TAG_COL_ID, values);
    this.close();
}

From source file:com.ubikod.urbantag.model.TagManager.java

/**
 * Update a tag on db//from w  ww  . j ava 2 s. co m
 * @param t
 */
private void dbUpdate(Tag t) {
    this.open();
    ContentValues values = new ContentValues();
    values.put(DatabaseHelper.TAG_COL_NAME, t.getValue());
    values.put(DatabaseHelper.TAG_COL_COLOR, t.getColor());
    values.put(DatabaseHelper.TAG_COL_NOTIFY, t.isSelected() ? 1 : 0);

    mDB.update(DatabaseHelper.TABLE_TAGS, values, DatabaseHelper.TAG_COL_ID + " =? ",
            new String[] { String.valueOf(t.getId()) });
    this.close();
}