List of usage examples for android.app SearchManager SUGGEST_COLUMN_TEXT_1
String SUGGEST_COLUMN_TEXT_1
To view the source code for android.app SearchManager SUGGEST_COLUMN_TEXT_1.
Click Source Link
From source file:android.support.v7.widget.SuggestionsAdapter.java
/** * Cache columns.//from w w w . ja v a 2s . c o m */ @Override public void changeCursor(Cursor c) { if (DBG) Log.d(LOG_TAG, "changeCursor(" + c + ")"); if (mClosed) { Log.w(LOG_TAG, "Tried to change cursor after adapter was closed."); if (c != null) c.close(); return; } try { super.changeCursor(c); if (c != null) { mText1Col = c.getColumnIndex(SearchManager.SUGGEST_COLUMN_TEXT_1); mText2Col = c.getColumnIndex(SearchManager.SUGGEST_COLUMN_TEXT_2); mText2UrlCol = c.getColumnIndex(SearchManager.SUGGEST_COLUMN_TEXT_2_URL); mIconName1Col = c.getColumnIndex(SearchManager.SUGGEST_COLUMN_ICON_1); mIconName2Col = c.getColumnIndex(SearchManager.SUGGEST_COLUMN_ICON_2); mFlagsCol = c.getColumnIndex(SearchManager.SUGGEST_COLUMN_FLAGS); } } catch (Exception e) { Log.e(LOG_TAG, "error changing cursor and caching columns", e); } }
From source file:com.dmsl.anyplace.SearchPOIActivity.java
private void handleIntent(Intent intent) { if (Intent.ACTION_SEARCH.equals(intent.getAction())) { // get the search type mSearchType = (SearchTypes) intent.getSerializableExtra("searchType"); if (mSearchType == null) finishSearch("No search type provided!", null); // get the query string final String query = intent.getStringExtra("query"); double lat = intent.getDoubleExtra("lat", 0); double lng = intent.getDoubleExtra("lng", 0); AnyplaceSuggestionsTask mSuggestionsTask = new AnyplaceSuggestionsTask( new AnyplaceSuggestionsTask.AnyplaceSuggestionsListener() { @Override//from w w w. j a va 2 s.c o m public void onSuccess(String result, List<? extends IPoisClass> pois) { // we have pois to query for a match mQueriedPoisStr = new ArrayList<Spanned>(); mQueriedPois = pois; // Display part of Description Text Only // Make an approximation of available space based on map size final int viewWidth = (int) (findViewById(R.id.txtResultsFound).getWidth() * 2); View infoWindow = getLayoutInflater() .inflate(R.layout.queried_pois_item_1_searchactivity, null); TextView infoSnippet = (TextView) infoWindow; TextPaint paint = infoSnippet.getPaint(); // Regular expression // ?i ignore case Pattern pattern = Pattern.compile(String.format("((?i)%s)", query)); for (IPoisClass pm : pois) { String name = "", description = ""; Matcher m; m = pattern.matcher(pm.name()); // Makes matched query bold using HTML format // $1 returns the regular's expression outer parenthesis value name = m.replaceAll("<b>$1</b>"); m = pattern.matcher(pm.description()); if (m.find()) { // Makes matched query bold using HTML format // $1 returns the regular's expression outer parenthesis value int startIndex = m.start(); description = m.replaceAll("<b>$1</b>"); description = AndroidUtils.fillTextBox(paint, viewWidth, description, startIndex + 3); } mQueriedPoisStr.add(Html.fromHtml(name + "<br>" + description)); } ArrayAdapter<Spanned> mAdapter = new ArrayAdapter<Spanned>( // getBaseContext(), R.layout.queried_pois_item_1, getBaseContext(), R.layout.queried_pois_item_1_searchactivity, mQueriedPoisStr); lvResultPois.setAdapter(mAdapter); txtResultsFound.setText("Results found [ " + mQueriedPoisStr.size() + " ]"); } @Override public void onErrorOrCancel(String result) { // no pois exist finishSearch("No Points of Interest exist!", null); } @Override public void onUpdateStatus(String string, Cursor cursor) { SimpleCursorAdapter adapter = new SimpleCursorAdapter(getBaseContext(), R.layout.queried_pois_item_1_searchactivity, cursor, new String[] { SearchManager.SUGGEST_COLUMN_TEXT_1 }, new int[] { android.R.id.text1 }); lvResultPois.setAdapter(adapter); txtResultsFound.setText("Results found [ " + cursor.getCount() + " ]"); } }, this, mSearchType, new GeoPoint(lat, lng), query); mSuggestionsTask.execute(); } }
From source file:au.com.cybersearch2.classyfy.TitleSearchResultsActivityTest.java
@Test public void test_OnCreate() throws Exception { titleSearchResultsActivity = (TitleSearchResultsActivity) controller.create().get(); assertThat(titleSearchResultsActivity.adapter).isNotNull(); verify(titleSearchResultsFragment).setListAdapter(eq(simpleCursorAdapter)); CursorAdapaterParameters params = new CursorAdapaterParameters(); assertThat(params.getLayout()).isEqualTo(android.R.layout.simple_list_item_2); assertThat(params.getCursor()).isNull(); assertThat(params.getUiBindFrom()).isEqualTo( new String[] { SearchManager.SUGGEST_COLUMN_TEXT_1, SearchManager.SUGGEST_COLUMN_TEXT_2 }); assertThat(params.getUiBindTo()).isEqualTo(new int[] { android.R.id.text1, android.R.id.text2 }); assertThat(params.getFlags()).isEqualTo(0); assertThat(((TestTitleSearchResultsActivity) titleSearchResultsActivity).titleSearchResultsFragmentId) .isEqualTo(R.id.title_search_results_fragment); }
From source file:com.wecandoit.jinju_0_0_4.jActivity_YoutubeSearchList.java
@Override public boolean onSuggestionClick(int position) { Cursor c = (Cursor) mSuggestionsAdapter.getItem(position); String query = c.getString(c.getColumnIndex(SearchManager.SUGGEST_COLUMN_TEXT_1)); jG.Log.d("onSuggestionClick = " + query); mSearchView.setQuery(query, false);/*from w w w.j a v a 2 s . com*/ return true; }
From source file:com.svpino.longhorn.activities.DashboardActivity.java
private void performSearch(String query) { this.stockListFragment.hideContextualActionBar(); Cursor cursor = DataProvider.search(getApplicationContext(), query); if (this.searchDialog == null || !this.searchDialog.isShowing()) { this.searchDialog = new Dialog(this); this.searchDialog.requestWindowFeature(Window.FEATURE_NO_TITLE); this.searchDialog.setContentView(R.layout.dialog); TextView messageTextView = (TextView) this.searchDialog.findViewById(R.id.messageTextView); TextView titleTextView = (TextView) this.searchDialog.findViewById(R.id.titleTextView); ListView listView = (ListView) this.searchDialog.findViewById(R.id.listView); if (cursor != null && cursor.getCount() > 0) { titleTextView.setText(String.format(getString(R.string.dialog_search_title), query)); messageTextView.setVisibility(View.GONE); String[] from = new String[] { SearchManager.SUGGEST_COLUMN_TEXT_1, SearchManager.SUGGEST_COLUMN_TEXT_2, LonghornDatabase.KEY_EXCHANGE_SYMBOL }; int[] to = new int[] { R.id.nameTextView, R.id.descriptionTextView, R.id.additionalTextView }; SimpleCursorAdapter adapter = new SimpleCursorAdapter(getApplicationContext(), R.layout.dialog_item, cursor, from, to, 0); adapter.setViewBinder(new ViewBinder() { @Override//from ww w . j av a 2 s . c om public boolean setViewValue(View view, Cursor cursor, int columnIndex) { if (columnIndex == 0) { ((View) view.getParent()).setTag(cursor.getString(columnIndex)); } return false; } }); listView.setAdapter(adapter); listView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) { Cursor cursor = (Cursor) adapterView.getItemAtPosition(position); addStockToWatchList(cursor.getString(0)); DashboardActivity.this.searchDialog.dismiss(); } }); } else { titleTextView.setText(getString(R.string.dialog_search_empty_title)); messageTextView.setText(String.format(getString(R.string.dialog_search_empty_message), query)); messageTextView.setVisibility(View.VISIBLE); listView.setVisibility(View.GONE); } this.searchDialog.show(); } }
From source file:ca.rmen.android.poetassistant.main.dictionaries.search.Search.java
private String[] getSearchHistory() { Cursor cursor = mContext.getContentResolver().query(SuggestionsProvider.CONTENT_URI, null, null, null, null);//from w w w .j a va 2 s . c o m if (cursor != null) { try { String[] result = new String[cursor.getCount()]; int columnIndex = cursor.getColumnIndex(SearchManager.SUGGEST_COLUMN_TEXT_1); while (cursor.moveToNext()) { result[cursor.getPosition()] = cursor.getString(columnIndex); } return result; } finally { cursor.close(); } } return new String[0]; }
From source file:net.peterkuterna.android.apps.devoxxsched.io.RemoteSessionsHandler.java
@Override public ArrayList<ContentProviderOperation> parse(ArrayList<JSONArray> entries, ContentResolver resolver) throws JSONException { final ArrayList<ContentProviderOperation> batch = Lists.newArrayList(); final HashSet<String> sessionIds = Sets.newHashSet(); final HashSet<String> trackIds = Sets.newHashSet(); final HashMap<String, HashSet<String>> sessionSpeakerIds = Maps.newHashMap(); final HashMap<String, HashSet<String>> sessionTagIds = Maps.newHashMap(); int nrEntries = 0; for (JSONArray sessions : entries) { Log.d(TAG, "Retrieved " + sessions.length() + " presentation entries."); nrEntries += sessions.length();/*ww w.j av a 2s . c om*/ for (int i = 0; i < sessions.length(); i++) { JSONObject session = sessions.getJSONObject(i); String id = session.getString("id"); final String sessionId = sanitizeId(id); final Uri sessionUri = Sessions.buildSessionUri(sessionId); sessionIds.add(sessionId); int isStarred = isStarred(sessionUri, resolver); boolean sessionUpdated = false; boolean newSession = false; ContentProviderOperation.Builder builder; if (isRowExisting(sessionUri, SessionsQuery.PROJECTION, resolver)) { builder = ContentProviderOperation.newUpdate(sessionUri); builder.withValue(Sessions.NEW, false); sessionUpdated = isSessionUpdated(sessionUri, session, resolver); if (isRemoteSync()) { builder.withValue(Sessions.UPDATED, sessionUpdated); } } else { newSession = true; builder = ContentProviderOperation.newInsert(Sessions.CONTENT_URI); builder.withValue(Sessions.SESSION_ID, sessionId); if (!isLocalSync()) { builder.withValue(Sessions.NEW, true); } } final String type = session.getString("type"); if (newSession || sessionUpdated) { builder.withValue(Sessions.TITLE, session.getString("title")); builder.withValue(Sessions.EXPERIENCE, session.getString("experience")); builder.withValue(Sessions.TYPE, type); builder.withValue(Sessions.SUMMARY, session.getString("summary")); builder.withValue(Sessions.STARRED, isStarred); } builder.withValue(Sessions.TYPE_ID, getTypeId(type)); batch.add(builder.build()); if (session.has("track")) { final String trackName = session.getString("track"); final String trackId = Tracks.generateTrackId(trackName); final Uri trackUri = Tracks.buildTrackUri(trackId); if (!trackIds.contains(trackId)) { trackIds.add(trackId); ContentProviderOperation.Builder trackBuilder; if (isRowExisting(Tracks.buildTrackUri(trackId), TracksQuery.PROJECTION, resolver)) { trackBuilder = ContentProviderOperation.newUpdate(trackUri); } else { trackBuilder = ContentProviderOperation.newInsert(Tracks.CONTENT_URI); trackBuilder.withValue(Tracks.TRACK_ID, trackId); } trackBuilder.withValue(Tracks.TRACK_NAME, trackName); final int color = Color.parseColor(getTrackColor(trackId)); trackBuilder.withValue(Tracks.TRACK_COLOR, color); batch.add(trackBuilder.build()); } if (newSession || sessionUpdated) { builder.withValue(Sessions.TRACK_ID, trackId); } } if (session.has("speakers")) { final Uri speakerSessionsUri = Sessions.buildSpeakersDirUri(sessionId); final JSONArray speakers = session.getJSONArray("speakers"); final HashSet<String> speakerIds = Sets.newHashSet(); if (!isLocalSync()) { final boolean sessionSpeakersUpdated = isSessionSpeakersUpdated(speakerSessionsUri, speakers, resolver); if (sessionSpeakersUpdated) { Log.d(TAG, "Speakers of session with id " + sessionId + " was udpated."); batch.add(ContentProviderOperation.newUpdate(sessionUri) .withValue(Sessions.UPDATED, true).build()); } } for (int j = 0; j < speakers.length(); j++) { JSONObject speaker = speakers.getJSONObject(j); final Uri speakerUri = Uri.parse(speaker.getString("speakerUri")); final String speakerId = speakerUri.getLastPathSegment(); speakerIds.add(speakerId); batch.add(ContentProviderOperation.newInsert(speakerSessionsUri) .withValue(SessionsSpeakers.SPEAKER_ID, speakerId) .withValue(SessionsSpeakers.SESSION_ID, sessionId).build()); } sessionSpeakerIds.put(sessionId, speakerIds); } if (session.has("tags")) { final Uri tagSessionsUri = Sessions.buildTagsDirUri(sessionId); final JSONArray tags = session.getJSONArray("tags"); final HashSet<String> tagIds = Sets.newHashSet(); for (int j = 0; j < tags.length(); j++) { JSONObject tag = tags.getJSONObject(j); final String tagName = tag.getString("name").toLowerCase(); final String tagId = Tags.generateTagId(tagName); tagIds.add(tagId); batch.add(ContentProviderOperation.newInsert(Tags.CONTENT_URI).withValue(Tags.TAG_ID, tagId) .withValue(Tags.TAG_NAME, tagName).build()); batch.add(ContentProviderOperation.newInsert(SearchSuggest.CONTENT_URI) .withValue(SearchManager.SUGGEST_COLUMN_TEXT_1, tagName).build()); batch.add(ContentProviderOperation.newInsert(tagSessionsUri) .withValue(SessionsTags.TAG_ID, tagId).withValue(SessionsTags.SESSION_ID, sessionId) .build()); } sessionTagIds.put(sessionId, tagIds); } } } if (isRemoteSync() && nrEntries > 0) { for (Entry<String, HashSet<String>> entry : sessionSpeakerIds.entrySet()) { String sessionId = entry.getKey(); HashSet<String> speakerIds = entry.getValue(); final Uri speakerSessionsUri = Sessions.buildSpeakersDirUri(sessionId); HashSet<String> lostSpeakerIds = getLostIds(speakerIds, speakerSessionsUri, SpeakersQuery.PROJECTION, SpeakersQuery.SPEAKER_ID, resolver); for (String lostSpeakerId : lostSpeakerIds) { final Uri deleteUri = Sessions.buildSessionSpeakerUri(sessionId, lostSpeakerId); batch.add(ContentProviderOperation.newDelete(deleteUri).build()); } } for (Entry<String, HashSet<String>> entry : sessionTagIds.entrySet()) { String sessionId = entry.getKey(); HashSet<String> tagIds = entry.getValue(); final Uri tagSessionsUri = Sessions.buildTagsDirUri(sessionId); HashSet<String> lostTagIds = getLostIds(tagIds, tagSessionsUri, TagsQuery.PROJECTION, TagsQuery.TAG_ID, resolver); for (String lostTagId : lostTagIds) { final Uri deleteUri = Sessions.buildSessionTagUri(sessionId, lostTagId); batch.add(ContentProviderOperation.newDelete(deleteUri).build()); } } HashSet<String> lostTrackIds = getLostIds(trackIds, Tracks.CONTENT_URI, TracksQuery.PROJECTION, TracksQuery.TRACK_ID, resolver); for (String lostTrackId : lostTrackIds) { Uri deleteUri = Tracks.buildSessionsUri(lostTrackId); batch.add(ContentProviderOperation.newDelete(deleteUri).build()); deleteUri = Tracks.buildTrackUri(lostTrackId); batch.add(ContentProviderOperation.newDelete(deleteUri).build()); } HashSet<String> lostSessionIds = getLostIds(sessionIds, Sessions.CONTENT_URI, SessionsQuery.PROJECTION, SessionsQuery.SESSION_ID, resolver); for (String lostSessionId : lostSessionIds) { Uri deleteUri = Sessions.buildSpeakersDirUri(lostSessionId); batch.add(ContentProviderOperation.newDelete(deleteUri).build()); deleteUri = Sessions.buildTagsDirUri(lostSessionId); batch.add(ContentProviderOperation.newDelete(deleteUri).build()); deleteUri = Sessions.buildSessionUri(lostSessionId); batch.add(ContentProviderOperation.newDelete(deleteUri).build()); } } return batch; }
From source file:com.smedic.tubtub.Pane.java
/** * Options menu in action bar/* w w w. java 2 s.com*/ * * @param menu * @return */ @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.menu_main, menu); MenuItem searchItem = menu.findItem(R.id.action_search); SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); final SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem); if (searchView != null) { searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName())); } //suggestions final CursorAdapter suggestionAdapter = new SimpleCursorAdapter(this, suggestions, null, new String[] { SearchManager.SUGGEST_COLUMN_TEXT_1 }, new int[] { android.R.id.text1 }, 0); final List<String> suggestions = new ArrayList<>(); searchView.setSuggestionsAdapter(suggestionAdapter); searchView.setOnSuggestionListener(new SearchView.OnSuggestionListener() { @Override public boolean onSuggestionSelect(int position) { return false; } @Override public boolean onSuggestionClick(int position) { searchView.setQuery(suggestions.get(position), false); searchView.clearFocus(); Intent suggestionIntent = new Intent(Intent.ACTION_SEARCH); suggestionIntent.putExtra(SearchManager.QUERY, suggestions.get(position)); handleIntent(suggestionIntent); return true; } }); searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String s) { return false; //if true, no new intent is started } @Override public boolean onQueryTextChange(final String query) { // check network connection. If not available, do not query. // this also disables onSuggestionClick triggering if (query.length() > 2) { //make suggestions after 3rd letter if (networkConf.isNetworkAvailable()) { suggestionLoader(suggestions, suggestionAdapter, query).forceLoad(); return true; } } return false; } }); return true; }
From source file:com.smedic.tubtub.Pane.java
private Loader suggestionLoader(final List<String> suggestions, final CursorAdapter suggestionAdapter, final String query) { return getSupportLoaderManager().restartLoader(4, null, new LoaderManager.LoaderCallbacks<List<String>>() { @Override//from w w w . ja v a 2 s . c o m public Loader<List<String>> onCreateLoader(final int id, final Bundle args) { return new SuggestionsLoader(getApplicationContext(), query); } @Override public void onLoadFinished(Loader<List<String>> loader, List<String> data) { if (data == null) return; suggestions.clear(); suggestions.addAll(data); String[] columns = { BaseColumns._ID, SearchManager.SUGGEST_COLUMN_TEXT_1 }; MatrixCursor cursor = new MatrixCursor(columns); for (int i = 0; i < data.size(); i++) { String[] tmp = { Integer.toString(i), data.get(i) }; cursor.addRow(tmp); } suggestionAdapter.swapCursor(cursor); } @Override public void onLoaderReset(Loader<List<String>> loader) { suggestions.clear(); suggestions.addAll(Collections.<String>emptyList()); } }); }
From source file:com.android.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; }// w w w.ja v a 2s .co m 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()); } } mController.executeSearch(query.trim()); return true; }