Search in sources :

Example 1 with Filterable

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);
}
Also used : SearchView(androidx.appcompat.widget.SearchView) Filterable(android.widget.Filterable) MenuItem(android.view.MenuItem) Resources(android.content.res.Resources)

Example 2 with Filterable

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);
    }
}
Also used : SearchView(android.widget.SearchView) Filterable(android.widget.Filterable) SettingsActivity(com.android.settings.SettingsActivity) Activity(android.app.Activity) MenuItem(android.view.MenuItem) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) ListView(android.widget.ListView) SearchView(android.widget.SearchView)

Aggregations

MenuItem (android.view.MenuItem)2 Filterable (android.widget.Filterable)2 Activity (android.app.Activity)1 Resources (android.content.res.Resources)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 ListView (android.widget.ListView)1 SearchView (android.widget.SearchView)1 TextView (android.widget.TextView)1 SearchView (androidx.appcompat.widget.SearchView)1 SettingsActivity (com.android.settings.SettingsActivity)1