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:moose.com.ac.MainActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    /**see http://stackoverflow.com/questions/27556623/creating-a-searchview-that-looks-like-the-material-design-guidelines*/
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.menu_main, menu);
    searchView = (SearchView) MenuItemCompat.getActionView(menu.findItem(R.id.action_search));
    SearchManager searchManager = (SearchManager) getSystemService(SEARCH_SERVICE);
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    searchView.setOnSearchClickListener(view -> searchShow = true);
    searchView.setOnCloseListener(() -> {
        searchShow = false;//from  ww w .  j  a  v a  2 s.  c om
        return false;
    });
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            if (!CommonUtil.isEmpty(query)) {
                Intent intent = new Intent(MainActivity.this, SearchActivity.class);
                intent.putExtra(Config.SEARCH_KEY, query);
                startActivity(intent);
                searchView.onActionViewCollapsed();
                searchShow = false;
            }
            return false;
        }

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

From source file:com.jbirdvegas.mgerrit.GerritControllerActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    mTheme = Prefs.getCurrentThemeID(this);
    setTheme(mTheme);/*from w  w w  .  j ava2s  .c om*/

    super.onCreate(savedInstanceState);

    // check if caller has a gerrit instance start screen preference
    String suppliedGerritInstance = getIntent().getStringExtra(GERRIT_INSTANCE);
    if (suppliedGerritInstance != null && !suppliedGerritInstance.isEmpty()
            && suppliedGerritInstance.contains("http")) {
        // just set the prefs and allow normal loading
        Prefs.setCurrentGerrit(this, suppliedGerritInstance);
    }

    GoogleAnalytics googleAnalytics = GoogleAnalytics.getInstance(this);

    String trackingId = getString(R.string.ga_trackingId);
    Tracker tracker = googleAnalytics.getTracker(trackingId);
    googleAnalytics.getLogger().setLogLevel(Logger.LogLevel.VERBOSE);
    tracker.send(MapBuilder.createAppView().build());

    // keep a log of what ROM our users run
    AnalyticsHelper.sendAnalyticsEvent(this, AnalyticsHelper.GA_APP_OPEN, AnalyticsHelper.GA_ROM_VERSION,
            ROMHelper.determineRom(this), null);

    // Keep track of what theme is being used
    AnalyticsHelper.sendAnalyticsEvent(this, AnalyticsHelper.GA_APP_OPEN, AnalyticsHelper.GA_THEME_SET_ON_OPEN,
            Prefs.getCurrentTheme(this), null);

    setContentView(R.layout.main);

    FragmentManager fm = getSupportFragmentManager();
    if (findViewById(R.id.change_detail_fragment) != null) {
        // The detail container view will be present only in
        // large-screen layouts(res/values-sw600dp). If this view is present,
        // then the activity should be in two-pane mode.
        mTwoPane = true;
        mChangeDetail = (PatchSetViewerFragment) fm.findFragmentById(R.id.change_detail_fragment);
    }
    Prefs.setTabletMode(this, mTwoPane);

    mChangeList = (ChangeListFragment) fm.findFragmentById(R.id.change_list_fragment);

    mGerritWebsite = Prefs.getCurrentGerrit(this);

    // Get the SearchView and set the searchable configuration
    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    mSearchView = (GerritSearchView) findViewById(R.id.search);
    mSearchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
}

From source file:com.whatsoft.contactbook.activity.MainActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.search_menu, menu);
    // Get the SearchView and set the searchable configuration
    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    searchView = (SearchView) menu.findItem(R.id.action_search).getActionView();
    // 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 SearchView.OnQueryTextListener() {
        @Override//from w  ww  .  ja  va  2s .c  om
        public boolean onQueryTextSubmit(String query) {
            Utils.hideSoftKeyboard(MainActivity.this);
            Fragment fragment = adapter.getItem(viewPager.getCurrentItem());
            if (fragment instanceof ContactsListFragment) {
                ((ContactsListFragment) fragment).doSearch(query);
            }
            return true;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            //search with keyword length >= 3
            //                if (!TextUtils.isEmpty(newText) && newText.trim().length() < 3) {
            //                    return false;
            //                }
            Fragment fragment = adapter.getItem(viewPager.getCurrentItem());
            if (fragment instanceof ContactsListFragment) {
                ((ContactsListFragment) fragment).doSearch(newText);
            }
            return true;
        }
    });
    return true;
}

From source file:com.conferenceengineer.android.iosched.ui.tablet.SessionsSandboxMultiPaneActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);
    getMenuInflater().inflate(R.menu.search, menu);
    MenuItem searchItem = menu.findItem(R.id.menu_search);
    if (searchItem != null && UIUtils.hasHoneycomb()) {
        SearchView searchView = (SearchView) searchItem.getActionView();
        if (searchView != null) {
            SearchManager searchManager = (SearchManager) getSystemService(SEARCH_SERVICE);
            searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
            searchView.setQueryRefinementEnabled(true);
        }//from w  w w  . j  a  v  a 2  s .c o  m
    }
    return true;
}

From source file:fr.bde_eseo.eseomega.plans.PlansActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.menu_search, menu);
    // Retrieve the SearchView and plug it into SearchManager
    final SearchView searchView = (SearchView) MenuItemCompat.getActionView(menu.findItem(R.id.action_search));
    SearchManager searchManager = (SearchManager) getSystemService(SEARCH_SERVICE);
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override//from w  w  w  . j  av  a2s. c  om
        public boolean onQueryTextSubmit(String query) {
            return false;
        }

        @Override
        public boolean onQueryTextChange(String newText) {

            if (newText.length() > 0) {
                searchInArray(newText);
                addHeaders();
            } else {
                fillItems();
                addHeaders();
            }
            mAdapter.notifyDataSetChanged();
            if (roomItemsDisplay.size() > 0)
                recList.scrollToPosition(0);
            return true;
        }
    });
    return true;
}

From source file:at.flack.activity.NewSMSContactActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.new_contact, menu);
    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    MenuItem searchMenuItem = menu.findItem(R.id.search);
    SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchMenuItem);

    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    searchView.setSubmitButtonEnabled(true);
    searchView.setOnQueryTextListener(this);
    return true;/*from  w  w  w .  j  a  va  2  s.  c om*/
}

From source file:com.loserskater.suhidegui.PackageActivity.java

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

    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    SearchView searchView = (SearchView) menu.findItem(R.id.action_search).getActionView();
    searchView.setOnQueryTextListener(this);
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    return true;// w  ww .  j a v  a  2  s .  co  m
}

From source file:cl.mmoscoso.geocomm.GeoCommMainActivity.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.map_view_main, menu);
    //SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
    //menu.findItem(R.id.action_search).getActionView();
    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    searchView = (SearchView) menu.findItem(R.id.action_search).getActionView();
    // Assumes current activity is the searchable activity
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    searchView.setIconifiedByDefault(false);
    searchView.setOnQueryTextListener(this);
    return true;/* www .  j a v  a  2  s .  c  o m*/
}

From source file:alaindc.memenguage.View.MainActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {

    getMenuInflater().inflate(R.menu.main, menu);
    // Retrieve the SearchView and plug it into SearchManager
    final SearchView searchView = (SearchView) MenuItemCompat.getActionView(menu.findItem(R.id.action_search));
    SearchManager searchManager = (SearchManager) getSystemService(SEARCH_SERVICE);
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override//from  ww w  .  jav  a  2 s.co  m
        public boolean onQueryTextSubmit(String query) {
            Log.d("MainActivity Search", query.toString());

            return false;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            Log.d("MainActivity Search", newText.toString());
            adapter.getFilter().filter(newText);
            adapter.notifyDataSetChanged();
            return false;
        }
    });
    return true;
}

From source file:im.vector.activity.CountryPickerActivity.java

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

    final MenuItem searchItem = menu.findItem(R.id.action_search);
    if (searchItem != null) {
        SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
        mSearchView = (SearchView) MenuItemCompat.getActionView(searchItem);
        mSearchView.setSubmitButtonEnabled(false);
        mSearchView.setQueryHint(getString(R.string.search_hint));
        mSearchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
        mSearchView.setOnQueryTextListener(this);
    }/*from w ww  .ja  v a 2  s  .c  o m*/
    return true;
}