Formatting
This commit is contained in:
parent
a1c826aa79
commit
3239853be9
1 changed files with 32 additions and 33 deletions
|
@ -61,8 +61,8 @@ public class SearchCityByNameActivity extends SearchByNameAbstractActivity<City>
|
|||
});
|
||||
getListView().addFooterView(ll);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
protected Comparator<? super City> createComparator() {
|
||||
final StringMatcherMode startsWith = CollatorStringMatcher.StringMatcherMode.CHECK_ONLY_STARTS_WITH;
|
||||
|
@ -71,34 +71,34 @@ public class SearchCityByNameActivity extends SearchByNameAbstractActivity<City>
|
|||
|
||||
@Override
|
||||
public AsyncTask<Object, ?, ?> getInitializeTask() {
|
||||
return new AsyncTask<Object, City, List<City>>(){
|
||||
return new AsyncTask<Object, City, List<City>>() {
|
||||
@Override
|
||||
protected void onPostExecute(List<City> 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<City> 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<City>() {
|
||||
|
||||
|
||||
@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<City>
|
|||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void filterLoop(String query, Collection<City> 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<City>() {
|
||||
|
@ -139,9 +139,9 @@ public class SearchCityByNameActivity extends SearchByNameAbstractActivity<City>
|
|||
}
|
||||
|
||||
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<City>
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@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<City>
|
|||
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<City>
|
|||
private final class CityComparator implements Comparator<City> {
|
||||
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<City>
|
|||
@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<City>
|
|||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue