Example usage for android.app SearchManager getSearchableInfo

List of usage examples for android.app SearchManager getSearchableInfo

Introduction

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

Prototype

public SearchableInfo getSearchableInfo(ComponentName componentName) 

Source Link

Document

Gets information about a searchable activity.

Usage

From source file:ca.zadrox.dota2esportticker.ui.TeamSearchActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);
    getMenuInflater().inflate(R.menu.team_search, menu);
    MenuItem searchItem = menu.findItem(R.id.action_search);
    Toolbar.LayoutParams params = new Toolbar.LayoutParams(Toolbar.LayoutParams.MATCH_PARENT,
            Toolbar.LayoutParams.MATCH_PARENT);

    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    mSearchView = (SearchView) searchItem.getActionView();
    mSearchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));

    mSearchView.setLayoutParams(params);
    mSearchView.setMaxWidth(getResources().getDisplayMetrics().widthPixels);

    mSearchView.setIconifiedByDefault(false);
    mSearchView.setQueryHint("Search");

    ImageView magImage = (ImageView) mSearchView.findViewById(R.id.search_mag_icon);
    magImage.setLayoutParams(new LinearLayout.LayoutParams(0, 0));

    final EditText editText = (AutoCompleteTextView) mSearchView.findViewById(R.id.search_src_text);
    editText.setHintTextColor(getResources().getColor(R.color.theme_primary_light));

    if (mQuery != null) {
        mSearchView.setQuery(mQuery, false);
    } else {/* ww w.j  a v a  2s  .  c om*/
        mSearchView.requestFocus();
    }

    mSearchView.setOnSuggestionListener(new SearchView.OnSuggestionListener() {
        @Override
        public boolean onSuggestionSelect(int i) {
            return onSuggestionClick(i);
        }

        @Override
        public boolean onSuggestionClick(int i) {
            Cursor c = (Cursor) mSearchView.getSuggestionsAdapter().getItem(i);
            mSearchView.setQuery(c.getString(1), true);
            mSearchView.clearFocus();

            return true;
        }
    });

    return true;
}

From source file:com.jbirdvegas.mgerrit.ProjectsList.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the options menu from XML
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.projects_menu, menu);

    // Get the SearchView and set the searchable configuration
    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    SearchView searchView = (SearchView) menu.findItem(R.id.menu_search).getActionView();
    // Assumes current activity is the searchable activity
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    searchView.setIconifiedByDefault(true);
    searchView.setOnQueryTextListener(this);

    return true;// ww  w . j  a v a2  s.c om
}

From source file:com.github.mobile.ui.issue.IssuesFragment.java

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

    SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE);
    MenuItem searchItem = optionsMenu.findItem(R.id.m_search);
    SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName()));

    Bundle args = new Bundle();
    args.putSerializable(EXTRA_REPOSITORY, repository);
    searchView.setAppSearchData(args);/* ww  w . j  a  v  a 2  s . co m*/
}

From source file:com.meycup.ducksound.MainActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.menu, menu);

    SearchManager searchManager = (SearchManager) getSystemService(SEARCH_SERVICE);
    SearchView searchView;/* w  w w . j  a va2  s .  com*/

    MenuItem menuItem = menu.findItem(R.id.search);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        searchView = (SearchView) menuItem.getActionView();
    } else {
        searchView = (SearchView) MenuItemCompat.getActionView(menuItem);
    }

    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    searchView.setQueryHint("Pesquise por sua msica");
    return true;
}

From source file:com.tencent.wetest.activity.AppListActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    MenuInflater menuInflater = getMenuInflater();
    menuInflater.inflate(R.menu.menu_app_list, menu);

    MenuItem searchItem = menu.findItem(R.id.action_search);

    SearchManager searchManager = (SearchManager) AppListActivity.this.getSystemService(Context.SEARCH_SERVICE);

    SearchView searchView = null;// ww  w. j av  a  2 s .c  om
    if (searchItem != null) {
        searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
    }
    if (searchView != null) {
        searchView.setSearchableInfo(searchManager.getSearchableInfo(AppListActivity.this.getComponentName()));
    }

    if (searchView != null) {
        searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
            @Override
            public boolean onQueryTextSubmit(String query) {
                return false;
            }

            @Override
            public boolean onQueryTextChange(String newText) {
                filterAdpList(newText);
                return false;
            }
        });
    }

    return true;
}

From source file:org.goodev.material.SearchActivity.java

private void setupSearchView() {
    SearchManager searchManager = (SearchManager) getSystemService(SEARCH_SERVICE);
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    // hint, inputType & ime options seem to be ignored from XML! Set in code
    searchView.setQueryHint(getString(R.string.search_hint));
    searchView.setInputType(InputType.TYPE_TEXT_FLAG_CAP_WORDS);
    searchView.setImeOptions(searchView.getImeOptions() | EditorInfo.IME_ACTION_SEARCH
            | EditorInfo.IME_FLAG_NO_EXTRACT_UI | EditorInfo.IME_FLAG_NO_FULLSCREEN);
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override//  w  w  w .ja va  2  s. com
        public boolean onQueryTextSubmit(String query) {
            searchFor(query);
            return true;
        }

        @Override
        public boolean onQueryTextChange(String query) {
            if (TextUtils.isEmpty(query)) {
                clearResults();
            }
            return true;
        }
    });

}

From source file:com.github.pockethub.android.ui.issue.IssuesFragment.java

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

    SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE);
    MenuItem searchItem = optionsMenu.findItem(R.id.m_search);
    SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName()));

    Bundle args = new Bundle();
    args.putParcelable(EXTRA_REPOSITORY, repository);
    searchView.setAppSearchData(args);//from  ww w .  j  a va 2  s  .  c  o  m
}

From source file:io.romain.passport.ui.MainActivity.java

@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_city_list_activity, menu);

    // Associate searchable configuration with the SearchView
    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    SearchView searchView = (SearchView) MenuItemCompat.getActionView(menu.findItem(R.id.search));
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    searchView.setOnQueryTextListener(this);

    return true;/*from  ww w  . jav a  2s  .c om*/
}

From source file:com.github.pockethub.ui.issue.IssuesFragment.java

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

    SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE);
    MenuItem searchItem = optionsMenu.findItem(R.id.m_search);
    SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName()));

    Bundle args = new Bundle();
    args.putParcelable(EXTRA_REPOSITORY, repository);
    searchView.setAppSearchData(args);//  w  w w.jav  a  2  s  . c o  m
}

From source file:com.stoneapp.ourvlemoodle2.fragments.MembersFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        SearchManager searchManager = (SearchManager) context.getSystemService(Context.SEARCH_SERVICE);

        searchitem = menu.findItem(R.id.action_search);
        searchView = (SearchView) MenuItemCompat.getActionView(searchitem); // set up search view

        searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName()));

        searchView.setOnQueryTextListener(this);
        searchView.setQueryHint("Search name");

        searchView.setOnCloseListener(new SearchView.OnCloseListener() {
            @Override/*from  w ww .  ja  v a  2 s  . co m*/
            public boolean onClose() {
                searchView.setQuery("", false); // clears text from search view
                return true;
            }
        });
    }
}