类android.app.SearchableInfo源码实例Demo

下面列出了怎么用android.app.SearchableInfo的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: android_9.0.0_r45   文件: SearchView.java
/**
 * 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
        mSearchSrcTextView.setPrivateImeOptions(IME_OPTION_NO_MICROPHONE);
    }
    updateViewsVisibility(isIconified());
}
 
源代码2 项目: android_9.0.0_r45   文件: SearchView.java
/**
 * Handles the key down event for dealing with action keys.
 *
 * @param keyCode This is the keycode of the typed key, and is the same value as
 *        found in the KeyEvent parameter.
 * @param event The complete event record for the typed key
 *
 * @return true if the event was handled here, or false if not.
 */
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (mSearchable == null) {
        return false;
    }

    // if it's an action specified by the searchable activity, launch the
    // entered query with the action key
    SearchableInfo.ActionKeyInfo actionKey = mSearchable.findActionKey(keyCode);
    if ((actionKey != null) && (actionKey.getQueryActionMsg() != null)) {
        launchQuerySearch(keyCode, actionKey.getQueryActionMsg(), mSearchSrcTextView.getText()
                .toString());
        return true;
    }

    return super.onKeyDown(keyCode, event);
}
 
源代码3 项目: android_9.0.0_r45   文件: SearchView.java
/**
 * For a given suggestion and a given cursor row, get the action message. If
 * not provided by the specific row/column, also check for a single
 * definition (for the action key).
 *
 * @param c The cursor providing suggestions
 * @param actionKey The actionkey record being examined
 *
 * @return Returns a string, or null if no action key message for this
 *         suggestion
 */
private static String getActionKeyMessage(Cursor c, SearchableInfo.ActionKeyInfo actionKey) {
    String result = null;
    // check first in the cursor data, for a suggestion-specific message
    final String column = actionKey.getSuggestActionMsgColumn();
    if (column != null) {
        result = SuggestionsAdapter.getColumnString(c, column);
    }
    // If the cursor didn't give us a message, see if there's a single
    // message defined
    // for the actionkey (for all suggestions)
    if (result == null) {
        result = actionKey.getSuggestActionMsg();
    }
    return result;
}
 
源代码4 项目: android_9.0.0_r45   文件: SearchView.java
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");
    }
}
 
@Override
public boolean onCreateOptionsMenu(Menu menu) {
  super.onCreateOptionsMenu(menu);

  // Inflate the options menu from XML
  MenuInflater inflater = getMenuInflater();
  inflater.inflate(R.menu.options_menu, menu);

  // Use the Search Manager to find the SearchableInfo related
  // to the Search Result Activity.
  SearchManager searchManager =
    (SearchManager) getSystemService(Context.SEARCH_SERVICE);

  SearchableInfo searchableInfo = searchManager.getSearchableInfo(
    new ComponentName(getApplicationContext(),
      EarthquakeSearchResultActivity.class));

  SearchView searchView =
    (SearchView)menu.findItem(R.id.search_view).getActionView();
  searchView.setSearchableInfo(searchableInfo);
  searchView.setIconifiedByDefault(false);
  return true;
}
 
@Override
public boolean onCreateOptionsMenu(Menu menu) {
  super.onCreateOptionsMenu(menu);

  // Inflate the options menu from XML
  MenuInflater inflater = getMenuInflater();
  inflater.inflate(R.menu.options_menu, menu);

  // Use the Search Manager to find the SearchableInfo related
  // to the Search Result Activity.
  SearchManager searchManager =
    (SearchManager) getSystemService(Context.SEARCH_SERVICE);

  SearchableInfo searchableInfo = searchManager.getSearchableInfo(
    new ComponentName(getApplicationContext(),
      EarthquakeSearchResultActivity.class));

  SearchView searchView =
    (SearchView)menu.findItem(R.id.search_view).getActionView();
  searchView.setSearchableInfo(searchableInfo);
  searchView.setIconifiedByDefault(false);
  return true;
}
 
@Override
public boolean onCreateOptionsMenu(Menu menu) {
  super.onCreateOptionsMenu(menu);

  // Inflate the options menu from XML
  MenuInflater inflater = getMenuInflater();
  inflater.inflate(R.menu.options_menu, menu);

  // Use the Search Manager to find the SearchableInfo related
  // to the Search Result Activity.
  SearchManager searchManager =
    (SearchManager) getSystemService(Context.SEARCH_SERVICE);

  SearchableInfo searchableInfo = searchManager.getSearchableInfo(
    new ComponentName(getApplicationContext(),
      EarthquakeSearchResultActivity.class));

  SearchView searchView =
    (SearchView)menu.findItem(R.id.search_view).getActionView();
  searchView.setSearchableInfo(searchableInfo);
  searchView.setIconifiedByDefault(false);
  return true;
}
 
@Override
public boolean onCreateOptionsMenu(Menu menu) {
  super.onCreateOptionsMenu(menu);

  // Inflate the options menu from XML
  MenuInflater inflater = getMenuInflater();
  inflater.inflate(R.menu.options_menu, menu);

  // Use the Search Manager to find the SearchableInfo related
  // to the Search Result Activity.
  SearchManager searchManager =
    (SearchManager) getSystemService(Context.SEARCH_SERVICE);

  SearchableInfo searchableInfo = searchManager.getSearchableInfo(
    new ComponentName(getApplicationContext(),
      EarthquakeSearchResultActivity.class));

  SearchView searchView =
    (SearchView)menu.findItem(R.id.search_view).getActionView();
  searchView.setSearchableInfo(searchableInfo);
  searchView.setIconifiedByDefault(false);
  return true;
}
 
@Override
public boolean onCreateOptionsMenu(Menu menu) {
  super.onCreateOptionsMenu(menu);

  // Inflate the options menu from XML
  MenuInflater inflater = getMenuInflater();
  inflater.inflate(R.menu.options_menu, menu);

  // Use the Search Manager to find the SearchableInfo related
  // to the Search Result Activity.
  SearchManager searchManager =
    (SearchManager) getSystemService(Context.SEARCH_SERVICE);

  SearchableInfo searchableInfo = searchManager.getSearchableInfo(
    new ComponentName(getApplicationContext(),
      EarthquakeSearchResultActivity.class));

  SearchView searchView =
    (SearchView)menu.findItem(R.id.search_view).getActionView();
  searchView.setSearchableInfo(searchableInfo);
  searchView.setIconifiedByDefault(false);
  return true;
}
 
@Override
public boolean onCreateOptionsMenu(Menu menu) {
  super.onCreateOptionsMenu(menu);

  // Inflate the options menu from XML
  MenuInflater inflater = getMenuInflater();
  inflater.inflate(R.menu.options_menu, menu);

  // Use the Search Manager to find the SearchableInfo related
  // to the Search Result Activity.
  SearchManager searchManager =
    (SearchManager) getSystemService(Context.SEARCH_SERVICE);

  SearchableInfo searchableInfo = searchManager.getSearchableInfo(
    new ComponentName(getApplicationContext(),
      EarthquakeSearchResultActivity.class));

  SearchView searchView =
    (SearchView)menu.findItem(R.id.search_view).getActionView();
  searchView.setSearchableInfo(searchableInfo);
  searchView.setIconifiedByDefault(false);
  return true;
}
 
源代码11 项目: Wrox-ProfessionalAndroid-4E   文件: MainActivity.java
@Override
public boolean onCreateOptionsMenu(Menu menu) {
  // Inflate the options menu from XML
  MenuInflater inflater = getMenuInflater();
  inflater.inflate(R.menu.menu_main, menu);

  // Use the Search Manager to find the SearchableInfo related
  // to this Activity.
  SearchManager searchManager =
    (SearchManager) getSystemService(Context.SEARCH_SERVICE);
  SearchableInfo searchableInfo =
    searchManager.getSearchableInfo(getComponentName());

  SearchView searchView =
    (SearchView) menu.findItem(R.id.search_view).getActionView();
  searchView.setSearchableInfo(searchableInfo);
  searchView.setIconifiedByDefault(false);
  return true;
}
 
