List of usage examples for android.content ContentValues getAsString
public String getAsString(String key)
From source file:at.bitfire.ical4android.AndroidTask.java
protected void populateTask(ContentValues values) throws FileNotFoundException, RemoteException, ParseException { task.uid = values.getAsString(Tasks._UID); task.summary = values.getAsString(Tasks.TITLE); task.location = values.getAsString(Tasks.LOCATION); if (values.containsKey(Tasks.GEO)) { String geo = values.getAsString(Tasks.GEO); if (geo != null) task.geoPosition = new Geo(geo); }//from w w w . j av a 2s . c o m ; task.description = StringUtils.stripToNull(values.getAsString(Tasks.DESCRIPTION)); task.url = StringUtils.stripToNull(values.getAsString(Tasks.URL)); String organizer = values.getAsString(Tasks.ORGANIZER); if (!TextUtils.isEmpty(organizer)) try { task.organizer = new Organizer("mailto:" + values.getAsString(Tasks.ORGANIZER)); } catch (URISyntaxException e) { Log.w(TAG, "Invalid ORGANIZER email", e); } Integer priority = values.getAsInteger(Tasks.PRIORITY); if (priority != null) task.priority = priority; Integer classification = values.getAsInteger(Tasks.CLASSIFICATION); if (classification != null) switch (classification) { case Tasks.CLASSIFICATION_PUBLIC: task.classification = Clazz.PUBLIC; break; case Tasks.CLASSIFICATION_CONFIDENTIAL: task.classification = Clazz.CONFIDENTIAL; break; default: task.classification = Clazz.PRIVATE; } Long completed = values.getAsLong(Tasks.COMPLETED); if (completed != null) // COMPLETED must always be a DATE-TIME task.completedAt = new Completed(new DateTime(completed)); Integer percentComplete = values.getAsInteger(Tasks.PERCENT_COMPLETE); if (percentComplete != null) task.percentComplete = percentComplete; Integer status = values.getAsInteger(Tasks.STATUS); if (status != null) switch (status) { case Tasks.STATUS_IN_PROCESS: task.status = Status.VTODO_IN_PROCESS; break; case Tasks.STATUS_COMPLETED: task.status = Status.VTODO_COMPLETED; break; case Tasks.STATUS_CANCELLED: task.status = Status.VTODO_CANCELLED; break; default: task.status = Status.VTODO_NEEDS_ACTION; } boolean allDay = false; if (values.getAsInteger(Tasks.IS_ALLDAY) != null) allDay = values.getAsInteger(Tasks.IS_ALLDAY) != 0; String tzID = values.getAsString(Tasks.TZ); TimeZone tz = (tzID != null) ? DateUtils.tzRegistry.getTimeZone(tzID) : null; Long createdAt = values.getAsLong(Tasks.CREATED); if (createdAt != null) task.createdAt = createdAt; Long lastModified = values.getAsLong(Tasks.LAST_MODIFIED); if (lastModified != null) task.lastModified = lastModified; Long dtStart = values.getAsLong(Tasks.DTSTART); if (dtStart != null) { long ts = dtStart; Date dt; if (allDay) dt = new Date(ts); else { dt = new DateTime(ts); if (tz != null) ((DateTime) dt).setTimeZone(tz); } task.dtStart = new DtStart(dt); } Long due = values.getAsLong(Tasks.DUE); if (due != null) { long ts = due; Date dt; if (allDay) dt = new Date(ts); else { dt = new DateTime(ts); if (tz != null) ((DateTime) dt).setTimeZone(tz); } task.due = new Due(dt); } String duration = values.getAsString(Tasks.DURATION); if (duration != null) task.duration = new Duration(new Dur(duration)); String rDate = values.getAsString(Tasks.RDATE); if (rDate != null) task.getRDates().add((RDate) DateUtils.androidStringToRecurrenceSet(rDate, RDate.class, allDay)); String exDate = values.getAsString(Tasks.EXDATE); if (exDate != null) task.getExDates().add((ExDate) DateUtils.androidStringToRecurrenceSet(exDate, ExDate.class, allDay)); String rRule = values.getAsString(Tasks.RRULE); if (rRule != null) task.rRule = new RRule(rRule); }
From source file:com.csipsimple.backup.Columns.java
public JSONObject contentValueToJSON(ContentValues cv) { JSONObject json = new JSONObject(); for (int i = 0; i < names.size(); i++) { if (!cv.containsKey(names.get(i))) { continue; }//from w w w. j ava 2s. com try { String name = names.get(i); switch (types.get(i)) { case STRING: json.put(name, cv.getAsString(name)); break; case INT: json.put(name, cv.getAsInteger(name)); break; case LONG: json.put(name, cv.getAsLong(name)); break; case FLOAT: json.put(name, cv.getAsFloat(name)); break; case DOUBLE: json.put(name, cv.getAsDouble(name)); break; case BOOLEAN: json.put(name, cv.getAsBoolean(name)); break; default: Log.w("Col", "Invalid type, can't unserialize " + types.get(i)); } } catch (JSONException e) { Log.e("Col", "Invalid type, can't unserialize ", e); } } return json; }
From source file:org.coocood.vcontentprovider.VContentProvider.java
/** * If the primary key value is given, either in ContentValues or uri, this * implementation will automatically intert the row if not exists. * // w ww . ja va 2 s .c o m * @see android.content.ContentProvider#update(android.net.Uri, * android.content.ContentValues, java.lang.String, java.lang.String[]) */ @Override public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) { int affectedRows = 0; String tableName = getTableName(uri); String idPath = getIdPath(uri); if (idPath == null) idPath = values.getAsString("_id"); db = mOpenHelper.getWritableDatabase(); if (idPath != null) { db.beginTransaction(); try { affectedRows = db.update(tableName, values, finalSelection(idPath, selection), null); if (affectedRows == 0) { values.put("_id", Long.parseLong(idPath)); if (db.insert(tableName, null, values) != -1) affectedRows = 1; } db.setTransactionSuccessful(); } finally { db.endTransaction(); } } else { affectedRows = db.update(tableName, values, finalSelection(idPath, selection), selectionArgs); } notifyChange(uri, affectedRows); return affectedRows; }
From source file:com.partypoker.poker.engagement.reach.EngagementReachInteractiveContent.java
EngagementReachInteractiveContent(CampaignId campaignId, ContentValues values) throws JSONException { /* Base fields */ super(campaignId, values); /* Behavior */ String deliveryTime = values.getAsString(DELIVERY_TIME); if (deliveryTime.equals("s")) mBehavior = Behavior.SESSION;//from w w w . jav a2 s . c o m else mBehavior = Behavior.ANYTIME; /* Notification type */ mSystemNotification = "s".equals(values.getAsString(NOTIFICATION_TYPE)); /* Is notification closeable? */ mNotiticationCloseable = parseBoolean(values, NOTIFICATION_CLOSEABLE); /* Has notification icon? */ mNotificationIcon = parseBoolean(values, NOTIFICATION_ICON); /* Sound and vibration */ mNotificationSound = parseBoolean(values, NOTIFICATION_SOUND); mNotificationVibrate = parseBoolean(values, NOTIFICATION_VIBRATION); /* Parse texts */ mNotificationTitle = values.getAsString(NOTIFICATION_TITLE); mNotificationMessage = values.getAsString(NOTIFICATION_MESSAGE); /* Big text */ mNotificationBigText = values.getAsString(NOTIFICATION_BIG_TEXT); /* Big picture */ mNotificationBigPicture = values.getAsString(NOTIFICATION_BIG_PICTURE); }
From source file:com.jasonmheim.rollout.station.CoreContentProvider.java
@Override public Uri insert(Uri uri, ContentValues values) { // TODO: make this a constant, or even better, create static helper methods String valuesAsString = values.getAsString("StationList"); try {// w w w . j av a 2 s . com StationList newStationList = gson.fromJson(valuesAsString, StationList.class); internalInsert(newStationList); } catch (RuntimeException ex) { Log.e("Rollout", "Insert deserialization exception", ex); } return Constants.STATION_URI; }
From source file:de.uni_koblenz_landau.apow.db.SyncDBHelper.java
/** * Updates a table with given values./*from w w w . ja v a2 s. c o m*/ * @param values Values * @param table Table * @return Affected rows */ private int updateTable(ContentValues values, String table) { // check if uuid exists in table int affectedRows = 0; String uuid = values.getAsString("uuid"); int dirty = isDirty(table, uuid); // row not in table if (dirty == -1) { // insert mDatabase.insert(table, null, values); affectedRows++; } else if (dirty == 0) { // replace mDatabase.update(table, values, "uuid = '" + uuid + "'", null); affectedRows++; } else if (dirty == 1) { // replace mDatabase.update(table, values, "uuid = '" + uuid + "'", null); setDirty(table, uuid, false); } return affectedRows; }
From source file:com.concentricsky.android.khanacademy.data.remote.LibraryUpdaterTask.java
private void insertTopicVideo(SQLiteDatabase tempDb, ContentValues values) { // This values is for a video. ContentValues v = new ContentValues(); v.put("topic_id", values.getAsString("parentTopic_id")); v.put("video_id", values.getAsString("readable_id")); tempDb.insertWithOnConflict(topicvideoTableName, null, v, SQLiteDatabase.CONFLICT_IGNORE); }
From source file:de.uni_koblenz_landau.apow.db.SyncDBHelper.java
/** * Updates the patients table./*from w w w. j av a2s . c om*/ * @param values Values * @return Affected rows */ public int updatePatients(List<ContentValues> values) { int affectedRows = 0; for (ContentValues item : values) { // prepare relations to locale IDs item.remove("patient_id"); String uuid = item.getAsString("uuid"); item.remove("uuid"); int id = getPersonIDByUUID(uuid); item.put("patient_id", id); // update table affectedRows += updatePatientTable(item); } return affectedRows; }
From source file:th.in.ffc.person.visit.VisitAncPregnancyActivity.java
private boolean doSaveRiskFragment() { FragmentManager fm = getSupportFragmentManager(); for (String tag : getDeleteList()) { Uri uri = VisitAncRisk.getContentUri(getPid(), mPregNo, tag); int del = getContentResolver().delete(uri, null, null); Log.d(TAG, "deleted=" + del + " uri=" + uri.toString()); }// www. j av a 2 s. c o m ArrayList<String> codeList = new ArrayList<String>(); for (String tag : getEditList()) { AncRiskFragment f = (AncRiskFragment) fm.findFragmentByTag(tag); if (f != null) { EditTransaction subEt = beginTransaction(); f.onSave(subEt); if (subEt.canCommit()) { // check for duplication RiskCode String code = subEt.getContentValues().getAsString(VisitAncRisk.CODE); if (!isAddedCode(codeList, code)) { codeList.add(code); } else { Toast.makeText(this, "duplicate", Toast.LENGTH_SHORT).show(); return false; } if (f.action.equals(Action.INSERT)) { ContentValues sCv = subEt.getContentValues(); String riskCode = sCv.getAsString(VisitAncRisk.CODE); f.action = Action.EDIT; f.key = riskCode; sCv.put(VisitAncPregnancy._PID, getPid()); sCv.put(VisitAncPregnancy._PCUCODEPERSON, getPcuCode()); subEt.retrieveData(VisitAncPregnancy._PREGNO, PregNo, false, 1, 99, "1-99"); Uri insert = subEt.commit(VisitAncRisk.CONTENT_URI); Log.d(TAG, "insert=" + insert.toString()); } else if (f.action.equals(Action.EDIT)) { Uri updateUri = VisitAncRisk.getContentUri(getPid(), mPregNo, f.key); int u = subEt.commit(updateUri, null, null); Log.d(TAG, "uri=" + u); } } else { return false; } } } return true; }
From source file:de.uni_koblenz_landau.apow.db.SyncDBHelper.java
/** * Updates the obs table./*from www. j a v a2s . c o m*/ * @param values Values * @return Affected rows */ public int updateObs(List<ContentValues> values) { int affectedRows = 0; for (ContentValues item : values) { // prepare relations to locale IDs item.remove("obs_id"); String personUUID = item.getAsString("person_id"); String encounterUUID = item.getAsString("encounter_id"); String obsGroupUUID = item.getAsString("obs_group_id"); item.remove("person_id"); item.remove("encounter_id"); item.remove("obs_group_id"); item.put("person_id", getPersonIDByUUID(personUUID)); item.put("encounter_id", getEncounterIDByUUID(encounterUUID)); if (obsGroupUUID != null) { item.put("obs_group_id", getObsIDByUUID(obsGroupUUID)); } affectedRows += updateTable(item, "obs"); } return affectedRows; }