From 1b165d9853815b1c0d723a334e8bf9ff81c1079c Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Fri, 10 Apr 2015 19:06:20 +0200 Subject: [PATCH 1/4] Filter by type fuel --- .../src/net/osmand/osm/AbstractPoiType.java | 18 ++++ .../src/net/osmand/osm/MapPoiTypes.java | 4 + OsmAnd-java/src/net/osmand/osm/PoiType.java | 19 +--- .../activities/search/SearchPOIActivity.java | 7 ++ .../net/osmand/plus/poi/PoiLegacyFilter.java | 91 ++++++++++++++++--- 5 files changed, 110 insertions(+), 29 deletions(-) diff --git a/OsmAnd-java/src/net/osmand/osm/AbstractPoiType.java b/OsmAnd-java/src/net/osmand/osm/AbstractPoiType.java index 6f4132fe7c..6bf4160189 100644 --- a/OsmAnd-java/src/net/osmand/osm/AbstractPoiType.java +++ b/OsmAnd-java/src/net/osmand/osm/AbstractPoiType.java @@ -1,12 +1,16 @@ package net.osmand.osm; +import java.util.ArrayList; +import java.util.Collections; import java.util.LinkedHashSet; +import java.util.List; import java.util.Map; public abstract class AbstractPoiType { protected final String keyName; protected final MapPoiTypes registry; + private List poiAdditionals = null; public AbstractPoiType(String keyName, MapPoiTypes registry) { this.keyName = keyName; @@ -20,6 +24,20 @@ public abstract class AbstractPoiType { public String getTranslation() { return registry.getTranslation(this); } + + public void addPoiAdditional(PoiType tp) { + if(poiAdditionals == null) { + poiAdditionals = new ArrayList(); + } + poiAdditionals.add(tp); + } + + public List getPoiAdditionals() { + if(poiAdditionals == null) { + return Collections.emptyList(); + } + return poiAdditionals; + } public abstract Map> putTypes(Map> acceptedTypes); diff --git a/OsmAnd-java/src/net/osmand/osm/MapPoiTypes.java b/OsmAnd-java/src/net/osmand/osm/MapPoiTypes.java index 0ae92bd8c2..b2990edbee 100644 --- a/OsmAnd-java/src/net/osmand/osm/MapPoiTypes.java +++ b/OsmAnd-java/src/net/osmand/osm/MapPoiTypes.java @@ -258,6 +258,10 @@ public class MapPoiTypes { tp.setOsmValue2(parser.getAttributeValue("","value2")); if(lastType != null) { lastType.addPoiAdditional(tp); + } else if(lastFilter != null) { + lastFilter.addPoiAdditional(tp); + } else if(lastCategory != null) { + lastCategory.addPoiAdditional(tp); } } else if(name.equals("poi_type")){ PoiType tp = new PoiType(this, diff --git a/OsmAnd-java/src/net/osmand/osm/PoiType.java b/OsmAnd-java/src/net/osmand/osm/PoiType.java index 0431c99fe0..6b1d9e0b92 100644 --- a/OsmAnd-java/src/net/osmand/osm/PoiType.java +++ b/OsmAnd-java/src/net/osmand/osm/PoiType.java @@ -1,9 +1,6 @@ package net.osmand.osm; -import java.util.ArrayList; -import java.util.Collections; import java.util.LinkedHashSet; -import java.util.List; import java.util.Map; public class PoiType extends AbstractPoiType { @@ -14,7 +11,7 @@ public class PoiType extends AbstractPoiType { private String osmTag2; private String osmValue; private String osmValue2; - private List poiAdditionals = null; + public PoiType(MapPoiTypes poiTypes, PoiCategory category, String name) { super(name, poiTypes); @@ -81,20 +78,6 @@ public class PoiType extends AbstractPoiType { return category; } - public void addPoiAdditional(PoiType tp) { - if(poiAdditionals == null) { - poiAdditionals = new ArrayList(); - } - poiAdditionals.add(tp); - } - - public List getPoiAdditionals() { - if(poiAdditionals == null) { - return Collections.emptyList(); - } - return poiAdditionals; - } - public Map> putTypes(Map> acceptedTypes) { PoiType rt = getReferenceType(); PoiType poiType = rt != null ? rt : this; diff --git a/OsmAnd/src/net/osmand/plus/activities/search/SearchPOIActivity.java b/OsmAnd/src/net/osmand/plus/activities/search/SearchPOIActivity.java index 8e7562c86f..b3a979b6c4 100644 --- a/OsmAnd/src/net/osmand/plus/activities/search/SearchPOIActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/search/SearchPOIActivity.java @@ -11,6 +11,7 @@ import java.util.Calendar; import java.util.Collection; import java.util.Collections; import java.util.List; +import java.util.Map; import net.osmand.Location; import net.osmand.ResultMatcher; @@ -342,6 +343,12 @@ public class SearchPOIActivity extends OsmandListActivity implements OsmAndCompa }); addFilter(optionsMenu, getString(R.string.shared_string_open).toLowerCase()); addFilter(optionsMenu, "24/7"); + Map poiAdditionals = f.getPoiAdditionals(); + if(poiAdditionals != null) { + for(PoiType vtype : poiAdditionals.values()) { + addFilter(optionsMenu, vtype.getTranslation().replace(' ', ':').toLowerCase()); + } + } optionsMenu.show(); } diff --git a/OsmAnd/src/net/osmand/plus/poi/PoiLegacyFilter.java b/OsmAnd/src/net/osmand/plus/poi/PoiLegacyFilter.java index adedc7fc51..7f3d8d30b6 100644 --- a/OsmAnd/src/net/osmand/plus/poi/PoiLegacyFilter.java +++ b/OsmAnd/src/net/osmand/plus/poi/PoiLegacyFilter.java @@ -4,10 +4,13 @@ package net.osmand.plus.poi; import java.util.ArrayList; import java.util.Calendar; import java.util.Collections; +import java.util.HashMap; +import java.util.Iterator; import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.List; import java.util.Map; +import java.util.Map.Entry; import java.util.Set; import net.osmand.CollatorStringMatcher; @@ -20,6 +23,7 @@ import net.osmand.data.LatLon; import net.osmand.osm.AbstractPoiType; import net.osmand.osm.MapPoiTypes; import net.osmand.osm.PoiCategory; +import net.osmand.osm.PoiFilter; import net.osmand.osm.PoiType; import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmandApplication; @@ -39,6 +43,7 @@ public class PoiLegacyFilter implements SearchPoiTypeFilter { private Map> acceptedTypes = new LinkedHashMap>(); + private Map poiAdditionals = new HashMap(); protected String filterId; protected String name; @@ -65,8 +70,9 @@ public class PoiLegacyFilter implements SearchPoiTypeFilter { name = type == null ? application.getString(R.string.poi_filter_closest_poi) : type.getTranslation(); //$NON-NLS-1$ if (type == null) { initSearchAll(); + updatePoiAdditionals(); } else { - type.putTypes(acceptedTypes); + updateTypesToAccept(type); } } @@ -94,8 +100,11 @@ public class PoiLegacyFilter implements SearchPoiTypeFilter { } else { this.acceptedTypes.putAll(acceptedTypes); } + updatePoiAdditionals(); } + + public String getFilterByName() { return filterByName; } @@ -245,6 +254,7 @@ public class PoiLegacyFilter implements SearchPoiTypeFilter { String[] items = filter.split(" "); boolean allTime = false; boolean open = false; + Map poiAdditionalsFilter = null; for(String s : items) { s = s.trim(); if(!Algorithms.isEmpty(s)){ @@ -252,16 +262,21 @@ public class PoiLegacyFilter implements SearchPoiTypeFilter { allTime = true; } else if(getNameTokenOpen().equalsIgnoreCase(s)){ open = true; + } else if(poiAdditionals.containsKey(s.toLowerCase())) { + if(poiAdditionalsFilter == null) { + poiAdditionalsFilter = new LinkedHashMap(); + } + poiAdditionalsFilter.put(poiAdditionals.get(s.toLowerCase()), null); } else { nmFilter.append(s).append(" "); } } } - return getNameFilterInternal(nmFilter, allTime, open); + return getNameFilterInternal(nmFilter, allTime, open, poiAdditionalsFilter); } private AmenityNameFilter getNameFilterInternal(StringBuilder nmFilter, - final boolean allTime, final boolean open) { + final boolean allTime, final boolean open, final Map poiAdditionals) { final CollatorStringMatcher sm = nmFilter.length() > 0 ? new CollatorStringMatcher(nmFilter.toString().trim(), StringMatcherMode.CHECK_CONTAINS) : null; @@ -276,6 +291,18 @@ public class PoiLegacyFilter implements SearchPoiTypeFilter { return false; } } + if(poiAdditionals != null) { + Iterator> it = poiAdditionals.entrySet().iterator(); + while(it.hasNext()) { + Entry e = it.next(); + String inf = a.getAdditionalInfo(e.getKey().getKeyName()); + if(inf == null) { + return false; + } else if(e.getValue() != null && !e.getValue().equalsIgnoreCase(inf)) { + return false; + } + } + } if (allTime) { if (!"24/7".equalsIgnoreCase(a.getOpeningHours())) { return false; @@ -388,6 +415,7 @@ public class PoiLegacyFilter implements SearchPoiTypeFilter { public void clearFilter() { acceptedTypes = new LinkedHashMap>(); + poiAdditionals.clear(); } public boolean areAllTypesAccepted(){ @@ -403,22 +431,45 @@ public class PoiLegacyFilter implements SearchPoiTypeFilter { } - public void setTypeToAccept(PoiCategory type, boolean accept){ - if(accept){ - acceptedTypes.put(type, new LinkedHashSet()); - } else { - acceptedTypes.remove(type); - } - } - public void updateTypesToAccept(AbstractPoiType pt) { acceptedTypes.clear(); pt.putTypes(acceptedTypes); + poiAdditionals.clear(); + fillPoiAdditionals(pt); } + private void fillPoiAdditionals(AbstractPoiType pt) { + for(PoiType add : pt.getPoiAdditionals()) { + poiAdditionals.put(add.getKeyName().replace('_', ':').replace(' ', ':'), add); + poiAdditionals.put(add.getTranslation().replace(' ', ':').toLowerCase(), add); + } + if(pt instanceof PoiFilter) { + for(PoiType ps : ((PoiFilter) pt).getPoiTypes()) { + fillPoiAdditionals(ps); + } + } + } + + private void updatePoiAdditionals() { + Iterator>> e = acceptedTypes.entrySet().iterator(); + poiAdditionals.clear(); + while(e.hasNext()) { + Entry> pc = e.next(); + fillPoiAdditionals(pc.getKey()); + if(pc.getValue() != null) { + for(String s : pc.getValue()) { + PoiType subtype = poiTypes.getPoiTypeByKey(s); + fillPoiAdditionals(subtype); + } + } + } + } + public void updateTypesToAccept(PoiLegacyFilter f) { acceptedTypes.clear(); acceptedTypes.putAll(f.acceptedTypes); + poiAdditionals.clear(); + poiAdditionals.putAll(f.poiAdditionals); } @@ -428,12 +479,27 @@ public class PoiLegacyFilter implements SearchPoiTypeFilter { public void selectSubTypesToAccept(PoiCategory t, LinkedHashSet accept){ acceptedTypes.put(t, accept); + fillPoiAdditionals(t); + } + + public void setTypeToAccept(PoiCategory poiCategory, boolean b) { + if(b) { + acceptedTypes.put(poiCategory, null); + } else { + acceptedTypes.remove(poiCategory); + } + updatePoiAdditionals(); + } public String getFilterId(){ return filterId; } + public Map getPoiAdditionals() { + return poiAdditionals; + } + public String getSimplifiedId(){ if(filterId.startsWith(STD_PREFIX)) { return filterId.substring(STD_PREFIX.length()).toLowerCase(); @@ -483,4 +549,7 @@ public class PoiLegacyFilter implements SearchPoiTypeFilter { public boolean accept(Amenity a) ; } + + + } From 8edc7cd00647bbd38c9e4ec1d0b78e0a834b6134 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Fri, 10 Apr 2015 19:26:36 +0200 Subject: [PATCH 2/4] Update poi type filters --- OsmAnd-java/src/net/osmand/binary/BinaryInspector.java | 10 +++++----- .../plus/activities/search/SearchPOIActivity.java | 7 ++++++- OsmAnd/src/net/osmand/plus/poi/PoiLegacyFilter.java | 2 +- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/OsmAnd-java/src/net/osmand/binary/BinaryInspector.java b/OsmAnd-java/src/net/osmand/binary/BinaryInspector.java index 3fc4439314..6170e8bf8a 100644 --- a/OsmAnd-java/src/net/osmand/binary/BinaryInspector.java +++ b/OsmAnd-java/src/net/osmand/binary/BinaryInspector.java @@ -65,15 +65,15 @@ public class BinaryInspector { // test cases show info if(args.length == 1 && "test".equals(args[0])) { in.inspector(new String[]{ -// "-vpoi", - "-vmap",// "-vmapobjects", + "-vpoi", +// "-vmap",// "-vmapobjects", // "-vrouting", // "-vaddress", "-vcities","-vstreetgroups", // "-vstreets", "-vbuildings", "-vintersections", "-zoom=16", // "-bbox=1.74,51.17,1.75,51.16", - "-vstats", - "/Users/victorshcherb/osmand/maps/Netherlands_europe_2.obf" +// "-vstats", +// "/Users/victorshcherb/osmand/maps/Netherlands_europe_2.obf" // "/Users/victorshcherb/osmand/maps/World_basemap_2.obf" }); } else { @@ -1047,7 +1047,7 @@ public class BinaryInspector { PoiSubType st = p.subTypes.get(i); println("\t\t\t" + st.name + " " + (st.text ? "text":(" encoded " + st.possibleValues.size()))); } - req.poiTypeFilter = null;//for test only +// req.poiTypeFilter = null;//for test only index.searchPoi(p, req); } diff --git a/OsmAnd/src/net/osmand/plus/activities/search/SearchPOIActivity.java b/OsmAnd/src/net/osmand/plus/activities/search/SearchPOIActivity.java index b3a979b6c4..cb2300e347 100644 --- a/OsmAnd/src/net/osmand/plus/activities/search/SearchPOIActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/search/SearchPOIActivity.java @@ -12,6 +12,7 @@ import java.util.Collection; import java.util.Collections; import java.util.List; import java.util.Map; +import java.util.TreeMap; import net.osmand.Location; import net.osmand.ResultMatcher; @@ -345,8 +346,12 @@ public class SearchPOIActivity extends OsmandListActivity implements OsmAndCompa addFilter(optionsMenu, "24/7"); Map poiAdditionals = f.getPoiAdditionals(); if(poiAdditionals != null) { + TreeMap adds = new TreeMap(); for(PoiType vtype : poiAdditionals.values()) { - addFilter(optionsMenu, vtype.getTranslation().replace(' ', ':').toLowerCase()); + adds.put(vtype.getTranslation().replace(' ', ':').toLowerCase(), vtype); + } + for(String vtype : adds.keySet()) { + addFilter(optionsMenu, vtype); } } diff --git a/OsmAnd/src/net/osmand/plus/poi/PoiLegacyFilter.java b/OsmAnd/src/net/osmand/plus/poi/PoiLegacyFilter.java index 7f3d8d30b6..3126f04a20 100644 --- a/OsmAnd/src/net/osmand/plus/poi/PoiLegacyFilter.java +++ b/OsmAnd/src/net/osmand/plus/poi/PoiLegacyFilter.java @@ -443,7 +443,7 @@ public class PoiLegacyFilter implements SearchPoiTypeFilter { poiAdditionals.put(add.getKeyName().replace('_', ':').replace(' ', ':'), add); poiAdditionals.put(add.getTranslation().replace(' ', ':').toLowerCase(), add); } - if(pt instanceof PoiFilter) { + if(pt instanceof PoiFilter && !(pt instanceof PoiCategory)) { for(PoiType ps : ((PoiFilter) pt).getPoiTypes()) { fillPoiAdditionals(ps); } From 08ab3b073a1348136c69e7d7b3e704dbdc102203 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Fri, 10 Apr 2015 19:36:46 +0200 Subject: [PATCH 3/4] Update small icons --- .../osmand/plus/activities/FavoritesListFragment.java | 8 +++++--- .../net/osmand/plus/myplaces/AvailableGPXFragment.java | 9 +++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/activities/FavoritesListFragment.java b/OsmAnd/src/net/osmand/plus/activities/FavoritesListFragment.java index 66b7c90a89..1cf96ab59e 100644 --- a/OsmAnd/src/net/osmand/plus/activities/FavoritesListFragment.java +++ b/OsmAnd/src/net/osmand/plus/activities/FavoritesListFragment.java @@ -201,12 +201,14 @@ public class FavoritesListFragment extends ListFragment implements SearchActivit TextView distanceText = (TextView) row.findViewById(R.id.distance); ImageView icon = (ImageView) row.findViewById(R.id.favourite_icon); ImageView direction = (ImageView) row.findViewById(R.id.direction); + ImageView giImage= (ImageView)row.findViewById(R.id.group_image); direction.setVisibility(View.VISIBLE); final FavouritePoint favorite = getItem(position); if (!favorite.getCategory().isEmpty()) { - row.findViewById(R.id.group_image).setVisibility(View.VISIBLE); + giImage.setVisibility(View.VISIBLE); + giImage.setImageDrawable(app.getIconsCache().getContentIcon(R.drawable.ic_small_group)); } else { - row.findViewById(R.id.group_image).setVisibility(View.GONE); + giImage.setVisibility(View.GONE); } ((TextView) row.findViewById(R.id.group_name)).setText(favorite.getCategory()); @@ -216,7 +218,7 @@ public class FavoritesListFragment extends ListFragment implements SearchActivit name.setText(getName(favorite)); final CheckBox ch = (CheckBox) row.findViewById(R.id.check_item); - row.findViewById(R.id.favourite_icon).setVisibility(View.VISIBLE); + icon.setVisibility(View.VISIBLE); ch.setVisibility(View.GONE); return row; } diff --git a/OsmAnd/src/net/osmand/plus/myplaces/AvailableGPXFragment.java b/OsmAnd/src/net/osmand/plus/myplaces/AvailableGPXFragment.java index 2655ef4772..ff95b7e6d3 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/AvailableGPXFragment.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/AvailableGPXFragment.java @@ -1325,6 +1325,15 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment { } else { v.findViewById(R.id.read_section).setVisibility(View.VISIBLE); v.findViewById(R.id.unknown_section).setVisibility(View.GONE); + ImageView distanceI = (ImageView) v.findViewById(R.id.distance_icon); + distanceI.setVisibility(View.VISIBLE); + distanceI.setImageDrawable(app.getIconsCache().getContentIcon(R.drawable.ic_small_distance)); + ImageView pointsI = (ImageView) v.findViewById(R.id.points_icon); + pointsI.setVisibility(View.VISIBLE); + pointsI.setImageDrawable(app.getIconsCache().getContentIcon(R.drawable.ic_small_point)); + ImageView timeI = (ImageView) v.findViewById(R.id.time_icon); + timeI.setVisibility(View.VISIBLE); + timeI.setImageDrawable(app.getIconsCache().getContentIcon(R.drawable.ic_small_time)); TextView time = (TextView) v.findViewById(R.id.time); TextView distance = (TextView) v.findViewById(R.id.distance); TextView pointsCount = (TextView) v.findViewById(R.id.points_count); From a5ad26fa587adbb5c4cc9bb540424fb20a416fa7 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Fri, 10 Apr 2015 19:49:52 +0200 Subject: [PATCH 4/4] Set default driving region --- .../src/net/osmand/plus/OsmandSettings.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/OsmAnd/src/net/osmand/plus/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/OsmandSettings.java index 57317b4e96..b7aa8e100b 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/OsmandSettings.java @@ -11,6 +11,7 @@ import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.LinkedList; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.Set; import java.util.StringTokenizer; @@ -657,6 +658,24 @@ public class OsmandSettings { } return super.setValue(prefs, val); }; + + protected DrivingRegion getDefaultValue() { + Locale df = Locale.getDefault(); + if(df == null) { + return DrivingRegion.EUROPE_ASIA; + } + if(df.getCountry().equalsIgnoreCase(Locale.US.getCountry())) { + return DrivingRegion.US; + } else if(df.getCountry().equalsIgnoreCase(Locale.CANADA.getCountry())) { + return DrivingRegion.CANADA; + } else if(df.getCountry().equalsIgnoreCase(Locale.JAPAN.getCountry())) { + return DrivingRegion.JAPAN; + // potentially wrong in europe +// } else if(df.getCountry().equalsIgnoreCase(Locale.UK.getCountry())) { +// return DrivingRegion.UK_AND_OTHERS; + } + return DrivingRegion.EUROPE_ASIA; + }; }.makeGlobal().cache(); // this value string is synchronized with settings_pref.xml preference name