Sort cities list
This commit is contained in:
parent
75211b4f19
commit
b5598d3454
3 changed files with 65 additions and 21 deletions
|
@ -17,7 +17,7 @@ public class CollatorStringMatcher implements StringMatcher {
|
|||
private final StringMatcherMode mode;
|
||||
private final String part;
|
||||
|
||||
public enum StringMatcherMode {
|
||||
public static enum StringMatcherMode {
|
||||
CHECK_ONLY_STARTS_WITH,
|
||||
CHECK_STARTS_FROM_SPACE,
|
||||
CHECK_STARTS_FROM_SPACE_NOT_BEGINNING,
|
||||
|
|
|
@ -48,7 +48,7 @@ public class BinaryInspector {
|
|||
// test cases show info
|
||||
|
||||
|
||||
// inspector(new String[]{"-vmap", /*"-bbox=-121.785,37.35,-121.744,37.33", */"/home/victor/projects/OsmAnd/data/osm-gen/Map.obf"});
|
||||
// inspector(new String[]{"-vaddress", /*"-bbox=-121.785,37.35,-121.744,37.33", */"/home/victor/projects/OsmAnd/temp/.obf"});
|
||||
// test case extract parts
|
||||
// test case
|
||||
}
|
||||
|
@ -439,30 +439,30 @@ public class BinaryInspector {
|
|||
for (int j = 0; j < cityType.length; j++) {
|
||||
int type = cityType[j];
|
||||
for (City c : index.getCities(region, null, type)) {
|
||||
println("\t\t" + c + " " + c.getId() + " (" + c.getStreets().size() + ")");
|
||||
index.preloadStreets(c, null);
|
||||
println("\t\t" + c + getId(c) + "("+c.getStreets().size()+")");
|
||||
for (Street t : c.getStreets()) {
|
||||
if (verbose.contains(t)) {
|
||||
index.preloadBuildings(t, null);
|
||||
print("\t\t\t" + t.getName() + getId(t) + "("+t.getBuildings().size()+")");
|
||||
// if (type == BinaryMapAddressReaderAdapter.CITY_TOWN_TYPE) {
|
||||
List<Building> buildings = t.getBuildings();
|
||||
if (buildings != null && !buildings.isEmpty()) {
|
||||
print("\t\t (");
|
||||
for (Building b : buildings) {
|
||||
print(b.toString() + ",");
|
||||
}
|
||||
print(")");
|
||||
print("\t\t\t" + t.getName() + getId(t) + " (" + t.getBuildings().size() + ")");
|
||||
// if (type == BinaryMapAddressReaderAdapter.CITY_TOWN_TYPE) {
|
||||
List<Building> buildings = t.getBuildings();
|
||||
if (buildings != null && !buildings.isEmpty()) {
|
||||
print("\t\t (");
|
||||
for (Building b : buildings) {
|
||||
print(b.toString() + ",");
|
||||
}
|
||||
List<Street> streets = t.getIntersectedStreets();
|
||||
if (streets != null && !streets.isEmpty()) {
|
||||
print("\n\t\t\t\t\t\t\t x (");
|
||||
for (Street s : streets) {
|
||||
print(s.getName() +", ");
|
||||
}
|
||||
print(")");
|
||||
print(")");
|
||||
}
|
||||
List<Street> streets = t.getIntersectedStreets();
|
||||
if (streets != null && !streets.isEmpty()) {
|
||||
print("\n\t\t\t\t\t\t\t x (");
|
||||
for (Street s : streets) {
|
||||
print(s.getName() + ", ");
|
||||
}
|
||||
// }
|
||||
print(")");
|
||||
}
|
||||
// }
|
||||
println("");
|
||||
}
|
||||
|
||||
|
|
|
@ -1,10 +1,16 @@
|
|||
package net.osmand.plus.activities.search;
|
||||
|
||||
import java.text.Collator;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
import net.osmand.CollatorStringMatcher;
|
||||
import net.osmand.CollatorStringMatcher.StringMatcherMode;
|
||||
import net.osmand.OsmAndFormatter;
|
||||
import net.osmand.ResultMatcher;
|
||||
import net.osmand.data.City;
|
||||
import net.osmand.data.City.CityType;
|
||||
import net.osmand.osm.LatLon;
|
||||
import net.osmand.osm.MapUtils;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
|
@ -26,6 +32,44 @@ public class SearchCityByNameActivity extends SearchByNameAbstractActivity<City>
|
|||
protected void onPostExecute(List<City> result) {
|
||||
((TextView)findViewById(R.id.Label)).setText(R.string.incremental_search_city);
|
||||
progress.setVisibility(View.INVISIBLE);
|
||||
final Collator cs = Collator.getInstance();
|
||||
final boolean en = region.useEnglishNames();
|
||||
final String part = getFilter().toString();
|
||||
final StringMatcherMode startsWith = CollatorStringMatcher.StringMatcherMode.CHECK_ONLY_STARTS_WITH;
|
||||
Collections.sort(result, new Comparator<City>() {
|
||||
@Override
|
||||
public int compare(City lhs, City rhs) {
|
||||
int compare = compareCityType(lhs, rhs);
|
||||
if (compare != 0) {
|
||||
return compare;
|
||||
}
|
||||
boolean st1 = CollatorStringMatcher.cmatches(cs, lhs.getName(en), part, startsWith);
|
||||
boolean st2 = CollatorStringMatcher.cmatches(cs, rhs.getName(en), part, startsWith);
|
||||
if(st1 != st2) {
|
||||
return st1 ? 1 : -1;
|
||||
}
|
||||
compare = cs.compare(lhs.getName(en), rhs.getName(en));
|
||||
if (compare != 0) {
|
||||
return compare;
|
||||
}
|
||||
if (locationToSearch != null) {
|
||||
double d1 = MapUtils.getDistance(locationToSearch, lhs.getLocation());
|
||||
double d2 = MapUtils.getDistance(locationToSearch, rhs.getLocation());
|
||||
return -Double.compare(d1, d2);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
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){
|
||||
return 0;
|
||||
}
|
||||
return c1? 1 : -1;
|
||||
}
|
||||
});
|
||||
|
||||
finishInitializing(result);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue