Search in sources :

Example 6 with SearchResultCollection

use of net.osmand.search.SearchUICore.SearchResultCollection in project Osmand by osmandapp.

the class QuickSearchDialogFragment method reloadHistoryInternal.

private void reloadHistoryInternal() {
    if (historySearchFragment != null) {
        try {
            SearchResultCollection res = searchUICore.shallowSearch(SearchHistoryAPI.class, "", null);
            List<QuickSearchListItem> rows = new ArrayList<>();
            if (res != null) {
                for (SearchResult sr : res.getCurrentSearchResults()) {
                    rows.add(new QuickSearchListItem(app, sr));
                }
            }
            historySearchFragment.updateListAdapter(rows, false);
        } catch (Exception e) {
            e.printStackTrace();
            app.showToastMessage(e.getMessage());
        }
    }
}
Also used : ArrayList(java.util.ArrayList) SearchResultCollection(net.osmand.search.SearchUICore.SearchResultCollection) QuickSearchListItem(net.osmand.plus.search.listitems.QuickSearchListItem) SearchResult(net.osmand.search.core.SearchResult) IOException(java.io.IOException)

Example 7 with SearchResultCollection

use of net.osmand.search.SearchUICore.SearchResultCollection in project Osmand by osmandapp.

the class QuickSearchDialogFragment method setupSearch.

private void setupSearch(final MapActivity mapActivity) {
    // Setup search core
    String locale = app.getSettings().MAP_PREFERRED_LOCALE.get();
    boolean transliterate = app.getSettings().MAP_TRANSLITERATE_NAMES.get();
    searchHelper = app.getSearchUICore();
    searchUICore = searchHelper.getCore();
    defaultResultListener = new SearchResultListener() {

        @Override
        public void publish(SearchResultCollection res, boolean append) {
            updateSearchResult(res, append);
        }

        @Override
        public void searchStarted(SearchPhrase phrase) {
        }

        @Override
        public boolean searchFinished(SearchPhrase phrase) {
            return true;
        }
    };
    stopAddressSearch();
    location = app.getLocationProvider().getLastKnownLocation();
    LatLon searchLatLon;
    if (centerLatLon == null) {
        LatLon clt = mapActivity.getMapView().getCurrentRotatedTileBox().getCenterLatLon();
        searchLatLon = clt;
        searchEditText.setHint(R.string.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);
    if (newSearch) {
        setResultCollection(null);
        if (!phraseDefined) {
            searchUICore.resetPhrase();
        }
        phraseDefined = false;
    }
}
Also used : LatLon(net.osmand.data.LatLon) SearchResultCollection(net.osmand.search.SearchUICore.SearchResultCollection) SearchSettings(net.osmand.search.core.SearchSettings) SpannableString(android.text.SpannableString) SearchPhrase(net.osmand.search.core.SearchPhrase)

Example 8 with SearchResultCollection

use of net.osmand.search.SearchUICore.SearchResultCollection in project Osmand by osmandapp.

the class SearchCoreUITest method testNoResortDuplicate.

@Test
public void testNoResortDuplicate() 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);
    SearchResult b2 = searchResult(rs, phrase, "b", 200);
    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(b1, cll.getCurrentSearchResults().get(1));
    Assert.assertSame(b2, 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 9 with SearchResultCollection

use of net.osmand.search.SearchUICore.SearchResultCollection in project Osmand by osmandapp.

the class SearchCoreUITest method testDuplicates.

@Test
public void testDuplicates() 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);
    SearchResult b2 = searchResult(rs, phrase, "b", 200);
    SearchResult b1 = searchResult(rs, phrase, "b", 100);
    /*SearchResult a3 = */
    searchResult(rs, phrase, "a", 100);
    cll.addSearchResults(rs, true, true);
    Assert.assertEquals(3, cll.getCurrentSearchResults().size());
    Assert.assertSame(a1, cll.getCurrentSearchResults().get(0));
    Assert.assertSame(b1, cll.getCurrentSearchResults().get(1));
    Assert.assertSame(b2, 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 10 with SearchResultCollection

use of net.osmand.search.SearchUICore.SearchResultCollection 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)

Aggregations

SearchResultCollection (net.osmand.search.SearchUICore.SearchResultCollection)11 SearchResult (net.osmand.search.core.SearchResult)9 ArrayList (java.util.ArrayList)8 LatLon (net.osmand.data.LatLon)7 SearchPhrase (net.osmand.search.core.SearchPhrase)6 SearchSettings (net.osmand.search.core.SearchSettings)6 IOException (java.io.IOException)3 QuickSearchListItem (net.osmand.plus.search.listitems.QuickSearchListItem)3 Test (org.junit.Test)3 SpannableString (android.text.SpannableString)2 View (android.view.View)2 OnClickListener (android.view.View.OnClickListener)2 AdapterView (android.widget.AdapterView)2 ImageView (android.widget.ImageView)2 ListView (android.widget.ListView)2 TextView (android.widget.TextView)2 Point (java.awt.Point)2 ActionEvent (java.awt.event.ActionEvent)2 ActionListener (java.awt.event.ActionListener)2 List (java.util.List)2