Search in sources :

Example 36 with SearchView

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();
}
Also used : DividerItemDecoration(androidx.recyclerview.widget.DividerItemDecoration) Chip(com.google.android.material.chip.Chip) Bundle(android.os.Bundle) ProgressBar(android.widget.ProgressBar) NonNull(androidx.annotation.NonNull) Uri(android.net.Uri) FrameLayout(android.widget.FrameLayout) ImageView(android.widget.ImageView) BookmarkLocationsDao(fr.free.nrw.commons.bookmarks.locations.BookmarkLocationsDao) MapView(com.mapbox.mapboxsdk.maps.MapView) Marker(com.mapbox.mapboxsdk.annotations.Marker) VectorDrawableCompat(androidx.vectordrawable.graphics.drawable.VectorDrawableCompat) OnClick(butterknife.OnClick) CommonsApplication(fr.free.nrw.commons.CommonsApplication) Manifest(android.Manifest) Utils(fr.free.nrw.commons.Utils) Log(android.util.Log) RxSearchView(com.jakewharton.rxbinding3.appcompat.RxSearchView) IntentFilter(android.content.IntentFilter) SearchView(androidx.appcompat.widget.SearchView) LocationServiceManager(fr.free.nrw.commons.location.LocationServiceManager) LayoutUtils(fr.free.nrw.commons.utils.LayoutUtils) Unit(kotlin.Unit) Nullable(androidx.annotation.Nullable) SystemThemeUtils(fr.free.nrw.commons.utils.SystemThemeUtils) UiUtils(fr.free.nrw.commons.utils.UiUtils) LOCATION_SLIGHTLY_CHANGED(fr.free.nrw.commons.location.LocationServiceManager.LocationChangeType.LOCATION_SLIGHTLY_CHANGED) Html(android.text.Html) LOCATION_SIGNIFICANTLY_CHANGED(fr.free.nrw.commons.location.LocationServiceManager.LocationChangeType.LOCATION_SIGNIFICANTLY_CHANGED) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) LatLngBounds(com.mapbox.mapboxsdk.geometry.LatLngBounds) CommonsDaggerSupportFragment(fr.free.nrw.commons.di.CommonsDaggerSupportFragment) Place(fr.free.nrw.commons.nearby.Place) ButterKnife(butterknife.ButterKnife) BottomSheetBehavior(com.google.android.material.bottomsheet.BottomSheetBehavior) OnMenuItemClickListener(android.view.MenuItem.OnMenuItemClickListener) ChipGroup(com.google.android.material.chip.ChipGroup) NearbyParentFragmentPresenter(fr.free.nrw.commons.nearby.presenter.NearbyParentFragmentPresenter) Callback(fr.free.nrw.commons.nearby.fragments.AdvanceQueryFragment.Callback) ArrayList(java.util.ArrayList) CameraUpdateFactory(com.mapbox.mapboxsdk.camera.CameraUpdateFactory) RxView(com.jakewharton.rxbinding2.view.RxView) MenuInflater(android.view.MenuInflater) Toast(android.widget.Toast) Menu(android.view.Menu) CameraPosition(com.mapbox.mapboxsdk.camera.CameraPosition) Settings(android.provider.Settings) Observable(io.reactivex.Observable) Named(javax.inject.Named) MapboxMap(com.mapbox.mapboxsdk.maps.MapboxMap) LocationUtils(fr.free.nrw.commons.utils.LocationUtils) ScaleBarOptions(com.mapbox.pluginscalebar.ScaleBarOptions) IOException(java.io.IOException) Gravity(android.view.Gravity) NearbyPlacesInfo(fr.free.nrw.commons.nearby.NearbyController.NearbyPlacesInfo) Configuration(android.content.res.Configuration) NetworkUtils(fr.free.nrw.commons.utils.NetworkUtils) NearbyMarker(fr.free.nrw.commons.nearby.NearbyMarker) LinearLayout(android.widget.LinearLayout) MainActivity(fr.free.nrw.commons.contributions.MainActivity) LengthUtils.formatDistanceBetween(fr.free.nrw.commons.utils.LengthUtils.formatDistanceBetween) UiSettings(com.mapbox.mapboxsdk.maps.UiSettings) PackageManager(android.content.pm.PackageManager) AppCompatImageView(androidx.appcompat.widget.AppCompatImageView) Date(java.util.Date) R(fr.free.nrw.commons.R) LinkMovementMethod(android.text.method.LinkMovementMethod) DrawableRes(androidx.annotation.DrawableRes) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) BindView(butterknife.BindView) ScaleBarPlugin(com.mapbox.pluginscalebar.ScaleBarPlugin) MarkerOptions(com.mapbox.mapboxsdk.annotations.MarkerOptions) ActiveFragment(fr.free.nrw.commons.contributions.MainActivity.ActiveFragment) FloatingActionButton(com.google.android.material.floatingactionbutton.FloatingActionButton) View(android.view.View) Button(android.widget.Button) Schedulers(io.reactivex.schedulers.Schedulers) Animation(android.view.animation.Animation) RecyclerView(androidx.recyclerview.widget.RecyclerView) Label(fr.free.nrw.commons.nearby.Label) JsonKvStore(fr.free.nrw.commons.kvstore.JsonKvStore) BroadcastReceiver(android.content.BroadcastReceiver) AppCompatButton(androidx.appcompat.widget.AppCompatButton) ViewGroup(android.view.ViewGroup) CheckBoxTriStates(fr.free.nrw.commons.nearby.CheckBoxTriStates) Timber(timber.log.Timber) CUSTOM_QUERY(fr.free.nrw.commons.location.LocationServiceManager.LocationChangeType.CUSTOM_QUERY) PolygonOptions(com.mapbox.mapboxsdk.annotations.PolygonOptions) FileUtils(fr.free.nrw.commons.upload.FileUtils) List(java.util.List) TextView(android.widget.TextView) NearbyBaseMarker(fr.free.nrw.commons.nearby.NearbyBaseMarker) Style(com.mapbox.mapboxsdk.maps.Style) RelativeLayout(android.widget.RelativeLayout) PermissionUtils(fr.free.nrw.commons.utils.PermissionUtils) NotNull(org.jetbrains.annotations.NotNull) LocationManager(android.location.LocationManager) Snackbar(com.google.android.material.snackbar.Snackbar) NearbyParentFragmentContract(fr.free.nrw.commons.nearby.contract.NearbyParentFragmentContract) AppCompatTextView(androidx.appcompat.widget.AppCompatTextView) DialogUtil(fr.free.nrw.commons.utils.DialogUtil) Context(android.content.Context) IconFactory(com.mapbox.mapboxsdk.annotations.IconFactory) NearbyFilterState(fr.free.nrw.commons.nearby.NearbyFilterState) AlertDialog(androidx.appcompat.app.AlertDialog) WikidataEditListener(fr.free.nrw.commons.wikidata.WikidataEditListener) Intent(android.content.Intent) ExecutorUtils(fr.free.nrw.commons.utils.ExecutorUtils) ViewUtil(fr.free.nrw.commons.utils.ViewUtil) MAP_UPDATED(fr.free.nrw.commons.location.LocationServiceManager.LocationChangeType.MAP_UPDATED) ContributionController(fr.free.nrw.commons.contributions.ContributionController) MenuItem(android.view.MenuItem) AnimationUtils(android.view.animation.AnimationUtils) Inject(javax.inject.Inject) SuppressLint(android.annotation.SuppressLint) LatLng(com.mapbox.mapboxsdk.geometry.LatLng) LoginActivity(fr.free.nrw.commons.auth.LoginActivity) LocationUpdateListener(fr.free.nrw.commons.location.LocationUpdateListener) MotionEvent(android.view.MotionEvent) Icon(com.mapbox.mapboxsdk.annotations.Icon) MarkerPlaceGroup(fr.free.nrw.commons.nearby.MarkerPlaceGroup) Iterator(java.util.Iterator) LayoutInflater(android.view.LayoutInflater) TimeUnit(java.util.concurrent.TimeUnit) Bitmap(android.graphics.Bitmap) NearbyFilterSearchRecyclerViewAdapter(fr.free.nrw.commons.nearby.NearbyFilterSearchRecyclerViewAdapter) NearbyController(fr.free.nrw.commons.nearby.NearbyController) Polygon(com.mapbox.mapboxsdk.annotations.Polygon) NearbyFABUtils(fr.free.nrw.commons.utils.NearbyFABUtils) PLACE_OBJECT(fr.free.nrw.commons.wikidata.WikidataConstants.PLACE_OBJECT) NearbyFilterSearchRecyclerViewAdapter(fr.free.nrw.commons.nearby.NearbyFilterSearchRecyclerViewAdapter) ArrayList(java.util.ArrayList) Label(fr.free.nrw.commons.nearby.Label) DividerItemDecoration(androidx.recyclerview.widget.DividerItemDecoration) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) SuppressLint(android.annotation.SuppressLint)

Example 37 with SearchView

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;
            }
        }
    });
}
Also used : SearchView(androidx.appcompat.widget.SearchView) Handler(android.os.Handler) ViewTreeObserver(android.view.ViewTreeObserver)

Example 38 with SearchView

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);
}
Also used : ArrayList(java.util.ArrayList) MenuItem(android.view.MenuItem) MangasRecAdapter(ar.rulosoft.mimanganu.adapters.MangasRecAdapter) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) SearchView(androidx.appcompat.widget.SearchView) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) SearchView(androidx.appcompat.widget.SearchView) ContextMenu(android.view.ContextMenu) Menu(android.view.Menu)

Example 39 with SearchView

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;
        }
    });
}
Also used : OnQueryTextListener(androidx.appcompat.widget.SearchView.OnQueryTextListener) SearchView(androidx.appcompat.widget.SearchView) Bundle(android.os.Bundle) MenuItem(android.view.MenuItem)

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