use of android.widget.Filterable in project Anki-Android by ankidroid.
the class DeckPicker method onCreateOptionsMenu.
@Override
public boolean onCreateOptionsMenu(Menu menu) {
Timber.d("onCreateOptionsMenu()");
getMenuInflater().inflate(R.menu.deck_picker, menu);
boolean sdCardAvailable = AnkiDroidApp.isSdCardMounted();
menu.findItem(R.id.action_sync).setEnabled(sdCardAvailable);
menu.findItem(R.id.action_new_filtered_deck).setEnabled(sdCardAvailable);
menu.findItem(R.id.action_check_database).setEnabled(sdCardAvailable);
menu.findItem(R.id.action_check_media).setEnabled(sdCardAvailable);
menu.findItem(R.id.action_empty_cards).setEnabled(sdCardAvailable);
MenuItem toolbarSearchItem = menu.findItem(R.id.deck_picker_action_filter);
mToolbarSearchView = (SearchView) toolbarSearchItem.getActionView();
mToolbarSearchView.setQueryHint(getString(R.string.search_decks));
mToolbarSearchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
mToolbarSearchView.clearFocus();
return true;
}
@Override
public boolean onQueryTextChange(String newText) {
Filterable adapter = (Filterable) mRecyclerView.getAdapter();
adapter.getFilter().filter(newText);
return true;
}
});
if (colIsOpen()) {
displaySyncBadge(menu);
// Show / hide undo
if (mFragmented || !getCol().undoAvailable()) {
menu.findItem(R.id.action_undo).setVisible(false);
} else {
Resources res = getResources();
menu.findItem(R.id.action_undo).setVisible(true);
String undo = res.getString(R.string.studyoptions_congrats_undo, getCol().undoName(res));
menu.findItem(R.id.action_undo).setTitle(undo);
}
// Remove the filter - not necessary and search has other implications for new users.
menu.findItem(R.id.deck_picker_action_filter).setVisible(getCol().getDecks().count() >= 10);
}
return super.onCreateOptionsMenu(menu);
}
use of android.widget.Filterable in project platform_packages_apps_Settings by BlissRoms.
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 && !TextUtils.isEmpty(mAddPrintersTitle) && 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 && !TextUtils.isEmpty(mSettingsTitle) && 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) {
((Filterable) getListView().getAdapter()).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);
}
}
Aggregations