Example usage for android.app SearchManager SUGGEST_COLUMN_INTENT_DATA_ID

List of usage examples for android.app SearchManager SUGGEST_COLUMN_INTENT_DATA_ID

Introduction

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

Prototype

String SUGGEST_COLUMN_INTENT_DATA_ID

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

Click Source Link

Document

Column name for suggestions cursor.

Usage

From source file:com.example.android.dragonTV.data.VideoDatabase.java

/**
 * Builds a map for all columns that may be requested, which will be given to the
 * SQLiteQueryBuilder. This is a good way to define aliases for column names, but must include
 * all columns, even if the value is the key. This allows the ContentProvider to request
 * columns w/o the need to know real column names and create the alias itself.
 *//*from w  w w.  ja  va  2s  .  c o  m*/
private static HashMap<String, String> buildColumnMap() {
    HashMap<String, String> map = new HashMap<String, String>();
    map.put(KEY_NAME, KEY_NAME);
    map.put(KEY_DESCRIPTION, KEY_DESCRIPTION);
    map.put(KEY_ICON, KEY_ICON);
    map.put(KEY_DATA_TYPE, KEY_DATA_TYPE);
    map.put(KEY_IS_LIVE, KEY_IS_LIVE);
    map.put(KEY_VIDEO_WIDTH, KEY_VIDEO_WIDTH);
    map.put(KEY_VIDEO_HEIGHT, KEY_VIDEO_HEIGHT);
    map.put(KEY_AUDIO_CHANNEL_CONFIG, KEY_AUDIO_CHANNEL_CONFIG);
    map.put(KEY_PURCHASE_PRICE, KEY_PURCHASE_PRICE);
    map.put(KEY_RENTAL_PRICE, KEY_RENTAL_PRICE);
    map.put(KEY_RATING_STYLE, KEY_RATING_STYLE);
    map.put(KEY_RATING_SCORE, KEY_RATING_SCORE);
    map.put(KEY_PRODUCTION_YEAR, KEY_PRODUCTION_YEAR);
    map.put(KEY_COLUMN_DURATION, KEY_COLUMN_DURATION);
    map.put(KEY_ACTION, KEY_ACTION);
    map.put(BaseColumns._ID, "rowid AS " + BaseColumns._ID);
    map.put(SearchManager.SUGGEST_COLUMN_INTENT_DATA_ID,
            "rowid AS " + SearchManager.SUGGEST_COLUMN_INTENT_DATA_ID);
    map.put(SearchManager.SUGGEST_COLUMN_SHORTCUT_ID, "rowid AS " + SearchManager.SUGGEST_COLUMN_SHORTCUT_ID);
    return map;
}

From source file:com.example.android.tvleanback2.data.VideoDatabase.java

/**
 * Builds a map for all columns that may be requested, which will be given to the
 * SQLiteQueryBuilder. This is a good way to define aliases for column names, but must include
 * all columns, even if the value is the key. This allows the ContentProvider to request
 * columns w/o the need to know real column names and create the alias itself.
 */// w  ww . jav a2  s.  c o m
