2013-04-18 23:35:02 +02:00
|
|
|
package net.osmand.data;
|
|
|
|
|
2015-08-21 16:48:27 +02:00
|
|
|
import net.osmand.Location;
|
|
|
|
import net.osmand.osm.PoiCategory;
|
|
|
|
import net.osmand.util.Algorithms;
|
|
|
|
|
2015-05-27 00:28:24 +02:00
|
|
|
import java.io.BufferedReader;
|
|
|
|
import java.io.ByteArrayInputStream;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.InputStreamReader;
|
2015-06-08 01:50:53 +02:00
|
|
|
import java.util.ArrayList;
|
2013-11-10 16:54:28 +01:00
|
|
|
import java.util.Collections;
|
2015-06-29 17:26:32 +02:00
|
|
|
import java.util.Iterator;
|
2013-11-10 16:54:28 +01:00
|
|
|
import java.util.LinkedHashMap;
|
2015-06-08 01:50:53 +02:00
|
|
|
import java.util.List;
|
2013-11-10 16:54:28 +01:00
|
|
|
import java.util.Map;
|
2015-06-29 17:26:32 +02:00
|
|
|
import java.util.Map.Entry;
|
2015-05-27 00:28:24 +02:00
|
|
|
import java.util.zip.GZIPInputStream;
|
2013-11-10 16:54:28 +01:00
|
|
|
|
2014-08-17 15:42:09 +02:00
|
|
|
|
|
|
|
public class Amenity extends MapObject {
|
2013-04-18 23:35:02 +02:00
|
|
|
|
2013-11-24 19:45:00 +01:00
|
|
|
public static final String WEBSITE = "website";
|
|
|
|
public static final String PHONE = "phone";
|
|
|
|
public static final String DESCRIPTION = "description";
|
|
|
|
public static final String OPENING_HOURS = "opening_hours";
|
2015-05-27 00:09:48 +02:00
|
|
|
public static final String CONTENT = "content";
|
2013-11-24 19:45:00 +01:00
|
|
|
|
2013-04-18 23:35:02 +02:00
|
|
|
private String subType;
|
2015-11-12 10:30:43 +01:00
|
|
|
private PoiCategory type;
|
2013-11-10 16:54:28 +01:00
|
|
|
// duplicate for fast access
|
2013-04-18 23:35:02 +02:00
|
|
|
private String openingHours;
|
2013-11-10 16:54:28 +01:00
|
|
|
private Map<String, String> additionalInfo;
|
2014-08-17 15:42:09 +02:00
|
|
|
private AmenityRoutePoint routePoint; // for search on path
|
2013-04-18 23:35:02 +02:00
|
|
|
|
|
|
|
public Amenity(){
|
|
|
|
}
|
|
|
|
|
2014-08-17 15:42:09 +02:00
|
|
|
public static class AmenityRoutePoint {
|
|
|
|
public double deviateDistance;
|
2016-01-23 10:27:53 +01:00
|
|
|
public boolean deviationDirectionRight;
|
2014-08-17 15:42:09 +02:00
|
|
|
public Location pointA;
|
|
|
|
public Location pointB;
|
|
|
|
}
|
|
|
|
|
2015-02-18 23:21:57 +01:00
|
|
|
public PoiCategory getType(){
|
2013-04-18 23:35:02 +02:00
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getSubType(){
|
|
|
|
return subType;
|
|
|
|
}
|
|
|
|
|
2015-02-18 23:21:57 +01:00
|
|
|
public void setType(PoiCategory type) {
|
2013-04-18 23:35:02 +02:00
|
|
|
this.type = type;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setSubType(String subType) {
|
|
|
|
this.subType = subType;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getOpeningHours() {
|
2013-11-10 16:54:28 +01:00
|
|
|
// getAdditionalInfo("opening_hours");
|
2013-04-18 23:35:02 +02:00
|
|
|
return openingHours;
|
|
|
|
}
|
|
|
|
|
2013-11-10 16:54:28 +01:00
|
|
|
public String getAdditionalInfo(String key){
|
|
|
|
if(additionalInfo == null) {
|
|
|
|
return null;
|
|
|
|
}
|
2015-05-27 00:28:24 +02:00
|
|
|
String str = additionalInfo.get(key);
|
2015-06-14 14:36:49 +02:00
|
|
|
str = unzipContent(str);
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String unzipContent(String str) {
|
2015-05-27 00:28:24 +02:00
|
|
|
if (str != null) {
|
|
|
|
if (str.startsWith(" gz ")) {
|
|
|
|
try {
|
|
|
|
int ind = 4;
|
|
|
|
byte[] bytes = new byte[str.length() - ind];
|
|
|
|
for (int i = ind; i < str.length(); i++) {
|
|
|
|
char ch = str.charAt(i);
|
|
|
|
bytes[i - ind] = (byte) ((int) ch - 128 - 32);
|
|
|
|
|
|
|
|
}
|
|
|
|
GZIPInputStream gzn = new GZIPInputStream(new ByteArrayInputStream(bytes));
|
|
|
|
BufferedReader br = new BufferedReader(new InputStreamReader(gzn, "UTF-8"));
|
|
|
|
StringBuilder bld = new StringBuilder();
|
|
|
|
String s;
|
|
|
|
while ((s = br.readLine()) != null) {
|
|
|
|
bld.append(s);
|
|
|
|
}
|
2015-11-18 15:52:15 +01:00
|
|
|
br.close();
|
2015-05-27 00:28:24 +02:00
|
|
|
str = bld.toString();
|
|
|
|
} catch (IOException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return str;
|
2013-11-10 16:54:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public Map<String, String> getAdditionalInfo() {
|
|
|
|
if(additionalInfo == null) {
|
|
|
|
return Collections.emptyMap();
|
|
|
|
}
|
|
|
|
return additionalInfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setAdditionalInfo(Map<String, String> additionalInfo) {
|
2015-06-29 17:26:32 +02:00
|
|
|
this.additionalInfo = null;
|
|
|
|
openingHours = null;
|
|
|
|
if(additionalInfo != null) {
|
|
|
|
Iterator<Entry<String, String>> it = additionalInfo.entrySet().iterator();
|
|
|
|
while(it.hasNext()) {
|
|
|
|
Entry<String, String> e = it.next();
|
|
|
|
setAdditionalInfo(e.getKey(), e.getValue());
|
|
|
|
}
|
|
|
|
}
|
2013-11-10 16:54:28 +01:00
|
|
|
}
|
2014-08-17 15:42:09 +02:00
|
|
|
|
|
|
|
public void setRoutePoint(AmenityRoutePoint routePoint) {
|
|
|
|
this.routePoint = routePoint;
|
2014-08-05 11:09:15 +02:00
|
|
|
}
|
|
|
|
|
2014-08-17 15:42:09 +02:00
|
|
|
public AmenityRoutePoint getRoutePoint() {
|
|
|
|
return routePoint;
|
2014-08-05 11:09:15 +02:00
|
|
|
}
|
2013-11-13 14:13:48 +01:00
|
|
|
|
2013-11-10 16:54:28 +01:00
|
|
|
public void setAdditionalInfo(String tag, String value) {
|
2013-11-24 20:24:14 +01:00
|
|
|
if("name".equals(tag)) {
|
|
|
|
setName(value);
|
|
|
|
} else if("name:en".equals(tag)) {
|
|
|
|
setEnName(value);
|
2015-06-29 17:26:32 +02:00
|
|
|
} else if(tag.startsWith("name:")) {
|
|
|
|
setName(tag.substring("name:".length()), value);
|
2013-11-24 20:24:14 +01:00
|
|
|
} else {
|
2015-06-29 17:26:32 +02:00
|
|
|
if(this.additionalInfo == null){
|
|
|
|
this.additionalInfo = new LinkedHashMap<String, String>();
|
|
|
|
}
|
2013-11-24 20:24:14 +01:00
|
|
|
this.additionalInfo.put(tag, value);
|
|
|
|
if (OPENING_HOURS.equals(tag)) {
|
|
|
|
this.openingHours = value;
|
|
|
|
}
|
2013-11-13 14:13:48 +01:00
|
|
|
}
|
2013-11-10 16:54:28 +01:00
|
|
|
}
|
|
|
|
|
2013-04-18 23:35:02 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public String toString() {
|
|
|
|
return type.toString() + " : " + subType + " "+ getName();
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getSite() {
|
2013-11-24 19:45:00 +01:00
|
|
|
return getAdditionalInfo(WEBSITE);
|
2013-04-18 23:35:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void setSite(String site) {
|
2013-11-24 19:45:00 +01:00
|
|
|
setAdditionalInfo(WEBSITE, site);
|
2013-04-18 23:35:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public String getPhone() {
|
2013-11-24 19:45:00 +01:00
|
|
|
return getAdditionalInfo(PHONE);
|
2013-04-18 23:35:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void setPhone(String phone) {
|
2013-11-24 19:45:00 +01:00
|
|
|
setAdditionalInfo(PHONE, phone);
|
2013-04-18 23:35:02 +02:00
|
|
|
}
|
|
|
|
|
2015-06-16 00:03:17 +02:00
|
|
|
public String getContentSelected(String tag, String lang, String defLang) {
|
2015-06-08 01:50:53 +02:00
|
|
|
if (lang != null) {
|
2015-06-16 00:03:17 +02:00
|
|
|
String translateName = getAdditionalInfo(tag + ":" + lang);
|
2015-06-08 01:50:53 +02:00
|
|
|
if (!Algorithms.isEmpty(translateName)) {
|
|
|
|
return lang;
|
|
|
|
}
|
|
|
|
}
|
2015-06-20 23:43:25 +02:00
|
|
|
String plainContent = getAdditionalInfo(tag);
|
|
|
|
if (!Algorithms.isEmpty(plainContent)) {
|
2015-06-15 10:41:52 +02:00
|
|
|
return defLang;
|
|
|
|
}
|
2015-06-16 00:03:17 +02:00
|
|
|
String enName = getAdditionalInfo(tag + ":en");
|
|
|
|
if (!Algorithms.isEmpty(enName)) {
|
|
|
|
return enName;
|
|
|
|
}
|
2015-06-20 23:43:25 +02:00
|
|
|
int maxLen = 0;
|
|
|
|
String lng = defLang;
|
2015-06-08 01:50:53 +02:00
|
|
|
for (String nm : getAdditionalInfo().keySet()) {
|
2015-06-20 23:43:25 +02:00
|
|
|
if (nm.startsWith(tag+":")) {
|
|
|
|
String key = nm.substring(tag.length() + 1);
|
|
|
|
String cnt = getAdditionalInfo(tag+":"+key);
|
|
|
|
if(!Algorithms.isEmpty(cnt) && cnt.length() > maxLen) {
|
|
|
|
maxLen = cnt.length();
|
|
|
|
lng = key;
|
|
|
|
}
|
2015-06-08 01:50:53 +02:00
|
|
|
}
|
|
|
|
}
|
2015-06-20 23:43:25 +02:00
|
|
|
return lng;
|
2015-06-08 01:50:53 +02:00
|
|
|
}
|
|
|
|
|
2015-06-14 19:10:46 +02:00
|
|
|
public List<String> getNames(String tag, String defTag) {
|
2015-06-08 01:50:53 +02:00
|
|
|
List<String> l = new ArrayList<String>();
|
|
|
|
for (String nm : getAdditionalInfo().keySet()) {
|
2015-06-14 14:36:49 +02:00
|
|
|
if (nm.startsWith(tag+":")) {
|
|
|
|
l.add(nm.substring(tag.length() +1));
|
2015-06-14 19:10:46 +02:00
|
|
|
} else if(nm.equals(tag)) {
|
|
|
|
l.add(defTag);
|
2015-06-08 01:50:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return l;
|
|
|
|
}
|
|
|
|
|
2015-05-27 00:09:48 +02:00
|
|
|
public String getContentLang(String tag, String lang) {
|
|
|
|
if (lang != null) {
|
|
|
|
String translateName = getAdditionalInfo(tag + ":" + lang);
|
|
|
|
if (!Algorithms.isEmpty(translateName)) {
|
|
|
|
return translateName;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
String plainName = getAdditionalInfo(tag);
|
|
|
|
if (!Algorithms.isEmpty(plainName)) {
|
|
|
|
return plainName;
|
|
|
|
}
|
|
|
|
String enName = getAdditionalInfo(tag + ":en");
|
|
|
|
if (!Algorithms.isEmpty(enName)) {
|
|
|
|
return enName;
|
|
|
|
}
|
2015-05-27 00:28:24 +02:00
|
|
|
for (String nm : getAdditionalInfo().keySet()) {
|
2015-05-27 00:09:48 +02:00
|
|
|
if (nm.startsWith(tag + ":")) {
|
|
|
|
return getAdditionalInfo(nm);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getDescription(String lang) {
|
|
|
|
String info = getContentLang(DESCRIPTION, lang);
|
|
|
|
if(!Algorithms.isEmpty(info)) {
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
return getContentLang(CONTENT, lang);
|
2013-04-18 23:35:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void setDescription(String description) {
|
2013-11-24 19:45:00 +01:00
|
|
|
setAdditionalInfo(DESCRIPTION, description);
|
2013-04-18 23:35:02 +02:00
|
|
|
}
|
|
|
|
|
2013-11-13 14:13:48 +01:00
|
|
|
public void setOpeningHours(String openingHours) {
|
2013-11-24 19:45:00 +01:00
|
|
|
setAdditionalInfo(OPENING_HOURS, openingHours);
|
2013-11-13 14:13:48 +01:00
|
|
|
}
|
|
|
|
|
2016-05-30 22:09:20 +02:00
|
|
|
|
2013-04-18 23:35:02 +02:00
|
|
|
}
|