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:net.seedboxer.seedroid.activities.fragments.DownloadsFragment.java

/**
 * Get the SearchView and set the searchable configuration
 * @param menu//from  w w w .j a v  a2 s . co m
 */
private void createFilteredMenu(Menu menu) {
    SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE);
    SearchView searchView = (SearchView) menu.findItem(R.id.menu_search).getActionView();
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName()));
    searchView.setIconifiedByDefault(false); // Do not iconify the widget; expand it by default
    searchView.setOnQueryTextListener(new OnQueryTextListener() {

        public boolean onQueryTextSubmit(String query) {
            adapter.getFilter().filter(query);
            return true;
        }

        public boolean onQueryTextChange(String newText) {
            adapter.getFilter().filter(newText);
            return true;
        }
    });
}

From source file:com.numenta.taurus.instance.InstanceListActivity.java

private void configureSearchView(@NonNull final SearchView searchView) {
    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    // Assumes current activity is the searchable activity
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));

    // Handle query events
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override/*  ww w  .  j a  va  2  s  .  com*/
        public boolean onQueryTextSubmit(String query) {
            // Hide Keyboard on submit
            InputMethodManager imm = (InputMethodManager) searchView.getContext()
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            if (imm != null) {
                imm.hideSoftInputFromWindow(searchView.getWindowToken(), 0);
            }

            return true;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            // Filter list as the user types
            _listFragment.applyFilter(newText);
            return true;
        }
    });

    // FIXME: Android does not support styling the search view across all versions.
    // For now, "peek" into internal API to make the appropriate changes to the SearchView.
    // In the future we should use the official android API to customize the SearchView widget.
    // See android.R.layout.search_view for the layout we are "peeking". It is no guarantee it
    // will work on all public android versions and/or OEM customizations.
    // This HACK is only valid for the POC phase. We should find a better solution before releasing
    Resources resources = searchView.getResources();

    // Style search box and text
    int searchPlateId = resources.getIdentifier("android:id/search_plate", null, null);
    View searchPlate = searchView.findViewById(searchPlateId);
    if (searchPlate != null) {
        int searchTextId = resources.getIdentifier("android:id/search_src_text", null, null);
        TextView searchText = (TextView) searchPlate.findViewById(searchTextId);
        if (searchText != null) {
            searchPlate.setBackgroundResource(android.R.drawable.editbox_background);
            searchText.setPadding(5, 0, 0, 0);
            searchText.setTextColor(Color.BLACK);
            searchText.setHintTextColor(Color.LTGRAY);
        }
    }
}

From source file:fr.kwiatkowski.apktrack.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);

    // Change the "Show system apps" text depending on the currently selected option.
    SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this);
    boolean show_system = pref.getBoolean(SettingsFragment.KEY_PREF_SHOW_SYSTEM, false);
    if (show_system) {
        menu.findItem(R.id.show_system).setTitle(R.string.hide_system_apps);
    }/*from  w ww. j  a  v  a 2 s.co  m*/
    // Disable it if all system apps are ignored.
    if (!InstalledApp.check_system_apps_tracked()) {
        menu.findItem(R.id.show_system).setEnabled(false);
    }

    // Change the change sort type text depending on the currently selected option.
    String sort_type = pref.getString(SettingsFragment.KEY_PREF_SORT_TYPE, SettingsFragment.ALPHA_SORT);
    if (sort_type.equals(SettingsFragment.ALPHA_SORT)) {
        menu.findItem(R.id.sort_type).setTitle(R.string.sort_type_updated);
    }

    SearchManager seaman = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    SearchView sv = (SearchView) MenuItemCompat.getActionView(menu.findItem(R.id.search));
    sv.setSearchableInfo(seaman.getSearchableInfo(getComponentName()));
    sv.addOnAttachStateChangeListener(new View.OnAttachStateChangeListener() {
        @Override
        public void onViewAttachedToWindow(View view) {
        }

        @Override
        public void onViewDetachedFromWindow(View view) {
            _app_display.restore_apps(); // Unfilter the list when the search bar is closed.
        }
    });

    return true;
}

From source file:br.com.moviecreator.views.home.HomeFragment.java

