List of usage examples for android.content ContentValues ContentValues
public ContentValues()
From source file:utils.database.sqlite.data.AFieldData.java
@Override public ContentValues toContentValue() { ContentValues cv = new ContentValues(); Set<IColumns> name = integerValue.keySet(); for (IColumns n : name) { cv.put(n.toString(), integerValue.get(n)); }//from w ww. j av a 2s. c o m name = stringValue.keySet(); for (IColumns n : name) { String t = stringValue.get(n); if (stringValue.containsKey(n)) { String nome = ((Enum) n).name(); if (nome.equals("DATA_RILIEVO")) { cv.put(n.toString(), UtilsDB.getData()); } else if (t != null) { cv.put(n.toString(), t); } } } name = doubleValue.keySet(); for (IColumns n : name) { cv.put(n.toString(), doubleValue.get(n)); } setCvToNew(cv); return cv; }
From source file:za.co.neilson.alarm.database.Database.java
public static int update(Alarm alarm) { ContentValues cv = new ContentValues(); cv.put(COLUMN_ALARM_ACTIVE, alarm.getAlarmActive()); cv.put(COLUMN_ALARM_TIME, alarm.getAlarmTimeString()); try {//w w w. jav a 2 s . c o m ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutputStream oos = null; oos = new ObjectOutputStream(bos); oos.writeObject(alarm.getDays()); byte[] buff = bos.toByteArray(); cv.put(COLUMN_ALARM_DAYS, buff); } catch (Exception e) { } cv.put(COLUMN_ALARM_DIFFICULTY, alarm.getDifficulty().ordinal()); cv.put(COLUMN_ALARM_TONE, alarm.getAlarmTonePath()); cv.put(COLUMN_ALARM_VIBRATE, alarm.getVibrate()); cv.put(COLUMN_ALARM_NAME, alarm.getAlarmName()); return getDatabase().update(ALARM_TABLE, cv, "_id=" + alarm.getId(), null); }
From source file:fr.mixit.android.utils.SyncUtils.java
public static void updateLocalMd5(ContentResolver resolver, String url, String md5) { final String syncId = MixItContract.Sync.generateSyncId(url); final ContentValues contentValues = new ContentValues(); contentValues.put(MixItContract.Sync.URI_ID, syncId); contentValues.put(MixItContract.Sync.URI, url); contentValues.put(MixItContract.Sync.MD5, md5); resolver.insert(MixItContract.Sync.CONTENT_URI, contentValues); }
From source file:edu.stanford.mobisocial.dungbeetle.Helpers.java
@Deprecated public static Uri sendMessage(final Context c, long contactId, JSONObject json, String type) { Uri url = Uri.parse(DungBeetleContentProvider.CONTENT_URI + "/out"); Obj obj = DbObjects.convertOldJsonToObj(c, type, json); ContentValues values = new ContentValues(); values.put(DbObject.TYPE, type);/* w ww . j a v a 2 s. c o m*/ values.put(DbObject.JSON, obj.getJson().toString()); if (obj.getRaw() != null) { values.put(DbObject.RAW, obj.getRaw()); } String to = Long.toString(contactId); values.put(DbObject.DESTINATION, to); return c.getContentResolver().insert(url, values); }
From source file:com.example.whetzel.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 w w . j a v a2 s. com*/ * @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; // Students: First, check if the location with this city name exists in the db Cursor locationCursor = mContext.getContentResolver().query(WeatherContract.LocationEntry.CONTENT_URI, new String[] { WeatherContract.LocationEntry._ID }, WeatherContract.LocationEntry.COLUMN_LOCATION_SETTING + " =? ", new String[] { locationSetting }, null); // If it exists, return the current ID // Otherwise, insert it using the content resolver and the base URI if (locationCursor.moveToFirst()) { int locationIdIndex = locationCursor.getColumnIndex(WeatherContract.LocationEntry._ID); locationId = locationCursor.getLong(locationIdIndex); } else { // Now that the content provider is set up, inserting rows of data is pretty simple. // First create a ContentValues object to hold the data you want to insert. ContentValues locationValues = new ContentValues(); // Then add the data, along with the corresponding name of the data type, // so the content provider knows what kind of value is being inserted. 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); // Finally, insert location data into the database. Uri insertedUri = mContext.getContentResolver().insert(WeatherContract.LocationEntry.CONTENT_URI, locationValues); // 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.ahmed.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/* ww w.jav a 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) { // 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 Cursor query = mContext.getContentResolver().query(WeatherContract.LocationEntry.CONTENT_URI, new String[] { WeatherContract.LocationEntry._ID }, WeatherContract.LocationEntry.COLUMN_LOCATION_SETTING + " = ?", new String[] { locationSetting }, null); if (query != null && query.moveToFirst()) { return query.getLong(query.getColumnIndex(WeatherContract.LocationEntry._ID)); } ContentValues values = new ContentValues(); values.put(WeatherContract.LocationEntry.COLUMN_CITY_NAME, cityName); values.put(WeatherContract.LocationEntry.COLUMN_LOCATION_SETTING, locationSetting); values.put(WeatherContract.LocationEntry.COLUMN_COORD_LAT, lat); values.put(WeatherContract.LocationEntry.COLUMN_COORD_LONG, lon); Uri inserted = mContext.getContentResolver().insert(WeatherContract.LocationEntry.CONTENT_URI, values); return ContentUris.parseId(inserted); }
From source file:net.ccghe.emocha.model.DBAdapter.java
public static boolean markForDeletion(String path, boolean state) { ContentValues values = new ContentValues(); values.put("to_delete", state ? 1 : 0); return sDB.update(TABLE_DOWNLOADS, values, "path='" + path + "'", null) > 0; }
From source file:com.example.tahmina.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 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; // First, check if the location with this city name exists in the db 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 locationIdIndex = locationCursor.getColumnIndex(WeatherContract.LocationEntry._ID); locationId = locationCursor.getLong(locationIdIndex); } else { // Now that the content provider is set up, inserting rows of data is pretty simple. // First create a ContentValues object to hold the data you want to insert. ContentValues locationValues = new ContentValues(); // Then add the data, along with the corresponding name of the data type, // so the content provider knows what kind of value is being inserted. 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); // Finally, insert location data into the database. Uri insertedUri = mContext.getContentResolver().insert(WeatherContract.LocationEntry.CONTENT_URI, locationValues); // The resulting URI contains the ID for the row. Extract the locationId from the Uri. locationId = ContentUris.parseId(insertedUri); } locationCursor.close(); // Wait, that worked? Yes! return locationId; }
From source file:app.com.example.manu.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/*from www . j av a 2 s . c om*/ * @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; // First, check if the location with this city name exists in the db 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 locationIdIndex = locationCursor.getColumnIndex(WeatherContract.LocationEntry._ID); locationId = locationCursor.getLong(locationIdIndex); } else { // Now that the content provider is set up, inserting rows of data is pretty simple. // First create a ContentValues object to hold the data you want to insert. ContentValues locationValues = new ContentValues(); // Then add the data, along with the corresponding name of the data type, // so the content provider knows what kind of value is being inserted. 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); // Finally, insert location data into the database. Uri insertedUri = mContext.getContentResolver().insert(WeatherContract.LocationEntry.CONTENT_URI, locationValues); // The resulting URI contains the ID for the row. Extract the locationId from the Uri. locationId = ContentUris.parseId(insertedUri); } locationCursor.close(); // Wait, that worked? Yes! return locationId; }
From source file:edu.cens.loci.provider.LociDbUtils.java
public long insertPlace(String name, int state, int type, int entry, long entryTime, long registerTime) { final SQLiteDatabase db = mDbHelper.getWritableDatabase(); ContentValues args = new ContentValues(); args.put(Places.PLACE_NAME, name);/* www. ja v a2s . c om*/ args.put(Places.PLACE_STATE, state); args.put(Places.PLACE_TYPE, type); args.put(Places.ENTRY, entry); args.put(Places.ENTRY_TIME, entryTime); args.put(Places.REGISTER_TIME, registerTime); return db.insert(Tables.PLACES, null, args); }