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.tt.jobtracker.MainActivity.java

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

    // Associate searchable configuration with the SearchView
    SearchManager searchManager = (SearchManager) getSystemService(this.SEARCH_SERVICE);
    SearchView searchView = (SearchView) menu.findItem(R.id.action_search).getActionView();
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));

    /* ImageView tickImg=(ImageView) menu.findItem(R.id.action_task_done);
     if(Shared.SelectedTask!=null)/*from w w  w  .  ja v a2  s .c om*/
     {
    int value = dbHelper.PhotoUploadCount(Shared.SelectedTask.ID);
    if(value==0)
    {
        tickImg.setImageResource(R.drawable.done);
        tickImg.setFocusable(true);
        tickImg.setFocusableInTouchMode(true);
            
    }
    else
    {
        tickImg.setFocusable(false);
        tickImg.setFocusableInTouchMode(false);
        tickImg.setImageResource(R.drawable.ic_launcher);
    }
     }*/

    SetActionBarMenuItems();
    return super.onCreateOptionsMenu(menu);
}

From source file:de.tap.easy_xkcd.Activities.MainActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.menu_main, menu);
    // Get the SearchView and set the searchable configuration
    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    final SearchView searchView = (SearchView) menu.findItem(R.id.action_search).getActionView();
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    searchView.setIconifiedByDefault(false);
    searchMenuItem = menu.findItem(R.id.action_search);

    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override//from  www  .j  av a  2 s  .c o  m
        public boolean onQueryTextSubmit(String query) {
            MenuItem searchMenuItem = getSearchMenuItem();
            searchMenuItem.collapseActionView();
            searchView.setQuery("", false);
            //Hide Keyboard
            View view = MainActivity.this.getCurrentFocus();
            if (view != null) {
                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
            }
            return false;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            return false;
        }
    });
    MenuItemCompat.setOnActionExpandListener(searchMenuItem, new MenuItemCompat.OnActionExpandListener() {
        @Override
        public boolean onMenuItemActionExpand(MenuItem item) {
            View view = getCurrentFocus();
            if (view != null) {
                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.showSoftInput(view, 0);
            }
            searchView.requestFocus();
            return true;
        }

        @Override
        public boolean onMenuItemActionCollapse(MenuItem item) {
            View view = getCurrentFocus();
            if (view != null) {
                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
            }
            return true;
        }
    });
    if (prefHelper.hideDonate())
        menu.findItem(R.id.action_donate).setVisible(false);
    return true;
}

From source file:org.gnucash.android.ui.account.AccountsListFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    if (mParentAccountId > 0)
        inflater.inflate(R.menu.sub_account_actions, menu);
    else {/*  w w  w.ja v a  2  s  . co  m*/
        inflater.inflate(R.menu.account_actions, menu);
        // Associate searchable configuration with the SearchView
        SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE);
        mSearchView = (com.actionbarsherlock.widget.SearchView) menu.findItem(R.id.menu_search).getActionView();
        if (mSearchView == null)
            return;

        mSearchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName()));
        mSearchView.setOnQueryTextListener(this);
        mSearchView.setOnCloseListener(this);
    }
}

From source file:com.boko.vimusic.ui.activities.AudioPlayerActivity.java

/**
 * {@inheritDoc}/*w  ww.java 2s .  c om*/
 */
@Override
public boolean onCreateOptionsMenu(final Menu menu) {
    // Search view
    getMenuInflater().inflate(R.menu.search, 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(AudioPlayerActivity.this, query);
            return true;
        }

        @Override
        public boolean onQueryTextChange(final String newText) {
            // Nothing to do
            return false;
        }
    });

    // Favorite action
    getMenuInflater().inflate(R.menu.favorite, menu);
    // Shuffle all
    getMenuInflater().inflate(R.menu.shuffle, menu);
    // Share, ringtone, and equalizer
    getMenuInflater().inflate(R.menu.audio_player, menu);
    // Settings
    getMenuInflater().inflate(R.menu.activity_base, menu);
    return true;
}

From source file:net.mypapit.mobile.myrepeater.RepeaterListActivity.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.display_map, menu);

    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
        SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
        SearchView searchView = (SearchView) menu.findItem(R.id.search).getActionView();
        searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
        searchView.setIconifiedByDefault(false);
        searchView.setQueryHint("part of repeater callsign");

        SearchView.OnQueryTextListener textChangeListener = new SearchView.OnQueryTextListener() {

            @Override/*from w  w w.  j av a 2s  .c o  m*/
            public boolean onQueryTextSubmit(String searchText) {

                adapter.getFilter().filter(searchText);
                Log.d("MYRepeater", "search: " + searchText);
                adapter.notifyDataSetChanged();
                return true;
            }

            @Override
            public boolean onQueryTextChange(String searchText) {
                // TODO Auto-generated method stub
                adapter.getFilter().filter(searchText);
                adapter.notifyDataSetChanged();
                return true;
            }
        };

        searchView.setOnQueryTextListener(textChangeListener);
    }

    return super.onCreateOptionsMenu(menu);
}

From source file:uk.ac.hutton.ics.buntata.activity.MainActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    /* Inflate the menu */
    MenuInflater menuInflater = getMenuInflater();
    menuInflater.inflate(R.menu.main_menu, menu);

    /* Find the search menu item */
    final MenuItem searchItem = menu.findItem(R.id.action_search);

    /* Get the search manager */
    SearchManager searchManager = (SearchManager) MainActivity.this.getSystemService(Context.SEARCH_SERVICE);

    /* Get the actual search view */
    searchView = (SearchView) MenuItemCompat.getActionView(searchItem);

    if (searchView != null) {
        DisplayMetrics displayMetrics = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);

        final MenuItem barcodeItem = menu.findItem(R.id.action_scan_barcode);

        searchView.setMaxWidth(displayMetrics.widthPixels / 2);
        searchView.setSearchableInfo(searchManager.getSearchableInfo(MainActivity.this.getComponentName()));
        searchView.setQueryHint(getString(R.string.search_query_hint));
        /* Listen to submit events */
        searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
            @Override//from   w  ww. j  a  va2s  . c  o  m
            public boolean onQueryTextSubmit(String query) {
                /* Trim leading and trailing spaces that some keyboards will add */
                query = query.trim();

                MainActivity.this.query = query;
                filter(query);

                searchView.clearFocus();

                return false;
            }

            @Override
            public boolean onQueryTextChange(String s) {
                /* Close the search field when the search string is empty */
                if (StringUtils.isEmpty(s)) {
                    searchView.setIconified(true);
                    searchView.clearFocus();
                }
                return false;
            }
        });
        searchView.setOnCloseListener(new SearchView.OnCloseListener() {
            @Override
            public boolean onClose() {
                MainActivity.this.query = null;
                filter("");
                barcodeItem.setVisible(false);

                return false;
            }
        });

        searchView.setOnSearchClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                barcodeItem.setVisible(true);
            }
        });
    }

    return super.onCreateOptionsMenu(menu);
}

From source file:com.nadmm.airports.ActivityBase.java

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

    MenuItem settingsItem = menu.findItem(R.id.menu_settings);
    settingsItem.setVisible(getSelfNavDrawerItem() == NAVDRAWER_ITEM_INVALID);

    MenuItem searchItem = menu.findItem(R.id.menu_search);
    SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    searchView.setIconifiedByDefault(false);

    return super.onCreateOptionsMenu(menu);
}

From source file:com.weebly.opus1269.copyeverywhere.ui.main.MainActivity.java

/**
 * Initialize the {@link android.support.v7.view.menu.ActionMenuItemView} for search
 *//*from w w  w .j a v a2  s .  co  m*/
private void setupSearch() {
    final SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    final MenuItem searchItem = mMenu.findItem(R.id.action_search);
    final SearchView searchView = (SearchView) searchItem.getActionView();
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    searchView.setOnQueryTextListener(this);

    if (!TextUtils.isEmpty(mQueryString)) {
        // http://stackoverflow.com/a/32397014/4468645
        searchView.post(new Runnable() {
            @Override
            public void run() {
                MenuItemCompat.expandActionView(searchItem);
                searchView.setQuery(mQueryString, true);
            }
        });
    }
}

From source file:at.ac.tuwien.detlef.activities.MainActivity.java

/**
 * Get the {@link SearchView} and set the {@link SearchableInfo}
 * configuration for the {@link EpisodeListFragment#getFilter() episode
 * keyword filter}./*from  w  ww  .  j  av a  2  s . co m*/
 */
private void setSearchManager() {
    String tmptag = "searchmanager";
    Log.d(tmptag, "setSearchManager()");

    if (menu.findItem(R.id.menu_search) == null) {
        Log.d(tmptag, "is null");
        return;
    }

    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);
    searchView.setOnQueryTextListener(new EpisodeSearchQueryTextListener(getEpisodeListFragment()));
}

From source file:com.vuze.android.remote.activity.TorrentViewActivity.java

@TargetApi(Build.VERSION_CODES.FROYO)
private void setupSearchView_Froyo(SearchView mSearchView) {
    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    if (searchManager != null) {
        mSearchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    }/*  w ww. j a v a 2s  .  c o m*/
}