Search in sources :

Example 71 with SearchView

use of android.widget.SearchView in project android_packages_apps_Settings by omnirom.

the class PrintServiceSettingsFragment method onCreateOptionsMenu.

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);
    inflater.inflate(R.menu.print_service_settings, menu);
    MenuItem addPrinters = menu.findItem(R.id.print_menu_item_add_printer);
    if (mServiceEnabled && mAddPrintersIntent != null) {
        addPrinters.setIntent(mAddPrintersIntent);
    } else {
        menu.removeItem(R.id.print_menu_item_add_printer);
    }
    MenuItem settings = menu.findItem(R.id.print_menu_item_settings);
    if (mServiceEnabled && mSettingsIntent != null) {
        settings.setIntent(mSettingsIntent);
    } else {
        menu.removeItem(R.id.print_menu_item_settings);
    }
    MenuItem searchItem = menu.findItem(R.id.print_menu_item_search);
    if (mServiceEnabled && mPrintersAdapter.getUnfilteredCount() > 0) {
        mSearchView = (SearchView) searchItem.getActionView();
        mSearchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {

            @Override
            public boolean onQueryTextSubmit(String query) {
                return true;
            }

            @Override
            public boolean onQueryTextChange(String searchString) {
                mPrintersAdapter.getFilter().filter(searchString);
                return true;
            }
        });
        mSearchView.addOnAttachStateChangeListener(new View.OnAttachStateChangeListener() {

            @Override
            public void onViewAttachedToWindow(View view) {
                if (AccessibilityManager.getInstance(getActivity()).isEnabled()) {
                    view.announceForAccessibility(getString(R.string.print_search_box_shown_utterance));
                }
            }

            @Override
            public void onViewDetachedFromWindow(View view) {
                Activity activity = getActivity();
                if (activity != null && !activity.isFinishing() && AccessibilityManager.getInstance(activity).isEnabled()) {
                    view.announceForAccessibility(getString(R.string.print_search_box_hidden_utterance));
                }
            }
        });
    } else {
        menu.removeItem(R.id.print_menu_item_search);
    }
}
Also used : SearchView(android.widget.SearchView) SettingsActivity(com.android.settings.SettingsActivity) Activity(android.app.Activity) MenuItem(android.view.MenuItem) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) SearchView(android.widget.SearchView) TextView(android.widget.TextView)

Example 72 with SearchView

use of android.widget.SearchView in project ShelterApp by farzamtn.

the class ShelterItemListActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_shelteritem_list);
    Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    toolbar.setTitle(getTitle());
    // Show the Up button in the action bar.
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(true);
    }
    View recyclerView = findViewById(R.id.shelteritem_list);
    assert recyclerView != null;
    setupRecyclerView((RecyclerView) recyclerView);
    SearchView searchBar = findViewById(R.id.search_bar);
    searchBar.setQueryHint("Search Shelters");
    searchBar.setSubmitButtonEnabled(true);
    searchBar.setOnQueryTextListener(new SearchView.OnQueryTextListener() {

        @Override
        public boolean onQueryTextSubmit(String query) {
            if ((query == null) || ("".equals(query))) {
                setupRecyclerView((RecyclerView) recyclerView);
            }
            setupRecyclerView((RecyclerView) recyclerView, searchBar.getQuery());
            return true;
        }

        @Override
        public boolean onQueryTextChange(String query) {
            if ((query == null) || ("".equals(query))) {
                setupRecyclerView((RecyclerView) recyclerView);
            }
            setupRecyclerView((RecyclerView) recyclerView, searchBar.getQuery());
            return true;
        }
    });
    if (findViewById(R.id.shelteritem_detail_container) != null) {
        // The detail container view will be present only in the
        // large-screen layouts (res/values-w900dp).
        // If this view is present, then the
        // activity should be in two-pane mode.
        mTwoPane = true;
    }
}
Also used : SearchView(android.widget.SearchView) RecyclerView(android.support.v7.widget.RecyclerView) SearchView(android.widget.SearchView) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) View(android.view.View) ActionBar(android.support.v7.app.ActionBar) Toolbar(android.support.v7.widget.Toolbar)

Aggregations

SearchView (android.widget.SearchView)72 View (android.view.View)37 TextView (android.widget.TextView)30 MenuItem (android.view.MenuItem)28 ImageView (android.widget.ImageView)16 ListView (android.widget.ListView)15 AdapterView (android.widget.AdapterView)14 RecyclerView (android.support.v7.widget.RecyclerView)12 SearchManager (android.app.SearchManager)11 Test (org.junit.Test)8 Activity (android.app.Activity)7 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)7 RecyclerView (androidx.recyclerview.widget.RecyclerView)7 SettingsActivity (com.android.settings.SettingsActivity)7 MenuInflater (android.view.MenuInflater)6 ViewGroup (android.view.ViewGroup)6 Toolbar (android.widget.Toolbar)6 Intent (android.content.Intent)4 RoboMenuItem (org.robolectric.fakes.RoboMenuItem)4 Nullable (android.support.annotation.Nullable)3