/** * Runs a query with the specified constraint. This query is requested by the filter attached to * this adapter. * * <p>The query is provided by a {@link android.widget.FilterQueryProvider}. If no provider is * specified, the current cursor is not filtered and returned. * * <p>After this method returns the resulting cursor is passed to {@link #changeCursor(Cursor)} * and the previous cursor is closed. * * <p>This method is always executed on a background thread, not on the application's main thread * (or UI thread.) * * <p>Contract: when constraint is null or empty, the original results, prior to any filtering, * must be returned. * * @param constraint the constraint with which the query must be filtered * @return a Cursor representing the results of the new query * @see #getFilter() * @see #getFilterQueryProvider() * @see #setFilterQueryProvider(android.widget.FilterQueryProvider) */ public Cursor runQueryOnBackgroundThread(CharSequence constraint) { if (mFilterQueryProvider != null) { return mFilterQueryProvider.runQuery(constraint); } return mCursor; }
@Override public Cursor runQueryOnBackgroundThread(CharSequence constraint) { if (mCursorClosed) return null; final FilterQueryProvider filter = getFilterQueryProvider(); if (filter != null) return filter.runQuery(constraint); final StringBuilder where = new StringBuilder(); constraint = constraint != null ? constraint.toString().replaceAll("_", "^_") : null; where.append(CachedUsers.SCREEN_NAME + " LIKE '" + constraint + "%' ESCAPE '^'"); where.append(" OR "); where.append(CachedUsers.NAME + " LIKE '" + constraint + "%' ESCAPE '^'"); return mResolver.query( CachedUsers.CONTENT_URI, CachedUsers.COLUMNS, constraint != null ? where.toString() : null, null, null); }