/** * Sets the SearchableInfo for this SearchView. Properties in the SearchableInfo are used * to display labels, hints, suggestions, create intents for launching search results screens * and controlling other affordances such as a voice button. * * @param searchable a SearchableInfo can be retrieved from the SearchManager, for a specific * activity or a global search provider. */ public void setSearchableInfo(SearchableInfo searchable) { mSearchable = searchable; if (mSearchable != null) { updateSearchAutoComplete(); updateQueryHint(); } // Cache the voice search capability mVoiceButtonEnabled = hasVoiceSearch(); if (mVoiceButtonEnabled) { // Disable the microphone on the keyboard, as a mic is displayed near the text box // TODO: use imeOptions to disable voice input when the new API will be available mQueryTextView.setPrivateImeOptions(IME_OPTION_NO_MICROPHONE); } updateViewsVisibility(isIconified()); }
private void onVoiceClicked() { // guard against possible race conditions if (mSearchable == null) { return; } SearchableInfo searchable = mSearchable; try { if (searchable.getVoiceSearchLaunchWebSearch()) { Intent webSearchIntent = createVoiceWebSearchIntent(mVoiceWebSearchIntent, searchable); getContext().startActivity(webSearchIntent); } else if (searchable.getVoiceSearchLaunchRecognizer()) { Intent appSearchIntent = createVoiceAppSearchIntent(mVoiceAppSearchIntent, searchable); getContext().startActivity(appSearchIntent); } } catch (ActivityNotFoundException e) { // Should not happen, since we check the availability of // voice search before showing the button. But just in case... Log.w(LOG_TAG, "Could not find voice search activity"); } }
Cursor getSearchManagerSuggestions(SearchableInfo searchable, String query, int limit) { if (searchable == null) { return null; } String authority = searchable.getSuggestAuthority(); if (authority == null) { return null; } Builder uriBuilder = new Builder().scheme(Utils.RESPONSE_CONTENT).authority(authority).query("").fragment(""); String contentPath = searchable.getSuggestPath(); if (contentPath != null) { uriBuilder.appendEncodedPath(contentPath); } uriBuilder.appendPath("search_suggest_query"); String selection = searchable.getSuggestSelection(); String[] selArgs = null; if (selection != null) { selArgs = new String[]{query}; } else { uriBuilder.appendPath(query); } if (limit > 0) { uriBuilder.appendQueryParameter("limit", String.valueOf(limit)); } return this.mContext.getContentResolver().query(uriBuilder.build(), null, selection, selArgs, null); }
public ActivityBasedSearchableManager(Context context, Map<String, String> searchablesConfigs) { searchables = new HashMap<>(searchablesConfigs.size()); SearchManager searchManager = (SearchManager) context.getSystemService(Context.SEARCH_SERVICE); for (Entry<String, String> entry : searchablesConfigs.entrySet()) { String entityName = entry.getKey(); String activityName = entry.getValue(); //Se não possui o pacote, tem que colocar o pacote da aplicação. if (activityName.startsWith(".")) { activityName = context.getApplicationInfo().packageName + activityName; } ComponentName componentName = new ComponentName(context, activityName); SearchableInfo searchableInfo = searchManager.getSearchableInfo(componentName); if (searchableInfo == null) { throw new IllegalArgumentException("Searchable not found for " + activityName); } searchables.put(entityName, searchableInfo); } }
public da(Context context, SearchView searchView, SearchableInfo searchableInfo, WeakHashMap weakHashMap) { super(context, searchView.getSuggestionRowLayout(), null, true); this.f1490p = false; this.f1491q = 1; this.f1493s = -1; this.f1494t = -1; this.f1495u = -1; this.f1496v = -1; this.f1497w = -1; this.f1498x = -1; this.f1484j = (SearchManager) this.d.getSystemService("search"); this.f1485k = searchView; this.f1486l = searchableInfo; this.f1489o = searchView.getSuggestionCommitIconResId(); this.f1487m = context; this.f1488n = weakHashMap; }
/** * Sets the SearchableInfo for this SearchView. Properties in the SearchableInfo are used * to display labels, hints, suggestions, create intents for launching search results screens * and controlling other affordances such as a voice button. * * @param searchable a SearchableInfo can be retrieved from the SearchManager, for a specific * activity or a global search provider. */ public void setSearchableInfo(SearchableInfo searchable) { mSearchable = searchable; if (mSearchable != null) { if (IS_AT_LEAST_FROYO) { updateSearchAutoComplete(); } updateQueryHint(); } // Cache the voice search capability mVoiceButtonEnabled = IS_AT_LEAST_FROYO && hasVoiceSearch(); if (mVoiceButtonEnabled) { // Disable the microphone on the keyboard, as a mic is displayed near the text box // TODO: use imeOptions to disable voice input when the new API will be available mSearchSrcTextView.setPrivateImeOptions(IME_OPTION_NO_MICROPHONE); } updateViewsVisibility(isIconified()); }
@TargetApi(Build.VERSION_CODES.FROYO) private void onVoiceClicked() { // guard against possible race conditions if (mSearchable == null) { return; } SearchableInfo searchable = mSearchable; try { if (searchable.getVoiceSearchLaunchWebSearch()) { Intent webSearchIntent = createVoiceWebSearchIntent(mVoiceWebSearchIntent, searchable); getContext().startActivity(webSearchIntent); } else if (searchable.getVoiceSearchLaunchRecognizer()) { Intent appSearchIntent = createVoiceAppSearchIntent(mVoiceAppSearchIntent, searchable); getContext().startActivity(appSearchIntent); } } catch (ActivityNotFoundException e) { // Should not happen, since we check the availability of // voice search before showing the button. But just in case... Log.w(LOG_TAG, "Could not find voice search activity"); } }
protected void onFinishSetupOptionsMenu(final Menu menu) { searchItem = menu.findItem(R.id.menu_global_search); if(searchItem != null) { searchView = (SearchView) MenuItemCompat.getActionView(searchItem); SearchManager searchManager = (SearchManager) context.getSystemService(Context.SEARCH_SERVICE); SearchableInfo searchableInfo = searchManager.getSearchableInfo(context.getComponentName()); if(searchableInfo == null) { Log.w(TAG, "Failed to get SearchableInfo"); } else { searchView.setSearchableInfo(searchableInfo); } String currentQuery = getCurrentQuery(); if(currentQuery != null) { searchView.setOnSearchClickListener(new View.OnClickListener() { @Override public void onClick(View v) { searchView.setQuery(getCurrentQuery(), false); } }); } } }
@Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.menu_search, menu); MenuItem item = menu.findItem(R.id.action_search); searchView = (SearchView) MenuItemCompat.getActionView(item); // 关联检索配置与 SearchActivity SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); SearchableInfo searchableInfo = searchManager.getSearchableInfo( new ComponentName(getApplicationContext(), SearchActivity.class)); searchView.setSearchableInfo(searchableInfo); searchView.onActionViewExpanded(); // // 设置搜索文字样式 // EditText searchEditText = (EditText) searchView.findViewById(android.support.v7.appcompat.R.id.search_src_text); // searchEditText.setTextColor(getResources().getColor(R.color.textColorPrimary)); // searchEditText.setHintTextColor(getResources().getColor(R.color.textColorPrimary)); // searchEditText.setBackgroundColor(Color.WHITE); setOnQuenyTextChangeListener(); return super.onCreateOptionsMenu(menu); }
public void setSearchableInfo(SearchableInfo paramSearchableInfo) { this.mSearchable = paramSearchableInfo; if (this.mSearchable != null) { if (IS_AT_LEAST_FROYO) { updateSearchAutoComplete(); } updateQueryHint(); } if ((IS_AT_LEAST_FROYO) && (hasVoiceSearch())) {} for (boolean bool = true;; bool = false) { this.mVoiceButtonEnabled = bool; if (this.mVoiceButtonEnabled) { this.mSearchSrcTextView.setPrivateImeOptions("nm"); } updateViewsVisibility(isIconified()); return; } }
@Override public boolean onCreateOptionsMenu(Menu iMenu) { //Inflating the menu (which will add items to the action bar) getMenuInflater().inflate(R.menu.menu_article, iMenu); //Setting up the SearchView SearchManager tSearchManager = (SearchManager)getSystemService(Context.SEARCH_SERVICE); SearchView tSearchView = (SearchView) iMenu.findItem(R.id.action_text_search).getActionView(); ComponentName tComponentName = this.getComponentName(); SearchableInfo tSearchableInfo = tSearchManager.getSearchableInfo(tComponentName); tSearchView.setSearchableInfo(tSearchableInfo); tSearchView.setIconifiedByDefault(false); if(BuildConfig.DEBUG == false){ MenuItem tMenuItem = iMenu.findItem(R.id.action_debug_download); tMenuItem.setVisible(false); } return true; }
private void setupSearchView(MenuItem searchItem) { //searchItem.setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW); SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); if (searchManager != null) { List<SearchableInfo> searchables = searchManager.getSearchablesInGlobalSearch(); SearchableInfo info = searchManager.getSearchableInfo(getComponentName()); for (SearchableInfo inf : searchables) { if (inf.getSuggestAuthority() != null && inf.getSuggestAuthority().startsWith("applications")) { info = inf; } } mSearchView.setSearchableInfo(info); } mSearchView.setOnQueryTextListener(this); }
private void setupSearchView(MenuItem searchItem) { if (isAlwaysExpanded()) { mSearchView.setIconifiedByDefault(false); } else { searchItem.setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW); } SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); if (searchManager != null) { List<SearchableInfo> searchables = searchManager.getSearchablesInGlobalSearch(); // Try to use the "applications" global search provider SearchableInfo info = searchManager.getSearchableInfo(getComponentName()); for (SearchableInfo inf : searchables) { if (inf.getSuggestAuthority() != null && inf.getSuggestAuthority().startsWith("applications")) { info = inf; } } mSearchView.setSearchableInfo(info); } mSearchView.setOnQueryTextListener(this); }
private void setupSearchView(MenuItem searchItem) { mSearchView.setIconifiedByDefault(false); SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); if (searchManager != null) { List<SearchableInfo> searchables = searchManager.getSearchablesInGlobalSearch(); SearchableInfo info = searchManager.getSearchableInfo(getComponentName()); for (SearchableInfo inf : searchables) { if (inf.getSuggestAuthority() != null && inf.getSuggestAuthority().startsWith("applications")) { info = inf; } } mSearchView.setSearchableInfo(info); } mSearchView.setOnQueryTextListener(this); mSearchView.setFocusable(false); mSearchView.setFocusableInTouchMode(false); }
public void setSearchableInfo(SearchableInfo searchableinfo) { mSearchable = searchableinfo; if (mSearchable != null) { if (IS_AT_LEAST_FROYO) { updateSearchAutoComplete(); } updateQueryHint(); } boolean flag; if (IS_AT_LEAST_FROYO && hasVoiceSearch()) { flag = true; } else { flag = false; } mVoiceButtonEnabled = flag; if (mVoiceButtonEnabled) { mSearchSrcTextView.setPrivateImeOptions("nm"); } updateViewsVisibility(isIconified()); }
public SuggestionsAdapter(Context context, SearchView searchview, SearchableInfo searchableinfo, WeakHashMap weakhashmap) { super(context, searchview.getSuggestionRowLayout(), null, true); mClosed = false; mQueryRefinement = 1; mText1Col = -1; mText2Col = -1; mText2UrlCol = -1; mIconName1Col = -1; mIconName2Col = -1; mFlagsCol = -1; mSearchManager = (SearchManager)mContext.getSystemService("search"); mSearchView = searchview; mSearchable = searchableinfo; mCommitIconResId = searchview.getSuggestionCommitIconResId(); mProviderContext = context; mOutsideDrawablesCache = weakhashmap; }