Example usage for android.app SearchManager SUGGEST_COLUMN_TEXT_1

List of usage examples for android.app SearchManager SUGGEST_COLUMN_TEXT_1

Introduction

In this page you can find the example usage for android.app SearchManager SUGGEST_COLUMN_TEXT_1.

Prototype

String SUGGEST_COLUMN_TEXT_1

To view the source code for android.app SearchManager SUGGEST_COLUMN_TEXT_1.

Click Source Link

Document

Column name for suggestions cursor.

Usage

From source file:android.support.v7.widget.SuggestionsAdapter.java

/**
 * Gets the text to show in the query field when a suggestion is selected.
 *
 * @param cursor The Cursor to read the suggestion data from. The Cursor should already
 *        be moved to the suggestion that is to be read from.
 * @return The text to show, or <code>null</code> if the query should not be
 *         changed when selecting this suggestion.
 *///from  w  ww .ja  v  a  2s  .  c  o m
@Override
public CharSequence convertToString(Cursor cursor) {
    if (cursor == null) {
        return null;
    }

    String query = getColumnString(cursor, SearchManager.SUGGEST_COLUMN_QUERY);
    if (query != null) {
        return query;
    }

    if (mSearchable.shouldRewriteQueryFromData()) {
        String data = getColumnString(cursor, SearchManager.SUGGEST_COLUMN_INTENT_DATA);
        if (data != null) {
            return data;
        }
    }

    if (mSearchable.shouldRewriteQueryFromText()) {
        String text1 = getColumnString(cursor, SearchManager.SUGGEST_COLUMN_TEXT_1);
        if (text1 != null) {
            return text1;
        }
    }

    return null;
}

From source file:fr.openbike.android.database.OpenBikeDBAdapter.java

public Cursor getStationsMatches(String query, String[] columns) {
    String table = STATIONS_VIRTUAL_TABLE;
    try {//from   ww w  .  j a  va  2  s  . c om
        Integer.parseInt(query);
        table = BaseColumns._ID;
    } catch (NumberFormatException ex) {
    }
    query += "*";
    // Network is not in argument list because when I do so, it doesn't work
    // !
    String s = "SELECT vs._id, vs._id as " + SearchManager.SUGGEST_COLUMN_INTENT_DATA_ID
            + ", 'n ' || vs._id as " + SearchManager.SUGGEST_COLUMN_TEXT_2 + ", vs.name as "
            + SearchManager.SUGGEST_COLUMN_TEXT_1 + " FROM" + " virtual_stations vs WHERE " + table
            + " MATCH ? AND vs.network = " + mPreferences.getInt(AbstractPreferencesActivity.NETWORK_PREFERENCE,
                    AbstractPreferencesActivity.NO_NETWORK)
            + ";";
    Cursor cursor = mDb.rawQuery(s, new String[] { query });
    /*
     * Cursor cursor = mDb.query(STATIONS_VIRTUAL_TABLE, new String[] {
     * BaseColumns._ID, "'n ' || " + BaseColumns._ID + " as " +
     * SearchManager.SUGGEST_COLUMN_TEXT_2, BaseColumns._ID + " as " +
     * SearchManager.SUGGEST_COLUMN_INTENT_DATA_ID, KEY_NAME + " as " +
     * SearchManager.SUGGEST_COLUMN_TEXT_1 }, table + " MATCH ? AND " +
     * KEY_NETWORK + " = ?", new String[] { query,
     * String.valueOf(mCurrentNetwork) }, null, null, null);
     */
    /*
     * Cursor cursor = mDb.rawQuery( "SELECT _id " +
     * SearchManager.SUGGEST_COLUMN_TEXT_2 + ", _id " +
     * SearchManager.SUGGEST_COLUMN_INTENT_DATA_ID + ", name " +
     * SearchManager.SUGGEST_COLUMN_TEXT_1 + " FROMvirtual_stations;"
     * "WHERE " + table + " MATCH ?;", null new String[] { query,
     * String.valueOf(mCurrentNetwork) });
     */
    if (cursor == null) {
        return null;
    } /*
      * else if (!cursor.moveToFirst()) { cursor.close(); return null;
      * 
      * }
      */
    return cursor;
}

From source file:com.tct.mail.ui.ActionBarController.java

