Fix compilation errors

This commit is contained in:
Victor Shcherb 2012-03-19 01:47:01 +01:00
parent 041ba66d05
commit 8d5d72f80e
12 changed files with 141 additions and 246 deletions

View file

@ -17,8 +17,15 @@ public class ToDoConstants {
// Polish UI with new builiding address search ...(Better completely new address search)
// TO try & to test
// Test images in the map // Test images in the map
// Test new POI categories, dynamic POI text in ...
// Test rendering of 2 dimensional values
// Polish UI with new builiding address search ...(Better completely new address search)
// Search for city in all indexes
// Test GeoIndexActivity
// == Osmand application (TODO 127) == // == Osmand application (TODO 127) ==

View file

@ -505,7 +505,7 @@ public class BinaryMapAddressReaderAdapter {
LatLon l = obj.getLocation(); LatLon l = obj.getLocation();
Street s = new Street(obj); Street s = new Street(obj);
readStreet(s, null, false, MapUtils.get31TileNumberX(l.getLatitude()) >> 7, readStreet(s, null, false, MapUtils.get31TileNumberX(l.getLatitude()) >> 7,
MapUtils.get31TileNumberY(l.getLongitude()) >> 7, null); MapUtils.get31TileNumberY(l.getLongitude()) >> 7, obj.isPostcode() ? obj.getName() : null);
if (matcher.matches(s.getName())) { if (matcher.matches(s.getName())) {
req.publish(s); req.publish(s);

View file

@ -23,6 +23,7 @@ import net.osmand.Algoritms;
import net.osmand.CollatorStringMatcher; import net.osmand.CollatorStringMatcher;
import net.osmand.LogUtil; import net.osmand.LogUtil;
import net.osmand.ResultMatcher; import net.osmand.ResultMatcher;
import net.osmand.StringMatcher;
import net.osmand.CollatorStringMatcher.StringMatcherMode; import net.osmand.CollatorStringMatcher.StringMatcherMode;
import net.osmand.binary.BinaryMapAddressReaderAdapter.AddressRegion; import net.osmand.binary.BinaryMapAddressReaderAdapter.AddressRegion;
import net.osmand.binary.BinaryMapAddressReaderAdapter.CitiesBlock; import net.osmand.binary.BinaryMapAddressReaderAdapter.CitiesBlock;
@ -466,16 +467,19 @@ public class BinaryMapIndexReader {
throw new IllegalArgumentException(name); throw new IllegalArgumentException(name);
} }
public List<City> getCities(String region, SearchRequest<City> resultMatcher, public List<City> getCities(String region, SearchRequest<City> resultMatcher,
int cityType) throws IOException { int cityType) throws IOException {
return getCities(region, resultMatcher, null, false, cityType);
}
public List<City> getCities(String region, SearchRequest<City> resultMatcher, StringMatcher matcher, boolean useEn,
int cityType) throws IOException {
List<City> cities = new ArrayList<City>(); List<City> cities = new ArrayList<City>();
AddressRegion r = getRegionByName(region); AddressRegion r = getRegionByName(region);
for(CitiesBlock block : r.cities) { for(CitiesBlock block : r.cities) {
if(block.type == cityType) { if(block.type == cityType) {
codedIS.seek(block.filePointer); codedIS.seek(block.filePointer);
int old = codedIS.pushLimit(block.length); int old = codedIS.pushLimit(block.length);
addressAdapter.readCities(cities, resultMatcher, null, false); addressAdapter.readCities(cities, resultMatcher, matcher, useEn);
codedIS.popLimit(old); codedIS.popLimit(old);
} }
} }
@ -510,7 +514,8 @@ public class BinaryMapIndexReader {
codedIS.seek(s.getFileOffset()); codedIS.seek(s.getFileOffset());
int size = codedIS.readRawVarint32(); int size = codedIS.readRawVarint32();
int old = codedIS.pushLimit(size); int old = codedIS.pushLimit(size);
addressAdapter.readStreet(s, resultMatcher, true, 0, 0, null); City city = s.getCity();
addressAdapter.readStreet(s, resultMatcher, true, 0, 0, city != null && city.isPostcode() ? city.getName() : null);
codedIS.popLimit(old); codedIS.popLimit(old);
} }
@ -1164,6 +1169,8 @@ public class BinaryMapIndexReader {
return request; return request;
} }
public static <T> SearchRequest<T> buildAddressByNameRequest(ResultMatcher<T> resultMatcher, String nameRequest){ public static <T> SearchRequest<T> buildAddressByNameRequest(ResultMatcher<T> resultMatcher, String nameRequest){
SearchRequest<T> request = new SearchRequest<T>(); SearchRequest<T> request = new SearchRequest<T>();
request.resultMatcher = resultMatcher; request.resultMatcher = resultMatcher;

View file

@ -14,6 +14,8 @@ import net.osmand.osm.OSMSettings.OSMTagKey;
public class City extends MapObject { public class City extends MapObject {
private static long POSTCODE_INTERNAL_ID = -1000;
public enum CityType { public enum CityType {
// that's tricky way to play with that numbers (to avoid including suburbs in city & vice verse) // that's tricky way to play with that numbers (to avoid including suburbs in city & vice verse)
CITY(10000), TOWN(5000), VILLAGE(1300), HAMLET(1000), SUBURB(400); CITY(10000), TOWN(5000), VILLAGE(1300), HAMLET(1000), SUBURB(400);
@ -65,13 +67,14 @@ public class City extends MapObject {
this.type = type; this.type = type;
} }
private City(String postcode) { private City(String postcode, long id) {
this.type = null; this.type = null;
this.name = this.enName = postcode; this.name = this.enName = postcode;
this.id = id;
} }
public static City createPostcode(String postcode){ public static City createPostcode(String postcode){
return new City(postcode); return new City(postcode, POSTCODE_INTERNAL_ID--);
} }

View file

@ -81,7 +81,7 @@ public class IndexCreator {
private OsmDbAccessor accessor; private OsmDbAccessor accessor;
// constants to start process from the middle and save temporary results // constants to start process from the middle and save temporary results
private boolean recreateOnlyBinaryFile = false; // false; private boolean recreateOnlyBinaryFile = false; // false;
private boolean deleteOsmDB = false; private boolean deleteOsmDB = true;
private boolean deleteDatabaseIndexes = true; private boolean deleteDatabaseIndexes = true;
private Object dbConn; private Object dbConn;

View file

@ -38,27 +38,23 @@ public interface RegionAddressRepository {
public void preloadStreets(City o, ResultMatcher<Street> resultMatcher); public void preloadStreets(City o, ResultMatcher<Street> resultMatcher);
public List<MapObject> getLoadedCities(); public List<City> getLoadedCities();
public City getPostcode(String name); // Returns city or postcode (if id < 0)
public City getCityById(long id, String name);
public City getCityById(Long id);
public Street getStreetByName(City cityOrPostcode, String name); public Street getStreetByName(City cityOrPostcode, String name);
public Building getBuildingByName(Street street, String name); public Building getBuildingByName(Street street, String name);
public List<Street> getStreetsIntersectStreets(City city, Street st); public List<Street> getStreetsIntersectStreets(Street st);
void addCityToPreloadedList(City city); void addCityToPreloadedList(City city);
public LatLon findStreetIntersection(Street street, Street street2);
// TODO remove that method
public List<Street> fillWithSuggestedStreets(City o, ResultMatcher<Street> resultMatcher, String... names);
public List<City> fillWithSuggestedCities(String name, ResultMatcher<City> resultMatcher, LatLon currentLocation); public List<City> fillWithSuggestedCities(String name, ResultMatcher<City> resultMatcher, LatLon currentLocation);
public List<MapObject> searchMapObjectsByName(String name, ResultMatcher<MapObject> resultMatcher);
public static class MapObjectNameDistanceComparator implements Comparator<MapObject> { public static class MapObjectNameDistanceComparator implements Comparator<MapObject> {

View file

@ -17,6 +17,7 @@ import net.osmand.LogUtil;
import net.osmand.ResultMatcher; import net.osmand.ResultMatcher;
import net.osmand.binary.BinaryMapAddressReaderAdapter; import net.osmand.binary.BinaryMapAddressReaderAdapter;
import net.osmand.binary.BinaryMapIndexReader; import net.osmand.binary.BinaryMapIndexReader;
import net.osmand.binary.BinaryMapIndexReader.SearchRequest;
import net.osmand.data.Building; import net.osmand.data.Building;
import net.osmand.data.City; import net.osmand.data.City;
import net.osmand.data.MapObject; import net.osmand.data.MapObject;
@ -84,8 +85,8 @@ public class RegionAddressRepositoryBinary implements RegionAddressRepository {
} }
@Override @Override
public synchronized List<MapObject> getLoadedCities(){ public synchronized List<City> getLoadedCities(){
return new ArrayList<MapObject>(cities.values()); return new ArrayList<City>(cities.values());
} }
@Override @Override
@ -108,35 +109,17 @@ public class RegionAddressRepositoryBinary implements RegionAddressRepository {
StringMatcherMode.CHECK_STARTS_FROM_SPACE_NOT_BEGINNING}; StringMatcherMode.CHECK_STARTS_FROM_SPACE_NOT_BEGINNING};
@Override @Override
public List<Street> fillWithSuggestedStreets(City o, ResultMatcher<Street> resultMatcher, String... names) { public List<MapObject> searchMapObjectsByName(String name, ResultMatcher<MapObject> resultMatcher) {
List<Street> streetsToFill = new ArrayList<Street>(); SearchRequest<MapObject> req = BinaryMapIndexReader.buildAddressByNameRequest(resultMatcher, name);
if(names.length == 0){ try {
preloadStreets(o, resultMatcher); file.searchAddressDataByName(req);
streetsToFill.addAll(o.getStreets()); } catch (IOException e) {
return streetsToFill; log.error("Disk operation failed", e); //$NON-NLS-1$
} }
preloadStreets(o, null); return req.getSearchResults();
Collection<Street> streets =o.getStreets();
// 1st step loading by starts with
for (StringMatcherMode mode : streetsCheckMode) {
for (Street s : streets) {
if (resultMatcher.isCancelled()) {
return streetsToFill;
}
String sName = s.getName(useEnglishNames); // lower case not needed, collator ensures that
for (String name : names) {
boolean match = CollatorStringMatcher.cmatches(collator, sName, name, mode);
if (match) {
resultMatcher.publish(s);
streetsToFill.add(s);
}
}
}
}
return streetsToFill;
} }
@ -160,7 +143,7 @@ public class RegionAddressRepositoryBinary implements RegionAddressRepository {
// also try to identify postcodes // also try to identify postcodes
String uName = name.toUpperCase(); String uName = name.toUpperCase();
for (City code : file.getCities(region, BinaryMapIndexReader.buildAddressRequest(resultMatcher), for (City code : file.getCities(region, BinaryMapIndexReader.buildAddressRequest(resultMatcher),
new CollatorStringMatcher(collator, uName, StringMatcherMode.CHECK_CONTAINS), new CollatorStringMatcher(collator, uName, StringMatcherMode.CHECK_CONTAINS), false,
BinaryMapAddressReaderAdapter.POSTCODES_TYPE)) { BinaryMapAddressReaderAdapter.POSTCODES_TYPE)) {
citiesToFill.add(code); citiesToFill.add(code);
if (resultMatcher.isCancelled()) { if (resultMatcher.isCancelled()) {
@ -184,8 +167,9 @@ public class RegionAddressRepositoryBinary implements RegionAddressRepository {
int initialsize = citiesToFill.size(); int initialsize = citiesToFill.size();
if (name.length() >= 3) { if (name.length() >= 3) {
for (City c : file.getVillages(region, BinaryMapIndexReader.buildAddressRequest(resultMatcher), for (City c : file.getCities(region, BinaryMapIndexReader.buildAddressRequest(resultMatcher),
new CollatorStringMatcher(collator, name,StringMatcherMode.CHECK_STARTS_FROM_SPACE), useEnglishNames)) { new CollatorStringMatcher(collator, name,StringMatcherMode.CHECK_STARTS_FROM_SPACE), useEnglishNames,
BinaryMapAddressReaderAdapter.VILLAGES_TYPE)) {
citiesToFill.add(c); citiesToFill.add(c);
if (resultMatcher.isCancelled()) { if (resultMatcher.isCancelled()) {
return citiesToFill; return citiesToFill;
@ -200,32 +184,9 @@ public class RegionAddressRepositoryBinary implements RegionAddressRepository {
} }
@Override @Override
public List<Street> getStreetsIntersectStreets(City city, Street st) { public List<Street> getStreetsIntersectStreets(Street st) {
List<Street> streetsToFill = new ArrayList<Street>(); preloadBuildings(st, null);
if(city != null){ return st.getIntersectedStreets();
preloadStreets(city, null);
try {
file.findIntersectedStreets(city, st, streetsToFill);
} catch (IOException e) {
log.error("Disk operation failed" , e); //$NON-NLS-1$
}
}
return streetsToFill;
}
@Override
public LatLon findStreetIntersection(Street street, Street street2) {
City city = street.getCity();
if(city != null){
preloadStreets(city, null);
try {
return file.findStreetIntersection(city, street, street2);
} catch (IOException e) {
log.error("Disk operation failed" , e); //$NON-NLS-1$
}
}
return null;
} }
@ -257,30 +218,40 @@ public class RegionAddressRepositoryBinary implements RegionAddressRepository {
} }
@Override @Override
public City getCityById(final Long id) { public City getCityById(final long id, String name) {
if (id == -1) { if (id == -1) {
// do not preload cities for that case // do not preload cities for that case
return null; return null;
} }
if(id < -1 && name != null){
name = name.toUpperCase();
}
final String cmpName = name;
preloadCities(null); preloadCities(null);
if (!cities.containsKey(id)) { if (!cities.containsKey(id)) {
try { try {
file.getVillages(region, BinaryMapIndexReader.buildAddressRequest(new ResultMatcher<MapObject>() { file.getCities(region, BinaryMapIndexReader.buildAddressRequest(new ResultMatcher<City>() {
boolean canceled = false; boolean canceled = false;
@Override @Override
public boolean isCancelled() { public boolean isCancelled() {
return canceled; return canceled;
} }
@Override @Override
public boolean publish(MapObject object) { public boolean publish(City object) {
if (object.getId().longValue() == id.longValue()) { if(id < -1) {
if(object.getName().toUpperCase().equals(cmpName)) {
addCityToPreloadedList(object);
canceled = true;
}
} else if (object.getId().longValue() == id) {
addCityToPreloadedList((City) object); addCityToPreloadedList((City) object);
canceled = true; canceled = true;
} }
return false; return false;
} }
}), null, useEnglishNames); }), id < -1 ? BinaryMapAddressReaderAdapter.POSTCODES_TYPE : BinaryMapAddressReaderAdapter.VILLAGES_TYPE);
} catch (IOException e) { } catch (IOException e) {
log.error("Disk operation failed", e); //$NON-NLS-1$ log.error("Disk operation failed", e); //$NON-NLS-1$
} }
@ -289,32 +260,11 @@ public class RegionAddressRepositoryBinary implements RegionAddressRepository {
} }
@Override @Override
public PostCode getPostcode(String name) { public Street getStreetByName(City o, String name) {
if(name == null){
return null;
}
String uc = name.toUpperCase();
if(!postCodes.containsKey(uc)){
try {
postCodes.put(uc, file.getPostcodeByName(this.region, name));
} catch (IOException e) {
log.error("Disk operation failed", e); //$NON-NLS-1$
}
}
return postCodes.get(uc);
}
@Override
public Street getStreetByName(MapObject o, String name) {
assert o instanceof PostCode || o instanceof City;
City city = (City) (o instanceof City ? o : null);
PostCode post = (PostCode) (o instanceof PostCode ? o : null);
name = name.toLowerCase(); name = name.toLowerCase();
preloadStreets(o, null); preloadStreets(o, null);
Collection<Street> streets = post == null ? city.getStreets() : post.getStreets(); Collection<Street> streets = o.getStreets() ;
for (Street s : streets) { for (Street s : streets) {
String sName = useEnglishNames ? s.getEnName() : s.getName(); //lower case not needed, collator ensures that String sName = useEnglishNames ? s.getEnName() : s.getName(); //lower case not needed, collator ensures that
if (collator.equals(sName,name)) { if (collator.equals(sName,name)) {

View file

@ -1,20 +1,18 @@
package net.osmand.plus.activities.search; package net.osmand.plus.activities.search;
import gnu.trove.map.hash.TLongObjectHashMap;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer; import java.util.StringTokenizer;
import net.osmand.OsmAndFormatter; import net.osmand.OsmAndFormatter;
import net.osmand.access.AccessibleToast; import net.osmand.access.AccessibleToast;
import net.osmand.ResultMatcher;
import net.osmand.data.City; import net.osmand.data.City;
import net.osmand.data.MapObject; import net.osmand.data.MapObject;
import net.osmand.data.PostCode;
import net.osmand.data.Street; import net.osmand.data.Street;
import net.osmand.osm.LatLon; import net.osmand.osm.LatLon;
import net.osmand.osm.MapUtils; import net.osmand.osm.MapUtils;
@ -230,66 +228,41 @@ public class GeoIntentActivity extends OsmandListActivity {
} }
// search cities for found countries // search cities for found countries
Map<RegionAddressRepository, List<MapObject>> citiesForRegion = new HashMap<RegionAddressRepository, List<MapObject>>(); final List<MapObject> results = new ArrayList<MapObject>();
final List<MapObject> connectedStreets = new ArrayList<MapObject>();
for (RegionAddressRepository rar : countriesToSearch) { for (RegionAddressRepository rar : countriesToSearch) {
List<MapObject> citiesFound = new ArrayList<MapObject>(); final TLongObjectHashMap<City> cityIds = new TLongObjectHashMap<City>();
for (String maybeCity : elements) { for (String element : elements) {
citiesFound.addAll(rar.fillWithSuggestedCities(maybeCity, null, null)); rar.searchMapObjectsByName(element, new ResultMatcher<MapObject>() {
} @Override
if (!citiesFound.isEmpty()) { public boolean publish(MapObject object) {
citiesForRegion.put(rar, citiesFound); if (object instanceof City && object.getId() != null) {
cityIds.put(object.getId(), (City) object);
} else if(object instanceof Street) {
City c = ((Street)object).getCity();
if(c != null && c.getId() != null && cityIds.containsKey(c.getId().longValue())) {
connectedStreets.add((Street) object);
return false;
} }
} }
// no cities found, we should locate the country only results.add(object);
Map<MapObject, List<Street>> streetsForCity = new HashMap<MapObject, List<Street>>(); return false;
if (citiesForRegion.isEmpty()) {
for (RegionAddressRepository rar : countriesToSearch) {
List<MapObject> allcities = rar.fillWithSuggestedCities("", null, location);
findStreetsForCities(streetsForCity, rar, allcities);
} }
} else {
// we have cities, now search for streets? @Override
for (RegionAddressRepository rar : citiesForRegion.keySet()) { public boolean isCancelled() {
findStreetsForCities(streetsForCity, rar, return false;
citiesForRegion.get(rar)); }
});
} }
} }
// don't go deeper, now populate result list
Set<MapObject> results = new HashSet<MapObject>(); // add all other results to connected streets
// add all found lists connectedStreets.addAll(results);
for (List<Street> streets : streetsForCity.values()) { return connectedStreets;
results.addAll(streets);
}
// add all found cities for which street was not found
for (List<MapObject> cities : citiesForRegion.values()) {
cities.removeAll(streetsForCity.keySet());
results.addAll(cities);
}
// TODO add all regions for which city was not found
return results;
} }
private void findStreetsForCities(
Map<MapObject, List<Street>> streetsForCity,
RegionAddressRepository rar, List<MapObject> allcities) {
for (MapObject city : allcities) {
List<Street> streets = rar.fillWithSuggestedStreets(city, null,
elements.toArray(new String[] {}));
// we must do this, or we will fill up the whole memory (streets
// are preloaded...)
// TODO some street iterator would be better, is it possible to
// create one?
if (city instanceof City) {
((City) city).removeAllStreets();
} else if (city instanceof PostCode) {
((PostCode) city).removeAllStreets();
}
if (!streets.isEmpty()) {
streetsForCity.put(city, streets);
}
}
}
} }
@ -314,12 +287,11 @@ public class GeoIntentActivity extends OsmandListActivity {
lonIndex = lonIndex > 0 ? lonIndex : geo.length(); lonIndex = lonIndex > 0 ? lonIndex : geo.length();
if (latIndex > 0) { if (latIndex > 0) {
try { try {
double latitude = Double.parseDouble(geo.substring(0, double latitude = Double.parseDouble(geo.substring(0, latIndex));
latIndex)); double longitude = Double.parseDouble(geo.substring(latIndex + 1, lonIndex));
double longitude = Double.parseDouble(geo.substring(
latIndex + 1, lonIndex));
// TODO zoom is omited for now // TODO zoom is omited for now
point = new MapObject(new Node(latitude, longitude, -1)) { point = new MapObject(new Node(latitude, longitude, -1)) {
private static final long serialVersionUID = -7028586132795853725L;
}; };
point.setName("Lat: " + latitude + ",Lon:" + longitude); point.setName("Lat: " + latitude + ",Lon:" + longitude);
} catch (NumberFormatException e) { } catch (NumberFormatException e) {

View file

@ -5,7 +5,6 @@ import java.util.List;
import net.osmand.ResultMatcher; import net.osmand.ResultMatcher;
import net.osmand.data.Building; import net.osmand.data.Building;
import net.osmand.data.City; import net.osmand.data.City;
import net.osmand.data.PostCode;
import net.osmand.data.Street; import net.osmand.data.Street;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
@ -18,7 +17,6 @@ public class SearchBuildingByNameActivity extends SearchByNameAbstractActivity<B
private RegionAddressRepository region; private RegionAddressRepository region;
private City city; private City city;
private Street street; private Street street;
private PostCode postcode;
@Override @Override
public AsyncTask<Object, ?, ?> getInitializeTask() { public AsyncTask<Object, ?, ?> getInitializeTask() {
@ -39,14 +37,9 @@ public class SearchBuildingByNameActivity extends SearchByNameAbstractActivity<B
protected List<Building> doInBackground(Object... params) { protected List<Building> doInBackground(Object... params) {
region = ((OsmandApplication)getApplication()).getResourceManager().getRegionRepository(settings.getLastSearchedRegion()); region = ((OsmandApplication)getApplication()).getResourceManager().getRegionRepository(settings.getLastSearchedRegion());
if(region != null){ if(region != null){
postcode = region.getPostcode(settings.getLastSearchedPostcode()); city = region.getCityById(settings.getLastSearchedCity(), settings.getLastSearchedCityName());
city = region.getCityById(settings.getLastSearchedCity());
if(postcode != null){
street = region.getStreetByName(postcode, settings.getLastSearchedStreet());
} else if(city != null){
street = region.getStreetByName(city, settings.getLastSearchedStreet()); street = region.getStreetByName(city, settings.getLastSearchedStreet());
} }
}
if(street != null){ if(street != null){
// preload here to avoid concurrent modification // preload here to avoid concurrent modification
region.preloadBuildings(street, new ResultMatcher<Building>() { region.preloadBuildings(street, new ResultMatcher<Building>() {
@ -68,16 +61,6 @@ public class SearchBuildingByNameActivity extends SearchByNameAbstractActivity<B
}; };
} }
@Override
public boolean filterObject(Building obj, String filter) {
if (postcode != null && !postcode.getName().equalsIgnoreCase(obj.getPostcode())) {
return false;
}
return super.filterObject(obj, filter);
}
@Override @Override
public String getText(Building obj) { public String getText(Building obj) {
return obj.getName(region.useEnglishNames()); return obj.getName(region.useEnglishNames());

View file

@ -5,8 +5,6 @@ import java.util.List;
import net.osmand.OsmAndFormatter; import net.osmand.OsmAndFormatter;
import net.osmand.ResultMatcher; import net.osmand.ResultMatcher;
import net.osmand.data.City; import net.osmand.data.City;
import net.osmand.data.MapObject;
import net.osmand.data.PostCode;
import net.osmand.osm.LatLon; import net.osmand.osm.LatLon;
import net.osmand.osm.MapUtils; import net.osmand.osm.MapUtils;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
@ -17,15 +15,15 @@ import android.os.Message;
import android.view.View; import android.view.View;
import android.widget.TextView; import android.widget.TextView;
public class SearchCityByNameActivity extends SearchByNameAbstractActivity<MapObject> { public class SearchCityByNameActivity extends SearchByNameAbstractActivity<City> {
private RegionAddressRepository region; private RegionAddressRepository region;
@Override @Override
public AsyncTask<Object, ?, ?> getInitializeTask() { public AsyncTask<Object, ?, ?> getInitializeTask() {
return new AsyncTask<Object, MapObject, List<MapObject>>(){ return new AsyncTask<Object, City, List<City>>(){
@Override @Override
protected void onPostExecute(List<MapObject> result) { protected void onPostExecute(List<City> result) {
((TextView)findViewById(R.id.Label)).setText(R.string.incremental_search_city); ((TextView)findViewById(R.id.Label)).setText(R.string.incremental_search_city);
progress.setVisibility(View.INVISIBLE); progress.setVisibility(View.INVISIBLE);
finishInitializing(result); finishInitializing(result);
@ -39,14 +37,14 @@ public class SearchCityByNameActivity extends SearchByNameAbstractActivity<MapOb
@Override @Override
protected List<MapObject> doInBackground(Object... params) { protected List<City> doInBackground(Object... params) {
region = ((OsmandApplication)getApplication()).getResourceManager().getRegionRepository(settings.getLastSearchedRegion()); region = ((OsmandApplication)getApplication()).getResourceManager().getRegionRepository(settings.getLastSearchedRegion());
if(region != null){ if(region != null){
// preload cities // preload cities
region.preloadCities(new ResultMatcher<MapObject>() { region.preloadCities(new ResultMatcher<City>() {
@Override @Override
public boolean publish(MapObject object) { public boolean publish(City object) {
addObjectToInitialList(object); addObjectToInitialList(object);
return true; return true;
} }
@ -64,18 +62,18 @@ public class SearchCityByNameActivity extends SearchByNameAbstractActivity<MapOb
} }
@Override @Override
protected void filterLoop(String query, List<MapObject> list) { protected void filterLoop(String query, List<City> list) {
if(!initializeTaskIsFinished() || query.length() <= 2){ if(!initializeTaskIsFinished() || query.length() <= 2){
super.filterLoop(query, list); super.filterLoop(query, list);
} else { } else {
region.fillWithSuggestedCities(query, new ResultMatcher<MapObject>() { region.fillWithSuggestedCities(query, new ResultMatcher<City>() {
@Override @Override
public boolean isCancelled() { public boolean isCancelled() {
return namesFilter.isCancelled; return namesFilter.isCancelled;
} }
@Override @Override
public boolean publish(MapObject object) { public boolean publish(City object) {
Message msg = uiHandler.obtainMessage(MESSAGE_ADD_ENTITY, object); Message msg = uiHandler.obtainMessage(MESSAGE_ADD_ENTITY, object);
msg.sendToTarget(); msg.sendToTarget();
return true; return true;
@ -86,7 +84,7 @@ public class SearchCityByNameActivity extends SearchByNameAbstractActivity<MapOb
@Override @Override
public String getText(MapObject obj) { public String getText(City obj) {
LatLon l = obj.getLocation(); LatLon l = obj.getLocation();
if (getFilter().length() > 2 && locationToSearch != null && l != null) { if (getFilter().length() > 2 && locationToSearch != null && l != null) {
String name =obj.getName(region.useEnglishNames()); String name =obj.getName(region.useEnglishNames());
@ -101,16 +99,11 @@ public class SearchCityByNameActivity extends SearchByNameAbstractActivity<MapOb
} }
@Override @Override
public void itemSelected(MapObject obj) { public void itemSelected(City obj) {
if (obj instanceof City) {
settings.setLastSearchedCity(obj.getId(), obj.getName(region.useEnglishNames()), obj.getLocation()); settings.setLastSearchedCity(obj.getId(), obj.getName(region.useEnglishNames()), obj.getLocation());
if (region.getCityById(obj.getId()) == null) { if (region.getCityById(obj.getId(), obj.getName(region.useEnglishNames())) == null) {
region.addCityToPreloadedList((City) obj); region.addCityToPreloadedList((City) obj);
} }
} else if(obj instanceof PostCode){
settings.setLastSearchedPostcode(obj.getName(region.useEnglishNames()), obj.getLocation());
}
finish(); finish();
} }
} }

View file

@ -3,7 +3,6 @@ package net.osmand.plus.activities.search;
import java.util.List; import java.util.List;
import net.osmand.data.City; import net.osmand.data.City;
import net.osmand.data.PostCode;
import net.osmand.data.Street; import net.osmand.data.Street;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
@ -14,8 +13,7 @@ import android.widget.TextView;
public class SearchStreet2ByNameActivity extends SearchByNameAbstractActivity<Street> { public class SearchStreet2ByNameActivity extends SearchByNameAbstractActivity<Street> {
private RegionAddressRepository region; private RegionAddressRepository region;
private City city; private City cityOrPostcode;
private PostCode postcode;
private Street street1; private Street street1;
@ -38,18 +36,12 @@ public class SearchStreet2ByNameActivity extends SearchByNameAbstractActivity<St
protected List<Street> doInBackground(Object... params) { protected List<Street> doInBackground(Object... params) {
region = ((OsmandApplication)getApplication()).getResourceManager().getRegionRepository(settings.getLastSearchedRegion()); region = ((OsmandApplication)getApplication()).getResourceManager().getRegionRepository(settings.getLastSearchedRegion());
if(region != null){ if(region != null){
postcode = region.getPostcode(settings.getLastSearchedPostcode()); cityOrPostcode = region.getCityById(settings.getLastSearchedCity(), settings.getLastSearchedCityName());
city = region.getCityById(settings.getLastSearchedCity()); if(cityOrPostcode != null){
if(postcode != null){ street1 = region.getStreetByName(cityOrPostcode, (settings.getLastSearchedStreet()));
street1 = region.getStreetByName(postcode, (settings.getLastSearchedStreet()));
if(street1 != null){
city = street1.getCity();
} }
} else if(city != null){ if(cityOrPostcode != null && street1 != null){
street1 = region.getStreetByName(city, (settings.getLastSearchedStreet())); return region.getStreetsIntersectStreets(street1);
}
if(city != null && street1 != null){
return region.getStreetsIntersectStreets(city, street1);
} }
} }
return null; return null;
@ -66,7 +58,7 @@ public class SearchStreet2ByNameActivity extends SearchByNameAbstractActivity<St
@Override @Override
public void itemSelected(Street obj) { public void itemSelected(Street obj) {
settings.setLastSearchedIntersectedStreet(obj.getName(region.useEnglishNames()), region.findStreetIntersection(street1, obj)); settings.setLastSearchedIntersectedStreet(obj.getName(region.useEnglishNames()), obj.getLocation());
finish(); finish();
} }
} }

View file

@ -8,7 +8,6 @@ import net.osmand.CollatorStringMatcher;
import net.osmand.CollatorStringMatcher.StringMatcherMode; import net.osmand.CollatorStringMatcher.StringMatcherMode;
import net.osmand.ResultMatcher; import net.osmand.ResultMatcher;
import net.osmand.data.City; import net.osmand.data.City;
import net.osmand.data.PostCode;
import net.osmand.data.Street; import net.osmand.data.Street;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
@ -21,7 +20,6 @@ import android.widget.TextView;
public class SearchStreetByNameActivity extends SearchByNameAbstractActivity<Street> { public class SearchStreetByNameActivity extends SearchByNameAbstractActivity<Street> {
private RegionAddressRepository region; private RegionAddressRepository region;
private City city; private City city;
private PostCode postcode;
@Override @Override
@ -44,30 +42,24 @@ public class SearchStreetByNameActivity extends SearchByNameAbstractActivity<Str
protected List<Street> doInBackground(Object... params) { protected List<Street> doInBackground(Object... params) {
region = ((OsmandApplication) getApplication()).getResourceManager().getRegionRepository(settings.getLastSearchedRegion()); region = ((OsmandApplication) getApplication()).getResourceManager().getRegionRepository(settings.getLastSearchedRegion());
if (region != null) { if (region != null) {
postcode = region.getPostcode(settings.getLastSearchedPostcode()); city = region.getCityById(settings.getLastSearchedCity(), settings.getLastSearchedCityName());
if (postcode == null) {
city = region.getCityById(settings.getLastSearchedCity());
if (city == null) { if (city == null) {
return null; return null;
} }
} region.preloadStreets(city, new ResultMatcher<Street>() {
region.preloadStreets(postcode == null ? city : postcode, new ResultMatcher<Street>() {
@Override @Override
public boolean publish(Street object) { public boolean publish(Street object) {
addObjectToInitialList(object); addObjectToInitialList(object);
return true; return true;
} }
@Override @Override
public boolean isCancelled() { public boolean isCancelled() {
return false; return false;
} }
}); });
if(postcode != null){
return new ArrayList<Street>(postcode.getStreets());
} else {
return new ArrayList<Street>(city.getStreets()); return new ArrayList<Street>(city.getStreets());
} }
}
return null; return null;
} }
}; };