Example usage for android.content Context SEARCH_SERVICE

List of usage examples for android.content Context SEARCH_SERVICE

Introduction

In this page you can find the example usage for android.content Context SEARCH_SERVICE.

Prototype

String SEARCH_SERVICE

To view the source code for android.content Context SEARCH_SERVICE.

Click Source Link

Document

Use with #getSystemService(String) to retrieve a android.app.SearchManager for handling searches.

Usage

From source file:net.vivekiyer.GAL.CorporateAddressBook.java

@TargetApi(11)
@Override//w w  w  . j a  v  a  2 s.co  m
public boolean onCreateOptionsMenu(Menu menu) {
    final MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.main_menu, menu);

    // Get the SearchView and set the searchable configuration for Honeycomb
    // and above
    if (!Utility.isPreHoneycomb()) {
        final SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
        final ComponentName component = getComponentName();
        final SearchableInfo searchableInfo = searchManager.getSearchableInfo(component);
        searchView = (SearchView) menu.findItem(R.id.menu_search).getActionView();
        searchView.setSearchableInfo(searchableInfo);

        //this.onSearchRequested();
    }

    return super.onCreateOptionsMenu(menu);
}

From source file:com.hybris.mobile.app.commerce.activity.MainActivity.java

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

    // HockeyApp feedback
    menu.findItem(R.id.menu_feedback).setOnMenuItemClickListener(new OnMenuItemClickListener() {

        @Override/*from  ww  w.jav  a 2s  .  c  om*/
        public boolean onMenuItemClick(MenuItem item) {
            HockeyAppUtils.showFeedbackActivity(MainActivity.this);
            return true;
        }
    });

    // Sync Settings
    menu.findItem(R.id.menu_settings).setOnMenuItemClickListener(new OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            startActivity(new Intent(MainActivity.this, SettingsActivity.class));
            return true;
        }
    });

    // Barcode scanner
    menu.findItem(R.id.menu_scanner).setOnMenuItemClickListener(new OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            CommerceApplication.getScannerHelper().launch(MainActivity.this, MainActivity.this);
            return true;
        }
    });

    // Cart items
    MenuItem item = menu.findItem(R.id.b2b_icon_cart);

    if (mCartDrawer != null) {

        // Onclick to open/hide cart menu
        item.getActionView().setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                if (mDrawerLayout != null) {
                    mDrawerLayout.closeDrawers();
                }
                if (mCartDrawer.isDrawerOpen(mCartDrawer.getChildAt(1))) {
                    mCartDrawer.closeDrawer(mCartDrawer.getChildAt(1));
                } else {
                    mCartDrawer.openDrawer(mCartDrawer.getChildAt(1));
                }
            }
        });
    } else {
        menu.removeItem(R.id.b2b_icon_cart);
    }

    // Search component
    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    SearchView searchView = (SearchView) menu.findItem(R.id.b2b_icon_search).getActionView();
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    searchView.setIconifiedByDefault(true);

    return true;
}

From source file:com.klinker.android.twitter.activities.drawer_activities.discover.trends.SearchedTrendsActivity.java

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

    // Get the SearchView and set the searchable configuration
    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    searchView = (SearchView) menu.findItem(R.id.menu_search).getActionView();
    // Assumes current activity is the searchable activity
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    searchView.setIconifiedByDefault(true); // Do not iconify the widget; expand it by default

    int searchImgId = getResources().getIdentifier("android:id/search_button", null, null);
    ImageView view = (ImageView) searchView.findViewById(searchImgId);
    view.setImageResource(settings.theme == AppSettings.THEME_LIGHT ? R.drawable.ic_action_search_light
            : R.drawable.ic_action_search_dark);

    return true;//www  . j av  a  2  s . c o m
}

From source file:it.gulch.linuxday.android.activities.MainActivity.java

