Fix compilation errors
This commit is contained in:
parent
041ba66d05
commit
8d5d72f80e
12 changed files with 141 additions and 246 deletions
|
@ -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 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) ==
|
||||
|
|
|
@ -505,7 +505,7 @@ public class BinaryMapAddressReaderAdapter {
|
|||
LatLon l = obj.getLocation();
|
||||
Street s = new Street(obj);
|
||||
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())) {
|
||||
req.publish(s);
|
||||
|
|
|
@ -23,6 +23,7 @@ import net.osmand.Algoritms;
|
|||
import net.osmand.CollatorStringMatcher;
|
||||
import net.osmand.LogUtil;
|
||||
import net.osmand.ResultMatcher;
|
||||
import net.osmand.StringMatcher;
|
||||
import net.osmand.CollatorStringMatcher.StringMatcherMode;
|
||||
import net.osmand.binary.BinaryMapAddressReaderAdapter.AddressRegion;
|
||||
import net.osmand.binary.BinaryMapAddressReaderAdapter.CitiesBlock;
|
||||
|
@ -466,16 +467,19 @@ public class BinaryMapIndexReader {
|
|||
throw new IllegalArgumentException(name);
|
||||
}
|
||||
|
||||
|
||||
public List<City> getCities(String region, SearchRequest<City> resultMatcher,
|
||||
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>();
|
||||
AddressRegion r = getRegionByName(region);
|
||||
for(CitiesBlock block : r.cities) {
|
||||
if(block.type == cityType) {
|
||||
codedIS.seek(block.filePointer);
|
||||
int old = codedIS.pushLimit(block.length);
|
||||
addressAdapter.readCities(cities, resultMatcher, null, false);
|
||||
addressAdapter.readCities(cities, resultMatcher, matcher, useEn);
|
||||
codedIS.popLimit(old);
|
||||
}
|
||||
}
|
||||
|
@ -510,7 +514,8 @@ public class BinaryMapIndexReader {
|
|||
codedIS.seek(s.getFileOffset());
|
||||
int size = codedIS.readRawVarint32();
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -1164,6 +1169,8 @@ public class BinaryMapIndexReader {
|
|||
return request;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static <T> SearchRequest<T> buildAddressByNameRequest(ResultMatcher<T> resultMatcher, String nameRequest){
|
||||
SearchRequest<T> request = new SearchRequest<T>();
|
||||
request.resultMatcher = resultMatcher;
|
||||
|
|
|
@ -14,6 +14,8 @@ import net.osmand.osm.OSMSettings.OSMTagKey;
|
|||
|
||||
public class City extends MapObject {
|
||||
|
||||
private static long POSTCODE_INTERNAL_ID = -1000;
|
||||
|
||||
public enum CityType {
|
||||
// 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);
|
||||
|
@ -65,13 +67,14 @@ public class City extends MapObject {
|
|||
this.type = type;
|
||||
}
|
||||
|
||||
private City(String postcode) {
|
||||
private City(String postcode, long id) {
|
||||
this.type = null;
|
||||
this.name = this.enName = postcode;
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public static City createPostcode(String postcode){
|
||||
return new City(postcode);
|
||||
return new City(postcode, POSTCODE_INTERNAL_ID--);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -81,7 +81,7 @@ public class IndexCreator {
|
|||
private OsmDbAccessor accessor;
|
||||
// constants to start process from the middle and save temporary results
|
||||
private boolean recreateOnlyBinaryFile = false; // false;
|
||||
private boolean deleteOsmDB = false;
|
||||
private boolean deleteOsmDB = true;
|
||||
private boolean deleteDatabaseIndexes = true;
|
||||
|
||||
private Object dbConn;
|
||||
|
|
|
@ -38,27 +38,23 @@ public interface RegionAddressRepository {
|
|||
public void preloadStreets(City o, ResultMatcher<Street> resultMatcher);
|
||||
|
||||
|
||||
public List<MapObject> getLoadedCities();
|
||||
public List<City> getLoadedCities();
|
||||
|
||||
public City getPostcode(String name);
|
||||
|
||||
public City getCityById(Long id);
|
||||
// Returns city or postcode (if id < 0)
|
||||
public City getCityById(long id, String name);
|
||||
|
||||
public Street getStreetByName(City cityOrPostcode, 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);
|
||||
|
||||
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<MapObject> searchMapObjectsByName(String name, ResultMatcher<MapObject> resultMatcher);
|
||||
|
||||
|
||||
|
||||
public static class MapObjectNameDistanceComparator implements Comparator<MapObject> {
|
||||
|
|
|
@ -17,6 +17,7 @@ import net.osmand.LogUtil;
|
|||
import net.osmand.ResultMatcher;
|
||||
import net.osmand.binary.BinaryMapAddressReaderAdapter;
|
||||
import net.osmand.binary.BinaryMapIndexReader;
|
||||
import net.osmand.binary.BinaryMapIndexReader.SearchRequest;
|
||||
import net.osmand.data.Building;
|
||||
import net.osmand.data.City;
|
||||
import net.osmand.data.MapObject;
|
||||
|
@ -84,8 +85,8 @@ public class RegionAddressRepositoryBinary implements RegionAddressRepository {
|
|||
}
|
||||
|
||||
@Override
|
||||
public synchronized List<MapObject> getLoadedCities(){
|
||||
return new ArrayList<MapObject>(cities.values());
|
||||
public synchronized List<City> getLoadedCities(){
|
||||
return new ArrayList<City>(cities.values());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -108,35 +109,17 @@ public class RegionAddressRepositoryBinary implements RegionAddressRepository {
|
|||
StringMatcherMode.CHECK_STARTS_FROM_SPACE_NOT_BEGINNING};
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public List<Street> fillWithSuggestedStreets(City o, ResultMatcher<Street> resultMatcher, String... names) {
|
||||
List<Street> streetsToFill = new ArrayList<Street>();
|
||||
if(names.length == 0){
|
||||
preloadStreets(o, resultMatcher);
|
||||
streetsToFill.addAll(o.getStreets());
|
||||
return streetsToFill;
|
||||
public List<MapObject> searchMapObjectsByName(String name, ResultMatcher<MapObject> resultMatcher) {
|
||||
SearchRequest<MapObject> req = BinaryMapIndexReader.buildAddressByNameRequest(resultMatcher, name);
|
||||
try {
|
||||
file.searchAddressDataByName(req);
|
||||
} catch (IOException e) {
|
||||
log.error("Disk operation failed", e); //$NON-NLS-1$
|
||||
}
|
||||
preloadStreets(o, null);
|
||||
|
||||
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;
|
||||
return req.getSearchResults();
|
||||
}
|
||||
|
||||
|
||||
|
@ -160,7 +143,7 @@ public class RegionAddressRepositoryBinary implements RegionAddressRepository {
|
|||
// also try to identify postcodes
|
||||
String uName = name.toUpperCase();
|
||||
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)) {
|
||||
citiesToFill.add(code);
|
||||
if (resultMatcher.isCancelled()) {
|
||||
|
@ -184,8 +167,9 @@ public class RegionAddressRepositoryBinary implements RegionAddressRepository {
|
|||
|
||||
int initialsize = citiesToFill.size();
|
||||
if (name.length() >= 3) {
|
||||
for (City c : file.getVillages(region, BinaryMapIndexReader.buildAddressRequest(resultMatcher),
|
||||
new CollatorStringMatcher(collator, name,StringMatcherMode.CHECK_STARTS_FROM_SPACE), useEnglishNames)) {
|
||||
for (City c : file.getCities(region, BinaryMapIndexReader.buildAddressRequest(resultMatcher),
|
||||
new CollatorStringMatcher(collator, name,StringMatcherMode.CHECK_STARTS_FROM_SPACE), useEnglishNames,
|
||||
BinaryMapAddressReaderAdapter.VILLAGES_TYPE)) {
|
||||
citiesToFill.add(c);
|
||||
if (resultMatcher.isCancelled()) {
|
||||
return citiesToFill;
|
||||
|
@ -200,32 +184,9 @@ public class RegionAddressRepositoryBinary implements RegionAddressRepository {
|
|||
}
|
||||
|
||||
@Override
|
||||
public List<Street> getStreetsIntersectStreets(City city, Street st) {
|
||||
List<Street> streetsToFill = new ArrayList<Street>();
|
||||
if(city != null){
|
||||
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;
|
||||
public List<Street> getStreetsIntersectStreets(Street st) {
|
||||
preloadBuildings(st, null);
|
||||
return st.getIntersectedStreets();
|
||||
}
|
||||
|
||||
|
||||
|
@ -257,30 +218,40 @@ public class RegionAddressRepositoryBinary implements RegionAddressRepository {
|
|||
}
|
||||
|
||||
@Override
|
||||
public City getCityById(final Long id) {
|
||||
if(id == -1){
|
||||
public City getCityById(final long id, String name) {
|
||||
if (id == -1) {
|
||||
// do not preload cities for that case
|
||||
return null;
|
||||
}
|
||||
if(id < -1 && name != null){
|
||||
name = name.toUpperCase();
|
||||
}
|
||||
final String cmpName = name;
|
||||
preloadCities(null);
|
||||
if (!cities.containsKey(id)) {
|
||||
try {
|
||||
file.getVillages(region, BinaryMapIndexReader.buildAddressRequest(new ResultMatcher<MapObject>() {
|
||||
file.getCities(region, BinaryMapIndexReader.buildAddressRequest(new ResultMatcher<City>() {
|
||||
boolean canceled = false;
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return canceled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean publish(MapObject object) {
|
||||
if (object.getId().longValue() == id.longValue()) {
|
||||
public boolean publish(City object) {
|
||||
if(id < -1) {
|
||||
if(object.getName().toUpperCase().equals(cmpName)) {
|
||||
addCityToPreloadedList(object);
|
||||
canceled = true;
|
||||
}
|
||||
} else if (object.getId().longValue() == id) {
|
||||
addCityToPreloadedList((City) object);
|
||||
canceled = true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}), null, useEnglishNames);
|
||||
}), id < -1 ? BinaryMapAddressReaderAdapter.POSTCODES_TYPE : BinaryMapAddressReaderAdapter.VILLAGES_TYPE);
|
||||
} catch (IOException e) {
|
||||
log.error("Disk operation failed", e); //$NON-NLS-1$
|
||||
}
|
||||
|
@ -289,32 +260,11 @@ public class RegionAddressRepositoryBinary implements RegionAddressRepository {
|
|||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public PostCode getPostcode(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);
|
||||
public Street getStreetByName(City o, String name) {
|
||||
name = name.toLowerCase();
|
||||
preloadStreets(o, null);
|
||||
Collection<Street> streets = post == null ? city.getStreets() : post.getStreets();
|
||||
Collection<Street> streets = o.getStreets() ;
|
||||
for (Street s : streets) {
|
||||
String sName = useEnglishNames ? s.getEnName() : s.getName(); //lower case not needed, collator ensures that
|
||||
if (collator.equals(sName,name)) {
|
||||
|
|
|
@ -1,20 +1,18 @@
|
|||
package net.osmand.plus.activities.search;
|
||||
|
||||
import gnu.trove.map.hash.TLongObjectHashMap;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
import net.osmand.OsmAndFormatter;
|
||||
import net.osmand.access.AccessibleToast;
|
||||
import net.osmand.ResultMatcher;
|
||||
import net.osmand.data.City;
|
||||
import net.osmand.data.MapObject;
|
||||
import net.osmand.data.PostCode;
|
||||
import net.osmand.data.Street;
|
||||
import net.osmand.osm.LatLon;
|
||||
import net.osmand.osm.MapUtils;
|
||||
|
@ -230,66 +228,41 @@ public class GeoIntentActivity extends OsmandListActivity {
|
|||
}
|
||||
|
||||
// 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) {
|
||||
List<MapObject> citiesFound = new ArrayList<MapObject>();
|
||||
for (String maybeCity : elements) {
|
||||
citiesFound.addAll(rar.fillWithSuggestedCities(maybeCity, null, null));
|
||||
}
|
||||
if (!citiesFound.isEmpty()) {
|
||||
citiesForRegion.put(rar, citiesFound);
|
||||
}
|
||||
}
|
||||
// no cities found, we should locate the country only
|
||||
Map<MapObject, List<Street>> streetsForCity = new HashMap<MapObject, List<Street>>();
|
||||
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?
|
||||
for (RegionAddressRepository rar : citiesForRegion.keySet()) {
|
||||
findStreetsForCities(streetsForCity, rar,
|
||||
citiesForRegion.get(rar));
|
||||
final TLongObjectHashMap<City> cityIds = new TLongObjectHashMap<City>();
|
||||
for (String element : elements) {
|
||||
rar.searchMapObjectsByName(element, new ResultMatcher<MapObject>() {
|
||||
@Override
|
||||
public boolean publish(MapObject object) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
results.add(object);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// don't go deeper, now populate result list
|
||||
Set<MapObject> results = new HashSet<MapObject>();
|
||||
// add all found lists
|
||||
for (List<Street> streets : streetsForCity.values()) {
|
||||
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;
|
||||
|
||||
// add all other results to connected streets
|
||||
connectedStreets.addAll(results);
|
||||
return connectedStreets;
|
||||
}
|
||||
|
||||
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();
|
||||
if (latIndex > 0) {
|
||||
try {
|
||||
double latitude = Double.parseDouble(geo.substring(0,
|
||||
latIndex));
|
||||
double longitude = Double.parseDouble(geo.substring(
|
||||
latIndex + 1, lonIndex));
|
||||
double latitude = Double.parseDouble(geo.substring(0, latIndex));
|
||||
double longitude = Double.parseDouble(geo.substring(latIndex + 1, lonIndex));
|
||||
// TODO zoom is omited for now
|
||||
point = new MapObject(new Node(latitude, longitude, -1)) {
|
||||
private static final long serialVersionUID = -7028586132795853725L;
|
||||
};
|
||||
point.setName("Lat: " + latitude + ",Lon:" + longitude);
|
||||
} catch (NumberFormatException e) {
|
||||
|
|
|
@ -5,7 +5,6 @@ import java.util.List;
|
|||
import net.osmand.ResultMatcher;
|
||||
import net.osmand.data.Building;
|
||||
import net.osmand.data.City;
|
||||
import net.osmand.data.PostCode;
|
||||
import net.osmand.data.Street;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
|
@ -18,7 +17,6 @@ public class SearchBuildingByNameActivity extends SearchByNameAbstractActivity<B
|
|||
private RegionAddressRepository region;
|
||||
private City city;
|
||||
private Street street;
|
||||
private PostCode postcode;
|
||||
|
||||
@Override
|
||||
public AsyncTask<Object, ?, ?> getInitializeTask() {
|
||||
|
@ -39,13 +37,8 @@ public class SearchBuildingByNameActivity extends SearchByNameAbstractActivity<B
|
|||
protected List<Building> doInBackground(Object... params) {
|
||||
region = ((OsmandApplication)getApplication()).getResourceManager().getRegionRepository(settings.getLastSearchedRegion());
|
||||
if(region != null){
|
||||
postcode = region.getPostcode(settings.getLastSearchedPostcode());
|
||||
city = region.getCityById(settings.getLastSearchedCity());
|
||||
if(postcode != null){
|
||||
street = region.getStreetByName(postcode, settings.getLastSearchedStreet());
|
||||
} else if(city != null){
|
||||
street = region.getStreetByName(city, settings.getLastSearchedStreet());
|
||||
}
|
||||
city = region.getCityById(settings.getLastSearchedCity(), settings.getLastSearchedCityName());
|
||||
street = region.getStreetByName(city, settings.getLastSearchedStreet());
|
||||
}
|
||||
if(street != null){
|
||||
// preload here to avoid concurrent modification
|
||||
|
@ -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
|
||||
public String getText(Building obj) {
|
||||
return obj.getName(region.useEnglishNames());
|
||||
|
|
|
@ -5,8 +5,6 @@ import java.util.List;
|
|||
import net.osmand.OsmAndFormatter;
|
||||
import net.osmand.ResultMatcher;
|
||||
import net.osmand.data.City;
|
||||
import net.osmand.data.MapObject;
|
||||
import net.osmand.data.PostCode;
|
||||
import net.osmand.osm.LatLon;
|
||||
import net.osmand.osm.MapUtils;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
|
@ -17,15 +15,15 @@ import android.os.Message;
|
|||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
public class SearchCityByNameActivity extends SearchByNameAbstractActivity<MapObject> {
|
||||
public class SearchCityByNameActivity extends SearchByNameAbstractActivity<City> {
|
||||
private RegionAddressRepository region;
|
||||
|
||||
|
||||
@Override
|
||||
public AsyncTask<Object, ?, ?> getInitializeTask() {
|
||||
return new AsyncTask<Object, MapObject, List<MapObject>>(){
|
||||
return new AsyncTask<Object, City, List<City>>(){
|
||||
@Override
|
||||
protected void onPostExecute(List<MapObject> result) {
|
||||
protected void onPostExecute(List<City> result) {
|
||||
((TextView)findViewById(R.id.Label)).setText(R.string.incremental_search_city);
|
||||
progress.setVisibility(View.INVISIBLE);
|
||||
finishInitializing(result);
|
||||
|
@ -39,14 +37,14 @@ public class SearchCityByNameActivity extends SearchByNameAbstractActivity<MapOb
|
|||
|
||||
|
||||
@Override
|
||||
protected List<MapObject> doInBackground(Object... params) {
|
||||
protected List<City> doInBackground(Object... params) {
|
||||
region = ((OsmandApplication)getApplication()).getResourceManager().getRegionRepository(settings.getLastSearchedRegion());
|
||||
if(region != null){
|
||||
// preload cities
|
||||
region.preloadCities(new ResultMatcher<MapObject>() {
|
||||
region.preloadCities(new ResultMatcher<City>() {
|
||||
|
||||
@Override
|
||||
public boolean publish(MapObject object) {
|
||||
public boolean publish(City object) {
|
||||
addObjectToInitialList(object);
|
||||
return true;
|
||||
}
|
||||
|
@ -64,18 +62,18 @@ public class SearchCityByNameActivity extends SearchByNameAbstractActivity<MapOb
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void filterLoop(String query, List<MapObject> list) {
|
||||
protected void filterLoop(String query, List<City> list) {
|
||||
if(!initializeTaskIsFinished() || query.length() <= 2){
|
||||
super.filterLoop(query, list);
|
||||
} else {
|
||||
region.fillWithSuggestedCities(query, new ResultMatcher<MapObject>() {
|
||||
region.fillWithSuggestedCities(query, new ResultMatcher<City>() {
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return namesFilter.isCancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean publish(MapObject object) {
|
||||
public boolean publish(City object) {
|
||||
Message msg = uiHandler.obtainMessage(MESSAGE_ADD_ENTITY, object);
|
||||
msg.sendToTarget();
|
||||
return true;
|
||||
|
@ -86,7 +84,7 @@ public class SearchCityByNameActivity extends SearchByNameAbstractActivity<MapOb
|
|||
|
||||
|
||||
@Override
|
||||
public String getText(MapObject obj) {
|
||||
public String getText(City obj) {
|
||||
LatLon l = obj.getLocation();
|
||||
if (getFilter().length() > 2 && locationToSearch != null && l != null) {
|
||||
String name =obj.getName(region.useEnglishNames());
|
||||
|
@ -101,16 +99,11 @@ public class SearchCityByNameActivity extends SearchByNameAbstractActivity<MapOb
|
|||
}
|
||||
|
||||
@Override
|
||||
public void itemSelected(MapObject obj) {
|
||||
if (obj instanceof City) {
|
||||
settings.setLastSearchedCity(obj.getId(), obj.getName(region.useEnglishNames()), obj.getLocation());
|
||||
if (region.getCityById(obj.getId()) == null) {
|
||||
region.addCityToPreloadedList((City) obj);
|
||||
}
|
||||
} else if(obj instanceof PostCode){
|
||||
settings.setLastSearchedPostcode(obj.getName(region.useEnglishNames()), obj.getLocation());
|
||||
public void itemSelected(City obj) {
|
||||
settings.setLastSearchedCity(obj.getId(), obj.getName(region.useEnglishNames()), obj.getLocation());
|
||||
if (region.getCityById(obj.getId(), obj.getName(region.useEnglishNames())) == null) {
|
||||
region.addCityToPreloadedList((City) obj);
|
||||
}
|
||||
finish();
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@ package net.osmand.plus.activities.search;
|
|||
import java.util.List;
|
||||
|
||||
import net.osmand.data.City;
|
||||
import net.osmand.data.PostCode;
|
||||
import net.osmand.data.Street;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
|
@ -14,8 +13,7 @@ import android.widget.TextView;
|
|||
|
||||
public class SearchStreet2ByNameActivity extends SearchByNameAbstractActivity<Street> {
|
||||
private RegionAddressRepository region;
|
||||
private City city;
|
||||
private PostCode postcode;
|
||||
private City cityOrPostcode;
|
||||
private Street street1;
|
||||
|
||||
|
||||
|
@ -38,18 +36,12 @@ public class SearchStreet2ByNameActivity extends SearchByNameAbstractActivity<St
|
|||
protected List<Street> doInBackground(Object... params) {
|
||||
region = ((OsmandApplication)getApplication()).getResourceManager().getRegionRepository(settings.getLastSearchedRegion());
|
||||
if(region != null){
|
||||
postcode = region.getPostcode(settings.getLastSearchedPostcode());
|
||||
city = region.getCityById(settings.getLastSearchedCity());
|
||||
if(postcode != null){
|
||||
street1 = region.getStreetByName(postcode, (settings.getLastSearchedStreet()));
|
||||
if(street1 != null){
|
||||
city = street1.getCity();
|
||||
}
|
||||
} else if(city != null){
|
||||
street1 = region.getStreetByName(city, (settings.getLastSearchedStreet()));
|
||||
cityOrPostcode = region.getCityById(settings.getLastSearchedCity(), settings.getLastSearchedCityName());
|
||||
if(cityOrPostcode != null){
|
||||
street1 = region.getStreetByName(cityOrPostcode, (settings.getLastSearchedStreet()));
|
||||
}
|
||||
if(city != null && street1 != null){
|
||||
return region.getStreetsIntersectStreets(city, street1);
|
||||
if(cityOrPostcode != null && street1 != null){
|
||||
return region.getStreetsIntersectStreets(street1);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
@ -66,7 +58,7 @@ public class SearchStreet2ByNameActivity extends SearchByNameAbstractActivity<St
|
|||
|
||||
@Override
|
||||
public void itemSelected(Street obj) {
|
||||
settings.setLastSearchedIntersectedStreet(obj.getName(region.useEnglishNames()), region.findStreetIntersection(street1, obj));
|
||||
settings.setLastSearchedIntersectedStreet(obj.getName(region.useEnglishNames()), obj.getLocation());
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,6 @@ import net.osmand.CollatorStringMatcher;
|
|||
import net.osmand.CollatorStringMatcher.StringMatcherMode;
|
||||
import net.osmand.ResultMatcher;
|
||||
import net.osmand.data.City;
|
||||
import net.osmand.data.PostCode;
|
||||
import net.osmand.data.Street;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
|
@ -21,52 +20,45 @@ import android.widget.TextView;
|
|||
public class SearchStreetByNameActivity extends SearchByNameAbstractActivity<Street> {
|
||||
private RegionAddressRepository region;
|
||||
private City city;
|
||||
private PostCode postcode;
|
||||
|
||||
|
||||
@Override
|
||||
public AsyncTask<Object, ?, ?> getInitializeTask() {
|
||||
return new AsyncTask<Object, Street, List<Street>>(){
|
||||
return new AsyncTask<Object, Street, List<Street>>() {
|
||||
@Override
|
||||
protected void onPostExecute(List<Street> result) {
|
||||
((TextView)findViewById(R.id.Label)).setText(R.string.incremental_search_street);
|
||||
((TextView) findViewById(R.id.Label)).setText(R.string.incremental_search_street);
|
||||
progress.setVisibility(View.INVISIBLE);
|
||||
finishInitializing(result);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPreExecute() {
|
||||
((TextView)findViewById(R.id.Label)).setText(R.string.loading_streets);
|
||||
((TextView) findViewById(R.id.Label)).setText(R.string.loading_streets);
|
||||
progress.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<Street> doInBackground(Object... params) {
|
||||
region = ((OsmandApplication)getApplication()).getResourceManager().getRegionRepository(settings.getLastSearchedRegion());
|
||||
if(region != null){
|
||||
postcode = region.getPostcode(settings.getLastSearchedPostcode());
|
||||
if (postcode == null) {
|
||||
city = region.getCityById(settings.getLastSearchedCity());
|
||||
if(city == null){
|
||||
return null;
|
||||
}
|
||||
region = ((OsmandApplication) getApplication()).getResourceManager().getRegionRepository(settings.getLastSearchedRegion());
|
||||
if (region != null) {
|
||||
city = region.getCityById(settings.getLastSearchedCity(), settings.getLastSearchedCityName());
|
||||
if (city == null) {
|
||||
return null;
|
||||
}
|
||||
region.preloadStreets(postcode == null ? city : postcode, new ResultMatcher<Street>() {
|
||||
region.preloadStreets(city, new ResultMatcher<Street>() {
|
||||
@Override
|
||||
public boolean publish(Street object) {
|
||||
addObjectToInitialList(object);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue