List of usage examples for android.content ContentValues ContentValues
public ContentValues()
From source file:edu.mit.mobile.android.livingpostcards.data.Card.java
/** * Creates a new card with a random UUID. Cards are marked DRAFT by default. * * @param cr//from w w w. ja v a 2s. c o m * @param title * @return */ public static Uri createNewCard(Context context, Account account, String title) { final ContentValues cv = new ContentValues(); cv.put(Card.COL_TITLE, title); return createNewCard(context, account, cv); }
From source file:com.riasayu.gosuke.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 . java2 s . c o 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 long locationRowId = -1; Cursor cursor = mContext.getContentResolver().query(WeatherContract.LocationEntry.CONTENT_URI, null, WeatherContract.LocationEntry.COLUMN_LOCATION_SETTING + " = ?", new String[] { locationSetting }, null); if (cursor.moveToFirst()) { locationRowId = cursor.getLong(cursor.getColumnIndex(WeatherContract.LocationEntry._ID)); } else { ContentValues locationValues = new ContentValues(); locationValues.put(WeatherContract.LocationEntry.COLUMN_LOCATION_SETTING, locationSetting); locationValues.put(WeatherContract.LocationEntry.COLUMN_CITY_NAME, cityName); locationValues.put(WeatherContract.LocationEntry.COLUMN_COORD_LONG, lon); locationValues.put(WeatherContract.LocationEntry.COLUMN_COORD_LAT, lat); Uri locationUri = mContext.getContentResolver().insert(WeatherContract.LocationEntry.CONTENT_URI, locationValues); locationRowId = ContentUris.parseId(locationUri); } return locationRowId; }
From source file:android.syncml.pim.PropertyNode.java
public PropertyNode(String propName, String propValue, List<String> propValue_vector, byte[] propValue_bytes, ContentValues paramMap, Set<String> paramMap_TYPE, Set<String> propGroupSet) { if (propName != null) { this.propName = propName; } else {/* www . j a va2s. c o m*/ this.propName = ""; } if (propValue != null) { this.propValue = propValue; } else { this.propValue = ""; } if (propValue_vector != null) { this.propValue_vector = propValue_vector; } else { this.propValue_vector = new ArrayList<String>(); } this.propValue_bytes = propValue_bytes; if (paramMap != null) { this.paramMap = paramMap; } else { this.paramMap = new ContentValues(); } if (paramMap_TYPE != null) { this.paramMap_TYPE = paramMap_TYPE; } else { this.paramMap_TYPE = new HashSet<String>(); } if (propGroupSet != null) { this.propGroupSet = propGroupSet; } else { this.propGroupSet = new HashSet<String>(); } }
From source file:edu.stanford.mobisocial.dungbeetle.Helpers.java
public static Uri insertContact(final Context c, String pubKeyStr, String name, String email) { ContentValues values = new ContentValues(); values.put(Contact.PUBLIC_KEY, pubKeyStr); values.put(Contact.NAME, name);//w w w . jav a2 s .c o m values.put(Contact.EMAIL, email); Uri url = Uri.parse(DungBeetleContentProvider.CONTENT_URI + "/contacts"); return c.getContentResolver().insert(url, values); }
From source file:com.android.browser.FetchUrlMimeType.java
@Override public ContentValues doInBackground(ContentValues... values) { mValues = values[0];//from ww w . j a va 2 s.c o m // Check to make sure we have a URI to download String uri = mValues.getAsString(Downloads.Impl.COLUMN_URI); if (uri == null || uri.length() == 0) { return null; } // User agent is likely to be null, though the AndroidHttpClient // seems ok with that. AndroidHttpClient client = AndroidHttpClient .newInstance(mValues.getAsString(Downloads.Impl.COLUMN_USER_AGENT)); HttpHead request = new HttpHead(uri); String cookie = mValues.getAsString(Downloads.Impl.COLUMN_COOKIE_DATA); if (cookie != null && cookie.length() > 0) { request.addHeader("Cookie", cookie); } String referer = mValues.getAsString(Downloads.Impl.COLUMN_REFERER); if (referer != null && referer.length() > 0) { request.addHeader("Referer", referer); } HttpResponse response; ContentValues result = new ContentValues(); try { response = client.execute(request); // We could get a redirect here, but if we do lets let // the download manager take care of it, and thus trust that // the server sends the right mimetype if (response.getStatusLine().getStatusCode() == 200) { Header header = response.getFirstHeader("Content-Type"); if (header != null) { String mimeType = header.getValue(); final int semicolonIndex = mimeType.indexOf(';'); if (semicolonIndex != -1) { mimeType = mimeType.substring(0, semicolonIndex); } result.put("Content-Type", mimeType); } Header contentDispositionHeader = response.getFirstHeader("Content-Disposition"); if (contentDispositionHeader != null) { result.put("Content-Disposition", contentDispositionHeader.getValue()); } } } catch (IllegalArgumentException ex) { request.abort(); } catch (IOException ex) { request.abort(); } finally { client.close(); } return result; }
From source file:com.udacity.sunshine.FetchWeatherTask.java
private long addLocation(String locationSetting, String cityName, double lat, double lon) { Log.v(LOG_TAG, "inserting " + cityName + ", with coord: " + lat + ", " + lon); String[] projection = { LocationEntry._ID }; // whichever column doesn't matter, but don't need to return all String[] selectionArgs = { locationSetting }; String selection = LocationEntry.COLUMN_LOCATION_SETTING + " = ? "; // Check to see if location setting exists in db Cursor cursor = mContext.getContentResolver().query(LocationEntry.CONTENT_URI, projection, selection, selectionArgs, null);//from w w w . j a v a 2s. co m long locationRowId; if (cursor.moveToFirst()) { Log.v(LOG_TAG, "Found it in the database!"); int locationIdIndex = cursor.getColumnIndex(LocationEntry._ID); locationRowId = cursor.getLong(locationIdIndex); } else { Log.v(LOG_TAG, "Didn't find it in the database, inserting now!"); 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 locationUri = mContext.getContentResolver().insert(LocationEntry.CONTENT_URI, locationValues); locationRowId = ContentUris.parseId(locationUri); } cursor.close(); return locationRowId; }
From source file:com.swisscom.android.sunshine.data.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 . ja v a 2 s . 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) { 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_SETTINGS + " = ?", new String[] { locationSetting }, null); if (cursor.moveToFirst()) { Log.v(LOG_TAG, "Found it in the database!"); int locationIdIndex = cursor.getColumnIndex(LocationEntry._ID); return cursor.getLong(locationIdIndex); } else { Log.v(LOG_TAG, "Didn't find it in the database, inserting now!"); ContentValues locationValues = new ContentValues(); locationValues.put(LocationEntry.COLUMN_LOCATION_SETTINGS, locationSetting); locationValues.put(LocationEntry.COLUMN_CITY_NAME, cityName); locationValues.put(LocationEntry.COLUMN_LATITUDE, lat); locationValues.put(LocationEntry.COLUMN_LONGITUDE, lon); Uri locationInsertUri = mContext.getContentResolver().insert(LocationEntry.CONTENT_URI, locationValues); return ContentUris.parseId(locationInsertUri); } }
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//from w w w .j a va 2 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) { // 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:com.fanfou.app.opensource.api.bean.Photo.java
@Override public ContentValues toContentValues() { final ContentValues cv = new ContentValues(); cv.put("id", this.id); cv.put("createdAt", this.createdAt.getTime()); cv.put("imageUrl", this.imageUrl); cv.put("thumbUrl", this.thumbUrl); cv.put("largeUrl", this.largeUrl); return cv;/*from w w w .j ava 2 s. co m*/ }
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// w w w . ja v a2 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; }