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.andrew.apollo.ui.activities.BaseActivity.java

/**
 * {@inheritDoc}/*  w  w  w. ja v  a2  s .c o  m*/
 */
@Override
public boolean onCreateOptionsMenu(final Menu menu) {
    // Search view
    getMenuInflater().inflate(R.menu.search, menu);
    // Settings
    getMenuInflater().inflate(R.menu.activity_base, menu);
    // Theme the search icon
    mResources.setSearchIcon(menu);

    final SearchView searchView = (SearchView) menu.findItem(R.id.menu_search).getActionView();
    // Add voice search
    final SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    final SearchableInfo searchableInfo = searchManager.getSearchableInfo(getComponentName());
    searchView.setSearchableInfo(searchableInfo);
    // Perform the search
    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:ch.citux.td.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 = (SearchView) MenuItemCompat.getActionView(searchItem);
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    searchView.setOnQueryTextFocusChangeListener(this);

    return true;//ww  w  . jav a2s .co m
}

From source file:httbdd.cse.nghiatran.halofind.screen.MainActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.sample_actions, menu);
    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    SearchView searchView = (SearchView) MenuItemCompat.getActionView(menu.findItem(R.id.search));
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    searchView.setSubmitButtonEnabled(true);
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override//from www . j a  v a2  s .  co m
        public boolean onQueryTextSubmit(String query) {
            handleSearch(query);
            return true;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            if (TextUtils.isEmpty(newText)) {
            } else {
            }
            return true;
        }
    });
    return true;
}

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:info.guardianproject.otr.app.im.app.ContactsPickerActivity.java

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

    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    mSearchView = (SearchView) MenuItemCompat.getActionView(menu.findItem(R.id.menu_search));

    if (mSearchView != null) {
        mSearchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
        mSearchView.setIconifiedByDefault(false);

        SearchView.OnQueryTextListener queryTextListener = new SearchView.OnQueryTextListener() {
            public boolean onQueryTextChange(String newText) {
                mSearchString = newText;
                doFilterAsync(mSearchString);
                return true;
            }//from w  w  w. j  a va  2s.  c  o m

            public boolean onQueryTextSubmit(String query) {
                mSearchString = query;
                doFilterAsync(mSearchString);

                return true;
            }
        };

        mSearchView.setOnQueryTextListener(queryTextListener);
    }

    return true;
}

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

    }/*from   w w  w  . j a  v a  2s  . c o  m*/
    return super.onCreateOptionsMenu(menu);
}

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

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Override/*from  w w w . ja v  a 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:uk.ac.horizon.artcodes.activity.NavigationActivity.java

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

    final MenuItem searchItem = menu.findItem(R.id.search);
    final SearchView searchView = (SearchView) searchItem.getActionView();
    final SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        private Runnable delayedAction = null;

        @Override/*from  w ww  . jav  a  2 s. c  om*/
        public boolean onQueryTextSubmit(String query) {
            search(query);
            return true;
        }

        @Override
        public boolean onQueryTextChange(final String newText) {
            if (delayedAction != null) {
                searchHandler.removeCallbacks(delayedAction);
                delayedAction = null;
            }

            if (newText.trim().length() > 3) {
                delayedAction = new Runnable() {
                    @Override
                    public void run() {
                        search(newText);
                    }
                };

                searchHandler.postDelayed(delayedAction, 1000);
            }
            return true;
        }
    });
    MenuItemCompat.setOnActionExpandListener(searchItem, new MenuItemCompat.OnActionExpandListener() {
        @Override
        public boolean onMenuItemActionExpand(final MenuItem item) {
            return true;
        }

        @Override
        public boolean onMenuItemActionCollapse(final MenuItem item) {
            Log.i("a", "Closed");
            Fragment fragment = getSupportFragmentManager().findFragmentByTag(FRAGMENT_TAG);
            if (fragment instanceof ExperienceSearchFragment) {
                getSupportFragmentManager().popBackStack();
            }
            return true;
        }
    });

    return true;

}

From source file:com.morlunk.mumbleclient.channel.ChannelListFragment.java

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

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

    final SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName()));
    searchView.setOnSuggestionListener(new SearchView.OnSuggestionListener() {
        @Override//from   www.ja v  a 2 s.  c  o m
        public boolean onSuggestionSelect(int i) {
            return false;
        }

        @Override
        public boolean onSuggestionClick(int i) {
            CursorWrapper cursor = (CursorWrapper) searchView.getSuggestionsAdapter().getItem(i);
            int typeColumn = cursor.getColumnIndex(SearchManager.SUGGEST_COLUMN_INTENT_EXTRA_DATA);
            int dataIdColumn = cursor.getColumnIndex(SearchManager.SUGGEST_COLUMN_INTENT_DATA);
            String itemType = cursor.getString(typeColumn);
            int itemId = cursor.getInt(dataIdColumn);
            if (ChannelSearchProvider.INTENT_DATA_CHANNEL.equals(itemType)) {
                if (getService().getSessionChannel().getId() != itemId) {
                    getService().joinChannel(itemId);
                } else {
                    scrollToChannel(itemId);
                }
                return true;
            } else if (ChannelSearchProvider.INTENT_DATA_USER.equals(itemType)) {
                scrollToUser(itemId);
                return true;
            }
            return false;
        }
    });
}

From source file:be.brunoparmentier.openbikesharing.app.activities.StationsListActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    this.optionsMenu = menu;
    getMenuInflater().inflate(R.menu.stations_list, menu);

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

    searchView = (SearchView) menu.findItem(R.id.action_search).getActionView();
    searchView.setSearchableInfo(manager.getSearchableInfo(getComponentName()));
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {

        @Override/*from  w w  w. j a va  2s  . com*/
        public boolean onQueryTextSubmit(String s) {
            return false;
        }

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

    return true;
}