Example usage for android.provider ContactsContract DEFERRED_SNIPPETING

List of usage examples for android.provider ContactsContract DEFERRED_SNIPPETING

Introduction

In this page you can find the example usage for android.provider ContactsContract DEFERRED_SNIPPETING.

Prototype

String DEFERRED_SNIPPETING

To view the source code for android.provider ContactsContract DEFERRED_SNIPPETING.

Click Source Link

Document

A key to a boolean in the "extras" bundle of the cursor.

Usage

From source file:com.android.contacts.common.list.ContactListItemView.java

/**
 * Shows search snippet./*from   w w w  .  j  a v  a2s .  c om*/
 */
public void showSnippet(Cursor cursor, int summarySnippetColumnIndex) {
    if (cursor.getColumnCount() <= summarySnippetColumnIndex
            || !SearchSnippets.SNIPPET.equals(cursor.getColumnName(summarySnippetColumnIndex))) {
        setSnippet(null);
        return;
    }

    String snippet = cursor.getString(summarySnippetColumnIndex);

    // Do client side snippeting if provider didn't do it
    final Bundle extras = cursor.getExtras();
    if (extras.getBoolean(ContactsContract.DEFERRED_SNIPPETING)) {

        final String query = extras.getString(ContactsContract.DEFERRED_SNIPPETING_QUERY);

        String displayName = null;
        int displayNameIndex = cursor.getColumnIndex(Contacts.DISPLAY_NAME);
        if (displayNameIndex >= 0) {
            displayName = cursor.getString(displayNameIndex);
        }

        snippet = updateSnippet(snippet, query, displayName);

    } else {
        if (snippet != null) {
            int from = 0;
            int to = snippet.length();
            int start = snippet.indexOf(DefaultContactListAdapter.SNIPPET_START_MATCH);
            if (start == -1) {
                snippet = null;
            } else {
                int firstNl = snippet.lastIndexOf('\n', start);
                if (firstNl != -1) {
                    from = firstNl + 1;
                }
                int end = snippet.lastIndexOf(DefaultContactListAdapter.SNIPPET_END_MATCH);
                if (end != -1) {
                    int lastNl = snippet.indexOf('\n', end);
                    if (lastNl != -1) {
                        to = lastNl;
                    }
                }

                StringBuilder sb = new StringBuilder();
                for (int i = from; i < to; i++) {
                    char c = snippet.charAt(i);
                    if (c != DefaultContactListAdapter.SNIPPET_START_MATCH
                            && c != DefaultContactListAdapter.SNIPPET_END_MATCH) {
                        sb.append(c);
                    }
                }
                snippet = sb.toString();
            }
        }
    }

    setSnippet(snippet);
}