Example usage for android.widget FilterQueryProvider runQuery

List of usage examples for android.widget FilterQueryProvider runQuery

Introduction

In this page you can find the example usage for android.widget FilterQueryProvider runQuery.

Prototype

Cursor runQuery(CharSequence constraint);

Source Link

Document

Runs a query with the specified constraint.

Usage

From source file:org.mariotaku.twidere.adapter.UserAutoCompleteAdapter.java

@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);
}

From source file:org.mariotaku.twidere.adapter.AutoCompleteAdapter.java

@Override
public Cursor runQueryOnBackgroundThread(final CharSequence constraint) {
    char token = mToken;
    if (mEditText != null && constraint != null) {
        final CharSequence text = mEditText.getText();
        token = text.charAt(mEditText.getSelectionEnd() - constraint.length() - 1);
    }//from w  w w  .java2 s . c  o m
    if (isAtSymbol(token) == isAtSymbol(mToken)) {
        final FilterQueryProvider filter = getFilterQueryProvider();
        if (filter != null)
            return filter.runQuery(constraint);
    }
    mToken = token;
    final CharSequence constraint_escaped = constraint != null ? constraint.toString().replaceAll("_", "^_")
            : null;
    if (isAtSymbol(token)) {
        final StringBuilder where = new StringBuilder();
        where.append(CachedUsers.SCREEN_NAME + " LIKE '" + constraint_escaped + "%' ESCAPE '^'");
        where.append(" OR ");
        where.append(CachedUsers.NAME + " LIKE '" + constraint_escaped + "%' ESCAPE '^'");
        return mResolver.query(CachedUsers.CONTENT_URI, CACHED_USERS_COLUMNS,
                constraint_escaped != null ? where.toString() : null, null, null);
    } else {
        final String where = CachedHashtags.NAME + " LIKE '" + constraint_escaped + "%' ESCAPE '^'";
        return mResolver.query(CachedHashtags.CONTENT_URI, CachedHashtags.COLUMNS,
                constraint_escaped != null ? where : null, null, null);
    }
}

From source file:org.mariotaku.twidere.adapter.ComposeAutoCompleteAdapter.java

@Override
public Cursor runQueryOnBackgroundThread(final CharSequence constraint) {
    if (TextUtils.isEmpty(constraint))
        return null;
    char token = constraint.charAt(0);
    if (getNormalizedSymbol(token) == getNormalizedSymbol(mToken)) {
        final FilterQueryProvider filter = getFilterQueryProvider();
        if (filter != null)
            return filter.runQuery(constraint);
    }//from   w  ww  .  jav  a 2  s  .  c o  m
    mToken = token;
    final Uri.Builder builder = Suggestions.AutoComplete.CONTENT_URI.buildUpon();
    builder.appendQueryParameter(QUERY_PARAM_QUERY,
            String.valueOf(constraint.subSequence(1, constraint.length())));
    switch (getNormalizedSymbol(token)) {
    case '#': {
        builder.appendQueryParameter(QUERY_PARAM_TYPE, Suggestions.AutoComplete.TYPE_HASHTAGS);
        break;
    }
    case '@': {
        builder.appendQueryParameter(QUERY_PARAM_TYPE, Suggestions.AutoComplete.TYPE_USERS);
        break;
    }
    default: {
        return null;
    }
    }
    builder.appendQueryParameter(QUERY_PARAM_ACCOUNT_KEY, String.valueOf(accountKey));
    return mContext.getContentResolver().query(builder.build(), Suggestions.AutoComplete.COLUMNS, null, null,
            null);
}

From source file:com.dwdesign.tweetings.adapter.UserAutoCompleteAdapter.java

