use of net.osmand.plus.plugins.osmedit.dialogs.EditPoiDialogFragment in project Osmand by osmandapp.
the class OsmEditingPlugin method registerMapContextMenuActions.
@Override
public void registerMapContextMenuActions(@NonNull final MapActivity mapActivity, final double latitude, final double longitude, ContextMenuAdapter adapter, final Object selectedObj, boolean configureMenu) {
ContextMenuAdapter.ItemClickListener listener = (adptr, resId, pos, isChecked, 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, "", false);
} else if (resId == R.string.context_menu_item_modify_note) {
modifyOsmNote(mapActivity, (OsmNotesPoint) selectedObj);
} else if (resId == R.string.poi_context_menu_modify) {
if (selectedObj instanceof TransportStop && ((TransportStop) selectedObj).getAmenity() != null) {
EditPoiDialogFragment.showEditInstance(((TransportStop) selectedObj).getAmenity(), mapActivity);
} else if (selectedObj instanceof MapObject) {
EditPoiDialogFragment.showEditInstance((MapObject) selectedObj, mapActivity);
}
} else if (resId == R.string.poi_context_menu_modify_osm_change) {
final Entity entity = ((OpenstreetmapPoint) selectedObj).getEntity();
EditPoiDialogFragment.createInstance(entity, false).show(mapActivity.getSupportFragmentManager(), EditPoiDialogFragment.TAG);
}
return true;
};
boolean isEditable = false;
if (selectedObj instanceof Amenity || (selectedObj instanceof TransportStop && ((TransportStop) selectedObj).getAmenity() != null)) {
Amenity amenity;
if (selectedObj instanceof Amenity) {
amenity = (Amenity) selectedObj;
} else {
amenity = ((TransportStop) selectedObj).getAmenity();
}
final PoiType poiType = amenity.getType().getPoiTypeByKeyName(amenity.getSubType());
isEditable = !amenity.getType().isWiki() && poiType != null && !poiType.isNotEditableOsm();
} else if (selectedObj instanceof MapObject) {
Long objectId = ((MapObject) selectedObj).getId();
isEditable = objectId != null && objectId > 0 && (objectId % 2 == MapObject.AMENITY_ID_RIGHT_SHIFT || (objectId >> MapObject.NON_AMENITY_ID_RIGHT_SHIFT) < Integer.MAX_VALUE);
}
if (isEditable) {
adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.poi_context_menu_modify, mapActivity).setId(MAP_CONTEXT_MENU_CREATE_POI).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).setId(MAP_CONTEXT_MENU_CREATE_POI).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).setId(MAP_CONTEXT_MENU_CREATE_POI).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).setId(MAP_CONTEXT_MENU_OPEN_OSM_NOTE).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).setId(MAP_CONTEXT_MENU_OPEN_OSM_NOTE).setIcon(R.drawable.ic_action_osm_note_add).setOrder(OPEN_OSM_NOTE_ITEM_ORDER).setListener(listener).createItem());
}
}
use of net.osmand.plus.plugins.osmedit.dialogs.EditPoiDialogFragment in project Osmand by osmandapp.
the class AddPOIAction method execute.
@Override
public void execute(@NonNull final MapActivity mapActivity) {
OsmandApplication app = mapActivity.getMyApplication();
OsmandSettings settings = app.getSettings();
OsmEditingPlugin plugin = OsmandPlugin.getPlugin(OsmEditingPlugin.class);
if (plugin == null)
return;
LatLon latLon = mapActivity.getMapView().getCurrentRotatedTileBox().getCenterLatLon();
Node node = new Node(latLon.getLatitude(), latLon.getLongitude(), -1);
node.replaceTags(getTagsFromParams());
EditPoiData editPoiData = new EditPoiData(node, mapActivity.getMyApplication());
if (Boolean.parseBoolean(getParams().get(KEY_DIALOG)) || editPoiData.hasEmptyValue()) {
Entity newEntity = editPoiData.getEntity();
EditPoiDialogFragment editPoiDialogFragment = EditPoiDialogFragment.createInstance(newEntity, true, getTagsFromParams());
editPoiDialogFragment.show(mapActivity.getSupportFragmentManager(), EditPoiDialogFragment.TAG);
} else {
OpenstreetmapUtil mOpenstreetmapUtil;
if (plugin.OFFLINE_EDITION.get() || !settings.isInternetConnectionAvailable(true)) {
mOpenstreetmapUtil = plugin.getPoiModificationLocalUtil();
} else {
mOpenstreetmapUtil = plugin.getPoiModificationRemoteUtil();
}
final boolean offlineEdit = mOpenstreetmapUtil instanceof OpenstreetmapLocalUtil;
Node newNode = new Node(node.getLatitude(), node.getLongitude(), node.getId());
Action action = newNode.getId() < 0 ? OsmPoint.Action.CREATE : OsmPoint.Action.MODIFY;
for (Map.Entry<String, String> tag : editPoiData.getTagValues().entrySet()) {
if (tag.getKey().equals(POI_TYPE_TAG)) {
final PoiType poiType = editPoiData.getAllTranslatedSubTypes().get(tag.getValue().trim().toLowerCase());
if (poiType != null) {
newNode.putTagNoLC(poiType.getEditOsmTag(), poiType.getEditOsmValue());
if (poiType.getOsmTag2() != null) {
newNode.putTagNoLC(poiType.getOsmTag2(), poiType.getOsmValue2());
}
if (poiType.getEditOsmTag2() != null) {
newNode.putTagNoLC(poiType.getEditOsmTag2(), poiType.getEditOsmValue2());
}
} else if (!Algorithms.isEmpty(tag.getValue())) {
PoiCategory category = editPoiData.getPoiCategory();
if (category != null) {
newNode.putTagNoLC(category.getDefaultTag(), tag.getValue());
}
}
if (offlineEdit && !Algorithms.isEmpty(tag.getValue())) {
newNode.putTagNoLC(tag.getKey(), tag.getValue());
}
} else if (!Algorithms.isEmpty(tag.getKey()) && !Algorithms.isEmpty(tag.getValue())) {
newNode.putTagNoLC(tag.getKey(), tag.getValue());
}
}
EditPoiDialogFragment.commitEntity(action, newNode, mOpenstreetmapUtil.getEntityInfo(newNode.getId()), "", false, result -> {
if (result != null) {
OsmEditingPlugin plugin1 = OsmandPlugin.getPlugin(OsmEditingPlugin.class);
if (plugin1 != null && offlineEdit) {
List<OpenstreetmapPoint> points = plugin1.getDBPOI().getOpenstreetmapPoints();
if (points.size() > 0) {
OsmPoint point = points.get(points.size() - 1);
mapActivity.getContextMenu().showOrUpdate(new LatLon(point.getLatitude(), point.getLongitude()), plugin1.getOsmEditsLayer(mapActivity).getObjectName(point), point);
}
}
mapActivity.getMapView().refreshMap(true);
}
return false;
}, mapActivity, mOpenstreetmapUtil, null);
}
}
Aggregations