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:io.github.hidroh.materialistic.BaseListActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    if (mIsMultiPane) {
        getMenuInflater().inflate(R.menu.menu_item, menu);
    }//  w  ww  . j  av a 2 s . c  om
    if (isSearchable()) {
        getMenuInflater().inflate(R.menu.menu_search, menu);
        MenuItem menuSearch = menu.findItem(R.id.menu_search);
        SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
        SearchView searchView = (SearchView) mActionViewResolver.getActionView(menuSearch);
        searchView.setSearchableInfo(
                searchManager.getSearchableInfo(new ComponentName(this, SearchActivity.class)));
        searchView.setIconified(true);
        searchView.setQuery("", false);
    }
    return super.onCreateOptionsMenu(menu);
}

From source file:edu.cmu.cylab.starslinger.view.PickRecipientsActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    setTheme(R.style.Theme_Safeslinger);
    super.onCreate(savedInstanceState);

    // inject view
    setContentView(R.layout.pickrecipients);

    final ActionBar bar = getSupportActionBar();
    bar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
    bar.setTitle(R.string.app_name);//from  w ww. jav a 2  s.co m
    bar.setSubtitle(R.string.title_PickRecipient);

    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

    mSearchEdt = (SearchView) findViewById(R.id.fragment_address_search);
    ((AutoCompleteTextView) mSearchEdt.findViewById(R.id.search_src_text))
            .setDropDownBackgroundResource(R.drawable.abc_search_dropdown_light);

    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    mSearchEdt.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    mSearchEdt.setOnQueryTextListener(new OnQueryTextListener() {

        @Override
        public boolean onQueryTextSubmit(String query) {
            // TODO Auto-generated method stub
            return false;
        }

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

    cbMostRecentOnly = (CheckBox) findViewById(R.id.ShowRecentCheckBox);
    listViewRecipients = (ListView) findViewById(R.id.RecipPickTableLayoutMembers);
    tvInstruct = (TextView) findViewById(R.id.tvInstruct);

    // always default to checked on view creation
    cbMostRecentOnly.setChecked(true);

    listViewRecipients.setOnScrollListener(new OnScrollListener() {

        @Override
        public void onScrollStateChanged(AbsListView view, int scrollState) {
            // nothing to do...
        }

        @Override
        public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
            // save list position
            if (visibleItemCount != 0) {
                mListVisiblePos = firstVisibleItem;
                View v = listViewRecipients.getChildAt(0);
                mListTopOffset = (v == null) ? 0 : v.getTop();
            }
        }
    });

    cbMostRecentOnly.setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            updateValues(null);
        }
    });

    updateValues(getIntent().getExtras());
}

From source file:com.vnapnic.streamgames.ui.TDActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.main, menu);
    refreshItem = menu.findItem(R.id.menu_refresh);
    searchItem = menu.findItem(R.id.menu_search);
    // Associate searchable configuration with the SearchView
    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    searchView.setOnQueryTextFocusChangeListener(this);
    return true;/*from   w w  w.j  a  v a 2 s. co  m*/
}

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

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void handleSearchForSdkAbove11() {

    MenuItem menuItem = menu.findItem(R.id.search);
    menuItem.setVisible(false);// w  w w. j a  v a2 s  .com

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

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

    search.setSearchableInfo(manager.getSearchableInfo(getComponentName()));

    search.setOnQueryTextListener(new OnQueryTextListener() {

        @Override
        public boolean onQueryTextChange(String query) {
            loadData(query);
            return true;
        }

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

    });

}

From source file:ufms.br.com.ufmsapp.fragment.NotasFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);
    getActivity().getMenuInflater().inflate(R.menu.notas_list_menu, menu);

    SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE);
    SearchView searchView = (SearchView) menu.findItem(R.id.search_nota).getActionView();
    searchView.setOnQueryTextListener(this);
    searchView.setQueryHint(getString(R.string.txt_busca));
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName()));
}

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;// ww  w  .  ja v 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:org.kontalk.ui.ConversationListFragment.java

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

    // compose message
    /*/*from w  w  w .jav  a 2 s .  c  o  m*/
    MenuItem item = menu.findItem(R.id.menu_compose);
    MenuItemCompat.setShowAsAction(item, MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
    */

    // search
    mSearchMenu = menu.findItem(R.id.menu_search);
    SearchView searchView = (SearchView) MenuItemCompat.getActionView(mSearchMenu);
    SearchManager searchManager = (SearchManager) getContext().getSystemService(Context.SEARCH_SERVICE);
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName()));
    // LayoutParams.MATCH_PARENT does not work, use a big value instead
    searchView.setMaxWidth(1000000);

    mDeleteAllMenu = menu.findItem(R.id.menu_delete_all);

    // offline mode
    mOfflineMenu = menu.findItem(R.id.menu_offline);

    // trigger manually
    onDatabaseChanged();
    updateOffline();
}

From source file:de.uni_koblenz_landau.apow.PatientListActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    mMenu = menu;/*from   w  ww.  ja  va 2 s .  co m*/
    getMenuInflater().inflate(R.menu.patient_list, menu);

    // Set up actionbar search.
    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    searchView = (SearchView) menu.findItem(R.id.patient_list_action_search).getActionView();
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    searchView.setOnQueryTextListener(new OnQueryTextListener() {

        @Override
        public boolean onQueryTextChange(String query) {
            if (!query.equals(mLastQuery)) {
                searchPatients(query, mReset);
            }
            mLastQuery = query;
            return true;
        }

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

    if (mSavedQuery.length() != 0) {
        mReset = false;
        MenuItem searchMenuItem = menu.findItem(R.id.patient_list_action_search);
        searchMenuItem.expandActionView();
        searchView.setQuery(mSavedQuery, false);
        searchView.clearFocus();
    }

    return super.onCreateOptionsMenu(menu);
}

From source file:com.zotfeed2.ListContentFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.menu_newu, menu);
    //        MenuItem item = menu.findItem(R.id.action_search);
    SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE);
    MenuItem searchItem = menu.findItem(R.id.action_search);
    SearchView sv = (SearchView) MenuItemCompat.getActionView(searchItem);

    if (sv != null) {
        sv.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName()));
        sv.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
            @Override/*w  ww . j ava2  s  .  com*/
            public boolean onQueryTextSubmit(String query) {
                System.out.print("QUERY:" + query);
                results = new ArrayList<Article>();
                if (!feeds.isEmpty() || feeds != null) {
                    for (Article article : feeds) {
                        //System.out.println("Title: " + article.getTitle());
                        if (article.getTitle().toLowerCase().contains(query.toLowerCase())) {
                            results.add(article);
                            System.out.println("Results: " + article.getTitle());
                        }
                    }
                    System.out.println("Size: " + results.size());
                    search = true;
                    recyclerView.setAdapter(new ContentAdapter(results));
                    recyclerView.setHasFixedSize(true);
                    recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
                    return true;
                } else {
                    return false;
                }
            }

            @Override
            public boolean onQueryTextChange(String newText) {
                if (newText.isEmpty() || newText.equals(" ")) {
                    if (feeds != null) {
                        recyclerView.setAdapter(new ContentAdapter(feeds));
                        recyclerView.setHasFixedSize(true);
                        recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
                    }
                }
                return false;
            }
        });
    }
    super.onCreateOptionsMenu(menu, inflater);

}

From source file:ru.besttuts.stockwidget.ui.SearchableQuoteActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {

    // Inflate the menu items for use in the action bar
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.search_activity_actions, menu);

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

    searchView.setOnQueryTextListener(new android.support.v7.widget.SearchView.OnQueryTextListener() {

        public boolean onQueryTextChange(String arg0) {
            LOGD(TAG, "onQueryTextChange: " + arg0);
            // TODO Auto-generated method stub
            return false;
        }/* www  .j a va  2s. c  o  m*/

        public boolean onQueryTextSubmit(String arg0) {
            LOGD(TAG, "onQueryTextSubmit: " + arg0);

            //                if (searchItem != null) {
            //                    searchItem.collapseActionView();
            //                }
            //                MenuItemCompat.collapseActionView(searchItem);
            return false;
        }

    });
    searchView.setOnCloseListener(new android.support.v7.widget.SearchView.OnCloseListener() {
        @Override
        public boolean onClose() {
            LOGD(TAG, "setOnCloseListener: onClose");

            return false;
        }
    });

    return super.onCreateOptionsMenu(menu);
}