diff --git a/OsmAnd/src/net/osmand/plus/activities/search/SearchCityByNameActivity.java b/OsmAnd/src/net/osmand/plus/activities/search/SearchCityByNameActivity.java index 356960e4b0..37ebb68a4c 100644 --- a/OsmAnd/src/net/osmand/plus/activities/search/SearchCityByNameActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/search/SearchCityByNameActivity.java @@ -61,8 +61,8 @@ public class SearchCityByNameActivity extends SearchByNameAbstractActivity }); getListView().addFooterView(ll); } - - + + @Override protected Comparator createComparator() { final StringMatcherMode startsWith = CollatorStringMatcher.StringMatcherMode.CHECK_ONLY_STARTS_WITH; @@ -71,34 +71,34 @@ public class SearchCityByNameActivity extends SearchByNameAbstractActivity @Override public AsyncTask getInitializeTask() { - return new AsyncTask>(){ + return new AsyncTask>() { @Override protected void onPostExecute(List result) { setLabelText(R.string.incremental_search_city); progress.setVisibility(View.INVISIBLE); finishInitializing(result); } - + @Override protected void onPreExecute() { setLabelText(R.string.loading_cities); progress.setVisibility(View.VISIBLE); } - - + + @Override protected List doInBackground(Object... params) { - region = ((OsmandApplication)getApplication()).getResourceManager().getRegionRepository(settings.getLastSearchedRegion()); - if(region != null){ + region = ((OsmandApplication) getApplication()).getResourceManager().getRegionRepository(settings.getLastSearchedRegion()); + if (region != null) { // preload cities region.preloadCities(new ResultMatcher() { - + @Override public boolean publish(City object) { addObjectToInitialList(object); return true; } - + @Override public boolean isCancelled() { return false; @@ -110,11 +110,11 @@ public class SearchCityByNameActivity extends SearchByNameAbstractActivity } }; } - + @Override protected void filterLoop(String query, Collection list) { redefineSearchVillagesMode(query.length()); - if(!initializeTaskIsFinished() || (query.length() <= 3 && !searchVillages())){ + if (!initializeTaskIsFinished() || (query.length() <= 3 && !searchVillages())) { super.filterLoop(query, list); } else { region.fillWithSuggestedCities(query, new ResultMatcher() { @@ -139,9 +139,9 @@ public class SearchCityByNameActivity extends SearchByNameAbstractActivity } private void redefineSearchVillagesMode(int queryLen) { - if(searchVillagesMode == 1) { + if (searchVillagesMode == 1) { searchVillagesMode = 0; - } else if(searchVillagesMode == 0 && queryLen <= 3) { + } else if (searchVillagesMode == 0 && queryLen <= 3) { searchVillagesMode = -1; uiHandler.post(new Runnable() { @Override @@ -152,17 +152,17 @@ public class SearchCityByNameActivity extends SearchByNameAbstractActivity } } - + @Override public String getText(City obj) { LatLon l = obj.getLocation(); - if (getCurrentFilter().length() > 2 ) { + if (getCurrentFilter().length() > 2) { String name = getShortText(obj); - if(obj.getClosestCity() != null) { - name += " - " + obj.getClosestCity().getName(region.getLang()) ; + if (obj.getClosestCity() != null) { + name += " - " + obj.getClosestCity().getName(region.getLang()); LatLon loc = obj.getClosestCity().getLocation(); - if(loc != null && l != null) { - name += " " + OsmAndFormatter.getFormattedDistance((int) MapUtils.getDistance(l, loc), getMyApplication()); + if (loc != null && l != null) { + name += " " + OsmAndFormatter.getFormattedDistance((int) MapUtils.getDistance(l, loc), getMyApplication()); } return name; } else { @@ -175,17 +175,17 @@ public class SearchCityByNameActivity extends SearchByNameAbstractActivity return getShortText(obj); } } - + @Override public String getShortText(City obj) { String lName = obj.getName(region.getLang()); String name = obj.getName(); - if(!lName.equals(name)) { + if (!lName.equals(name)) { return lName + " / " + name; } return lName; } - + @Override public void itemSelected(City obj) { settings.setLastSearchedCity(obj.getId(), obj.getName(region.getLang()), obj.getLocation()); @@ -203,10 +203,9 @@ public class SearchCityByNameActivity extends SearchByNameAbstractActivity private final class CityComparator implements Comparator { private final StringMatcherMode startsWith; private final net.osmand.Collator cs; - private final String lang ; + private final String lang; - private CityComparator(StringMatcherMode startsWith, - String lang ) { + private CityComparator(StringMatcherMode startsWith, String lang) { this.startsWith = startsWith; this.cs = OsmAndCollator.primaryCollator(); this.lang = lang; @@ -215,16 +214,16 @@ public class SearchCityByNameActivity extends SearchByNameAbstractActivity @Override public int compare(City lhs, City rhs) { final String part = getFilter().toString(); - + int compare = compareCityType(lhs, rhs); if (compare != 0) { return compare; } boolean st1 = CollatorStringMatcher.cmatches(cs, lhs.getName(lang), part, startsWith); boolean st2 = CollatorStringMatcher.cmatches(cs, rhs.getName(lang), part, startsWith); - if(st1 != st2) { - return st1 ? 1 : -1; - } + if (st1 != st2) { + return st1 ? 1 : -1; + } compare = cs.compare(getText(lhs), getText(rhs)); if (compare != 0) { return compare; @@ -240,12 +239,12 @@ public class SearchCityByNameActivity extends SearchByNameAbstractActivity private int compareCityType(City lhs, City rhs) { boolean c1 = lhs.getType() == CityType.CITY || lhs.getType() == CityType.TOWN; boolean c2 = rhs.getType() == CityType.CITY || rhs.getType() == CityType.TOWN; - if(c1 == c2){ + if (c1 == c2) { return 0; } - return c1? 1 : -1; + return c1 ? 1 : -1; } } - + }