use of net.osmand.data.Amenity in project Osmand by osmandapp.
the class PoiUIFilter method searchAmenities.
public List<Amenity> searchAmenities(double top, double left, double bottom, double right, int zoom, ResultMatcher<Amenity> matcher) {
List<Amenity> results = new ArrayList<Amenity>();
List<Amenity> tempResults = currentSearchResult;
if (tempResults != null) {
for (Amenity a : tempResults) {
LatLon l = a.getLocation();
if (l != null && l.getLatitude() <= top && l.getLatitude() >= bottom && l.getLongitude() >= left && l.getLongitude() <= right) {
if (matcher == null || matcher.publish(a)) {
results.add(a);
}
}
}
}
List<Amenity> amenities = searchAmenitiesInternal(top / 2 + bottom / 2, left / 2 + right / 2, top, bottom, left, right, zoom, matcher);
results.addAll(amenities);
return results;
}
use of net.osmand.data.Amenity in project Osmand by osmandapp.
the class PoiUIFilter method getNameFilter.
public AmenityNameFilter getNameFilter(String filter) {
if (Algorithms.isEmpty(filter)) {
return new AmenityNameFilter() {
@Override
public boolean accept(Amenity a) {
return true;
}
};
}
StringBuilder nmFilter = new StringBuilder();
String[] items = filter.split(" ");
boolean allTime = false;
boolean open = false;
List<PoiType> poiAdditionalsFilter = null;
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 if (poiAdditionals.containsKey(s.toLowerCase())) {
if (poiAdditionalsFilter == null) {
poiAdditionalsFilter = new ArrayList<>();
}
PoiType pt = poiAdditionals.get(s.toLowerCase());
if (pt != null) {
poiAdditionalsFilter.add(pt);
}
} else {
nmFilter.append(s).append(" ");
}
}
}
return getNameFilterInternal(nmFilter, allTime, open, poiAdditionalsFilter);
}
use of net.osmand.data.Amenity in project Osmand by osmandapp.
the class PoiUIFilter method updateFilterResults.
public void updateFilterResults() {
List<Amenity> prev = currentSearchResult;
if (prev != null) {
AmenityNameFilter nameFilter = getNameFilter(filterByName);
List<Amenity> newResults = new ArrayList<Amenity>();
for (Amenity a : prev) {
if (nameFilter.accept(a)) {
newResults.add(a);
}
}
currentSearchResult = newResults;
}
}
use of net.osmand.data.Amenity in project Osmand by osmandapp.
the class OsmEditingPlugin method registerMapContextMenuActions.
@Override
public void registerMapContextMenuActions(final MapActivity mapActivity, final double latitude, final double longitude, ContextMenuAdapter adapter, final Object selectedObj) {
ContextMenuAdapter.ItemClickListener listener = new ContextMenuAdapter.ItemClickListener() {
@Override
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int resId, int pos, boolean isChecked, int[] viewCoordinates) {
if (resId == R.string.context_menu_item_create_poi) {
// getPoiActions(mapActivity).showCreateDialog(latitude, longitude);
EditPoiDialogFragment editPoiDialogFragment = EditPoiDialogFragment.createAddPoiInstance(latitude, longitude, mapActivity.getMyApplication());
editPoiDialogFragment.show(mapActivity.getSupportFragmentManager(), EditPoiDialogFragment.TAG);
} else if (resId == R.string.context_menu_item_open_note) {
openOsmNote(mapActivity, latitude, longitude);
} else if (resId == R.string.context_menu_item_modify_note) {
modifyOsmNote(mapActivity, (OsmNotesPoint) selectedObj);
} else if (resId == R.string.poi_context_menu_modify) {
EditPoiDialogFragment.showEditInstance((Amenity) selectedObj, mapActivity);
} else if (resId == R.string.poi_context_menu_modify_osm_change) {
final Node entity = ((OpenstreetmapPoint) selectedObj).getEntity();
EditPoiDialogFragment.createInstance(entity, false).show(mapActivity.getSupportFragmentManager(), EditPoiDialogFragment.TAG);
}
return true;
}
};
boolean isEditable = false;
if (selectedObj instanceof Amenity) {
Amenity amenity = (Amenity) selectedObj;
final PoiType poiType = amenity.getType().getPoiTypeByKeyName(amenity.getSubType());
isEditable = !amenity.getType().isWiki() && poiType != null && !poiType.isNotEditableOsm();
}
if (isEditable) {
adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.poi_context_menu_modify, mapActivity).setIcon(R.drawable.ic_action_edit_dark).setOrder(MODIFY_POI_ITEM_ORDER).setListener(listener).createItem());
} else if (selectedObj instanceof OpenstreetmapPoint && ((OpenstreetmapPoint) selectedObj).getAction() != Action.DELETE) {
adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.poi_context_menu_modify_osm_change, mapActivity).setIcon(R.drawable.ic_action_edit_dark).setOrder(MODIFY_OSM_CHANGE_ITEM_ORDER).setListener(listener).createItem());
} else {
adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.context_menu_item_create_poi, mapActivity).setIcon(R.drawable.ic_action_plus_dark).setOrder(CREATE_POI_ITEM_ORDER).setListener(listener).createItem());
}
if (selectedObj instanceof OsmNotesPoint) {
adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.context_menu_item_modify_note, mapActivity).setIcon(R.drawable.ic_action_edit_dark).setOrder(MODIFY_OSM_NOTE_ITEM_ORDER).setListener(listener).createItem());
} else {
adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.context_menu_item_open_note, mapActivity).setIcon(R.drawable.ic_action_bug_dark).setOrder(OPEN_OSM_NOTE_ITEM_ORDER).setListener(listener).createItem());
}
}
use of net.osmand.data.Amenity in project Osmand by osmandapp.
the class MenuBuilder method getCollapsableWikiView.
protected View getCollapsableWikiView(Context context, boolean collapsed) {
final LinearLayout view = new LinearLayout(context);
view.setOrientation(LinearLayout.VERTICAL);
view.setVisibility(collapsed ? View.GONE : View.VISIBLE);
LinearLayout.LayoutParams llParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
llParams.setMargins(dpToPx(68f), 0, dpToPx(12f), dpToPx(13f));
view.setLayoutParams(llParams);
for (final Amenity wiki : nearestWiki) {
AppCompatButton wikiButton = new AppCompatButton(new ContextThemeWrapper(view.getContext(), R.style.AppTheme));
LinearLayout.LayoutParams llWikiButtonParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
wikiButton.setLayoutParams(llWikiButtonParams);
wikiButton.setPadding(dpToPx(14f), 0, dpToPx(14f), 0);
wikiButton.setTextColor(app.getResources().getColor(light ? R.color.color_dialog_buttons_light : R.color.color_dialog_buttons_dark));
wikiButton.setText(wiki.getName());
wikiButton.setGravity(Gravity.LEFT | Gravity.CENTER_VERTICAL);
wikiButton.setSingleLine(true);
wikiButton.setEllipsize(TextUtils.TruncateAt.END);
wikiButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
PointDescription pointDescription = MenuController.getObjectName(wiki);
mainActivity.getContextMenu().show(new LatLon(wiki.getLocation().getLatitude(), wiki.getLocation().getLongitude()), pointDescription, wiki);
}
});
view.addView(wikiButton);
}
return view;
}
Aggregations