@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;
    constraint = constraint != null ? constraint.toString().replaceAll("'", "") : null;
    isHash = false;//www  .jav  a2s  .  c om
    if (constraint != null) {
        if (constraint.length() > 1 && constraint.charAt(0) == '@') {
            isHash = false;

            mLookupText = null;
            final String lookup = constraint.subSequence(1, constraint.length() - 1).toString();
            where.append(CachedUsers.SCREEN_NAME + " LIKE '" + lookup + "%' ESCAPE '^'");
            where.append(" OR ");
            where.append(CachedUsers.NAME + " LIKE '" + lookup + "%' ESCAPE '^'");
            return mResolver.query(CachedUsers.CONTENT_URI, CachedUsers.COLUMNS,
                    lookup != null ? where.toString() : null, null, null);
        } else if (constraint.length() > 0 && constraint.charAt(0) == '@') {
            isHash = false;
            mLookupText = null;

            return mResolver.query(CachedUsers.CONTENT_URI, CachedUsers.COLUMNS, null, null, null);
        } else if (constraint.length() > 1 && constraint.charAt(0) == '#') {
            isHash = true;
            mLookupText = constraint.toString();
            where.append(Statuses.TEXT_PLAIN + " LIKE '%" + constraint + "%' ESCAPE '^'");
            return mResolver.query(Statuses.CONTENT_URI, Statuses.COLUMNS,
                    constraint != null ? where.toString() : null, null, null);
        } else if (constraint.length() > 0 && constraint.charAt(0) == '#') {
            isHash = true;
            mLookupText = null;

            return mResolver.query(Statuses.CONTENT_URI, Statuses.COLUMNS, null, null, null);
        }
    }
    return null;
}

From source file:org.getlantern.firetweet.adapter.UserHashtagAutoCompleteAdapter.java

@Override
public Cursor runQueryOnBackgroundThread(final CharSequence constraint) {
    char token = mToken;
    if (mEditText != null && constraint != null) {
        final CharSequence text = mEditText.getText();
        token = text.charAt(mEditText.getSelectionEnd() - constraint.length() - 1);
    }/*from  www  .j av  a  2s  .c o  m*/
    if (isAtSymbol(token) == isAtSymbol(mToken)) {
        final FilterQueryProvider filter = getFilterQueryProvider();
        if (filter != null)
            return filter.runQuery(constraint);
    }
    mToken = token;
    final String constraintEscaped = constraint != null ? constraint.toString().replaceAll("_", "^_") : null;
    if (isAtSymbol(token)) {
        final Expression selection;
        final String[] selectionArgs;
        if (constraintEscaped != null) {
            final long[] nicknameIds = Utils.getMatchedNicknameIds(ParseUtils.parseString(constraint),
                    mUserNicknamePreferences);
            selection = Expression.or(Expression.likeRaw(new Column(CachedUsers.SCREEN_NAME), "?||'%'", "^"),
                    Expression.likeRaw(new Column(CachedUsers.NAME), "?||'%'", "^"),
                    Expression.in(new Column(CachedUsers.USER_ID), new RawItemArray(nicknameIds)));
            selectionArgs = new String[] { constraintEscaped, constraintEscaped };
        } else {
            selection = null;
            selectionArgs = null;
        }
        final OrderBy orderBy = new OrderBy(
                new String[] { CachedUsers.LAST_SEEN, "score", CachedUsers.SCREEN_NAME, CachedUsers.NAME },
                new boolean[] { false, false, true, true });
        final Cursor cursor = mResolver.query(
                Uri.withAppendedPath(CachedUsers.CONTENT_URI_WITH_SCORE, String.valueOf(mAccountId)),
                CachedUsers.BASIC_COLUMNS, selection != null ? selection.getSQL() : null, selectionArgs,
                orderBy.getSQL());
        if (Utils.isDebugBuild() && cursor == null)
            throw new NullPointerException();
        return cursor;
    } else {
        final String selection = constraintEscaped != null ? CachedHashtags.NAME + " LIKE ?||'%' ESCAPE '^'"
                : null;
        final String[] selectionArgs = constraintEscaped != null ? new String[] { constraintEscaped } : null;
        final Cursor cursor = mDatabase.query(true, CachedHashtags.TABLE_NAME, CachedHashtags.COLUMNS,
                selection, selectionArgs, null, null, CachedHashtags.NAME, null);
        if (Utils.isDebugBuild() && cursor == null)
            throw new NullPointerException();
        return cursor;
    }
}

From source file:org.mariotaku.twidere.adapter.UserHashtagAutoCompleteAdapter.java

