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.google.samples.apps.sergio.ui.SearchActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);
    getMenuInflater().inflate(R.menu.search, menu);
    final MenuItem searchItem = menu.findItem(R.id.menu_search);
    if (searchItem != null) {
        SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
        final SearchView view = (SearchView) searchItem.getActionView();
        mSearchView = view;/*from  w  w  w  .j  av a 2s . c om*/
        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 ("zzznotif".equals(s)) {
                        (new ShowFeedbackNotificationAction()).run(SearchActivity.this, null);
                    }
                    return true;
                }

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

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

From source file:com.rowland.movies.ui.activities.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);
    // Acquire the search manager
    SearchManager SManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    // Acquire the relevant search menu item
    MenuItem searchMenuItem = menu.findItem(R.id.action_search);
    // Acquire the search view
    SearchView mSearchView = (SearchView) MenuItemCompat.getActionView(searchMenuItem);
    // Set the Search activity class
    mSearchView.setSearchableInfo(/*from  w ww.  j a  v  a 2s  .c o m*/
            SManager.getSearchableInfo(new ComponentName(getApplicationContext(), SearchActivity.class)));
    // Set if should use an icon
    mSearchView.setIconifiedByDefault(true);
    // return whether menu was succesfully created
    return super.onCreateOptionsMenu(menu);
}

From source file:org.addhen.smssync.presentation.view.ui.activity.MainActivity.java

private void initSearchView() {
    final SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    mSearchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    mSearchView.clearFocus();/*w ww  .j a va2s  .c o  m*/
    mSearchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String s) {
            mSearchView.clearFocus();
            performQuery(s);
            return true;
        }

        @Override
        public boolean onQueryTextChange(String s) {
            performQuery(s);
            return true;
        }
    });

    mSearchView.setOnCloseListener(new SearchView.OnCloseListener() {
        @Override
        public boolean onClose() {
            reloadMessages();
            return false;
        }
    });

    if (!TextUtils.isEmpty(mQuery)) {
        mSearchView.setQuery(mQuery, false);
    }
    SearchView.SearchAutoComplete searchAutoComplete = (SearchView.SearchAutoComplete) mSearchView
            .findViewById(android.support.v7.appcompat.R.id.search_src_text);
    searchAutoComplete.setHintTextColor(getResources().getColor(android.R.color.white));
    searchAutoComplete.setTextSize(14);
}

From source file:im.ene.lab.attiq.ui.activities.SearchActivity.java

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

          @Override
          public boolean onQueryTextChange(String query) {
              if (TextUtils.isEmpty(query)) {
                  clearResults();
              }
              return true;
          }
      });
      mSearchView.setOnQueryTextFocusChangeListener(new View.OnFocusChangeListener() {
          @Override
          public void onFocusChange(View v, boolean hasFocus) {

          }
      });
  }

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

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Override//from  w  w  w .j a  v  a2 s.  c om
public boolean onCreateOptionsMenu(Menu menu) {
    this.getSupportActionBar()
            .setSubtitle(getString(R.string.dashboard_logged_as, OpenMRS.getInstance().getUsername()));
    getMenuInflater().inflate(R.menu.find_patients_menu, menu);

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

    SearchView findVisitView;

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

    SearchableInfo info = searchManager.getSearchableInfo(getComponentName());
    findVisitView.setSearchableInfo(info);
    return true;
}

From source file:com.bukanir.android.activities.MoviesListActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.main, menu);
    MenuItem searchItem = menu.findItem(R.id.action_search);
    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    searchView.setIconifiedByDefault(false);
    return true;/*from w  w w  .  j  av a2s .  c  om*/
}

From source file:com.sage42.androidappaddicts.app.main.MainActivity.java

@OptionsItem(R.id.action_search)
public void initSearchView(final MenuItem item) {

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

    this.mSearchViewMenuItem = item;
    this.mSearchView = (SearchView) this.mSearchViewMenuItem.getActionView();
    this.mSearchView.setSearchableInfo(searchManager.getSearchableInfo(this.getComponentName()));
    this.mSearchView.setIconifiedByDefault(true);

    this.setSearchTextColour(this.mSearchView);
    this.mSearchView.setQueryHint("Search Apps"); //$NON-NLS-1$
    this.mSearchView.setSuggestionsAdapter(this.mAdapter);
    this.mSearchViewMenuItem.setOnActionExpandListener(new OnActionExpandListener() {

        @Override/*from   w w  w  .  j a va  2  s .c  om*/
        public boolean onMenuItemActionCollapse(final MenuItem menuItem)

        {
            MainActivity.this.mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
            MainActivity.this.mSearchResult.setVisibility(View.GONE);
            return true;
        }

        @Override
        public boolean onMenuItemActionExpand(final MenuItem menuItem) {
            MainActivity.this.mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
            MainActivity.this.mSearchResult.setVisibility(View.VISIBLE);
            return true;
        }

    });

}

From source file:com.saarang.samples.apps.iosched.ui.SearchActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);
    getMenuInflater().inflate(com.saarang.samples.apps.iosched.R.menu.search, menu);
    final MenuItem searchItem = menu.findItem(com.saarang.samples.apps.iosched.R.id.menu_search);
    if (searchItem != null) {
        SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
        final SearchView view = (SearchView) searchItem.getActionView();
        mSearchView = view;/*from w  ww  . j  ava2s  . c  o  m*/
        if (view == null) {
            LogUtils.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 ("zzznotif".equals(s)) {
                        (new ShowFeedbackNotificationAction()).run(SearchActivity.this, null);
                    }
                    return true;
                }

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

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

From source file:org.y20k.transistor.MainActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // inflate the menu items for use in the action bar
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.menu_main_actionbar, menu);

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

    return super.onCreateOptionsMenu(menu);
}

From source file:com.example.skode6.scanenvy.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);
    final SearchView searchView = (SearchView) MenuItemCompat.getActionView(menu.findItem(R.id.search));
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override/*w  ww  .j av a2 s . c om*/
        public boolean onQueryTextSubmit(String query) {
            return false;
        }

        @Override
        public boolean onQueryTextChange(String query) {
            //loadHistory(query);
            return false;
        }
    });
    if (searchView != null) {
        searchView.setIconifiedByDefault(true);
        searchView.setFocusable(true);
        searchView.setIconified(true);
        searchView.setOnSearchClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.showSoftInput(searchView, InputMethodManager.HIDE_IMPLICIT_ONLY);
                fabToolbar.hide();
            }
        });
        searchView.setFocusableInTouchMode(false);
        searchView.setOnClickListener(clickText());
        searchView.setOnFocusChangeListener(focusText());
    } else {
        Toast toast = Toast.makeText(getApplicationContext(), "Not Null", Toast.LENGTH_SHORT);
        toast.show();
    }
    InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.hideSoftInputFromWindow(searchView.getWindowToken(), 0);
    return super.onCreateOptionsMenu(menu);
}