@SuppressLint("NewApi")
@Override/*from ww  w  .j a  va  2s.  co  m*/
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.main, menu);

    MenuItem searchMenuItem = menu.findItem(R.id.search);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO) {
        this.searchMenuItem = searchMenuItem;
        // Associate searchable configuration with the SearchView
        SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
        SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchMenuItem);
        searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    } else {
        // Legacy search mode for Eclair
        MenuItemCompat.setActionView(searchMenuItem, null);
        MenuItemCompat.setShowAsAction(searchMenuItem, MenuItemCompat.SHOW_AS_ACTION_IF_ROOM);
    }

    return true;
}

From source file:com.esri.android.ecologicalmarineunitexplorer.MainActivity.java

/**
 *
 * @param menu Menu/*from  w  w w .  ja v  a2 s  .  c  om*/
 * @return boolean
 */
@Override
public boolean onCreateOptionsMenu(final Menu menu) {
    super.onCreateOptionsMenu(menu);
    getMenuInflater().inflate(R.menu.menu, menu);
    // Retrieve the SearchView and plug it into SearchManager
    final SearchView searchView = (SearchView) MenuItemCompat.getActionView(menu.findItem(R.id.action_search));
    searchView.setQueryHint(getString(R.string.query_hint));
    final SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(final String query) {
            mMapPresenter.geocodeAddress(query);
            searchView.clearFocus();
            return true;
        }

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

From source file:learn2crack.activities.WnContactsListFragment.java

@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
@Override/*from  www  .  j  a  va2s  .co  m*/
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    MenuItem searchItem = menu.findItem(R.id.action_search);

    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);
        //final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        //toolbar.setNavigationContentDescription(new Toolbar.On);
        //searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName()));

        // 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, WnContactsListFragment.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, WnContactsListFragment.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.ferid.app.frequentcontacts.selectnumber.SelectNumberActivity.java

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

    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    SearchView searchView = (SearchView) menu.findItem(R.id.ic_action_search).getActionView();
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override/*w w  w.ja  v  a2  s.c o  m*/
        public boolean onQueryTextSubmit(String s) {
            return true;
        }

        @Override
        public boolean onQueryTextChange(String s) {
            if (s.length() >= 1)
                searchEngine(s);
            else {
                numberList.clear();
                numberList.addAll(wholeArrayList);
                adapter.notifyDataSetChanged();
            }
            return true;
        }
    });

    return true;
}

From source file:com.klinker.android.twitter.activities.search.SearchPager.java

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

    // Get the SearchView and set the searchable configuration
    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    searchView = (SearchView) menu.findItem(R.id.menu_search).getActionView();

    // Assumes current activity is the searchable activity
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    searchView.setIconifiedByDefault(true);

    int searchImgId = getResources().getIdentifier("android:id/search_button", null, null);
    ImageView view = (ImageView) searchView.findViewById(searchImgId);
    view.setImageResource(settings.theme == AppSettings.THEME_LIGHT ? R.drawable.ic_action_search_light
            : R.drawable.ic_action_search_dark);

    return true;/*w ww.j a  va 2  s  .c om*/
}

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   w ww  .ja  va  2 s . c  o  m*/
}

From source file:com.peaceworld.wikisms.view.newui.BaseActivity.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void loadData(String query) {

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {

        // Load data from list to cursor
        String[] columns = new String[] { "_id", "text", "cid" };
        Object[] temp = new Object[] { 0, "name", -1l };

        MatrixCursor cursor = new MatrixCursor(columns);

        int index = 0;
        for (int i = 0; i < items.size(); i++) {
            if (query == null || items.get(i).getName().contains(query.trim())) {
                temp[0] = index;//  www .  j a va2 s.  c o  m
                temp[1] = items.get(i).getName();
                temp[2] = items.get(i).getId();
                cursor.addRow(temp);
                index++;
            }
        }

        temp[0] = index;
        temp[1] = "     " + " \"" + query + "\" ";
        temp[2] = query.trim();
        cursor.addRow(temp);

        SearchManager manager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);

        final SearchView search = (SearchView) menu.findItem(R.id.menu_search).getActionView();

        search.setSearchableInfo(manager.getSearchableInfo(getComponentName()));
        ActionBarSearchAdapter adapter = new ActionBarSearchAdapter(this, cursor, this, search);
        search.setSuggestionsAdapter(adapter);

    }

}