diff options
author | Bananeweizen <bananeweizen@gmx.de> | 2014-01-04 10:51:15 +0100 |
---|---|---|
committer | Bananeweizen <bananeweizen@gmx.de> | 2014-01-04 10:51:15 +0100 |
commit | fd2664c70770a1670330b488eb01b3a976a06433 (patch) | |
tree | 08a899c14fcdff1c27e776cd6e13d53552bfc5ec /cgeo-contacts/src | |
parent | de68e6ef9afd755f12f50b2f754c9ef6b472957b (diff) | |
download | cgeo-fd2664c70770a1670330b488eb01b3a976a06433.zip cgeo-fd2664c70770a1670330b488eb01b3a976a06433.tar.gz cgeo-fd2664c70770a1670330b488eb01b3a976a06433.tar.bz2 |
new: contacts addon searches by display name
Diffstat (limited to 'cgeo-contacts/src')
-rw-r--r-- | cgeo-contacts/src/cgeo/contacts/ContactsActivity.java | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/cgeo-contacts/src/cgeo/contacts/ContactsActivity.java b/cgeo-contacts/src/cgeo/contacts/ContactsActivity.java index 00a0fde..a9e8e2f 100644 --- a/cgeo-contacts/src/cgeo/contacts/ContactsActivity.java +++ b/cgeo-contacts/src/cgeo/contacts/ContactsActivity.java @@ -8,6 +8,7 @@ import android.content.Intent; import android.database.Cursor; import android.net.Uri; import android.os.Bundle; +import android.provider.BaseColumns; import android.provider.ContactsContract; import android.util.Log; import android.view.Gravity; @@ -35,7 +36,14 @@ public final class ContactsActivity extends Activity { return; } - int contactId = getContactId(nickName); + // search by nickname + int contactId = getContactId(nickName, ContactsContract.Data.CONTENT_URI, ContactsContract.Data.CONTACT_ID, ContactsContract.CommonDataKinds.Nickname.NAME); + + // search by display name + if (contactId == 0) { + contactId = getContactId(nickName, ContactsContract.Contacts.CONTENT_URI, BaseColumns._ID, ContactsContract.Contacts.DISPLAY_NAME); + } + if (contactId == 0) { showToast(getString(R.string.contact_not_found, nickName)); finish(); @@ -53,22 +61,22 @@ public final class ContactsActivity extends Activity { startActivity(intent); } - private int getContactId(final String searchName) { + private int getContactId(final String searchName, Uri uri, final String idColumnName, final String selectionColumnName) { int foundId = 0; - final String[] projection = new String[] { ContactsContract.Data.CONTACT_ID }; - final String selection = ContactsContract.CommonDataKinds.Nickname.NAME + " = ? COLLATE NOCASE"; + final String[] projection = new String[] { idColumnName }; + final String selection = selectionColumnName + " = ? COLLATE NOCASE"; final String[] selectionArgs = new String[] { searchName }; - Cursor nicknameCursor = null; + Cursor cursor = null; try { - nicknameCursor = getContentResolver().query(ContactsContract.Data.CONTENT_URI, projection, selection, selectionArgs, null); - if (nicknameCursor != null && nicknameCursor.moveToNext()) { - foundId = nicknameCursor.getInt(0); + cursor = getContentResolver().query(uri, projection, selection, selectionArgs, null); + if (cursor != null && cursor.moveToNext()) { + foundId = cursor.getInt(0); } } catch (Exception e) { Log.e(LOG_TAG, "ContactsActivity.getContactId", e); } finally { - if (nicknameCursor != null) { - nicknameCursor.close(); + if (cursor != null) { + cursor.close(); } } return foundId; |