Example usage for android.app SearchManager SUGGEST_COLUMN_QUERY

List of usage examples for android.app SearchManager SUGGEST_COLUMN_QUERY

Introduction

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

Prototype

String SUGGEST_COLUMN_QUERY

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

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  ww  w  .  j ava 2s  . co 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:cm.aptoide.com.actionbarsherlock.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.
 */// w  ww  . j  av a  2s .  co 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;
    }

    return null;
}

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  va 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: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./* ww  w .  ja va 2  s .  c o  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) {
            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./*from   ww w . j a  v a  2s .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./*  ww w  .  j a va 2s .c o  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.tandong.sa.sherlock.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./*ww w .j av  a  2s  .  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) {
            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;
    }
}