Search in sources :

Example 21 with SearchView

use of androidx.appcompat.widget.SearchView in project AntennaPod by AntennaPod.

the class GpodnetMainFragment method setupToolbar.

private void setupToolbar(Toolbar toolbar) {
    toolbar.setTitle(R.string.gpodnet_main_label);
    toolbar.setNavigationOnClickListener(v -> getParentFragmentManager().popBackStack());
    toolbar.inflateMenu(R.menu.search);
    MenuItem searchItem = toolbar.getMenu().findItem(R.id.action_search);
    final SearchView sv = (SearchView) searchItem.getActionView();
    sv.setQueryHint(getString(R.string.gpodnet_search_hint));
    sv.setOnQueryTextListener(new SearchView.OnQueryTextListener() {

        @Override
        public boolean onQueryTextSubmit(String query) {
            Activity activity = getActivity();
            if (activity != null) {
                searchItem.collapseActionView();
                ((MainActivity) activity).loadChildFragment(OnlineSearchFragment.newInstance(GpodnetPodcastSearcher.class, query));
            }
            return true;
        }

        @Override
        public boolean onQueryTextChange(String s) {
            return false;
        }
    });
}
Also used : SearchView(androidx.appcompat.widget.SearchView) MainActivity(de.danoeh.antennapod.activity.MainActivity) Activity(android.app.Activity) MenuItem(android.view.MenuItem)

Example 22 with SearchView

use of androidx.appcompat.widget.SearchView in project AntennaPod by AntennaPod.

the class SearchFragment method setupToolbar.

private void setupToolbar(Toolbar toolbar) {
    toolbar.setTitle(R.string.search_label);
    toolbar.setNavigationOnClickListener(v -> getParentFragmentManager().popBackStack());
    toolbar.inflateMenu(R.menu.search);
    MenuItem item = toolbar.getMenu().findItem(R.id.action_search);
    item.expandActionView();
    searchView = (SearchView) item.getActionView();
    searchView.setQueryHint(getString(R.string.search_label));
    searchView.requestFocus();
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {

        @Override
        public boolean onQueryTextSubmit(String s) {
            searchView.clearFocus();
            searchWithProgressBar();
            return true;
        }

        @Override
        public boolean onQueryTextChange(String s) {
            automaticSearchDebouncer.removeCallbacksAndMessages(null);
            if (s.isEmpty() || s.endsWith(" ") || (lastQueryChange != 0 && System.currentTimeMillis() > lastQueryChange + SEARCH_DEBOUNCE_INTERVAL)) {
                search();
            } else {
                automaticSearchDebouncer.postDelayed(() -> {
                    search();
                    // Don't search instantly with first symbol after some pause
                    lastQueryChange = 0;
                }, SEARCH_DEBOUNCE_INTERVAL / 2);
            }
            lastQueryChange = System.currentTimeMillis();
            return false;
        }
    });
    item.setOnActionExpandListener(new MenuItem.OnActionExpandListener() {

        @Override
        public boolean onMenuItemActionExpand(MenuItem item) {
            return true;
        }

        @Override
        public boolean onMenuItemActionCollapse(MenuItem item) {
            getParentFragmentManager().popBackStack();
            return true;
        }
    });
}
Also used : SearchView(androidx.appcompat.widget.SearchView) MenuItem(android.view.MenuItem)

Example 23 with SearchView

use of androidx.appcompat.widget.SearchView in project orgzly-android by orgzly.

the class MainActivity method setupSearchView.

/**
 * SearchView setup and query text listeners.
 * TODO: http://developer.android.com/training/search/setup.html
 */
private void setupSearchView(Menu menu) {
    final MenuItem searchItem = menu.findItem(R.id.activity_action_search);
    final SearchView searchView = (SearchView) searchItem.getActionView();
    searchView.setQueryHint(getString(R.string.search_hint));
    /* When user starts the search, fill the search box with text depending on current fragment. */
    searchView.setOnSearchClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            /* Make search as wide as possible. */
            ViewGroup.LayoutParams layoutParams = searchView.getLayoutParams();
            layoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT;
            /* For Query fragment, fill the box with full query. */
            String q = DisplayManager.getDisplayedQuery(getSupportFragmentManager());
            if (q != null) {
                searchView.setQuery(q + " ", false);
            } else {
                /* If searching from book, add book name to query. */
                Book book = getActiveFragmentBook();
                if (book != null) {
                    DottedQueryBuilder builder = new DottedQueryBuilder();
                    String query = builder.build(new Query(new Condition.InBook(book.getName())));
                    searchView.setQuery(query + " ", false);
                }
            }
        }
    });
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {

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

        @Override
        public boolean onQueryTextSubmit(String str) {
            if (BuildConfig.LOG_DEBUG)
                LogUtils.d(TAG, str);
            /* Close search. */
            searchItem.collapseActionView();
            DisplayManager.displayQuery(getSupportFragmentManager(), str.trim());
            return true;
        }
    });
}
Also used : Condition(com.orgzly.android.query.Condition) Query(com.orgzly.android.query.Query) MenuItem(android.view.MenuItem) DrawerNavigationView(com.orgzly.android.ui.drawer.DrawerNavigationView) SearchView(androidx.appcompat.widget.SearchView) View(android.view.View) NavigationView(com.google.android.material.navigation.NavigationView) DottedQueryBuilder(com.orgzly.android.query.user.DottedQueryBuilder) SearchView(androidx.appcompat.widget.SearchView) Book(com.orgzly.android.db.entity.Book)

Example 24 with SearchView

use of androidx.appcompat.widget.SearchView in project RSAndroidApp by RailwayStations.

the class HighScoreActivity method onCreateOptionsMenu.

@Override
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public boolean onCreateOptionsMenu(final Menu menu) {
    getMenuInflater().inflate(R.menu.menu_high_score, menu);
    final SearchManager manager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    final SearchView search = (SearchView) menu.findItem(R.id.search).getActionView();
    search.setSearchableInfo(manager.getSearchableInfo(getComponentName()));
    search.setOnQueryTextListener(new SearchView.OnQueryTextListener() {

        @Override
        public boolean onQueryTextSubmit(final String s) {
            Log.d(TAG, "onQueryTextSubmit ");
            if (adapter != null) {
                adapter.getFilter().filter(s);
                if (adapter.isEmpty()) {
                    Toast.makeText(HighScoreActivity.this, R.string.no_records_found, Toast.LENGTH_LONG).show();
                } else {
                    Toast.makeText(HighScoreActivity.this, getResources().getQuantityString(R.plurals.records_found, adapter.getCount(), adapter.getCount()), Toast.LENGTH_LONG).show();
                }
            }
            return false;
        }

        @Override
        public boolean onQueryTextChange(final String s) {
            Log.d(TAG, "onQueryTextChange ");
            if (adapter != null) {
                adapter.getFilter().filter(s);
            }
            return false;
        }
    });
    return true;
}
Also used : SearchView(androidx.appcompat.widget.SearchView) SearchManager(android.app.SearchManager) TargetApi(android.annotation.TargetApi)

Example 25 with SearchView

use of androidx.appcompat.widget.SearchView in project Gadgetbridge by Freeyourgadget.

the class AppBlacklistActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_appblacklist);
    RecyclerView appListView = (RecyclerView) findViewById(R.id.appListView);
    appListView.setLayoutManager(new LinearLayoutManager(this));
    appBlacklistAdapter = new AppBlacklistAdapter(R.layout.item_app_blacklist, this);
    appListView.setAdapter(appBlacklistAdapter);
    SearchView searchView = (SearchView) findViewById(R.id.appListViewSearch);
    searchView.setIconifiedByDefault(false);
    searchView.setIconified(false);
    searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {

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

        @Override
        public boolean onQueryTextChange(String newText) {
            appBlacklistAdapter.getFilter().filter(newText);
            return true;
        }
    });
}
Also used : SearchView(androidx.appcompat.widget.SearchView) RecyclerView(androidx.recyclerview.widget.RecyclerView) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) AppBlacklistAdapter(nodomain.freeyourgadget.gadgetbridge.adapter.AppBlacklistAdapter)

Aggregations

SearchView (androidx.appcompat.widget.SearchView)39 MenuItem (android.view.MenuItem)29 View (android.view.View)7 Bundle (android.os.Bundle)5 SearchManager (android.app.SearchManager)4 Intent (android.content.Intent)4 Drawable (android.graphics.drawable.Drawable)4 SpannableString (android.text.SpannableString)4 MenuInflater (android.view.MenuInflater)4 LinearLayout (android.widget.LinearLayout)4 TextView (android.widget.TextView)4 RecyclerView (androidx.recyclerview.widget.RecyclerView)4 SuppressLint (android.annotation.SuppressLint)3 TargetApi (android.annotation.TargetApi)3 Activity (android.app.Activity)3 Context (android.content.Context)3 Uri (android.net.Uri)3 Handler (android.os.Handler)3 Menu (android.view.Menu)3 ViewTreeObserver (android.view.ViewTreeObserver)3