/* * Resolves username and image either from a locally saved mapping or from * synced cloud contacts. If no mapping is found, no mame is set and the * default image is assumed */ void updateContact(Contact c) { long contactId = getContactId(c); boolean found = false; if (contactId <= 0) { Log.v(this.toString(), "contactId could not be resolved for " + c.getTopic()); setContactImageAndName(c, null, null); return; } else { Log.v(this.toString(), "contactId for " + c.getTopic() + " was resolved to " + contactId); } Cursor cursor = this.context .getContentResolver() .query( RawContacts.CONTENT_URI, null, ContactsContract.Data.CONTACT_ID + " = ?", new String[] {contactId + ""}, null); if (!cursor.isAfterLast()) { while (cursor.moveToNext()) { Bitmap image = Contact.resolveImage(this.context.getContentResolver(), contactId); String displayName = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME)); Log.v( this.toString(), "Resolved display Name: " + displayName + ", image: " + image + " for topic " + c.getTopic()); c.setName(displayName); c.setUserImage(image); found = true; break; } } if (!found) setContactImageAndName(c, null, null); cursor.close(); }
void setContactImageAndName(Contact c, Bitmap image, String name) { c.setName(name); c.setUserImage(image); }