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:com.jackleeentertainment.oq.ui.layout.fragment.ContactsListFragment.java

@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
@Override/*from   www.j  av  a 2s.c  o m*/
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {

    // Inflate the menu items
    inflater.inflate(R.menu.contact_list_menu, menu);
    // Locate the search item
    MenuItem searchItem = menu.findItem(R.id.menu_search);

    // In version 3.0 and later, sets up and configures the ActionBar SearchView
    if (Utils.hasHoneycomb()) {

        // Retrieves the system search manager service
        final SearchManager searchManager = (SearchManager) getActivity()
                .getSystemService(Context.SEARCH_SERVICE);

        // Retrieves the SearchView from the search menu item
        final SearchView searchView = (SearchView) searchItem.getActionView();

        // Assign searchable info to SearchView
        searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName()));

        // Set listeners for SearchView
        searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
            @Override
            public boolean onQueryTextSubmit(String queryText) {
                // Nothing needs to happen when the user submits the search string
                return true;
            }

            @Override
            public boolean onQueryTextChange(String newText) {
                // Called when the action bar search text has changed.  Updates
                // the search filter, and restarts the loader to do a new query
                // using the new search string.
                String newFilter = !TextUtils.isEmpty(newText) ? newText : null;

                // Don't do anything if the filter is empty
                if (mSearchTerm == null && newFilter == null) {
                    return true;
                }

                // Don't do anything if the new filter is the same as the current filter
                if (mSearchTerm != null && mSearchTerm.equals(newFilter)) {
                    return true;
                }

                // Updates current filter to new filter
                mSearchTerm = newFilter;

                // Restarts the loader. This triggers onCreateLoader(), which builds the
                // necessary content Uri from mSearchTerm.
                mSearchQueryChanged = true;
                getLoaderManager().restartLoader(ContactsQuery.QUERY_ID, null, ContactsListFragment.this);
                return true;
            }
        });

        if (Utils.hasICS()) {
            // This listener added in ICS
            searchItem.setOnActionExpandListener(new MenuItem.OnActionExpandListener() {
                @Override
                public boolean onMenuItemActionExpand(MenuItem menuItem) {
                    // Nothing to do when the action item is expanded
                    return true;
                }

                @Override
                public boolean onMenuItemActionCollapse(MenuItem menuItem) {
                    // When the user collapses the SearchView the current search string is
                    // cleared and the loader restarted.
                    if (!TextUtils.isEmpty(mSearchTerm)) {
                        onSelectionCleared();
                    }
                    mSearchTerm = null;
                    getLoaderManager().restartLoader(ContactsQuery.QUERY_ID, null, ContactsListFragment.this);
                    return true;
                }
            });
        }

        if (mSearchTerm != null) {
            // If search term is already set here then this fragment is
            // being restored from a saved state and the search menu item
            // needs to be expanded and populated again.

            // Stores the search term (as it will be wiped out by
            // onQueryTextChange() when the menu item is expanded).
            final String savedSearchTerm = mSearchTerm;

            // Expands the search menu item
            if (Utils.hasICS()) {
                searchItem.expandActionView();
            }

            // Sets the SearchView to the previous search string
            searchView.setQuery(savedSearchTerm, false);
        }
    }
}

From source file:com.chris.ni.omw.ContactsListFragment.java

@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
@Override/*from w  w  w .  ja  va2  s.c o  m*/
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);
    // Inflate the menu items
    inflater.inflate(R.menu.contact_list_menu, menu);
    // Locate the search item
    MenuItem searchItem = menu.findItem(R.id.menu_search);
    // In versions prior to Android 3.0, hides the search item to prevent additional
    // searches. In Android 3.0 and later, searching is done via a SearchView in the ActionBar.
    // Since the search doesn't create a new Activity to do the searching, the menu item
    // doesn't need to be turned off.
    if (mIsSearchResultView) {
        searchItem.setVisible(false);
    }

    // In version 3.0 and later, sets up and configures the ActionBar SearchView
    if (Utils.hasHoneycomb()) {

        // Retrieves the system search manager service
        final SearchManager searchManager = (SearchManager) getActivity()
                .getSystemService(Context.SEARCH_SERVICE);

        // Retrieves the SearchView from the search menu item
        final SearchView searchView = (SearchView) searchItem.getActionView();

        // Assign searchable info to SearchView
        searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName()));

        // Set listeners for SearchView
        searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
            @Override
            public boolean onQueryTextSubmit(String queryText) {
                // Nothing needs to happen when the user submits the search string
                return true;
            }

            @Override
            public boolean onQueryTextChange(String newText) {
                // Called when the action bar search text has changed.  Updates
                // the search filter, and restarts the loader to do a new query
                // using the new search string.
                String newFilter = !TextUtils.isEmpty(newText) ? newText : null;

                // Don't do anything if the filter is empty
                if (mSearchTerm == null && newFilter == null) {
                    return true;
                }

                // Don't do anything if the new filter is the same as the current filter
                if (mSearchTerm != null && mSearchTerm.equals(newFilter)) {
                    return true;
                }

                // Updates current filter to new filter
                mSearchTerm = newFilter;

                // Restarts the loader. This triggers onCreateLoader(), which builds the
                // necessary content Uri from mSearchTerm.
                mSearchQueryChanged = true;
                getLoaderManager().restartLoader(ContactsQuery.QUERY_ID, null, ContactsListFragment.this);
                return true;
            }
        });

        if (Utils.hasICS()) {
            // This listener added in ICS
            MenuItemCompat.setOnActionExpandListener(searchItem, new MenuItemCompat.OnActionExpandListener() {
                @Override
                public boolean onMenuItemActionExpand(MenuItem menuItem) {
                    // Nothing to do when the action item is expanded
                    return true;
                }

                @Override
                public boolean onMenuItemActionCollapse(MenuItem menuItem) {
                    // When the user collapses the SearchView the current search string is
                    // cleared and the loader restarted.
                    if (!TextUtils.isEmpty(mSearchTerm)) {
                        onSelectionCleared();
                    }
                    mSearchTerm = null;
                    getLoaderManager().restartLoader(ContactsQuery.QUERY_ID, null, ContactsListFragment.this);
                    return true;
                }
            });
        }

        if (mSearchTerm != null) {
            // If search term is already set here then this fragment is
            // being restored from a saved state and the search menu item
            // needs to be expanded and populated again.

            // Stores the search term (as it will be wiped out by
            // onQueryTextChange() when the menu item is expanded).
            final String savedSearchTerm = mSearchTerm;

            // Expands the search menu item
            if (Utils.hasICS()) {
                searchItem.expandActionView();
            }

            // Sets the SearchView to the previous search string
            searchView.setQuery(savedSearchTerm, false);
        }
    }
}

From source file:com.forktech.cmerge.ui.ContactsListFragment.java