private static HashMap<String, String> buildColumnMap() {
    HashMap<String, String> map = new HashMap<>();
    map.put(KEY_NAME, KEY_NAME);
    map.put(KEY_DESCRIPTION, KEY_DESCRIPTION);
    map.put(KEY_ICON, KEY_ICON);
    map.put(KEY_DATA_TYPE, KEY_DATA_TYPE);
    map.put(KEY_IS_LIVE, KEY_IS_LIVE);
    map.put(KEY_VIDEO_WIDTH, KEY_VIDEO_WIDTH);
    map.put(KEY_VIDEO_HEIGHT, KEY_VIDEO_HEIGHT);
    map.put(KEY_AUDIO_CHANNEL_CONFIG, KEY_AUDIO_CHANNEL_CONFIG);
    map.put(KEY_PURCHASE_PRICE, KEY_PURCHASE_PRICE);
    map.put(KEY_RENTAL_PRICE, KEY_RENTAL_PRICE);
    map.put(KEY_RATING_STYLE, KEY_RATING_STYLE);
    map.put(KEY_RATING_SCORE, KEY_RATING_SCORE);
    map.put(KEY_PRODUCTION_YEAR, KEY_PRODUCTION_YEAR);
    map.put(KEY_COLUMN_DURATION, KEY_COLUMN_DURATION);
    map.put(KEY_ACTION, KEY_ACTION);
    map.put(BaseColumns._ID, "rowid AS " + BaseColumns._ID);
    map.put(SearchManager.SUGGEST_COLUMN_INTENT_DATA_ID,
            "rowid AS " + SearchManager.SUGGEST_COLUMN_INTENT_DATA_ID);
    map.put(SearchManager.SUGGEST_COLUMN_SHORTCUT_ID, "rowid AS " + SearchManager.SUGGEST_COLUMN_SHORTCUT_ID);
    return map;
}

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  o  m*/
        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.vishwa.pinit.MainActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.main_action_bar, menu);
    mMenu = menu;/* w  ww  .  ja  v  a 2 s . c  om*/
    mSearchMenuItem = menu.findItem(R.id.action_search);
    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    mSearchView = (SearchView) mSearchMenuItem.getActionView();
    mSearchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    mSearchView.setQueryHint("Search for locations...");

    mSearchView.setOnSuggestionListener(new OnSuggestionListener() {

        @Override
        public boolean onSuggestionSelect(int position) {
            return false;
        }

        @Override
        public boolean onSuggestionClick(int position) {
            CursorAdapter adapter = mSearchView.getSuggestionsAdapter();
            Cursor cursor = adapter.getCursor();
            if (cursor != null) {
                if (cursor.moveToPosition(position)) {
                    InputMethodManager imm = (InputMethodManager) getSystemService(
                            Context.INPUT_METHOD_SERVICE);
                    imm.hideSoftInputFromWindow(mSearchView.getWindowToken(), 0);
                    mSearchMenuItem.collapseActionView();
                    String geolocation = cursor
                            .getString(cursor.getColumnIndex(SearchManager.SUGGEST_COLUMN_INTENT_DATA_ID));
                    if (geolocation != null && !geolocation.isEmpty()) {
                        double latitude = Double.parseDouble(geolocation.split(",")[0]);
                        double longitude = Double.parseDouble(geolocation.split(",")[1]);
                        LatLng geopoint = new LatLng(latitude, longitude);
                        mMap.animateCamera(
                                CameraUpdateFactory.newCameraPosition(new CameraPosition(geopoint, 17, 0, 0)));
                    }
                }
            }
            return true;
        }
    });

    mSearchView.setOnQueryTextListener(new OnQueryTextListener() {

        @Override
        public boolean onQueryTextSubmit(String query) {
            CursorAdapter adapter = mSearchView.getSuggestionsAdapter();
            Cursor cursor = adapter.getCursor();
            if (cursor != null) {
                if (cursor.moveToFirst()) {
                    InputMethodManager imm = (InputMethodManager) getSystemService(
                            Context.INPUT_METHOD_SERVICE);
                    imm.hideSoftInputFromWindow(mSearchView.getWindowToken(), 0);
                    mSearchMenuItem.collapseActionView();
                    String geolocation = cursor
                            .getString(cursor.getColumnIndex(SearchManager.SUGGEST_COLUMN_INTENT_DATA_ID));
                    if (geolocation != null && !geolocation.isEmpty()) {
                        double latitude = Double.parseDouble(geolocation.split(",")[0]);
                        double longitude = Double.parseDouble(geolocation.split(",")[1]);
                        LatLng geopoint = new LatLng(latitude, longitude);
                        mMap.animateCamera(
                                CameraUpdateFactory.newCameraPosition(new CameraPosition(geopoint, 17, 0, 0)));
                    }
                }
            }
            return true;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            return false;
        }
    });

    if (!mHasInternet) {
        hideNonRefreshMenuItems();
    } else {
        showNonRefreshMenuItems();
    }
    return true;
}

From source file:com.gelakinetic.mtgfam.helpers.CardDbAdapter.java

/**
 * Builds a map for all columns that may be requested, which will be given
 * to the SQLiteQueryBuilder. This is a good way to define aliases for
 * column names, but must include all columns, even if the value is the key.
 * This allows the ContentProvider to request columns w/o the need to know
 * real column names and create the alias itself.
 *///from   w  ww  .j a  v a 2 s  .  co m
