Search in sources :

Example 16 with SearchSettings

use of net.osmand.search.core.SearchSettings in project Osmand by osmandapp.

the class SearchCoreUITest method testNoResort.

@Test
public void testNoResort() throws IOException {
    SearchSettings ss = new SearchSettings((SearchSettings) null);
    ss = ss.setOriginalLocation(new LatLon(0, 0));
    SearchPhrase phrase = new SearchPhrase(ss, OsmAndCollator.primaryCollator());
    SearchResultCollection cll = new SearchUICore.SearchResultCollection(phrase);
    List<SearchResult> rs = new ArrayList<>();
    SearchResult a1 = searchResult(rs, phrase, "a", 100);
    cll.addSearchResults(rs, false, true);
    rs.clear();
    SearchResult b2 = searchResult(rs, phrase, "b", 200);
    cll.addSearchResults(rs, false, true);
    rs.clear();
    SearchResult b1 = searchResult(rs, phrase, "b", 100);
    cll.addSearchResults(rs, false, true);
    rs.clear();
    /*SearchResult a3 = */
    searchResult(rs, phrase, "a", 100);
    cll.addSearchResults(rs, false, true);
    rs.clear();
    Assert.assertEquals(3, cll.getCurrentSearchResults().size());
    Assert.assertSame(a1, cll.getCurrentSearchResults().get(0));
    Assert.assertSame(b2, cll.getCurrentSearchResults().get(1));
    Assert.assertSame(b1, cll.getCurrentSearchResults().get(2));
}
Also used : LatLon(net.osmand.data.LatLon) ArrayList(java.util.ArrayList) SearchSettings(net.osmand.search.core.SearchSettings) SearchResultCollection(net.osmand.search.SearchUICore.SearchResultCollection) SearchResult(net.osmand.search.core.SearchResult) SearchPhrase(net.osmand.search.core.SearchPhrase) Test(org.junit.Test)

Example 17 with SearchSettings

use of net.osmand.search.core.SearchSettings in project Osmand by osmandapp.

the class QuickSearchDialogFragment method setupSearch.

private void setupSearch(final MainActivity mainActivity) {
    // Setup search core
    // app.getSettings().MAP_PREFERRED_LOCALE.get();
    String locale = "";
    // app.getSettings().MAP_TRANSLITERATE_NAMES.get();
    boolean transliterate = false;
    searchHelper = app.getSearchUICore();
    searchUICore = searchHelper.getCore();
    if (newSearch) {
        setResultCollection(null);
        if (!phraseDefined) {
            searchUICore.resetPhrase();
        }
        phraseDefined = false;
    }
    location = app.getLocationProvider().getLastKnownLocation();
    LatLon searchLatLon;
    if (centerLatLon == null) {
        LatLon clt = mainActivity.getScreenCenter();
        searchLatLon = clt;
        searchEditText.setHint(app.getString("search_poi_category_hint"));
        if (location != null) {
            double d = MapUtils.getDistance(clt, location.getLatitude(), location.getLongitude());
            if (d < DISTANCE_THRESHOLD) {
                searchLatLon = new LatLon(location.getLatitude(), location.getLongitude());
            } else {
                useMapCenter = true;
            }
        } else {
            useMapCenter = true;
        }
    } else {
        searchLatLon = centerLatLon;
        useMapCenter = true;
    }
    SearchSettings settings = searchUICore.getSearchSettings().setOriginalLocation(new LatLon(searchLatLon.getLatitude(), searchLatLon.getLongitude()));
    settings = settings.setLang(locale, transliterate);
    searchUICore.updateSettings(settings);
    searchUICore.setOnSearchStart(new Runnable() {

        @Override
        public void run() {
            cancelPrev = false;
        }
    });
    searchUICore.setOnResultsComplete(new Runnable() {

        @Override
        public void run() {
            app.runInUIThread(new Runnable() {

                @Override
                public void run() {
                    searching = false;
                    if (!paused && !cancelPrev) {
                        hideProgressBar();
                        if (searchUICore.isSearchMoreAvailable(searchUICore.getPhrase())) {
                            addMoreButton();
                        }
                    }
                }
            });
        }
    });
}
Also used : LatLon(net.osmand.data.LatLon) SearchSettings(net.osmand.search.core.SearchSettings)

