Search in sources :

Example 1 with OsmPoint

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);
    }
}
Also used : OsmPoint(net.osmand.plus.osmedit.OsmPoint) Node(net.osmand.osm.edit.Node) AbstractPoiType(net.osmand.osm.AbstractPoiType) PoiType(net.osmand.osm.PoiType) EditPoiDialogFragment(net.osmand.plus.osmedit.EditPoiDialogFragment) OsmEditingPlugin(net.osmand.plus.osmedit.OsmEditingPlugin) LatLon(net.osmand.data.LatLon) OpenstreetmapLocalUtil(net.osmand.plus.osmedit.OpenstreetmapLocalUtil) EditPoiData(net.osmand.plus.osmedit.EditPoiData) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) OpenstreetmapUtil(net.osmand.plus.osmedit.OpenstreetmapUtil) MapActivity(net.osmand.plus.activities.MapActivity)

Example 2 with OsmPoint

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;
}
Also used : TargetPointMenuController(net.osmand.plus.mapcontextmenu.controllers.TargetPointMenuController) WptPt(net.osmand.plus.GPXUtilities.WptPt) HistoryMenuController(net.osmand.plus.mapcontextmenu.controllers.HistoryMenuController) TransportStopController(net.osmand.plus.mapcontextmenu.controllers.TransportStopController) FavouritePoint(net.osmand.data.FavouritePoint) MapMarker(net.osmand.plus.MapMarkersHelper.MapMarker) MapillaryImage(net.osmand.plus.mapillary.MapillaryImage) ParkingPositionMenuController(net.osmand.plus.parkingpoint.ParkingPositionMenuController) GpxDisplayItem(net.osmand.plus.GpxSelectionHelper.GpxDisplayItem) GpxItemMenuController(net.osmand.plus.mapcontextmenu.controllers.GpxItemMenuController) MapDataMenuController(net.osmand.plus.mapcontextmenu.controllers.MapDataMenuController) TargetPoint(net.osmand.plus.TargetPointsHelper.TargetPoint) RenderedObjectMenuController(net.osmand.plus.mapcontextmenu.controllers.RenderedObjectMenuController) ImpassibleRoadsMenuController(net.osmand.plus.mapcontextmenu.controllers.ImpassibleRoadsMenuController) EditPOIMenuController(net.osmand.plus.osmedit.EditPOIMenuController) TransportStopRoute(net.osmand.plus.transport.TransportStopRoute) MapMarkerMenuController(net.osmand.plus.mapcontextmenu.controllers.MapMarkerMenuController) PointDescriptionMenuController(net.osmand.plus.mapcontextmenu.controllers.PointDescriptionMenuController) AMapPointMenuController(net.osmand.plus.mapcontextmenu.controllers.AMapPointMenuController) TransportStop(net.osmand.data.TransportStop) Amenity(net.osmand.data.Amenity) FavouritePointMenuController(net.osmand.plus.mapcontextmenu.controllers.FavouritePointMenuController) AudioVideoNoteMenuController(net.osmand.plus.audionotes.AudioVideoNoteMenuController) OsmBugMenuController(net.osmand.plus.osmedit.OsmBugMenuController) OsmPoint(net.osmand.plus.osmedit.OsmPoint) TransportRouteController(net.osmand.plus.mapcontextmenu.controllers.TransportRouteController) AMapPoint(net.osmand.aidl.maplayer.point.AMapPoint) AmenityMenuController(net.osmand.plus.mapcontextmenu.controllers.AmenityMenuController) DownloadMapObject(net.osmand.plus.views.DownloadedRegionsLayer.DownloadMapObject) MyLocationMenuController(net.osmand.plus.mapcontextmenu.controllers.MyLocationMenuController) RenderedObjectMenuController(net.osmand.plus.mapcontextmenu.controllers.RenderedObjectMenuController) PointDescriptionMenuController(net.osmand.plus.mapcontextmenu.controllers.PointDescriptionMenuController) MapMarkerMenuController(net.osmand.plus.mapcontextmenu.controllers.MapMarkerMenuController) AMapPointMenuController(net.osmand.plus.mapcontextmenu.controllers.AMapPointMenuController) OsmBugMenuController(net.osmand.plus.osmedit.OsmBugMenuController) WptPtMenuController(net.osmand.plus.mapcontextmenu.controllers.WptPtMenuController) MapillaryMenuController(net.osmand.plus.mapillary.MapillaryMenuController) GpxItemMenuController(net.osmand.plus.mapcontextmenu.controllers.GpxItemMenuController) HistoryMenuController(net.osmand.plus.mapcontextmenu.controllers.HistoryMenuController) ParkingPositionMenuController(net.osmand.plus.parkingpoint.ParkingPositionMenuController) MapDataMenuController(net.osmand.plus.mapcontextmenu.controllers.MapDataMenuController) TargetPointMenuController(net.osmand.plus.mapcontextmenu.controllers.TargetPointMenuController) AudioVideoNoteMenuController(net.osmand.plus.audionotes.AudioVideoNoteMenuController) AmenityMenuController(net.osmand.plus.mapcontextmenu.controllers.AmenityMenuController) ImpassibleRoadsMenuController(net.osmand.plus.mapcontextmenu.controllers.ImpassibleRoadsMenuController) EditPOIMenuController(net.osmand.plus.osmedit.EditPOIMenuController) FavouritePointMenuController(net.osmand.plus.mapcontextmenu.controllers.FavouritePointMenuController) MyLocationMenuController(net.osmand.plus.mapcontextmenu.controllers.MyLocationMenuController) LatLon(net.osmand.data.LatLon) RenderedObject(net.osmand.NativeLibrary.RenderedObject) OpenStreetNote(net.osmand.plus.osmedit.OsmBugsLayer.OpenStreetNote) RouteDataObject(net.osmand.binary.RouteDataObject) Recording(net.osmand.plus.audionotes.AudioVideoNotesPlugin.Recording) WptPtMenuController(net.osmand.plus.mapcontextmenu.controllers.WptPtMenuController) MapillaryMenuController(net.osmand.plus.mapillary.MapillaryMenuController)

Example 3 with OsmPoint

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;
}
Also used : OsmPoint(net.osmand.plus.osmedit.OsmPoint) HashMap(java.util.HashMap) PoiType(net.osmand.osm.PoiType) HashMap(java.util.HashMap) Map(java.util.Map) OpenstreetmapPoint(net.osmand.plus.osmedit.OpenstreetmapPoint) OsmPoint(net.osmand.plus.osmedit.OsmPoint)

Example 4 with OsmPoint

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();
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) EditText(android.widget.EditText) OsmPoint(net.osmand.plus.osmedit.OsmPoint) OsmandApplication(net.osmand.plus.OsmandApplication) DialogInterface(android.content.DialogInterface) View(android.view.View) OsmandSettings(net.osmand.plus.OsmandSettings) OpenstreetmapPoint(net.osmand.plus.osmedit.OpenstreetmapPoint) CheckBox(android.widget.CheckBox) CompoundButton(android.widget.CompoundButton) SwitchCompat(android.support.v7.widget.SwitchCompat) MapActivity(net.osmand.plus.activities.MapActivity) NonNull(android.support.annotation.NonNull)

Aggregations

OsmPoint (net.osmand.plus.osmedit.OsmPoint)4 HashMap (java.util.HashMap)2 Map (java.util.Map)2 LatLon (net.osmand.data.LatLon)2 PoiType (net.osmand.osm.PoiType)2 MapActivity (net.osmand.plus.activities.MapActivity)2 DialogInterface (android.content.DialogInterface)1 NonNull (android.support.annotation.NonNull)1 AlertDialog (android.support.v7.app.AlertDialog)1 SwitchCompat (android.support.v7.widget.SwitchCompat)1 View (android.view.View)1 CheckBox (android.widget.CheckBox)1 CompoundButton (android.widget.CompoundButton)1 EditText (android.widget.EditText)1 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 RenderedObject (net.osmand.NativeLibrary.RenderedObject)1 AMapPoint (net.osmand.aidl.maplayer.point.AMapPoint)1 RouteDataObject (net.osmand.binary.RouteDataObject)1