private void initSearch(MenuItem item) {
    SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE);

    SearchView searchView = (SearchView) MenuItemCompat.getActionView(item);
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName()));

    if (criteria != null) {
        searchView.setIconified(false);/*from   www .jav a  2  s.c om*/
    }

    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {

        @Override
        public boolean onQueryTextSubmit(String query) {
            if (!query.equals(criteria) && query.length() > 2) {
                adapter.clear();
                searchMovie(query);
                criteria = query;
            }

            return false;
        }

        @Override
        public boolean onQueryTextChange(final String query) {
            if (query.equals(criteria) || query.length() < 3) {
                return true;
            }
            return false;
        }
    });
    searchView.setOnCloseListener(new SearchView.OnCloseListener() {

        @Override
        public boolean onClose() {
            /*adapter.clear();
                    
            fetch(null, null);*/

            return false;
        }
    });
}

From source file:algolia.com.demo.moviesearch.ui.MovieSearchActivity.java

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

    // Configure search view.
    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    searchView = (SearchView) MenuItemCompat.getActionView(menu.findItem(R.id.search));
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    searchView.setIconifiedByDefault(false);
    searchView.setOnQueryTextListener(this);

    return true;//from  ww w.  ja v  a 2s  .co m
}

From source file:com.ronnyml.sweetplayer.ui.MainActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.menu_main, menu);
    MenuItem searchItem = menu.findItem(R.id.action_search);
    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));

    return true;//from  w w  w  .  jav a2s  . c o  m
}

From source file:no.group09.ucsoftwarestore.MainActivity.java

/**
 * Creates options menu//from  w  w w  . j  ava  2s  .  co  m
 */
@SuppressLint("NewApi")
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.main_menu, menu);

    //When the menu is created, check the preferences and set the correct text
    if (sharedPref.getBoolean("hide_incompatible", false)) {
        menu.getItem(1).setTitle("Hide incompatible");
        menu.getItem(1).setChecked(true);

    } else {
        menu.getItem(1).setTitle("Hide incompatible");
        menu.getItem(1).setChecked(false);
    }

    //Search bar for versions over API level 11
    int SDK_INT = android.os.Build.VERSION.SDK_INT;

    if (SDK_INT >= 11) {
        SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
        SearchView searchView = (SearchView) menu.findItem(R.id.menu_search).getActionView();

        searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
        searchView.setSubmitButtonEnabled(true);
    }
    return true;
}

From source file:com.hartcode.hartweather.list.WeatherListActivity.java

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

    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    this.searchMenuItem = menu.findItem(R.id.action_add);
    this.searchView = (SearchView) searchMenuItem.getActionView();
    this.searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    this.searchView.setIconifiedByDefault(true);
    MenuItemCompat.setOnActionExpandListener(this.searchMenuItem, this);
    if (this.isSearchShown) {
        this.searchMenuItem.expandActionView();
    }/*w ww .  j a  v  a2s .  com*/
    if (this.searchText != null && this.searchText.length() > 0) {
        this.searchView.setQuery(searchText, false);
    }
    return true;
}

From source file:fi.villel.foosquare.SearchActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_search);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);/*from  w  ww . j a  v  a 2  s  . c o m*/
    toolbar.setLogo(R.drawable.ic_launcher);
    toolbar.setLogoDescription(R.string.app_name);
    toolbar.setTitle("");

    // Get the RecentQueryView and set the searchable configuration
    SearchManager searchManager = (SearchManager) getSystemService(SEARCH_SERVICE);
    SearchView searchView = (SearchView) findViewById(R.id.search);
    // Assumes current activity is the searchable activity
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));

    if (savedInstanceState == null) {
        Fragment fragment = new ResultFragment();
        getSupportFragmentManager().beginTransaction().add(R.id.result_container, fragment).commit();
    }

    // TODO: Receive location updates
    mLocationManager = (LocationManager) getSystemService(LOCATION_SERVICE);

    mPresenter.onSearchViewCreate(this);
    handleIntent(getIntent());
}

From source file:uk.org.crimetalk.SearchActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {

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

    // Modify some aspects of the SearchView
    final SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    final MenuItem searchItem = menu.findItem(R.id.action_search);
    final SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    searchView.setQuery(mQuery, false);//  w ww.j  a v a2 s  .  c o  m
    searchView.setIconified(false);
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {

        @Override
        public boolean onQueryTextSubmit(String s) {

            return false;

        }

        @Override
        public boolean onQueryTextChange(String query) {

            SearchActivity.this.mQuery = query;

            return false;

        }

    });

    final SearchView.SearchAutoComplete searchAutoComplete = (SearchView.SearchAutoComplete) searchView
            .findViewById(R.id.search_src_text);
    searchAutoComplete.setTextColor(getResources().getColor(R.color.white));

    // Recovering from orientation change, try not to have focus
    if (mQuery != null && !mQuery.isEmpty()) {

        searchView.clearFocus();

    }

    return true;

}