Merge remote-tracking branch 'origin/master'

This commit is contained in:
Weblate 2015-04-06 23:46:31 +02:00
commit 4ff225af89
12 changed files with 288 additions and 312 deletions

View file

@ -3,7 +3,12 @@ package net.osmand.osm;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.text.Collator;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.TreeMap; import java.util.TreeMap;
@ -61,6 +66,33 @@ public class MapPoiTypes {
return otherCategory; return otherCategory;
} }
public List<PoiFilter> getTopVisibleFilters() {
List<PoiFilter> lf = new ArrayList<PoiFilter>();
for(PoiCategory pc : categories) {
if(pc.isTopVisible()) {
lf.add(pc);
}
for(PoiFilter p : pc.getPoiFilters()) {
if(p.isTopVisible()) {
lf.add(p);
}
}
}
sortList(lf);
return lf;
}
private void sortList(List<? extends PoiFilter> lf) {
final Collator instance = Collator.getInstance();
Collections.sort(lf, new Comparator<PoiFilter>() {
@Override
public int compare(PoiFilter object1, PoiFilter object2) {
return instance.compare(object1.getTranslation(), object2.getTranslation());
}
});
}
public PoiCategory getUserDefinedCategory() { public PoiCategory getUserDefinedCategory() {
return otherCategory; return otherCategory;
} }
@ -70,21 +102,23 @@ public class MapPoiTypes {
return getPoiCategoryByName(name, false); return getPoiCategoryByName(name, false);
} }
public PoiType getPoiTypeByKey(String name) {
public PoiCategory getPoiCategoryBySubtypeName(String name) {
for(PoiCategory pc : categories) { for(PoiCategory pc : categories) {
PoiType pt = pc.getPoiTypeByKeyName(name); PoiType pt = pc.getPoiTypeByKeyName(name);
if(pt != null) { if(pt != null && !pt.isReference()) {
return pc; return pt;
} }
} }
return otherCategory; return null;
} }
public Map<String, PoiType> getAllTranslatedNames() { public Map<String, PoiType> getAllTranslatedNames() {
Map<String, PoiType> translation = new TreeMap<String, PoiType>(); Map<String, PoiType> translation = new TreeMap<String, PoiType>();
for(PoiCategory pc : categories) { for(PoiCategory pc : categories) {
for(PoiType pt : pc.getPoiTypes()) { for(PoiType pt : pc.getPoiTypes()) {
if(pt.isReference()) {
continue;
}
translation.put(pt.getTranslation(), pt); translation.put(pt.getTranslation(), pt);
} }
} }
@ -126,11 +160,14 @@ public class MapPoiTypes {
public void setPoiTranslator(PoiTranslator poiTranslator) { public void setPoiTranslator(PoiTranslator poiTranslator) {
this.poiTranslator = poiTranslator; this.poiTranslator = poiTranslator;
sortList(categories);
} }
public void init(){ public void init(){
InputStream is; InputStream is;
List<PoiType> referenceTypes = new ArrayList<PoiType>();
try { try {
if(resourceName == null){ if(resourceName == null){
is = MapRenderingTypes.class.getResourceAsStream("poi_types.xml"); //$NON-NLS-1$ is = MapRenderingTypes.class.getResourceAsStream("poi_types.xml"); //$NON-NLS-1$
@ -148,16 +185,19 @@ public class MapPoiTypes {
String name = parser.getName(); String name = parser.getName();
if (name.equals("poi_category")) { if (name.equals("poi_category")) {
lastCategory = new PoiCategory(this, parser.getAttributeValue("","name"), categories.size()); lastCategory = new PoiCategory(this, parser.getAttributeValue("","name"), categories.size());
lastCategory.setTopVisible(Boolean.parseBoolean(parser.getAttributeValue("","top")));
categories.add(lastCategory); categories.add(lastCategory);
} else if (name.equals("poi_filter")) { } else if (name.equals("poi_filter")) {
PoiFilter tp = new PoiFilter(this, lastCategory, PoiFilter tp = new PoiFilter(this, lastCategory,
parser.getAttributeValue("", "name")); parser.getAttributeValue("", "name"));
tp.setTopVisible(Boolean.parseBoolean(parser.getAttributeValue("","top")));
lastFilter = tp; lastFilter = tp;
lastCategory.addPoiType(tp); lastCategory.addPoiType(tp);
} else if(name.equals("poi_reference")){ } else if(name.equals("poi_reference")){
PoiType tp = new PoiType(this, PoiType tp = new PoiType(this,
lastCategory, parser.getAttributeValue("","name")); lastCategory, parser.getAttributeValue("","name"));
tp.setReference(true); referenceTypes.add(tp);
tp.setReferenceType(tp);
if(lastFilter != null) { if(lastFilter != null) {
lastFilter.addPoiType(tp); lastFilter.addPoiType(tp);
} }
@ -197,6 +237,14 @@ public class MapPoiTypes {
e.printStackTrace(); e.printStackTrace();
throw new RuntimeException(e); throw new RuntimeException(e);
} }
for (PoiType gt : referenceTypes) {
PoiType pt = getPoiTypeByKey(gt.keyName);
if (pt == null || pt.getOsmTag() == null) {
throw new IllegalStateException("Can't find poi type for poi reference '" + gt.keyName + "'");
} else {
gt.setReferenceType(pt);
}
}
findDefaultOtherCategory(); findDefaultOtherCategory();
init = true; init = true;
} }
@ -229,14 +277,25 @@ public class MapPoiTypes {
private static void print(String indent, PoiFilter f) { private static void print(String indent, PoiFilter f) {
for(PoiType pt : f.getPoiTypes()) { for(PoiType pt : f.getPoiTypes()) {
System.out.println(indent + " Type " + pt.getName()); System.out.println(indent + " Type " + pt.getName() +
(pt.isReference() ? (" -> " + pt.getReferenceType().getCategory().getKey() ): ""));
} }
} }
public static void main(String[] args) { public static void main(String[] args) {
DEFAULT_INSTANCE = new MapPoiTypes("/Users/victorshcherb/osmand/repos/resources/poi/poi_types.xml"); DEFAULT_INSTANCE = new MapPoiTypes("/Users/victorshcherb/osmand/repos/resources/poi/poi_types.xml");
DEFAULT_INSTANCE.init(); DEFAULT_INSTANCE.init();
print(DEFAULT_INSTANCE) ; // print(DEFAULT_INSTANCE) ;
// System.out.println("-----------------");
List<PoiFilter> lf = DEFAULT_INSTANCE.getTopVisibleFilters();
for(PoiFilter l : lf) {
System.out.println("----------------- " + l.getKeyName());
print("", l);
Map<PoiCategory, LinkedHashSet<String>> m =
l.putTypes(new LinkedHashMap<PoiCategory, LinkedHashSet<String>>());
System.out.println(m);
}
} }
public String getTranslation(AbstractPoiType abstractPoiType) { public String getTranslation(AbstractPoiType abstractPoiType) {
@ -253,9 +312,5 @@ public class MapPoiTypes {
public boolean isRegisteredType(PoiCategory t) { public boolean isRegisteredType(PoiCategory t) {
return getPoiCategoryByName(t.getKeyName()) != otherCategory; return getPoiCategoryByName(t.getKeyName()) != otherCategory;
} }
} }

View file

@ -1,7 +1,9 @@
package net.osmand.osm; package net.osmand.osm;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List; import java.util.List;
import java.util.Map;
public class PoiCategory extends PoiFilter { public class PoiCategory extends PoiFilter {
@ -33,6 +35,13 @@ public class PoiCategory extends PoiFilter {
public void setDefaultTag(String defaultTag) { public void setDefaultTag(String defaultTag) {
this.defaultTag = defaultTag; this.defaultTag = defaultTag;
} }
public Map<PoiCategory, LinkedHashSet<String>> putTypes(
Map<PoiCategory, LinkedHashSet<String>> acceptedTypes) {
acceptedTypes.put(this, null);
addReferenceTypes(acceptedTypes);
return acceptedTypes;
}
public boolean isWiki() { public boolean isWiki() {
@ -47,4 +56,6 @@ public class PoiCategory extends PoiFilter {
return regId; return regId;
} }
} }

View file

@ -2,12 +2,14 @@ package net.osmand.osm;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
public class PoiFilter extends AbstractPoiType { public class PoiFilter extends AbstractPoiType {
private PoiCategory pc; private PoiCategory pc;
private boolean topVisible;
private List<PoiType> poiTypes = new ArrayList<PoiType>(); private List<PoiType> poiTypes = new ArrayList<PoiType>();
private Map<String, PoiType> map = new LinkedHashMap<String, PoiType>(); private Map<String, PoiType> map = new LinkedHashMap<String, PoiType>();
@ -28,6 +30,40 @@ public class PoiFilter extends AbstractPoiType {
if(!map.containsKey(type.getName())) { if(!map.containsKey(type.getName())) {
poiTypes.add(type); poiTypes.add(type);
map.put(type.getName(), type); map.put(type.getName(), type);
} else {
PoiType prev = map.get(type.getName());
if(prev.isReference()) {
poiTypes.remove(prev);
poiTypes.add(type);
map.put(type.getName(), type);
}
}
}
public Map<PoiCategory, LinkedHashSet<String>> putTypes(Map<PoiCategory, LinkedHashSet<String>> acceptedTypes) {
if (!acceptedTypes.containsKey(pc)) {
acceptedTypes.put(pc, new LinkedHashSet<String>());
}
LinkedHashSet<String> set = acceptedTypes.get(pc);
for (PoiType pt : poiTypes) {
set.add(pt.getKeyName());
}
addReferenceTypes(acceptedTypes);
return acceptedTypes;
}
protected void addReferenceTypes(Map<PoiCategory, LinkedHashSet<String>> acceptedTypes) {
for (PoiType pt : getPoiTypes()) {
if (pt.isReference()) {
PoiCategory refCat = pt.getReferenceType().getCategory();
if (!acceptedTypes.containsKey(refCat)) {
acceptedTypes.put(refCat, new LinkedHashSet<String>());
}
LinkedHashSet<String> ls = acceptedTypes.get(refCat);
if (ls != null) {
ls.add(pt.getKeyName());
}
}
} }
} }
@ -39,5 +75,12 @@ public class PoiFilter extends AbstractPoiType {
return keyName; return keyName;
} }
public void setTopVisible(boolean topVisible) {
this.topVisible = topVisible;
}
public boolean isTopVisible() {
return topVisible;
}
} }

View file

@ -1,15 +1,35 @@
package net.osmand.osm; package net.osmand.osm;
public class PoiType extends AbstractPoiType { public class PoiType extends AbstractPoiType {
private PoiCategory category;
private PoiType referenceType;
private String osmTag;
private String osmTag2;
private String osmValue;
private String osmValue2;
public PoiType(MapPoiTypes poiTypes, PoiCategory category, String name) {
public PoiType(MapPoiTypes poiTypes, PoiCategory category, String name){
super(name, poiTypes); super(name, poiTypes);
this.category = category; this.category = category;
} }
public PoiType getReferenceType() {
return referenceType;
}
public void setReferenceType(PoiType referenceType) {
this.referenceType = referenceType;
}
public boolean isReference() {
return referenceType != null;
}
public String getOsmTag() { public String getOsmTag() {
if(isReference()) {
return referenceType.getOsmTag();
}
return osmTag; return osmTag;
} }
@ -18,6 +38,9 @@ public class PoiType extends AbstractPoiType {
} }
public String getOsmTag2() { public String getOsmTag2() {
if(isReference()) {
return referenceType.getOsmTag2();
}
return osmTag2; return osmTag2;
} }
@ -26,6 +49,9 @@ public class PoiType extends AbstractPoiType {
} }
public String getOsmValue() { public String getOsmValue() {
if(isReference()) {
return referenceType.getOsmValue();
}
return osmValue; return osmValue;
} }
@ -34,6 +60,9 @@ public class PoiType extends AbstractPoiType {
} }
public String getOsmValue2() { public String getOsmValue2() {
if(isReference()) {
return referenceType.getOsmValue2();
}
return osmValue2; return osmValue2;
} }
@ -41,21 +70,9 @@ public class PoiType extends AbstractPoiType {
this.osmValue2 = osmValue2; this.osmValue2 = osmValue2;
} }
private PoiCategory category;
private String osmTag;
private String osmTag2;
private String osmValue;
private String osmValue2;
public PoiCategory getCategory() { public PoiCategory getCategory() {
return category; return category;
} }
public void setReference(boolean b) {
}
} }

View file

@ -380,10 +380,6 @@ public class MapActivity extends AccessibleActivity {
String filterId = settings.getPoiFilterForMap(); String filterId = settings.getPoiFilterForMap();
PoiLegacyFilter poiFilter = app.getPoiFilters().getFilterById(filterId); PoiLegacyFilter poiFilter = app.getPoiFilters().getFilterById(filterId);
if (poiFilter == null) {
poiFilter = new PoiLegacyFilter(null, app);
}
mapLayers.getPoiMapLayer().setFilter(poiFilter); mapLayers.getPoiMapLayer().setFilter(poiFilter);
// if destination point was changed try to recalculate route // if destination point was changed try to recalculate route

View file

@ -259,16 +259,13 @@ public class MapActivityLayers {
OsmandApplication app = (OsmandApplication)getApplication(); OsmandApplication app = (OsmandApplication)getApplication();
final PoiFiltersHelper poiFilters = app.getPoiFilters(); final PoiFiltersHelper poiFilters = app.getPoiFilters();
final ContextMenuAdapter adapter = new ContextMenuAdapter(activity); final ContextMenuAdapter adapter = new ContextMenuAdapter(activity);
final List<PoiLegacyFilter> list = new ArrayList<PoiLegacyFilter>();
Item is = adapter.item(getString(R.string.any_poi)); for (PoiLegacyFilter f : poiFilters.getTopDefinedPoiFilters()) {
if(RenderingIcons.containsBigIcon("null")) { if(PoiLegacyFilter.BY_NAME_FILTER_ID.equals(f.getFilterId()) ||
is.icon(RenderingIcons.getBigIconResourceId("null")); PoiLegacyFilter.NAME_FINDER_FILTER_ID.equals(f.getFilterId())) {
} continue;
is.reg(); }
// 2nd custom list.add(f);
adapter.item(getString(R.string.poi_filter_custom_filter)).icon(RenderingIcons.getBigIconResourceId("user_defined")).reg();
for (PoiLegacyFilter f : poiFilters.getUserDefinedPoiFilters()) {
Item it = adapter.item(f.getName()); Item it = adapter.item(f.getName());
if (RenderingIcons.containsBigIcon(f.getSimplifiedId())) { if (RenderingIcons.containsBigIcon(f.getSimplifiedId())) {
it.icon(RenderingIcons.getBigIconResourceId(f.getSimplifiedId())); it.icon(RenderingIcons.getBigIconResourceId(f.getSimplifiedId()));
@ -278,22 +275,15 @@ public class MapActivityLayers {
it.reg(); it.reg();
userDefined.add(f); userDefined.add(f);
} }
final List<PoiCategory> categories = getApplication().getPoiTypes().getCategories();
for(PoiCategory t : categories){
Item it = adapter.item(t.getTranslation());
if(RenderingIcons.containsBigIcon(t.getKeyName())) {
it.icon(RenderingIcons.getBigIconResourceId(t.getKeyName()));
}
it.reg();
}
Builder builder = new AlertDialog.Builder(activity); Builder builder = new AlertDialog.Builder(activity);
ListAdapter listAdapter =adapter.createListAdapter(activity, app.getSettings().isLightContent()); ListAdapter listAdapter = adapter.createListAdapter(activity, app.getSettings().isLightContent());
builder.setAdapter(listAdapter, new DialogInterface.OnClickListener(){ builder.setAdapter(listAdapter, new DialogInterface.OnClickListener(){
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
if(which == 1){ PoiLegacyFilter pf = list.get(which);
String filterId = PoiLegacyFilter.CUSTOM_FILTER_ID; String filterId = pf.getFilterId();
if(filterId.equals(PoiLegacyFilter.CUSTOM_FILTER_ID)){
getApplication().getSettings().setPoiFilterForMap(filterId); getApplication().getSettings().setPoiFilterForMap(filterId);
Intent newIntent = new Intent(activity, EditPOIFilterActivity.class); Intent newIntent = new Intent(activity, EditPOIFilterActivity.class);
newIntent.putExtra(EditPOIFilterActivity.AMENITY_FILTER, filterId); newIntent.putExtra(EditPOIFilterActivity.AMENITY_FILTER, filterId);
@ -301,23 +291,15 @@ public class MapActivityLayers {
newIntent.putExtra(EditPOIFilterActivity.SEARCH_LON, mapView.getLongitude()); newIntent.putExtra(EditPOIFilterActivity.SEARCH_LON, mapView.getLongitude());
activity.startActivity(newIntent); activity.startActivity(newIntent);
} else { } else {
String filterId;
if (which == 0) {
filterId = PoiFiltersHelper.getOsmDefinedFilterId(null);
} else if (which <= userDefined.size() + 1) {
filterId = userDefined.get(which - 2).getFilterId();
} else {
filterId = PoiFiltersHelper.getOsmDefinedFilterId(categories.get(which - userDefined.size() - 2));
}
getApplication().getSettings().setPoiFilterForMap(filterId); getApplication().getSettings().setPoiFilterForMap(filterId);
PoiLegacyFilter f = poiFilters.getFilterById(filterId); pf = poiFilters.getFilterById(filterId);
if (f != null) { if (pf != null && pf.isStandardFilter()) {
f.clearNameFilter(); pf.clearNameFilter();
} }
poiMapLayer.setFilter(f); poiMapLayer.setFilter(pf);
mapView.refreshMap(); mapView.refreshMap();
if(selected != null && selected.length > 0) { if(selected != null && selected.length > 0) {
selected[0] = f; selected[0] = pf;
} }
} }
} }

View file

@ -71,10 +71,7 @@ public class SearchPoiFilterFragment extends ListFragment implements SearchActiv
public void refreshPoiListAdapter() { public void refreshPoiListAdapter() {
PoiFiltersHelper poiFilters = getApp().getPoiFilters(); PoiFiltersHelper poiFilters = getApp().getPoiFilters();
List<PoiLegacyFilter> filters = new ArrayList<PoiLegacyFilter>() ; List<PoiLegacyFilter> filters = new ArrayList<PoiLegacyFilter>() ;
filters.addAll(poiFilters.getTopStandardFilters()); filters.addAll(poiFilters.getTopDefinedPoiFilters());
filters.addAll(poiFilters.getUserDefinedPoiFilters());
filters.addAll(poiFilters.getOsmDefinedPoiFilters());
filters.add(poiFilters.getNameFinderPOIFilter());
setListAdapter(new AmenityAdapter(filters)); setListAdapter(new AmenityAdapter(filters));
} }

View file

@ -24,7 +24,7 @@ import org.xmlpull.v1.XmlPullParserException;
public class NameFinderPoiFilter extends PoiLegacyFilter { public class NameFinderPoiFilter extends PoiLegacyFilter {
public static final String FILTER_ID = "name_finder"; //$NON-NLS-1$ public static final String FILTER_ID = NAME_FINDER_FILTER_ID; //$NON-NLS-1$
private static final Log log = PlatformUtil.getLog(NameFinderPoiFilter.class); private static final Log log = PlatformUtil.getLog(NameFinderPoiFilter.class);
private static final int LIMIT = 300; private static final int LIMIT = 300;

View file

@ -12,6 +12,7 @@ import java.util.Map;
import net.osmand.osm.MapPoiTypes; import net.osmand.osm.MapPoiTypes;
import net.osmand.osm.PoiCategory; import net.osmand.osm.PoiCategory;
import net.osmand.osm.PoiFilter;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.api.SQLiteAPI.SQLiteConnection; import net.osmand.plus.api.SQLiteAPI.SQLiteConnection;
@ -23,8 +24,6 @@ public class PoiFiltersHelper {
private NameFinderPoiFilter nameFinderPOIFilter; private NameFinderPoiFilter nameFinderPOIFilter;
private List<PoiLegacyFilter> cacheTopStandardFilters; private List<PoiLegacyFilter> cacheTopStandardFilters;
private List<PoiLegacyFilter> cacheUserDefinedFilters;
private List<PoiLegacyFilter> cacheOsmDefinedFilters;
private static final String UDF_CAR_AID = "car_aid"; private static final String UDF_CAR_AID = "car_aid";
private static final String UDF_FOR_TOURISTS = "for_tourists"; private static final String UDF_FOR_TOURISTS = "for_tourists";
@ -37,7 +36,10 @@ public class PoiFiltersHelper {
private static final String UDF_RESTAURANTS = "restaurants"; private static final String UDF_RESTAURANTS = "restaurants";
private static final String UDF_PARKING = "parking"; private static final String UDF_PARKING = "parking";
private static final String[] DEL = new String[] {}; private static final String[] DEL = new String[] {
UDF_CAR_AID, UDF_FOR_TOURISTS, UDF_FOOD_SHOP, UDF_FUEL, UDF_SIGHTSEEING, UDF_EMERGENCY,
UDF_PUBLIC_TRANSPORT, UDF_ACCOMMODATION, UDF_RESTAURANTS, UDF_PARKING
};
public PoiFiltersHelper(OsmandApplication application){ public PoiFiltersHelper(OsmandApplication application){
this.application = application; this.application = application;
@ -50,202 +52,96 @@ public class PoiFiltersHelper {
} }
private PoiLegacyFilter findPoiFilter(String filterId, List<PoiLegacyFilter>... collections) {
for(List<PoiLegacyFilter> c : collections) { public PoiLegacyFilter getFilterById(String filterId){
for(PoiLegacyFilter f : c) { if(filterId == null){
if(f.getFilterId().equals(filterId)){ return null;
return f; }
} for(PoiLegacyFilter f : getTopDefinedPoiFilters()) {
if(f.getFilterId().equals(filterId)){
return f;
} }
} }
return null; return null;
} }
@SuppressWarnings("unchecked")
public PoiLegacyFilter getFilterById(String filterId){
if(filterId == null){
return null;
}
if(filterId.equals(NameFinderPoiFilter.FILTER_ID)){
return getNameFinderPOIFilter();
}
return findPoiFilter(filterId, getUserDefinedPoiFilters(), getTopStandardFilters(), getOsmDefinedPoiFilters());
}
private void putAll(MapPoiTypes poiTypes, Map<PoiCategory, LinkedHashSet<String>> types, String tp) {
types.put(poiTypes.getPoiCategoryByName(tp), null);
}
private void putValues(MapPoiTypes poiTypes, Map<PoiCategory, LinkedHashSet<String>> types, String p, String... vls) {
LinkedHashSet<String> list = new LinkedHashSet<String>();
Collections.addAll(list, vls);
PoiCategory pc = poiTypes.getPoiCategoryByName(p);
if(pc == null) {
throw new NullPointerException("Category " + p + " was not found");
}
types.put(poiTypes.getPoiCategoryByName(p), list);
}
private List<PoiLegacyFilter> getUserDefinedDefaultFilters(MapPoiTypes poiTypes) {
List<PoiLegacyFilter> filters = new ArrayList<PoiLegacyFilter>();
filters.add(new PoiLegacyFilter(application.getString(R.string.poi_filter_accomodation), PoiLegacyFilter.USER_PREFIX + UDF_ACCOMMODATION,
configureDefaultUserDefinedFilter(poiTypes, UDF_ACCOMMODATION), application));
filters.add(new PoiLegacyFilter(application.getString(R.string.poi_filter_car_aid), PoiLegacyFilter.USER_PREFIX + UDF_CAR_AID,
configureDefaultUserDefinedFilter(poiTypes, UDF_CAR_AID), application));
filters.add(new PoiLegacyFilter(application.getString(R.string.poi_filter_food_shop), PoiLegacyFilter.USER_PREFIX + UDF_FOOD_SHOP,
configureDefaultUserDefinedFilter(poiTypes, UDF_FOOD_SHOP), application));
filters.add(new PoiLegacyFilter(application.getString(R.string.poi_filter_for_tourists), PoiLegacyFilter.USER_PREFIX + UDF_FOR_TOURISTS,
configureDefaultUserDefinedFilter(poiTypes, UDF_FOR_TOURISTS), application));
filters.add(new PoiLegacyFilter(application.getString(R.string.poi_filter_fuel), PoiLegacyFilter.USER_PREFIX + UDF_FUEL,
configureDefaultUserDefinedFilter(poiTypes, UDF_FUEL), application));
filters.add(new PoiLegacyFilter(application.getString(R.string.poi_filter_parking), PoiLegacyFilter.USER_PREFIX + UDF_PARKING,
configureDefaultUserDefinedFilter(poiTypes, UDF_PARKING), application));
filters.add(new PoiLegacyFilter(application.getString(R.string.poi_filter_public_transport),
PoiLegacyFilter.USER_PREFIX + UDF_PUBLIC_TRANSPORT, configureDefaultUserDefinedFilter(poiTypes, UDF_PUBLIC_TRANSPORT), application));
filters.add(new PoiLegacyFilter(application.getString(R.string.poi_filter_restaurants), PoiLegacyFilter.USER_PREFIX + UDF_RESTAURANTS,
configureDefaultUserDefinedFilter(poiTypes, UDF_RESTAURANTS), application));
filters.add(new PoiLegacyFilter(application.getString(R.string.poi_filter_sightseeing), PoiLegacyFilter.USER_PREFIX + UDF_SIGHTSEEING,
configureDefaultUserDefinedFilter(poiTypes, UDF_SIGHTSEEING), application));
// UDF_EMERGENCY = "emergency";
// UDF_ENTERTAINMENT = "entertainment";
return filters;
}
private Map<PoiCategory, LinkedHashSet<String>> configureDefaultUserDefinedFilter(MapPoiTypes poiTypes, String key) {
Map<PoiCategory, LinkedHashSet<String>> types = new LinkedHashMap<PoiCategory, LinkedHashSet<String>>();
if(UDF_ACCOMMODATION.equals(key)){
putValues(poiTypes, types, "tourism", "camp_site",
"caravan_site","picnic_site","alpine_hut", "chalet","guest_house",
"hostel", "hotel","motel");
} else if (UDF_CAR_AID.equals(key)) {
putValues(poiTypes, types, "transportation", "fuel", "car_wash", "car_repair","car", "car_sharing");
putValues(poiTypes, types, "shop", "fuel", "car_wash", "car_repair","car", "car_parts");
} else if (UDF_FOOD_SHOP.equals(key)) {
putValues(poiTypes, types, "shop", "alcohol", "bakery", "beverages", "butcher", "convenience", "department_store",
"convenience", "farm", "general", "ice_cream", "kiosk", "seafood", "supermarket", "variety_store");
} else if(UDF_FOR_TOURISTS.equals(key)){
putAll(poiTypes, types, "tourism");
putAll(poiTypes, types, "finance");
putAll(poiTypes, types, "osmwiki");
} else if(UDF_FUEL.equals(key)){
putValues(poiTypes, types, "transportation", "fuel");
} else if (UDF_PARKING.equals(key)) {
putValues(poiTypes, types, "transportation", "parking",
"bicycle_parking");
} else if (UDF_PUBLIC_TRANSPORT.equals(key)) {
putValues(poiTypes, types, "transportation", "public_transport_stop_position", "public_transport_platform",
"public_transport_station",
// railway
"railway_platform", "railway_station", "halt", "tram_stop", "subway_entrance", "railway_buffer_stop",
// bus, cars, bicycle
"bus_stop", "platform", "ferry_terminal", "taxi", "bicycle_rental", "bus_station", "car_rental", "car_sharing",
// aero
"airport", "aerodrome", "terminal", "gate",
// aerial ways ( hide ways)
// "aerialway_cable_car", "aerialway_gondola", "aerialway_chair_lift", "aerialway_mixed_lift", "aerialway_drag_lift", "aerialway_goods",
"aerialway_station"
// ways (hide ways)
// "rail", "tram", "light_rail", "subway", "railway_narrow_gauge", "railway_monorail", "railway_funicular"
);
} else if (UDF_RESTAURANTS.equals(key)) {
putValues(poiTypes, types, "sustenance", "restaurant_not_found",
"cafe", "food_court", "pub", "bar", "biergarten");
} else if (UDF_SIGHTSEEING.equals(key)) {
// TODO filter only sightseeing from tourimsm
// putValues(types, "tourism", "...","...");
putAll(poiTypes, types, "tourism");
putAll(poiTypes, types, "osmwiki");
} else if (UDF_EMERGENCY.equals(key)) {
putAll(poiTypes, types, "healthcare");
putAll(poiTypes, types, "emergency");
}
return types;
}
public void reloadAllPoiFilters() { public void reloadAllPoiFilters() {
cacheOsmDefinedFilters = null;
cacheTopStandardFilters = null; cacheTopStandardFilters = null;
cacheUserDefinedFilters = null; getTopDefinedPoiFilters();
getUserDefinedPoiFilters(); }
getTopStandardFilters();
getOsmDefinedPoiFilters();
private List<PoiLegacyFilter> getUserDefinedPoiFilters() {
ArrayList<PoiLegacyFilter> userDefinedFilters = new ArrayList<PoiLegacyFilter>();
PoiFilterDbHelper helper = openDbHelper();
if (helper != null) {
List<PoiLegacyFilter> userDefined = helper.getFilters(helper.getReadableDatabase());
userDefinedFilters.addAll(userDefined);
helper.close();
}
return userDefinedFilters;
}
public void sortListOfFilters(List<PoiLegacyFilter> list) {
final Collator instance = Collator.getInstance();
Collections.sort(list, new Comparator<PoiLegacyFilter>() {
private int getRank(PoiLegacyFilter lf) {
if(PoiLegacyFilter.BY_NAME_FILTER_ID.equals(lf.getFilterId())) {
return 0;
} else if(lf.areAllTypesAccepted()) {
return 3;
} else if(PoiLegacyFilter.CUSTOM_FILTER_ID.equals(lf.getFilterId())) {
return 4;
} else if(PoiLegacyFilter.NAME_FINDER_FILTER_ID.equals(lf.getFilterId())) {
return 5;
} else if(lf.isStandardFilter()) {
return 2;
}
return 1;
}
@Override
public int compare(PoiLegacyFilter lhs, PoiLegacyFilter rhs) {
int lr = getRank(lhs);
int rr = getRank(rhs);
if(lr != rr) {
return lr < rr ? -1 : 1;
}
return instance.compare(lhs.getName(), rhs.getName());
}
});
} }
public List<PoiLegacyFilter> getTopDefinedPoiFilters() {
public List<PoiLegacyFilter> getUserDefinedPoiFilters(){
if(cacheUserDefinedFilters == null){
cacheUserDefinedFilters = new ArrayList<PoiLegacyFilter>();
PoiFilterDbHelper helper = openDbHelper();
if (helper != null) {
List<PoiLegacyFilter> userDefined = helper.getFilters(helper.getReadableDatabase());
sortListOfFiltersByName(userDefined);
cacheUserDefinedFilters.addAll(userDefined);
helper.close();
}
}
return Collections.unmodifiableList(cacheUserDefinedFilters);
}
private void sortListOfFiltersByName(List<PoiLegacyFilter> userDefined) {
final Collator instance = Collator.getInstance();
Collections.sort(userDefined, new Comparator<PoiLegacyFilter>() {
@Override
public int compare(PoiLegacyFilter object1, PoiLegacyFilter object2) {
return instance.compare(object1.getName(), object2.getName());
}
});
}
public List<PoiLegacyFilter> getTopStandardFilters() {
if (cacheTopStandardFilters == null) { if (cacheTopStandardFilters == null) {
cacheTopStandardFilters = new ArrayList<PoiLegacyFilter>(); cacheTopStandardFilters = new ArrayList<PoiLegacyFilter>();
// by name
PoiLegacyFilter filter = new SearchByNameFilter(application); PoiLegacyFilter filter = new SearchByNameFilter(application);
filter.setStandardFilter(true); filter.setStandardFilter(true);
cacheTopStandardFilters.add(filter); cacheTopStandardFilters.add(filter);
// custom
filter = new PoiLegacyFilter(application.getString(R.string.poi_filter_custom_filter), filter = new PoiLegacyFilter(application.getString(R.string.poi_filter_custom_filter),
PoiLegacyFilter.CUSTOM_FILTER_ID, new LinkedHashMap<PoiCategory, LinkedHashSet<String>>(), application); //$NON-NLS-1$ PoiLegacyFilter.CUSTOM_FILTER_ID, new LinkedHashMap<PoiCategory, LinkedHashSet<String>>(), application); //$NON-NLS-1$
filter.setStandardFilter(true); filter.setStandardFilter(true);
cacheTopStandardFilters.add(filter); cacheTopStandardFilters.add(filter);
// all
cacheTopStandardFilters.add(new PoiLegacyFilter(null, application)); cacheTopStandardFilters.add(new PoiLegacyFilter(null, application));
// name finder
cacheTopStandardFilters.add(getNameFinderPOIFilter());
// user defined
cacheTopStandardFilters.addAll(getUserDefinedPoiFilters());
// default
MapPoiTypes poiTypes = application.getPoiTypes();
for (PoiFilter t : poiTypes.getTopVisibleFilters()) {
cacheTopStandardFilters.add(new PoiLegacyFilter(t, application));
}
sortListOfFilters(cacheTopStandardFilters);
} }
return Collections.unmodifiableList(cacheTopStandardFilters); return Collections.unmodifiableList(cacheTopStandardFilters);
} }
public static String getOsmDefinedFilterId(PoiCategory t){
return PoiLegacyFilter.STD_PREFIX + (t == null ? null : t.getKeyName());
}
public void updateFilters(boolean onlyAddFilters){
PoiFilterDbHelper helper = openDbHelper();
if(helper != null ) {
helper.upgradeFilters(helper.getWritableDatabase(), onlyAddFilters);
helper.close();
}
}
public List<PoiLegacyFilter> getOsmDefinedPoiFilters(){
if(cacheOsmDefinedFilters == null){
cacheOsmDefinedFilters = new ArrayList<PoiLegacyFilter>();
MapPoiTypes poiTypes = application.getPoiTypes();
for(PoiCategory t : poiTypes.getCategories()){
cacheOsmDefinedFilters.add(new PoiLegacyFilter(t, application));
}
final Collator instance = Collator.getInstance();
Collections.sort(cacheOsmDefinedFilters, new Comparator<PoiLegacyFilter>() {
@Override
public int compare(PoiLegacyFilter object1, PoiLegacyFilter object2) {
return instance.compare(object1.getName(), object2.getName());
}
});
}
return Collections.unmodifiableList(cacheOsmDefinedFilters);
}
private PoiFilterDbHelper openDbHelper(){ private PoiFilterDbHelper openDbHelper(){
if(!application.getPoiTypes().isInit()) { if(!application.getPoiTypes().isInit()) {
return null; return null;
@ -265,7 +161,7 @@ public class PoiFiltersHelper {
} }
boolean res = helper.deleteFilter(helper.getWritableDatabase(), filter); boolean res = helper.deleteFilter(helper.getWritableDatabase(), filter);
if(res){ if(res){
cacheUserDefinedFilters.remove(filter); cacheTopStandardFilters.remove(filter);
} }
helper.close(); helper.close();
return res; return res;
@ -278,8 +174,8 @@ public class PoiFiltersHelper {
} }
boolean res = helper.addFilter(filter, helper.getWritableDatabase(), false); boolean res = helper.addFilter(filter, helper.getWritableDatabase(), false);
if(res){ if(res){
cacheUserDefinedFilters.add(filter); cacheTopStandardFilters.add(filter);
sortListOfFiltersByName(cacheUserDefinedFilters); sortListOfFilters(cacheTopStandardFilters);
} }
helper.close(); helper.close();
return res; return res;
@ -305,7 +201,7 @@ public class PoiFiltersHelper {
public class PoiFilterDbHelper { public class PoiFilterDbHelper {
public static final String DATABASE_NAME = "poi_filters"; //$NON-NLS-1$ public static final String DATABASE_NAME = "poi_filters"; //$NON-NLS-1$
private static final int DATABASE_VERSION = 4; private static final int DATABASE_VERSION = 5;
private static final String FILTER_NAME = "poi_filters"; //$NON-NLS-1$ private static final String FILTER_NAME = "poi_filters"; //$NON-NLS-1$
private static final String FILTER_COL_NAME = "name"; //$NON-NLS-1$ private static final String FILTER_COL_NAME = "name"; //$NON-NLS-1$
private static final String FILTER_COL_ID = "id"; //$NON-NLS-1$ private static final String FILTER_COL_ID = "id"; //$NON-NLS-1$
@ -365,45 +261,23 @@ public class PoiFiltersHelper {
public void onCreate(SQLiteConnection conn) { public void onCreate(SQLiteConnection conn) {
conn.execSQL(FILTER_TABLE_CREATE); conn.execSQL(FILTER_TABLE_CREATE);
conn.execSQL(CATEGORIES_TABLE_CREATE); conn.execSQL(CATEGORIES_TABLE_CREATE);
upgradeFilters(conn, true);
} }
public void upgradeFilters(SQLiteConnection conn, boolean onlyAdd) {
List<PoiLegacyFilter> filters = PoiFilterDbHelper.this.getFilters( conn);
List<PoiLegacyFilter> def = getUserDefinedDefaultFilters(mapPoiTypes);
for(PoiLegacyFilter f : filters){
PoiLegacyFilter std = null;
for(PoiLegacyFilter d : def){
if(f.getFilterId().equals(d.getFilterId())){
std = d;
break;
}
}
for(String toDel : DEL) {
if(f.getFilterId().equals(toDel)) {
deleteFilter(conn, f);
}
}
if(std != null){
if(!onlyAdd){
editFilter(conn, std);
} else {
updateName(conn, std);
}
def.remove(std);
}
}
for(PoiLegacyFilter d : def){
addFilter(d, conn, false);
}
}
public void onUpgrade(SQLiteConnection conn, int oldVersion, int newVersion) { public void onUpgrade(SQLiteConnection conn, int oldVersion, int newVersion) {
upgradeFilters(conn, false); if(newVersion <= 5) {
deleteOldFilters(conn);
}
conn.setVersion(newVersion); conn.setVersion(newVersion);
} }
protected boolean addFilter(PoiLegacyFilter p, SQLiteConnection db, boolean addOnlyCategories){ private void deleteOldFilters(SQLiteConnection conn) {
for (String toDel : DEL) {
deleteFilter(conn, "user_" + toDel);
}
}
protected boolean addFilter(PoiLegacyFilter p, SQLiteConnection db, boolean addOnlyCategories){
if(db != null){ if(db != null){
if(!addOnlyCategories){ if(!addOnlyCategories){
db.execSQL("INSERT INTO " + FILTER_NAME + " VALUES (?, ?, ?)",new Object[]{p.getName(), p.getFilterId(), p.getFilterByName()}); //$NON-NLS-1$ //$NON-NLS-2$ db.execSQL("INSERT INTO " + FILTER_NAME + " VALUES (?, ?, ?)",new Object[]{p.getName(), p.getFilterId(), p.getFilterByName()}); //$NON-NLS-1$ //$NON-NLS-2$
@ -493,13 +367,19 @@ public class PoiFiltersHelper {
} }
protected boolean deleteFilter(SQLiteConnection db, PoiLegacyFilter p){ protected boolean deleteFilter(SQLiteConnection db, PoiLegacyFilter p){
if(db != null){ String key = p.getFilterId();
db.execSQL("DELETE FROM " + FILTER_NAME + " WHERE " +FILTER_COL_ID + " = ?",new Object[]{p.getFilterId()}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ return deleteFilter(db, key);
db.execSQL("DELETE FROM " + CATEGORIES_NAME + " WHERE " +CATEGORIES_FILTER_ID + " = ?", new Object[]{p.getFilterId()}); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
return true;
}
return false;
} }
private boolean deleteFilter(SQLiteConnection db, String key) {
if (db != null) {
db.execSQL("DELETE FROM " + FILTER_NAME + " WHERE " + FILTER_COL_ID + " = ?", new Object[] { key }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
db.execSQL(
"DELETE FROM " + CATEGORIES_NAME + " WHERE " + CATEGORIES_FILTER_ID + " = ?", new Object[] { key }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
return true;
}
return false;
}

View file

@ -14,6 +14,7 @@ import net.osmand.ResultMatcher;
import net.osmand.data.Amenity; import net.osmand.data.Amenity;
import net.osmand.osm.MapPoiTypes; import net.osmand.osm.MapPoiTypes;
import net.osmand.osm.PoiCategory; import net.osmand.osm.PoiCategory;
import net.osmand.osm.PoiFilter;
import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
@ -26,6 +27,7 @@ public class PoiLegacyFilter {
public final static String USER_PREFIX = "user_"; //$NON-NLS-1$ public final static String USER_PREFIX = "user_"; //$NON-NLS-1$
public final static String CUSTOM_FILTER_ID = USER_PREFIX + "custom_id"; //$NON-NLS-1$ public final static String CUSTOM_FILTER_ID = USER_PREFIX + "custom_id"; //$NON-NLS-1$
public final static String BY_NAME_FILTER_ID = USER_PREFIX + "by_name"; //$NON-NLS-1$ public final static String BY_NAME_FILTER_ID = USER_PREFIX + "by_name"; //$NON-NLS-1$
public static final String NAME_FINDER_FILTER_ID = "name_finder";
private Map<PoiCategory, LinkedHashSet<String>> acceptedTypes = new LinkedHashMap<PoiCategory, private Map<PoiCategory, LinkedHashSet<String>> acceptedTypes = new LinkedHashMap<PoiCategory,
LinkedHashSet<String>>(); LinkedHashSet<String>>();
@ -45,18 +47,20 @@ public class PoiLegacyFilter {
// constructor for standard filters // constructor for standard filters
public PoiLegacyFilter(PoiCategory type, OsmandApplication application){ public PoiLegacyFilter(PoiFilter type, OsmandApplication application) {
this.app = application; this.app = application;
isStandardFilter = true; isStandardFilter = true;
filterId = STD_PREFIX + (type == null? null: type.getName()); filterId = STD_PREFIX + (type == null ? null : type.getName());
poiTypes = application.getPoiTypes(); poiTypes = application.getPoiTypes();
name = type == null ? application.getString(R.string.poi_filter_closest_poi) : type.getTranslation(); //$NON-NLS-1$ name = type == null ? application.getString(R.string.poi_filter_closest_poi) : type.getTranslation(); //$NON-NLS-1$
if (type == null) { if (type == null) {
initSearchAll(); initSearchAll();
} else { } else {
acceptedTypes.put(type, null); type.putTypes(acceptedTypes);
} }
} }
// constructor for user defined filters // constructor for user defined filters
public PoiLegacyFilter(String name, String filterId, Map<PoiCategory, LinkedHashSet<String>> acceptedTypes, OsmandApplication app){ public PoiLegacyFilter(String name, String filterId, Map<PoiCategory, LinkedHashSet<String>> acceptedTypes, OsmandApplication app){

View file

@ -466,7 +466,6 @@ public class ResourceManager {
boolean isFirstInstall = context.getSettings().PREVIOUS_INSTALLED_VERSION.get().equals(""); boolean isFirstInstall = context.getSettings().PREVIOUS_INSTALLED_VERSION.get().equals("");
unpackBundledAssets(assetManager, applicationDataDir, progress, isFirstInstall); unpackBundledAssets(assetManager, applicationDataDir, progress, isFirstInstall);
context.getSettings().PREVIOUS_INSTALLED_VERSION.set(Version.getFullVersion(context)); context.getSettings().PREVIOUS_INSTALLED_VERSION.set(Version.getFullVersion(context));
context.getPoiFilters().updateFilters(false);
copyRegionsBoundaries(); copyRegionsBoundaries();
} catch (SQLiteException e) { } catch (SQLiteException e) {
log.error(e.getMessage(), e); log.error(e.getMessage(), e);

View file

@ -81,38 +81,30 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon
@Override @Override
protected List<Amenity> calculateResult(RotatedTileBox tileBox) { protected List<Amenity> calculateResult(RotatedTileBox tileBox) {
QuadRect latLonBounds = tileBox.getLatLonBounds(); QuadRect latLonBounds = tileBox.getLatLonBounds();
// if(path) { if (filter == null) {
// RouteCalculationResult result = routingHelper.getRoute(); return new ArrayList<Amenity>();
// return resourceManager.searchAmenitiesOnThePath(result.getImmutableAllLocations(), radius, filter, null); }
// } else { return resourceManager.searchAmenities(filter, latLonBounds.top, latLonBounds.left,
return resourceManager.searchAmenities(filter, latLonBounds.top, latLonBounds.left, latLonBounds.bottom, latLonBounds.right, tileBox.getZoom(), new ResultMatcher<Amenity>() {
latLonBounds.bottom, latLonBounds.right, tileBox.getZoom(), new ResultMatcher<Amenity>() {
@Override @Override
public boolean publish(Amenity object) { public boolean publish(Amenity object) {
return true; return true;
} }
@Override @Override
public boolean isCancelled() { public boolean isCancelled() {
return isInterrupted(); return isInterrupted();
} }
}); });
// }
} }
}; };
} }
public PoiLegacyFilter getFilter() {
return filter;
}
public void setFilter(PoiLegacyFilter filter) { public void setFilter(PoiLegacyFilter filter) {
this.filter = filter; this.filter = filter;
data.clearCache(); data.clearCache();
} }
public void getAmenityFromPoint(RotatedTileBox tb, PointF point, List<? super Amenity> am) { public void getAmenityFromPoint(RotatedTileBox tb, PointF point, List<? super Amenity> am) {
List<Amenity> objects = data.getResults(); List<Amenity> objects = data.getResults();