@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
@Override/*  ww  w.j  a va2 s.  c  o m*/
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {

    // Inflate the menu items
    inflater.inflate(R.menu.contact_list_menu, menu);
    // Locate the search item
    MenuItem searchItem = menu.findItem(R.id.menu_search);

    // In versions prior to Android 3.0, hides the search item to prevent
    // additional
    // searches. In Android 3.0 and later, searching is done via a
    // SearchView in the ActionBar.
    // Since the search doesn't create a new Activity to do the searching,
    // the menu item
    // doesn't need to be turned off.
    if (mIsSearchResultView) {
        searchItem.setVisible(false);
    }

    // In version 3.0 and later, sets up and configures the ActionBar
    // SearchView
    if (Utils.hasHoneycomb()) {

        // Retrieves the system search manager service
        final SearchManager searchManager = (SearchManager) getActivity()
                .getSystemService(Context.SEARCH_SERVICE);

        // Retrieves the SearchView from the search menu item
        final SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);

        // Assign searchable info to SearchView
        searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName()));

        // Set listeners for SearchView
        searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
            @Override
            public boolean onQueryTextSubmit(String queryText) {
                // Nothing needs to happen when the user submits the
                // search string
                return true;
            }

            @Override
            public boolean onQueryTextChange(String newText) {
                // Called when the action bar search text has
                // changed. Updates
                // the search filter, and restarts the loader to do
                // a new query
                // using the new search string.
                String newFilter = !TextUtils.isEmpty(newText) ? newText : null;

                // Don't do anything if the filter is empty
                if (mSearchTerm == null && newFilter == null) {
                    return true;
                }

                // Don't do anything if the new filter is the same
                // as the current filter
                if (mSearchTerm != null && mSearchTerm.equals(newFilter)) {
                    return true;
                }

                // Updates current filter to new filter
                mSearchTerm = newFilter;
                mAdapter.setSearchTerm(newFilter);

                // Restarts the loader. This triggers
                // onCreateLoader(), which builds the
                // necessary content Uri from mSearchTerm.
                mSearchQueryChanged = true;
                getLoaderManager().restartLoader(ContactsQuery.QUERY_ID, null, ContactsListFragment.this);
                return true;
            }
        });

        // if (Utils.hasICS()) {
        // // This listener added in ICS
        // searchItem.setOnActionExpandListener(new
        // MenuItem.OnActionExpandListener() {
        // @Override
        // public boolean onMenuItemActionExpand(MenuItem menuItem) {
        // // Nothing to do when the action item is expanded
        // return true;
        // }
        //
        // @Override
        // public boolean onMenuItemActionCollapse(MenuItem menuItem) {
        // // When the user collapses the SearchView the current search
        // string is
        // // cleared and the loader restarted.
        // if (!TextUtils.isEmpty(mSearchTerm)) {
        // onSelectionCleared();
        // }
        // mSearchTerm = null;
        // mAdapter.setSearchTerm(null);
        // getLoaderManager().restartLoader(
        // ContactsQuery.QUERY_ID, null, ContactsListFragment.this);
        // return true;
        // }
        // });
        // }

        if (mSearchTerm != null) {
            // If search term is already set here then this fragment is
            // being restored from a saved state and the search menu item
            // needs to be expanded and populated again.

            // Stores the search term (as it will be wiped out by
            // onQueryTextChange() when the menu item is expanded).
            final String savedSearchTerm = mSearchTerm;

            // Expands the search menu item
            if (Utils.hasICS()) {
                searchItem.expandActionView();
            }

            // Sets the SearchView to the previous search string
            searchView.setQuery(savedSearchTerm, false);
        }
    }
}

From source file:android.com.example.contactslist.ui.ContactsListFragment.java

@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
@Override/*  w ww.  jav  a 2 s. c  o  m*/
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {

    // Inflate the menu items
    inflater.inflate(R.menu.contact_list_menu, menu);
    // Locate the search item
    MenuItem searchItem = menu.findItem(R.id.menu_search);

    // In versions prior to Android 3.0, hides the search item to prevent additional
    // searches. In Android 3.0 and later, searching is done via a SearchView in the ActionBar.
    // Since the search doesn't create a new Activity to do the searching, the menu item
    // doesn't need to be turned off.
    if (mIsSearchResultView) {
        searchItem.setVisible(false);
    }

    // In version 3.0 and later, sets up and configures the ActionBar SearchView
    if (Utils.hasHoneycomb()) {

        // Retrieves the system search manager service
        final SearchManager searchManager = (SearchManager) getActivity()
                .getSystemService(Context.SEARCH_SERVICE);

        // Retrieves the SearchView from the search menu item
        final SearchView searchView = (SearchView) searchItem.getActionView();

        // Assign searchable info to SearchView
        searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName()));

        // Set listeners for SearchView
        searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
            @Override
            public boolean onQueryTextSubmit(String queryText) {
                // Nothing needs to happen when the user submits the search string
                return true;
            }

            @Override
            public boolean onQueryTextChange(String newText) {
                // Called when the action bar search text has changed.  Updates
                // the search filter, and restarts the loader to do a new query
                // using the new search string.
                String newFilter = !TextUtils.isEmpty(newText) ? newText : null;

                // Don't do anything if the filter is empty
                if (mSearchTerm == null && newFilter == null) {
                    return true;
                }

                // Don't do anything if the new filter is the same as the current filter
                if (mSearchTerm != null && mSearchTerm.equals(newFilter)) {
                    return true;
                }

                // Updates current filter to new filter
                mSearchTerm = newFilter;

                // Restarts the loader. This triggers onCreateLoader(), which builds the
                // necessary content Uri from mSearchTerm.
                mSearchQueryChanged = true;
                getLoaderManager().restartLoader(ContactsQuery.QUERY_ID, null, ContactsListFragment.this);
                return true;
            }
        });

        if (Utils.hasICS()) {
            // This listener added in ICS
            searchItem.setOnActionExpandListener(new MenuItem.OnActionExpandListener() {
                @Override
                public boolean onMenuItemActionExpand(MenuItem menuItem) {
                    // Nothing to do when the action item is expanded
                    return true;
                }

                @Override
                public boolean onMenuItemActionCollapse(MenuItem menuItem) {
                    // When the user collapses the SearchView the current search string is
                    // cleared and the loader restarted.
                    if (!TextUtils.isEmpty(mSearchTerm)) {
                        onSelectionCleared();
                    }
                    mSearchTerm = null;
                    getLoaderManager().restartLoader(ContactsQuery.QUERY_ID, null, ContactsListFragment.this);
                    return true;
                }
            });
        }

        if (mSearchTerm != null) {
            // If search term is already set here then this fragment is
            // being restored from a saved state and the search menu item
            // needs to be expanded and populated again.

            // Stores the search term (as it will be wiped out by
            // onQueryTextChange() when the menu item is expanded).
            final String savedSearchTerm = mSearchTerm;

            // Expands the search menu item
            if (Utils.hasICS()) {
                searchItem.expandActionView();
            }

            // Sets the SearchView to the previous search string
            searchView.setQuery(savedSearchTerm, false);
        }
    }
}

