Java Code Examples for android.provider.ContactsContract.Contacts#DISPLAY_NAME
The following examples show how to use
android.provider.ContactsContract.Contacts#DISPLAY_NAME .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: List2.java From codeexamples-android with Eclipse Public License 1.0 | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Get a cursor with all people Cursor c = getContentResolver().query(Contacts.CONTENT_URI, CONTACT_PROJECTION, null, null, null); startManagingCursor(c); ListAdapter adapter = new SimpleCursorAdapter(this, // Use a template that displays a text view android.R.layout.simple_list_item_1, // Give the cursor to the list adatper c, // Map the NAME column in the people database to... new String[] {Contacts.DISPLAY_NAME}, // The "text1" view defined in the XML template new int[] {android.R.id.text1}); setListAdapter(adapter); }
Example 2
Source File: Gallery2.java From codeexamples-android with Eclipse Public License 1.0 | 6 votes |
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.gallery_2); // Get a cursor with all people Cursor c = getContentResolver().query(Contacts.CONTENT_URI, CONTACT_PROJECTION, null, null, null); startManagingCursor(c); SpinnerAdapter adapter = new SimpleCursorAdapter(this, // Use a template that displays a text view android.R.layout.simple_gallery_item, // Give the cursor to the list adatper c, // Map the NAME column in the people database to... new String[] {Contacts.DISPLAY_NAME}, // The "text1" view defined in the XML template new int[] { android.R.id.text1 }); Gallery g = (Gallery) findViewById(R.id.gallery); g.setAdapter(adapter); }
Example 3
Source File: LoaderCursor.java From codeexamples-android with Eclipse Public License 1.0 | 6 votes |
public Loader<Cursor> onCreateLoader(int id, Bundle args) { // This is called when a new Loader needs to be created. This // sample only has one Loader, so we don't care about the ID. // First, pick the base URI to use depending on whether we are // currently filtering. Uri baseUri; if (mCurFilter != null) { baseUri = Uri.withAppendedPath(Contacts.CONTENT_FILTER_URI, Uri.encode(mCurFilter)); } else { baseUri = Contacts.CONTENT_URI; } // Now create and return a CursorLoader that will take care of // creating a Cursor for the data being displayed. String select = "((" + Contacts.DISPLAY_NAME + " NOTNULL) AND (" + Contacts.HAS_PHONE_NUMBER + "=1) AND (" + Contacts.DISPLAY_NAME + " != '' ))"; return new CursorLoader(getActivity(), baseUri, CONTACTS_SUMMARY_PROJECTION, select, null, Contacts.DISPLAY_NAME + " COLLATE LOCALIZED ASC"); }
Example 4
Source File: CursorFragment.java From V.FlyoutTest with MIT License | 6 votes |
public Loader<Cursor> onCreateLoader(int id, Bundle args) { // This is called when a new Loader needs to be created. This // sample only has one Loader, so we don't care about the ID. // First, pick the base URI to use depending on whether we are // currently filtering. Uri baseUri; if (mCurFilter != null) { baseUri = Uri.withAppendedPath(Contacts.CONTENT_FILTER_URI, Uri.encode(mCurFilter)); } else { baseUri = Contacts.CONTENT_URI; } // Now create and return a CursorLoader that will take care of // creating a Cursor for the data being displayed. String select = "((" + Contacts.DISPLAY_NAME + " NOTNULL) AND (" + Contacts.HAS_PHONE_NUMBER + "=1) AND (" + Contacts.DISPLAY_NAME + " != '' ))"; return new CursorLoader(getActivity(), baseUri, CONTACTS_SUMMARY_PROJECTION, select, null, Contacts.DISPLAY_NAME + " COLLATE LOCALIZED ASC"); }
Example 5
Source File: CursorFragment.java From V.FlyoutTest with MIT License | 6 votes |
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); // Give some text to display if there is no data. In a real // application this would come from a resource. setEmptyText("No phone numbers"); // We have a menu item to show in action bar. setHasOptionsMenu(true); // Create an empty adapter we will use to display the loaded data. mAdapter = new SimpleCursorAdapter(getActivity(), android.R.layout.simple_list_item_2, null, new String[] { Contacts.DISPLAY_NAME, Contacts.CONTACT_STATUS }, new int[] { android.R.id.text1, android.R.id.text2 }, 0); setListAdapter(mAdapter); // Start out with a progress indicator. setListShown(false); // Prepare the loader. Either re-connect with an existing one, // or start a new one. getLoaderManager().initLoader(0, null, this); }
Example 6
Source File: LoaderCursor.java From codeexamples-android with Eclipse Public License 1.0 | 6 votes |
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); // Give some text to display if there is no data. In a real // application this would come from a resource. setEmptyText("No phone numbers"); // We have a menu item to show in action bar. setHasOptionsMenu(true); // Create an empty adapter we will use to display the loaded data. mAdapter = new SimpleCursorAdapter(getActivity(), android.R.layout.simple_list_item_2, null, new String[] { Contacts.DISPLAY_NAME, Contacts.CONTACT_STATUS }, new int[] { android.R.id.text1, android.R.id.text2 }, 0); setListAdapter(mAdapter); // Start out with a progress indicator. setListShown(false); // Prepare the loader. Either re-connect with an existing one, // or start a new one. getLoaderManager().initLoader(0, null, this); }
Example 7
Source File: ContactsListActivity.java From coursera-android with MIT License | 6 votes |
private void loadContacts() { // Contact data String columnsToExtract[] = new String[] { Contacts._ID, Contacts.DISPLAY_NAME, Contacts.PHOTO_THUMBNAIL_URI }; // Get the ContentResolver ContentResolver contentResolver = getContentResolver(); // filter contacts with empty names String whereClause = "((" + Contacts.DISPLAY_NAME + " NOTNULL) AND (" + Contacts.DISPLAY_NAME + " != '' ) AND (" + Contacts.STARRED + "== 1))"; // sort by increasing ID String sortOrder = Contacts._ID + " ASC"; // query contacts ContentProvider mCursor = contentResolver.query(Contacts.CONTENT_URI, columnsToExtract, whereClause, null, sortOrder); // pass mCursor to custom list adapter setListAdapter(new ContactInfoListAdapter(this, R.layout.list_item, mCursor, 0)); }
Example 8
Source File: DisplayActivity.java From coursera-android with MIT License | 5 votes |
public Loader<Cursor> onCreateLoader(int id, Bundle args) { String select = "((" + Contacts.DISPLAY_NAME + " NOTNULL) AND (" + Contacts.DISPLAY_NAME + " != '' ) AND (" + Contacts.STARRED + "== 1))"; return new CursorLoader(this, Contacts.CONTENT_URI, columnsToExtract, select, null, Contacts._ID + " ASC"); }
Example 9
Source File: RecipientAlternatesAdapter.java From ChipsLibrary with Apache License 2.0 | 5 votes |
private static Cursor doQuery(final CharSequence constraint,final int limit,final Long directoryId,final Account account,final ContentResolver resolver,final Query query) { String constraintStr=constraint.toString(); final Uri.Builder builder; String selection=null; String[] selectionArgs=null; if(query!=Queries.PHONE) builder=query.getContentFilterUri().buildUpon().appendPath(constraintStr).appendQueryParameter(ContactsContract.LIMIT_PARAM_KEY,String.valueOf(limit+BaseRecipientAdapter.ALLOWANCE_FOR_DUPLICATES)); else { builder=query.getContentUri().buildUpon().appendQueryParameter(ContactsContract.LIMIT_PARAM_KEY,String.valueOf(limit+BaseRecipientAdapter.ALLOWANCE_FOR_DUPLICATES)); selection=Contacts.DISPLAY_NAME+" LIKE ? OR "+Phone.NUMBER+" LIKE ?"; constraintStr="%"+constraintStr+"%"; selectionArgs=new String[] {constraintStr,constraintStr}; } if(directoryId!=null) builder.appendQueryParameter(ContactsContract.DIRECTORY_PARAM_KEY,String.valueOf(directoryId)); if(account!=null) { builder.appendQueryParameter(BaseRecipientAdapter.PRIMARY_ACCOUNT_NAME,account.name); builder.appendQueryParameter(BaseRecipientAdapter.PRIMARY_ACCOUNT_TYPE,account.type); } // final long start = System.currentTimeMillis(); final Uri uri=builder.build(); final Cursor cursor=resolver.query(uri,query.getProjection(),selection,selectionArgs,null); // final long end = System.currentTimeMillis(); // if (DEBUG) { // Log.d(TAG, "Time for autocomplete (query: " + constraint + ", directoryId: " + directoryId // + ", num_of_results: " + (cursor != null ? cursor.getCount() : "null") + "): " + (end - start) // + " ms"); // } return cursor; }
Example 10
Source File: BaseRecipientAdapter.java From ChipsLibrary with Apache License 2.0 | 5 votes |
private Cursor doQuery(final CharSequence constraint,final int limit,final Long directoryId) { String constraintStr=constraint.toString(); final Uri.Builder builder; String selection=null; String[] selectionArgs=null; if(mQuery!=Queries.PHONE) builder=mQuery.getContentFilterUri().buildUpon().appendPath(constraintStr); else { builder=mQuery.getContentUri().buildUpon(); // search for either contact name or its phone number selection=Contacts.DISPLAY_NAME+" LIKE ? OR "+Phone.NUMBER+" LIKE ?"; constraintStr="%"+constraintStr+"%"; selectionArgs=new String[] {constraintStr,constraintStr}; } builder.appendQueryParameter(ContactsContract.LIMIT_PARAM_KEY,String.valueOf(limit+ALLOWANCE_FOR_DUPLICATES)); if(directoryId!=null) builder.appendQueryParameter(ContactsContract.DIRECTORY_PARAM_KEY,String.valueOf(directoryId)); if(mAccount!=null) { builder.appendQueryParameter(PRIMARY_ACCOUNT_NAME,mAccount.name); builder.appendQueryParameter(PRIMARY_ACCOUNT_TYPE,mAccount.type); } // final long start = System.currentTimeMillis(); final Uri uri=builder.build(); final Cursor cursor=mContentResolver.query(uri,mQuery.getProjection(),selection,selectionArgs,null); // final long end = System.currentTimeMillis(); // if (DEBUG) { // Log.d(TAG, "Time for autocomplete (query: " + constraint + ", directoryId: " + directoryId // + ", num_of_results: " + (cursor != null ? cursor.getCount() : "null") + "): " + (end - start) // + " ms"); // } return cursor; }
Example 11
Source File: QuickContactsDemo.java From codeexamples-android with Eclipse Public License 1.0 | 5 votes |
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); String select = "((" + Contacts.DISPLAY_NAME + " NOTNULL) AND (" + Contacts.HAS_PHONE_NUMBER + "=1) AND (" + Contacts.DISPLAY_NAME + " != '' ))"; Cursor c = getContentResolver().query(Contacts.CONTENT_URI, CONTACTS_SUMMARY_PROJECTION, select, null, Contacts.DISPLAY_NAME + " COLLATE LOCALIZED ASC"); startManagingCursor(c); ContactListItemAdapter adapter = new ContactListItemAdapter(this, R.layout.quick_contacts, c); setListAdapter(adapter); }
Example 12
Source File: ContactsListExample.java From coursera-android with MIT License | 5 votes |
@Override public Loader<Cursor> onCreateLoader(int id, Bundle args) { // String used to filter contacts with empty or missing names or are unstarred String select = "((" + Contacts.DISPLAY_NAME + " NOTNULL) AND (" + Contacts.DISPLAY_NAME + " != '' ) AND (" + Contacts.STARRED + "== 1))"; // String used for defining the sort order String sortOrder = Contacts._ID + " ASC"; return new CursorLoader(this, Contacts.CONTENT_URI, CONTACTS_ROWS, select, null, sortOrder); }
Example 13
Source File: ContactsListExample.java From coursera-android with MIT License | 5 votes |
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Contact data String columnsToExtract[] = new String[] { Contacts._ID, Contacts.DISPLAY_NAME, Contacts.PHOTO_THUMBNAIL_URI }; // Get the ContentResolver ContentResolver contentResolver = getContentResolver(); // filter contacts with empty names String whereClause = "((" + Contacts.DISPLAY_NAME + " NOTNULL) AND (" + Contacts.DISPLAY_NAME + " != '' ) AND (" + Contacts.STARRED + "== 1))"; // sort by increasing ID String sortOrder = Contacts._ID + " ASC"; // query contacts ContentProvider Cursor cursor = contentResolver.query(Contacts.CONTENT_URI, columnsToExtract, whereClause, null, sortOrder); // pass cursor to custom list adapter setListAdapter(new ContactInfoListAdapter(this, R.layout.list_item, cursor, 0)); }
Example 14
Source File: DisplayActivity.java From coursera-android with MIT License | 5 votes |
public Loader<Cursor> onCreateLoader(int id, Bundle args) { String select = "((" + Contacts.DISPLAY_NAME + " NOTNULL) AND (" + Contacts.DISPLAY_NAME + " != '' ) AND (" + Contacts.STARRED + "== 1))"; return new CursorLoader(this, Contacts.CONTENT_URI, columnsToExtract, select, null, Contacts._ID + " ASC"); }
Example 15
Source File: QueryContactsCommand.java From mobilecloud-15 with Apache License 2.0 | 5 votes |
/** * This hook method is called back by the LoaderManager when the * LoaderManager is initialized. */ public Loader<Cursor> onCreateLoader(int id, Bundle args) { // Columns to query. final String columnsToQuery[] = new String[] { ContactsContract.Contacts._ID, ContactsContract.Contacts.DISPLAY_NAME, ContactsContract.Contacts.STARRED }; // Contacts to select. final String selection = "((" + Contacts.DISPLAY_NAME + " NOTNULL) AND (" + Contacts.DISPLAY_NAME + " != '' ) AND (" + Contacts.STARRED + "== 1))"; // Create a new CursorLoader that will perform the query // asynchronously. return new CursorLoader(mOps.getActivityContext(), ContactsContract.Contacts.CONTENT_URI, columnsToQuery, selection, null, Contacts._ID + " ASC"); }
Example 16
Source File: QueryContactsCommand.java From mobilecloud-15 with Apache License 2.0 | 5 votes |
/** * Asynchronously query the contacts based on selection * criteria. */ @Override public void execute() { // Columns to query. final String columnsToQuery[] = new String[] { ContactsContract.Contacts._ID, ContactsContract.Contacts.DISPLAY_NAME, ContactsContract.Contacts.STARRED }; // Contacts to select. final String selection = "((" + Contacts.DISPLAY_NAME + " NOTNULL) AND (" + Contacts.DISPLAY_NAME + " != '' ) AND (" + Contacts.STARRED + "== 1))"; // Initiate an asynchronous query. getArgs().getAdapter() .startQuery(this, 0, ContactsContract.Contacts.CONTENT_URI, columnsToQuery, selection, // ContactsContract.Contacts.STARRED /* + "= 0" */, null, ContactsContract.Contacts._ID + " ASC"); }
Example 17
Source File: QueryContactsCommand.java From mobilecloud-15 with Apache License 2.0 | 5 votes |
/** * Synchronously query for contacts in the Contacts * ContentProvider. */ public Cursor queryAllContacts(ContentResolver cr) { // Columns to query. final String columnsToQuery[] = new String[] { ContactsContract.Contacts._ID, ContactsContract.Contacts.DISPLAY_NAME, ContactsContract.Contacts.STARRED }; // Contacts to select. final String selection = "((" + Contacts.DISPLAY_NAME + " NOTNULL) AND (" + Contacts.DISPLAY_NAME + " != '' ) AND (" + Contacts.STARRED + "== 1))"; // Perform a synchronous (blocking) query on the // ContactsContentProvider. return cr.query(ContactsContract.RawContacts.CONTENT_URI, columnsToQuery, selection, null, ContactsContract.Contacts._ID + " ASC"); }
Example 18
Source File: ContactsUtils5.java From CSipSimple with GNU General Public License v3.0 | 5 votes |
@Override public Cursor getContactsByGroup(Context ctxt, String groupName) { if (TextUtils.isEmpty(groupName)) { return null; } String[] projection; if (Compatibility.isCompatible(11)) { projection = new String[] { Contacts._ID, Contacts.DISPLAY_NAME, Contacts.PHOTO_ID, Contacts.CONTACT_STATUS_ICON, Contacts.CONTACT_STATUS, Contacts.CONTACT_PRESENCE, Contacts.PHOTO_URI }; } else { projection = new String[] { Contacts._ID, Contacts.DISPLAY_NAME, Contacts.PHOTO_ID, Contacts.CONTACT_STATUS, Contacts.CONTACT_PRESENCE }; } Uri searchUri = Uri.withAppendedPath(Contacts.CONTENT_GROUP_URI, Uri.encode(groupName)); Cursor c = null; try { c = ctxt.getContentResolver().query(searchUri, projection, null, null, Contacts.DISPLAY_NAME + " ASC"); } catch(Exception e) { Log.e(THIS_FILE, "Error while retrieving group", e); } return c; }
Example 19
Source File: ContactAccessor.java From mollyim-android with GNU General Public License v3.0 | 4 votes |
/*** * If the code below looks shitty to you, that's because it was taken * directly from the Android source, where shitty code is all you get. */ public Cursor getCursorForRecipientFilter(CharSequence constraint, ContentResolver mContentResolver) { final String SORT_ORDER = Contacts.TIMES_CONTACTED + " DESC," + Contacts.DISPLAY_NAME + "," + Contacts.Data.IS_SUPER_PRIMARY + " DESC," + Phone.TYPE; final String[] PROJECTION_PHONE = { Phone._ID, // 0 Phone.CONTACT_ID, // 1 Phone.TYPE, // 2 Phone.NUMBER, // 3 Phone.LABEL, // 4 Phone.DISPLAY_NAME, // 5 }; String phone = ""; String cons = null; if (constraint != null) { cons = constraint.toString(); if (RecipientsAdapter.usefulAsDigits(cons)) { phone = PhoneNumberUtils.convertKeypadLettersToDigits(cons); if (phone.equals(cons) && !PhoneNumberUtils.isWellFormedSmsAddress(phone)) { phone = ""; } else { phone = phone.trim(); } } } Uri uri = Uri.withAppendedPath(Phone.CONTENT_FILTER_URI, Uri.encode(cons)); String selection = String.format("%s=%s OR %s=%s OR %s=%s", Phone.TYPE, Phone.TYPE_MOBILE, Phone.TYPE, Phone.TYPE_WORK_MOBILE, Phone.TYPE, Phone.TYPE_MMS); Cursor phoneCursor = mContentResolver.query(uri, PROJECTION_PHONE, null, null, SORT_ORDER); if (phone.length() > 0) { ArrayList result = new ArrayList(); result.add(Integer.valueOf(-1)); // ID result.add(Long.valueOf(-1)); // CONTACT_ID result.add(Integer.valueOf(Phone.TYPE_CUSTOM)); // TYPE result.add(phone); // NUMBER /* * The "\u00A0" keeps Phone.getDisplayLabel() from deciding * to display the default label ("Home") next to the transformation * of the letters into numbers. */ result.add("\u00A0"); // LABEL result.add(cons); // NAME ArrayList<ArrayList> wrap = new ArrayList<ArrayList>(); wrap.add(result); ArrayListCursor translated = new ArrayListCursor(PROJECTION_PHONE, wrap); return new MergeCursor(new Cursor[] { translated, phoneCursor }); } else { return phoneCursor; } }
Example 20
Source File: ContactAccessor.java From Silence with GNU General Public License v3.0 | 4 votes |
/*** * If the code below looks shitty to you, that's because it was taken * directly from the Android source, where shitty code is all you get. */ public Cursor getCursorForRecipientFilter(CharSequence constraint, ContentResolver mContentResolver) { final String SORT_ORDER = Contacts.TIMES_CONTACTED + " DESC," + Contacts.DISPLAY_NAME + "," + Contacts.Data.IS_SUPER_PRIMARY + " DESC," + Phone.TYPE; final String[] PROJECTION_PHONE = { Phone._ID, // 0 Phone.CONTACT_ID, // 1 Phone.TYPE, // 2 Phone.NUMBER, // 3 Phone.LABEL, // 4 Phone.DISPLAY_NAME, // 5 }; String phone = ""; String cons = null; if (constraint != null) { cons = constraint.toString(); if (RecipientsAdapter.usefulAsDigits(cons)) { phone = PhoneNumberUtils.convertKeypadLettersToDigits(cons); if (phone.equals(cons) && !PhoneNumberUtils.isWellFormedSmsAddress(phone)) { phone = ""; } else { phone = phone.trim(); } } } Uri uri = Uri.withAppendedPath(Phone.CONTENT_FILTER_URI, Uri.encode(cons)); String selection = String.format("%s=%s OR %s=%s OR %s=%s", Phone.TYPE, Phone.TYPE_MOBILE, Phone.TYPE, Phone.TYPE_WORK_MOBILE, Phone.TYPE, Phone.TYPE_MMS); Cursor phoneCursor = mContentResolver.query(uri, PROJECTION_PHONE, null, null, SORT_ORDER); if (phone.length() > 0) { ArrayList result = new ArrayList(); result.add(-1); // ID result.add((long) -1); // CONTACT_ID result.add(Phone.TYPE_CUSTOM); // TYPE result.add(phone); // NUMBER /* * The "\u00A0" keeps Phone.getDisplayLabel() from deciding * to display the default label ("Home") next to the transformation * of the letters into numbers. */ result.add("\u00A0"); // LABEL result.add(cons); // NAME ArrayList<ArrayList> wrap = new ArrayList<ArrayList>(); wrap.add(result); ArrayListCursor translated = new ArrayListCursor(PROJECTION_PHONE, wrap); return new MergeCursor(new Cursor[] { translated, phoneCursor }); } else { return phoneCursor; } }