/** * Looks up a contacts display name by contact id - if not found, the * address (phone number) will be formatted and returned instead. */ public static String getPersonName(Context context, String id, String address) { if (id == null) { if (address != null) { // Log.v("Contact not found, formatting number"); return PhoneNumberUtils.formatNumber(address); } else { return null; } } Cursor cursor = context.getContentResolver().query(Uri.withAppendedPath(Contacts.People.CONTENT_URI, id), new String[] { PeopleColumns.DISPLAY_NAME }, null, null, null); if (cursor != null) { try { if (cursor.getCount() > 0) { cursor.moveToFirst(); String name = cursor.getString(0); // Log.v("Contact Display Name: " + name); return name; } } finally { cursor.close(); } } if (address != null) { // Log.v("Contact not found, formatting number"); return PhoneNumberUtils.formatNumber(address); } return null; }
@Override public void bindView(View v, Context context, Cursor c) { int nameCol = c.getColumnIndex(PeopleColumns.NAME); String name = c.getString(nameCol); /** * * Next set the name of the entry. */ TextView name_text = new TextView(context); if (name_text != null) { name_text.setText(name); } }
@Override public View newView(Context context, Cursor cursor, ViewGroup parent) { Cursor c = getCursor(); final LayoutInflater inflater = LayoutInflater.from(context); View v = inflater.inflate(layout, parent, false); int nameCol = c.getColumnIndex(PeopleColumns.NAME); String name = c.getString(nameCol); /** * * Next set the name of the entry. */ TextView name_text = new TextView(context); if (name_text != null) { name_text.setText(name); } return v; }
@Override public Cursor runQueryOnBackgroundThread(CharSequence constraint) { /* * used by the textfilter interface */ if (getFilterQueryProvider() != null) { return getFilterQueryProvider().runQuery(constraint); } StringBuilder buffer = null; String[] args = null; if (constraint != null) { buffer = new StringBuilder(); buffer.append("UPPER("); buffer.append(PeopleColumns.NAME); buffer.append(") GLOB ?"); args = new String[] { constraint.toString().toUpperCase() + "*" }; } return context.getContentResolver().query(People.CONTENT_URI, null, buffer == null ? null : buffer.toString(), args, PeopleColumns.NAME + " ASC"); }