From source file:gc.david.dfm.ui.activity.MainActivity.java

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

    searchMenuItem = menu.findItem(R.id.action_search);
    final SearchView searchView = (SearchView) searchMenuItem.getActionView();
    final SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    // Indicamos que la activity actual sea la buscadora
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    searchView.setSubmitButtonEnabled(false);
    searchView.setQueryRefinementEnabled(true);
    searchView.setIconifiedByDefault(true);

    // TODO: 16.01.17 move this to presenter
    final MenuItem loadItem = menu.findItem(R.id.action_load);
    loadDistancesUseCase.execute(new LoadDistancesUseCase.Callback() {
        @Override//  w  ww.ja  v a  2 s .  c  o  m
        public void onDistanceListLoaded(final List<Distance> distanceList) {
            if (distanceList.isEmpty()) {
                loadItem.setVisible(false);
            }
        }

        @Override
        public void onError() {
            loadItem.setVisible(false);
        }
    });

    menu.findItem(R.id.action_crash).setVisible(!isReleaseBuild());

    return super.onCreateOptionsMenu(menu);
}

From source file:co.tinode.tindroid.ContactsFragment.java

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

    // Inflate the menu items
    inflater.inflate(R.menu.menu_contacts, menu);

    // Locate the search item
    MenuItem searchItem = menu.findItem(R.id.menu_search);

    // Retrieves the system search manager service
    final SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE);

    // Retrieves the SearchView from the search menu item
    final SearchView searchView = (SearchView) searchItem.getActionView();
    // searchView.setFocusable(true);

    // Assign searchable info to SearchView
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName()));

    // Set listeners for SearchView
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override//from   ww  w . j a  va2  s.c  o m
        public boolean onQueryTextSubmit(String queryText) {
            // Nothing needs to happen when the user submits the search string
            return true;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            // Called when the action bar search text has changed.  Updates
            // the search filter, and restarts the loader to do a new query
            // using the new search string.
            String newFilter = !TextUtils.isEmpty(newText) ? newText : null;

            // Don't do anything if the filter is empty
            if (mSearchTerm == null && newFilter == null) {
                return true;
            }

            // Don't do anything if the new filter is the same as the current filter
            if (mSearchTerm != null && mSearchTerm.equals(newFilter)) {
                return true;
            }

            // Updates current filter to new filter
            mSearchTerm = newFilter;

            // Restarts the loader. This triggers onCreateLoader(), which builds the
            // necessary content Uri from mSearchTerm.
            getLoaderManager().restartLoader(ContactsQuery.CORE_QUERY_ID, null, mContactsLoaderCallback);
            return true;
        }
    });

    MenuItemCompat.setOnActionExpandListener(searchItem, new MenuItemCompat.OnActionExpandListener() {
        @Override
        public boolean onMenuItemActionExpand(MenuItem menuItem) {
            Log.d(TAG, "EXPAND onMenuItemActionCollapse");
            searchView.setIconified(false);
            searchView.requestFocusFromTouch();
            return true;
        }

        @Override
        public boolean onMenuItemActionCollapse(MenuItem menuItem) {
            Log.d(TAG, "COLLAPSE onMenuItemActionCollapse");
            searchView.clearFocus();
            // When the user collapses the SearchView the current search string is
            // cleared and the loader restarted.
            if (!TextUtils.isEmpty(mSearchTerm)) {
                onSelectionCleared();
            }
            mSearchTerm = null;
            getLoaderManager().restartLoader(ContactsQuery.CORE_QUERY_ID, null, mContactsLoaderCallback);
            return true;
        }
    });

    if (mSearchTerm != null) {
        // If search term is already set here then this fragment is
        // being restored from a saved state and the search menu item
        // needs to be expanded and populated again.

        // Stores the search term (as it will be wiped out by
        // onQueryTextChange() when the menu item is expanded).
        final String savedSearchTerm = mSearchTerm;

        // Expands the search menu item
        searchItem.expandActionView();

        // Sets the SearchView to the previous search string
        searchView.setQuery(savedSearchTerm, false);
    }
}

