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: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);//from w  w w . j  a  va 2 s. co m
}

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 a v  a 2  s .  c o m
        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);
}

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);/*from ww w .jav a  2  s .c  om*/
}

From source file:org.bwgz.quotation.activity.HomeActivity.java

@Override
public boolean onCreateOptionsMenu(final Menu menu) {
    Log.d(TAG, String.format("onCreateOptionsMenu - menu: %s", menu));

    getMenuInflater().inflate(R.menu.options_menu, menu);

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

    final ListView drawerView = (ListView) findViewById(R.id.drawer);
    DrawerAdapter adapter = new DrawerAdapter(getResources().getStringArray(R.array.home_drawer), 0);
    drawerView.setAdapter(adapter);// ww  w . j  a v a  2 s  . c o m
    drawerView.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Log.d(TAG, String.format("drawer - onItemClick - parent: %s  view: %s  position: %d  id: %d",
                    parent, view, position, id));

            drawerLayout.closeDrawer(drawerView);

            if (id == 1) {
                Intent intent = new Intent(parent.getContext(), QuotationsActivity.class);
                intent.putExtra(CategoryActivity.EXTRA_ITEM, QuotationsActivity.QUOTATIONS_ITEM_BOOKMARKS);
                startActivity(intent);
            }
        }
    });

    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);/* w  w  w .j  a  va2 s . co m*/
}

From source file:org.apache.taverna.mobile.ui.favouriteworkflow.FavouriteWorkflowsFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);
    SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE);
    searchView = (SearchView) menu.findItem(R.id.action_search).getActionView();

    searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName()));
    searchView.setSubmitButtonEnabled(false);
    searchView.setOnQueryTextListener(this);
    searchView.setOnCloseListener(this);
}

From source file:com.akhbulatov.wordkeeper.ui.fragment.WordListFragment.java

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

    MenuItem searchItem = menu.findItem(R.id.menu_search_word);
    SearchView searchView = (SearchView) searchItem.getActionView();

    SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE);
    searchView.setSearchableInfo(/*from   w  w  w .  ja  v a2  s  .co m*/
            searchManager.getSearchableInfo(new ComponentName(getActivity(), MainActivity.class)));
    searchView.setImeOptions(EditorInfo.IME_ACTION_SEARCH);
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            return false;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            final Cursor cursor = mWordDbAdapter.getAll(sSortMode);
            final int column = cursor.getColumnIndex(WordEntry.COLUMN_NAME);
            if (newText.length() > 0) {
                mWordAdapter.swapCursor(new FilterCursorWrapper(cursor, newText, column));

                mTextEmptyWordList.setVisibility(View.GONE);
                if (mWordAdapter.getItemCount() == 0) {
                    String escapedNewText = TextUtils.htmlEncode(newText);
                    String formattedNoResults = String.format(getString(R.string.no_results_word),
                            escapedNewText);
                    CharSequence styledNoResults = Html.fromHtml(formattedNoResults);

                    mTextNoResultsWord.setText(styledNoResults);
                    mTextNoResultsWord.setVisibility(View.VISIBLE);
                } else {
                    mTextNoResultsWord.setVisibility(View.GONE);
                }
            } else {
                mWordAdapter.swapCursor(cursor);

                mTextNoResultsWord.setVisibility(View.GONE);
                if (mWordAdapter.getItemCount() == 0) {
                    mTextEmptyWordList.setVisibility(View.VISIBLE);
                }
            }
            return true;
        }
    });
}

From source file:com.ksharkapps.musicnow.ui.activities.BaseActivity.java

/**
 * {@inheritDoc}/*www .j  a va2 s .c  om*/
 */
@Override
public boolean onCreateOptionsMenu(final Menu menu) {
    // Search view
    getMenuInflater().inflate(R.menu.search, menu);
    // Settings
    getMenuInflater().inflate(R.menu.activity_base, menu);

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

    final SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
    // Add voice search
    final SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    final SearchableInfo searchableInfo = searchManager.getSearchableInfo(getComponentName());
    searchView.setSearchableInfo(searchableInfo);
    // Perform the search
    if (searchView != null)
        searchView.setOnQueryTextListener(new OnQueryTextListener() {

            @Override
            public boolean onQueryTextSubmit(final String query) {
                // Open the search activity
                NavUtils.openSearch(BaseActivity.this, query);
                return true;
            }

            @Override
            public boolean onQueryTextChange(final String newText) {
                // Nothing to do
                return false;
            }
        });
    return super.onCreateOptionsMenu(menu);
}

From source file:com.akhbulatov.wordkeeper.ui.fragment.CategoryListFragment.java

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

    MenuItem searchItem = menu.findItem(R.id.menu_search_category);
    SearchView searchView = (SearchView) searchItem.getActionView();

    SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE);
    searchView.setSearchableInfo(/*from  w ww .  jav a 2 s .  c  om*/
            searchManager.getSearchableInfo(new ComponentName(getActivity(), MainActivity.class)));
    searchView.setImeOptions(EditorInfo.IME_ACTION_SEARCH);
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextChange(String newText) {
            final Cursor cursor = mCategoryDbAdapter.getAll();
            final int column = cursor.getColumnIndex(CategoryEntry.COLUMN_NAME);
            if (newText.length() > 0) {
                mCategoryAdapter.swapCursor(new FilterCursorWrapper(cursor, newText, column));

                if (mCategoryAdapter.getItemCount() == 0) {
                    String escapedNewText = TextUtils.htmlEncode(newText);
                    String formattedNoResults = String.format(getString(R.string.no_results_category),
                            escapedNewText);
                    CharSequence styledNoResults = Html.fromHtml(formattedNoResults);

                    mTextNoResultsCategory.setText(styledNoResults);
                    mTextNoResultsCategory.setVisibility(View.VISIBLE);
                } else {
                    mTextNoResultsCategory.setVisibility(View.GONE);
                }
            } else {
                mCategoryAdapter.swapCursor(cursor);
                mTextNoResultsCategory.setVisibility(View.GONE);
            }
            return true;
        }

        @Override
        public boolean onQueryTextSubmit(String query) {
            return false;
        }
    });
}

From source file:net.mypapit.mobile.callsignview.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) menu.findItem(R.id.search).getActionView();
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));

    if (!mSearchHandle) {
        searchView.setQueryHint("Search Callsign");
    } else {/*from w w w  . j av  a 2  s  . c o  m*/
        searchView.setQueryHint("Search Handle/Name");
    }
    searchView.setOnQueryTextListener(this);

    return true;
}