@Override
public boolean onSuggestionClick(int position) {
    final Cursor c = mSearchWidget.getSuggestionsAdapter().getCursor();
    final boolean haveValidQuery = (c != null) && c.moveToPosition(position);
    if (!haveValidQuery) {
        LogUtils.d(LOG_TAG, "onSuggestionClick: Couldn't get a search query");
        // We haven't handled this query, but the default behavior will
        // leave EXTRA_ACCOUNT un-populated, leading to a crash. So claim
        // that we have handled the event.
        return true;
    }/*from  w ww .  j a v a  2 s  .com*/
    collapseSearch();
    // what is in the text field
    String queryText = mSearchWidget.getQuery().toString();
    // What the suggested query is
    String query = c.getString(c.getColumnIndex(SearchManager.SUGGEST_COLUMN_TEXT_1));
    // If the text the user typed in is a prefix of what is in the search
    // widget suggestion query, just take the search widget suggestion
    // query. Otherwise, it is a suffix and we want to remove matching
    // prefix portions.
    if (!TextUtils.isEmpty(queryText) && query.indexOf(queryText) != 0) {
        final int queryTokenIndex = queryText
                .lastIndexOf(SearchRecentSuggestionsProvider.QUERY_TOKEN_SEPARATOR);
        if (queryTokenIndex > -1) {
            queryText = queryText.substring(0, queryTokenIndex);
        }
        // Since we auto-complete on each token in a query, if the query the
        // user typed up until the last token is a substring of the
        // suggestion they click, make sure we don't double include the
        // query text. For example:
        // user types john, that matches john palo alto
        // User types john p, that matches john john palo alto
        // Remove the first john
        // Only do this if we have multiple query tokens.
        if (queryTokenIndex > -1 && !TextUtils.isEmpty(query) && query.contains(queryText)
                && queryText.length() < query.length()) {
            int start = query.indexOf(queryText);
            query = query.substring(0, start) + query.substring(start + queryText.length());
        }
    }
    //TS: junwei-xu 2015-10-27 EMAIL BUGFIX-791734 MOD_S
    //NOTE: Check if mController is null
    if (mController != null) {
        mController.executeSearch(query.trim());
    }
    //TS: junwei-xu 2015-10-27 EMAIL BUGFIX-791734 MOD_E
    return true;
}

From source file:de.sourcestream.movieDB.MainActivity.java

/**
 * Initialize the contents of the Activity's standard options menu.
 * This is only called once, the first time the options menu is displayed.
 *
 * @param menu the options menu in which we place our items.
 * @return You must return true for the menu to be displayed; if you return false it will not be shown.
 */// ww  w . jav  a2 s. com
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.menu_main, menu);
    searchViewItem = menu.findItem(R.id.search);
    searchView = (SearchView) MenuItemCompat.getActionView(searchViewItem);

    searchView.setQueryHint(getResources().getString(R.string.search_hint));
    searchView.setOnQueryTextListener(searchViewOnQueryTextListener);
    searchView.setOnSuggestionListener(searchSuggestionListener);

    // Associate searchable configuration with the SearchView
    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    SearchView searchViewItemC = (SearchView) menu.findItem(R.id.search).getActionView();
    searchViewItemC.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));

    String[] from = { SearchManager.SUGGEST_COLUMN_ICON_1, SearchManager.SUGGEST_COLUMN_TEXT_1,
            SearchManager.SUGGEST_COLUMN_TEXT_2 };
    int[] to = { R.id.posterPath, R.id.title, R.id.info };
    searchAdapter = new SimpleCursorAdapter(getApplicationContext(), R.layout.suggestionrow, null, from, to,
            0) {
        @Override
        public void changeCursor(Cursor cursor) {
            super.swapCursor(cursor);
        }
    };
    searchViewItemC.setSuggestionsAdapter(searchAdapter);

    MenuItemCompat.setOnActionExpandListener(searchViewItem, onSearchViewItemExpand);

    return true;
}

From source file:com.dmsl.anyplace.UnifiedNavigationActivity.java

private void showSearchResult(Cursor cursor) {
    // bind the text data from the results to the
    // custom//from w  ww .j  av  a  2s.  c  om
    // layout
    String[] from = { SearchManager.SUGGEST_COLUMN_TEXT_1
            // ,SearchManager.SUGGEST_COLUMN_TEXT_2
    };
    int[] to = { android.R.id.text1
            // ,android.R.id.text2
    };
    // add the cursor of the results to the search view
    // SimpleCursorAdapter adapter = new SimpleCursorAdapter(UnifiedNavigationActivity.this, R.layout.queried_pois_item_1_searchbox, cursor, from, to, 0);
    // searchView.setSuggestionsAdapter(adapter);
    // adapter.notifyDataSetChanged();

    AnyPlaceSeachingHelper.HTMLCursorAdapter adapter = new HTMLCursorAdapter(UnifiedNavigationActivity.this,
            R.layout.queried_pois_item_1_searchbox, cursor, from, to);
    searchView.setSuggestionsAdapter(adapter);
    adapter.notifyDataSetChanged();
}