Search in sources :

Example 16 with OsmEditingPlugin

use of net.osmand.plus.plugins.osmedit.OsmEditingPlugin in project Osmand by osmandapp.

the class AvailableGPXFragment method openPopUpMenu.

private void openPopUpMenu(View v, final GpxInfo gpxInfo) {
    UiUtilities iconsCache = app.getUIUtilities();
    final List<PopUpMenuItem> items = new ArrayList<>();
    items.add(new PopUpMenuItem.Builder(app).setTitleId(R.string.shared_string_show_on_map).setIcon(iconsCache.getThemedIcon(R.drawable.ic_show_on_map)).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            showGpxOnMap(gpxInfo);
        }
    }).create());
    GPXTrackAnalysis analysis;
    if ((analysis = getGpxTrackAnalysis(gpxInfo, app, null)) != null) {
        if (analysis.totalDistance != 0 && !gpxInfo.currentlyRecordingTrack) {
            items.add(new PopUpMenuItem.Builder(app).setTitleId(R.string.analyze_on_map).setIcon(iconsCache.getThemedIcon(R.drawable.ic_action_info_dark)).setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    new OpenGpxDetailsTask(gpxInfo).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
                }
            }).create());
        }
    }
    items.add(new PopUpMenuItem.Builder(app).setTitleId(R.string.shared_string_move).setIcon(iconsCache.getThemedIcon(R.drawable.ic_action_folder_stroke)).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            moveGpx(gpxInfo);
        }
    }).create());
    items.add(new PopUpMenuItem.Builder(app).setTitleId(R.string.shared_string_rename).setIcon(iconsCache.getThemedIcon(R.drawable.ic_action_edit_dark)).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            FragmentActivity activity = getActivity();
            if (activity != null) {
                FileUtils.renameFile(activity, gpxInfo.file, AvailableGPXFragment.this, false);
            }
        }
    }).create());
    Drawable shareIcon = iconsCache.getThemedIcon((R.drawable.ic_action_gshare_dark));
    items.add(new PopUpMenuItem.Builder(app).setTitleId(R.string.shared_string_share).setIcon(AndroidUtils.getDrawableForDirection(app, shareIcon)).setOnClickListener(v1 -> {
        Activity activity = getActivity();
        if (activity != null) {
            Uri fileUri = AndroidUtils.getUriForFile(activity, gpxInfo.file);
            Intent sendIntent = new Intent(Intent.ACTION_SEND).putExtra(Intent.EXTRA_STREAM, fileUri).setType("text/plain").addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
            AndroidUtils.startActivityIfSafe(activity, sendIntent);
        }
    }).create());
    final OsmEditingPlugin osmEditingPlugin = OsmandPlugin.getActivePlugin(OsmEditingPlugin.class);
    if (osmEditingPlugin != null) {
        items.add(new PopUpMenuItem.Builder(app).setTitleId(R.string.shared_string_export).setIcon(iconsCache.getThemedIcon(R.drawable.ic_action_export)).setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                osmEditingPlugin.sendGPXFiles(getActivity(), AvailableGPXFragment.this, gpxInfo);
            }
        }).create());
    }
    items.add(new PopUpMenuItem.Builder(app).setTitleId(R.string.shared_string_delete).setIcon(iconsCache.getThemedIcon(R.drawable.ic_action_delete_dark)).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
            builder.setMessage(R.string.recording_delete_confirm);
            builder.setPositiveButton(R.string.shared_string_yes, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    operationTask = new DeleteGpxTask();
                    operationTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, gpxInfo);
                }
            });
            builder.setNegativeButton(R.string.shared_string_cancel, null);
            builder.show();
        }
    }).create());
    new PopUpMenuHelper.Builder(v, items, nightMode).show();
}
Also used : AlertDialog(androidx.appcompat.app.AlertDialog) DialogInterface(android.content.DialogInterface) ArrayList(java.util.ArrayList) GPXTrackAnalysis(net.osmand.GPXUtilities.GPXTrackAnalysis) Drawable(android.graphics.drawable.Drawable) MapActivity(net.osmand.plus.activities.MapActivity) FragmentActivity(androidx.fragment.app.FragmentActivity) Activity(android.app.Activity) Intent(android.content.Intent) PopUpMenuItem(net.osmand.plus.widgets.popup.PopUpMenuItem) ImageView(android.widget.ImageView) SearchView(androidx.appcompat.widget.SearchView) View(android.view.View) TextView(android.widget.TextView) AbsListView(android.widget.AbsListView) ExpandableListView(android.widget.ExpandableListView) Uri(android.net.Uri) OsmEditingPlugin(net.osmand.plus.plugins.osmedit.OsmEditingPlugin) UiUtilities(net.osmand.plus.utils.UiUtilities) FragmentActivity(androidx.fragment.app.FragmentActivity) PopUpMenuHelper(net.osmand.plus.widgets.popup.PopUpMenuHelper)

