List of usage examples for android.content ContentValues getAsInteger
public Integer getAsInteger(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 ww w.ja va 2s .co 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:at.bitfire.vcard4android.AndroidContact.java
protected void populateEvent(ContentValues row) { SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd", Locale.US); try {/*from w w w. j a va2s. c o m*/ Date date = formatter.parse(row.getAsString(CommonDataKinds.Event.START_DATE)); if (row.containsKey(Event.TYPE)) switch (row.getAsInteger(Event.TYPE)) { case Event.TYPE_ANNIVERSARY: contact.anniversary = new Anniversary(date); break; case Event.TYPE_BIRTHDAY: contact.birthDay = new Birthday(date); break; } } catch (ParseException e) { Constants.log.warn("Couldn't parse birthday/anniversary date from database", e); } }
From source file:at.bitfire.vcard4android.AndroidContact.java
protected void populateRelation(ContentValues row) { String name = row.getAsString(Relation.NAME); if (TextUtils.isEmpty(name)) return;/*w ww . j av a 2s. c o m*/ Related related = new Related(); related.setText(name); if (row.containsKey(Relation.TYPE)) switch (row.getAsInteger(Relation.TYPE)) { case Relation.TYPE_ASSISTANT: case Relation.TYPE_MANAGER: related.addType(RelatedType.CO_WORKER); break; case Relation.TYPE_BROTHER: case Relation.TYPE_SISTER: related.addType(RelatedType.SIBLING); break; case Relation.TYPE_CHILD: related.addType(RelatedType.CHILD); break; case Relation.TYPE_DOMESTIC_PARTNER: related.addType(RelatedType.CO_RESIDENT); break; case Relation.TYPE_FRIEND: related.addType(RelatedType.FRIEND); break; case Relation.TYPE_FATHER: case Relation.TYPE_MOTHER: case Relation.TYPE_PARENT: related.addType(RelatedType.PARENT); break; case Relation.TYPE_PARTNER: case Relation.TYPE_SPOUSE: related.addType(RelatedType.SWEETHEART); break; case Relation.TYPE_RELATIVE: related.addType(RelatedType.KIN); break; } contact.getRelations().add(related); }
From source file:at.bitfire.vcard4android.AndroidContact.java
protected void populateIMPP(ContentValues row) { String handle = row.getAsString(Im.DATA); if (TextUtils.isEmpty(handle)) { Constants.log.warn("Ignoring instant messenger record without handle"); return;/*from w w w. java 2 s .c o m*/ } Impp impp = null; if (row.containsKey(Im.PROTOCOL)) switch (row.getAsInteger(Im.PROTOCOL)) { case Im.PROTOCOL_AIM: impp = Impp.aim(handle); break; case Im.PROTOCOL_MSN: impp = Impp.msn(handle); break; case Im.PROTOCOL_YAHOO: impp = Impp.yahoo(handle); break; case Im.PROTOCOL_SKYPE: impp = Impp.skype(handle); break; case Im.PROTOCOL_QQ: impp = new Impp("qq", handle); break; case Im.PROTOCOL_GOOGLE_TALK: impp = new Impp("google-talk", handle); break; case Im.PROTOCOL_ICQ: impp = Impp.icq(handle); break; case Im.PROTOCOL_JABBER: impp = Impp.xmpp(handle); break; case Im.PROTOCOL_NETMEETING: impp = new Impp("netmeeting", handle); break; case Im.PROTOCOL_CUSTOM: try { impp = new Impp(toURIScheme(row.getAsString(Im.CUSTOM_PROTOCOL)), handle); } catch (IllegalArgumentException e) { Constants.log.error("Messenger type/value can't be expressed as URI; ignoring"); } } if (impp != null) { Integer type = row.getAsInteger(Im.TYPE); if (type != null) switch (type) { case Im.TYPE_HOME: impp.addType(ImppType.HOME); break; case Im.TYPE_WORK: impp.addType(ImppType.WORK); break; case Im.TYPE_CUSTOM: String customType = row.getAsString(Im.LABEL); if (!TextUtils.isEmpty(customType)) impp.addType(ImppType.get(labelToXName(customType))); } contact.getImpps().add(impp); } }
From source file:com.openerp.orm.ORM.java
/** * Creates the./* www . j a va2s . c om*/ * * @param dbHelper * the db helper * @param values * the values * @return the int */ public int create(BaseDBHelper dbHelper, ContentValues data_values) { int newId = 0; ContentValues values = new ContentValues(); if (data_values.containsKey("id")) { newId = data_values.getAsInteger("id"); } else { newId = createRecordOnserver(dbHelper, data_values); data_values.put("id", newId); } for (Fields field : dbHelper.getColumns()) { values.put(field.getName(), data_values.getAsString(field.getName())); } values.put("oea_name", OpenERPAccountManager.currentUser(context).getAndroidName()); // Handling Many2Many Records HashMap<String, Object> many2manycols = dbHelper.getMany2ManyColumns(); for (String key : many2manycols.keySet()) { try { JSONArray m2mArray = new JSONArray(values.getAsString(key)); Many2Many m2m = (Many2Many) many2manycols.get(key); createM2MRecords(values.getAsString("id"), m2mArray, key, dbHelper, m2m, values); } catch (Exception e) { } values.remove(key); } // Handling Many2One Record HashMap<String, Object> many2onecols = dbHelper.getMany2OneColumns(); for (String key : many2onecols.keySet()) { try { if (!values.getAsString(key).equals("false")) { JSONArray m2oArray = new JSONArray(values.getAsString(key)); values.put(key, many2oneRecord(m2oArray)); List<Integer> list = new ArrayList<Integer>(); int m2o_id = Integer.parseInt(many2oneRecord(m2oArray)); list.add(m2o_id); BaseDBHelper m2oDb = ((Many2One) many2onecols.get(key)).getM2OObject(); if (!m2oDb.hasRecord(m2oDb, m2o_id)) { oe_obj.syncReferenceTables(m2oDb, list, false); } } } catch (Exception e) { } } SQLiteDatabase db = getWritableDatabase(); db.insert(modelToTable(dbHelper.getModelName()), null, values); db.close(); return newId; }
From source file:com.granita.icloudcalsync.resource.LocalAddressBook.java
protected void populateRelation(Contact c, ContentValues row) throws RemoteException { String name = row.getAsString(Relation.NAME); // find relation by name or create new one Related related = null;/*from w w w. j a va 2s .c o m*/ for (Related rel : c.getRelations()) { if (rel.getText().equals(name)) { related = rel; break; } } if (related == null) { related = new Related(); c.getRelations().add(related); } Set<RelatedType> types = related.getTypes(); switch (row.getAsInteger(Relation.TYPE)) { case Relation.TYPE_ASSISTANT: types.add(RelatedType.AGENT); break; case Relation.TYPE_BROTHER: types.add(RelatedType.SIBLING); types.add(Contact.RELATED_TYPE_BROTHER); break; case Relation.TYPE_CHILD: types.add(RelatedType.CHILD); break; case Relation.TYPE_DOMESTIC_PARTNER: types.add(RelatedType.CO_RESIDENT); break; case Relation.TYPE_FATHER: types.add(Contact.RELATED_TYPE_FATHER); break; case Relation.TYPE_FRIEND: types.add(RelatedType.FRIEND); break; case Relation.TYPE_MANAGER: types.add(Contact.RELATED_TYPE_MANAGER); break; case Relation.TYPE_MOTHER: types.add(Contact.RELATED_TYPE_MOTHER); break; case Relation.TYPE_PARENT: types.add(RelatedType.PARENT); break; case Relation.TYPE_PARTNER: types.add(RelatedType.SWEETHEART); break; case Relation.TYPE_REFERRED_BY: types.add(Contact.RELATED_TYPE_REFERRED_BY); case Relation.TYPE_RELATIVE: types.add(RelatedType.KIN); break; case Relation.TYPE_SISTER: types.add(RelatedType.SIBLING); types.add(Contact.RELATED_TYPE_SISTER); break; case Relation.TYPE_SPOUSE: types.add(RelatedType.SPOUSE); case Relation.TYPE_CUSTOM: String customType = row.getAsString(Relation.LABEL); if (StringUtils.isNotEmpty(customType)) types.add(RelatedType.get(customType)); } }
From source file:com.goliathonline.android.kegbot.io.RemoteDrinksHandler.java
/** {@inheritDoc} */ @Override//from w w w . j a v a 2s .co m public ArrayList<ContentProviderOperation> parse(JSONObject parser, ContentResolver resolver) throws JSONException, IOException { final ArrayList<ContentProviderOperation> batch = Lists.newArrayList(); // Walk document, parsing any incoming entries int drink_id = 0; JSONObject result = parser.getJSONObject("result"); JSONArray drinks = result.getJSONArray("drinks"); JSONObject drink; for (int i = 0; i < drinks.length(); i++) { if (drink_id == 0) { // && ENTRY.equals(parser.getName() // Process single spreadsheet row at a time drink = drinks.getJSONObject(i); final String drinkId = sanitizeId(drink.getString("id")); final Uri drinkUri = Drinks.buildDrinkUri(drinkId); // Check for existing details, only update when changed final ContentValues values = queryDrinkDetails(drinkUri, resolver); final long localUpdated = values.getAsLong(SyncColumns.UPDATED); final long serverUpdated = 500; //entry.getUpdated(); if (Log.isLoggable(TAG, Log.VERBOSE)) { Log.v(TAG, "found drink " + drinkId); Log.v(TAG, "found localUpdated=" + localUpdated + ", server=" + serverUpdated); } if (localUpdated != KegbotContract.UPDATED_NEVER) continue; final Uri drinkKegUri = Drinks.buildKegUri(drinkId); final Uri drinkUserUri = Drinks.buildUserUri(drinkId); // Clear any existing values for this session, treating the // incoming details as authoritative. batch.add(ContentProviderOperation.newDelete(drinkUri).build()); batch.add(ContentProviderOperation.newDelete(drinkKegUri).build()); final ContentProviderOperation.Builder builder = ContentProviderOperation .newInsert(Drinks.CONTENT_URI); builder.withValue(SyncColumns.UPDATED, serverUpdated); builder.withValue(Drinks.DRINK_ID, drinkId); // Inherit starred value from previous row if (values.containsKey(Drinks.DRINK_STARRED)) { builder.withValue(Drinks.DRINK_STARRED, values.getAsInteger(Drinks.DRINK_STARRED)); } if (drink.has("session_id")) builder.withValue(Drinks.SESSION_ID, drink.getInt("session_id")); if (drink.has("status")) builder.withValue(Drinks.STATUS, drink.getString("status")); if (drink.has("user_id")) builder.withValue(Drinks.USER_ID, drink.getString("user_id")); if (drink.has("keg_id")) builder.withValue(Drinks.KEG_ID, drink.getInt("keg_id")); if (drink.has("volume_ml")) builder.withValue(Drinks.VOLUME, drink.getDouble("volume_ml")); if (drink.has("pour_time")) builder.withValue(Drinks.POUR_TIME, drink.getString("pour_time")); // Normal session details ready, write to provider batch.add(builder.build()); // Assign kegs final int kegId = drink.getInt("keg_id"); batch.add(ContentProviderOperation.newInsert(drinkKegUri).withValue(DrinksKeg.DRINK_ID, drinkId) .withValue(DrinksKeg.KEG_ID, kegId).build()); // Assign users if (drink.has("user_id")) { final String userId = drink.getString("user_id"); batch.add(ContentProviderOperation.newInsert(drinkUserUri) .withValue(DrinksUser.DRINK_ID, drinkId).withValue(DrinksUser.USER_ID, userId).build()); } } } return batch; }
From source file:at.bitfire.davdroid.resource.LocalAddressBook.java
protected void populateRelation(Contact c, ContentValues row) { String name = row.getAsString(Relation.NAME); // don't process empty relations if (StringUtils.isEmpty(name)) return;/*from w w w . j av a 2s . c o m*/ // find relation by name or create new one Related related = null; for (Related rel : c.getRelations()) { if (name.equals(rel.getText())) { related = rel; break; } } if (related == null) { related = new Related(); c.getRelations().add(related); } Set<RelatedType> types = related.getTypes(); switch (row.getAsInteger(Relation.TYPE)) { case Relation.TYPE_ASSISTANT: types.add(RelatedType.AGENT); break; case Relation.TYPE_BROTHER: types.add(RelatedType.SIBLING); types.add(Contact.RELATED_TYPE_BROTHER); break; case Relation.TYPE_CHILD: types.add(RelatedType.CHILD); break; case Relation.TYPE_DOMESTIC_PARTNER: types.add(RelatedType.CO_RESIDENT); break; case Relation.TYPE_FATHER: types.add(Contact.RELATED_TYPE_FATHER); break; case Relation.TYPE_FRIEND: types.add(RelatedType.FRIEND); break; case Relation.TYPE_MANAGER: types.add(Contact.RELATED_TYPE_MANAGER); break; case Relation.TYPE_MOTHER: types.add(Contact.RELATED_TYPE_MOTHER); break; case Relation.TYPE_PARENT: types.add(RelatedType.PARENT); break; case Relation.TYPE_PARTNER: types.add(RelatedType.SWEETHEART); break; case Relation.TYPE_REFERRED_BY: types.add(Contact.RELATED_TYPE_REFERRED_BY); case Relation.TYPE_RELATIVE: types.add(RelatedType.KIN); break; case Relation.TYPE_SISTER: types.add(RelatedType.SIBLING); types.add(Contact.RELATED_TYPE_SISTER); break; case Relation.TYPE_SPOUSE: types.add(RelatedType.SPOUSE); case Relation.TYPE_CUSTOM: String customType = row.getAsString(Relation.LABEL); if (StringUtils.isNotEmpty(customType)) types.add(RelatedType.get(customType)); } }
From source file:at.bitfire.ical4android.AndroidEvent.java
@TargetApi(16) protected void populateAttendee(ContentValues values) { try {/* w ww .j a v a 2s . c om*/ final Attendee attendee; final String email = values.getAsString(Attendees.ATTENDEE_EMAIL), idNS, id; if (Build.VERSION.SDK_INT >= 16) { idNS = values.getAsString(Attendees.ATTENDEE_ID_NAMESPACE); id = values.getAsString(Attendees.ATTENDEE_IDENTITY); } else idNS = id = null; if (idNS != null || id != null) { // attendee identified by namespace and ID attendee = new Attendee(new URI(idNS, id, null)); if (email != null) attendee.getParameters().add(new iCalendar.Email(email)); } else // attendee identified by email address attendee = new Attendee(new URI("mailto", email, null)); final ParameterList params = attendee.getParameters(); String cn = values.getAsString(Attendees.ATTENDEE_NAME); if (cn != null) params.add(new Cn(cn)); // type int type = values.getAsInteger(Attendees.ATTENDEE_TYPE); params.add((type == Attendees.TYPE_RESOURCE) ? CuType.RESOURCE : CuType.INDIVIDUAL); // role int relationship = values.getAsInteger(Attendees.ATTENDEE_RELATIONSHIP); switch (relationship) { case Attendees.RELATIONSHIP_ORGANIZER: case Attendees.RELATIONSHIP_ATTENDEE: case Attendees.RELATIONSHIP_PERFORMER: case Attendees.RELATIONSHIP_SPEAKER: params.add((type == Attendees.TYPE_REQUIRED) ? Role.REQ_PARTICIPANT : Role.OPT_PARTICIPANT); params.add(new Rsvp(true)); break; case Attendees.RELATIONSHIP_NONE: params.add(Role.NON_PARTICIPANT); } // status switch (values.getAsInteger(Attendees.ATTENDEE_STATUS)) { case Attendees.ATTENDEE_STATUS_INVITED: params.add(PartStat.NEEDS_ACTION); break; case Attendees.ATTENDEE_STATUS_ACCEPTED: params.add(PartStat.ACCEPTED); break; case Attendees.ATTENDEE_STATUS_DECLINED: params.add(PartStat.DECLINED); break; case Attendees.ATTENDEE_STATUS_TENTATIVE: params.add(PartStat.TENTATIVE); break; } event.getAttendees().add(attendee); } catch (URISyntaxException ex) { Log.e(TAG, "Couldn't parse attendee information, ignoring", ex); } }
From source file:com.koushikdutta.superuser.MultitaskSuRequestActivity.java
void manageSocket() { new Thread() { @Override// w ww.j a v a2s . co m public void run() { try { mSocket = new LocalSocket(); mSocket.connect(new LocalSocketAddress(mSocketPath, Namespace.FILESYSTEM)); DataInputStream is = new DataInputStream(mSocket.getInputStream()); ContentValues payload = new ContentValues(); for (int i = 0; i < SU_PROTOCOL_PARAM_MAX; i++) { int nameLen = is.readInt(); if (nameLen > SU_PROTOCOL_NAME_MAX) throw new IllegalArgumentException("name length too long: " + nameLen); byte[] nameBytes = new byte[nameLen]; is.readFully(nameBytes); String name = new String(nameBytes); int dataLen = is.readInt(); if (dataLen > getValueMax(name)) throw new IllegalArgumentException(name + " data length too long: " + dataLen); byte[] dataBytes = new byte[dataLen]; is.readFully(dataBytes); String data = new String(dataBytes); payload.put(name, data); // Log.i(LOGTAG, name); // Log.i(LOGTAG, data); if ("eof".equals(name)) break; } int protocolVersion = payload.getAsInteger("version"); mCallerUid = payload.getAsInteger("from.uid"); mDesiredUid = payload.getAsByte("to.uid"); mDesiredCmd = payload.getAsString("command"); String calledBin = payload.getAsString("from.bin"); mPid = payload.getAsInteger("pid"); runOnUiThread(new Runnable() { @Override public void run() { mRequestReady = true; requestReady(); } }); if ("com.koushikdutta.superuser".equals(getPackageName())) { if (!SuHelper.CURRENT_VERSION.equals(payload.getAsString("binary.version"))) SuCheckerReceiver.doNotification(MultitaskSuRequestActivity.this); } } catch (Exception ex) { Log.i(LOGTAG, ex.getMessage(), ex); try { mSocket.close(); } catch (Exception e) { } runOnUiThread(new Runnable() { @Override public void run() { finish(); } }); } } }.start(); }