Search in sources :

Example 1 with MAP_CONTEXT_MENU_CREATE_POI

use of net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_CONTEXT_MENU_CREATE_POI 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)

Aggregations

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 Iterator (java.util.Iterator)1 List (java.util.List)1 PlatformUtil (net.osmand.PlatformUtil)1 MAP_CONTEXT_MENU_CREATE_POI (net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_CONTEXT_MENU_CREATE_POI)1 MAP_CONTEXT_MENU_OPEN_OSM_NOTE (net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_CONTEXT_MENU_OPEN_OSM_NOTE)1