Merge remote-tracking branch 'origin/master'

This commit is contained in:
Weblate 2016-06-28 10:30:19 +02:00
commit 38affee113
14 changed files with 238 additions and 61 deletions

View file

@ -0,0 +1,43 @@
package net.osmand.core.samples.android.sample1.adapters;
import net.osmand.core.jni.Building;
import net.osmand.core.jni.Street;
import net.osmand.core.jni.StreetGroup;
import net.osmand.core.samples.android.sample1.MapUtils;
import net.osmand.core.samples.android.sample1.SampleApplication;
import net.osmand.core.samples.android.sample1.search.objects.BuildingSearchObject;
public class BuildingSearchListItem extends SearchListPositionItem {
private String nameStr;
private String typeStr;
public BuildingSearchListItem(SampleApplication app, BuildingSearchObject searchObject) {
super(app, searchObject);
nameStr = searchObject.getName(MapUtils.LANGUAGE);
Building building = searchObject.getBuilding();
Street street = building.getStreet();
if (street != null) {
StreetGroup streetGroup = street.getStreetGroup();
if (streetGroup != null) {
typeStr = streetGroup.getNativeName() + ", " + street.getNativeName();
} else {
typeStr = street.getNativeName();
}
} else {
typeStr = "Building";
}
}
@Override
public String getName() {
return nameStr;
}
@Override
public String getTypeName() {
return typeStr;
}
}

View file