Example 17 with OsmEditingPlugin

use of net.osmand.plus.plugins.osmedit.OsmEditingPlugin 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);
    }
}
Also used : Entity(net.osmand.osm.edit.Entity) QuickAction(net.osmand.plus.quickaction.QuickAction) Action(net.osmand.plus.plugins.osmedit.data.OsmPoint.Action) OsmPoint(net.osmand.plus.plugins.osmedit.data.OsmPoint) OsmandApplication(net.osmand.plus.OsmandApplication) Node(net.osmand.osm.edit.Node) AbstractPoiType(net.osmand.osm.AbstractPoiType) PoiType(net.osmand.osm.PoiType) EditPoiDialogFragment(net.osmand.plus.plugins.osmedit.dialogs.EditPoiDialogFragment) OsmandSettings(net.osmand.plus.settings.backend.OsmandSettings) OsmEditingPlugin(net.osmand.plus.plugins.osmedit.OsmEditingPlugin) LatLon(net.osmand.data.LatLon) OpenstreetmapLocalUtil(net.osmand.plus.plugins.osmedit.helpers.OpenstreetmapLocalUtil) OpenstreetmapPoint(net.osmand.plus.plugins.osmedit.data.OpenstreetmapPoint) PoiCategory(net.osmand.osm.PoiCategory) EditPoiData(net.osmand.plus.plugins.osmedit.data.EditPoiData) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) OpenstreetmapUtil(net.osmand.plus.plugins.osmedit.helpers.OpenstreetmapUtil)

Example 18 with OsmEditingPlugin

use of net.osmand.plus.plugins.osmedit.OsmEditingPlugin in project Osmand by osmandapp.

the class EditPoiDialogFragment method onAttach.

@Override
public void onAttach(@NonNull Context activity) {
    super.onAttach(activity);
    OsmEditingPlugin plugin = OsmandPlugin.getPlugin(OsmEditingPlugin.class);
    if (plugin.OFFLINE_EDITION.get() || !getSettings().isInternetConnectionAvailable(true)) {
        mOpenstreetmapUtil = plugin.getPoiModificationLocalUtil();
    } else {
        mOpenstreetmapUtil = plugin.getPoiModificationRemoteUtil();
    }
    Entity entity = (Entity) getArguments().getSerializable(KEY_AMENITY_ENTITY);
    editPoiData = new EditPoiData(entity, getMyApplication());
}
Also used : Entity(net.osmand.osm.edit.Entity) EditPoiData(net.osmand.plus.plugins.osmedit.data.EditPoiData) OsmEditingPlugin(net.osmand.plus.plugins.osmedit.OsmEditingPlugin)

Example 19 with OsmEditingPlugin

use of net.osmand.plus.plugins.osmedit.OsmEditingPlugin in project Osmand by osmandapp.

the class EditPoiDialogFragment method save.

public void save() {
    Entity original = editPoiData.getEntity();
    final boolean offlineEdit = mOpenstreetmapUtil instanceof OpenstreetmapLocalUtil;
    Entity entity;
    if (original instanceof Node) {
        entity = new Node(original.getLatitude(), original.getLongitude(), original.getId());
    } else if (original instanceof Way) {
        entity = new Way(original.getId(), ((Way) original).getNodeIds(), original.getLatitude(), original.getLongitude());
    } else {
        return;
    }
    Action action = entity.getId() < 0 ? Action.CREATE : Action.MODIFY;
    for (Map.Entry<String, String> tag : editPoiData.getTagValues().entrySet()) {
        if (!Algorithms.isEmpty(tag.getKey()) && !Algorithms.isEmpty(tag.getValue()) && !tag.getKey().equals(POI_TYPE_TAG)) {
            entity.putTagNoLC(tag.getKey(), tag.getValue());
        }
    }
    String poiTypeTag = editPoiData.getTagValues().get(POI_TYPE_TAG);
    String comment = "";
    if (poiTypeTag != null) {
        final PoiType poiType = editPoiData.getAllTranslatedSubTypes().get(poiTypeTag.trim().toLowerCase());
        if (poiType != null) {
            entity.putTagNoLC(poiType.getEditOsmTag(), poiType.getEditOsmValue());
            entity.removeTag(Entity.REMOVE_TAG_PREFIX + poiType.getEditOsmTag());
            if (poiType.getOsmTag2() != null) {
                entity.putTagNoLC(poiType.getOsmTag2(), poiType.getOsmValue2());
                entity.removeTag(Entity.REMOVE_TAG_PREFIX + poiType.getOsmTag2());
            }
            if (poiType.getEditOsmTag2() != null) {
                entity.putTagNoLC(poiType.getEditOsmTag2(), poiType.getEditOsmValue2());
                entity.removeTag(Entity.REMOVE_TAG_PREFIX + poiType.getEditOsmTag2());
            }
        } else if (!Algorithms.isEmpty(poiTypeTag)) {
            PoiCategory category = editPoiData.getPoiCategory();
            if (category != null) {
                entity.putTagNoLC(category.getDefaultTag(), poiTypeTag);
            }
        }
        if (offlineEdit && !Algorithms.isEmpty(poiTypeTag)) {
            entity.putTagNoLC(POI_TYPE_TAG, poiTypeTag);
        }
        String actionString = action == Action.CREATE ? getString(R.string.default_changeset_add) : getString(R.string.default_changeset_edit);
        comment = actionString + " " + poiTypeTag;
    }
    commitEntity(action, entity, mOpenstreetmapUtil.getEntityInfo(entity.getId()), comment, false, result -> {
        OsmEditingPlugin plugin = OsmandPlugin.getPlugin(OsmEditingPlugin.class);
        if (result != null) {
            if (offlineEdit) {
                List<OpenstreetmapPoint> points = plugin.getDBPOI().getOpenstreetmapPoints();
                if (getActivity() instanceof MapActivity && points.size() > 0) {
                    OsmPoint point = points.get(points.size() - 1);
                    MapActivity mapActivity = (MapActivity) getActivity();
                    mapActivity.getContextMenu().showOrUpdate(new LatLon(point.getLatitude(), point.getLongitude()), plugin.getOsmEditsLayer(mapActivity).getObjectName(point), point);
                    mapActivity.getMapLayers().getContextMenuLayer().updateContextMenu();
                }
            }
            if (getActivity() instanceof MapActivity) {
                ((MapActivity) getActivity()).getMapView().refreshMap(true);
            }
            dismissAllowingStateLoss();
        } else {
            mOpenstreetmapUtil = plugin.getPoiModificationLocalUtil();
            Button saveButton = view.findViewById(R.id.saveButton);
            saveButton.setText(mOpenstreetmapUtil instanceof OpenstreetmapRemoteUtil ? R.string.shared_string_upload : R.string.shared_string_save);
        }
        return false;
    }, getActivity(), mOpenstreetmapUtil, action == Action.MODIFY ? editPoiData.getChangedTags() : null);
}
Also used : Entity(net.osmand.osm.edit.Entity) Action(net.osmand.plus.plugins.osmedit.data.OsmPoint.Action) OsmPoint(net.osmand.plus.plugins.osmedit.data.OsmPoint) Node(net.osmand.osm.edit.Node) PoiType(net.osmand.osm.PoiType) Way(net.osmand.osm.edit.Way) OsmEditingPlugin(net.osmand.plus.plugins.osmedit.OsmEditingPlugin) OpenstreetmapLocalUtil(net.osmand.plus.plugins.osmedit.helpers.OpenstreetmapLocalUtil) LatLon(net.osmand.data.LatLon) OpenstreetmapPoint(net.osmand.plus.plugins.osmedit.data.OpenstreetmapPoint) OpenstreetmapRemoteUtil(net.osmand.plus.plugins.osmedit.helpers.OpenstreetmapRemoteUtil) ImageButton(android.widget.ImageButton) Button(android.widget.Button) AppCompatImageButton(androidx.appcompat.widget.AppCompatImageButton) PoiCategory(net.osmand.osm.PoiCategory) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) MapActivity(net.osmand.plus.activities.MapActivity)

