List of usage examples for android.content ContentValues put
public void put(String key, byte[] value)
From source file:gov.wa.wsdot.android.wsdot.service.CamerasSyncService.java
@Override protected void onHandleIntent(Intent intent) { ContentResolver resolver = getContentResolver(); Cursor cursor = null;/*from ww w . j a va 2 s . c o 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, projection, Caches.CACHE_TABLE_NAME + " LIKE ?", new String[] { "cameras" }, null); if (cursor != null && cursor.moveToFirst()) { long lastUpdated = cursor.getLong(0); //long deltaDays = (now - lastUpdated) / DateUtils.DAY_IN_MILLIS; //Log.d(DEBUG_TAG, "Delta since last update is " + deltaDays + " day(s)"); shouldUpdate = (Math.abs(now - lastUpdated) > (7 * DateUtils.DAY_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(CAMERAS_URL); URLConnection urlConn = url.openConnection(); BufferedInputStream bis = new BufferedInputStream(urlConn.getInputStream()); GZIPInputStream gzin = new GZIPInputStream(bis); InputStreamReader is = new InputStreamReader(gzin); BufferedReader in = new BufferedReader(is); String jsonFile = ""; String line; while ((line = in.readLine()) != null) jsonFile += line; in.close(); JSONObject obj = new JSONObject(jsonFile); JSONObject result = obj.getJSONObject("cameras"); JSONArray items = result.getJSONArray("items"); List<ContentValues> cams = new ArrayList<ContentValues>(); int numItems = items.length(); for (int j = 0; j < numItems; j++) { JSONObject item = items.getJSONObject(j); ContentValues cameraData = new ContentValues(); cameraData.put(Cameras.CAMERA_ID, item.getString("id")); cameraData.put(Cameras.CAMERA_TITLE, item.getString("title")); cameraData.put(Cameras.CAMERA_URL, item.getString("url")); cameraData.put(Cameras.CAMERA_LATITUDE, item.getString("lat")); cameraData.put(Cameras.CAMERA_LONGITUDE, item.getString("lon")); cameraData.put(Cameras.CAMERA_HAS_VIDEO, item.getString("video")); cameraData.put(Cameras.CAMERA_ROAD_NAME, item.getString("roadName")); if (starred.contains(Integer.parseInt(item.getString("id")))) { cameraData.put(Cameras.CAMERA_IS_STARRED, 1); } cams.add(cameraData); } // Purge existing cameras covered by incoming data resolver.delete(Cameras.CONTENT_URI, null, null); // Bulk insert all the new cameras resolver.bulkInsert(Cameras.CONTENT_URI, cams.toArray(new ContentValues[cams.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 + " LIKE ?", new String[] { "cameras" }); 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.CAMERAS_RESPONSE"); broadcastIntent.addCategory(Intent.CATEGORY_DEFAULT); broadcastIntent.putExtra("responseString", responseString); sendBroadcast(broadcastIntent); }
From source file:heartware.com.heartware_master.DBAdapter.java
public void createMeetup(HashMap<String, String> queryValues) { SQLiteDatabase database = this.getWritableDatabase(); ContentValues values = new ContentValues(); values.put(USER_ID, queryValues.get(USER_ID)); values.put(NOTE, queryValues.get(NOTE)); values.put(EXERCISE, queryValues.get(EXERCISE)); values.put(LOCATION, queryValues.get(LOCATION)); values.put(DATE, queryValues.get(DATE)); values.put(PEOPLE, queryValues.get(PEOPLE)); database.insert(MEETUPS_TABLE, null, values); database.close();/*from w w w. j a v a2 s.c o m*/ }
From source file:com.bellman.bible.service.db.mynote.MyNoteDBAdapter.java
public MyNoteDto insertMyNote(MyNoteDto mynote) { // Create a new row of values to insert. Log.d(TAG, "about to insertMyNote: " + mynote.getVerseRange()); VerseRange verseRange = mynote.getVerseRange(); String v11nName = getVersification(verseRange); // Gets the current system time in milliseconds Long now = Long.valueOf(System.currentTimeMillis()); ContentValues newValues = new ContentValues(); newValues.put(MyNoteColumn.KEY, verseRange.getOsisRef()); newValues.put(MyNoteColumn.VERSIFICATION, v11nName); newValues.put(MyNoteColumn.MYNOTE, mynote.getNoteText()); newValues.put(MyNoteColumn.LAST_UPDATED_ON, now); newValues.put(MyNoteColumn.CREATED_ON, now); long newId = db.insert(Table.MYNOTE, null, newValues); MyNoteDto newMyNote = getMyNoteDto(newId); return newMyNote; }
From source file:gov.wa.wsdot.android.wsdot.service.FerriesSchedulesSyncService.java
@Override protected void onHandleIntent(Intent intent) { ContentResolver resolver = getContentResolver(); Cursor cursor = null;/*from w w w. ja va2s. c o m*/ 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_schedules" }, 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) > (30 * 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(FERRIES_SCHEDULES_URL); URLConnection urlConn = url.openConnection(); BufferedInputStream bis = new BufferedInputStream(urlConn.getInputStream()); GZIPInputStream gzin = new GZIPInputStream(bis); InputStreamReader is = new InputStreamReader(gzin); BufferedReader in = new BufferedReader(is); String jsonFile = ""; String line; while ((line = in.readLine()) != null) jsonFile += line; in.close(); JSONArray items = new JSONArray(jsonFile); List<ContentValues> schedules = new ArrayList<ContentValues>(); int numItems = items.length(); for (int i = 0; i < numItems; i++) { JSONObject item = items.getJSONObject(i); ContentValues schedule = new ContentValues(); schedule.put(FerriesSchedules.FERRIES_SCHEDULE_ID, item.getInt("RouteID")); schedule.put(FerriesSchedules.FERRIES_SCHEDULE_TITLE, item.getString("Description")); schedule.put(FerriesSchedules.FERRIES_SCHEDULE_DATE, item.getString("Date")); schedule.put(FerriesSchedules.FERRIES_SCHEDULE_ALERT, item.getString("RouteAlert")); schedule.put(FerriesSchedules.FERRIES_SCHEDULE_UPDATED, dateFormat .format(new Date(Long.parseLong(item.getString("CacheDate").substring(6, 19))))); if (starred.contains(item.getInt("RouteID"))) { schedule.put(FerriesSchedules.FERRIES_SCHEDULE_IS_STARRED, 1); } schedules.add(schedule); } // Purge existing travel times covered by incoming data resolver.delete(FerriesSchedules.CONTENT_URI, null, null); // Bulk insert all the new travel times resolver.bulkInsert(FerriesSchedules.CONTENT_URI, schedules.toArray(new ContentValues[schedules.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_schedules" }); 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.FERRIES_SCHEDULES_RESPONSE"); broadcastIntent.addCategory(Intent.CATEGORY_DEFAULT); broadcastIntent.putExtra("responseString", responseString); sendBroadcast(broadcastIntent); }
From source file:heartware.com.heartware_master.DBAdapter.java
public int updateMeetup(final String note, final String userId, HashMap<String, String> queryValues) { SQLiteDatabase database = this.getWritableDatabase(); ContentValues values = new ContentValues(); values.put(USER_ID, queryValues.get(USER_ID)); values.put(NOTE, queryValues.get(NOTE)); values.put(EXERCISE, queryValues.get(EXERCISE)); values.put(LOCATION, queryValues.get(LOCATION)); values.put(DATE, queryValues.get(DATE)); values.put(PEOPLE, queryValues.get(PEOPLE)); // update(TableName, ContentValueForTable, WhereClause, ArgumentForWhereClause) return database.update(MEETUPS_TABLE, values, NOTE + " = '" + note + "' AND " + USER_ID + " = " + userId, null);/*from w ww. ja va 2 s.c om*/ }
From source file:com.bellman.bible.service.db.mynote.MyNoteDBAdapter.java
public MyNoteDto updateMyNote(MyNoteDto mynote) { // Create a new row of values to insert. Log.d(TAG, "about to updateMyNote: " + mynote.getVerseRange()); VerseRange verserange = mynote.getVerseRange(); String v11nName = getVersification(verserange); // Gets the current system time in milliseconds Long now = Long.valueOf(System.currentTimeMillis()); ContentValues newValues = new ContentValues(); newValues.put(MyNoteColumn.KEY, verserange.getOsisRef()); newValues.put(MyNoteColumn.VERSIFICATION, v11nName); newValues.put(MyNoteColumn.MYNOTE, mynote.getNoteText()); newValues.put(MyNoteColumn.LAST_UPDATED_ON, now); long rowsUpdated = db.update(Table.MYNOTE, newValues, "_id=?", new String[] { String.valueOf(mynote.getId()) }); Log.d(TAG, "Rows updated:" + rowsUpdated); return getMyNoteDto(mynote.getId()); }
From source file:com.android.providers.contacts.ContactsSyncAdapter.java
private static void contactsElementToValues(ContentValues values, ContactsElement element, HashMap<Byte, Integer> map) { values.put("type", map.get(element.getType())); values.put("label", element.getLabel()); values.put("isprimary", element.isPrimary() ? 1 : 0); }
From source file:gov.wa.wsdot.android.wsdot.service.FerriesTerminalSailingSpaceSyncService.java
@Override protected void onHandleIntent(Intent intent) { ContentResolver resolver = getContentResolver(); Cursor cursor = null;//w w w .j ava2 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.example.android.myargmenuplanner.data.FetchJsonDataTask.java
private void getDataFoodFromJson(String JsonStr) throws JSONException { final String JSON_LIST = "foods"; final String JSON_TITLE = "title"; final String JSON_IMAGE_ID = "image_id"; final String JSON_DESCRIPTION = "description"; final String JSON_TIME = "time"; final String JSON_ID = "id"; try {/*from www.j a va 2s . c o m*/ JSONObject dataJson = new JSONObject(JsonStr); JSONArray moviesArray = dataJson.getJSONArray(JSON_LIST); Vector<ContentValues> cVVector = new Vector<ContentValues>(moviesArray.length()); for (int i = 0; i < moviesArray.length(); i++) { JSONObject movie = moviesArray.getJSONObject(i); String title = movie.getString(JSON_TITLE); String image_id = movie.getString(JSON_IMAGE_ID); String description = movie.getString(JSON_DESCRIPTION); String time = movie.getString(JSON_TIME); String id = movie.getString(JSON_ID); ContentValues foodsValues = new ContentValues(); foodsValues.put(FoodEntry.COLUMN_ID, id); foodsValues.put(FoodEntry.COLUMN_TITLE, title); foodsValues.put(FoodEntry.COLUMN_IMAGE_ID, image_id); foodsValues.put(FoodEntry.COLUMN_DESCRIPTION, description); foodsValues.put(FoodEntry.COLUMN_TIME, time); cVVector.add(foodsValues); } int inserted = 0; // delete database int rowdeleted = mContext.getContentResolver().delete(FoodEntry.CONTENT_URI, null, null); // // add to database Log.i(LOG_TAG, "Creando registros en base de datos. Tabla Food: "); if (cVVector.size() > 0) { ContentValues[] cvArray = new ContentValues[cVVector.size()]; cVVector.toArray(cvArray); inserted = mContext.getContentResolver().bulkInsert(FoodEntry.CONTENT_URI, cvArray); Log.i(LOG_TAG, "Registros nuevos creados en tabla Food: " + inserted); } } catch (JSONException e) { Log.e(LOG_TAG, e.getMessage(), e); e.printStackTrace(); } }
From source file:android.database.DatabaseUtils.java
/** * Reads a Long out of a field in a Cursor and writes it to a Map. * * @param cursor The cursor to read from * @param field The INTEGER field to read * @param values The {@link ContentValues} to put the value into * @param key The key to store the value with in the map *///from ww w. ja v a 2 s .c om public static void cursorLongToContentValues(Cursor cursor, String field, ContentValues values, String key) { int colIndex = cursor.getColumnIndex(field); if (!cursor.isNull(colIndex)) { Long value = Long.valueOf(cursor.getLong(colIndex)); values.put(key, value); } else { values.put(key, (Long) null); } }