List of usage examples for android.content ContentValues getAsLong
public Long getAsLong(String key)
From source file:com.todoroo.astrid.gcal.GCalControlSet.java
@Override protected void writeToModelAfterInitialized(Task task) { if (!task.hasDueDate()) { return;//from w ww . j av a 2 s .com } if ((gcal.isDefaultCalendarSet() || calendarSelector.getSelectedItemPosition() != 0) && calendarUri == null) { try { ContentResolver cr = activity.getContentResolver(); ContentValues values = new ContentValues(); String calendarId = calendars.calendarIds[calendarSelector.getSelectedItemPosition() - 1]; values.put("calendar_id", calendarId); calendarUri = gcal.createTaskEvent(task, cr, values); if (calendarUri != null) { task.setCalendarUri(calendarUri.toString()); if (calendarSelector.getSelectedItemPosition() != 0 && !hasEvent) { // pop up the new event Intent intent = new Intent(Intent.ACTION_VIEW, calendarUri); intent.putExtra("beginTime", values.getAsLong("dtstart")); intent.putExtra("endTime", values.getAsLong("dtend")); activity.startActivity(intent); } } } catch (Exception e) { log.error(e.getMessage(), e); } } else if (calendarUri != null) { try { ContentValues updateValues = new ContentValues(); // check if we need to update the item ContentValues setValues = task.getSetValues(); if (setValues.containsKey(Task.TITLE.name)) { updateValues.put("title", task.getTitle()); } if (setValues.containsKey(Task.NOTES.name)) { updateValues.put("description", task.getNotes()); } if (setValues.containsKey(Task.DUE_DATE.name) || setValues.containsKey(Task.ESTIMATED_SECONDS.name)) { gcal.createStartAndEndDate(task, updateValues); } ContentResolver cr = activity.getContentResolver(); cr.update(calendarUri, updateValues, null, null); } catch (Exception e) { log.error("unable-to-update-calendar: " + task.getCalendarURI(), e); } } }
From source file:com.abcvoipsip.ui.favorites.FavAdapter.java
@Override public void bindView(View view, Context context, Cursor cursor) { ContentValues cv = new ContentValues(); DatabaseUtils.cursorRowToContentValues(cursor, cv); int type = ContactsWrapper.TYPE_CONTACT; if (cv.containsKey(ContactsWrapper.FIELD_TYPE)) { type = cv.getAsInteger(ContactsWrapper.FIELD_TYPE); }//from w w w. ja v a 2 s . c o m if (type == ContactsWrapper.TYPE_GROUP) { showViewForHeader(view, true); TextView tv = (TextView) view.findViewById(R.id.header_text); ImageView icon = (ImageView) view.findViewById(R.id.header_icon); PresenceStatusSpinner presSpinner = (PresenceStatusSpinner) view .findViewById(R.id.header_presence_spinner); tv.setText(cv.getAsString(SipProfile.FIELD_DISPLAY_NAME)); icon.setImageResource(WizardUtils.getWizardIconRes(cv.getAsString(SipProfile.FIELD_WIZARD))); presSpinner.setProfileId(cv.getAsLong(BaseColumns._ID)); } else { showViewForHeader(view, false); ContactsWrapper.getInstance().bindContactView(view, context, cursor); } }
From source file:com.dalaran.async.task.http.AbstractHTTPService.java
@TargetApi(Build.VERSION_CODES.HONEYCOMB) protected List<ContentValues> parseJson(JsonReader reader) throws IOException { List<ContentValues> contentValueses = new ArrayList<ContentValues>(); ContentValues values = new ContentValues(); Long threadId = 0L;/*w ww . j a v a 2 s . com*/ boolean notEnd = true; String name = ""; if (reader.hasNext()) { //todo android.util.MalformedJsonException: Use JsonReader.setLenient(true) do { switch (reader.peek()) { case BEGIN_OBJECT: values = new ContentValues(); if (threadId != 0) { values.put("threadId", threadId); } reader.beginObject(); break; case BEGIN_ARRAY: if (values != null && values.getAsLong("threadId") != null) { threadId = values.getAsLong("threadId"); } reader.beginArray(); break; case BOOLEAN: values.put(name, reader.nextBoolean()); break; case END_ARRAY: reader.endArray(); break; case END_DOCUMENT: notEnd = false; break; case END_OBJECT: contentValueses.add(values); reader.endObject(); break; case NAME: name = reader.nextName(); break; case NULL: reader.nextNull(); break; case NUMBER: values.put(name, reader.nextDouble()); break; case STRING: values.put(name, reader.nextString()); break; default: reader.skipValue(); } } while (notEnd); } return contentValueses; }
From source file:at.bitfire.ical4android.AndroidEvent.java
protected void populateEvent(ContentValues values) { event.summary = values.getAsString(Events.TITLE); event.location = values.getAsString(Events.EVENT_LOCATION); event.description = values.getAsString(Events.DESCRIPTION); final boolean allDay = values.getAsInteger(Events.ALL_DAY) != 0; final long tsStart = values.getAsLong(Events.DTSTART); final String duration = values.getAsString(Events.DURATION); String tzId;//w w w . j a v a2 s .com Long tsEnd = values.getAsLong(Events.DTEND); if (allDay) { event.setDtStart(tsStart, null); if (tsEnd == null) { Dur dur = new Dur(duration); java.util.Date dEnd = dur.getTime(new java.util.Date(tsStart)); tsEnd = dEnd.getTime(); } event.setDtEnd(tsEnd, null); } else { // use the start time zone for the end time, too // because apps like Samsung Planner allow the user to change "the" time zone but change the start time zone only tzId = values.getAsString(Events.EVENT_TIMEZONE); event.setDtStart(tsStart, tzId); if (tsEnd != null) event.setDtEnd(tsEnd, tzId); else if (!StringUtils.isEmpty(duration)) event.duration = new Duration(new Dur(duration)); } // recurrence try { String strRRule = values.getAsString(Events.RRULE); if (!StringUtils.isEmpty(strRRule)) event.rRule = new RRule(strRRule); String strRDate = values.getAsString(Events.RDATE); if (!StringUtils.isEmpty(strRDate)) { RDate rDate = (RDate) DateUtils.androidStringToRecurrenceSet(strRDate, RDate.class, allDay); event.getRDates().add(rDate); } String strExRule = values.getAsString(Events.EXRULE); if (!StringUtils.isEmpty(strExRule)) { ExRule exRule = new ExRule(); exRule.setValue(strExRule); event.exRule = exRule; } String strExDate = values.getAsString(Events.EXDATE); if (!StringUtils.isEmpty(strExDate)) { ExDate exDate = (ExDate) DateUtils.androidStringToRecurrenceSet(strExDate, ExDate.class, allDay); event.getExDates().add(exDate); } } catch (ParseException ex) { Log.w(TAG, "Couldn't parse recurrence rules, ignoring", ex); } catch (IllegalArgumentException ex) { Log.w(TAG, "Invalid recurrence rules, ignoring", ex); } if (values.containsKey(Events.ORIGINAL_INSTANCE_TIME)) { // this event is an exception of a recurring event long originalInstanceTime = values.getAsLong(Events.ORIGINAL_INSTANCE_TIME); boolean originalAllDay = false; if (values.containsKey(Events.ORIGINAL_ALL_DAY)) originalAllDay = values.getAsInteger(Events.ORIGINAL_ALL_DAY) != 0; Date originalDate = originalAllDay ? new Date(originalInstanceTime) : new DateTime(originalInstanceTime); if (originalDate instanceof DateTime) ((DateTime) originalDate).setUtc(true); event.recurrenceId = new RecurrenceId(originalDate); } // status if (values.containsKey(Events.STATUS)) switch (values.getAsInteger(Events.STATUS)) { case Events.STATUS_CONFIRMED: event.status = Status.VEVENT_CONFIRMED; break; case Events.STATUS_TENTATIVE: event.status = Status.VEVENT_TENTATIVE; break; case Events.STATUS_CANCELED: event.status = Status.VEVENT_CANCELLED; } // availability event.opaque = values.getAsInteger(Events.AVAILABILITY) != Events.AVAILABILITY_FREE; // set ORGANIZER if there's attendee data if (values.getAsInteger(Events.HAS_ATTENDEE_DATA) != 0 && values.containsKey(Events.ORGANIZER)) try { event.organizer = new Organizer(new URI("mailto", values.getAsString(Events.ORGANIZER), null)); } catch (URISyntaxException ex) { Log.e(TAG, "Error when creating ORGANIZER mailto URI, ignoring", ex); } // classification switch (values.getAsInteger(Events.ACCESS_LEVEL)) { case Events.ACCESS_CONFIDENTIAL: case Events.ACCESS_PRIVATE: event.forPublic = false; break; case Events.ACCESS_PUBLIC: event.forPublic = true; } }
From source file:export.UploadManager.java
public long load(String uploaderName) { String from[] = new String[] { "_id", Constants.DB.ACCOUNT.NAME, Constants.DB.ACCOUNT.AUTH_CONFIG, Constants.DB.ACCOUNT.FLAGS }; String args[] = { uploaderName }; Cursor c = mDB.query(Constants.DB.ACCOUNT.TABLE, from, Constants.DB.ACCOUNT.NAME + " = ?", args, null, null, null, null);/*from ww w . j a v a2 s . c o m*/ long id = -1; if (c.moveToFirst()) { ContentValues config = DBHelper.get(c); id = config.getAsLong("_id"); add(config); } c.close(); return id; }
From source file:edu.mit.mobile.android.locast.sync.SyncEngine.java
/** * The mobile needs to store the modified date in its own timescale, so it can tell if a local * update is newer than that of the server. * * @param cv//w ww .ja va 2s.c om * @param fromKey * @param localOffset */ private void correctServerOffset(ContentValues cv, String fromKey, String destKey, long localOffset) { final long serverModified = cv.getAsLong(fromKey); cv.put(destKey, serverModified + localOffset); }
From source file:org.runnerup.export.UploadManager.java
public long load(String uploaderName) { String from[] = new String[] { "_id", DB.ACCOUNT.NAME, DB.ACCOUNT.AUTH_CONFIG, DB.ACCOUNT.FLAGS }; String args[] = { uploaderName }; Cursor c = mDB.query(DB.ACCOUNT.TABLE, from, DB.ACCOUNT.NAME + " = ?", args, null, null, null, null); long id = -1; if (c.moveToFirst()) { ContentValues config = DBHelper.get(c); id = config.getAsLong("_id"); add(config);//from w w w . ja v a 2 s.c o m } c.close(); return id; }
From source file:com.ubikod.capptain.android.sdk.reach.CapptainReachAgent.java
/** * Parse a content.//from w w w . ja v a 2s. com * @param values content as returned by the storage. * @return content. * @throws Exception parsing problem, most likely invalid XML. */ private CapptainReachContent parseContent(ContentValues values) throws Exception { /* Parse the first XML tag */ CapptainReachContent content = parseContent(values.getAsString(XML), values.getAsString(JID)); content.setState(values); /* Set local id */ content.setLocalId(values.getAsLong(ID)); return content; }
From source file:edu.mit.mobile.android.locast.sync.SyncEngine.java
/** * Loads the an item from a JSONObject into a SyncStatus object. * * Sets {@link SyncStatus#remoteCVs}, {@link SyncStatus#remoteModifiedTime}, * {@link SyncStatus#remoteJson}, {@link SyncStatus#remote} * * @param jo/* w w w . j av a 2 s. com*/ * @param syncMap * @param serverTime * @return * @throws JSONException * @throws IOException * @throws NetworkProtocolException */ private SyncStatus loadItemFromJsonObject(JSONObject jo, SyncMap syncMap, long serverTime) throws JSONException, IOException, NetworkProtocolException { final ContentValues cv = JsonSyncableItem.fromJSON(mContext, null, jo, syncMap); final String remoteUri = cv.getAsString(JsonSyncableItem._PUBLIC_URI); final long remoteModified = cv.getAsLong(JsonSyncableItem._SERVER_MODIFIED_DATE); // the status starts out based on this knowledge and gets filled in // as the sync progresses final SyncStatus syncStatus = new SyncStatus(remoteUri, SyncState.REMOTE_ONLY); syncStatus.remoteModifiedTime = remoteModified; syncStatus.remoteCVs = cv; syncStatus.remoteJson = jo; syncStatus.remote = remoteUri; return syncStatus; }
From source file:ca.marcmeszaros.papyrus.browser.BooksBrowser.java
/** * Executes the query to loan out the book *///from w ww . java 2s.c o m private void loanBook(int mYear, int mMonth, int mDay) { // set the due date Calendar c = Calendar.getInstance(); c.set(mYear, mMonth, mDay); // gets the uri path to the user selected Uri user = loanData.getData(); // gets the user id String id = user.getLastPathSegment(); // prepare the query ContentValues values = new ContentValues(); values.put(PapyrusContentProvider.Loans.FIELD_BOOK_ID, selectedBookID); values.put(PapyrusContentProvider.Loans.FIELD_CONTACT_ID, id); values.put(PapyrusContentProvider.Loans.FIELD_LEND_DATE, System.currentTimeMillis()); values.put(PapyrusContentProvider.Loans.FIELD_DUE_DATE, c.getTimeInMillis()); // insert the entry in the database, and get the new loan id Uri newLoan = resolver.insert(PapyrusContentProvider.Loans.CONTENT_URI, values); int loanID = (int) ContentUris.parseId(newLoan); // Book book = new Book(isbn10, title, author); Loan loan = new Loan(loanID, values.getAsInteger(PapyrusContentProvider.Loans.FIELD_BOOK_ID), values.getAsInteger(PapyrusContentProvider.Loans.FIELD_CONTACT_ID), values.getAsLong(PapyrusContentProvider.Loans.FIELD_LEND_DATE), values.getAsLong(PapyrusContentProvider.Loans.FIELD_DUE_DATE)); // get an alarm manager AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE); // create the intent for the alarm Intent intent = new Intent(this, AlarmReceiver.class); // put the loan object into the alarm receiver intent.putExtra("loan", loan); // create the pendingIntent to run when the alarm goes off and be handled by a receiver PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, 0); // set the repeating alarm am.set(AlarmManager.RTC, c.getTimeInMillis(), pendingIntent); Toast.makeText(this, getString(R.string.BooksBrowser_toast_loanSuccessful), Toast.LENGTH_LONG).show(); }