Example 18 with SearchSettings

use of net.osmand.search.core.SearchSettings in project Osmand by osmandapp.

the class QuickSearchDialogFragment method runSearch.

private void runSearch(String text) {
    showProgressBar();
    SearchSettings settings = searchUICore.getPhrase().getSettings();
    if (settings.getRadiusLevel() != 1) {
        searchUICore.updateSettings(settings.setRadiusLevel(1));
    }
    runCoreSearch(text, true, false);
}
Also used : SearchSettings(net.osmand.search.core.SearchSettings)

Example 19 with SearchSettings

use of net.osmand.search.core.SearchSettings in project Osmand by osmandapp.

the class QuickSearchDialogFragment method startNearestCitySearch.

private void startNearestCitySearch() {
    SearchSettings settings = searchUICore.getSearchSettings().setEmptyQueryAllowed(true).setSortByName(false).setSearchTypes(ObjectType.CITY).setRadiusLevel(1);
    searchUICore.updateSettings(settings);
}
Also used : SearchSettings(net.osmand.search.core.SearchSettings)

Example 20 with SearchSettings

use of net.osmand.search.core.SearchSettings in project Osmand by osmandapp.

the class QuickSearchDialogFragment method addMoreButton.

private void addMoreButton(boolean searchMoreAvailable) {
    if (!paused && !cancelPrev && mainSearchFragment != null && !isTextEmpty()) {
        QuickSearchMoreListItem moreListItem = new QuickSearchMoreListItem(app, null, new SearchMoreItemOnClickListener() {

            @Override
            public void increaseRadiusOnClick() {
                if (!interruptedSearch) {
                    SearchSettings settings = searchUICore.getSearchSettings();
                    searchUICore.updateSettings(settings.setRadiusLevel(settings.getRadiusLevel() + 1));
                }
                runCoreSearch(searchQuery, false, true);
            }

            @Override
            public void onlineSearchOnClick() {
                startOnlineSearch();
                mainSearchFragment.getAdapter().clear();
                updateTabbarVisibility(false);
                runCoreSearch(searchQuery, false, true);
            }
        });
        moreListItem.setInterruptedSearch(interruptedSearch);
        moreListItem.setEmptySearch(isResultEmpty());
        moreListItem.setOnlineSearch(isOnlineSearch());
        moreListItem.setSearchMoreAvailable(searchMoreAvailable);
        mainSearchFragment.addListItem(moreListItem);
    }
}
Also used : QuickSearchMoreListItem(net.osmand.plus.search.listitems.QuickSearchMoreListItem) SearchMoreItemOnClickListener(net.osmand.plus.search.listitems.QuickSearchMoreListItem.SearchMoreItemOnClickListener) SearchSettings(net.osmand.search.core.SearchSettings)

Aggregations

SearchSettings (net.osmand.search.core.SearchSettings)24 LatLon (net.osmand.data.LatLon)11 SearchResult (net.osmand.search.core.SearchResult)7 SearchResultCollection (net.osmand.search.SearchUICore.SearchResultCollection)6 SearchPhrase (net.osmand.search.core.SearchPhrase)6 ArrayList (java.util.ArrayList)4 SpannableString (android.text.SpannableString)3 SearchWord (net.osmand.search.core.SearchWord)3 SuppressLint (android.annotation.SuppressLint)2 Bundle (android.os.Bundle)2 Editable (android.text.Editable)2 TextWatcher (android.text.TextWatcher)2 View (android.view.View)2 OnClickListener (android.view.View.OnClickListener)2 ImageView (android.widget.ImageView)2 TextView (android.widget.TextView)2 Point (java.awt.Point)2 ActionEvent (java.awt.event.ActionEvent)2 ActionListener (java.awt.event.ActionListener)2 Test (org.junit.Test)2