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;
}
});
}
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;
}
});
}
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;
}
});
}
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;
}
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;
}
});
}
Aggregations