From source file:br.com.mybaby.contatos.ContactsListFragment.java

@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
@Override/*from   w  w w  . ja v  a  2  s.c o m*/
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {

    // Inflate the menu items
    inflater.inflate(R.menu.contatos_list_menu, menu);
    // Locate the search item
    MenuItem searchItem = menu.findItem(R.id.menu_search);

    // In versions prior to Android 3.0, hides the search item to prevent additional
    // searches. In Android 3.0 and later, searching is done via a SearchView in the ActionBar.
    // Since the search doesn't create a new Activity to do the searching, the menu item
    // doesn't need to be turned off.
    if (mIsSearchResultView) {
        searchItem.setVisible(false);
    }

    // In version 3.0 and later, sets up and configures the ActionBar SearchView
    if (Util.hasHoneycomb()) {

        // Retrieves the system search manager service
        final SearchManager searchManager = (SearchManager) getActivity()
                .getSystemService(Context.SEARCH_SERVICE);

        // Retrieves the SearchView from the search menu item
        final SearchView searchView = (SearchView) searchItem.getActionView();

        // Assign searchable info to SearchView
        searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName()));

        // Set listeners for SearchView
        searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
            @Override
            public boolean onQueryTextSubmit(String queryText) {
                // Nothing needs to happen when the user submits the search string
                return true;
            }

            @Override
            public boolean onQueryTextChange(String newText) {
                // Called when the action bar search text has changed.  Updates
                // the search filter, and restarts the loader to do a new query
                // using the new search string.
                String newFilter = !TextUtils.isEmpty(newText) ? newText : null;

                // Don't do anything if the filter is empty
                if (mSearchTerm == null && newFilter == null) {
                    return true;
                }

                // Don't do anything if the new filter is the same as the current filter
                if (mSearchTerm != null && mSearchTerm.equals(newFilter)) {
                    return true;
                }

                // Updates current filter to new filter
                mSearchTerm = newFilter;

                // Restarts the loader. This triggers onCreateLoader(), which builds the
                // necessary content Uri from mSearchTerm.
                mSearchQueryChanged = true;
                getLoaderManager().restartLoader(ContactsQuery.QUERY_ID, null, ContactsListFragment.this);
                return true;
            }
        });

        if (Util.hasICS()) {
            // This listener added in ICS
            searchItem.setOnActionExpandListener(new MenuItem.OnActionExpandListener() {
                @Override
                public boolean onMenuItemActionExpand(MenuItem menuItem) {
                    // Nothing to do when the action item is expanded
                    return true;
                }

                @Override
                public boolean onMenuItemActionCollapse(MenuItem menuItem) {
                    // When the user collapses the SearchView the current search string is
                    // cleared and the loader restarted.
                    if (!TextUtils.isEmpty(mSearchTerm)) {
                        onSelectionCleared();
                    }
                    mSearchTerm = null;
                    getLoaderManager().restartLoader(ContactsQuery.QUERY_ID, null, ContactsListFragment.this);
                    return true;
                }
            });
        }

        if (mSearchTerm != null) {
            // If search term is already set here then this fragment is
            // being restored from a saved state and the search menu item
            // needs to be expanded and populated again.

            // Stores the search term (as it will be wiped out by
            // onQueryTextChange() when the menu item is expanded).
            final String savedSearchTerm = mSearchTerm;

            // Expands the search menu item
            if (Util.hasICS()) {
                searchItem.expandActionView();
            }

            // Sets the SearchView to the previous search string
            searchView.setQuery(savedSearchTerm, false);
        }
    }
}

From source file:com.paramonod.kikos.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_main, menu);
    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    searchView = (SearchView) MenuItemCompat.getActionView(menu.findItem(R.id.action_settings));
    System.out.println(searchView);
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));

    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override//from   ww w. ja  v  a  2s.co  m
        public boolean onQueryTextSubmit(String query) {
            Menu menu = bottomNavigationView.getMenu();
            Menu mm = navigationView.getMenu();
            FragmentManager fragmentManager = MainActivity.this.getSupportFragmentManager();
            List<Fragment> fragments = fragmentManager.getFragments();
            Fragment f = null;
            System.out.println(fragments);
            if (fragments != null) {
                for (Fragment fragment : fragments) {
                    if (fragment != null && fragment.isVisible())
                        f = fragment;
                    System.out.println(f);
                }
            }
            if (f instanceof CardContentFragment) {
                main.searchListener(query, 2);

            }
            if (f instanceof CategoryContentFragment) {
                main.searchListener(query, 1);

            }
            if (f instanceof MapViewFragment) {
                main.searchListener(query, 0);

            }
            if (f instanceof ListContentFragment) {
                main.searchListener(query, 3);
            }
            if (mm.getItem(1).isChecked()) {
                main.searchListener(query, 3);
            } else
                for (int i = 0; i < bottomNavigationView.getMenu().size(); i++) {
                    MenuItem menuItem = menu.getItem(i);
                    if (menuItem.isChecked()) {
                        main.searchListener(query, i);
                    }
                }

            return false;
        }

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

    return super.onCreateOptionsMenu(menu);
}

From source file:com.vishwa.pinit.MainActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.main_action_bar, menu);
    mMenu = menu;//w  w  w  .j ava2s  .  com
    mSearchMenuItem = menu.findItem(R.id.action_search);
    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    mSearchView = (SearchView) mSearchMenuItem.getActionView();
    mSearchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    mSearchView.setQueryHint("Search for locations...");

    mSearchView.setOnSuggestionListener(new OnSuggestionListener() {

        @Override
        public boolean onSuggestionSelect(int position) {
            return false;
        }

        @Override
        public boolean onSuggestionClick(int position) {
            CursorAdapter adapter = mSearchView.getSuggestionsAdapter();
            Cursor cursor = adapter.getCursor();
            if (cursor != null) {
                if (cursor.moveToPosition(position)) {
                    InputMethodManager imm = (InputMethodManager) getSystemService(
                            Context.INPUT_METHOD_SERVICE);
                    imm.hideSoftInputFromWindow(mSearchView.getWindowToken(), 0);
                    mSearchMenuItem.collapseActionView();
                    String geolocation = cursor
                            .getString(cursor.getColumnIndex(SearchManager.SUGGEST_COLUMN_INTENT_DATA_ID));
                    if (geolocation != null && !geolocation.isEmpty()) {
                        double latitude = Double.parseDouble(geolocation.split(",")[0]);
                        double longitude = Double.parseDouble(geolocation.split(",")[1]);
                        LatLng geopoint = new LatLng(latitude, longitude);
                        mMap.animateCamera(
                                CameraUpdateFactory.newCameraPosition(new CameraPosition(geopoint, 17, 0, 0)));
                    }
                }
            }
            return true;
        }
    });

    mSearchView.setOnQueryTextListener(new OnQueryTextListener() {

        @Override
        public boolean onQueryTextSubmit(String query) {
            CursorAdapter adapter = mSearchView.getSuggestionsAdapter();
            Cursor cursor = adapter.getCursor();
            if (cursor != null) {
                if (cursor.moveToFirst()) {
                    InputMethodManager imm = (InputMethodManager) getSystemService(
                            Context.INPUT_METHOD_SERVICE);
                    imm.hideSoftInputFromWindow(mSearchView.getWindowToken(), 0);
                    mSearchMenuItem.collapseActionView();
                    String geolocation = cursor
                            .getString(cursor.getColumnIndex(SearchManager.SUGGEST_COLUMN_INTENT_DATA_ID));
                    if (geolocation != null && !geolocation.isEmpty()) {
                        double latitude = Double.parseDouble(geolocation.split(",")[0]);
                        double longitude = Double.parseDouble(geolocation.split(",")[1]);
                        LatLng geopoint = new LatLng(latitude, longitude);
                        mMap.animateCamera(
                                CameraUpdateFactory.newCameraPosition(new CameraPosition(geopoint, 17, 0, 0)));
                    }
                }
            }
            return true;
        }

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

    if (!mHasInternet) {
        hideNonRefreshMenuItems();
    } else {
        showNonRefreshMenuItems();
    }
    return true;
}

From source file:com.tavant.droid.womensecurity.fragments.ContactsListFragment.java

@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
@Override//from  w w w  .  j ava  2s  . c  o  m
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {

    // Inflate the menu items
    inflater.inflate(R.menu.contacts_list_menu, menu);
    // Locate the search item
    MenuItem searchItem = menu.findItem(R.id.menu_search);

    // In versions prior to Android 3.0, hides the search item to prevent
    // additional
    // searches. In Android 3.0 and later, searching is done via a
    // SearchView in the ActionBar.
    // Since the search doesn't create a new Activity to do the searching,
    // the menu item
    // doesn't need to be turned off.
    if (mIsSearchResultView) {
        searchItem.setVisible(false);
    }

    // In version 3.0 and later, sets up and configures the ActionBar
    // SearchView
    if (Utils.hasHoneycomb()) {

        // Retrieves the system search manager service
        final SearchManager searchManager = (SearchManager) getActivity()
                .getSystemService(Context.SEARCH_SERVICE);

        // Retrieves the SearchView from the search menu item
        final SearchView searchView = (SearchView) searchItem.getActionView();

        // Assign searchable info to SearchView
        searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName()));

        // Set listeners for SearchView
        searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
            @Override
            public boolean onQueryTextSubmit(String queryText) {
                // Nothing needs to happen when the user submits the
                // search string
                return true;
            }

            @Override
            public boolean onQueryTextChange(String newText) {
                // Called when the action bar search text has
                // changed. Updates
                // the search filter, and restarts the loader to do
                // a new query
                // using the new search string.
                String newFilter = !TextUtils.isEmpty(newText) ? newText : null;

                // Don't do anything if the filter is empty
                if (mSearchTerm == null && newFilter == null) {
                    return true;
                }

                // Don't do anything if the new filter is the same
                // as the current filter
                if (mSearchTerm != null && mSearchTerm.equals(newFilter)) {
                    return true;
                }

                // Updates current filter to new filter
                mSearchTerm = newFilter;

                // Restarts the loader. This triggers
                // onCreateLoader(), which builds the
                // necessary content Uri from mSearchTerm.
                mSearchQueryChanged = true;
                getLoaderManager().restartLoader(ContactsQuery.QUERY_ID, null, ContactsListFragment.this);
                return true;
            }
        });

        if (Utils.hasICS()) {
            // This listener added in ICS
            searchItem.setOnActionExpandListener(new MenuItem.OnActionExpandListener() {
                @Override
                public boolean onMenuItemActionExpand(MenuItem menuItem) {
                    // Nothing to do when the action item is
                    // expanded
                    return true;
                }

                @Override
                public boolean onMenuItemActionCollapse(MenuItem menuItem) {
                    // When the user collapses the SearchView the
                    // current search string is
                    // cleared and the loader restarted.
                    if (!TextUtils.isEmpty(mSearchTerm)) {
                        onSelectionCleared();
                    }
                    mSearchTerm = null;
                    getLoaderManager().restartLoader(ContactsQuery.QUERY_ID, null, ContactsListFragment.this);
                    return true;
                }
            });
        }

        if (mSearchTerm != null) {
            // If search term is already set here then this fragment is
            // being restored from a saved state and the search menu item
            // needs to be expanded and populated again.

            // Stores the search term (as it will be wiped out by
            // onQueryTextChange() when the menu item is expanded).
            final String savedSearchTerm = mSearchTerm;

            // Expands the search menu item
            if (Utils.hasICS()) {
                searchItem.expandActionView();
            }

            // Sets the SearchView to the previous search string
            searchView.setQuery(savedSearchTerm, false);
        }
    }
}