List of usage examples for android.content ContentValues put
public void put(String key, byte[] value)
From source file:com.hufeiya.SignIn.persistence.TopekaDatabaseHelper.java
private void fillCategory(SQLiteDatabase db, ContentValues values, JSONObject category, String categoryId) throws JSONException { values.clear();//from www . jav a2 s.c om values.put(CategoryTable.COLUMN_ID, categoryId); values.put(CategoryTable.COLUMN_NAME, category.getString(JsonAttributes.NAME)); values.put(CategoryTable.COLUMN_THEME, category.getString(JsonAttributes.THEME)); values.put(CategoryTable.COLUMN_SOLVED, category.getString(JsonAttributes.SOLVED)); db.insert(CategoryTable.NAME, null, values); }
From source file:com.clearcenter.mobile_demo.mdSyncAdapter.java
public void onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) {/*from ww w .j a v a2 s . c o m*/ String authtoken = null; Log.i(TAG, "Starting sync operation..."); try { mdSSLUtil.DisableSecurity(); // Use the account manager to request the AuthToken we'll need // to talk to our sample server. If we don't have an AuthToken // yet, this could involve a round-trip to the server to request // an AuthToken. authtoken = account_manager.blockingGetAuthToken(account, mdConstants.AUTHTOKEN_TYPE, NOTIFY_AUTH_FAILURE); final String hostname = account_manager.getUserData(account, "hostname"); long _last_sample = -1; if (last_sample.containsKey(account.name)) _last_sample = last_sample.get(account.name); // Get sync data from server... final String data = mdRest.GetSystemInfo(hostname, authtoken, _last_sample); // Something went wrong :^( if (TextUtils.isEmpty(data)) return; if (_last_sample < 0) { int count = provider.delete(mdDeviceSamples.CONTENT_URI, mdDeviceSamples.NICKNAME + " = ?", new String[] { account.name }); Log.d(TAG, "Reset database, purged " + count + " samples."); } try { JSONObject json_data = new JSONObject(data); if (json_data.has("time")) _last_sample = Long.valueOf(json_data.getString("time")); Log.d(TAG, account.name + ": last sample time-stamp: " + _last_sample); } catch (JSONException e) { Log.e(TAG, "JSONException", e); return; } last_sample.put(account.name, _last_sample); ContentValues values = new ContentValues(); values.put(mdDeviceSamples.NICKNAME, account.name); values.put(mdDeviceSamples.DATA, data); provider.insert(mdDeviceSamples.CONTENT_URI, values); String projection[] = new String[] { mdDeviceSamples.SAMPLE_ID }; Cursor cursor = provider.query(mdDeviceSamples.CONTENT_URI, projection, mdDeviceSamples.NICKNAME + " = ?", new String[] { account.name }, mdDeviceSamples.SAMPLE_ID); int rows = cursor.getCount(); Log.d(TAG, "Rows: " + rows); if (rows <= mdConstants.MAX_SAMPLES) { cursor.close(); return; } Log.d(TAG, "Samples to purge: " + (rows - mdConstants.MAX_SAMPLES)); cursor.move(rows - mdConstants.MAX_SAMPLES); int top_id = cursor.getInt(cursor.getColumnIndex(mdDeviceSamples.SAMPLE_ID)); Log.d(TAG, "Top ID: " + top_id); cursor.close(); int count = provider.delete(mdDeviceSamples.CONTENT_URI, mdDeviceSamples.SAMPLE_ID + " <= ? AND " + mdDeviceSamples.NICKNAME + " = ?", new String[] { String.valueOf(top_id), account.name }); Log.d(TAG, "Purged " + count + " samples."); } catch (final RemoteException e) { Log.e(TAG, "RemoteException", e); syncResult.stats.numParseExceptions++; } catch (final AuthenticatorException e) { Log.e(TAG, "AuthenticatorException", e); syncResult.stats.numParseExceptions++; } catch (final OperationCanceledException e) { Log.e(TAG, "OperationCanceledExcetpion", e); } catch (final IOException e) { Log.e(TAG, "IOException", e); syncResult.stats.numIoExceptions++; } catch (final ParseException e) { Log.e(TAG, "ParseException", e); syncResult.stats.numParseExceptions++; } catch (final AuthenticationException e) { Log.e(TAG, "AuthenticationException", e); syncResult.stats.numAuthExceptions++; account_manager.invalidateAuthToken(mdConstants.AUTHTOKEN_TYPE, authtoken); } catch (GeneralSecurityException e) { Log.e(TAG, "GeneralSecurityException", e); } catch (final JSONException e) { Log.e(TAG, "JSONException", e); syncResult.stats.numParseExceptions++; } }
From source file:de.tudarmstadt.dvs.myhealthassistant.myhealthhub.services.transformationmanager.database.LocalTransformationDBMS.java
public boolean addDateOfTraffic(String date, int trafficId) { ContentValues values = new ContentValues(); values.put(LocalTransformationDB.COLUMN_TRAFFIC_ID, trafficId); values.put(LocalTransformationDB.COLUMN_DATE_TEXT, date); long insertId = database.insert(LocalTransformationDB.TABLE_DATE_TO_TRAFFIC, null, values); if (insertId == -1) { Log.e(TAG, "addTraffic failed at:[" + date + "]"); }//from w ww. j a va2 s .c o m return insertId != -1; }
From source file:cn.loveapple.client.android.database.impl.TemperatureDaoImpl.java
/** * // w w w . j av a2 s. co m * {@inheritDoc} */ @Override public TemperatureEntity save(TemperatureEntity source) { TemperatureEntity result = null; ContentValues values = new ContentValues(); values.put(COLUMN_COITUS_FLG, source.getCoitusFlg()); values.put(COLUMN_DATE, source.getDate()); values.put(COLUMN_TIMESTAMP, source.getTimestamp()); values.put(COLUMN_TEMPERATURE, source.getTemperature()); values.put(COLUMN_MENSTRUATION_FLG, source.getMenstruationFlg()); values.put(COLUMN_DYSMENORRHEA_FLG, source.getDysmenorrheaFlg()); values.put(COLUMN_LEUKORRHEA, source.getLeukorrhea()); values.put(COLUMN_MENSTRUATION_LEVEL, source.getMenstruationLevel()); values.put(COLUMN_MENSTRUATION_CYCLE, source.getMenstruationCycle()); try { writableDb = getWritableDb(); int colNum = writableDb.update(TABLE_NAME, values, COLUMN_DATE + "=?", new String[] { source.getDate() }); if (colNum < 1) { writableDb.insert(TABLE_NAME, null, values); Log.i(LOG_TAG, "update : " + ToStringBuilder.reflectionToString(values)); } result = findByDate(source.getDate()); } finally { writableDb.close(); } return result; }
From source file:de.tudarmstadt.dvs.myhealthassistant.myhealthhub.services.transformationmanager.database.LocalTransformationDBMS.java
public boolean addTraffic(String date, int trafficType, double xValue, double yValue) { ContentValues values = new ContentValues(); values.put(LocalTransformationDB.COLUMN_DATE_TEXT, date); values.put(LocalTransformationDB.COLUMN_TYPE, trafficType); values.put(LocalTransformationDB.COLUMN_X_AXIS, xValue); values.put(LocalTransformationDB.COLUMN_Y_AXIS, yValue); long insertId = database.insert(LocalTransformationDB.TABLE_TRAFFIC_MON, null, values); if (insertId == -1) { Log.e(TAG, "addTraffic failed at:[" + date + "; type:" + trafficType + "; " + xValue + "; " + yValue + "]"); }// w ww . ja v a 2s .co m return insertId != -1; }
From source file:com.nononsenseapps.notepad.sync.googleapi.GoogleTask.java
public ContentValues toGTasksBackRefContentValues(int pos) { ContentValues values = new ContentValues(); values.put(NotePad.GTasks.COLUMN_NAME_DB_ID, pos); return values; }
From source file:net.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.getVerse()); Verse verse = mynote.getVerse();// w ww .j a v a 2 s. co m String v11nName = getVersification(verse); // Gets the current system time in milliseconds Long now = Long.valueOf(System.currentTimeMillis()); ContentValues newValues = new ContentValues(); newValues.put(MyNoteColumn.KEY, verse.getOsisID()); 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:com.arisprung.tailgate.GCMIntentService.java
private void parseLocationJSON(JSONObject jObj) { try {//w w w . jav a 2s .c om getContentResolver().delete(CONTENT_URI_LOCATION, null, null); JSONArray array = jObj.getJSONArray("json_array_location"); for (int i = 0; i < array.length(); i++) { // **line 2** JSONObject childJSONObject = array.getJSONObject(i); String faceID = childJSONObject.getString("faceID"); String logn = childJSONObject.getString("lognitude"); String lati = childJSONObject.getString("latitude"); String name = childJSONObject.getString("user"); ContentValues contentValues = new ContentValues(); contentValues.put(TailGateMessagesDataBase.COLUMN_LOCATION_FACE_ID, faceID); contentValues.put(TailGateMessagesDataBase.COLUMN_LOCATION_FACE_NAME, name); contentValues.put(TailGateMessagesDataBase.COLUMN_LONGNITUDE, logn); contentValues.put(TailGateMessagesDataBase.COLUMN_LANITUDE, lati); getContentResolver().insert(CONTENT_URI_LOCATION, contentValues); } } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:de.tudarmstadt.dvs.myhealthassistant.myhealthhub.services.transformationmanager.database.LocalTransformationDBMS.java
public boolean addTransformation(long bundleId, String transformationName, String producedEventType, List<String> requiredEventTypes, int costs) { // generate semicolon separated list of required event types String requiredEvents = ""; for (String type : requiredEventTypes) { requiredEvents += type + ";"; }/* w w w . jav a 2 s . c om*/ ContentValues values = new ContentValues(); values.put(LocalTransformationDB.COLUMN_BUNDLE_ID, bundleId); values.put(LocalTransformationDB.COLUMN_TRANSFORMATION_NAME, transformationName); values.put(LocalTransformationDB.COLUMN_PRODUCED_EVENT_TYPE, producedEventType); values.put(LocalTransformationDB.COLUMN_REQUIRED_EVENT_TYPES, requiredEvents); values.put(LocalTransformationDB.COLUMN_TRANSFORMATION_COSTS, costs); long insertId = database.insert(LocalTransformationDB.TABLE_LOCAL_TRANSFORMATIONS, null, values); return insertId != -1; }
From source file:net.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.getVerse()); Verse verse = mynote.getVerse();/* ww w . j a va 2 s . c om*/ String v11nName = getVersification(verse); // Gets the current system time in milliseconds Long now = Long.valueOf(System.currentTimeMillis()); ContentValues newValues = new ContentValues(); newValues.put(MyNoteColumn.KEY, verse.getOsisID()); 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()); }