private static HashMap<String, String> buildColumnMap() {
    HashMap<String, String> map = new HashMap<String, String>();
    map.put(KEY_NAME, KEY_NAME);
    map.put(BaseColumns._ID, "rowid AS " + BaseColumns._ID);
    map.put(SearchManager.SUGGEST_COLUMN_INTENT_DATA_ID,
            "rowid AS " + SearchManager.SUGGEST_COLUMN_INTENT_DATA_ID);
    map.put(SearchManager.SUGGEST_COLUMN_SHORTCUT_ID, "rowid AS " + SearchManager.SUGGEST_COLUMN_SHORTCUT_ID);
    return map;
}

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

/**
 * When a particular suggestion has been selected, perform the various lookups required
 * to use the suggestion.  This includes checking the cursor for suggestion-specific data,
 * and/or falling back to the XML for defaults;  It also creates REST style Uri data when
 * the suggestion includes a data id./*from ww w.  ja  v a  2  s  .  co m*/
 *
 * @param c The suggestions cursor, moved to the row of the user's selection
 * @param actionKey The key code of the action key that was pressed,
 *        or {@link KeyEvent#KEYCODE_UNKNOWN} if none.
 * @param actionMsg The message for the action key that was pressed,
 *        or <code>null</code> if none.
 * @return An intent for the suggestion at the cursor's position.
 */
private Intent createIntentFromSuggestion(Cursor c, int actionKey, String actionMsg) {
    try {
        // use specific action if supplied, or default action if supplied, or fixed default
        String action = getColumnString(c, SearchManager.SUGGEST_COLUMN_INTENT_ACTION);

        if (action == null && Build.VERSION.SDK_INT >= 8) {
            action = mSearchable.getSuggestIntentAction();
        }
        if (action == null) {
            action = Intent.ACTION_SEARCH;
        }

        // use specific data if supplied, or default data if supplied
        String data = getColumnString(c, SearchManager.SUGGEST_COLUMN_INTENT_DATA);
        if (IS_AT_LEAST_FROYO && data == null) {
            data = mSearchable.getSuggestIntentData();
        }
        // then, if an ID was provided, append it.
        if (data != null) {
            String id = getColumnString(c, SearchManager.SUGGEST_COLUMN_INTENT_DATA_ID);
            if (id != null) {
                data = data + "/" + Uri.encode(id);
            }
        }
        Uri dataUri = (data == null) ? null : Uri.parse(data);

        String query = getColumnString(c, SearchManager.SUGGEST_COLUMN_QUERY);
        String extraData = getColumnString(c, SearchManager.SUGGEST_COLUMN_INTENT_EXTRA_DATA);

        return createIntent(action, dataUri, extraData, query, actionKey, actionMsg);
    } catch (RuntimeException e) {
        int rowNum;
        try { // be really paranoid now
            rowNum = c.getPosition();
        } catch (RuntimeException e2) {
            rowNum = -1;
        }
        Log.w(LOG_TAG, "Search suggestions cursor at row " + rowNum + " returned exception.", e);
        return null;
    }
}

From source file:com.gelakinetic.mtgfam.helpers.CardDbAdapter.java

/**
 * Returns a Cursor over all words that match the given query
 * /*from   w w  w.  java  2 s  . c o m*/
 * @param query
 *            The string to search for
 * @param columns
 *            The columns to include, if null then all are included
 * @return Cursor over all words that match, or null if none found.
 * @throws FamiliarDbException
 */
public Cursor getWordMatches(String query, String[] columns) throws FamiliarDbException {

    query = query.replace("'", "''").replace(Character.toChars(0xE6)[0], Character.toChars(0xC6)[0]).trim();
    String convert = query.toLowerCase().replace("ae", String.valueOf(Character.toChars(0xC6)[0]));

    if (query.length() < 2) {
        return null;
    }

    String sql = "SELECT * FROM (" + "SELECT " + DATABASE_TABLE_CARDS + "." + KEY_NAME + " AS " + KEY_NAME
            + ", " + DATABASE_TABLE_CARDS + "." + KEY_ID + " AS " + KEY_ID + ", " + DATABASE_TABLE_CARDS + "."
            + KEY_ID + " AS " + SearchManager.SUGGEST_COLUMN_INTENT_DATA_ID + " FROM " + DATABASE_TABLE_CARDS
            + " JOIN " + DATABASE_TABLE_SETS + " ON " + DATABASE_TABLE_SETS + "." + KEY_CODE + " = "
            + DATABASE_TABLE_CARDS + "." + KEY_SET + " WHERE " + DATABASE_TABLE_CARDS + "." + KEY_NAME
            + " LIKE '" + query + "%'" + " OR " + DATABASE_TABLE_CARDS + "." + KEY_NAME + " LIKE '" + convert
            + "%'" + " ORDER BY " + DATABASE_TABLE_CARDS + "." + KEY_NAME + " COLLATE UNICODE, "
            + DATABASE_TABLE_SETS + "." + KEY_DATE + " ASC " + ") GROUP BY " + KEY_NAME;
    return mDb.rawQuery(sql, null);
}

From source file:cm.aptoide.com.actionbarsherlock.widget.SearchView.java

/**
 * When a particular suggestion has been selected, perform the various lookups required
 * to use the suggestion.  This includes checking the cursor for suggestion-specific data,
 * and/or falling back to the XML for defaults;  It also creates REST style Uri data when
 * the suggestion includes a data id./*from w ww . j a  v a 2  s.  c  om*/
 *
 * @param c The suggestions cursor, moved to the row of the user's selection
 * @param actionKey The key code of the action key that was pressed,
 *        or {@link KeyEvent#KEYCODE_UNKNOWN} if none.
 * @param actionMsg The message for the action key that was pressed,
 *        or <code>null</code> if none.
 * @return An intent for the suggestion at the cursor's position.
 */
private Intent createIntentFromSuggestion(Cursor c, int actionKey, String actionMsg) {
    try {
        // use specific action if supplied, or default action if supplied, or fixed default
        String action = getColumnString(c, SearchManager.SUGGEST_COLUMN_INTENT_ACTION);

        if (action == null) {
            action = mSearchable.getSuggestIntentAction();
        }
        if (action == null) {
            action = Intent.ACTION_SEARCH;
        }

        // use specific data if supplied, or default data if supplied
        String data = getColumnString(c, SearchManager.SUGGEST_COLUMN_INTENT_DATA);
        if (data == null) {
            data = mSearchable.getSuggestIntentData();
        }
        // then, if an ID was provided, append it.
        if (data != null) {
            String id = getColumnString(c, SearchManager.SUGGEST_COLUMN_INTENT_DATA_ID);
            if (id != null) {
                data = data + "/" + Uri.encode(id);
            }
        }
        Uri dataUri = (data == null) ? null : Uri.parse(data);

        String query = getColumnString(c, SearchManager.SUGGEST_COLUMN_QUERY);
        String extraData = getColumnString(c, SearchManager.SUGGEST_COLUMN_INTENT_EXTRA_DATA);

        return createIntent(action, dataUri, extraData, query, actionKey, actionMsg);
    } catch (RuntimeException e) {
        int rowNum;
        try { // be really paranoid now
            rowNum = c.getPosition();
        } catch (RuntimeException e2) {
            rowNum = -1;
        }
        Log.w(LOG_TAG, "Search suggestions cursor at row " + rowNum + " returned exception.", e);
        return null;
    }
}

From source file:android.support.v7ox.widget.SearchView.java

/**
 * When a particular suggestion has been selected, perform the various lookups required
 * to use the suggestion.  This includes checking the cursor for suggestion-specific data,
 * and/or falling back to the XML for defaults;  It also creates REST style Uri data when
 * the suggestion includes a data id./* w  w w . j  a  va2  s. co m*/
 *
 * @param c The suggestions cursor, moved to the row of the user's selection
 * @param actionKey The key code of the action key that was pressed,
 *        or {@link KeyEvent#KEYCODE_UNKNOWN} if none.
 * @param actionMsg The message for the action key that was pressed,
 *        or <code>null</code> if none.
 * @return An intent for the suggestion at the cursor's position.
 */
private Intent createIntentFromSuggestion(Cursor c, int actionKey, String actionMsg) {
    try {
        // use specific action if supplied, or default action if supplied, or fixed default
        String action = SuggestionsAdapter.getColumnString(c, SearchManager.SUGGEST_COLUMN_INTENT_ACTION);

        if (action == null && Build.VERSION.SDK_INT >= 8) {
            action = mSearchable.getSuggestIntentAction();
        }
        if (action == null) {
            action = Intent.ACTION_SEARCH;
        }

        // use specific data if supplied, or default data if supplied
        String data = SuggestionsAdapter.getColumnString(c, SearchManager.SUGGEST_COLUMN_INTENT_DATA);
        if (IS_AT_LEAST_FROYO && data == null) {
            data = mSearchable.getSuggestIntentData();
        }
        // then, if an ID was provided, append it.
        if (data != null) {
            String id = SuggestionsAdapter.getColumnString(c, SearchManager.SUGGEST_COLUMN_INTENT_DATA_ID);
            if (id != null) {
                data = data + "/" + Uri.encode(id);
            }
        }
        Uri dataUri = (data == null) ? null : Uri.parse(data);

        String query = SuggestionsAdapter.getColumnString(c, SearchManager.SUGGEST_COLUMN_QUERY);
        String extraData = SuggestionsAdapter.getColumnString(c,
                SearchManager.SUGGEST_COLUMN_INTENT_EXTRA_DATA);

        return createIntent(action, dataUri, extraData, query, actionKey, actionMsg);
    } catch (RuntimeException e) {
        int rowNum;
        try { // be really paranoid now
            rowNum = c.getPosition();
        } catch (RuntimeException e2) {
            rowNum = -1;
        }
        Log.w(LOG_TAG, "Search suggestions cursor at row " + rowNum + " returned exception.", e);
        return null;
    }
}

From source file:com.example.navigationsearchview.NavigationSearchView.java

/**
 * When a particular suggestion has been selected, perform the various
 * lookups required to use the suggestion. This includes checking the cursor
 * for suggestion-specific data, and/or falling back to the XML for
 * defaults; It also creates REST style Uri data when the suggestion
 * includes a data id.//from  w  w  w . ja v a 2 s . com
 *
 * @param c
 *            The suggestions cursor, moved to the row of the user's
 *            selection
 * @param actionKey
 *            The key code of the action key that was pressed, or
 *            {@link KeyEvent#KEYCODE_UNKNOWN} if none.
 * @param actionMsg
 *            The message for the action key that was pressed, or
 *            <code>null</code> if none.
 * @return An intent for the suggestion at the cursor's position.
 */
private Intent createIntentFromSuggestion(Cursor c, int actionKey, String actionMsg) {
    try {
        // use specific action if supplied, or default action if supplied,
        // or fixed default
        String action = getColumnString(c, SearchManager.SUGGEST_COLUMN_INTENT_ACTION);

        if (action == null && Build.VERSION.SDK_INT >= 8) {
            action = mSearchable.getSuggestIntentAction();
        }
        if (action == null) {
            action = Intent.ACTION_SEARCH;
        }

        // use specific data if supplied, or default data if supplied
        String data = getColumnString(c, SearchManager.SUGGEST_COLUMN_INTENT_DATA);
        if (IS_AT_LEAST_FROYO && data == null) {
            data = mSearchable.getSuggestIntentData();
        }
        // then, if an ID was provided, append it.
        if (data != null) {
            String id = getColumnString(c, SearchManager.SUGGEST_COLUMN_INTENT_DATA_ID);
            if (id != null) {
                data = data + "/" + Uri.encode(id);
            }
        }
        Uri dataUri = (data == null) ? null : Uri.parse(data);

        String query = getColumnString(c, SearchManager.SUGGEST_COLUMN_QUERY);
        String extraData = getColumnString(c, SearchManager.SUGGEST_COLUMN_INTENT_EXTRA_DATA);

        return createIntent(action, dataUri, extraData, query, actionKey, actionMsg);
    } catch (RuntimeException e) {
        int rowNum;
        try { // be really paranoid now
            rowNum = c.getPosition();
        } catch (RuntimeException e2) {
            rowNum = -1;
        }
        Log.w(LOG_TAG, "Search suggestions cursor at row " + rowNum + " returned exception.", e);
        return null;
    }
}