Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
94beca83df
4 changed files with 114 additions and 24 deletions
|
@ -654,6 +654,9 @@ public class OpeningHoursParser {
|
||||||
* @return null when parsing was unsuccessful
|
* @return null when parsing was unsuccessful
|
||||||
*/
|
*/
|
||||||
public static OpeningHours parseOpenedHours(String format){
|
public static OpeningHours parseOpenedHours(String format){
|
||||||
|
if(format == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
// split the OSM string in multiple rules
|
// split the OSM string in multiple rules
|
||||||
String[] rules = format.split(";"); //$NON-NLS-1$
|
String[] rules = format.split(";"); //$NON-NLS-1$
|
||||||
// FIXME: What if the semicolon is inside a quoted string?
|
// FIXME: What if the semicolon is inside a quoted string?
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
3. All your modified/created strings are in the top of the file (to make easier find what\'s translated).
|
3. All your modified/created strings are in the top of the file (to make easier find what\'s translated).
|
||||||
PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy
|
PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy
|
||||||
-->
|
-->
|
||||||
|
<string name="shared_string_open">Open</string>
|
||||||
<string name="rendering_attr_OSMMapperAssistant_name">OSM mapper assistant</string>
|
<string name="rendering_attr_OSMMapperAssistant_name">OSM mapper assistant</string>
|
||||||
<string name="agps_info">A-GPS info</string>
|
<string name="agps_info">A-GPS info</string>
|
||||||
<string name="shared_string_manage">Manage</string>
|
<string name="shared_string_manage">Manage</string>
|
||||||
|
|
|
@ -35,6 +35,7 @@ import net.osmand.plus.dashboard.DashLocationFragment;
|
||||||
import net.osmand.plus.dialogs.DirectionsDialogs;
|
import net.osmand.plus.dialogs.DirectionsDialogs;
|
||||||
import net.osmand.plus.poi.NominatimPoiFilter;
|
import net.osmand.plus.poi.NominatimPoiFilter;
|
||||||
import net.osmand.plus.poi.PoiLegacyFilter;
|
import net.osmand.plus.poi.PoiLegacyFilter;
|
||||||
|
import net.osmand.plus.poi.PoiLegacyFilter.AmenityNameFilter;
|
||||||
import net.osmand.plus.render.RenderingIcons;
|
import net.osmand.plus.render.RenderingIcons;
|
||||||
import net.osmand.plus.views.DirectionDrawable;
|
import net.osmand.plus.views.DirectionDrawable;
|
||||||
import net.osmand.util.Algorithms;
|
import net.osmand.util.Algorithms;
|
||||||
|
@ -339,9 +340,28 @@ public class SearchPOIActivity extends OsmandListActivity implements OsmAndCompa
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
addFilter(optionsMenu, getString(R.string.shared_string_open).toLowerCase());
|
||||||
|
addFilter(optionsMenu, "24/7");
|
||||||
|
|
||||||
optionsMenu.show();
|
optionsMenu.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void addFilter(PopupMenu optionsMenu, final String value) {
|
||||||
|
IconsCache iconsCache = getMyApplication().getIconsCache();
|
||||||
|
MenuItem item = optionsMenu.getMenu().add(getString(R.string.search_poi_filter) + " " + value)
|
||||||
|
.setIcon(iconsCache.getContentIcon(R.drawable.ic_action_filter_dark));
|
||||||
|
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onMenuItemClick(MenuItem item) {
|
||||||
|
if(searchFilterLayout.getVisibility() == View.GONE) {
|
||||||
|
searchFilterLayout.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
searchFilter.setText((searchFilter.getText().toString() + " " + value).trim());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private void showEditActivity(PoiLegacyFilter poi) {
|
private void showEditActivity(PoiLegacyFilter poi) {
|
||||||
Intent newIntent = new Intent(this, EditPOIFilterActivity.class);
|
Intent newIntent = new Intent(this, EditPOIFilterActivity.class);
|
||||||
// folder selected
|
// folder selected
|
||||||
|
@ -357,10 +377,13 @@ public class SearchPOIActivity extends OsmandListActivity implements OsmAndCompa
|
||||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
if (requestCode == RESULT_REQUEST_CODE && resultCode == EditPOIFilterActivity.EDIT_ACTIVITY_RESULT_OK) {
|
if (requestCode == RESULT_REQUEST_CODE && resultCode == EditPOIFilterActivity.EDIT_ACTIVITY_RESULT_OK) {
|
||||||
PoiLegacyFilter custom = app.getPoiFilters().getCustomPOIFilter();
|
PoiLegacyFilter custom = app.getPoiFilters().getCustomPOIFilter();
|
||||||
if(this.filter.isStandardFilter()) {
|
if (this.filter.isStandardFilter()) {
|
||||||
PoiLegacyFilter old = this.filter;
|
|
||||||
this.filter = custom;
|
this.filter = custom;
|
||||||
this.filter.setFilterByName(old.getFilterByName());
|
if (!Algorithms.isEmpty(searchFilter.getText().toString())) {
|
||||||
|
this.filter.setFilterByName(searchFilter.getText().toString());
|
||||||
|
} else {
|
||||||
|
this.filter.setFilterByName(null);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
this.filter.updateTypesToAccept(custom);
|
this.filter.updateTypesToAccept(custom);
|
||||||
}
|
}
|
||||||
|
@ -771,11 +794,10 @@ public class SearchPOIActivity extends OsmandListActivity implements OsmAndCompa
|
||||||
results.values = listToFilter;
|
results.values = listToFilter;
|
||||||
results.count = listToFilter.size();
|
results.count = listToFilter.size();
|
||||||
} else {
|
} else {
|
||||||
boolean en = app.getSettings().usingEnglishNames();
|
|
||||||
String lowerCase = constraint.toString().toLowerCase();
|
|
||||||
List<Amenity> res = new ArrayList<Amenity>();
|
List<Amenity> res = new ArrayList<Amenity>();
|
||||||
|
AmenityNameFilter nm = filter.getNameFilter(constraint.toString().toLowerCase());
|
||||||
for (Amenity item : listToFilter) {
|
for (Amenity item : listToFilter) {
|
||||||
if (filter.checkNameFilter(item, lowerCase, en)) {
|
if (nm.accept(item)) {
|
||||||
res.add(item);
|
res.add(item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package net.osmand.plus.poi;
|
||||||
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Calendar;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
|
@ -9,10 +10,9 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import net.osmand.Collator;
|
|
||||||
import net.osmand.CollatorStringMatcher;
|
import net.osmand.CollatorStringMatcher;
|
||||||
|
import net.osmand.CollatorStringMatcher.StringMatcherMode;
|
||||||
import net.osmand.Location;
|
import net.osmand.Location;
|
||||||
import net.osmand.OsmAndCollator;
|
|
||||||
import net.osmand.ResultMatcher;
|
import net.osmand.ResultMatcher;
|
||||||
import net.osmand.binary.BinaryMapIndexReader.SearchPoiTypeFilter;
|
import net.osmand.binary.BinaryMapIndexReader.SearchPoiTypeFilter;
|
||||||
import net.osmand.data.Amenity;
|
import net.osmand.data.Amenity;
|
||||||
|
@ -20,13 +20,14 @@ import net.osmand.data.LatLon;
|
||||||
import net.osmand.osm.AbstractPoiType;
|
import net.osmand.osm.AbstractPoiType;
|
||||||
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.osm.PoiType;
|
import net.osmand.osm.PoiType;
|
||||||
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;
|
||||||
import net.osmand.util.Algorithms;
|
import net.osmand.util.Algorithms;
|
||||||
import net.osmand.util.MapUtils;
|
import net.osmand.util.MapUtils;
|
||||||
|
import net.osmand.util.OpeningHoursParser;
|
||||||
|
import net.osmand.util.OpeningHoursParser.OpeningHours;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
public class PoiLegacyFilter implements SearchPoiTypeFilter {
|
public class PoiLegacyFilter implements SearchPoiTypeFilter {
|
||||||
|
@ -54,7 +55,6 @@ public class PoiLegacyFilter implements SearchPoiTypeFilter {
|
||||||
protected String filterByName = null;
|
protected String filterByName = null;
|
||||||
protected String savedFilterByName = null;
|
protected String savedFilterByName = null;
|
||||||
protected List<Amenity> currentSearchResult = null;
|
protected List<Amenity> currentSearchResult = null;
|
||||||
private Collator collator;
|
|
||||||
|
|
||||||
// constructor for standard filters
|
// constructor for standard filters
|
||||||
public PoiLegacyFilter(AbstractPoiType type, OsmandApplication application) {
|
public PoiLegacyFilter(AbstractPoiType type, OsmandApplication application) {
|
||||||
|
@ -231,31 +231,90 @@ public class PoiLegacyFilter implements SearchPoiTypeFilter {
|
||||||
topLatitude, leftLongitude, bottomLatitude, rightLongitude, -1, wrapResultMatcher(matcher));
|
topLatitude, leftLongitude, bottomLatitude, rightLongitude, -1, wrapResultMatcher(matcher));
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean checkNameFilter(Amenity object, String filter, boolean en) {
|
public AmenityNameFilter getNameFilter(String filter) {
|
||||||
boolean publish = false;
|
|
||||||
if (Algorithms.isEmpty(filter)) {
|
if (Algorithms.isEmpty(filter)) {
|
||||||
publish = true;
|
return new AmenityNameFilter() {
|
||||||
} else {
|
|
||||||
String lower = OsmAndFormatter.getPoiStringWithoutType(object, en);
|
@Override
|
||||||
publish = CollatorStringMatcher.ccontains(getCollator(), lower, filter);
|
public boolean accept(Amenity a) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
return publish;
|
StringBuilder nmFilter = new StringBuilder();
|
||||||
|
String[] items = filter.split(" ");
|
||||||
|
boolean allTime = false;
|
||||||
|
boolean open = false;
|
||||||
|
for(String s : items) {
|
||||||
|
s = s.trim();
|
||||||
|
if(!Algorithms.isEmpty(s)){
|
||||||
|
if(getNameToken24H().equalsIgnoreCase(s)){
|
||||||
|
allTime = true;
|
||||||
|
} else if(getNameTokenOpen().equalsIgnoreCase(s)){
|
||||||
|
open = true;
|
||||||
|
} else {
|
||||||
|
nmFilter.append(s).append(" ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return getNameFilterInternal(nmFilter, allTime, open);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Collator getCollator() {
|
private AmenityNameFilter getNameFilterInternal(StringBuilder nmFilter,
|
||||||
if (collator == null) {
|
final boolean allTime, final boolean open) {
|
||||||
collator = OsmAndCollator.primaryCollator();
|
final CollatorStringMatcher sm =
|
||||||
}
|
nmFilter.length() > 0 ?
|
||||||
return collator;
|
new CollatorStringMatcher(nmFilter.toString().trim(), StringMatcherMode.CHECK_CONTAINS) : null;
|
||||||
|
final boolean en = app.getSettings().usingEnglishNames();
|
||||||
|
return new AmenityNameFilter() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean accept(Amenity a) {
|
||||||
|
if (sm != null) {
|
||||||
|
String lower = OsmAndFormatter.getPoiStringWithoutType(a, en);
|
||||||
|
if (!sm.matches(lower)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (allTime) {
|
||||||
|
if (!"24/7".equalsIgnoreCase(a.getOpeningHours())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (open) {
|
||||||
|
OpeningHours rs = OpeningHoursParser.parseOpenedHours(a.getOpeningHours());
|
||||||
|
if (rs != null) {
|
||||||
|
Calendar inst = Calendar.getInstance();
|
||||||
|
inst.setTimeInMillis(System.currentTimeMillis());
|
||||||
|
boolean work = rs.isOpenedForTime(inst);
|
||||||
|
if (!work) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getNameToken24H() {
|
||||||
|
return "24/7";
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNameTokenOpen() {
|
||||||
|
return app.getString(R.string.shared_string_open);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private ResultMatcher<Amenity> wrapResultMatcher(final ResultMatcher<Amenity> matcher) {
|
private ResultMatcher<Amenity> wrapResultMatcher(final ResultMatcher<Amenity> matcher) {
|
||||||
final boolean en = app.getSettings().usingEnglishNames();
|
final AmenityNameFilter nm = getNameFilter(filterByName);
|
||||||
return new ResultMatcher<Amenity>() {
|
return new ResultMatcher<Amenity>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean publish(Amenity a) {
|
public boolean publish(Amenity a) {
|
||||||
if (checkNameFilter(a, filterByName, en)) {
|
if (nm.accept(a)) {
|
||||||
if (matcher == null || matcher.publish(a)) {
|
if (matcher == null || matcher.publish(a)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -419,4 +478,9 @@ public class PoiLegacyFilter implements SearchPoiTypeFilter {
|
||||||
return acceptedTypes.isEmpty();
|
return acceptedTypes.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public interface AmenityNameFilter {
|
||||||
|
|
||||||
|
public boolean accept(Amenity a) ;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue