Example usage for android.database Cursor getExtras

List of usage examples for android.database Cursor getExtras

Introduction

In this page you can find the example usage for android.database Cursor getExtras.

Prototype

Bundle getExtras();

Source Link

Document

Returns a bundle of extra values.

Usage

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

/**
 * Shows search snippet.//from  ww  w. j a v a 2 s. com
 */
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);
}