use of net.osmand.plus.osmedit.OsmPoint in project Osmand by osmandapp.
the class AddPOIAction method execute.
@Override
public void execute(final MapActivity activity) {
LatLon latLon = activity.getMapView().getCurrentRotatedTileBox().getCenterLatLon();
OsmEditingPlugin plugin = OsmandPlugin.getPlugin(OsmEditingPlugin.class);
if (plugin == null)
return;
Node node = new Node(latLon.getLatitude(), latLon.getLongitude(), -1);
node.replaceTags(getTagsFromParams());
EditPoiData editPoiData = new EditPoiData(node, activity.getMyApplication());
if (Boolean.valueOf(getParams().get(KEY_DIALOG))) {
Node newNode = editPoiData.getEntity();
EditPoiDialogFragment editPoiDialogFragment = EditPoiDialogFragment.createInstance(newNode, true, getTagsFromParams());
editPoiDialogFragment.show(activity.getSupportFragmentManager(), EditPoiDialogFragment.TAG);
} else {
OpenstreetmapUtil mOpenstreetmapUtil;
if (activity.getMyApplication().getSettings().OFFLINE_EDITION.get() || !activity.getMyApplication().getSettings().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());
OsmPoint.Action action = newNode.getId() < 0 ? OsmPoint.Action.CREATE : OsmPoint.Action.MODIFY;
for (Map.Entry<String, String> tag : editPoiData.getTagValues().entrySet()) {
if (tag.getKey().equals(EditPoiData.POI_TYPE_TAG)) {
final PoiType poiType = editPoiData.getAllTranslatedSubTypes().get(tag.getValue().trim().toLowerCase());
if (poiType != null) {
newNode.putTagNoLC(poiType.getOsmTag(), poiType.getOsmValue());
if (poiType.getOsmTag2() != null) {
newNode.putTagNoLC(poiType.getOsmTag2(), poiType.getOsmValue2());
}
} else if (!Algorithms.isEmpty(tag.getValue())) {
newNode.putTagNoLC(editPoiData.getPoiCategory().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.commitNode(action, newNode, mOpenstreetmapUtil.getEntityInfo(newNode.getId()), "", false, new CallbackWithObject<Node>() {
@Override
public boolean processResult(Node result) {
if (result != null) {
OsmEditingPlugin plugin = OsmandPlugin.getPlugin(OsmEditingPlugin.class);
if (plugin != null && offlineEdit) {
List<OpenstreetmapPoint> points = plugin.getDBPOI().getOpenstreetmapPoints();
if (activity instanceof MapActivity && points.size() > 0) {
OsmPoint point = points.get(points.size() - 1);
activity.getContextMenu().showOrUpdate(new LatLon(point.getLatitude(), point.getLongitude()), plugin.getOsmEditsLayer(activity).getObjectName(point), point);
}
}
if (activity instanceof MapActivity) {
activity.getMapView().refreshMap(true);
}
} else {
// OsmEditingPlugin plugin = OsmandPlugin.getPlugin(OsmEditingPlugin.class);
// mOpenstreetmapUtil = plugin.getPoiModificationLocalUtil();
// Button saveButton = (Button) view.findViewById(R.id.saveButton);
// saveButton.setText(mOpenstreetmapUtil instanceof OpenstreetmapRemoteUtil
// ? R.string.shared_string_upload : R.string.shared_string_save);
}
return false;
}
}, activity, mOpenstreetmapUtil, null);
}
}
use of net.osmand.plus.osmedit.OsmPoint in project Osmand by osmandapp.
the class MenuController method getMenuController.
public static MenuController getMenuController(MapActivity mapActivity, LatLon latLon, PointDescription pointDescription, Object object, MenuType menuType) {
MenuController menuController = null;
if (object != null) {
if (object instanceof Amenity) {
menuController = new AmenityMenuController(mapActivity, pointDescription, (Amenity) object);
} else if (object instanceof FavouritePoint) {
menuController = new FavouritePointMenuController(mapActivity, pointDescription, (FavouritePoint) object);
} else if (object instanceof SearchHistoryHelper.HistoryEntry) {
menuController = new HistoryMenuController(mapActivity, pointDescription, (SearchHistoryHelper.HistoryEntry) object);
} else if (object instanceof TargetPoint) {
menuController = new TargetPointMenuController(mapActivity, pointDescription, (TargetPoint) object);
} else if (object instanceof Recording) {
menuController = new AudioVideoNoteMenuController(mapActivity, pointDescription, (Recording) object);
} else if (object instanceof OsmPoint) {
menuController = new EditPOIMenuController(mapActivity, pointDescription, (OsmPoint) object);
} else if (object instanceof WptPt) {
menuController = new WptPtMenuController(mapActivity, pointDescription, (WptPt) object);
} else if (object instanceof DownloadMapObject) {
menuController = new MapDataMenuController(mapActivity, pointDescription, (DownloadMapObject) object);
} else if (object instanceof OpenStreetNote) {
menuController = new OsmBugMenuController(mapActivity, pointDescription, (OpenStreetNote) object);
} else if (object instanceof GpxDisplayItem) {
menuController = new GpxItemMenuController(mapActivity, pointDescription, (GpxDisplayItem) object);
} else if (object instanceof MapMarker) {
menuController = new MapMarkerMenuController(mapActivity, pointDescription, (MapMarker) object);
} else if (object instanceof TransportStopRoute) {
menuController = new TransportRouteController(mapActivity, pointDescription, (TransportStopRoute) object);
} else if (object instanceof TransportStop) {
menuController = new TransportStopController(mapActivity, pointDescription, (TransportStop) object);
} else if (object instanceof AMapPoint) {
menuController = new AMapPointMenuController(mapActivity, pointDescription, (AMapPoint) object);
} else if (object instanceof LatLon) {
if (pointDescription.isParking()) {
menuController = new ParkingPositionMenuController(mapActivity, pointDescription);
} else if (pointDescription.isMyLocation()) {
menuController = new MyLocationMenuController(mapActivity, pointDescription);
}
} else if (object instanceof RouteDataObject) {
menuController = new ImpassibleRoadsMenuController(mapActivity, pointDescription, (RouteDataObject) object);
} else if (object instanceof RenderedObject) {
menuController = new RenderedObjectMenuController(mapActivity, pointDescription, (RenderedObject) object);
} else if (object instanceof MapillaryImage) {
menuController = new MapillaryMenuController(mapActivity, pointDescription, (MapillaryImage) object);
}
}
if (menuController == null) {
menuController = new PointDescriptionMenuController(mapActivity, pointDescription);
}
menuController.menuType = menuType;
menuController.setLatLon(latLon);
menuController.onCreated();
return menuController;
}
use of net.osmand.plus.osmedit.OsmPoint in project Osmand by osmandapp.
the class SendPoiDialogFragment method createDefaultChangeSet.
private String createDefaultChangeSet() {
Map<String, PoiType> allTranslatedSubTypes = getMyApplication().getPoiTypes().getAllTranslatedNames(true);
if (allTranslatedSubTypes == null) {
return "";
}
Map<String, Integer> addGroup = new HashMap<>();
Map<String, Integer> editGroup = new HashMap<>();
Map<String, Integer> deleteGroup = new HashMap<>();
Map<String, Integer> reopenGroup = new HashMap<>();
String comment = "";
for (OsmPoint p : poi) {
if (p.getGroup() == OsmPoint.Group.POI) {
OsmPoint.Action action = p.getAction();
String type = ((OpenstreetmapPoint) p).getEntity().getTag(EditPoiData.POI_TYPE_TAG);
if (type == null) {
continue;
}
PoiType localizedPoiType = allTranslatedSubTypes.get(type.toLowerCase().trim());
if (localizedPoiType != null) {
type = Algorithms.capitalizeFirstLetter(localizedPoiType.getKeyName().replace('_', ' '));
}
if (action == OsmPoint.Action.CREATE) {
if (!addGroup.containsKey(type)) {
addGroup.put(type, 1);
} else {
addGroup.put(type, addGroup.get(type) + 1);
}
} else if (action == OsmPoint.Action.MODIFY) {
if (!editGroup.containsKey(type)) {
editGroup.put(type, 1);
} else {
editGroup.put(type, editGroup.get(type) + 1);
}
} else if (action == OsmPoint.Action.DELETE) {
if (!deleteGroup.containsKey(type)) {
deleteGroup.put(type, 1);
} else {
deleteGroup.put(type, deleteGroup.get(type) + 1);
}
} else if (action == OsmPoint.Action.REOPEN) {
if (!reopenGroup.containsKey(type)) {
reopenGroup.put(type, 1);
} else {
reopenGroup.put(type, reopenGroup.get(type) + 1);
}
}
}
}
int modifiedItemsOutOfLimit = 0;
for (int i = 0; i < 4; i++) {
String action;
Map<String, Integer> group;
switch(i) {
case 0:
action = getString(R.string.default_changeset_add);
group = addGroup;
break;
case 1:
action = getString(R.string.default_changeset_edit);
group = editGroup;
break;
case 2:
action = getString(R.string.default_changeset_delete);
group = deleteGroup;
break;
case 3:
action = getString(R.string.default_changeset_reopen);
group = reopenGroup;
break;
default:
action = "";
group = new HashMap<>();
}
if (!group.isEmpty()) {
int pos = 0;
for (Map.Entry<String, Integer> entry : group.entrySet()) {
String type = entry.getKey();
int quantity = entry.getValue();
if (comment.length() > 200) {
modifiedItemsOutOfLimit += quantity;
} else {
if (pos == 0) {
comment = comment.concat(comment.length() == 0 ? "" : "; ").concat(action).concat(" ").concat(quantity == 1 ? "" : quantity + " ").concat(type);
} else {
comment = comment.concat(", ").concat(quantity == 1 ? "" : quantity + " ").concat(type);
}
}
pos++;
}
}
}
if (modifiedItemsOutOfLimit != 0) {
comment = comment.concat("; ").concat(modifiedItemsOutOfLimit + " ").concat(getString(R.string.items_modified)).concat(".");
} else if (!comment.equals("")) {
comment = comment.concat(".");
}
return comment;
}
use of net.osmand.plus.osmedit.OsmPoint in project Osmand by osmandapp.
the class SendPoiDialogFragment method onCreateDialog.
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
poi = (OsmPoint[]) getArguments().getSerializable(OPENSTREETMAP_POINT);
final PoiUploaderType poiUploaderType = PoiUploaderType.valueOf(getArguments().getString(POI_UPLOADER_TYPE, PoiUploaderType.SIMPLE.name()));
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
View view = getActivity().getLayoutInflater().inflate(R.layout.send_poi_dialog, null);
final SwitchCompat uploadAnonymously = (SwitchCompat) view.findViewById(R.id.upload_anonymously_switch);
final EditText messageEditText = (EditText) view.findViewById(R.id.message_field);
final EditText userNameEditText = (EditText) view.findViewById(R.id.user_name_field);
final EditText passwordEditText = (EditText) view.findViewById(R.id.password_field);
final View messageLabel = view.findViewById(R.id.message_label);
final View userNameLabel = view.findViewById(R.id.osm_user_name_label);
final View passwordLabel = view.findViewById(R.id.osm_user_password_label);
final CheckBox closeChangeSetCheckBox = (CheckBox) view.findViewById(R.id.close_change_set_checkbox);
final OsmandSettings settings = ((OsmandApplication) getActivity().getApplication()).getSettings();
userNameEditText.setText(settings.USER_NAME.get());
passwordEditText.setText(settings.USER_PASSWORD.get());
boolean hasPoiGroup = false;
assert poi != null;
for (OsmPoint p : poi) {
if (p.getGroup() == OsmPoint.Group.POI) {
hasPoiGroup = true;
break;
}
}
String defaultChangeSet = createDefaultChangeSet();
messageEditText.setText(defaultChangeSet);
final boolean hasPOI = hasPoiGroup;
messageLabel.setVisibility(hasPOI ? View.VISIBLE : View.GONE);
messageEditText.setVisibility(hasPOI ? View.VISIBLE : View.GONE);
closeChangeSetCheckBox.setVisibility(hasPOI ? View.VISIBLE : View.GONE);
closeChangeSetCheckBox.setChecked(hasPOI && !defaultChangeSet.equals(""));
view.findViewById(R.id.osm_note_header).setVisibility(hasPOI ? View.GONE : View.VISIBLE);
uploadAnonymously.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
userNameLabel.setVisibility(isChecked ? View.GONE : View.VISIBLE);
userNameEditText.setVisibility(isChecked ? View.GONE : View.VISIBLE);
passwordLabel.setVisibility(isChecked ? View.GONE : View.VISIBLE);
passwordEditText.setVisibility(isChecked ? View.GONE : View.VISIBLE);
}
});
final ProgressDialogPoiUploader progressDialogPoiUploader;
if (poiUploaderType == PoiUploaderType.SIMPLE && getActivity() instanceof MapActivity) {
progressDialogPoiUploader = new SendPoiDialogFragment.SimpleProgressDialogPoiUploader((MapActivity) getActivity());
} else {
progressDialogPoiUploader = (ProgressDialogPoiUploader) getParentFragment();
}
builder.setTitle(hasPOI ? R.string.upload_poi : R.string.upload_osm_note).setView(view).setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (progressDialogPoiUploader != null) {
settings.USER_NAME.set(userNameEditText.getText().toString());
settings.USER_PASSWORD.set(passwordEditText.getText().toString());
String comment = messageEditText.getText().toString();
if (comment.length() > 0) {
for (OsmPoint osmPoint : poi) {
if (osmPoint.getGroup() == OsmPoint.Group.POI) {
((OpenstreetmapPoint) osmPoint).setComment(comment);
break;
}
}
}
progressDialogPoiUploader.showProgressDialog(poi, closeChangeSetCheckBox.isChecked(), !hasPOI && uploadAnonymously.isChecked());
}
}
}).setNegativeButton(R.string.shared_string_cancel, null);
return builder.create();
}
Aggregations