@Override
public boolean onCreateOptionsMenu(Menu menu) {
  super.onCreateOptionsMenu(menu);

  // Inflate the options menu from XML
  MenuInflater inflater = getMenuInflater();
  inflater.inflate(R.menu.options_menu, menu);

  // Use the Search Manager to find the SearchableInfo related
  // to the Search Result Activity.
  SearchManager searchManager =
    (SearchManager) getSystemService(Context.SEARCH_SERVICE);

  SearchableInfo searchableInfo = searchManager.getSearchableInfo(
    new ComponentName(getApplicationContext(),
      EarthquakeSearchResultActivity.class));

  SearchView searchView =
    (SearchView)menu.findItem(R.id.search_view).getActionView();
  searchView.setSearchableInfo(searchableInfo);
  searchView.setIconifiedByDefault(false);
  return true;
}
 
@Override
public boolean onCreateOptionsMenu(Menu menu) {
  super.onCreateOptionsMenu(menu);

  // Inflate the options menu from XML
  MenuInflater inflater = getMenuInflater();
  inflater.inflate(R.menu.options_menu, menu);

  // Use the Search Manager to find the SearchableInfo related
  // to the Search Result Activity.
  SearchManager searchManager =
    (SearchManager) getSystemService(Context.SEARCH_SERVICE);

  SearchableInfo searchableInfo = searchManager.getSearchableInfo(
    new ComponentName(getApplicationContext(),
      EarthquakeSearchResultActivity.class));

  SearchView searchView =
    (SearchView)menu.findItem(R.id.search_view).getActionView();
  searchView.setSearchableInfo(searchableInfo);
  searchView.setIconifiedByDefault(false);
  return true;
}
 
@Override
public boolean onCreateOptionsMenu(Menu menu) {
  super.onCreateOptionsMenu(menu);

  // Inflate the options menu from XML
  MenuInflater inflater = getMenuInflater();
  inflater.inflate(R.menu.options_menu, menu);

  // Use the Search Manager to find the SearchableInfo related
  // to the Search Result Activity.
  SearchManager searchManager =
    (SearchManager) getSystemService(Context.SEARCH_SERVICE);

  SearchableInfo searchableInfo = searchManager.getSearchableInfo(
    new ComponentName(getApplicationContext(),
      EarthquakeSearchResultActivity.class));

  SearchView searchView =
    (SearchView)menu.findItem(R.id.search_view).getActionView();
  searchView.setSearchableInfo(searchableInfo);
  searchView.setIconifiedByDefault(false);
  return true;
}
 
源代码15 项目: CSipSimple   文件: SearchView.java
/**
 * 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());
}
 
源代码16 项目: CSipSimple   文件: SearchView.java
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");
    }
}
 
源代码17 项目: Audinaut   文件: SubsonicFragment.java
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(v -> searchView.setQuery(getCurrentQuery(), false));
        }
    }
}
 
源代码18 项目: Toutiao   文件: SearchActivity.java
@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);
    }
 
源代码19 项目: PacketSender-Android   文件: MainActivity.java
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);
    }
 
源代码20 项目: Popeens-DSub   文件: SubsonicFragment.java
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);
				}
			});
		}
	}
}
 
源代码21 项目: io2015-codelabs   文件: SearchActivity.java
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);
    }
 
源代码22 项目: search-samples   文件: SearchActivity.java
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);
    }
 
源代码23 项目: zen4android   文件: SearchView.java
/**
 * 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());
}
 
源代码24 项目: zen4android   文件: SearchView.java
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");
    }
}
 
源代码25 项目: zhangshangwuda   文件: SearchView.java
/**
 * 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());
}
 
源代码26 项目: zhangshangwuda   文件: SearchView.java
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");
    }
}
 
源代码27 项目: codeexamples-android   文件: SearchViewActionBar.java
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);
    }
 
/**
 * 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");
    }
}
 
源代码30 项目: android_9.0.0_r45   文件: SearchManagerService.java
/**
 * Returns the SearchableInfo for a given activity.
 *
 * @param launchActivity The activity from which we're launching this search.
 * @return Returns a SearchableInfo record describing the parameters of the search,
 * or null if no searchable metadata was available.
 */
@Override
public SearchableInfo getSearchableInfo(final ComponentName launchActivity) {
    if (launchActivity == null) {
        Log.e(TAG, "getSearchableInfo(), activity == null");
        return null;
    }
    return getSearchables(UserHandle.getCallingUserId()).getSearchableInfo(launchActivity);
}
 
 类所在包
 同包方法