use of androidx.appcompat.widget.SearchView in project apps-android-commons by commons-app.
the class NearbyParentFragment method initNearbyFilter.
public void initNearbyFilter() {
nearbyFilterList.setVisibility(View.GONE);
searchView.setOnQueryTextFocusChangeListener((v, hasFocus) -> {
if (hasFocus) {
presenter.searchViewGainedFocus();
nearbyFilterList.setVisibility(View.VISIBLE);
} else {
nearbyFilterList.setVisibility(View.GONE);
}
});
recyclerView.setHasFixedSize(true);
recyclerView.addItemDecoration(new DividerItemDecoration(getContext(), DividerItemDecoration.VERTICAL));
final LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getActivity());
linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
recyclerView.setLayoutManager(linearLayoutManager);
nearbyFilterSearchRecyclerViewAdapter = new NearbyFilterSearchRecyclerViewAdapter(getContext(), new ArrayList<>(Label.valuesAsList()), recyclerView);
nearbyFilterSearchRecyclerViewAdapter.setCallback(new NearbyFilterSearchRecyclerViewAdapter.Callback() {
@Override
public void setCheckboxUnknown() {
presenter.setCheckboxUnknown();
}
@Override
public void filterByMarkerType(final ArrayList<Label> selectedLabels, final int i, final boolean b, final boolean b1) {
presenter.filterByMarkerType(selectedLabels, i, b, b1);
}
@Override
public boolean isDarkTheme() {
return isDarkTheme;
}
});
nearbyFilterList.getLayoutParams().width = (int) LayoutUtils.getScreenWidth(getActivity(), 0.75);
recyclerView.setAdapter(nearbyFilterSearchRecyclerViewAdapter);
LayoutUtils.setLayoutHeightAllignedToWidth(1.25, nearbyFilterList);
compositeDisposable.add(RxSearchView.queryTextChanges(searchView).takeUntil(RxView.detaches(searchView)).debounce(500, TimeUnit.MILLISECONDS).observeOn(AndroidSchedulers.mainThread()).subscribe(query -> {
((NearbyFilterSearchRecyclerViewAdapter) recyclerView.getAdapter()).getFilter().filter(query.toString());
}));
initFilterChips();
}
use of androidx.appcompat.widget.SearchView in project nextcloud-notes by stefan-niedermann.
the class SearchableBaseNoteFragment method onPrepareOptionsMenu.
@Override
public void onPrepareOptionsMenu(@NonNull Menu menu) {
super.onPrepareOptionsMenu(menu);
final var searchMenuItem = menu.findItem(R.id.search);
searchView = (SearchView) searchMenuItem.getActionView();
if (!TextUtils.isEmpty(searchQuery) && isNew) {
searchMenuItem.expandActionView();
searchView.setQuery(searchQuery, true);
searchView.clearFocus();
}
searchMenuItem.collapseActionView();
final var searchEditFrame = searchView.findViewById(R.id.search_edit_frame);
searchEditFrame.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
int oldVisibility = -1;
@Override
public void onGlobalLayout() {
final int currentVisibility = searchEditFrame.getVisibility();
if (currentVisibility != oldVisibility) {
if (currentVisibility != View.VISIBLE) {
colorWithText("", null, mainColor, textColor);
searchQuery = "";
hideSearchFabs();
} else {
jumpToOccurrence();
colorWithText(searchQuery, null, mainColor, textColor);
occurrenceCount = countOccurrences(getContent(), searchQuery);
showSearchFabs();
}
oldVisibility = currentVisibility;
}
}
});
final var next = getSearchNextButton();
final var prev = getSearchPrevButton();
if (next != null) {
next.setOnClickListener(v -> {
currentOccurrence++;
jumpToOccurrence();
colorWithText(searchView.getQuery().toString(), currentOccurrence, mainColor, textColor);
});
}
if (prev != null) {
prev.setOnClickListener(v -> {
occurrenceCount = countOccurrences(getContent(), searchView.getQuery().toString());
currentOccurrence--;
jumpToOccurrence();
colorWithText(searchView.getQuery().toString(), currentOccurrence, mainColor, textColor);
});
}
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
private DelayQueryRunnable delayQueryTask;
private final Handler handler = new Handler();
@Override
public boolean onQueryTextSubmit(@NonNull String query) {
currentOccurrence++;
jumpToOccurrence();
colorWithText(query, currentOccurrence, mainColor, textColor);
return true;
}
@Override
public boolean onQueryTextChange(@NonNull String newText) {
queryWithHandler(newText);
return true;
}
private void queryMatch(@NonNull String newText) {
searchQuery = newText;
occurrenceCount = countOccurrences(getContent(), searchQuery);
if (occurrenceCount > 1) {
showSearchFabs();
} else {
hideSearchFabs();
}
currentOccurrence = 1;
jumpToOccurrence();
colorWithText(searchQuery, currentOccurrence, mainColor, textColor);
}
private void queryWithHandler(@NonNull String newText) {
if (delayQueryTask != null) {
delayQueryTask.cancel();
handler.removeCallbacksAndMessages(null);
}
delayQueryTask = new DelayQueryRunnable(newText);
// If there is only one char in the search pattern, we should start the search immediately.
handler.postDelayed(delayQueryTask, newText.length() > 1 ? delay : 0);
}
class DelayQueryRunnable implements Runnable {
private String text;
private boolean canceled = false;
public DelayQueryRunnable(String text) {
this.text = text;
}
@Override
public void run() {
if (canceled) {
return;
}
queryMatch(text);
}
public void cancel() {
canceled = true;
}
}
});
}
use of androidx.appcompat.widget.SearchView in project MiMangaNu by raulhaag.
the class MainFragment method onCreateOptionsMenu.
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.view_mismangas, menu);
final Menu mMenu = menu;
/* Local Search */
MenuItem search = menu.findItem(R.id.action_search_local);
final SearchView searchView = (SearchView) MenuItemCompat.getActionView(search);
searchView.setOnSearchClickListener(new SearchView.OnClickListener() {
@Override
public void onClick(View view) {
mMenu.findItem(R.id.action_view_download).setVisible(false);
}
});
searchView.setOnCloseListener(new SearchView.OnCloseListener() {
@Override
public boolean onClose() {
setListManga(false);
mMenu.findItem(R.id.action_view_download).setVisible(true);
return false;
}
});
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String value) {
searchView.clearFocus();
return false;
}
@Override
public boolean onQueryTextChange(String value) {
if (!value.isEmpty()) {
ArrayList<Manga> mangaList;
if (value.contains("'"))
value = value.replaceAll("'", "''");
try {
mangaList = Database.getMangasCondition(getActivity(), " ((nombre LIKE '%" + value + "%') AND (vault = '" + currentVault + "')) ", null, false);
mMAdapter = new MangasRecAdapter(mangaList, getContext(), MainFragment.this);
mMAdapter.setMangaClickListener(MainFragment.this);
recyclerView.setAdapter(mMAdapter);
} catch (Exception e) {
Log.e("MF", "Exception", e);
// ACRA.getErrorReporter().handleException(e);
}
}
return false;
}
});
MenuItem vmi = menu.findItem(R.id.open_vault);
if (!currentVault.isEmpty()) {
vmi.setTitle(R.string.close_vault);
}
/* Set hide/unhide checkbox */
boolean checkedRead = pm.getInt(SELECT_MODE, MODE_SHOW_ALL) > 0;
menu.findItem(R.id.action_hide_read).setChecked(checkedRead);
/* Set sort mode */
int[] sortList = { R.id.sort_last_read, R.id.sort_last_read_desc, R.id.sort_name, R.id.sort_name_desc, R.id.sort_author, R.id.sort_author_desc, R.id.sort_finished, R.id.sort_finished_asc, R.id.sort_as_added_to_db_asc, R.id.sort_as_added_to_db_desc, R.id.sort_last_updated };
menu.findItem(sortList[pm.getInt("manga_view_sort_by", 0)]).setChecked(true);
}
use of androidx.appcompat.widget.SearchView in project MiMangaNu by raulhaag.
the class ServerFilteredNavigationFragment method onCreateOptionsMenu.
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.manga_server_visual, menu);
MenuItem search = menu.findItem(R.id.action_search);
if (!serverBase.hasList()) {
MenuItem item = menu.findItem(R.id.ver_como_lista);
item.setVisible(false);
}
if (serverBase.getServerFilters().length == 0) {
MenuItem item = menu.findItem(R.id.filter);
item.setVisible(false);
}
if (!serverBase.hasSearch()) {
MenuItem item = menu.findItem(R.id.action_search);
item.setVisible(false);
}
SearchView searchView = (SearchView) MenuItemCompat.getActionView(search);
searchView.setOnQueryTextListener(new OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String value) {
Bundle bundle = new Bundle();
bundle.putInt(MainFragment.SERVER_ID, serverBase.getServerID());
bundle.putString(SearchResultsFragment.TERM, value);
SearchResultsFragment searchResultsFragment = new SearchResultsFragment();
searchResultsFragment.setArguments(bundle);
((MainActivity) getActivity()).replaceFragment(searchResultsFragment, "SearchFragment");
return true;
}
@Override
public boolean onQueryTextChange(String s) {
return false;
}
});
}
Aggregations