List of usage examples for android.content ContentValues getAsLong
public Long getAsLong(String key)
From source file:Main.java
public static void shiftTableIds(HashMap<String, ArrayList<ContentValues>> operationMap, String tableName, String idColumnName, long topTableId) { ArrayList<ContentValues> restoreOperations = operationMap.get(tableName); if (null == restoreOperations) { return;/*from w ww . ja v a2s . co m*/ } for (ContentValues restoreCv : restoreOperations) { restoreCv.put(idColumnName, restoreCv.getAsLong(idColumnName) + topTableId); } }
From source file:Main.java
public static void shiftTableIdsExceptWhen(HashMap<String, ArrayList<ContentValues>> operationMap, String tableName, String idColumnName, long topTableId, String exceptionColumn, String exceptionValue) { ArrayList<ContentValues> restoreOperations = operationMap.get(tableName); if (null == restoreOperations || null == exceptionValue) { return;// w w w . j a v a 2s.com } for (ContentValues restoreCv : restoreOperations) { if (!exceptionValue.equals(restoreCv.getAsString(exceptionColumn))) { restoreCv.put(idColumnName, restoreCv.getAsLong(idColumnName) + topTableId); } } }
From source file:at.bitfire.davdroid.model.CollectionInfo.java
public static CollectionInfo fromDB(ContentValues values) { CollectionInfo info = new CollectionInfo(); info.id = values.getAsLong(Collections.ID); info.serviceID = values.getAsLong(Collections.SERVICE_ID); info.url = values.getAsString(Collections.URL); info.readOnly = values.getAsInteger(Collections.READ_ONLY) != 0; info.displayName = values.getAsString(Collections.DISPLAY_NAME); info.description = values.getAsString(Collections.DESCRIPTION); info.color = values.getAsInteger(Collections.COLOR); info.timeZone = values.getAsString(Collections.TIME_ZONE); info.supportsVEVENT = getAsBooleanOrNull(values, Collections.SUPPORTS_VEVENT); info.supportsVTODO = getAsBooleanOrNull(values, Collections.SUPPORTS_VTODO); info.selected = values.getAsInteger(Collections.SYNC) != 0; return info;/*from w ww . ja v a2 s . co m*/ }
From source file:Main.java
public static void removeEntriesWhereMatch(HashMap<String, ArrayList<ContentValues>> operationMap, String tableName, String idColumnName, ArrayList<ContentValues> compareContentValues, String compareColumnName) { ArrayList<ContentValues> restoreOperations = operationMap.get(tableName); if (null == restoreOperations) { return;/*from w w w . j av a 2 s .c o m*/ } ArrayList<ContentValues> removeOperations = new ArrayList<ContentValues>(); for (ContentValues restoreCv : restoreOperations) { for (ContentValues compareCv : compareContentValues) { if (restoreCv.containsKey(idColumnName) && compareCv.containsKey(compareColumnName)) { if (restoreCv.getAsLong(idColumnName) == compareCv.getAsLong(compareColumnName)) { removeOperations.add(restoreCv); } } } } for (ContentValues removeCv : removeOperations) { restoreOperations.remove(removeCv); } }
From source file:at.bitfire.ical4android.AndroidCalendar.java
public static AndroidCalendar findByID(Account account, ContentProviderClient provider, AndroidCalendarFactory factory, long id) throws FileNotFoundException, CalendarStorageException { @Cleanup/*from w ww. j a v a2 s . co m*/ EntityIterator iterCalendars = null; try { iterCalendars = CalendarContract.CalendarEntity.newEntityIterator(provider.query( syncAdapterURI(ContentUris.withAppendedId(CalendarContract.CalendarEntity.CONTENT_URI, id), account), null, null, null, null)); } catch (RemoteException e) { throw new CalendarStorageException("Couldn't query calendars", e); } if (iterCalendars.hasNext()) { ContentValues values = iterCalendars.next().getEntityValues(); AndroidCalendar calendar = factory.newInstance(account, provider, values.getAsLong(Calendars._ID)); calendar.populate(values); return calendar; } throw new FileNotFoundException(); }
From source file:at.bitfire.ical4android.AndroidCalendar.java
public static AndroidCalendar[] find(Account account, ContentProviderClient provider, AndroidCalendarFactory factory, String where, String whereArgs[]) throws CalendarStorageException { @Cleanup/*from w ww . j av a2 s .c om*/ EntityIterator iterCalendars = null; try { iterCalendars = CalendarContract.CalendarEntity.newEntityIterator( provider.query(syncAdapterURI(CalendarContract.CalendarEntity.CONTENT_URI, account), null, where, whereArgs, null)); } catch (RemoteException e) { throw new CalendarStorageException("Couldn't query calendars", e); } List<AndroidCalendar> calendars = new LinkedList<>(); while (iterCalendars.hasNext()) { ContentValues values = iterCalendars.next().getEntityValues(); AndroidCalendar calendar = factory.newInstance(account, provider, values.getAsLong(Calendars._ID)); calendar.populate(values); calendars.add(calendar); } return calendars.toArray(factory.newArray(calendars.size())); }
From source file:at.bitfire.ical4android.AndroidTaskList.java
public static AndroidTaskList[] find(Account account, TaskProvider provider, AndroidTaskListFactory factory, String where, String whereArgs[]) throws CalendarStorageException { List<AndroidTaskList> taskLists = new LinkedList<>(); try {//from www . ja va 2 s .co m @Cleanup Cursor cursor = provider.client.query(syncAdapterURI(provider.taskListsUri(), account), null, null, null, null); while (cursor != null && cursor.moveToNext()) { ContentValues values = new ContentValues(cursor.getColumnCount()); DatabaseUtils.cursorRowToContentValues(cursor, values); AndroidTaskList taskList = factory.newInstance(account, provider, values.getAsLong(TaskLists._ID)); taskList.populate(values); taskLists.add(taskList); } } catch (RemoteException e) { throw new CalendarStorageException("Couldn't query task list by ID", e); } return taskLists.toArray(factory.newArray(taskLists.size())); }
From source file:com.csipsimple.backup.SipProfileJson.java
private static boolean restoreSipProfile(JSONObject jsonObj, ContentResolver cr) { // Restore accounts Columns cols;// w w w. j a va 2s. c om ContentValues cv; cols = getSipProfileColumns(false); cv = cols.jsonToContentValues(jsonObj); long profileId = cv.getAsLong(SipProfile.FIELD_ID); if (profileId >= 0) { Uri insertedUri = cr.insert(SipProfile.ACCOUNT_URI, cv); profileId = ContentUris.parseId(insertedUri); } // TODO : else restore call handler in private db // Restore filters cols = new Columns(Filter.FULL_PROJ, Filter.FULL_PROJ_TYPES); try { JSONArray filtersObj = jsonObj.getJSONArray(FILTER_KEY); Log.d(THIS_FILE, "We have filters for " + profileId + " > " + filtersObj.length()); for (int i = 0; i < filtersObj.length(); i++) { JSONObject filterObj = filtersObj.getJSONObject(i); // Log.d(THIS_FILE, "restoring "+filterObj.toString(4)); cv = cols.jsonToContentValues(filterObj); cv.put(Filter.FIELD_ACCOUNT, profileId); cr.insert(SipManager.FILTER_URI, cv); } } catch (JSONException e) { Log.e(THIS_FILE, "Error while restoring filters", e); } return false; }
From source file:org.anhonesteffort.flock.sync.calendar.EventFactory.java
private static void handleAttachPropertiesForCopiedRecurrenceWithExceptions(ContentValues values, VEvent event) {//from ww w . j a va 2 s .c o m Long copiedEventId = values.getAsLong(CalendarContract.Events.SYNC_DATA2); if (copiedEventId != null && copiedEventId > 0) event.getProperties() .add(new XProperty(PROPERTY_NAME_FLOCK_COPY_EVENT_ID, String.valueOf(copiedEventId))); }
From source file:org.anhonesteffort.flock.sync.calendar.EventFactory.java
private static void handleAddPropertiesForEditExceptionToRecurring(String path, ContentValues eventValues, VEvent vEvent) throws InvalidComponentException { Log.w(TAG, "gonna try and export edit exception from androids recurrence model..."); Long originalLocalId = eventValues.getAsLong(CalendarContract.Events.ORIGINAL_ID); String originalSyncId = eventValues.getAsString(CalendarContract.Events.ORIGINAL_SYNC_ID); Long originalInstanceTime = eventValues.getAsLong(CalendarContract.Events.ORIGINAL_INSTANCE_TIME); String syncId = eventValues.getAsString(CalendarContract.Events._SYNC_ID); if (TextUtils.isEmpty(originalSyncId)) throw new InvalidComponentException("original sync id required on recurring event edit exceptions", false, CalDavConstants.CALDAV_NAMESPACE, path); if (originalLocalId == null || originalLocalId < 1 || originalInstanceTime == null) throw new InvalidComponentException( "original local id and instance time required on recurring event edit exceptions", false, CalDavConstants.CALDAV_NAMESPACE, path); if (vEvent.getUid() == null) vEvent.getProperties().add(new Uid(syncId)); else if (vEvent.getUid().getValue() == null) vEvent.getUid().setValue(syncId); vEvent.getProperties().add(new XProperty(PROPERTY_NAME_FLOCK_ORIGINAL_SYNC_ID, originalSyncId)); vEvent.getProperties().add(/*from www . j av a2 s . com*/ new XProperty(PROPERTY_NAME_FLOCK_ORIGINAL_INSTANCE_TIME, String.valueOf(originalInstanceTime))); }