List of usage examples for android.content ContentValues ContentValues
public ContentValues()
From source file:com.calgen.prodek.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 * @param lon the longitude of the city * @return the row ID of the added location. *///from w ww . j a v a 2s .c o m 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 long locationId; //Checking if the 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 uri = mContext.getContentResolver().insert(WeatherContract.LocationEntry.CONTENT_URI, locationValues); locationId = ContentUris.parseId(uri); } locationCursor.close(); return locationId; }
From source file:app.com.ferchofpz.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 w w w . j av a 2s .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 long itemId = -1; Cursor cursor = mContext.getContentResolver().query(WeatherContract.LocationEntry.CONTENT_URI, new String[] { WeatherContract.LocationEntry._ID }, WeatherContract.LocationEntry.COLUMN_LOCATION_SETTING + " = ?", new String[] { locationSetting }, null); if (cursor.moveToFirst()) { int columnIndex = cursor.getColumnIndex(WeatherContract.LocationEntry._ID); itemId = cursor.getLong(columnIndex); } else { ContentValues insertValues = new ContentValues(); insertValues.put(WeatherContract.LocationEntry.COLUMN_CITY_NAME, cityName); insertValues.put(WeatherContract.LocationEntry.COLUMN_LOCATION_SETTING, locationSetting); insertValues.put(WeatherContract.LocationEntry.COLUMN_COORD_LAT, lat); insertValues.put(WeatherContract.LocationEntry.COLUMN_COORD_LONG, lon); Uri insertedUri = mContext.getContentResolver().insert(WeatherContract.LocationEntry.CONTENT_URI, insertValues); itemId = ContentUris.parseId(insertedUri); } cursor.close(); return itemId; }
From source file:io.github.the_dagger.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//from w w w . jav a 2 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 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 locationIdIndex = locationCursor.getColumnIndex(WeatherContract.LocationEntry._ID); locationId = locationCursor.getLong(locationIdIndex); } else { ContentValues contentValues = new ContentValues(); contentValues.put(WeatherContract.LocationEntry.COLUMN_CITY_NAME, cityName); contentValues.put(WeatherContract.LocationEntry.COLUMN_LOCATION_SETTING, locationSetting); contentValues.put(WeatherContract.LocationEntry.COLUMN_COORD_LAT, lat); contentValues.put(WeatherContract.LocationEntry.COLUMN_COORD_LONG, lon); Uri insertLocationUri = mContext.getContentResolver().insert(WeatherContract.LocationEntry.CONTENT_URI, contentValues); locationId = ContentUris.parseId(insertLocationUri); } locationCursor.close(); return locationId; }
From source file:com.example.avs.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 .j av a 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) { 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 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); // 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:com.morphoss.jumble.models.Category.java
/** * /* w w w . ja v a 2s . c o m*/ * @param context * required to work * @return the next word of the available ones */ public Word getNextWord(Context context) { ContentValues cv = new ContentValues(); ArrayList<String> tempsolved = CategoryWords.getSolvedWordsFromCategory(context, this); double ratioSolved = (double) tempsolved.size() / (double) words.size(); Log.d(TAG, "size of solved list : " + tempsolved.size()); Log.d(TAG, "size of words list : " + words.size()); Log.d(TAG, "ratio solved : " + ratioSolved); Log.d(TAG, "category selected : " + this.getLocalisedName()); int ratio = (int) (ratioSolved * 100); Log.d(TAG, "ratio :" + ratio); if (this.getLocalisedName() == null) { Log.e(TAG, "error localised name is null :"); } cv.put(JumbleCategoryTable.UNLOCK, "0"); cv.put(JumbleCategoryTable.CATEGORY, this.getLocalisedName()); cv.put(JumbleCategoryTable.RATIO, ratio); cv.put(JumbleCategoryTable.CC, SettingsActivity.getLanguageToLoad()); if (ratio == 0) { context.getContentResolver().insert(JumbleProvider.CONTENT_URI_CATEGORIES, cv); } else { cv = new ContentValues(); cv.put(JumbleCategoryTable.RATIO, ratio); String selection = JumbleCategoryTable.CATEGORY + "= ? AND " + JumbleCategoryTable.CC + "= ?"; String[] selectionArgs = { this.getLocalisedName(), SettingsActivity.getLanguageToLoad() }; context.getContentResolver().update( Uri.withAppendedPath(JumbleProvider.CONTENT_URI_CATEGORIES, "addratio"), cv, selection, selectionArgs); } Category nextCategory = CategoryGridAdapter.getCategory(getId()); Log.d(TAG, "next category name : " + nextCategory.getLocalisedName()); if (nextCategory.getLocalisedName() != null && ratio == 0) { cv = new ContentValues(); cv.put(JumbleCategoryTable.UNLOCK, "0"); cv.put(JumbleCategoryTable.CATEGORY, nextCategory.getLocalisedName()); cv.put(JumbleCategoryTable.RATIO, ratio); cv.put(JumbleCategoryTable.CC, SettingsActivity.getLanguageToLoad()); context.getContentResolver().insert(JumbleProvider.CONTENT_URI_CATEGORIES, cv); } if (!nextCategory.unlocked() && ratio > 20 && nextCategory.getLocalisedName() != null) { Log.d(TAG, "unlocking a new category"); unlockedCategories.add(nextCategory.getLocalisedName()); cv = new ContentValues(); //cv.put(JumbleCategoryTable.CATEGORY, nextCategory.getLocalisedName()); //cv.put(JumbleCategoryTable.CC, SettingsActivity.getLanguageToLoad()); cv.put(JumbleCategoryTable.UNLOCK, "1"); String selection = JumbleCategoryTable.CATEGORY + "= ? AND " + JumbleCategoryTable.CC + "= ?"; String[] selectionArgs = { nextCategory.getLocalisedName(), SettingsActivity.getLanguageToLoad() }; context.getContentResolver().update( Uri.withAppendedPath(JumbleProvider.CONTENT_URI_CATEGORIES, "unlockCategory"), cv, selection, selectionArgs); //context.getContentResolver().insert(JumbleProvider.CONTENT_URI_CATEGORIES,cv); nextCategory.setUnlocked(true); } int countEasyWords = wordsEasy.size(); Log.d(TAG, "count of easy words :" + countEasyWords); int countMediumWords = wordsMedium.size(); Log.d(TAG, "count of medium words :" + countMediumWords); int countAdvancedWords = wordsAdvanced.size(); Log.d(TAG, "count of advanced words :" + countAdvancedWords); ArrayList<Word> filteredwords = new ArrayList<Word>(); filteredwords.addAll(wordsEasy); if (filteredwords.size() < 3) filteredwords.addAll(wordsMedium); if (filteredwords.size() < 3) filteredwords.addAll(wordsAdvanced); if (filteredwords.size() == 0) return null; Word word = CategoryWords.getRandomItem(filteredwords); ArrayList<Word> wordList; Log.d(TAG, "the random word is : " + word.getLocalisedWord() + " with level :" + word.getLevel()); switch (word.getLevel()) { case EASY: wordList = wordsEasy; break; case MEDIUM: wordList = wordsMedium; break; case ADVANCED: wordList = wordsAdvanced; break; default: wordList = wordsAdvanced; break; } for (int i = 0; i < wordList.size(); i++) { if (wordList.get(i).equals(word)) { wordList.remove(i); break; } } return word; }
From source file:android.provider.Checkin.java
/** * Helper function to log an event to the database. * * @param resolver from {@link android.content.Context#getContentResolver} * @param tag identifying the type of event being recorded * @param value associated with event, if any * @return URI of the event that was added *//*from ww w. j ava 2s . com*/ static public Uri logEvent(ContentResolver resolver, Events.Tag tag, String value) { try { // Don't specify the date column; the content provider will add that. ContentValues values = new ContentValues(); values.put(Events.TAG, tag.toString()); if (value != null) values.put(Events.VALUE, value); return resolver.insert(Events.CONTENT_URI, values); } catch (SQLException e) { Log.e(TAG, "Can't log event: " + tag, e); // Database errors are not fatal. return null; } }
From source file:com.task.krabiysok.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 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) { 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.LOCATION_SETTING + " =?", new String[] { locationSetting }, null); // If it exists, return the current ID if (locationCursor.moveToFirst()) { int locationIdIndex = locationCursor.getColumnIndex(WeatherContract.LocationEntry._ID); locationId = locationCursor.getLong(locationIdIndex); } else { // Otherwise, insert it using the content resolver and the base URI 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.CITY_NAME, cityName); locationValues.put(WeatherContract.LocationEntry.LOCATION_SETTING, locationSetting); locationValues.put(WeatherContract.LocationEntry.COORD_LAT, lat); locationValues.put(WeatherContract.LocationEntry.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:at.bitfire.davdroid.model.CollectionInfo.java
public ContentValues toDB() { ContentValues values = new ContentValues(); // Collections.SERVICE_ID is never changed values.put(Collections.URL, url); values.put(Collections.READ_ONLY, readOnly ? 1 : 0); values.put(Collections.DISPLAY_NAME, displayName); values.put(Collections.DESCRIPTION, description); values.put(Collections.COLOR, color); values.put(Collections.TIME_ZONE, timeZone); if (supportsVEVENT != null) values.put(Collections.SUPPORTS_VEVENT, supportsVEVENT ? 1 : 0); if (supportsVTODO != null) values.put(Collections.SUPPORTS_VTODO, supportsVTODO ? 1 : 0); values.put(Collections.SYNC, selected ? 1 : 0); return values; }
From source file:com.ryansmertz.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 w w w. ja v 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; //Check if lcoatoin with this city name is 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 { 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); } return locationId; }
From source file:com.example.diokey.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. j a v a 2 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 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 it exists, return the current ID if (locationCursor.moveToFirst()) { int locationIndex = locationCursor.getColumnIndex(WeatherContract.LocationEntry._ID); locationId = locationCursor.getLong(locationIndex); } else { // Otherwise, insert it using the content resolver and the base URI ContentValues contentValues = new ContentValues(); contentValues.put(WeatherContract.LocationEntry.COLUMN_CITY_NAME, cityName); contentValues.put(WeatherContract.LocationEntry.COLUMN_LOCATION_SETTING, locationSetting); contentValues.put(WeatherContract.LocationEntry.COLUMN_COORD_LAT, lat); contentValues.put(WeatherContract.LocationEntry.COLUMN_COORD_LONG, lon); Uri locationUri = mContext.getContentResolver().insert(WeatherContract.LocationEntry.CONTENT_URI, contentValues); locationId = ContentUris.parseId(locationUri); } return locationId; }