List of usage examples for android.app SearchManager SUGGEST_COLUMN_INTENT_DATA
String SUGGEST_COLUMN_INTENT_DATA
To view the source code for android.app SearchManager SUGGEST_COLUMN_INTENT_DATA.
Click Source Link
From source file:com.dmsl.anyplace.nav.AnyPlaceSeachingHelper.java
public static Cursor prepareSearchViewCursor(List<? extends IPoisClass> places) { String req_columns[] = { BaseColumns._ID, SearchManager.SUGGEST_COLUMN_TEXT_1, SearchManager.SUGGEST_COLUMN_TEXT_2, SearchManager.SUGGEST_COLUMN_INTENT_DATA }; MatrixCursor mcursor = new MatrixCursor(req_columns); int i = 0;/*from w w w .j a v a 2 s.c o m*/ if (places != null) { GsonBuilder gsonBuilder = new GsonBuilder(); gsonBuilder.registerTypeAdapter(IPoisClass.class, new IPoisClass.MyInterfaceAdapter()); Gson gson = gsonBuilder.create(); for (IPoisClass p : places) { mcursor.addRow(new String[] { Integer.toString(i++), p.name(), p.description().equals("") ? "no description" : p.description(), gson.toJson(p, IPoisClass.class) }); } } return mcursor; }
From source file:com.dmsl.anyplace.nav.AnyPlaceSeachingHelper.java
public static Cursor prepareSearchViewCursor(List<? extends IPoisClass> places, String query) { String req_columns[] = { BaseColumns._ID, SearchManager.SUGGEST_COLUMN_TEXT_1, SearchManager.SUGGEST_COLUMN_INTENT_DATA }; MatrixCursor mcursor = new MatrixCursor(req_columns); int i = 0;/* w ww. ja v a2 s. co m*/ if (places != null) { GsonBuilder gsonBuilder = new GsonBuilder(); gsonBuilder.registerTypeAdapter(IPoisClass.class, new IPoisClass.MyInterfaceAdapter()); Gson gson = gsonBuilder.create(); // Better Use AndroidUtils.fillTextBox instead of regular expression // Regular expression // ?i ignore case Pattern patternTitle = Pattern.compile(String.format("((?i)%s)", query)); // Matches X words before query and Y words after Pattern patternDescription = Pattern.compile( String.format("(([^\\s]+\\s+){0,%d}[^\\s]*)((?i)%s)([^\\s]*(\\s+[^\\s]+){0,%d})", 2, query, 2)); for (IPoisClass p : places) { String name = "", description = ""; Matcher m; m = patternTitle.matcher(p.name()); // Makes matched query bold using HTML format // $1 returns the regular's expression outer parenthesis value name = m.replaceAll("<b>$1</b>"); m = patternDescription.matcher(p.description()); if (m.find()) { // Makes matched query bold using HTML format description = String.format(" %s<b>%s</b>%s", m.group(1), m.group(3), m.group(4)); } mcursor.addRow(new String[] { Integer.toString(i++), name + description, gson.toJson(p, IPoisClass.class) }); } } return mcursor; }
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 a v a2 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)) { 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 a v a2 s.c om 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.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 w w . jav 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: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./*w ww. ja v a 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 && 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./* w w w . j a va2s .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; } }
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 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 = 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./* w w w. j a va2 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 && 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 ww w.ja v a2 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; } }