Example usage for android.content Entity getSubValues

List of usage examples for android.content Entity getSubValues

Introduction

In this page you can find the example usage for android.content Entity getSubValues.

Prototype

public ArrayList<NamedContentValues> getSubValues() 

Source Link

Usage

From source file:at.bitfire.ical4android.AndroidEvent.java

public Event getEvent() throws FileNotFoundException, CalendarStorageException {
    if (event != null)
        return event;

    try {//from   w  ww  . jav a 2 s .c o  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 {/*w w w  . j a v a 2  s.com*/
        @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

/**
 * Build up the entries to display on the screen.
 *
 * @param personCursor the URI for the contact being displayed
 *//* w  ww.  j  a va  2s . c  om*/
private final void buildEntries() {

    final Context context = this;
    final Sources sources = Sources.getInstance(context);

    ArrayList<ViewEntry> items = new ArrayList<ViewEntry>();

    int typeIcon = R.drawable.icon_question;
    String typeString = "Unknown";

    if (mPlace.type == Places.TYPE_GPS) {
        typeIcon = R.drawable.icon_satellite;
        typeString = "GPS";
    } else if (mPlace.type == Places.TYPE_WIFI) {
        typeIcon = R.drawable.icon_wifi;
        typeString = "Wi-Fi";
    }

    // detection type
    items.add(new ViewEntry(LIST_ACTION_NO_ACTION, typeIcon, "Dectection Sensor", typeString, null));

    // recent visit time
    String recentVisitTime = getRecentVisitSubstring(); //"May 4, 3:00pm, 1hr";
    items.add(new ViewEntry(LIST_ACTION_VIEW_VISITS, R.drawable.ic_clock_strip_desk_clock, "View recent visits",
            recentVisitTime, null));

    for (Entity entity : mEntities) {
        final ContentValues entValues = entity.getEntityValues();
        final String accountType = entValues.getAsString(Places.ACCOUNT_TYPE);
        final long placeId = entValues.getAsLong(Places._ID);

        for (NamedContentValues subValue : entity.getSubValues()) {
            final ContentValues entryValues = subValue.values;
            entryValues.put(Places.Data.PLACE_ID, placeId);
            final long dataId = entryValues.getAsLong(Data._ID);
            final String mimeType = entryValues.getAsString(Data.MIMETYPE);
            if (mimeType == null)
                continue;

            final DataKind kind = sources.getKindOrFallback(accountType, mimeType, this,
                    PlacesSource.LEVEL_MIMETYPES);
            if (kind == null)
                continue;

            //Log.e(TAG, "buildEntries: dataId=" + dataId + ", mimeType=" + mimeType);

            // public ViewEntry(int action, int icon, String text, String subtext, Intent intent) {

            if (WifiFingerprint.CONTENT_ITEM_TYPE.equals(mimeType)) {
                String fingerprint = entryValues.getAsString(WifiFingerprint.FINGERPRINT);
                long timestamp = entryValues.getAsLong(WifiFingerprint.TIMESTAMP);
                String subtext = "Captured at " + MyDateUtils.getAbrv_MMM_d_h_m(timestamp);
                //Log.d(TAG, fingerprint);
                //String apsAbstract = getWifiInfoSubstring(5, fingerprint); 
                ViewEntry item = new ViewEntry(LIST_ACTION_VIEW_WIFIS, R.drawable.ic_settings_wireless,
                        "View Wi-Fi APs", subtext, null);
                item.extra_string = fingerprint;
                mWifiEntries.add(item);
            } else if (GpsCircleArea.CONTENT_ITEM_TYPE.equals(mimeType)) {
                double lat = entryValues.getAsDouble(GpsCircleArea.LATITUDE);
                double lon = entryValues.getAsDouble(GpsCircleArea.LONGITUDE);
                float rad = entryValues.getAsFloat(GpsCircleArea.RADIUS);
                //Log.d(TAG, "lat=" + lat + ",lon=" + lon + ",rad=" + rad);
                ViewEntry item = new ViewEntry(-1, -1, null, null, null);
                item.extra_double1 = lat;
                item.extra_double2 = lon;
                item.extra_float1 = rad;
                mGpsEntries.add(item);
            } else if (StructuredPostal.CONTENT_ITEM_TYPE.equals(mimeType)) {
                ViewEntry item = ViewEntry.fromValues(context, mimeType, kind, placeId, dataId, entryValues);
                String uri = "geo:0,0?q=" + TextUtils.htmlEncode(item.data);
                item.intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
                item.action = LIST_ACTION_POSTAL;
                item.text = item.label;
                item.subtext = item.data;
                mPostalEntries.add(item);
            } else if (Keyword.CONTENT_ITEM_TYPE.equals(mimeType)) {
                ViewEntry item = ViewEntry.fromValues(context, mimeType, kind, placeId, dataId, entryValues);
                item.text = item.data;
                item.subtext = null;
                mTagEntries.add(item);
            } else if (Note.CONTENT_ITEM_TYPE.equals(mimeType)) {
                ViewEntry item = ViewEntry.fromValues(context, mimeType, kind, placeId, dataId, entryValues);
                item.text = item.label;
                item.subtext = item.data;
                mOtherEntries.add(item);
            } else if (Website.CONTENT_ITEM_TYPE.equals(mimeType)) {
                ViewEntry item = ViewEntry.fromValues(context, mimeType, kind, placeId, dataId, entryValues);
                item.uri = null;
                item.action = LIST_ACTION_WEBSITE;
                item.text = item.label;
                item.subtext = item.data;
                item.intent = new Intent(Intent.ACTION_VIEW, Uri.parse(item.data));
                mWebsiteEntries.add(item);
            }
        }
    }

    for (ViewEntry item : mWifiEntries) {
        items.add(item);
    }
    mWifiEntries.clear();
    for (ViewEntry item : mPostalEntries) {
        items.add(item);
    }
    mPostalEntries.clear();
    for (ViewEntry item : mTagEntries) {
        items.add(item);
    }
    mTagEntries.clear();
    for (ViewEntry item : mWebsiteEntries) {
        items.add(item);
    }
    mWebsiteEntries.clear();
    for (ViewEntry item : mOtherEntries) {
        items.add(item);
    }
    mOtherEntries.clear();
    // Log.d(TAG, "size of items = " + items.size());

    ViewEntryAdapter adapter = new ViewEntryAdapter(this, R.layout.place_view_list_item, items);
    mListView.setAdapter(adapter);
}

From source file:at.bitfire.vcard4android.AndroidContact.java

public Contact getContact() throws FileNotFoundException, ContactsStorageException {
    if (contact != null)
        return contact;

    try {/* ww w .ja va2 s .co  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);
    }
}

From source file:at.bitfire.davdroid.resource.LocalAddressBook.java

@Override
public void populate(Resource res) throws LocalStorageException {
    Contact c = (Contact) res;//w  w  w  .  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.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 w  w. java2s  .  c om

    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);
    }
}