Example 20 with OsmEditingPlugin

use of net.osmand.plus.plugins.osmedit.OsmEditingPlugin in project Osmand by osmandapp.

the class EditPoiDialogFragment method showEditInstance.

public static void showEditInstance(final MapObject mapObject, final AppCompatActivity activity) {
    final OsmEditingPlugin plugin = OsmandPlugin.getPlugin(OsmEditingPlugin.class);
    if (plugin == null) {
        return;
    }
    final OsmandApplication app = ((OsmandApplication) activity.getApplication());
    final OpenstreetmapUtil openstreetmapUtilToLoad = app.getSettings().isInternetConnectionAvailable(true) ? plugin.getPoiModificationRemoteUtil() : plugin.getPoiModificationLocalUtil();
    new AsyncTask<Void, Void, Entity>() {

        @Override
        protected Entity doInBackground(Void... params) {
            return openstreetmapUtilToLoad.loadEntity(mapObject);
        }

        @Override
        protected void onPostExecute(Entity entity) {
            if (entity != null) {
                Entity existingOsmEditEntity = getExistingOsmEditEntity(plugin, entity.getId());
                Entity entityToEdit = existingOsmEditEntity != null ? existingOsmEditEntity : entity;
                EditPoiDialogFragment fragment = EditPoiDialogFragment.createInstance(entityToEdit, false);
                fragment.show(activity.getSupportFragmentManager(), TAG);
            } else {
                Toast.makeText(activity, activity.getString(R.string.poi_cannot_be_found), Toast.LENGTH_LONG).show();
            }
        }

        @Nullable
        private Entity getExistingOsmEditEntity(@NonNull OsmEditingPlugin osmEditingPlugin, long entityId) {
            List<OpenstreetmapPoint> osmEdits = osmEditingPlugin.getDBPOI().getOpenstreetmapPoints();
            for (OpenstreetmapPoint osmEdit : osmEdits) {
                if (osmEdit.getId() == entityId && osmEdit.getAction() == Action.MODIFY) {
                    return osmEdit.getEntity();
                }
            }
            return null;
        }
    }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
Also used : Entity(net.osmand.osm.edit.Entity) OpenstreetmapPoint(net.osmand.plus.plugins.osmedit.data.OpenstreetmapPoint) OsmandApplication(net.osmand.plus.OsmandApplication) List(java.util.List) Nullable(androidx.annotation.Nullable) OsmEditingPlugin(net.osmand.plus.plugins.osmedit.OsmEditingPlugin) OpenstreetmapUtil(net.osmand.plus.plugins.osmedit.helpers.OpenstreetmapUtil)

Aggregations

OsmEditingPlugin (net.osmand.plus.plugins.osmedit.OsmEditingPlugin)20 OpenstreetmapPoint (net.osmand.plus.plugins.osmedit.data.OpenstreetmapPoint)5 Entity (net.osmand.osm.edit.Entity)4 OsmandApplication (net.osmand.plus.OsmandApplication)4 MapActivity (net.osmand.plus.activities.MapActivity)4 AlertDialog (androidx.appcompat.app.AlertDialog)3 LinkedHashMap (java.util.LinkedHashMap)3 Map (java.util.Map)3 OsmPoint (net.osmand.plus.plugins.osmedit.data.OsmPoint)3 DialogInterface (android.content.DialogInterface)2 FragmentActivity (androidx.fragment.app.FragmentActivity)2 File (java.io.File)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 LatLon (net.osmand.data.LatLon)2 PoiCategory (net.osmand.osm.PoiCategory)2 PoiType (net.osmand.osm.PoiType)2 Node (net.osmand.osm.edit.Node)2 ProgressDialogFragment (net.osmand.plus.dialogs.ProgressDialogFragment)2 UploadOpenstreetmapPointAsyncTask (net.osmand.plus.plugins.osmedit.asynctasks.UploadOpenstreetmapPointAsyncTask)2