Merge remote-tracking branch 'origin/master'

This commit is contained in:
Weblate 2015-04-10 01:35:13 +02:00
commit 94beca83df
4 changed files with 114 additions and 24 deletions

View file

@ -654,6 +654,9 @@ public class OpeningHoursParser {
* @return null when parsing was unsuccessful
*/
public static OpeningHours parseOpenedHours(String format){
if(format == null) {
return null;
}
// split the OSM string in multiple rules
String[] rules = format.split(";"); //$NON-NLS-1$
// FIXME: What if the semicolon is inside a quoted string?

View file

@ -9,6 +9,7 @@
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
-->
<string name="shared_string_open">Open</string>
<string name="rendering_attr_OSMMapperAssistant_name">OSM mapper assistant</string>
<string name="agps_info">A-GPS info</string>
<string name="shared_string_manage">Manage</string>

View file

@ -35,6 +35,7 @@ import net.osmand.plus.dashboard.DashLocationFragment;
import net.osmand.plus.dialogs.DirectionsDialogs;
import net.osmand.plus.poi.NominatimPoiFilter;
import net.osmand.plus.poi.PoiLegacyFilter;
import net.osmand.plus.poi.PoiLegacyFilter.AmenityNameFilter;
import net.osmand.plus.render.RenderingIcons;
import net.osmand.plus.views.DirectionDrawable;
import net.osmand.util.Algorithms;
@ -339,9 +340,28 @@ public class SearchPOIActivity extends OsmandListActivity implements OsmAndCompa
return true;
}
});
addFilter(optionsMenu, getString(R.string.shared_string_open).toLowerCase());
addFilter(optionsMenu, "24/7");
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) {
Intent newIntent = new Intent(this, EditPOIFilterActivity.class);
// folder selected
@ -357,10 +377,13 @@ public class SearchPOIActivity extends OsmandListActivity implements OsmAndCompa
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == RESULT_REQUEST_CODE && resultCode == EditPOIFilterActivity.EDIT_ACTIVITY_RESULT_OK) {
PoiLegacyFilter custom = app.getPoiFilters().getCustomPOIFilter();
if(this.filter.isStandardFilter()) {
PoiLegacyFilter old = this.filter;
if (this.filter.isStandardFilter()) {
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 {
this.filter.updateTypesToAccept(custom);
}
@ -771,11 +794,10 @@ public class SearchPOIActivity extends OsmandListActivity implements OsmAndCompa
results.values = listToFilter;
results.count = listToFilter.size();
} else {
boolean en = app.getSettings().usingEnglishNames();
String lowerCase = constraint.toString().toLowerCase();
List<Amenity> res = new ArrayList<Amenity>();
AmenityNameFilter nm = filter.getNameFilter(constraint.toString().toLowerCase());
for (Amenity item : listToFilter) {
if (filter.checkNameFilter(item, lowerCase, en)) {
if (nm.accept(item)) {
res.add(item);
}
}

View file

@ -2,6 +2,7 @@ package net.osmand.plus.poi;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
@ -9,10 +10,9 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import net.osmand.Collator;
import net.osmand.CollatorStringMatcher;
import net.osmand.CollatorStringMatcher.StringMatcherMode;
import net.osmand.Location;
import net.osmand.OsmAndCollator;
import net.osmand.ResultMatcher;
import net.osmand.binary.BinaryMapIndexReader.SearchPoiTypeFilter;
import net.osmand.data.Amenity;
@ -20,13 +20,14 @@ 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;
import net.osmand.plus.R;
import net.osmand.util.Algorithms;
import net.osmand.util.MapUtils;
import net.osmand.util.OpeningHoursParser;
import net.osmand.util.OpeningHoursParser.OpeningHours;
import android.content.Context;
public class PoiLegacyFilter implements SearchPoiTypeFilter {
@ -54,7 +55,6 @@ public class PoiLegacyFilter implements SearchPoiTypeFilter {
protected String filterByName = null;
protected String savedFilterByName = null;
protected List<Amenity> currentSearchResult = null;
private Collator collator;
// constructor for standard filters
public PoiLegacyFilter(AbstractPoiType type, OsmandApplication application) {
@ -231,31 +231,90 @@ public class PoiLegacyFilter implements SearchPoiTypeFilter {
topLatitude, leftLongitude, bottomLatitude, rightLongitude, -1, wrapResultMatcher(matcher));
}
public boolean checkNameFilter(Amenity object, String filter, boolean en) {
boolean publish = false;
public AmenityNameFilter getNameFilter(String filter) {
if (Algorithms.isEmpty(filter)) {
publish = true;
} else {
String lower = OsmAndFormatter.getPoiStringWithoutType(object, en);
publish = CollatorStringMatcher.ccontains(getCollator(), lower, filter);
return new AmenityNameFilter() {
@Override
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() {
if (collator == null) {
collator = OsmAndCollator.primaryCollator();
}
return collator;
private AmenityNameFilter getNameFilterInternal(StringBuilder nmFilter,
final boolean allTime, final boolean open) {
final CollatorStringMatcher sm =
nmFilter.length() > 0 ?
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) {
final boolean en = app.getSettings().usingEnglishNames();
final AmenityNameFilter nm = getNameFilter(filterByName);
return new ResultMatcher<Amenity>() {
@Override
public boolean publish(Amenity a) {
if (checkNameFilter(a, filterByName, en)) {
if (nm.accept(a)) {
if (matcher == null || matcher.publish(a)) {
return true;
}
@ -419,4 +478,9 @@ public class PoiLegacyFilter implements SearchPoiTypeFilter {
return acceptedTypes.isEmpty();
}
public interface AmenityNameFilter {
public boolean accept(Amenity a) ;
}
}