List of usage examples for android.content ContentValues ContentValues
public ContentValues()
From source file:com.google.android.apps.gutenberg.provider.SyncAdapter.java
private void syncCheckins(ContentProviderClient provider, String cookie) { Cursor cursor = null;//from w ww.ja v a 2 s. c om try { cursor = provider.query(Table.ATTENDEE.getBaseUri(), new String[] { Table.Attendee.ID, Table.Attendee.CHECKIN, Table.Attendee.EVENT_ID, }, Table.Attendee.CHECKIN_MODIFIED, null, null); if (0 == cursor.getCount()) { Log.d(TAG, "No checkin to sync."); return; } int syncCount = 0; while (cursor.moveToNext()) { String attendeeId = cursor.getString(cursor.getColumnIndexOrThrow(Table.Attendee.ID)); String eventId = cursor.getString(cursor.getColumnIndexOrThrow(Table.Attendee.EVENT_ID)); long checkin = cursor.getLong(cursor.getColumnIndexOrThrow(Table.Attendee.CHECKIN)); long serverCheckin = postCheckIn(attendeeId, eventId, checkin == 0, cookie); if (serverCheckin >= 0) { ContentValues values = new ContentValues(); values.put(Table.Attendee.CHECKIN_MODIFIED, false); if (0 == serverCheckin) { values.putNull(Table.Attendee.CHECKIN); } else { values.put(Table.Attendee.CHECKIN, serverCheckin); } provider.update(Table.ATTENDEE.getItemUri(eventId, attendeeId), values, null, null); ++syncCount; } } Log.d(TAG, syncCount + " checkin(s) synced."); } catch (RemoteException e) { e.printStackTrace(); } finally { if (cursor != null) { cursor.close(); } } }
From source file:net.peterkuterna.android.apps.devoxxfrsched.service.CfpSyncService.java
@Override protected void doSync(Intent intent) throws Exception { Log.d(TAG, "Start sync"); final Context context = this; final SharedPreferences settings = Prefs.get(context); final int localVersion = settings.getInt(DevoxxPrefs.CFP_LOCAL_VERSION, VERSION_NONE); final long startLocal = System.currentTimeMillis(); final boolean localParse = localVersion < VERSION_CURRENT; Log.d(TAG, "found localVersion=" + localVersion + " and VERSION_CURRENT=" + VERSION_CURRENT); if (localParse) { // Parse values from local cache first mLocalExecutor.execute(R.xml.search_suggest, new SearchSuggestHandler()); mLocalExecutor.execute(R.xml.rooms, new RoomsHandler()); mLocalExecutor.execute(R.xml.tracks, new TracksHandler()); mLocalExecutor.execute(R.xml.presentationtypes, new SessionTypesHandler()); mLocalExecutor.execute(context, "cache-speakers.json", new SpeakersHandler()); mLocalExecutor.execute(context, "cache-presentations.json", new SessionsHandler()); mLocalExecutor.execute(context, "cache-schedule.json", new ScheduleHandler()); // Save local parsed version settings.edit().putInt(DevoxxPrefs.CFP_LOCAL_VERSION, VERSION_CURRENT).commit(); final ContentValues values = new ContentValues(); values.put(Sessions.SESSION_NEW, 0); getContentResolver().update(Sessions.CONTENT_NEW_URI, values, null, null); }/* ww w . jav a 2 s .c o m*/ Log.d(TAG, "Local sync took " + (System.currentTimeMillis() - startLocal) + "ms"); final CfpSyncManager syncManager = new CfpSyncManager(context); if (syncManager.shouldPerformRemoteSync(Intent.ACTION_SYNC.equals(intent.getAction()))) { Log.d(TAG, "Should perform remote sync"); final long startRemote = System.currentTimeMillis(); Editor prefsEditor = syncManager.hasRemoteContentChanged(mHttpClient); if (prefsEditor != null) { Log.d(TAG, "Remote content was changed"); mRemoteExecutor.executeGet(SPEAKERS_URL, new SpeakersHandler()); mRemoteExecutor.executeGet(PRESENTATIONS_URL, new SessionsHandler()); mRemoteExecutor.executeGet(SCHEDULE_URL, new ScheduleHandler()); prefsEditor.commit(); } Log.d(TAG, "Remote sync took " + (System.currentTimeMillis() - startRemote) + "ms"); } else { Log.d(TAG, "Should not perform remote sync"); } final CfpDatabase database = new CfpDatabase(this); database.cleanupLinkTables(); if (!localParse) { final NotifierManager notifierManager = new NotifierManager(this); notifierManager.notifyNewSessions(); } Log.d(TAG, "Sync finished"); }
From source file:com.kku.apps.pricesearch.util.Utils.java
public static void entryHistory(Context context, ListItem item) { final ContentValues cv = new ContentValues(); cv.put(HistoryColumns.KEYWORDS, item.getKeywords()); cv.put(HistoryColumns.NAME, item.getName()); if (item.getImage() != null) { cv.put(HistoryColumns.IMAGE, getByteImage(item.getImage())); }// ww w. j a v a 2 s. c o m cv.put(HistoryColumns.DATE, Utils.getDate()); final AsyncQueryHandler dbHandler = new AsyncQueryHandler(context.getContentResolver()) { @Override protected void onQueryComplete(int token, Object cookie, Cursor cursor) { super.onQueryComplete(token, cookie, cursor); } }; dbHandler.startInsert(0, null, SearchContract.URI_HISTORY, cv); }
From source file:edu.stanford.mobisocial.dungbeetle.Helpers.java
/** * @see Helpers#sendMessage(Context, Collection, DbObject) *///from w w w . j av a 2 s . c om @Deprecated public static void sendIM(final Context c, final Collection<Contact> contacts, final String msg) { Uri url = Uri.parse(DungBeetleContentProvider.CONTENT_URI + "/out"); ContentValues values = new ContentValues(); JSONObject obj = IMObj.json(msg); values.put(DbObject.JSON, obj.toString()); String to = buildAddresses(contacts); values.put(DbObject.DESTINATION, to); values.put(DbObject.TYPE, IMObj.TYPE); c.getContentResolver().insert(url, values); }
From source file:com.example.android.myargmenuplanner.data.FetchJsonDataTask.java
private void getDataIngrFromJson(String JsonStr) throws JSONException { final String JSON_LIST = "ingredients"; final String JSON_NAME = "name"; final String JSON_QTY = "qty"; final String JSON_UNIT = "unit"; final String JSON_ID_FOOD = "id_food"; try {//www .j a v a2s . c om JSONObject dataJson = new JSONObject(JsonStr); JSONArray ingrArray = dataJson.getJSONArray(JSON_LIST); Vector<ContentValues> cVVector = new Vector<ContentValues>(ingrArray.length()); for (int i = 0; i < ingrArray.length(); i++) { JSONObject ingr = ingrArray.getJSONObject(i); String id_food = ingr.getString(JSON_ID_FOOD); String name = ingr.getString(JSON_NAME); String qty = ingr.getString(JSON_QTY); String unit = ingr.getString(JSON_UNIT); ContentValues values = new ContentValues(); values.put(IngrEntry.COLUMN_ID_FOOD, id_food); values.put(IngrEntry.COLUMN_NAME, name); values.put(IngrEntry.COLUMN_QTY, qty); values.put(IngrEntry.COLUMN_UNIT, unit); cVVector.add(values); } int inserted = 0; // delete database int rowdeleted = mContext.getContentResolver().delete(IngrEntry.CONTENT_URI, null, null); // // add to database Log.i(LOG_TAG, "Creando registros en base de datos. Tabla Ingredientes "); if (cVVector.size() > 0) { ContentValues[] cvArray = new ContentValues[cVVector.size()]; cVVector.toArray(cvArray); inserted = mContext.getContentResolver().bulkInsert(IngrEntry.CONTENT_URI, cvArray); Log.i(LOG_TAG, "Registros nuevos creados en Tabla Ingredientes: " + inserted); } } catch (JSONException e) { Log.e(LOG_TAG, e.getMessage(), e); e.printStackTrace(); } }
From source file:grytsenko.coworkers.web.Employee.java
/** * Returns data about full name for {@link ContentResolver}. * //from w w w. j a va 2 s .c om * @param preferNative * shows that name in native language is preferred. * * @return the set of values. */ public ContentValues getFullName(boolean preferNative) { if (preferNative && hasNative()) { ContentValues values = new ContentValues(); values.put(StructuredName.GIVEN_NAME, firstNameNative); values.put(StructuredName.FAMILY_NAME, lastNameNative); return values; } ContentValues values = new ContentValues(); values.put(StructuredName.GIVEN_NAME, firstName); values.put(StructuredName.FAMILY_NAME, lastName); return values; }
From source file:com.liferay.alerts.model.Alert.java
public ContentValues toContentValues() { ContentValues values = new ContentValues(); values.put(USER_ID, _userId);// ww w . j a va 2s . c o m values.put(PAYLOAD, _payload.toString()); values.put(READ, (_read ? 1 : 0)); values.put(TIMESTAMP, _timestamp); return values; }
From source file:com.example.orangeweather.JSONWeatherParser.java
public static HashMap<String, ContentValues> getWeather3(JSONObject jObj) throws JSONException { ContentValues cvWeather = new ContentValues(); ContentValues cvCity = new ContentValues(); JSONObject coordObj = getObject("coord", jObj); cvCity.put(CityTags.CITY_NAME, getString("name", jObj)); cvCity.put("_id", getInt("id", jObj)); cvWeather.put("_id", getInt("id", jObj)); cvWeather.put(WeatherTags.WEATHER_DT, getInt("dt", jObj)); cvCity.put(CityTags.CITY_COORD, getDMSCoordinates(getFloat("lat", coordObj), getFloat("lon", coordObj))); JSONObject sysObj = getObject("sys", jObj); cvCity.put(CityTags.CITY_SYS_COUNTRY, getString("country", sysObj)); if (sysObj.has("sunrise")) { cvWeather.put(WeatherTags.WEATHER_SYS_SUNRISE, getInt("sunrise", sysObj)); }// w w w. j av a 2 s. c om if (sysObj.has("sunset")) { cvWeather.put(WeatherTags.WEATHER_SYS_SUNSET, getInt("sunset", sysObj)); } JSONArray jArr = jObj.getJSONArray("weather"); JSONObject JSONWeather = jArr.getJSONObject(0); cvWeather.put(WeatherTags.WEATHER_CONDITION_DESC, getString("description", JSONWeather)); cvWeather.put(WeatherTags.WEATHER_CONDITION_MAIN, getString("main", JSONWeather)); JSONObject mainObj = getObject("main", jObj); cvWeather.put(WeatherTags.WEATHER_MAIN_HUMIDITY, getInt("humidity", mainObj)); cvWeather.put(WeatherTags.WEATHER_MAIN_PRESSURE, getInt("pressure", mainObj)); cvWeather.put(WeatherTags.WEATHER_MAIN_TEMP_MAX, getTemperatureString(getFloat("temp_max", mainObj))); cvWeather.put(WeatherTags.WEATHER_MAIN_TEMP_MIN, getTemperatureString(getFloat("temp_min", mainObj))); cvWeather.put(WeatherTags.WEATHER_MAIN_TEMP, getTemperatureString(getFloat("temp", mainObj))); JSONObject wObj = getObject("wind", jObj); cvWeather.put(WeatherTags.WEATHER_WIND_SPEED, getFloat("speed", wObj)); cvWeather.put(WeatherTags.WEATHER_WIND_DEG, getInt("deg", wObj)); if (wObj.has("var_beg")) { cvWeather.put(WeatherTags.WEATHER_WIND_VAR_BEG, getInt("var_beg", wObj)); } if (wObj.has("var_end")) { cvWeather.put(WeatherTags.WEATHER_WIND_VAR_END, getInt("var_end", wObj)); } JSONObject cObj = getObject("clouds", jObj); cvWeather.put(WeatherTags.WEATHER_CLOUDS_ALL, getInt("all", cObj)); HashMap<String, ContentValues> hm = new HashMap<String, ContentValues>(); hm.put(CityTags.OBJECT_TAG, cvCity); hm.put(WeatherTags.OBJECT_TAG, cvWeather); return hm; }
From source file:com.frostwire.android.gui.Librarian.java
public String renameFile(final Context context, FileDescriptor fd, String newFileName) { try {//w ww . j a v a2 s .c o m String filePath = fd.filePath; File oldFile = new File(filePath); String ext = FilenameUtils.getExtension(filePath); File newFile = new File(oldFile.getParentFile(), newFileName + '.' + ext); ContentResolver cr = context.getContentResolver(); ContentValues values = new ContentValues(); values.put(MediaColumns.DATA, newFile.getAbsolutePath()); values.put(MediaColumns.DISPLAY_NAME, FilenameUtils.getBaseName(newFileName)); values.put(MediaColumns.TITLE, FilenameUtils.getBaseName(newFileName)); TableFetcher fetcher = TableFetchers.getFetcher(fd.fileType); cr.update(fetcher.getContentUri(), values, BaseColumns._ID + "=?", new String[] { String.valueOf(fd.id) }); oldFile.renameTo(newFile); return newFile.getAbsolutePath(); } catch (Throwable e) { Log.e(TAG, "Failed to rename file: " + fd, e); } return null; }