Example usage for android.app SearchManager SUGGEST_COLUMN_INTENT_EXTRA_DATA

List of usage examples for android.app SearchManager SUGGEST_COLUMN_INTENT_EXTRA_DATA

Introduction

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

Prototype

String SUGGEST_COLUMN_INTENT_EXTRA_DATA

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

Click Source Link

Document

Column name for suggestions cursor.

Usage

From source file:fr.matthiasbosc.translucentmap.PlaceProvider.java

@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
    Cursor c = null;//  w  ww  .  j  a va  2  s .co  m

    PlaceJSONParser parser = new PlaceJSONParser();
    PlaceDetailsJSONParser detailsParser = new PlaceDetailsJSONParser();

    String jsonString = "";
    String jsonPlaceDetails = "";

    List<HashMap<String, String>> list = null;
    List<HashMap<String, String>> detailsList = null;

    MatrixCursor mCursor = null;

    switch (mUriMatcher.match(uri)) {
    case SEARCH:
        // Defining a cursor object with columns description, lat and lng
        mCursor = new MatrixCursor(new String[] { "description", "lat", "lng" });

        // Create a parser object to parse places in JSON format
        parser = new PlaceJSONParser();

        // Create a parser object to parse place details in JSON format
        detailsParser = new PlaceDetailsJSONParser();

        // Get Places from Google Places API
        jsonString = getPlaces(selectionArgs);
        try {
            // Parse the places ( JSON => List )
            list = parser.parse(new JSONObject(jsonString));

            // Finding latitude and longitude for each places using Google Places Details API
            for (int i = 0; i < list.size(); i++) {
                HashMap<String, String> hMap = (HashMap<String, String>) list.get(i);

                detailsParser = new PlaceDetailsJSONParser();

                // Get Place details
                jsonPlaceDetails = getPlaceDetails(hMap.get("reference"));

                // Parse the details ( JSON => List )
                detailsList = detailsParser.parse(new JSONObject(jsonPlaceDetails));

                // Creating cursor object with places
                for (int j = 0; j < detailsList.size(); j++) {
                    HashMap<String, String> hMapDetails = detailsList.get(j);

                    // Adding place details to cursor
                    mCursor.addRow(new String[] { hMap.get("description"), hMapDetails.get("lat"),
                            hMapDetails.get("lng") });
                }

            }
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        c = mCursor;
        break;

    case SUGGESTIONS:

        // Defining a cursor object with columns id, SUGGEST_COLUMN_TEXT_1, SUGGEST_COLUMN_INTENT_EXTRA_DATA
        mCursor = new MatrixCursor(new String[] { "_id", SearchManager.SUGGEST_COLUMN_TEXT_1,
                SearchManager.SUGGEST_COLUMN_INTENT_EXTRA_DATA });

        // Creating a parser object to parse places in JSON format
        parser = new PlaceJSONParser();

        // Get Places from Google Places API
        jsonString = getPlaces(selectionArgs);

        try {
            // Parse the places ( JSON => List )
            list = parser.parse(new JSONObject(jsonString));

            // Creating cursor object with places
            for (int i = 0; i < list.size(); i++) {
                HashMap<String, String> hMap = (HashMap<String, String>) list.get(i);

                // Adding place details to cursor
                mCursor.addRow(
                        new String[] { Integer.toString(i), hMap.get("description"), hMap.get("reference") });
            }
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        c = mCursor;
        break;

    case DETAILS:
        // Defining a cursor object with columns description, lat and lng
        mCursor = new MatrixCursor(new String[] { "description", "lat", "lng" });

        detailsParser = new PlaceDetailsJSONParser();
        jsonPlaceDetails = getPlaceDetails(selectionArgs[0]);
        try {
            detailsList = detailsParser.parse(new JSONObject(jsonPlaceDetails));
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        for (int j = 0; j < detailsList.size(); j++) {
            HashMap<String, String> hMapDetails = detailsList.get(j);
            mCursor.addRow(new String[] { hMapDetails.get("formatted_address"), hMapDetails.get("lat"),
                    hMapDetails.get("lng") });
        }
        c = mCursor;
        break;

    }

    return c;
}

From source file:com.terracom.mumbleclient.channel.ChannelListFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.fragment_channel_list, menu);

    MenuItem searchItem = menu.findItem(R.id.menu_search);
    SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE);

    final SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName()));
    searchView.setOnSuggestionListener(new SearchView.OnSuggestionListener() {
        @Override/*from w w w  .  j  av  a2  s  . com*/
        public boolean onSuggestionSelect(int i) {
            return false;
        }

        @Override
        public boolean onSuggestionClick(int i) {
            CursorWrapper cursor = (CursorWrapper) searchView.getSuggestionsAdapter().getItem(i);
            int typeColumn = cursor.getColumnIndex(SearchManager.SUGGEST_COLUMN_INTENT_EXTRA_DATA);
            int dataIdColumn = cursor.getColumnIndex(SearchManager.SUGGEST_COLUMN_INTENT_DATA);
            String itemType = cursor.getString(typeColumn);
            int itemId = cursor.getInt(dataIdColumn);
            if (ChannelSearchProvider.INTENT_DATA_CHANNEL.equals(itemType)) {
                try {
                    if (getService().getSessionChannel().getId() != itemId) {
                        getService().joinChannel(itemId);
                    } else {
                        scrollToChannel(itemId);
                    }
                } catch (RemoteException e) {
                    e.printStackTrace();
                }
                return true;
            } else if (ChannelSearchProvider.INTENT_DATA_USER.equals(itemType)) {
                scrollToUser(itemId);
                return true;
            }
            return false;
        }
    });
}

From source file:com.morlunk.mumbleclient.channel.ChannelListFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.fragment_channel_list, menu);

    MenuItem searchItem = menu.findItem(R.id.menu_search);
    SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE);

    final SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName()));
    searchView.setOnSuggestionListener(new SearchView.OnSuggestionListener() {
        @Override/*from   w  w  w  . j  av  a  2 s. c  o  m*/
        public boolean onSuggestionSelect(int i) {
            return false;
        }

        @Override
        public boolean onSuggestionClick(int i) {
            CursorWrapper cursor = (CursorWrapper) searchView.getSuggestionsAdapter().getItem(i);
            int typeColumn = cursor.getColumnIndex(SearchManager.SUGGEST_COLUMN_INTENT_EXTRA_DATA);
            int dataIdColumn = cursor.getColumnIndex(SearchManager.SUGGEST_COLUMN_INTENT_DATA);
            String itemType = cursor.getString(typeColumn);
            int itemId = cursor.getInt(dataIdColumn);
            if (ChannelSearchProvider.INTENT_DATA_CHANNEL.equals(itemType)) {
                if (getService().getSessionChannel().getId() != itemId) {
                    getService().joinChannel(itemId);
                } else {
                    scrollToChannel(itemId);
                }
                return true;
            } else if (ChannelSearchProvider.INTENT_DATA_USER.equals(itemType)) {
                scrollToUser(itemId);
                return true;
            }
            return false;
        }
    });
}

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 w w 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.//from   ww  w.  j  av a2 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.ja  va2 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 = 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  av  a2s  .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./*from w ww .  j a  v a2 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) {
            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;
    }
}