Example usage for android.widget SearchView setSearchableInfo

List of usage examples for android.widget SearchView setSearchableInfo

Introduction

In this page you can find the example usage for android.widget SearchView setSearchableInfo.

Prototype

public void setSearchableInfo(SearchableInfo searchable) 

Source Link

Document

Sets the SearchableInfo for this SearchView.

Usage

From source file:dev.vision.shopping.center.Fragments.GourmetFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    //inflater.inflate(R.menu.main, menu);
    inflater.inflate(R.menu.offers, menu);
    MenuItem searchItem = menu.findItem(R.id.action_search);
    MenuItem expand = menu.findItem(R.id.expand);
    expand.setVisible(false);/*from   w  w  w.  j  a  v  a2  s  . c om*/

    SearchView searchView = null;

    searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
    if (searchView == null)
        searchView = (SearchView) searchItem.getActionView();
    SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE);

    searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName()));
    searchView.setOnQueryTextListener(this);

}

From source file:net.abcdroid.devfest12.ui.HomeActivity.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void setupSearchMenuItem(Menu 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()));
        }/*w  w w .j  a v a2s  . c o m*/
    }
}

From source file:com.google.android.apps.iosched.ui.tablet.SessionsVendorsMultiPaneActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);
    getSupportMenuInflater().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()));
        }//from   www .j  a va 2s  . c om
    }
    return true;
}

From source file:org.jitsi.android.gui.contactlist.ContactListFragment.java

/**
 * Invoked when the options menu is created. Creates our own options menu
 * from the corresponding xml./*from  ww  w  .  j  ava  2s  .  c  om*/
 *
 * @param menu the options menu
 */
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater menuInflater) {
    super.onCreateOptionsMenu(menu, menuInflater);

    Activity activity = getActivity();

    // Get the SearchView and set the searchable configuration
    SearchManager searchManager = (SearchManager) activity.getSystemService(Context.SEARCH_SERVICE);

    this.searchItem = menu.findItem(R.id.search);

    // OnActionExpandListener not supported prior API 14
    if (AndroidUtils.hasAPI(14)) {
        searchItem.setOnActionExpandListener(new MenuItem.OnActionExpandListener() {
            @Override
            public boolean onMenuItemActionCollapse(MenuItem item) {
                filterContactList("");

                return true; // Return true to collapse action view
            }

            public boolean onMenuItemActionExpand(MenuItem item) {
                return true; // Return true to expand action view
            }
        });
    }

    if (AndroidUtils.hasAPI(11)) {
        SearchView searchView = (SearchView) searchItem.getActionView();
        searchView.setSearchableInfo(searchManager.getSearchableInfo(activity.getComponentName()));

        int id = searchView.getContext().getResources().getIdentifier("android:id/search_src_text", null, null);
        TextView textView = (TextView) searchView.findViewById(id);
        textView.setTextColor(getResources().getColor(R.color.white));
        textView.setHintTextColor(getResources().getColor(R.color.white));

        bindSearchListener();
    }
}

From source file:com.example.lowviscam.GalleryActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu items for use in the action bar
    MenuInflater inflater = getMenuInflater();
    if (isLight == true) {
        inflater.inflate(R.menu.gallery, menu);
    } else {/*w ww .  ja v a  2s  .co  m*/
        inflater.inflate(R.menu.gallery_dark, menu);
    }

    // Get the SearchView and set the searchable configuration
    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    SearchView 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.setSubmitButtonEnabled(true);
    searchView.setOnQueryTextListener(new OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            search(query);
            // First image toast
            String firstResult;
            if (numSearchResults == 0) {
                firstResult = "No results found for  " + query + ".";
            } else {
                firstResult = "The first image result is titled " + tagList[0];
            }

            SpannableString s = new SpannableString(firstResult);
            s.setSpan(new TypefaceSpan(GalleryActivity.this, "APHont-Regular_q15c.otf"), 0, s.length(),
                    Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            Toast.makeText(GalleryActivity.this, s, Toast.LENGTH_LONG).show();
            return true;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            if (TextUtils.isEmpty(newText)) {
                search("");
            }

            return true;
        }

        public void search(String query) {
            // hide keyboard
            InputMethodManager inputManager = (InputMethodManager) GalleryActivity.this
                    .getSystemService(Context.INPUT_METHOD_SERVICE);
            inputManager.hideSoftInputFromWindow(GalleryActivity.this.getCurrentFocus().getWindowToken(),
                    InputMethodManager.HIDE_NOT_ALWAYS);

            // Fetch the {@link LayoutInflater} service so that new views can be created
            LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);

            // Find the {@link GridView} that was already defined in the XML layout
            GridView gridView = (GridView) findViewById(R.id.grid);
            try {
                gridView.setAdapter(new CouponAdapter(inflater, createSearchedCoupons(query)));
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        }

    });

    return true;
    //return super.onCreateOptionsMenu(menu);
}

From source file:fr.cph.chicago.activity.MainActivity.java

@Override
public boolean onCreateOptionsMenu(final Menu menu) {
    this.mMenu = menu;
    getMenuInflater().inflate(R.menu.main, menu);
    // Associate searchable configuration with the SearchView
    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    SearchView searchView = (SearchView) menu.findItem(R.id.action_search).getActionView();
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
    return super.onCreateOptionsMenu(menu);
}

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

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

    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);
    MenuItem searchMenuItem = menu.findItem(R.id.action_search);

    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
        @Override//from   w  w w .java  2s .c o  m
        public boolean onQueryTextSubmit(String query) {
            return false;
        }

        @Override
        public boolean onQueryTextChange(String newText) {
            if (task != null) {
                task.cancel(true);
            }
            task = new searchTask();
            task.execute(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;
        }
    });
    return true;
}

From source file:com.andrew.apollo.ui.activities.BaseActivity.java

/**
 * {@inheritDoc}//  www  .  j a  va 2  s  . co 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:itcr.gitsnes.MainActivity.java

/**
 *  Methods inflate menu options panel//from w  w  w. ja  v  a  2 s . co m
 *  Params:
 *      - [menu]
 *  Returns:
 *      - State of building [true]
 */
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    /* Inflate the menu; this adds items to the action bar if it is present. */
    getMenuInflater().inflate(R.menu.main, menu);

    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    SearchView searchView = (SearchView) menu.findItem(R.id.search).getActionView();
    if (null != searchView) {
        searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));
        searchView.setIconifiedByDefault(false);
    }

    SearchView.OnQueryTextListener queryTextListener = new SearchView.OnQueryTextListener() {
        public boolean onQueryTextChange(String newText) {
            // this is your adapter that will be filtered
            // Log.i("log_tag",newText);

            return true;
        }

        public boolean onQueryTextSubmit(String query) {
            Log.i("log_tag", query);

            MasterGames new_fragment = new MasterGames(json_arr);
            new_fragment.setQname(query);

            RelativeLayout rl = (RelativeLayout) findViewById(R.id.mainback);
            rl.setBackgroundColor(Color.parseColor("#009f28"));
            authButton.setVisibility(View.INVISIBLE);

            FragmentTransaction transaction = getFragmentManager().beginTransaction();
            transaction.replace(R.id.placeholder, new_fragment);
            transaction.addToBackStack(null);
            transaction.commit();

            return true;

        }
    };

    searchView.setOnQueryTextListener(queryTextListener);

    return super.onCreateOptionsMenu(menu);
}

From source file:com.racoon.ampdroid.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.main, menu);

    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    SearchView searchView = (SearchView) menu.findItem(R.id.search).getActionView();
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));

    return true;//from   www .  j av  a  2s.  co m
}