List of usage examples for android.content EntityIterator hasNext
boolean hasNext();
From source file:at.bitfire.ical4android.AndroidCalendar.java
public static AndroidCalendar findByID(Account account, ContentProviderClient provider, AndroidCalendarFactory factory, long id) throws FileNotFoundException, CalendarStorageException { @Cleanup EntityIterator iterCalendars = null; try {/*w w w . jav a 2s .c om*/ 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 EntityIterator iterCalendars = null; try {/*from ww w.j av a 2 s.com*/ 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.AndroidEvent.java
public Event getEvent() throws FileNotFoundException, CalendarStorageException { if (event != null) return event; try {/*from w w w . java2 s . co m*/ @Cleanup EntityIterator iterEvents = CalendarContract.EventsEntity.newEntityIterator(calendar.provider.query( calendar.syncAdapterURI( ContentUris.withAppendedId(CalendarContract.EventsEntity.CONTENT_URI, id)), null, null, null, null), calendar.provider); if (iterEvents.hasNext()) { event = new Event(); Entity e = iterEvents.next(); populateEvent(e.getEntityValues()); List<Entity.NamedContentValues> subValues = e.getSubValues(); for (Entity.NamedContentValues subValue : subValues) { if (Attendees.CONTENT_URI.equals(subValue.uri)) populateAttendee(subValue.values); if (Reminders.CONTENT_URI.equals(subValue.uri)) populateReminder(subValue.values); } populateExceptions(); return event; } else throw new FileNotFoundException("Locally stored event couldn't be found"); } catch (RemoteException e) { throw new CalendarStorageException("Couldn't read locally stored event", e); } }
From source file:at.bitfire.davdroid.resource.LocalCalendar.java
@Override public void populate(Resource resource) throws LocalStorageException { Event event = (Event) resource; try {/*from www .j ava2 s.co m*/ @Cleanup EntityIterator iterEvents = CalendarContract.EventsEntity.newEntityIterator( providerClient.query(syncAdapterURI(CalendarContract.EventsEntity.CONTENT_URI), null, Events._ID + "=" + event.getLocalID(), null, null), providerClient); while (iterEvents.hasNext()) { Entity e = iterEvents.next(); ContentValues values = e.getEntityValues(); populateEvent(event, values); List<Entity.NamedContentValues> subValues = e.getSubValues(); for (Entity.NamedContentValues subValue : subValues) { values = subValue.values; if (Attendees.CONTENT_URI.equals(subValue.uri)) populateAttendee(event, values); if (Reminders.CONTENT_URI.equals(subValue.uri)) populateReminder(event, values); } populateExceptions(event); } } catch (RemoteException ex) { throw new LocalStorageException("Couldn't process locally stored event", ex); } }
From source file:edu.cens.loci.ui.PlaceViewActivity.java
public void onQueryComplete(int token, Object cookie, final Cursor cursor) { final ArrayList<Entity> oldEntities = mEntities; (new AsyncTask<Void, Void, ArrayList<Entity>>() { @Override// ww w. j a va2 s . c o m protected ArrayList<Entity> doInBackground(Void... params) { ArrayList<Entity> newEntities = new ArrayList<Entity>(cursor.getCount()); EntityIterator iterator = Places.newEntityIterator(cursor); try { while (iterator.hasNext()) { Entity entity = iterator.next(); newEntities.add(entity); } } finally { iterator.close(); } return newEntities; } @Override protected void onPostExecute(ArrayList<Entity> newEntities) { if (newEntities == null) { // There was an error loading. return; } synchronized (PlaceViewActivity.this) { if (mEntities != oldEntities) { // Multiple async tasks were in flight and we // lost the race. return; } mEntities = newEntities; mHasEntities = true; } considerBindData(); } }).execute(); }
From source file:at.bitfire.davdroid.resource.LocalAddressBook.java
@Override public void populate(Resource res) throws LocalStorageException { Contact c = (Contact) res;//w ww . j av a 2 s. c o m try { @Cleanup EntityIterator iter = ContactsContract.RawContacts.newEntityIterator( providerClient.query(syncAdapterURI(ContactsContract.RawContactsEntity.CONTENT_URI), null, RawContacts._ID + "=" + c.getLocalID(), null, null)); if (iter.hasNext()) { Entity e = iter.next(); ContentValues values = e.getEntityValues(); c.setUid(values.getAsString(entryColumnUID())); c.unknownProperties = values.getAsString(COLUMN_UNKNOWN_PROPERTIES); c.starred = values.getAsInteger(RawContacts.STARRED) != 0; List<Entity.NamedContentValues> subValues = e.getSubValues(); for (Entity.NamedContentValues subValue : subValues) { values = subValue.values; String mimeType = values.getAsString(ContactsContract.RawContactsEntity.MIMETYPE); switch (mimeType) { case StructuredName.CONTENT_ITEM_TYPE: populateStructuredName(c, values); break; case Phone.CONTENT_ITEM_TYPE: populatePhoneNumber(c, values); break; case Email.CONTENT_ITEM_TYPE: populateEmailAddress(c, values); break; case Photo.CONTENT_ITEM_TYPE: populatePhoto(c, values); break; case Organization.CONTENT_ITEM_TYPE: populateOrganization(c, values); break; case Im.CONTENT_ITEM_TYPE: populateIMPP(c, values); break; case Nickname.CONTENT_ITEM_TYPE: populateNickname(c, values); break; case Note.CONTENT_ITEM_TYPE: populateNote(c, values); break; case StructuredPostal.CONTENT_ITEM_TYPE: populatePostalAddress(c, values); break; case GroupMembership.CONTENT_ITEM_TYPE: populateGroupMembership(c, values); break; case Website.CONTENT_ITEM_TYPE: populateURL(c, values); break; case CommonDataKinds.Event.CONTENT_ITEM_TYPE: populateEvent(c, values); break; case Relation.CONTENT_ITEM_TYPE: populateRelation(c, values); break; case SipAddress.CONTENT_ITEM_TYPE: populateSipAddress(c, values); break; } } } else throw new RecordNotFoundException(); } catch (RemoteException ex) { throw new LocalStorageException(ex); } }
From source file:com.granita.icloudcalsync.resource.LocalAddressBook.java
@Override public void populate(Resource res) throws LocalStorageException { Contact c = (Contact) res;/* w ww. ja v a2 s . c o m*/ try { @Cleanup EntityIterator iter = ContactsContract.RawContacts.newEntityIterator( providerClient.query(syncAdapterURI(ContactsContract.RawContactsEntity.CONTENT_URI), null, RawContacts._ID + "=" + c.getLocalID(), null, null)); if (iter.hasNext()) { Entity e = iter.next(); ContentValues values = e.getEntityValues(); c.setUid(values.getAsString(entryColumnUID())); c.setUnknownProperties(values.getAsString(COLUMN_UNKNOWN_PROPERTIES)); c.setStarred(values.getAsInteger(RawContacts.STARRED) != 0); List<Entity.NamedContentValues> subValues = e.getSubValues(); for (Entity.NamedContentValues subValue : subValues) { values = subValue.values; String mimeType = values.getAsString(ContactsContract.RawContactsEntity.MIMETYPE); switch (mimeType) { case StructuredName.CONTENT_ITEM_TYPE: populateStructuredName(c, values); break; case Phone.CONTENT_ITEM_TYPE: populatePhoneNumber(c, values); break; case Email.CONTENT_ITEM_TYPE: populateEmailAddress(c, values); break; case Photo.CONTENT_ITEM_TYPE: populatePhoto(c, values); break; case Organization.CONTENT_ITEM_TYPE: populateOrganization(c, values); break; case Im.CONTENT_ITEM_TYPE: populateIMPP(c, values); break; case Nickname.CONTENT_ITEM_TYPE: populateNickname(c, values); break; case Note.CONTENT_ITEM_TYPE: populateNote(c, values); break; case StructuredPostal.CONTENT_ITEM_TYPE: populatePostalAddress(c, values); break; case GroupMembership.CONTENT_ITEM_TYPE: populateGroupMembership(c, values); break; case Website.CONTENT_ITEM_TYPE: populateURL(c, values); break; case CommonDataKinds.Event.CONTENT_ITEM_TYPE: populateEvent(c, values); break; case Relation.CONTENT_ITEM_TYPE: populateRelation(c, values); break; case SipAddress.CONTENT_ITEM_TYPE: populateSipAddress(c, values); break; } } } else throw new RecordNotFoundException(); } catch (RemoteException ex) { throw new LocalStorageException(ex); } }
From source file:at.bitfire.vcard4android.AndroidContact.java
public Contact getContact() throws FileNotFoundException, ContactsStorageException { if (contact != null) return contact; try {//from w w w .j av a 2 s . c o m @Cleanup EntityIterator iter = RawContacts.newEntityIterator(addressBook.provider.query( addressBook.syncAdapterURI(ContactsContract.RawContactsEntity.CONTENT_URI), null, ContactsContract.RawContacts._ID + "=?", new String[] { String.valueOf(id) }, null)); if (iter.hasNext()) { Entity e = iter.next(); contact = new Contact(); populateContact(e.getEntityValues()); List<Entity.NamedContentValues> subValues = e.getSubValues(); for (Entity.NamedContentValues subValue : subValues) { ContentValues values = subValue.values; String mimeType = values.getAsString(ContactsContract.RawContactsEntity.MIMETYPE); if (mimeType == null) { Constants.log.error("Ignoring raw contact data row without " + ContactsContract.RawContactsEntity.MIMETYPE); continue; } switch (mimeType) { case StructuredName.CONTENT_ITEM_TYPE: populateStructuredName(values); break; case Phone.CONTENT_ITEM_TYPE: populatePhoneNumber(values); break; case Email.CONTENT_ITEM_TYPE: populateEmail(values); break; case Photo.CONTENT_ITEM_TYPE: populatePhoto(values); break; case Organization.CONTENT_ITEM_TYPE: populateOrganization(values); break; case Im.CONTENT_ITEM_TYPE: populateIMPP(values); break; case Nickname.CONTENT_ITEM_TYPE: populateNickname(values); break; case Note.CONTENT_ITEM_TYPE: populateNote(values); break; case StructuredPostal.CONTENT_ITEM_TYPE: populateStructuredPostal(values); break; case GroupMembership.CONTENT_ITEM_TYPE: populateGroupMembership(values); break; case Website.CONTENT_ITEM_TYPE: populateWebsite(values); break; case Event.CONTENT_ITEM_TYPE: populateEvent(values); break; case Relation.CONTENT_ITEM_TYPE: populateRelation(values); break; case SipAddress.CONTENT_ITEM_TYPE: populateSipAddress(values); break; } } return contact; } else throw new FileNotFoundException(); } catch (RemoteException e) { throw new ContactsStorageException("Couldn't read local contact", e); } }