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:atv.com.project.monkeylivetv.Activity.MainActivity.java

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

    //Share/*from   w w w .j  av a2 s .  c  o m*/
    MenuItem menuItem = menu.findItem(R.id.action_share);
    shareActionProvider = (ShareActionProvider) MenuItemCompat.getActionProvider(menuItem);
    setShareIntent(createShareIntent());

    //Search
    MenuItem searchItem = menu.findItem(R.id.action_search);
    SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
    searchView.setOnQueryTextListener(this);

    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    searchView.setSearchableInfo(
            searchManager.getSearchableInfo(new ComponentName(this, SearchableActivity.class)));
    searchView.setIconifiedByDefault(false);

    return true;
}

From source file:sk.mpage.androidsample.searchviewtoolbar.SearchActivity.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_search, menu);

    searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    searchView = (SearchView) menu.findItem(R.id.search).getActionView();
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));

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

From source file:im.neon.activity.CountryPickerActivity.java

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

    final MenuItem searchItem = menu.findItem(R.id.action_search);
    if (searchItem != null) {
        SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
        mSearchView = (SearchView) MenuItemCompat.getActionView(searchItem);
        mSearchView.setMaxWidth(Integer.MAX_VALUE);
        mSearchView.setSubmitButtonEnabled(false);
        mSearchView.setQueryHint(getString(R.string.search_hint));
        mSearchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
        mSearchView.setOnQueryTextListener(this);
    }//from  www.  ja v  a  2  s .  c  o m
    return true;
}

From source file:im.vector.activity.CountryPickerActivity.java

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

    final MenuItem searchItem = menu.findItem(R.id.action_search);
    if (searchItem != null) {
        SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
        mSearchView = (SearchView) MenuItemCompat.getActionView(searchItem);
        mSearchView.setSubmitButtonEnabled(false);
        mSearchView.setQueryHint(getString(R.string.search_hint));
        mSearchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
        mSearchView.setOnQueryTextListener(this);
    }//www  .  j a  v  a2  s  . c o  m
    return true;
}

From source file:org.openmrs.client.activities.FindActiveVisitsSearchActivity.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Override/*ww  w .j ava 2 s.c o  m*/
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.find_patients_menu, menu);

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

    SearchView findPatientView;

    mFindActiveVisitItem = menu.findItem(R.id.actionSearch);
    if (OpenMRS.getInstance().isRunningHoneycombVersionOrHigher()) {
        findPatientView = (SearchView) mFindActiveVisitItem.getActionView();
    } else {
        findPatientView = (SearchView) MenuItemCompat.getActionView(mFindActiveVisitItem);
    }

    SearchableInfo info = searchManager.getSearchableInfo(getComponentName());
    findPatientView.setSearchableInfo(info);
    findPatientView.setIconifiedByDefault(false);
    return true;
}

From source file:org.onebusaway.android.util.UIUtils.java

/**
 * Sets up the search view in the action bar
 *//*from   w w w.  jav a2s. com*/
public static void setupSearch(Activity activity, Menu menu) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        SearchManager searchManager = (SearchManager) activity.getSystemService(Context.SEARCH_SERVICE);
        final MenuItem searchMenu = menu.findItem(R.id.action_search);
        SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchMenu);
        searchView.setSearchableInfo(searchManager.getSearchableInfo(activity.getComponentName()));
        // Close the keyboard and SearchView at same time when the back button is pressed
        searchView.setOnQueryTextFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View view, boolean queryTextFocused) {
                if (!queryTextFocused) {
                    MenuItemCompat.collapseActionView(searchMenu);
                }
            }
        });
    }
}

From source file:at.flack.activity.NewSMSContactActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.new_contact, menu);
    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    MenuItem searchMenuItem = menu.findItem(R.id.search);
    SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchMenuItem);

    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    searchView.setSubmitButtonEnabled(true);
    searchView.setOnQueryTextListener(this);
    return true;/*from   w ww.  j  av a  2s  .  com*/
}

From source file:com.keylesspalace.tusky.SearchActivity.java

private void setupSearchView(SearchView searchView) {
    searchView.setIconifiedByDefault(false);

    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    if (searchManager != null) {
        SearchableInfo searchableInfo = searchManager.getSearchableInfo(getComponentName());
        searchView.setSearchableInfo(searchableInfo);
    }//from  w  w w  .ja  v a  2s  . com

    searchView.setOnQueryTextListener(this);
    searchView.requestFocus();

    searchView.setMaxWidth(Integer.MAX_VALUE);
}

From source file:ch.kanti_baden.pu_marc_14b.traffictimewaste.SORT_TYPE.java

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

    // Disable create post button if user isn't logged in
    if (DatabaseLink.instance.isLoggedIn()) {
        MenuItem menuItem = menu.findItem(R.id.action_login);
        menuItem.setEnabled(false);/* www .  j a v  a2 s .  co m*/
    } else {
        MenuItem menuItem = menu.findItem(R.id.action_create);
        menuItem.setEnabled(false);
        Drawable icon = menuItem.getIcon();
        icon.mutate().setColorFilter(Color.GRAY, PorterDuff.Mode.SRC_IN);
        menuItem.setIcon(icon);
    }

    // Get the SearchView and set the searchable configuration
    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    final SearchView searchView = (SearchView) menu.findItem(R.id.action_search).getActionView();
    searchView.setOnSearchClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            searchView.setTranslationX(500f);
            searchView.setAlpha(0f);
            searchView.animate().translationX(0);
            searchView.animate().alpha(1f);
        }
    });
    // Assumes current activity is the searchable activity
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));

    return true;
}

From source file:com.andrada.sitracker.ui.SearchActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    final MenuItem searchItem = menu.findItem(R.id.action_search);
    if (searchItem != null) {
        SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
        final SearchView view = (SearchView) MenuItemCompat.getActionView(searchItem);
        mSearchView = view;/*ww w  .  jav a 2  s . co  m*/
        if (view == null) {
            LOGW(TAG, "Could not set up search view, view is null.");
        } else {
            view.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
            view.setIconified(false);
            view.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
                @Override
                public boolean onQueryTextSubmit(String s) {
                    view.clearFocus();
                    if (mAuthorsFragment != null) {
                        mAuthorsFragment.requestQueryUpdate(s, mCurrentSearchType);
                    }
                    return true;
                }

                @Override
                public boolean onQueryTextChange(String s) {
                    mQuery = s;
                    return true;
                }
            });
            view.setOnCloseListener(new SearchView.OnCloseListener() {
                @Override
                public boolean onClose() {
                    finish();
                    return false;
                }
            });

            ShowcaseView.Builder bldr = new ShowcaseView.Builder(this).setTarget(new ViewTarget(mSearchView))
                    .setContentTitle(getString(R.string.showcase_search_title))
                    .setContentText(getString(R.string.showcase_search_detail))
                    .setStyle(R.style.ShowcaseView_Base);
            if (!BuildConfig.DEBUG) {
                bldr.singleShot(Constants.SHOWCASE_ADD_AUTHORS_SEARCH_SHOT_ID);
            }
            bldr.build();

            if (!TextUtils.isEmpty(mQuery)) {
                view.setQuery(mQuery, false);
            }
        }
    }
    return true;
}