Merge remote-tracking branch 'origin/master'

This commit is contained in:
Weblate 2016-04-25 10:10:32 +02:00
commit 09ad5a9fea
10 changed files with 314 additions and 195 deletions

View file

@ -217,10 +217,10 @@ public class AppInitializer implements IProgress {
private void checkMapUpdates() {
long diff = System.currentTimeMillis() - app.getSettings().LAST_CHECKED_UPDATES.get();
if(diff >= 2 * 24 * 60 * 60l && new Random().nextInt(5) == 0 &&
if (diff >= 2 * 24 * 60 * 60l && new Random().nextInt(5) == 0 &&
app.getSettings().isInternetConnectionAvailable()) {
app.getDownloadThread().runReloadIndexFiles();
} else if(Version.isDeveloperVersion(app)) {
} else if (Version.isDeveloperVersion(app)) {
// app.getDownloadThread().runReloadIndexFiles();
}
}
@ -489,6 +489,7 @@ public class AppInitializer implements IProgress {
notifyEvent(InitEvents.NATIVE_INITIALIZED);
app.poiFilters.reloadAllPoiFilters();
app.poiFilters.loadSelectedPoiFilters();
notifyEvent(InitEvents.POI_TYPES_INITIALIZED);
indexRegionsBoundaries(warnings);
notifyEvent(InitEvents.INDEX_REGION_BOUNDARIES);

View file

@ -38,7 +38,9 @@ import java.io.IOException;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
@ -48,6 +50,7 @@ import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.TreeSet;
public class OsmandSettings {
@ -2319,9 +2322,22 @@ public class OsmandSettings {
return settingsAPI.edit(globalPreferences).putString(LAST_SEARCHED_INTERSECTED_STREET, street).commit();
}
// Avoid using this property, probably you need to use PoiFiltersHelper.getSelectedPoiFilters()
public final OsmandPreference<String> SELECTED_POI_FILTER_FOR_MAP = new StringPreference("selected_poi_filter_for_map", null).makeGlobal().cache();
public Set<String> getSelectedPoiFilters() {
Set<String> result = new LinkedHashSet<>();
String filtersId = SELECTED_POI_FILTER_FOR_MAP.get();
if (filtersId != null) {
Collections.addAll(result, filtersId.split(","));
}
return result;
}
public void setSelectedPoiFilters(final Set<String> poiFilters) {
SELECTED_POI_FILTER_FOR_MAP.set(android.text.TextUtils.join(",", poiFilters));
}
public static final String VOICE_PROVIDER_NOT_USE = "VOICE_PROVIDER_NOT_USE";
public static final String[] TTS_AVAILABLE_VOICES = new String[]{

View file

@ -4,6 +4,7 @@ package net.osmand.plus.activities;
import android.content.DialogInterface;
import android.content.Intent;
import android.support.v7.app.AlertDialog;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.Toast;
@ -53,6 +54,7 @@ import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map.Entry;
import java.util.Set;
/**
* Object is responsible to maintain layers using by map activity
@ -257,7 +259,7 @@ public class MapActivityLayers {
}
public AlertDialog selectPOIFilterLayer(final OsmandMapTileView mapView, final PoiUIFilter[] selected) {
public AlertDialog selectPOIFilterLayer(final OsmandMapTileView mapView) {
OsmandApplication app = getApplication();
final PoiFiltersHelper poiFilters = app.getPoiFilters();
final ContextMenuAdapter adapter = new ContextMenuAdapter();
@ -269,41 +271,52 @@ public class MapActivityLayers {
for (PoiUIFilter f : poiFilters.getTopDefinedPoiFilters()) {
addFilterToList(adapter, list, f);
}
for (PoiUIFilter f : poiFilters.getSearchPoiFilters()) {
addFilterToList(adapter, list, f);
}
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
ListAdapter listAdapter = adapter.createListAdapter(activity, app.getSettings().isLightContent());
builder.setAdapter(listAdapter, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
PoiUIFilter pf = list.get(which);
String filterId = pf.getFilterId();
if (filterId.equals(PoiUIFilter.CUSTOM_FILTER_ID)) {
public void onClick(DialogInterface dialog, int position) {
PoiUIFilter pf = list.get(position);
String filterId = pf.getFilterId();
if (filterId.equals(PoiUIFilter.CUSTOM_FILTER_ID)) {
Intent search = new Intent(activity, SearchActivity.class);
search.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
activity.getMyApplication().getSettings().SEARCH_TAB.set(SearchActivity.POI_TAB_INDEX);
activity.startActivity(search);
} else {
pf = poiFilters.getFilterById(filterId);
if (pf != null) {
pf.setFilterByName(pf.getSavedFilterByName());
}
getApplication().getSettings().SELECTED_POI_FILTER_FOR_MAP.set(filterId);
mapView.refreshMap();
if (selected != null && selected.length > 0) {
selected[0] = pf;
}
}
}
});
builder.setNegativeButton(R.string.shared_string_cancel, null);
builder.setTitle(R.string.show_poi_over_map)
.setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
mapView.refreshMap();
}
})
.setNegativeButton(R.string.shared_string_cancel, null);
return builder.show();
}
private void addFilterToList(final ContextMenuAdapter adapter, final List<PoiUIFilter> list, PoiUIFilter f) {
private void addFilterToList(final ContextMenuAdapter adapter, final List<PoiUIFilter> list, final PoiUIFilter f) {
list.add(f);
ContextMenuItem.ItemBuilder builder = new ContextMenuItem.ItemBuilder();
builder.setListener(new ContextMenuAdapter.ItemClickListener() {
@Override
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int position, boolean isChecked) {
if (isChecked) {
getApplication().getPoiFilters().addSelectedPoiFilter(f);
} else {
getApplication().getPoiFilters().removeSelectedPoiFilter(f);
}
return true;
}
});
builder.setTitle(f.getName());
builder.setSelected(getApplication().getPoiFilters().isPoiFilterSelected(f));
if (RenderingIcons.containsBigIcon(f.getIconId())) {
builder.setIcon(RenderingIcons.getBigIconResourceId(f.getIconId()));
} else {

View file

@ -157,7 +157,7 @@ public class SearchPOIActivity extends OsmandListActivity implements OsmAndCompa
public boolean onMenuItemClick(MenuItem item) {
OsmandSettings settings = app.getSettings();
filter.setFilterByName(searchFilter.getText().toString().trim());
settings.SELECTED_POI_FILTER_FOR_MAP.set(filter.getFilterId());
app.getPoiFilters().addSelectedPoiFilter(filter);
if (location != null) {
settings.setMapLocationToShow(location.getLatitude(), location.getLongitude(), 15);
}
@ -828,8 +828,9 @@ public class SearchPOIActivity extends OsmandListActivity implements OsmAndCompa
List<String> attributes = new ArrayList<String>();
NavigationInfo navigationInfo = app.getLocationProvider().getNavigationInfo();
String direction = navigationInfo.getDirectionString(amenity.getLocation(), heading);
if (direction != null)
if (direction != null) {
attributes.add(direction);
}
String[] as = OsmAndFormatter.getAmenityDescriptionContent(getMyApplication(), amenity, false).split("\n");
for (String s : as) {
attributes.add(s.replace(':', ' '));

View file

@ -28,6 +28,7 @@ import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.PluginActivity;
import net.osmand.plus.activities.SettingsActivity;
import net.osmand.plus.activities.TransportRouteHelper;
import net.osmand.plus.poi.PoiFiltersHelper;
import net.osmand.plus.poi.PoiUIFilter;
import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin;
import net.osmand.plus.render.RendererRegistry;
@ -125,17 +126,18 @@ public class ConfigureMapMenu {
@Override
public boolean onContextMenuClick(final ArrayAdapter<ContextMenuItem> adapter, int itemId, final int pos, boolean isChecked) {
final OsmandSettings settings = ma.getMyApplication().getSettings();
final PoiFiltersHelper pfh = ma.getMyApplication().getPoiFilters();
final ContextMenuItem item = cm.getItem(pos);
if (item.getSelected() != null) {
item.setColorRes(isChecked ? R.color.osmand_orange : ContextMenuItem.INVALID_ID);
adapter.notifyDataSetChanged();
}
if (itemId == R.string.layer_poi) {
settings.SELECTED_POI_FILTER_FOR_MAP.set(null);
pfh.clearSelectedPoiFilters();
if (isChecked) {
selectPOILayer(adapter, adapter.getItem(pos));
} else {
adapter.getItem(pos).setDescription(POIMapLayer.getSelectedPoiName(ma.getMyApplication()));
adapter.getItem(pos).setDescription(pfh.getSelectedPoiFiltersName());
}
} else if (itemId == R.string.layer_amenity_label) {
settings.SHOW_POI_LABEL.set(isChecked);
@ -184,17 +186,15 @@ public class ConfigureMapMenu {
protected void selectPOILayer(final ArrayAdapter<ContextMenuItem> adapter,
final ContextMenuItem item) {
final PoiUIFilter[] selected = new PoiUIFilter[1];
AlertDialog dlg = ma.getMapLayers().selectPOIFilterLayer(ma.getMapView(), selected);
AlertDialog dlg = ma.getMapLayers().selectPOIFilterLayer(ma.getMapView());
dlg.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
OsmandApplication myApplication = ma.getMyApplication();
boolean selected = myApplication.getSettings()
.SELECTED_POI_FILTER_FOR_MAP.get() != null;
PoiFiltersHelper pf = ma.getMyApplication().getPoiFilters();
boolean selected = pf.isShowingAnyPoi();
item.setSelected(selected);
item.setDescription(POIMapLayer.getSelectedPoiName(myApplication));
item.setDescription(pf.getSelectedPoiFiltersName());
item.setColorRes(selected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID);
adapter.notifyDataSetChanged();
}
@ -217,11 +217,11 @@ public class ConfigureMapMenu {
.setColor(selected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID)
.setIcon(R.drawable.ic_action_fav_dark)
.setListener(l).createItem());
selected = settings.SELECTED_POI_FILTER_FOR_MAP.get() != null;
selected = app.getPoiFilters().isShowingAnyPoi();
adapter.addItem(new ContextMenuItem.ItemBuilder()
.setTitleId(R.string.layer_poi, activity)
.setSelected(settings.SELECTED_POI_FILTER_FOR_MAP.get() != null)
.setDescription(POIMapLayer.getSelectedPoiName(app))
.setSelected(selected)
.setDescription(app.getPoiFilters().getSelectedPoiFiltersName())
.setColor(selected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID)
.setIcon(R.drawable.ic_action_info_dark)
.setSecondaryIcon(R.drawable.ic_action_additional_option)

View file

@ -603,8 +603,7 @@ public class WaypointDialogHelper {
if (type == WaypointHelper.POI) {
v = ctx.getLayoutInflater().inflate(R.layout.drawer_list_radius_ex, null);
AndroidUtils.setTextPrimaryColor(mapActivity, (TextView) v.findViewById(R.id.titleEx), nightMode);
String descEx = waypointHelper.getPoiFilter() == null ? ctx.getString(R.string.poi) : waypointHelper
.getPoiFilter().getName();
String descEx = app.getPoiFilters().isShowingAnyPoi() ? ctx.getString(R.string.poi) : app.getPoiFilters().getSelectedPoiFiltersName();
((TextView) v.findViewById(R.id.title)).setText(ctx.getString(R.string.search_radius_proximity) + ":");
((TextView) v.findViewById(R.id.titleEx)).setText(ctx.getString(R.string.shared_string_type) + ":");
final TextView radiusEx = (TextView) v.findViewById(R.id.descriptionEx);
@ -615,8 +614,7 @@ public class WaypointDialogHelper {
running[0] = position;
thisAdapter.notifyDataSetInvalidated();
MapActivity map = (MapActivity) ctx;
final PoiUIFilter[] selected = new PoiUIFilter[1];
AlertDialog dlg = map.getMapLayers().selectPOIFilterLayer(map.getMapView(), selected);
AlertDialog dlg = map.getMapLayers().selectPOIFilterLayer(map.getMapView());
dlg.setOnDismissListener(new OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
@ -688,15 +686,14 @@ public class WaypointDialogHelper {
private void selectPoi(final int[] running, final ArrayAdapter<Object> listAdapter, final int type,
final boolean enable, Activity ctx) {
if (ctx instanceof MapActivity &&
!PoiUIFilter.CUSTOM_FILTER_ID.equals(app.getSettings().SELECTED_POI_FILTER_FOR_MAP.get())) {
!app.getPoiFilters().isPoiFilterSelected(PoiUIFilter.CUSTOM_FILTER_ID)) {
MapActivity map = (MapActivity) ctx;
final PoiUIFilter[] selected = new PoiUIFilter[1];
AlertDialog dlg = map.getMapLayers().selectPOIFilterLayer(map.getMapView(), selected);
AlertDialog dlg = map.getMapLayers().selectPOIFilterLayer(map.getMapView());
dlg.setOnDismissListener(new OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
if (selected != null) {
if (app.getPoiFilters().isShowingAnyPoi()) {
enableType(running, listAdapter, type, enable);
}
}

View file

@ -8,6 +8,7 @@ import java.util.Collections;
import java.util.Comparator;
import java.util.EnumSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import net.osmand.FloatMath;
@ -538,10 +539,12 @@ public class WaypointHelper {
protected void calculatePoi(RouteCalculationResult route, List<LocationPointWrapper> locationPoints) {
PoiUIFilter pf = getPoiFilter();
if (pf != null) {
if (app.getPoiFilters().isShowingAnyPoi()) {
final List<Location> locs = route.getImmutableAllLocations();
List<Amenity> amenities = pf.searchAmenitiesOnThePath(locs, poiSearchDeviationRadius);
List<Amenity> amenities = new ArrayList<>();
for (PoiUIFilter pf : app.getPoiFilters().getSelectedPoiFilters()) {
amenities.addAll(pf.searchAmenitiesOnThePath(locs, poiSearchDeviationRadius));
}
for (Amenity a : amenities) {
AmenityRoutePoint rp = a.getRoutePoint();
int i = locs.indexOf(rp.pointA);
@ -607,8 +610,8 @@ public class WaypointHelper {
///
public PoiUIFilter getPoiFilter() {
return app.getPoiFilters().getFilterById(app.getSettings().SELECTED_POI_FILTER_FOR_MAP.get());
public Set<PoiUIFilter> getPoiFilters() {
return app.getPoiFilters().getSelectedPoiFilters();
}
public boolean showPOI() {
@ -758,18 +761,23 @@ public class WaypointHelper {
@Override
public boolean equals(Object obj) {
if (this == obj)
if (this == obj) {
return true;
if (obj == null)
}
if (obj == null) {
return false;
if (getClass() != obj.getClass())
}
if (getClass() != obj.getClass()) {
return false;
}
LocationPointWrapper other = (LocationPointWrapper) obj;
if (point == null) {
if (other.point != null)
if (other.point != null) {
return false;
} else if (!point.equals(other.point))
}
} else if (!point.equals(other.point)) {
return false;
}
return true;
}

View file

@ -1,43 +1,48 @@
package net.osmand.plus.poi;
import java.text.Collator;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import net.osmand.access.AccessibilityPlugin;
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.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R;
import net.osmand.plus.api.SQLiteAPI.SQLiteConnection;
import net.osmand.plus.api.SQLiteAPI.SQLiteCursor;
import net.osmand.plus.api.SQLiteAPI.SQLiteStatement;
import net.osmand.util.Algorithms;
import android.support.annotation.NonNull;
import android.util.ArraySet;
import java.lang.reflect.Array;
import java.text.Collator;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
public class PoiFiltersHelper {
private final OsmandApplication application;
private NominatimPoiFilter nominatimPOIFilter;
private NominatimPoiFilter nominatimAddresFilter;
private NominatimPoiFilter nominatimAddressFilter;
private PoiUIFilter searchByNamePOIFilter;
private PoiUIFilter customPOIFilter;
private PoiUIFilter showAllPOIFilter;
private PoiUIFilter localWikiPoiFilter;
private List<PoiUIFilter> cacheTopStandardFilters;
private Set<PoiUIFilter> selectedPoiFilters = new TreeSet<>();
private static final String UDF_CAR_AID = "car_aid";
private static final String UDF_FOR_TOURISTS = "for_tourists";
private static final String UDF_FOOD_SHOP = "food_shop";
@ -45,7 +50,7 @@ public class PoiFiltersHelper {
private static final String UDF_SIGHTSEEING = "sightseeing";
private static final String UDF_EMERGENCY = "emergency";
private static final String UDF_PUBLIC_TRANSPORT = "public_transport";
private static final String UDF_ACCOMMODATION = "accomodation";
private static final String UDF_ACCOMMODATION = "accommodation";
private static final String UDF_RESTAURANTS = "restaurants";
private static final String UDF_PARKING = "parking";
@ -66,10 +71,10 @@ public class PoiFiltersHelper {
}
public NominatimPoiFilter getNominatimAddressFilter() {
if(nominatimAddresFilter == null){
nominatimAddresFilter = new NominatimPoiFilter(application, true);
if(nominatimAddressFilter == null){
nominatimAddressFilter = new NominatimPoiFilter(application, true);
}
return nominatimAddresFilter;
return nominatimAddressFilter;
}
public PoiUIFilter getSearchByNamePOIFilter() {
@ -81,10 +86,8 @@ public class PoiFiltersHelper {
return searchByNamePOIFilter;
}
public PoiUIFilter getCustomPOIFilter() {
if(customPOIFilter == null){
if (customPOIFilter == null){
PoiUIFilter filter = new PoiUIFilter(application.getString(R.string.poi_filter_custom_filter),
PoiUIFilter.CUSTOM_FILTER_ID, new LinkedHashMap<PoiCategory, LinkedHashSet<String>>(), application); //$NON-NLS-1$
filter.setStandardFilter(true);
@ -94,10 +97,10 @@ public class PoiFiltersHelper {
}
public PoiUIFilter getLocalWikiPOIFilter() {
if(localWikiPoiFilter == null){
if (localWikiPoiFilter == null){
PoiType place = application.getPoiTypes().getPoiTypeByKey("wiki_place");
if (place != null && !Algorithms.isEmpty(application.getLanguage())) {
PoiUIFilter filter = new PoiUIFilter(place, application, " " +
PoiUIFilter filter = new PoiUIFilter(place, application, " " +
application.getLangTranslation(application.getLanguage())); //$NON-NLS-1$
filter.setSavedFilterByName("wiki:lang:"+application.getLanguage());
filter.setStandardFilter(true);
@ -108,7 +111,7 @@ public class PoiFiltersHelper {
}
public PoiUIFilter getShowAllPOIFilter() {
if(showAllPOIFilter == null){
if (showAllPOIFilter == null){
PoiUIFilter filter = new PoiUIFilter(null, application, ""); //$NON-NLS-1$
filter.setStandardFilter(true);
showAllPOIFilter = filter;
@ -118,20 +121,20 @@ public class PoiFiltersHelper {
private PoiUIFilter getFilterById(String filterId, PoiUIFilter... filters){
for(PoiUIFilter pf : filters) {
if(pf.getFilterId().equals(filterId)){
for (PoiUIFilter pf : filters) {
if (pf.getFilterId().equals(filterId)) {
return pf;
}
}
return null;
}
public PoiUIFilter getFilterById(String filterId){
if(filterId == null){
if (filterId == null){
return null;
}
for(PoiUIFilter f : getTopDefinedPoiFilters()) {
if(f.getFilterId().equals(filterId)){
for (PoiUIFilter f : getTopDefinedPoiFilters()) {
if (f.getFilterId().equals(filterId)) {
return f;
}
}
@ -140,39 +143,37 @@ public class PoiFiltersHelper {
if (ff != null) {
return ff;
}
if(filterId.startsWith(PoiUIFilter.STD_PREFIX)) {
if (filterId.startsWith(PoiUIFilter.STD_PREFIX)) {
String typeId = filterId.substring(PoiUIFilter.STD_PREFIX.length());
AbstractPoiType tp = application.getPoiTypes().getAnyPoiTypeByKey(typeId);
if(tp != null) {
if (tp != null) {
PoiUIFilter lf = new PoiUIFilter(tp, application, "");
ArrayList<PoiUIFilter> copy = new ArrayList<PoiUIFilter>(cacheTopStandardFilters);
copy.add(lf);
sortListOfFilters(copy);
Collections.sort(copy);
cacheTopStandardFilters = copy;
return lf;
}
AbstractPoiType lt = application.getPoiTypes().getAnyPoiAdditionalTypeByKey(typeId);
if(lt != null) {
if (lt != null) {
PoiUIFilter lf = new PoiUIFilter(lt, application, "");
ArrayList<PoiUIFilter> copy = new ArrayList<PoiUIFilter>(cacheTopStandardFilters);
copy.add(lf);
sortListOfFilters(copy);
Collections.sort(copy);
cacheTopStandardFilters = copy;
return lf;
}
}
return null;
}
public void reloadAllPoiFilters() {
showAllPOIFilter = null;
getShowAllPOIFilter();
cacheTopStandardFilters = null;
getTopDefinedPoiFilters();
}
private List<PoiUIFilter> getUserDefinedPoiFilters() {
ArrayList<PoiUIFilter> userDefinedFilters = new ArrayList<PoiUIFilter>();
PoiFilterDbHelper helper = openDbHelper();
@ -183,33 +184,34 @@ public class PoiFiltersHelper {
}
return userDefinedFilters;
}
public void sortListOfFilters(List<PoiUIFilter> list) {
final Collator instance = Collator.getInstance();
Collections.sort(list, new Comparator<PoiUIFilter>() {
@Override
public int compare(PoiUIFilter lhs, PoiUIFilter rhs) {
return instance.compare(lhs.getName(), rhs.getName());
public List<PoiUIFilter> getSearchPoiFilters() {
List<PoiUIFilter> result = new ArrayList<>();
List<PoiUIFilter> filters = Arrays.asList(getCustomPOIFilter(), // getShowAllPOIFilter(),
getSearchByNamePOIFilter(), getNominatimPOIFilter(), getNominatimAddressFilter());
for (PoiUIFilter f : filters) {
if (f != null && !f.isEmpty()) {
result.add(f);
}
});
}
return result;
}
public List<PoiUIFilter> getTopDefinedPoiFilters() {
if (cacheTopStandardFilters == null) {
List<PoiUIFilter> top = new ArrayList<PoiUIFilter>();
// user defined
top.addAll(getUserDefinedPoiFilters());
if(getLocalWikiPOIFilter() != null) {
if (getLocalWikiPOIFilter() != null) {
top.add(getLocalWikiPOIFilter());
}
// default
MapPoiTypes poiTypes = application.getPoiTypes();
for (PoiFilter t : poiTypes.getTopVisibleFilters()) {
top.add(new PoiUIFilter(t, application, ""));
PoiUIFilter f = new PoiUIFilter(t, application, "");
top.add(f);
}
sortListOfFilters(top);
Collections.sort(top);
cacheTopStandardFilters = top;
}
List<PoiUIFilter> result = new ArrayList<PoiUIFilter>();
@ -222,21 +224,21 @@ public class PoiFiltersHelper {
if(!application.getPoiTypes().isInit()) {
return null;
}
return new PoiFilterDbHelper(application.getPoiTypes(), application);
return new PoiFilterDbHelper(application.getPoiTypes(), application);
}
public boolean removePoiFilter(PoiUIFilter filter){
if(filter.getFilterId().equals(PoiUIFilter.CUSTOM_FILTER_ID) ||
if (filter.getFilterId().equals(PoiUIFilter.CUSTOM_FILTER_ID) ||
filter.getFilterId().equals(PoiUIFilter.BY_NAME_FILTER_ID) ||
filter.getFilterId().startsWith(PoiUIFilter.STD_PREFIX)){
filter.getFilterId().startsWith(PoiUIFilter.STD_PREFIX)) {
return false;
}
PoiFilterDbHelper helper = openDbHelper();
if(helper == null){
if (helper == null) {
return false;
}
boolean res = helper.deleteFilter(helper.getWritableDatabase(), filter);
if(res){
if (res) {
ArrayList<PoiUIFilter> copy = new ArrayList<>(cacheTopStandardFilters);
copy.remove(filter);
cacheTopStandardFilters = copy;
@ -261,17 +263,15 @@ public class PoiFiltersHelper {
if(res){
ArrayList<PoiUIFilter> copy = new ArrayList<>(cacheTopStandardFilters);
copy.add(filter);
sortListOfFilters(copy);
Collections.sort(copy);
cacheTopStandardFilters = copy;
}
helper.close();
return res;
}
public boolean editPoiFilter(PoiUIFilter filter) {
if (filter.getFilterId().equals(PoiUIFilter.CUSTOM_FILTER_ID) ||
if (filter.getFilterId().equals(PoiUIFilter.CUSTOM_FILTER_ID) ||
filter.getFilterId().equals(PoiUIFilter.BY_NAME_FILTER_ID) || filter.getFilterId().startsWith(PoiUIFilter.STD_PREFIX)) {
return false;
}
@ -283,8 +283,75 @@ public class PoiFiltersHelper {
}
return false;
}
@NonNull
public Set<PoiUIFilter> getSelectedPoiFilters() {
return selectedPoiFilters;
}
public void addSelectedPoiFilter(PoiUIFilter filter) {
selectedPoiFilters.add(filter);
saveSelectedPoiFilters();
}
public void removeSelectedPoiFilter(PoiUIFilter filter) {
selectedPoiFilters.remove(filter);
saveSelectedPoiFilters();
}
public boolean isShowingAnyPoi() {
return !selectedPoiFilters.isEmpty();
}
public void clearSelectedPoiFilters() {
selectedPoiFilters.clear();
saveSelectedPoiFilters();
}
public String getFiltersName(Set<PoiUIFilter> filters) {
if (filters.isEmpty()) {
return application.getResources().getString(R.string.shared_string_none);
} else {
List<String> names = new ArrayList<>();
for (PoiUIFilter filter : filters) {
names.add(filter.getName());
}
return android.text.TextUtils.join(", ", names);
}
}
public String getSelectedPoiFiltersName() {
return getFiltersName(selectedPoiFilters);
}
public boolean isPoiFilterSelected(PoiUIFilter filter) {
return selectedPoiFilters.contains(filter);
}
public boolean isPoiFilterSelected(String filterId) {
for (PoiUIFilter filter: selectedPoiFilters) {
if (filter.filterId.equals(filterId)) {
return true;
}
}
return false;
}
public void loadSelectedPoiFilters() {
Set<String> filters = application.getSettings().getSelectedPoiFilters();
for (String f: filters) {
selectedPoiFilters.add(getFilterById(f));
}
}
public void saveSelectedPoiFilters() {
Set<String> filters = new HashSet<>();
for (PoiUIFilter f: selectedPoiFilters) {
filters.add(f.filterId);
}
application.getSettings().setSelectedPoiFilters(filters);
}
public class PoiFilterDbHelper {
public static final String DATABASE_NAME = "poi_filters"; //$NON-NLS-1$
@ -295,8 +362,8 @@ public class PoiFiltersHelper {
private static final String FILTER_COL_FILTERBYNAME = "filterbyname"; //$NON-NLS-1$
private static final String FILTER_TABLE_CREATE = "CREATE TABLE " + FILTER_NAME + " (" + //$NON-NLS-1$ //$NON-NLS-2$
FILTER_COL_NAME + ", " + FILTER_COL_ID + ", " + FILTER_COL_FILTERBYNAME + ");"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
private static final String CATEGORIES_NAME = "categories"; //$NON-NLS-1$
private static final String CATEGORIES_FILTER_ID = "filter_id"; //$NON-NLS-1$
private static final String CATEGORIES_COL_CATEGORY = "category"; //$NON-NLS-1$
@ -311,7 +378,7 @@ public class PoiFiltersHelper {
this.mapPoiTypes = mapPoiTypes;
this.context = context;
}
public SQLiteConnection getWritableDatabase() {
return openConnection(false);
}
@ -357,7 +424,7 @@ public class PoiFiltersHelper {
}
conn.setVersion(newVersion);
}
private void deleteOldFilters(SQLiteConnection conn) {
for (String toDel : DEL) {
deleteFilter(conn, "user_" + toDel);
@ -391,7 +458,7 @@ public class PoiFiltersHelper {
}
return false;
}
protected List<PoiUIFilter> getFilters(SQLiteConnection conn){
ArrayList<PoiUIFilter> list = new ArrayList<PoiUIFilter>();
if(conn != null){
@ -436,7 +503,7 @@ public class PoiFiltersHelper {
}
return list;
}
protected boolean editFilter(SQLiteConnection conn, PoiUIFilter filter) {
if (conn != null) {
conn.execSQL("DELETE FROM " + CATEGORIES_NAME + " WHERE " + CATEGORIES_FILTER_ID + " = ?", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
@ -452,7 +519,7 @@ public class PoiFiltersHelper {
db.execSQL("UPDATE " + FILTER_NAME + " SET " + FILTER_COL_FILTERBYNAME + " = ?, " + FILTER_COL_NAME + " = ? " + " WHERE " //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
+ FILTER_COL_ID + "= ?", new Object[] { filter.getFilterByName(), filter.getName(), filter.getFilterId() }); //$NON-NLS-1$
}
protected boolean deleteFilter(SQLiteConnection db, PoiUIFilter p){
String key = p.getFilterId();
return deleteFilter(db, key);
@ -467,7 +534,7 @@ public class PoiFiltersHelper {
}
return false;
}
}

View file

@ -11,7 +11,9 @@ import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.Set;
import java.util.TreeSet;
import net.osmand.CollatorStringMatcher;
import net.osmand.CollatorStringMatcher.StringMatcherMode;
@ -33,8 +35,9 @@ import net.osmand.util.MapUtils;
import net.osmand.util.OpeningHoursParser;
import net.osmand.util.OpeningHoursParser.OpeningHours;
import android.content.Context;
import android.support.annotation.NonNull;
public class PoiUIFilter implements SearchPoiTypeFilter {
public class PoiUIFilter implements SearchPoiTypeFilter, Comparable<PoiUIFilter> {
public final static String STD_PREFIX = "std_"; //$NON-NLS-1$
public final static String USER_PREFIX = "user_"; //$NON-NLS-1$
@ -61,7 +64,7 @@ public class PoiUIFilter implements SearchPoiTypeFilter {
protected String filterByName = null;
protected String savedFilterByName = null;
protected List<Amenity> currentSearchResult = null;
// constructor for standard filters
public PoiUIFilter(AbstractPoiType type, OsmandApplication application, String idSuffix) {
this.app = application;
@ -97,12 +100,12 @@ public class PoiUIFilter implements SearchPoiTypeFilter {
this.app = app;
isStandardFilter = false;
poiTypes = app.getPoiTypes();
if(filterId == null){
if (filterId == null) {
filterId = USER_PREFIX + name.replace(' ', '_').toLowerCase();
}
this.filterId = filterId;
this.name = name;
if(acceptedTypes == null){
if (acceptedTypes == null) {
initSearchAll();
} else {
this.acceptedTypes.putAll(acceptedTypes);
@ -110,8 +113,6 @@ public class PoiUIFilter implements SearchPoiTypeFilter {
updatePoiAdditionals();
}
public String getFilterByName() {
return filterByName;
}
@ -123,7 +124,7 @@ public class PoiUIFilter implements SearchPoiTypeFilter {
public void updateFilterResults() {
List<Amenity> prev = currentSearchResult;
if(prev != null) {
if (prev != null) {
AmenityNameFilter nameFilter = getNameFilter(filterByName);
List<Amenity> newResults = new ArrayList<Amenity>();
for(Amenity a : prev) {
@ -151,7 +152,7 @@ public class PoiUIFilter implements SearchPoiTypeFilter {
public List<Amenity> searchAgain(double lat, double lon) {
List<Amenity> amenityList ;
if(currentSearchResult != null) {
if (currentSearchResult != null) {
amenityList = currentSearchResult;
} else {
amenityList = searchAmenities(lat, lon, null);
@ -162,7 +163,7 @@ public class PoiUIFilter implements SearchPoiTypeFilter {
public List<Amenity> searchFurther(double latitude, double longitude, ResultMatcher<Amenity> matcher){
if(distanceInd < distanceToSearchValues.length - 1){
if (distanceInd < distanceToSearchValues.length - 1) {
distanceInd ++;
}
List<Amenity> amenityList = searchAmenities( latitude, longitude, matcher);
@ -354,8 +355,7 @@ public class PoiUIFilter implements SearchPoiTypeFilter {
public String getNameTokenOpen() {
return app.getString(R.string.shared_string_open);
}
private ResultMatcher<Amenity> wrapResultMatcher(final ResultMatcher<Amenity> matcher) {
final AmenityNameFilter nm = getNameFilter(filterByName);
return new ResultMatcher<Amenity>() {
@ -450,8 +450,7 @@ public class PoiUIFilter implements SearchPoiTypeFilter {
}
return false;
}
public void updateTypesToAccept(AbstractPoiType pt) {
pt.putTypes(acceptedTypes);
if (pt instanceof PoiType && ((PoiType) pt).isAdditional() && ((PoiType) pt).getParentType() != null) {
@ -466,7 +465,7 @@ public class PoiUIFilter implements SearchPoiTypeFilter {
poiAdditionals.put(add.getKeyName().replace('_', ':').replace(' ', ':'), add);
poiAdditionals.put(add.getTranslation().replace(' ', ':').toLowerCase(), add);
}
if(pt instanceof PoiFilter && !(pt instanceof PoiCategory)) {
if (pt instanceof PoiFilter && !(pt instanceof PoiCategory)) {
for(PoiType ps : ((PoiFilter) pt).getPoiTypes()) {
fillPoiAdditionals(ps);
}
@ -490,14 +489,40 @@ public class PoiUIFilter implements SearchPoiTypeFilter {
}
}
public void replaceWithPoiFilter(PoiUIFilter f) {
acceptedTypes.clear();
public void combineWithPoiFilter(PoiUIFilter f) {
acceptedTypes.putAll(f.acceptedTypes);
poiAdditionals.clear();
poiAdditionals.putAll(f.poiAdditionals);
}
public static void combineStandardPoiFilters(Set<PoiUIFilter> filters, OsmandApplication app) {
Set<PoiUIFilter> standardFilters = new TreeSet<>();
for (PoiUIFilter filter : filters) {
if ((filter.isStandardFilter() && filter.filterId.startsWith(PoiUIFilter.STD_PREFIX))
|| filter.filterId.startsWith(PoiUIFilter.CUSTOM_FILTER_ID)) {
standardFilters.add(filter);
}
}
if (!standardFilters.isEmpty()) {
PoiUIFilter standardFiltersCombined = null;
for (PoiUIFilter f : standardFilters) {
if (standardFiltersCombined == null) {
standardFiltersCombined = f;
f.filterId = PoiUIFilter.STD_PREFIX + "combined";
f.name = app.getPoiFilters().getFiltersName(standardFilters);
} else {
standardFiltersCombined.combineWithPoiFilter(f);
}
}
filters.removeAll(standardFilters);
filters.add(standardFiltersCombined);
}
}
public void replaceWithPoiFilter(PoiUIFilter f) {
clearFilter();
combineWithPoiFilter(f);
}
public Map<PoiCategory, LinkedHashSet<String>> getAcceptedTypes(){
return new LinkedHashMap<PoiCategory, LinkedHashSet<String>>(acceptedTypes);
}
@ -508,7 +533,7 @@ public class PoiUIFilter implements SearchPoiTypeFilter {
}
public void setTypeToAccept(PoiCategory poiCategory, boolean b) {
if(b) {
if (b) {
acceptedTypes.put(poiCategory, null);
} else {
acceptedTypes.remove(poiCategory);
@ -525,9 +550,9 @@ public class PoiUIFilter implements SearchPoiTypeFilter {
}
public String getIconId(){
if(filterId.startsWith(STD_PREFIX)) {
if (filterId.startsWith(STD_PREFIX)) {
return standardIconId;
} else if(filterId.startsWith(USER_PREFIX)) {
} else if (filterId.startsWith(USER_PREFIX)) {
return filterId.substring(USER_PREFIX.length()).toLowerCase();
}
return filterId;
@ -547,17 +572,17 @@ public class PoiUIFilter implements SearchPoiTypeFilter {
@Override
public boolean accept(PoiCategory type, String subtype) {
if(type == null) {
if (type == null) {
return true;
}
if(!poiTypes.isRegisteredType(type)) {
if (!poiTypes.isRegisteredType(type)) {
type = poiTypes.getOtherPoiCategory();
}
if(!acceptedTypes.containsKey(type)){
if (!acceptedTypes.containsKey(type)){
return false;
}
LinkedHashSet<String> set = acceptedTypes.get(type);
if(set == null){
if (set == null){
return true;
}
return set.contains(subtype);
@ -565,15 +590,22 @@ public class PoiUIFilter implements SearchPoiTypeFilter {
@Override
public boolean isEmpty() {
return acceptedTypes.isEmpty();
return acceptedTypes.isEmpty() &&
(currentSearchResult == null || currentSearchResult.isEmpty());
}
@Override
public int compareTo(@NonNull PoiUIFilter another) {
if (another.filterId.equals(this.filterId)) {
return 0;
} else {
return this.name.compareTo(another.name);
}
}
public interface AmenityNameFilter {
public boolean accept(Amenity a) ;
}
}
}

View file

@ -83,24 +83,20 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon
private OsmandMapTileView view;
private final static int MAXIMUM_SHOW_AMENITIES = 5;
private ResourceManager resourceManager;
private RoutingHelper routingHelper;
private PoiUIFilter filter;
private Set<PoiUIFilter> filters = new TreeSet<>();
private MapTextLayer mapTextLayer;
/// cache for displayed POI
// Work with cache (for map copied from AmenityIndexRepositoryOdb)
private MapLayerData<List<Amenity>> data;
private OsmandSettings settings;
private OsmandApplication app;
public POIMapLayer(final MapActivity activity) {
routingHelper = activity.getRoutingHelper();
routingHelper.addListener(this);
settings = activity.getMyApplication().getSettings();
app = activity.getMyApplication();
data = new OsmandMapLayer.MapLayerData<List<Amenity>>() {
{
@ -120,24 +116,28 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon
@Override
protected List<Amenity> calculateResult(RotatedTileBox tileBox) {
QuadRect latLonBounds = tileBox.getLatLonBounds();
if (filter == null || latLonBounds == null) {
if (filters.isEmpty() || latLonBounds == null) {
return new ArrayList<>();
}
int z = (int) Math.floor(tileBox.getZoom() + Math.log(view.getSettings().MAP_DENSITY.get()) / Math.log(2));
List<Amenity> res = filter.searchAmenities(latLonBounds.top, latLonBounds.left,
latLonBounds.bottom, latLonBounds.right, z, new ResultMatcher<Amenity>() {
List<Amenity> res = new ArrayList<>();
PoiUIFilter.combineStandardPoiFilters(filters, app);
for (PoiUIFilter filter : filters) {
res.addAll(filter.searchAmenities(latLonBounds.top, latLonBounds.left,
latLonBounds.bottom, latLonBounds.right, z, new ResultMatcher<Amenity>() {
@Override
public boolean publish(Amenity object) {
return true;
}
@Override
public boolean publish(Amenity object) {
return true;
}
@Override
public boolean isCancelled() {
return isInterrupted();
}
});
@Override
public boolean isCancelled() {
return isInterrupted();
}
}));
}
Collections.sort(res, new Comparator<Amenity>() {
@Override
@ -197,7 +197,6 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon
poiBackground = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_white_orange_poi_shield);
poiBackgroundSmall = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_white_orange_poi_shield_small);
resourceManager = view.getApplication().getResourceManager();
mapTextLayer = view.getLayerByClass(MapTextLayer.class);
}
@ -221,14 +220,9 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon
@Override
public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) {
if (!Algorithms.objectEquals(this.settings.SELECTED_POI_FILTER_FOR_MAP.get(),
filter == null ? null : filter.getFilterId())) {
if (this.settings.SELECTED_POI_FILTER_FOR_MAP.get() == null) {
this.filter = null;
} else {
PoiFiltersHelper pfh = app.getPoiFilters();
this.filter = pfh.getFilterById(this.settings.SELECTED_POI_FILTER_FOR_MAP.get());
}
Set<PoiUIFilter> selectedPoiFilters = app.getPoiFilters().getSelectedPoiFilters();
if (!this.filters.equals(selectedPoiFilters)) {
this.filters = new TreeSet<>(selectedPoiFilters);
data.clearCache();
}
@ -236,7 +230,7 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon
List<Amenity> fullObjects = new ArrayList<>();
List<LatLon> fullObjectsLatLon = new ArrayList<>();
List<LatLon> smallObjectsLatLon = new ArrayList<>();
if (filter != null) {
if (!filters.isEmpty()) {
if (tileBox.getZoom() >= startZoom) {
data.queryNewData(tileBox);
objects = data.getResults();
@ -315,19 +309,10 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon
showText(ctx, app, text, title);
}
public static String getSelectedPoiName(OsmandApplication app) {
PoiFiltersHelper pfh = app.getPoiFilters();
String filterId = app.getSettings().SELECTED_POI_FILTER_FOR_MAP.get();
if (filterId == null) {
return app.getResources().getString(R.string.shared_string_none);
}
PoiUIFilter filter = pfh.getFilterById(filterId);
return filter.getName();
}
static int getResIdFromAttribute(final Context ctx, final int attr) {
if (attr == 0)
if (attr == 0) {
return 0;
}
final TypedValue typedvalueattr = new TypedValue();
ctx.getTheme().resolveAttribute(attr, typedvalueattr, true);
return typedvalueattr.resourceId;
@ -491,7 +476,6 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon
}
@Override
public String getObjectDescription(Object o) {
if (o instanceof Amenity) {