Update poi types

This commit is contained in:
Victor Shcherb 2015-04-08 00:21:31 +02:00
parent ca31455f0e
commit c6ad42ee79
11 changed files with 121 additions and 111 deletions

View file

@ -1,21 +1,18 @@
package net.osmand.osm; package net.osmand.osm;
public class AbstractPoiType { import java.util.LinkedHashSet;
import java.util.Map;
public abstract class AbstractPoiType {
protected final String keyName; protected final String keyName;
protected final MapPoiTypes registry; protected final MapPoiTypes registry;
public AbstractPoiType(String keyName, MapPoiTypes registry) { public AbstractPoiType(String keyName, MapPoiTypes registry) {
this.keyName = keyName; this.keyName = keyName;
this.registry = registry; this.registry = registry;
} }
public String getName() {
return keyName;
}
public String getKeyName() { public String getKeyName() {
return keyName; return keyName;
} }
@ -24,5 +21,7 @@ public class AbstractPoiType {
return registry.getTranslation(this); return registry.getTranslation(this);
} }
public abstract Map<PoiCategory, LinkedHashSet<String>> putTypes(Map<PoiCategory, LinkedHashSet<String>> acceptedTypes);
} }

View file

@ -144,7 +144,7 @@ public class MapPoiTypes {
name = "tourism"; name = "tourism";
} }
for(PoiCategory p : categories ) { for(PoiCategory p : categories ) {
if(p.getName().equals(name) || p.getKey().equalsIgnoreCase(name)) { if(p.getKeyName().equalsIgnoreCase(name)) {
return p; return p;
} }
} }
@ -267,9 +267,9 @@ public class MapPoiTypes {
private static void print(MapPoiTypes df) { private static void print(MapPoiTypes df) {
List<PoiCategory> pc = df.getCategories(); List<PoiCategory> pc = df.getCategories();
for(PoiCategory p : pc) { for(PoiCategory p : pc) {
System.out.println("Category " + p.getName()); System.out.println("Category " + p.getKeyName());
for(PoiFilter f : p.getPoiFilters()) { for(PoiFilter f : p.getPoiFilters()) {
System.out.println(" Filter " + f.getName()); System.out.println(" Filter " + f.getKeyName());
print(" ", f); print(" ", f);
} }
print(" ", p); print(" ", p);
@ -279,8 +279,8 @@ 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.getKeyName() +
(pt.isReference() ? (" -> " + pt.getReferenceType().getCategory().getKey() ): "")); (pt.isReference() ? (" -> " + pt.getReferenceType().getCategory().getKeyName() ): ""));
} }
} }
@ -307,7 +307,7 @@ public class MapPoiTypes {
return translation; return translation;
} }
} }
return Algorithms.capitalizeFirstLetterAndLowercase(abstractPoiType.getName().replace('_', ' ')); return Algorithms.capitalizeFirstLetterAndLowercase(abstractPoiType.getKeyName().replace('_', ' '));
} }

View file

@ -48,9 +48,6 @@ public class PoiCategory extends PoiFilter {
return keyName.equals(MapPoiTypes.OSM_WIKI_CATEGORY); return keyName.equals(MapPoiTypes.OSM_WIKI_CATEGORY);
} }
public String getKey() {
return keyName;
}
public int ordinal() { public int ordinal() {
return regId; return regId;

View file

@ -27,15 +27,15 @@ public class PoiFilter extends AbstractPoiType {
} }
public void addPoiType(PoiType type) { public void addPoiType(PoiType type) {
if(!map.containsKey(type.getName())) { if(!map.containsKey(type.getKeyName())) {
poiTypes.add(type); poiTypes.add(type);
map.put(type.getName(), type); map.put(type.getKeyName(), type);
} else { } else {
PoiType prev = map.get(type.getName()); PoiType prev = map.get(type.getKeyName());
if(prev.isReference()) { if(prev.isReference()) {
poiTypes.remove(prev); poiTypes.remove(prev);
poiTypes.add(type); poiTypes.add(type);
map.put(type.getName(), type); map.put(type.getKeyName(), type);
} }
} }
} }
@ -71,10 +71,6 @@ public class PoiFilter extends AbstractPoiType {
return poiTypes; return poiTypes;
} }
public String getName() {
return keyName;
}
public void setTopVisible(boolean topVisible) { public void setTopVisible(boolean topVisible) {
this.topVisible = topVisible; this.topVisible = topVisible;
} }

View file

@ -1,5 +1,8 @@
package net.osmand.osm; package net.osmand.osm;
import java.util.LinkedHashSet;
import java.util.Map;
public class PoiType extends AbstractPoiType { public class PoiType extends AbstractPoiType {
private PoiCategory category; private PoiCategory category;
@ -74,5 +77,17 @@ public class PoiType extends AbstractPoiType {
return category; return category;
} }
public Map<PoiCategory, LinkedHashSet<String>> putTypes(Map<PoiCategory, LinkedHashSet<String>> acceptedTypes) {
PoiType rt = getReferenceType();
PoiType poiType = rt != null ? rt : this;
if (!acceptedTypes.containsKey(poiType.category)) {
acceptedTypes.put(poiType.category, new LinkedHashSet<String>());
}
LinkedHashSet<String> set = acceptedTypes.get(poiType.category);
if(set != null) {
set.add(poiType.getKeyName());
}
return acceptedTypes;
}
} }

View file

@ -10,6 +10,7 @@
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginLeft="5dp" android:layout_marginLeft="5dp"
android:visibility="gone"
android:orientation="horizontal" > android:orientation="horizontal" >
<ImageView <ImageView
@ -59,7 +60,7 @@
android:layout_weight="1" /> android:layout_weight="1" />
<net.osmand.plus.activities.search.toolbar.SplitToolbar <net.osmand.plus.activities.search.toolbar.SplitToolbar
android:id="@+id/bottomControls" android:id="@+id/poiSplitbar"
android:layout_width="fill_parent" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="?attr/bottomToolBarColor" android:background="?attr/bottomToolBarColor"

View file

@ -255,26 +255,14 @@ public class MapActivityLayers {
public AlertDialog selectPOIFilterLayer(final OsmandMapTileView mapView, final PoiLegacyFilter[] selected){ public AlertDialog selectPOIFilterLayer(final OsmandMapTileView mapView, final PoiLegacyFilter[] selected){
final List<PoiLegacyFilter> userDefined = new ArrayList<PoiLegacyFilter>();
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>(); final List<PoiLegacyFilter> list = new ArrayList<PoiLegacyFilter>();
for (PoiLegacyFilter f : poiFilters.getTopDefinedPoiFilters()) { for (PoiLegacyFilter f : poiFilters.getTopDefinedPoiFilters()) {
if(PoiLegacyFilter.BY_NAME_FILTER_ID.equals(f.getFilterId()) || addFilterToList(adapter, list, f);
PoiLegacyFilter.NAME_FINDER_FILTER_ID.equals(f.getFilterId())) {
continue;
}
list.add(f);
Item it = adapter.item(f.getName());
if (RenderingIcons.containsBigIcon(f.getSimplifiedId())) {
it.icon(RenderingIcons.getBigIconResourceId(f.getSimplifiedId()));
} else {
it.icon(RenderingIcons.getBigIconResourceId("user_defined"));
}
it.reg();
userDefined.add(f);
} }
addFilterToList(adapter, list, poiFilters.getCustomPOIFilter());
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(){
@ -309,6 +297,17 @@ public class MapActivityLayers {
return builder.show(); return builder.show();
} }
private void addFilterToList(final ContextMenuAdapter adapter, final List<PoiLegacyFilter> list, PoiLegacyFilter f) {
list.add(f);
Item it = adapter.item(f.getName());
if (RenderingIcons.containsBigIcon(f.getSimplifiedId())) {
it.icon(RenderingIcons.getBigIconResourceId(f.getSimplifiedId()));
} else {
it.icon(RenderingIcons.getBigIconResourceId("user_defined"));
}
it.reg();
}
public void selectMapLayer(final OsmandMapTileView mapView){ public void selectMapLayer(final OsmandMapTileView mapView){
if(OsmandPlugin.getEnabledPlugin(OsmandRasterMapsPlugin.class) == null) { if(OsmandPlugin.getEnabledPlugin(OsmandRasterMapsPlugin.class) == null) {
AccessibleToast.makeText(activity, R.string.map_online_plugin_is_not_installed, Toast.LENGTH_LONG).show(); AccessibleToast.makeText(activity, R.string.map_online_plugin_is_not_installed, Toast.LENGTH_LONG).show();

View file

@ -52,7 +52,6 @@ import android.graphics.drawable.Drawable;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.AsyncTask.Status; import android.os.AsyncTask.Status;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler;
import android.support.v4.view.MenuItemCompat; import android.support.v4.view.MenuItemCompat;
import android.support.v7.widget.PopupMenu; import android.support.v7.widget.PopupMenu;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
@ -61,21 +60,17 @@ import android.text.SpannableString;
import android.text.TextWatcher; import android.text.TextWatcher;
import android.text.method.LinkMovementMethod; import android.text.method.LinkMovementMethod;
import android.text.util.Linkify; import android.text.util.Linkify;
import android.view.Gravity;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.MenuItem.OnMenuItemClickListener; import android.view.MenuItem.OnMenuItemClickListener;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.view.WindowManager; import android.view.WindowManager;
import android.widget.AdapterView; import android.widget.AdapterView;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText; import android.widget.EditText;
import android.widget.Filter; import android.widget.Filter;
import android.widget.FrameLayout;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
@ -104,7 +99,6 @@ public class SearchPOIActivity extends OsmandListActivity implements OsmAndCompa
private net.osmand.Location location = null; private net.osmand.Location location = null;
private Float heading = null; private Float heading = null;
private Handler uiHandler;
private OsmandSettings settings; private OsmandSettings settings;
private float width = 24; private float width = 24;
@ -116,7 +110,6 @@ public class SearchPOIActivity extends OsmandListActivity implements OsmAndCompa
private MenuItem showFilterItem; private MenuItem showFilterItem;
private MenuItem showOnMapItem; private MenuItem showOnMapItem;
private MenuItem searchPOILevel; private MenuItem searchPOILevel;
private Button searchFooterButton;
@Override @Override
public boolean onCreateOptionsMenu(Menu menu) { public boolean onCreateOptionsMenu(Menu menu) {
@ -188,7 +181,7 @@ public class SearchPOIActivity extends OsmandListActivity implements OsmAndCompa
} }
public Toolbar getClearToolbar(boolean visible) { public Toolbar getClearToolbar(boolean visible) {
final Toolbar tb = (Toolbar) findViewById(R.id.bottomControls); final Toolbar tb = (Toolbar) findViewById(R.id.poiSplitbar);
tb.setTitle(null); tb.setTitle(null);
tb.getMenu().clear(); tb.getMenu().clear();
tb.setVisibility(visible ? View.VISIBLE : View.GONE); tb.setVisibility(visible ? View.VISIBLE : View.GONE);
@ -229,7 +222,6 @@ public class SearchPOIActivity extends OsmandListActivity implements OsmAndCompa
app = (OsmandApplication) getApplication(); app = (OsmandApplication) getApplication();
uiHandler = new Handler();
searchFilter = (EditText) findViewById(R.id.edit); searchFilter = (EditText) findViewById(R.id.edit);
searchFilterLayout = findViewById(R.id.SearchFilterLayout); searchFilterLayout = findViewById(R.id.SearchFilterLayout);
@ -245,9 +237,6 @@ public class SearchPOIActivity extends OsmandListActivity implements OsmAndCompa
searchPOILevel.setEnabled(true); searchPOILevel.setEnabled(true);
searchPOILevel.setTitle(R.string.search_button); searchPOILevel.setTitle(R.string.search_button);
} }
searchFooterButton.setEnabled(true);
searchFooterButton.setText(R.string.search_button);
// Cancel current search request here?
} }
} }
@ -267,7 +256,6 @@ public class SearchPOIActivity extends OsmandListActivity implements OsmAndCompa
} }
} }
}); });
addFooterView();
amenityAdapter = new AmenityAdapter(new ArrayList<Amenity>()); amenityAdapter = new AmenityAdapter(new ArrayList<Amenity>());
setListAdapter(amenityAdapter); setListAdapter(amenityAdapter);
@ -280,25 +268,6 @@ public class SearchPOIActivity extends OsmandListActivity implements OsmAndCompa
} }
} }
private void addFooterView() {
final FrameLayout ll = new FrameLayout(this);
android.widget.FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
lp.gravity = Gravity.CENTER_HORIZONTAL;
searchFooterButton = new Button(this);
searchFooterButton.setText(R.string.search_POI_level_btn);
searchFooterButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
searchMore();
}
});
searchFooterButton.setLayoutParams(lp);
ll.addView(searchFooterButton);
getListView().addFooterView(ll);
}
@Override @Override
protected void onResume() { protected void onResume() {
super.onResume(); super.onResume();
@ -436,14 +405,6 @@ public class SearchPOIActivity extends OsmandListActivity implements OsmAndCompa
searchPOILevel.setEnabled(enabled); searchPOILevel.setEnabled(enabled);
searchPOILevel.setTitle(title); searchPOILevel.setTitle(title);
} }
// if(ResourcesCompat.getResources_getBoolean(this, R.bool.abs__split_action_bar_is_narrow)) {
if (true) {
searchFooterButton.setVisibility(View.GONE);
} else {
searchFooterButton.setVisibility(View.VISIBLE);
searchFooterButton.setEnabled(enabled);
searchFooterButton.setText(title);
}
} }
private net.osmand.Location getSearchedLocation() { private net.osmand.Location getSearchedLocation() {
@ -637,7 +598,6 @@ public class SearchPOIActivity extends OsmandListActivity implements OsmAndCompa
if (searchPOILevel != null) { if (searchPOILevel != null) {
searchPOILevel.setEnabled(false); searchPOILevel.setEnabled(false);
} }
searchFooterButton.setEnabled(false);
existingObjects = new TLongHashSet(); existingObjects = new TLongHashSet();
updateExisting = new TLongHashSet(); updateExisting = new TLongHashSet();
if (request.type == SearchAmenityRequest.NEW_SEARCH_INIT) { if (request.type == SearchAmenityRequest.NEW_SEARCH_INIT) {

View file

@ -50,13 +50,16 @@ public class SearchPoiFilterFragment extends ListFragment implements SearchActiv
private EditText searchEditText; private EditText searchEditText;
private SearchPoiByNameTask currentTask = null; private SearchPoiByNameTask currentTask = null;
private PoiFiltersAdapter poiFitlersAdapter;
public View onCreateView(LayoutInflater inflater, ViewGroup container, public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) { Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.searchpoi, container, false); View v = inflater.inflate(R.layout.searchpoi, container, false);
v.findViewById(R.id.SearchFilterLayout).setVisibility(View.VISIBLE);
setupSearchEditText((EditText) v.findViewById(R.id.edit)); setupSearchEditText((EditText) v.findViewById(R.id.edit));
setupOptions(v.findViewById(R.id.options)); setupOptions(v.findViewById(R.id.options));
v.findViewById(R.id.bottomControls).setVisibility(View.GONE); v.findViewById(R.id.poiSplitbar).setVisibility(View.GONE);
return v; return v;
} }
@ -89,15 +92,16 @@ public class SearchPoiFilterFragment extends ListFragment implements SearchActiv
@Override @Override
public void onActivityCreated(Bundle savedInstanceState) { public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState); super.onActivityCreated(savedInstanceState);
setHasOptionsMenu(true);
refreshPoiListAdapter(); refreshPoiListAdapter();
setHasOptionsMenu(true);
} }
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.getTopDefinedPoiFilters()); filters.addAll(poiFilters.getTopDefinedPoiFilters());
setListAdapter(new AmenityAdapter(filters)); poiFitlersAdapter = new PoiFiltersAdapter(filters);
setListAdapter(poiFitlersAdapter);
} }
public OsmandApplication getApp(){ public OsmandApplication getApp(){
@ -139,12 +143,7 @@ public class SearchPoiFilterFragment extends ListFragment implements SearchActiv
@Override @Override
public void onListItemClick(ListView listView, View v, int position, long id) { public void onListItemClick(ListView listView, View v, int position, long id) {
final PoiLegacyFilter filter = ((AmenityAdapter) getListAdapter()).getItem(position); final PoiLegacyFilter filter = ((PoiFiltersAdapter) getListAdapter()).getItem(position);
if (filter.getFilterId().equals(PoiLegacyFilter.CUSTOM_FILTER_ID)) {
filter.clearFilter();
showEditActivity(filter);
return;
}
if(!(filter instanceof NameFinderPoiFilter)){ if(!(filter instanceof NameFinderPoiFilter)){
ResourceManager rm = getApp().getResourceManager(); ResourceManager rm = getApp().getResourceManager();
if(!rm.containsAmenityRepositoryToSearch(filter instanceof SearchByNameFilter)){ if(!rm.containsAmenityRepositoryToSearch(filter instanceof SearchByNameFilter)){
@ -177,10 +176,10 @@ public class SearchPoiFilterFragment extends ListFragment implements SearchActiv
} }
class AmenityAdapter extends ArrayAdapter<PoiLegacyFilter> { class PoiFiltersAdapter extends ArrayAdapter<PoiLegacyFilter> {
AmenityAdapter(List<PoiLegacyFilter> list) { PoiFiltersAdapter(List<PoiLegacyFilter> list) {
super(getActivity(), R.layout.searchpoifolder_list, list); super(getActivity(), R.layout.searchpoifolder_list, list);
} }

View file

@ -13,6 +13,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.osm.PoiFilter;
import net.osmand.osm.PoiType;
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,6 +24,9 @@ public class PoiFiltersHelper {
private final OsmandApplication application; private final OsmandApplication application;
private NameFinderPoiFilter nameFinderPOIFilter; private NameFinderPoiFilter nameFinderPOIFilter;
private PoiLegacyFilter searchByNamePOIFilter;
private PoiLegacyFilter customPOIFilter;
private PoiLegacyFilter showAllPOIFilter;
private List<PoiLegacyFilter> cacheTopStandardFilters; private List<PoiLegacyFilter> cacheTopStandardFilters;
private static final String UDF_CAR_AID = "car_aid"; private static final String UDF_CAR_AID = "car_aid";
@ -44,6 +48,7 @@ public class PoiFiltersHelper {
public PoiFiltersHelper(OsmandApplication application){ public PoiFiltersHelper(OsmandApplication application){
this.application = application; this.application = application;
} }
public NameFinderPoiFilter getNameFinderPOIFilter() { public NameFinderPoiFilter getNameFinderPOIFilter() {
if(nameFinderPOIFilter == null){ if(nameFinderPOIFilter == null){
nameFinderPOIFilter = new NameFinderPoiFilter(application); nameFinderPOIFilter = new NameFinderPoiFilter(application);
@ -51,7 +56,43 @@ public class PoiFiltersHelper {
return nameFinderPOIFilter; return nameFinderPOIFilter;
} }
public PoiLegacyFilter getSearchByNamePOIFilter() {
if(searchByNamePOIFilter == null){
PoiLegacyFilter filter = new SearchByNameFilter(application);
filter.setStandardFilter(true);
searchByNamePOIFilter = filter;
}
return searchByNamePOIFilter;
}
public PoiLegacyFilter getCustomPOIFilter() {
if(customPOIFilter == null){
PoiLegacyFilter filter = new PoiLegacyFilter(application.getString(R.string.poi_filter_custom_filter),
PoiLegacyFilter.CUSTOM_FILTER_ID, new LinkedHashMap<PoiCategory, LinkedHashSet<String>>(), application); //$NON-NLS-1$
filter.setStandardFilter(true);
customPOIFilter = filter;
}
return customPOIFilter;
}
public PoiLegacyFilter getShowAllPOIFilter() {
if(showAllPOIFilter == null){
PoiLegacyFilter filter = new PoiLegacyFilter(null, application); //$NON-NLS-1$
filter.setStandardFilter(true);
showAllPOIFilter = filter;
}
return showAllPOIFilter;
}
private PoiLegacyFilter getFilterById(String filterId, PoiLegacyFilter... filters){
for(PoiLegacyFilter pf : filters) {
if(pf.getFilterId().equals(filterId)){
return pf;
}
}
return null;
}
public PoiLegacyFilter getFilterById(String filterId){ public PoiLegacyFilter getFilterById(String filterId){
if(filterId == null){ if(filterId == null){
@ -62,6 +103,18 @@ public class PoiFiltersHelper {
return f; return f;
} }
} }
PoiLegacyFilter ff = getFilterById(filterId, getCustomPOIFilter(), getSearchByNamePOIFilter(),
getShowAllPOIFilter(), getNameFinderPOIFilter());
if (ff != null) {
return ff;
}
if(filterId.startsWith(PoiLegacyFilter.STD_PREFIX)) {
String typeId = filterId.substring(PoiLegacyFilter.STD_PREFIX.length());
PoiType tp = application.getPoiTypes().getPoiTypeByKey(typeId);
if(tp != null) {
return new PoiLegacyFilter(tp, application);
}
}
return null; return null;
} }
@ -117,19 +170,6 @@ public class PoiFiltersHelper {
public List<PoiLegacyFilter> getTopDefinedPoiFilters() { public List<PoiLegacyFilter> getTopDefinedPoiFilters() {
if (cacheTopStandardFilters == null) { if (cacheTopStandardFilters == null) {
cacheTopStandardFilters = new ArrayList<PoiLegacyFilter>(); cacheTopStandardFilters = new ArrayList<PoiLegacyFilter>();
// by name
PoiLegacyFilter filter = new SearchByNameFilter(application);
filter.setStandardFilter(true);
cacheTopStandardFilters.add(filter);
// custom
filter = new PoiLegacyFilter(application.getString(R.string.poi_filter_custom_filter),
PoiLegacyFilter.CUSTOM_FILTER_ID, new LinkedHashMap<PoiCategory, LinkedHashSet<String>>(), application); //$NON-NLS-1$
filter.setStandardFilter(true);
cacheTopStandardFilters.add(filter);
// all
cacheTopStandardFilters.add(new PoiLegacyFilter(null, application));
// name finder
cacheTopStandardFilters.add(getNameFinderPOIFilter());
// user defined // user defined
cacheTopStandardFilters.addAll(getUserDefinedPoiFilters()); cacheTopStandardFilters.addAll(getUserDefinedPoiFilters());
// default // default
@ -139,7 +179,10 @@ public class PoiFiltersHelper {
} }
sortListOfFilters(cacheTopStandardFilters); sortListOfFilters(cacheTopStandardFilters);
} }
return Collections.unmodifiableList(cacheTopStandardFilters); List<PoiLegacyFilter> result = new ArrayList<PoiLegacyFilter>();
result.add(getShowAllPOIFilter());
result.addAll(cacheTopStandardFilters);
return result;
} }
private PoiFilterDbHelper openDbHelper(){ private PoiFilterDbHelper openDbHelper(){
@ -287,13 +330,13 @@ public class PoiFiltersHelper {
for(PoiCategory a : types.keySet()){ for(PoiCategory a : types.keySet()){
if(types.get(a) == null){ if(types.get(a) == null){
insertCategories.bindString(1, p.getFilterId()); insertCategories.bindString(1, p.getFilterId());
insertCategories.bindString(2, a.getKey()); insertCategories.bindString(2, a.getKeyName());
insertCategories.bindNull(3); insertCategories.bindNull(3);
insertCategories.execute(); insertCategories.execute();
} else { } else {
for(String s : types.get(a)){ for(String s : types.get(a)){
insertCategories.bindString(1, p.getFilterId()); insertCategories.bindString(1, p.getFilterId());
insertCategories.bindString(2, a.getKey()); insertCategories.bindString(2, a.getKeyName());
insertCategories.bindString(3, s); insertCategories.bindString(3, s);
insertCategories.execute(); insertCategories.execute();
} }

View file

@ -12,6 +12,7 @@ import java.util.Set;
import net.osmand.ResultMatcher; import net.osmand.ResultMatcher;
import net.osmand.data.Amenity; import net.osmand.data.Amenity;
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.PoiFilter;
@ -47,10 +48,10 @@ public class PoiLegacyFilter {
// constructor for standard filters // constructor for standard filters
public PoiLegacyFilter(PoiFilter type, OsmandApplication application) { public PoiLegacyFilter(AbstractPoiType 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.getKeyName());
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) {