List of usage examples for android.content ContentValues ContentValues
public ContentValues()
From source file:com.android.browser.DownloadTouchIcon.java
private void storeIcon(Bitmap icon) { // Do this first in case the download failed. if (mTab != null) { // Remove the touch icon loader from the BrowserActivity. mTab.mTouchIconLoader = null;/*from ww w. j a v a2s . c om*/ } if (icon == null || mCursor == null || isCancelled()) { return; } final ByteArrayOutputStream os = new ByteArrayOutputStream(); icon.compress(Bitmap.CompressFormat.PNG, 100, os); ContentValues values = new ContentValues(); values.put(Browser.BookmarkColumns.TOUCH_ICON, os.toByteArray()); if (mCursor.moveToFirst()) { do { mContentResolver.update(ContentUris.withAppendedId(Browser.BOOKMARKS_URI, mCursor.getInt(0)), values, null, null); } while (mCursor.moveToNext()); } }
From source file:heartware.com.heartware_master.DBAdapter.java
public void createProfile(HashMap<String, String> queryValues) { SQLiteDatabase database = this.getWritableDatabase(); ContentValues values = new ContentValues(); values.put(USERNAME, queryValues.get(USERNAME)); values.put(PASSWORD, queryValues.get(PASSWORD)); values.put(DIFFICULTY, queryValues.get(DIFFICULTY)); values.put(DISABILITY, queryValues.get(DISABILITY)); database.insert(PROFILES_TABLE, null, values); database.close();/* www.j av a 2s .c o m*/ }
From source file:com.bellman.bible.service.db.bookmark.BookmarkDBAdapter.java
public LabelDto updateLabel(LabelDto label) { // Create a new row of values to insert. ContentValues newValues = new ContentValues(); newValues.put(LabelColumn.NAME, label.getName()); long newId = db.update(Table.LABEL, newValues, "_id=?", new String[] { String.valueOf(label.getId()) }); LabelDto newLabel = getLabelDto(newId); return newLabel; }
From source file:com.nextgis.woody.activity.EditActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_edit); setToolbar(R.id.main_toolbar);/*from w w w. j a va 2 s .c o m*/ btLeft = (Button) findViewById(R.id.left_button); btLeft.setOnClickListener(this); btRight = (Button) findViewById(R.id.right_button); btRight.setOnClickListener(this); values = new ContentValues(); Intent intent = this.getIntent(); mFeatureId = intent.getLongExtra(Constants.FEATURE_ID, NOT_FOUND); mapCenter = new GeoPoint(intent.getDoubleExtra(SettingsConstants.KEY_PREF_SCROLL_X, 0), intent.getDoubleExtra(SettingsConstants.KEY_PREF_SCROLL_Y, 0)); if (NOT_FOUND != mFeatureId) { MapBase mapBase = MapBase.getInstance(); NGWVectorLayer vectorLayer = (NGWVectorLayer) mapBase.getLayerByName(Constants.KEY_MAIN); Feature feature = vectorLayer.getFeature(mFeatureId); values = feature.getContentValues(true); } firstStep(); }
From source file:de.vanita5.twittnuker.task.CacheUsersStatusesTask.java
@Override protected Void doInBackground(final Void... args) { if (responses == null || responses.length == 0) return null; final ContentResolver resolver = context.getContentResolver(); final Extractor extractor = new Extractor(); final Set<ContentValues> usersValues = new HashSet<>(); final Set<ContentValues> statusesValues = new HashSet<>(); final Set<ContentValues> hashTagValues = new HashSet<>(); final Set<Long> allStatusIds = new HashSet<>(); final Set<String> allHashTags = new HashSet<>(); final Set<User> users = new HashSet<>(); for (final TwitterListResponse<twitter4j.Status> response : responses) { if (response == null || response.list == null) { continue; }//w w w.j ava 2s . c om final List<twitter4j.Status> list = response.list; final Set<Long> userIds = new HashSet<>(); for (final twitter4j.Status status : list) { if (status == null || status.getId() <= 0) { continue; } if (status.isRetweet()) { final User retweetUser = status.getRetweetedStatus().getUser(); userIds.add(retweetUser.getId()); } allStatusIds.add(status.getId()); statusesValues.add(createStatus(status, response.account_id)); allHashTags.addAll(extractor.extractHashtags(status.getText())); final User user = status.getUser(); users.add(user); userIds.add(user.getId()); final ContentValues filtered_users_values = new ContentValues(); filtered_users_values.put(Filters.Users.NAME, user.getName()); filtered_users_values.put(Filters.Users.SCREEN_NAME, user.getScreenName()); final String filtered_users_where = Expression.equals(Filters.Users.USER_ID, user.getId()).getSQL(); resolver.update(Filters.Users.CONTENT_URI, filtered_users_values, filtered_users_where, null); } } bulkDelete(resolver, CachedStatuses.CONTENT_URI, CachedStatuses.STATUS_ID, allStatusIds, null, false); bulkInsert(resolver, CachedStatuses.CONTENT_URI, statusesValues); for (final String hashtag : allHashTags) { final ContentValues values = new ContentValues(); values.put(CachedHashtags.NAME, hashtag); hashTagValues.add(values); } bulkDelete(resolver, CachedHashtags.CONTENT_URI, CachedHashtags.NAME, allHashTags, null, true); bulkInsert(resolver, CachedHashtags.CONTENT_URI, hashTagValues); for (final User user : users) { usersValues.add(createCachedUser(user)); } bulkInsert(resolver, CachedUsers.CONTENT_URI, usersValues); return null; }
From source file:gov.wa.wsdot.android.wsdot.service.BorderWaitSyncService.java
@Override protected void onHandleIntent(Intent intent) { ContentResolver resolver = getContentResolver(); Cursor cursor = null;/*w w w .j av a 2s .co m*/ long now = System.currentTimeMillis(); boolean shouldUpdate = true; String responseString = ""; /** * Check the cache table for the last time data was downloaded. If we are within * the allowed time period, don't sync, otherwise get fresh data from the server. */ try { cursor = resolver.query(Caches.CONTENT_URI, new String[] { Caches.CACHE_LAST_UPDATED }, Caches.CACHE_TABLE_NAME + " LIKE ?", new String[] { "border_wait" }, null); if (cursor != null && cursor.moveToFirst()) { long lastUpdated = cursor.getLong(0); //long deltaMinutes = (now - lastUpdated) / DateUtils.MINUTE_IN_MILLIS; //Log.d(DEBUG_TAG, "Delta since last update is " + deltaMinutes + " min"); shouldUpdate = (Math.abs(now - lastUpdated) > (15 * DateUtils.MINUTE_IN_MILLIS)); } } finally { if (cursor != null) { cursor.close(); } } // Ability to force a refresh of camera data. boolean forceUpdate = intent.getBooleanExtra("forceUpdate", false); if (shouldUpdate || forceUpdate) { List<Integer> starred = new ArrayList<Integer>(); starred = getStarred(); try { URL url = new URL(BORDER_WAIT_URL); URLConnection urlConn = url.openConnection(); BufferedReader in = new BufferedReader(new InputStreamReader(urlConn.getInputStream())); String jsonFile = ""; String line; while ((line = in.readLine()) != null) jsonFile += line; in.close(); JSONObject obj = new JSONObject(jsonFile); JSONObject result = obj.getJSONObject("waittimes"); JSONArray items = result.getJSONArray("items"); List<ContentValues> times = new ArrayList<ContentValues>(); int numItems = items.length(); for (int j = 0; j < numItems; j++) { JSONObject item = items.getJSONObject(j); ContentValues timesValues = new ContentValues(); timesValues.put(BorderWait.BORDER_WAIT_ID, item.getInt("id")); timesValues.put(BorderWait.BORDER_WAIT_TITLE, item.getString("name")); timesValues.put(BorderWait.BORDER_WAIT_UPDATED, item.getString("updated")); timesValues.put(BorderWait.BORDER_WAIT_LANE, item.getString("lane")); timesValues.put(BorderWait.BORDER_WAIT_ROUTE, item.getInt("route")); timesValues.put(BorderWait.BORDER_WAIT_DIRECTION, item.getString("direction")); timesValues.put(BorderWait.BORDER_WAIT_TIME, item.getInt("wait")); if (starred.contains(item.getInt("id"))) { timesValues.put(BorderWait.BORDER_WAIT_IS_STARRED, 1); } times.add(timesValues); } // Purge existing border wait times covered by incoming data resolver.delete(BorderWait.CONTENT_URI, null, null); // Bulk insert all the new travel times resolver.bulkInsert(BorderWait.CONTENT_URI, times.toArray(new ContentValues[times.size()])); // Update the cache table with the time we did the update ContentValues values = new ContentValues(); values.put(Caches.CACHE_LAST_UPDATED, System.currentTimeMillis()); resolver.update(Caches.CONTENT_URI, values, Caches.CACHE_TABLE_NAME + "=?", new String[] { "border_wait" }); responseString = "OK"; } catch (Exception e) { Log.e(DEBUG_TAG, "Error: " + e.getMessage()); responseString = e.getMessage(); } } else { responseString = "NOP"; } Intent broadcastIntent = new Intent(); broadcastIntent.setAction("gov.wa.wsdot.android.wsdot.intent.action.BORDER_WAIT_RESPONSE"); broadcastIntent.addCategory(Intent.CATEGORY_DEFAULT); broadcastIntent.putExtra("responseString", responseString); sendBroadcast(broadcastIntent); }
From source file:br.com.oromar.dev.android.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 * @param lon the longitude of the city * @return the row ID of the added location. *//*from w ww. j av a 2 s .c o m*/ public long addLocation(String locationSetting, String cityName, double lat, double lon) { long id = 0; // Students: First, check if the location with this city name exists in the db Cursor cursor = mContext.getContentResolver().query(WeatherContract.LocationEntry.CONTENT_URI, // Uri null, //projection WeatherContract.LocationEntry.CITY_NAME + " = ?", //selection new String[] { cityName }, //selectionArgs null);//sortBy // If it exists, return the current ID if (cursor.moveToFirst()) { id = cursor.getInt(cursor.getColumnIndex("_id")); // Otherwise, insert it using the content resolver and the base URI } else { ContentValues contentValues = new ContentValues(); contentValues.put(WeatherContract.LocationEntry.LOCATION_SETTING, locationSetting); contentValues.put(WeatherContract.LocationEntry.CITY_NAME, cityName); contentValues.put(WeatherContract.LocationEntry.COORD_LAT, lat); contentValues.put(WeatherContract.LocationEntry.COORD_LONG, lon); Uri uri = mContext.getContentResolver().insert(WeatherContract.LocationEntry.CONTENT_URI, contentValues); id = Integer.valueOf(uri.getPathSegments().get(1)); } return id; }
From source file:com.dahl.brendan.wordsearch.view.IOService.java
private static void readFile(Context context, File file, boolean overwrite) { if (file.canRead()) { if (overwrite) { context.getContentResolver().delete(Word.CONTENT_URI, "1", null); }/*from ww w. ja v a2 s .c o m*/ try { byte[] buffer = new byte[(int) file.length()]; BufferedInputStream f = new BufferedInputStream(new FileInputStream(file)); f.read(buffer); JSONArray array = new JSONArray(new String(buffer)); List<ContentValues> values = new LinkedList<ContentValues>(); for (int i = 0; i < array.length(); i++) { Log.v(LOGTAG, array.getString(i)); ContentValues value = new ContentValues(); value.put(Word.WORD, array.getString(i)); values.add(value); } context.getContentResolver().bulkInsert(Word.CONTENT_URI, values.toArray(new ContentValues[0])); } catch (IOException e) { Log.e(LOGTAG, "IO error", e); } catch (JSONException e) { Log.e(LOGTAG, "bad input", e); } } }
From source file:gov.wa.wsdot.android.wsdot.service.FerriesTerminalSailingSpaceSyncService.java
@Override protected void onHandleIntent(Intent intent) { ContentResolver resolver = getContentResolver(); Cursor cursor = null;//from w w w . j a va 2 s . com long now = System.currentTimeMillis(); boolean shouldUpdate = true; String responseString = ""; DateFormat dateFormat = new SimpleDateFormat("MMMM d, yyyy h:mm a"); /** * Check the cache table for the last time data was downloaded. If we are within * the allowed time period, don't sync, otherwise get fresh data from the server. */ try { cursor = resolver.query(Caches.CONTENT_URI, new String[] { Caches.CACHE_LAST_UPDATED }, Caches.CACHE_TABLE_NAME + " LIKE ?", new String[] { "ferries_terminal_sailing_space" }, null); if (cursor != null && cursor.moveToFirst()) { long lastUpdated = cursor.getLong(0); shouldUpdate = (Math.abs(now - lastUpdated) > (15 * DateUtils.SECOND_IN_MILLIS)); } } finally { if (cursor != null) { cursor.close(); } } // Ability to force a refresh of camera data. boolean forceUpdate = intent.getBooleanExtra("forceUpdate", false); if (shouldUpdate || forceUpdate) { List<Integer> starred = new ArrayList<Integer>(); starred = getStarred(); try { URL url = new URL(TERMINAL_SAILING_SPACE_URL); URLConnection urlConn = url.openConnection(); BufferedReader in = new BufferedReader(new InputStreamReader(urlConn.getInputStream())); String jsonFile = ""; String line; while ((line = in.readLine()) != null) jsonFile += line; in.close(); JSONArray array = new JSONArray(jsonFile); List<ContentValues> terminal = new ArrayList<ContentValues>(); int numItems = array.length(); for (int j = 0; j < numItems; j++) { JSONObject item = array.getJSONObject(j); ContentValues sailingSpaceValues = new ContentValues(); sailingSpaceValues.put(FerriesTerminalSailingSpace.TERMINAL_ID, item.getInt("TerminalID")); sailingSpaceValues.put(FerriesTerminalSailingSpace.TERMINAL_NAME, item.getString("TerminalName")); sailingSpaceValues.put(FerriesTerminalSailingSpace.TERMINAL_ABBREV, item.getString("TerminalAbbrev")); sailingSpaceValues.put(FerriesTerminalSailingSpace.TERMINAL_DEPARTING_SPACES, item.getString("DepartingSpaces")); sailingSpaceValues.put(FerriesTerminalSailingSpace.TERMINAL_LAST_UPDATED, dateFormat.format(new Date(System.currentTimeMillis()))); if (starred.contains(item.getInt("TerminalID"))) { sailingSpaceValues.put(FerriesTerminalSailingSpace.TERMINAL_IS_STARRED, 1); } terminal.add(sailingSpaceValues); } // Purge existing terminal sailing space items covered by incoming data resolver.delete(FerriesTerminalSailingSpace.CONTENT_URI, null, null); // Bulk insert all the new terminal sailing space items resolver.bulkInsert(FerriesTerminalSailingSpace.CONTENT_URI, terminal.toArray(new ContentValues[terminal.size()])); // Update the cache table with the time we did the update ContentValues values = new ContentValues(); values.put(Caches.CACHE_LAST_UPDATED, System.currentTimeMillis()); resolver.update(Caches.CONTENT_URI, values, Caches.CACHE_TABLE_NAME + "=?", new String[] { "ferries_terminal_sailing_space" }); responseString = "OK"; } catch (Exception e) { Log.e(TAG, "Error: " + e.getMessage()); responseString = e.getMessage(); } } else { responseString = "NOP"; } Intent broadcastIntent = new Intent(); broadcastIntent .setAction("gov.wa.wsdot.android.wsdot.intent.action.FERRIES_TERMINAL_SAILING_SPACE_RESPONSE"); broadcastIntent.addCategory(Intent.CATEGORY_DEFAULT); broadcastIntent.putExtra("responseString", responseString); sendBroadcast(broadcastIntent); }
From source file:com.csipsimple.backup.Columns.java
public ContentValues jsonToContentValues(JSONObject j) { ContentValues cv = new ContentValues(); for (int i = 0; i < names.size(); i++) { String name = names.get(i); switch (types.get(i)) { case STRING: j2cvString(j, cv, name);//from w w w . j a v a 2 s .c o m break; case INT: j2cvInt(j, cv, name); break; case LONG: j2cvLong(j, cv, name); break; case FLOAT: j2cvFloat(j, cv, name); break; case DOUBLE: j2cvDouble(j, cv, name); break; case BOOLEAN: j2cvBoolean(j, cv, name); } } return cv; }