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