@Override
public Cursor runQueryOnBackgroundThread(final CharSequence constraint) {
    char token = mToken;
    if (mEditText != null && constraint != null) {
        final CharSequence text = mEditText.getText();
        token = text.charAt(mEditText.getSelectionEnd() - constraint.length() - 1);
    }/*from  ww  w.ja va  2  s . c om*/
    if (isAtSymbol(token) == isAtSymbol(mToken)) {
        final FilterQueryProvider filter = getFilterQueryProvider();
        if (filter != null)
            return filter.runQuery(constraint);
    }
    mToken = token;
    final String constraintEscaped = constraint != null ? constraint.toString().replaceAll("_", "^_") : null;
    if (isAtSymbol(token)) {
        final Expression selection;
        final String[] selectionArgs;
        if (constraintEscaped != null) {
            final long[] nicknameIds = Utils.getMatchedNicknameIds(ParseUtils.parseString(constraint),
                    mUserColorNameManager);
            selection = Expression.or(Expression.likeRaw(new Column(CachedUsers.SCREEN_NAME), "?||'%'", "^"),
                    Expression.likeRaw(new Column(CachedUsers.NAME), "?||'%'", "^"),
                    Expression.in(new Column(CachedUsers.USER_ID), new RawItemArray(nicknameIds)));
            selectionArgs = new String[] { constraintEscaped, constraintEscaped };
        } else {
            selection = null;
            selectionArgs = null;
        }
        final OrderBy orderBy = new OrderBy(
                new String[] { CachedUsers.LAST_SEEN, "score", CachedUsers.SCREEN_NAME, CachedUsers.NAME },
                new boolean[] { false, false, true, true });
        final Cursor cursor = mResolver.query(
                Uri.withAppendedPath(CachedUsers.CONTENT_URI_WITH_SCORE, String.valueOf(mAccountId)),
                CachedUsers.BASIC_COLUMNS, selection != null ? selection.getSQL() : null, selectionArgs,
                orderBy.getSQL());
        if (BuildConfig.DEBUG && cursor == null)
            throw new NullPointerException();
        return cursor;
    } else {
        final String selection = constraintEscaped != null ? CachedHashtags.NAME + " LIKE ?||'%' ESCAPE '^'"
                : null;
        final String[] selectionArgs = constraintEscaped != null ? new String[] { constraintEscaped } : null;
        final Cursor cursor = mDatabase.query(true, CachedHashtags.TABLE_NAME, CachedHashtags.COLUMNS,
                selection, selectionArgs, null, null, CachedHashtags.NAME, null);
        if (BuildConfig.DEBUG && cursor == null)
            throw new NullPointerException();
        return cursor;
    }
}

From source file:de.vanita5.twittnuker.adapter.UserHashtagAutoCompleteAdapter.java

@Override
public Cursor runQueryOnBackgroundThread(final CharSequence constraint) {
    char token = mToken;
    if (mEditText != null && constraint != null) {
        final CharSequence text = mEditText.getText();
        token = text.charAt(mEditText.getSelectionEnd() - constraint.length() - 1);
    }//from www  . j av a2s.  c  om
    if (isAtSymbol(token) == isAtSymbol(mToken)) {
        final FilterQueryProvider filter = getFilterQueryProvider();
        if (filter != null)
            return filter.runQuery(constraint);
    }
    mToken = token;
    final String constraint_escaped = constraint != null ? constraint.toString().replaceAll("_", "^_") : null;
    if (isAtSymbol(token)) {
        final StringBuilder builder = new StringBuilder();
        builder.append(CachedUsers.SCREEN_NAME + " LIKE ?||'%' ESCAPE '^'");
        builder.append(" OR ");
        builder.append(CachedUsers.NAME + " LIKE ?||'%' ESCAPE '^'");
        builder.append(" OR ");
        builder.append(Where.in(new Column(CachedUsers.USER_ID),
                new RawItemArray(getMatchedNicknameIds(ParseUtils.parseString(constraint)))).getSQL());
        final String selection = constraint_escaped != null ? builder.toString() : null;
        final String[] selectionArgs = constraint_escaped != null
                ? new String[] { constraint_escaped, constraint_escaped }
                : null;
        final String orderBy = CachedUsers.SCREEN_NAME + ", " + CachedUsers.NAME;
        return mResolver.query(CachedUsers.CONTENT_URI, CACHED_USERS_COLUMNS, selection, selectionArgs,
                orderBy);
    } else {
        final String selection = constraint_escaped != null ? CachedHashtags.NAME + " LIKE ?||'%' ESCAPE '^'"
                : null;
        final String[] selectionArgs = constraint_escaped != null ? new String[] { constraint_escaped } : null;
        return mDatabase.query(true, CachedHashtags.TABLE_NAME, CachedHashtags.COLUMNS, selection,
                selectionArgs, null, null, CachedHashtags.NAME, null);
    }
}