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());
}
}
}
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;
}
}
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));
}
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));
}
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));
}
Aggregations