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.kangsoo.pharmacy.fragment.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();
    //kskim to-do
    args.putSerializable(EXTRA_REPOSITORY, shoppingCategory);
    searchView.setAppSearchData(args);/* ww  w .j  ava  2s  .  c om*/
}

From source file:com.hybris.mobile.activity.StoreLocatorActivity.java

/**
 * Menu methods// w  w  w.j  a  va 2  s .com
 */
@Override
public boolean onCreateOptionsMenu(final Menu menu) {
    MenuInflater inflater = this.getMenuInflater();
    inflater.inflate(R.menu.store_finder, menu);

    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    MenuItem searchViewMenuItem = menu.findItem(R.id.store_search);
    this.mSearchView = searchViewMenuItem;
    SearchView searchView = ((SearchView) searchViewMenuItem.getActionView());

    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    searchView.setIconifiedByDefault(true);
    searchView.setQueryHint(getResources().getString(R.string.store_search_hint));
    searchView.setOnQueryTextListener(this);

    return true;
}

From source file:com.khmelenko.lab.travisclient.activity.MainActivity.java

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

    MenuItem searchItem = menu.findItem(R.id.action_search);
    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);

    mSearchView = null;/*from  w  w w . j av a2 s  . c om*/
    if (searchItem != null) {
        mSearchView = (SearchView) searchItem.getActionView();
    }
    if (mSearchView != null) {
        mSearchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
        mSearchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {

            @Override
            public boolean onQueryTextSubmit(String query) {
                boolean submitProhibited = true;
                if (query.length() > SEARCH_LIMIT) {
                    // save search query to history
                    SearchRecentSuggestions suggestionsProvider = new SearchRecentSuggestions(MainActivity.this,
                            SearchHistoryProvider.AUTHORITY, SearchHistoryProvider.MODE);
                    suggestionsProvider.saveRecentQuery(query, null);
                    submitProhibited = false;
                }
                return submitProhibited;
            }

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

        });
        mSearchView.setOnSuggestionListener(new SearchView.OnSuggestionListener() {
            @Override
            public boolean onSuggestionClick(int position) {
                mSearchView.setQuery(mQueryItems.get(position), true);
                return true;
            }

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

        reloadSearchHistoryAdapter("");

        // restore query if it was
        if (!TextUtils.isEmpty(mSavedQuery)) {
            mSearchView.setQuery(mSavedQuery, false);
            mSearchView.setIconified(false);
        }
    }
    return super.onCreateOptionsMenu(menu);
}

From source file:jm.org.data.area.IndicatorActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater menuInflater = getMenuInflater();
    menuInflater.inflate(R.menu.main, menu);
    //Log.d(TAG, "OnCreateOptionsMenu");
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        // only for android newer than gingerbread
        // TODO Implement a Search Dialog fall back for compatibility with
        // Android 2.3 and lower
        // Currently crashes on Gingerbread or lower

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

    }// w  w  w .ja  v a 2s  .  co m
    return super.onCreateOptionsMenu(menu);
}

From source file:inc.bait.jubilee.ui.fragments.ContactsListFragment.java

@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
@Override//from  ww w  . jav a2  s.  c  om
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.contact_list_menu, menu);
    MenuItem searchItem = menu.findItem(R.id.menu_search);
    if (isSearchResultView) {
        searchItem.setVisible(false);
    }
    if (ApiHelper.hasHoneycomb()) {
        final SearchManager searchManager = (SearchManager) getActivity()
                .getSystemService(Context.SEARCH_SERVICE);
        final SearchView searchView = (SearchView) searchItem.getActionView();
        searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName()));
        searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
            @Override
            public boolean onQueryTextSubmit(String queryText) {
                return true;
            }

            @Override
            public boolean onQueryTextChange(String newText) {
                String newFilter = !TextUtils.isEmpty(newText) ? newText : null;
                if (searchString == null && newFilter == null) {
                    return true;
                }
                if (searchString != null && searchString.equals(newFilter)) {
                    return true;
                }
                searchString = newFilter;
                mSearchQueryChanged = true;
                getLoaderManager().restartLoader(ContactsQuery.QUERY_ID, null, ContactsListFragment.this);
                return true;
            }
        });

        if (ApiHelper.hasICS()) {
            searchItem.setOnActionExpandListener(new MenuItem.OnActionExpandListener() {
                @Override
                public boolean onMenuItemActionExpand(MenuItem menuItem) {
                    return true;
                }

                @Override
                public boolean onMenuItemActionCollapse(MenuItem menuItem) {
                    if (!TextUtils.isEmpty(searchString)) {
                        onSelectionCleared();
                    }
                    searchString = null;
                    getLoaderManager().restartLoader(ContactsQuery.QUERY_ID, null, ContactsListFragment.this);
                    return true;
                }
            });
        }

        if (searchString != null) {
            final String savedSearchTerm = searchString;

            // Expands the search menu item
            if (ApiHelper.hasICS()) {
                searchItem.expandActionView();
            }
            searchView.setQuery(savedSearchTerm, false);
        }
    }
}

From source file:com.timemachine.controller.ControllerActivity.java

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

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

    // Change the text color in the search view
    int id = searchView.getContext().getResources().getIdentifier("android:id/search_src_text", null, null);
    searchTextView = (TextView) searchView.findViewById(id);
    searchTextView.setHintTextColor(Color.parseColor("#80ffffff"));
    searchTextView.setTextColor(Color.parseColor("#ffffff"));

    return super.onCreateOptionsMenu(menu);
}

From source file:com.github.pockethub.android.ui.MainActivity.java

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

    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    MenuItem searchItem = optionMenu.findItem(R.id.m_search);
    SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));

    return super.onCreateOptionsMenu(optionMenu);
}

From source file:com.stoneapp.ourvlemoodle2.fragments.CourseContentFragment.java

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

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        Context context = getActivity();
        SearchManager searchManager = (SearchManager) context.getSystemService(Context.SEARCH_SERVICE);

        searchitem = menu.findItem(R.id.action_search);
        searchView = (SearchView) MenuItemCompat.getActionView(searchitem); // set up search view

        searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName()));

        searchView.setOnQueryTextListener(this);
        searchView.setQueryHint("Search name"); // sets the hint text

        searchView.setOnCloseListener(new SearchView.OnCloseListener() {
            @Override/* w  w w .j  a  va  2 s . c  om*/
            public boolean onClose() {
                searchView.setQuery("", false); // clears text from search view
                return true;
            }
        });
    }
}

From source file:com.teocci.utubinbg.MainActivity.java

/**
 * Options menu in action bar//from   w w w  .  j av  a 2  s  .c  o  m
 *
 * @param menu
 * @return
 */
@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);

    MenuItem searchItem = menu.findItem(R.id.action_search);
    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);

    final SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
    if (searchView != null) {
        searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    }

    //suggestions
    final CursorAdapter suggestionAdapter = new SimpleCursorAdapter(this, R.layout.dropdown_menu, null,
            new String[] { SearchManager.SUGGEST_COLUMN_TEXT_1 }, new int[] { android.R.id.text1 }, 0);
    final List<String> suggestions = new ArrayList<>();

    searchView.setSuggestionsAdapter(suggestionAdapter);

    searchView.setOnSuggestionListener(new SearchView.OnSuggestionListener() {
        @Override
        public boolean onSuggestionSelect(int position) {
            return false;
        }

        @Override
        public boolean onSuggestionClick(int position) {
            searchView.setQuery(suggestions.get(position), false);
            searchView.clearFocus();

            Intent suggestionIntent = new Intent(Intent.ACTION_SEARCH);
            suggestionIntent.putExtra(SearchManager.QUERY, suggestions.get(position));
            handleIntent(suggestionIntent);

            return true;
        }
    });

    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String s) {
            return false; //if true, no new intent is started
        }

        @Override
        public boolean onQueryTextChange(String suggestion) {
            // check network connection. If not available, do not query.
            // this also disables onSuggestionClick triggering
            if (suggestion.length() > 2) { //make suggestions after 3rd letter

                if (networkConf.isNetworkAvailable()) {

                    new JsonAsyncTask(new JsonAsyncTask.AsyncResponse() {
                        @Override
                        public void processFinish(ArrayList<String> result) {
                            suggestions.clear();
                            suggestions.addAll(result);
                            String[] columns = { BaseColumns._ID, SearchManager.SUGGEST_COLUMN_TEXT_1 };
                            MatrixCursor cursor = new MatrixCursor(columns);

                            for (int i = 0; i < result.size(); i++) {
                                String[] tmp = { Integer.toString(i), result.get(i) };
                                cursor.addRow(tmp);
                            }
                            suggestionAdapter.swapCursor(cursor);

                        }
                    }).execute(suggestion);
                    return true;
                }
            }
            return false;
        }
    });

    return true;
}

From source file:com.foodie.app.Activity.MainActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.home_actions, menu);
    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    MenuItem searchMenuItem = menu.findItem(R.id.id_action_search);
    SearchView searchView = null;//  ww  w  .  java  2s  .c  om
    if (searchMenuItem != null) {
        searchView = (SearchView) searchMenuItem.getActionView();
    }
    if (searchView != null) {
        searchView.setSearchableInfo(searchManager.getSearchableInfo(MainActivity.this.getComponentName()));
    }
    SearchView.SearchAutoComplete searchAutoComplete = (SearchView.SearchAutoComplete) searchView
            .findViewById(android.support.v7.appcompat.R.id.search_src_text);
    searchAutoComplete.setHintTextColor(Color.WHITE);
    searchAutoComplete.setTextColor(Color.WHITE);
    searchAutoComplete.setHint("?,,");
    //?
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            //Toast.makeText(MainActivity.this,""+query,Toast.LENGTH_SHORT).show();
            Intent intent = new Intent(MainActivity.this, SearchResultsActivity.class);
            intent.putExtra("query", query);
            startActivity(intent);
            return true;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            //Toast.makeText(MainActivity.this,""+newText,Toast.LENGTH_SHORT).show();
            return false;
        }
    });
    //??
    View searchplate = (View) searchView.findViewById(android.support.v7.appcompat.R.id.search_plate);
    //searchplate.setBackgroundResource(R.drawable.ic_search_white_24dp);

    ImageView searchCloseIcon = (ImageView) searchView
            .findViewById(android.support.v7.appcompat.R.id.search_close_btn);
    searchCloseIcon.setImageResource(R.drawable.ic_close_white_24dp);

    ImageView voiceIcon = (ImageView) searchView
            .findViewById(android.support.v7.appcompat.R.id.search_voice_btn);
    voiceIcon.setImageResource(R.drawable.ic_settings_voice_white_24dp);

    //searchView.setSubmitButtonEnabled(true); // to enable submit button

    ImageView b = (ImageView) searchView.findViewById(android.support.v7.appcompat.R.id.search_button);
    b.setImageResource(R.drawable.ic_search_white_24dp); //to change submit button icon

    ImageView searchIcon = (ImageView) searchView
            .findViewById(android.support.v7.appcompat.R.id.search_mag_icon);
    searchIcon.setImageResource(R.drawable.ic_search_white_24dp);

    switch (currentTab) {
    case 0:
        MenuItem miMap = menu.findItem(R.id.id_action_map);
        miMap.setVisible(false);
        break;
    case 1:
        MenuItem miSearch = menu.findItem(R.id.id_action_search);
        miSearch.setVisible(false);
        break;
    case 2:
        MenuItem mi1 = menu.findItem(R.id.id_action_map);
        mi1.setVisible(false);
        MenuItem mi2 = menu.findItem(R.id.id_action_search);
        mi2.setVisible(false);
    case 3:
        MenuItem mi3 = menu.findItem(R.id.id_action_map);
        mi3.setVisible(false);
        MenuItem mi4 = menu.findItem(R.id.id_action_search);
        mi4.setVisible(false);
        break;
    default:
        break;
    }

    return true;
}