Contacting Our Friends
This just says that the only column we want back is the contact's ID. Also,
add imports to android.provider.ContactsContract and
android.provider.ContactsContract.CommonDataKinds.
Finally, modify the TimelineEntry constructor to be as follows:
TimelineEntry(String friend, String createdAt,
String status) {
this.friend=friend;
this.createdAt=createdAt;
this.status=status;
String[] args={friend};
StringBuilder query=new StringBuilder(CommonDataKinds.Im.CUSTOM_PROTOCOL);
query.append("='identi.ca' AND ");
query.append(CommonDataKinds.Im.DATA);
query.append("=?");
Cursor c=managedQuery(ContactsContract.Data.CONTENT_URI,
PROJECTION,
query.toString(),
args, null);
if (c.getCount()> 0 ) {
this.isContact=true;
}
}
We use managedQuery() to get a Cursor representing our contact, if any. All
we do is look to see if we got one (or, conceivably, more) matches on our
screen name, and use that information to set the value of isContact.
The net result is that any friends whose screen names are in our contacts
will show up with their screen names on a blue background.
Extra Credit................................................................................................
Here are some things you can try beyond those step-by-step instructions:
- Provide a means from the Patchy UI to see the contact information
for a contact from whom we have received a status update.
- Cache the matching contacts for a short period of time, to reduce
contact lookups when new status updates come in.