@ -9,10 +9,10 @@ public class CitySearchListItem extends SearchListPositionItem{
private String nameStr;
private String typeStr;
public CitySearchListItem(SampleApplication app, CitySearchObject searchItem) {
super(app, searchItem);
public CitySearchListItem(SampleApplication app, CitySearchObject searchObject) {
super(app, searchObject);
nameStr = searchItem.getName(MapUtils.LANGUAGE);
nameStr = searchObject.getName(MapUtils.LANGUAGE);
typeStr = "City";
}

View file

@ -26,9 +26,9 @@ public class PoiSearchListItem extends SearchListPositionItem {
private String nameStr;
private String typeStr;
public PoiSearchListItem(SampleApplication app, PoiSearchObject searchItem) {
super(app, searchItem);
amenity = parseAmenity(searchItem);
public PoiSearchListItem(SampleApplication app, PoiSearchObject searchObject) {
super(app, searchObject);
amenity = parseAmenity(searchObject);
nameStr = amenity.getName(MapUtils.LANGUAGE);
typeStr = getTypeStr();
}

View file

@ -10,10 +10,10 @@ public class PostcodeSearchListItem extends SearchListPositionItem {
private String nameStr;
private String typeStr;
public PostcodeSearchListItem(SampleApplication app, PostcodeSearchObject searchItem) {
super(app, searchItem);
public PostcodeSearchListItem(SampleApplication app, PostcodeSearchObject searchObject) {
super(app, searchObject);
nameStr = searchItem.getNativeName();
nameStr = searchObject.getNativeName();
typeStr = "Postcode";
}

View file

@ -3,10 +3,12 @@ package net.osmand.core.samples.android.sample1.adapters;
import android.graphics.drawable.Drawable;
import net.osmand.core.samples.android.sample1.SampleApplication;
import net.osmand.core.samples.android.sample1.search.objects.BuildingSearchObject;
import net.osmand.core.samples.android.sample1.search.objects.CitySearchObject;
import net.osmand.core.samples.android.sample1.search.objects.PoiSearchObject;
import net.osmand.core.samples.android.sample1.search.objects.PostcodeSearchObject;
import net.osmand.core.samples.android.sample1.search.objects.SearchObject;
import net.osmand.core.samples.android.sample1.search.objects.StreetIntersectionSearchObject;
import net.osmand.core.samples.android.sample1.search.objects.StreetSearchObject;
import net.osmand.core.samples.android.sample1.search.objects.VillageSearchObject;
@ -20,18 +22,22 @@ public class SearchListItem {
this.searchObject = searchObject;
}
public static SearchListItem buildListItem(SampleApplication app, SearchObject item) {
switch (item.getType()) {
public static SearchListItem buildListItem(SampleApplication app, SearchObject searchObject) {
switch (searchObject.getType()) {
case POI:
return new PoiSearchListItem(app, (PoiSearchObject) item);
return new PoiSearchListItem(app, (PoiSearchObject) searchObject);
case BUILDING:
return new BuildingSearchListItem(app, (BuildingSearchObject) searchObject);
case STREET_INTERSECTION:
return new StreetIntersectionSearchListItem(app, (StreetIntersectionSearchObject) searchObject);
case STREET:
return new StreetSearchListItem(app, (StreetSearchObject) item);
return new StreetSearchListItem(app, (StreetSearchObject) searchObject);
case CITY:
return new CitySearchListItem(app, (CitySearchObject) item);
return new CitySearchListItem(app, (CitySearchObject) searchObject);
case VILLAGE:
return new VillageSearchListItem(app, (VillageSearchObject) item);
return new VillageSearchListItem(app, (VillageSearchObject) searchObject);
case POSTCODE:
return new PostcodeSearchListItem(app, (PostcodeSearchObject) item);
return new PostcodeSearchListItem(app, (PostcodeSearchObject) searchObject);
}
return null;
}

View file

@ -0,0 +1,43 @@
package net.osmand.core.samples.android.sample1.adapters;
import net.osmand.core.jni.Street;
import net.osmand.core.jni.StreetGroup;
import net.osmand.core.jni.StreetIntersection;
import net.osmand.core.samples.android.sample1.MapUtils;
import net.osmand.core.samples.android.sample1.SampleApplication;
import net.osmand.core.samples.android.sample1.search.objects.StreetIntersectionSearchObject;
public class StreetIntersectionSearchListItem extends SearchListPositionItem {
private String nameStr;
private String typeStr;
public StreetIntersectionSearchListItem(SampleApplication app, StreetIntersectionSearchObject searchObject) {
super(app, searchObject);
nameStr = searchObject.getName(MapUtils.LANGUAGE);
StreetIntersection streetIntersection = searchObject.getStreetIntersection();
Street street = streetIntersection.getStreet();
if (street != null) {
StreetGroup streetGroup = street.getStreetGroup();
if (streetGroup != null) {
typeStr = streetGroup.getNativeName() + ", " + street.getNativeName();
} else {
typeStr = street.getNativeName();
}
} else {
typeStr = "Street intersection";
}
}
@Override
public String getName() {
return nameStr;
}
@Override
public String getTypeName() {
return typeStr;
}
}

View file

@ -10,12 +10,12 @@ public class StreetSearchListItem extends SearchListPositionItem {
private String nameStr;
private String typeStr;
public StreetSearchListItem(SampleApplication app, StreetSearchObject searchItem) {
super(app, searchItem);
public StreetSearchListItem(SampleApplication app, StreetSearchObject searchObject) {
super(app, searchObject);
nameStr = searchItem.getName(MapUtils.LANGUAGE);
nameStr = searchObject.getName(MapUtils.LANGUAGE);
StreetGroup streetGroup = searchItem.getStreet().getStreetGroup();
StreetGroup streetGroup = searchObject.getStreet().getStreetGroup();
if (streetGroup != null) {
typeStr = streetGroup.getNativeName() + "" + getTypeStr(streetGroup);
} else {
@ -26,17 +26,9 @@ public class StreetSearchListItem extends SearchListPositionItem {
private String getTypeStr(StreetGroup streetGroup) {
String typeStr;
if (streetGroup.getSubtype() != ObfAddressStreetGroupSubtype.Unknown) {
try {
typeStr = streetGroup.getSubtype().name();
} catch (IllegalArgumentException e) {
typeStr = "Out of subtype";
}
typeStr = streetGroup.getSubtype().name();
} else {
try {
typeStr = streetGroup.getType().name();
} catch (IllegalArgumentException e) {
typeStr = "Out of type";
}
typeStr = streetGroup.getType().name();
}
return typeStr;
}

View file

@ -10,10 +10,10 @@ public class VillageSearchListItem extends SearchListPositionItem{
private String nameStr;
private String typeStr;
public VillageSearchListItem(SampleApplication app, VillageSearchObject searchItem) {
super(app, searchItem);
public VillageSearchListItem(SampleApplication app, VillageSearchObject searchObject) {
super(app, searchObject);
nameStr = searchItem.getName(MapUtils.LANGUAGE);
nameStr = searchObject.getName(MapUtils.LANGUAGE);
typeStr = "Village";
}

View file

@ -11,6 +11,7 @@ import net.osmand.core.jni.Street;
import net.osmand.core.jni.StreetGroup;
import net.osmand.core.jni.Utilities;
import net.osmand.core.samples.android.sample1.search.objects.PoiSearchObject;
import net.osmand.core.samples.android.sample1.search.objects.PostcodeSearchObject;
import net.osmand.core.samples.android.sample1.search.objects.SearchObject;
import net.osmand.core.samples.android.sample1.search.objects.SearchObject.SearchObjectType;
import net.osmand.core.samples.android.sample1.search.objects.SearchPositionObject;
@ -96,7 +97,25 @@ public class SearchScope {
}
public void setupAddressSearchCriteria(AddressesByNameSearch.Criteria criteria) {
// not implemented
if (objectTokens.containsKey(SearchObjectType.STREET)) {
StreetSearchObject streetSearchObject =
(StreetSearchObject) objectTokens.get(SearchObjectType.STREET).getSearchObject();
criteria.setAddressFilter(streetSearchObject.getStreet());
if (objectTokens.containsKey(SearchObjectType.POSTCODE)) {
PostcodeSearchObject postcodeSearchObject =
(PostcodeSearchObject) objectTokens.get(SearchObjectType.POSTCODE).getSearchObject();
criteria.setPostcode(postcodeSearchObject.getNativeName());
}
} else if (objectTokens.containsKey(SearchObjectType.CITY)) {
criteria.setAddressFilter(((StreetGroupSearchObject) objectTokens.get(SearchObjectType.CITY)
.getSearchObject()).getStreetGroup());
} else if (objectTokens.containsKey(SearchObjectType.VILLAGE)) {
criteria.setAddressFilter(((StreetGroupSearchObject) objectTokens.get(SearchObjectType.VILLAGE)
.getSearchObject()).getStreetGroup());
} else if (objectTokens.containsKey(SearchObjectType.POSTCODE)) {
criteria.setAddressFilter(((StreetGroupSearchObject) objectTokens.get(SearchObjectType.POSTCODE)
.getSearchObject()).getStreetGroup());
}
}
public boolean processPoiSearchObject(PoiSearchObject poiSearchObject) {
@ -117,7 +136,7 @@ public class SearchScope {
@Override
public int compare(SearchObject lhs, SearchObject rhs) {
int res = Double.compare(lhs.getPriority(), rhs.getPriority());
if (res == 0 && lhs.isSortByName() && rhs.isSortByName()) {
if (res == 0) {
return lhs.getName(lang).compareToIgnoreCase(rhs.getName(lang));
} else {
return res;
@ -170,25 +189,27 @@ public class SearchScope {
}
private boolean processSearchObject(SearchObject searchObject) {
double priority = 0d;
boolean sortByName = false;
double priority = 0.0;
switch (searchObject.getType()) {
case BUILDING:
priority = 3.0;
break;
case POI:
priority = getPriorityByDistance(10, ((PoiSearchObject) searchObject).getDistance());
priority = getPriorityByDistance(10.0, ((PoiSearchObject) searchObject).getDistance());
break;
case CITY:
case VILLAGE:
case POSTCODE:
float cityType = getCityType((StreetGroupSearchObject) searchObject);
double cityType = getCityType((StreetGroupSearchObject) searchObject);
priority = (getPriorityByDistance(citySelected
? 20f : 7f + cityType, ((StreetGroupSearchObject) searchObject).getDistance()));
? 20.0 : 7.0 + cityType, ((StreetGroupSearchObject) searchObject).getDistance()));
break;
case STREET:
StreetSearchObject streetSearchObject = (StreetSearchObject) searchObject;
Street street = streetSearchObject.getStreet();
if (!citySelected) {
priority = getPriorityByDistance(9f, streetSearchObject.getDistance());
priority = getPriorityByDistance(9.0, streetSearchObject.getDistance());
} else {
boolean streetFromSelectedCity = false;
for (SearchToken st : objectTokens.values()) {
@ -209,33 +230,31 @@ public class SearchScope {
}
}
if (streetFromSelectedCity) {
priority = 3f;
sortByName = true;
priority = 3.0;
} else {
priority = getPriorityByDistance(9f, streetSearchObject.getDistance());
priority = getPriorityByDistance(9.0, streetSearchObject.getDistance());
}
}
break;
}
searchObject.setPriority(priority);
searchObject.setSortByName(sortByName);
return true;
}
private float getCityType(StreetGroupSearchObject searchObject) {
private double getCityType(StreetGroupSearchObject searchObject) {
if (searchObject.getStreetGroup().getType() == ObfAddressStreetGroupType.CityOrTown) {
if (searchObject.getStreetGroup().getSubtype() == ObfAddressStreetGroupSubtype.City) {
return 1f;
return 1.0;
} else if (searchObject.getStreetGroup().getSubtype() == ObfAddressStreetGroupSubtype.Town) {
return 1.5f;
return 1.5;
}
}
return 2.5f;
return 2.5;
}
private double getPriorityByDistance(double priority, double distance) {
return priority + 1d - (1d / (1d + distance));
return priority + 1.0 - (1.0 / (1.0 + distance));
}
private void updateDistance(SearchPositionObject item) {

View file

@ -0,0 +1,31 @@
package net.osmand.core.samples.android.sample1.search.objects;
import net.osmand.core.jni.Building;
import net.osmand.core.jni.PointI;
import net.osmand.core.jni.QStringStringHash;
public class BuildingSearchObject extends SearchPositionObject {
public BuildingSearchObject(Building building) {
super(SearchObjectType.BUILDING, building);
}
public Building getBuilding() {
return (Building) getInternalObject();
}
@Override
public PointI getPosition31() {
return getBuilding().getPosition31();
}
@Override
public String getNativeName() {
return getBuilding().getNativeName();
}
@Override
protected QStringStringHash getLocalizedNames() {
return getBuilding().getLocalizedNames();
}
}

View file

@ -9,6 +9,7 @@ public abstract class SearchObject {
VILLAGE,
POSTCODE,
STREET,
STREET_INTERSECTION,
BUILDING,
POI_TYPE,
POI_FILTER,
@ -20,7 +21,6 @@ public abstract class SearchObject {
private Object internalObject;
private double priority;
private boolean sortByName;
protected SearchObject(SearchObjectType type, Object internalObject) {
this.type = type;
@ -67,14 +67,6 @@ public abstract class SearchObject {
this.priority = priority;
}
public boolean isSortByName() {
return sortByName;
}
public void setSortByName(boolean sortByName) {
this.sortByName = sortByName;
}
protected abstract QStringStringHash getLocalizedNames();
@Override

View file

@ -1,16 +1,25 @@
package net.osmand.core.samples.android.sample1.search.objects;
import net.osmand.core.jni.Address;
import net.osmand.core.jni.Building;
import net.osmand.core.jni.OsmAndCoreJNI;
import net.osmand.core.jni.Street;
import net.osmand.core.jni.StreetGroup;
import net.osmand.core.jni.StreetIntersection;
public class SearchObjectsHelper {
public static SearchPositionObject getAddressObject(Address address) {
switch (address.getAddressType()) {
//todo add Building type to Address class
case Building:
BuildingInternal building = new BuildingInternal(address);
return new BuildingSearchObject(building);
case StreetIntersection:
StreetIntercestionInternal streetIntersection = new StreetIntercestionInternal(address);
return new StreetIntersectionSearchObject(streetIntersection);
case Street:
StreetInternal street = new StreetInternal(address);
return new StreetSearchObject(street);
@ -30,6 +39,18 @@ public class SearchObjectsHelper {
return null;
}
private static class BuildingInternal extends Building {
public BuildingInternal(Address address) {
super(OsmAndCoreJNI.Street_SWIGSmartPtrUpcast(Address.getCPtr(address)), false);
}
}
private static class StreetIntercestionInternal extends StreetIntersection {
public StreetIntercestionInternal(Address address) {
super(OsmAndCoreJNI.Street_SWIGSmartPtrUpcast(Address.getCPtr(address)), false);
}
}
private static class StreetInternal extends Street {
public StreetInternal(Address address) {
super(OsmAndCoreJNI.Street_SWIGSmartPtrUpcast(Address.getCPtr(address)), false);

View file

@ -0,0 +1,31 @@
package net.osmand.core.samples.android.sample1.search.objects;
import net.osmand.core.jni.PointI;
import net.osmand.core.jni.QStringStringHash;
import net.osmand.core.jni.StreetIntersection;
public class StreetIntersectionSearchObject extends SearchPositionObject {
public StreetIntersectionSearchObject(StreetIntersection streetIntersection) {
super(SearchObjectType.STREET_INTERSECTION, streetIntersection);
}
public StreetIntersection getStreetIntersection() {
return (StreetIntersection) getInternalObject();
}
@Override
public PointI getPosition31() {
return getStreetIntersection().getPosition31();
}
@Override
public String getNativeName() {
return getStreetIntersection().getNativeName();
}
@Override
protected QStringStringHash getLocalizedNames() {
return getStreetIntersection().getLocalizedNames();
}
}

View file

@ -148,7 +148,6 @@ public class CoreSearchRequest extends SearchRequest {
// Setup Addresses by name search
AddressesByNameSearch addrByNameSearch = new AddressesByNameSearch(searchScope.getObfsCollection());
final AddressesByNameSearch.Criteria addrByNameCriteria = new AddressesByNameSearch.Criteria();
//todo implement StreetGroup and Street parameters in AddressesByNameSearch.Criteria and apply them here
addrByNameCriteria.setName(keyword);
if (searchScope.getObfAreaFilter() != null) {
addrByNameCriteria.setObfInfoAreaFilter(new NullableAreaI(searchScope.getObfAreaFilter()));