Search in sources :

Example 1 with EditPoiDialogFragment

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());
    }
}
Also used : OsmPoint(net.osmand.plus.plugins.osmedit.data.OsmPoint) SendGpxBottomSheetFragment(net.osmand.plus.plugins.osmedit.dialogs.SendGpxBottomSheetFragment) NonNull(androidx.annotation.NonNull) R(net.osmand.plus.R) AddOSMBugAction(net.osmand.plus.plugins.osmedit.quickactions.AddOSMBugAction) INVALID_ID(net.osmand.plus.ContextMenuItem.INVALID_ID) OsmBugsDbHelper(net.osmand.plus.plugins.osmedit.helpers.OsmBugsDbHelper) Drawable(android.graphics.drawable.Drawable) ContextMenuAdapter.makeDeleteAction(net.osmand.plus.ContextMenuAdapter.makeDeleteAction) Fragment(androidx.fragment.app.Fragment) View(android.view.View) Amenity(net.osmand.data.Amenity) LoginBottomSheetFragment(net.osmand.plus.measurementtool.LoginBottomSheetFragment) DashFragmentData(net.osmand.plus.dashboard.tools.DashFragmentData) OsmBugsRemoteUtil(net.osmand.plus.plugins.osmedit.helpers.OsmBugsRemoteUtil) OsmandApplication(net.osmand.plus.OsmandApplication) OsmandPlugin(net.osmand.plus.plugins.OsmandPlugin) StringRes(androidx.annotation.StringRes) List(java.util.List) Nullable(androidx.annotation.Nullable) DashboardType(net.osmand.plus.dashboard.DashboardOnMap.DashboardType) ContextMenuAdapter(net.osmand.plus.ContextMenuAdapter) OsmBugsLocalUtil(net.osmand.plus.plugins.osmedit.helpers.OsmBugsLocalUtil) MAP_CONTEXT_MENU_CREATE_POI(net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_CONTEXT_MENU_CREATE_POI) TabActivity(net.osmand.plus.activities.TabActivity) Typeface(android.graphics.Typeface) Context(android.content.Context) OSM_NOTES(net.osmand.aidlapi.OsmAndCustomizationConstants.OSM_NOTES) MapObject(net.osmand.data.MapObject) GpxInfo(net.osmand.plus.myplaces.ui.AvailableGPXFragment.GpxInfo) MAP_CONTEXT_MENU_OPEN_OSM_NOTE(net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_CONTEXT_MENU_OPEN_OSM_NOTE) PLUGIN_OSMAND_EDITING(net.osmand.aidlapi.OsmAndCustomizationConstants.PLUGIN_OSMAND_EDITING) OsmandMapTileView(net.osmand.plus.views.OsmandMapTileView) CommonPreference(net.osmand.plus.settings.backend.preferences.CommonPreference) AddPOIAction(net.osmand.plus.plugins.osmedit.quickactions.AddPOIAction) Intent(android.content.Intent) OsmandPreference(net.osmand.plus.settings.backend.preferences.OsmandPreference) FragmentActivity(androidx.fragment.app.FragmentActivity) ArrayList(java.util.ArrayList) RenderingRuleProperty(net.osmand.render.RenderingRuleProperty) PoiType(net.osmand.osm.PoiType) OsmEditsFragment(net.osmand.plus.plugins.osmedit.fragments.OsmEditsFragment) OpenstreetmapLocalUtil(net.osmand.plus.plugins.osmedit.helpers.OpenstreetmapLocalUtil) SettingsScreenType(net.osmand.plus.settings.fragments.BaseSettingsFragment.SettingsScreenType) OSM_EDITS(net.osmand.aidlapi.OsmAndCustomizationConstants.OSM_EDITS) AvailableGPXFragment(net.osmand.plus.myplaces.ui.AvailableGPXFragment) DashOsmEditsFragment(net.osmand.plus.plugins.osmedit.fragments.DashOsmEditsFragment) PlatformUtil(net.osmand.PlatformUtil) Algorithms(net.osmand.util.Algorithms) AndroidUtils(net.osmand.plus.utils.AndroidUtils) Entity(net.osmand.osm.edit.Entity) Iterator(java.util.Iterator) ItemBuilder(net.osmand.plus.ContextMenuItem.ItemBuilder) SpannableString(android.text.SpannableString) EditPoiDialogFragment(net.osmand.plus.plugins.osmedit.dialogs.EditPoiDialogFragment) StyleSpan(android.text.style.StyleSpan) TextUtils(android.text.TextUtils) POI_TYPE_TAG(net.osmand.osm.edit.Entity.POI_TYPE_TAG) TransportStop(net.osmand.data.TransportStop) ArrayAdapter(android.widget.ArrayAdapter) OpenstreetmapsDbHelper(net.osmand.plus.plugins.osmedit.helpers.OpenstreetmapsDbHelper) OsmNotesPoint(net.osmand.plus.plugins.osmedit.data.OsmNotesPoint) ShowHideOSMBugAction(net.osmand.plus.plugins.osmedit.quickactions.ShowHideOSMBugAction) Action(net.osmand.plus.plugins.osmedit.data.OsmPoint.Action) OPEN_STREET_MAP(net.osmand.aidlapi.OsmAndCustomizationConstants.OPEN_STREET_MAP) ContextMenuItem(net.osmand.plus.ContextMenuItem) FavoritesActivity(net.osmand.plus.myplaces.ui.FavoritesActivity) OpenstreetmapPoint(net.osmand.plus.plugins.osmedit.data.OpenstreetmapPoint) ConfigureMapMenu(net.osmand.plus.dialogs.ConfigureMapMenu) Log(org.apache.commons.logging.Log) OpenstreetmapRemoteUtil(net.osmand.plus.plugins.osmedit.helpers.OpenstreetmapRemoteUtil) QuickActionType(net.osmand.plus.quickaction.QuickActionType) MapActivity(net.osmand.plus.activities.MapActivity) Entity(net.osmand.osm.edit.Entity) Amenity(net.osmand.data.Amenity) ContextMenuItem(net.osmand.plus.ContextMenuItem) OsmNotesPoint(net.osmand.plus.plugins.osmedit.data.OsmNotesPoint) PoiType(net.osmand.osm.PoiType) EditPoiDialogFragment(net.osmand.plus.plugins.osmedit.dialogs.EditPoiDialogFragment) ContextMenuAdapter(net.osmand.plus.ContextMenuAdapter) OpenstreetmapPoint(net.osmand.plus.plugins.osmedit.data.OpenstreetmapPoint) ItemBuilder(net.osmand.plus.ContextMenuItem.ItemBuilder) TransportStop(net.osmand.data.TransportStop) MapObject(net.osmand.data.MapObject) ItemBuilder(net.osmand.plus.ContextMenuItem.ItemBuilder)

Example 2 with EditPoiDialogFragment

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);
    }
}
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)

Aggregations

PoiType (net.osmand.osm.PoiType)2 Entity (net.osmand.osm.edit.Entity)2 OsmandApplication (net.osmand.plus.OsmandApplication)2 Context (android.content.Context)1 Intent (android.content.Intent)1 Typeface (android.graphics.Typeface)1 Drawable (android.graphics.drawable.Drawable)1 SpannableString (android.text.SpannableString)1 TextUtils (android.text.TextUtils)1 StyleSpan (android.text.style.StyleSpan)1 View (android.view.View)1 ArrayAdapter (android.widget.ArrayAdapter)1 NonNull (androidx.annotation.NonNull)1 Nullable (androidx.annotation.Nullable)1 StringRes (androidx.annotation.StringRes)1 Fragment (androidx.fragment.app.Fragment)1 FragmentActivity (androidx.fragment.app.FragmentActivity)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1