Search in sources :

Example 21 with MapMarker

use of net.osmand.plus.mapmarkers.MapMarker in project Osmand by osmandapp.

the class MapActivityActions method addActionsToAdapter.

public void addActionsToAdapter(final double latitude, final double longitude, final ContextMenuAdapter adapter, Object selectedObj, boolean configureMenu) {
    ItemBuilder itemBuilder = new ItemBuilder();
    adapter.addItem(itemBuilder.setTitleId(selectedObj instanceof FavouritePoint ? R.string.favourites_context_menu_edit : R.string.shared_string_add, mapActivity).setId(MAP_CONTEXT_MENU_ADD_ID).setIcon(selectedObj instanceof FavouritePoint ? R.drawable.ic_action_edit_dark : R.drawable.ic_action_favorite_stroke).setOrder(10).createItem());
    adapter.addItem(itemBuilder.setTitleId(selectedObj instanceof MapMarker ? R.string.shared_string_edit : R.string.shared_string_marker, mapActivity).setId(MAP_CONTEXT_MENU_MARKER_ID).setOrder(20).setIcon(selectedObj instanceof MapMarker ? R.drawable.ic_action_edit_dark : R.drawable.ic_action_flag_stroke).createItem());
    adapter.addItem(itemBuilder.setTitleId(R.string.shared_string_share, mapActivity).setId(MAP_CONTEXT_MENU_SHARE_ID).setOrder(30).setIcon(R.drawable.ic_action_gshare_dark).createItem());
    adapter.addItem(itemBuilder.setTitleId(R.string.shared_string_actions, mapActivity).setId(MAP_CONTEXT_MENU_MORE_ID).setIcon(R.drawable.ic_actions_menu).setOrder(40).createItem());
    adapter.addItem(itemBuilder.setTitleId(R.string.context_menu_item_directions_from, mapActivity).setId(MAP_CONTEXT_MENU_DIRECTIONS_FROM_ID).setIcon(R.drawable.ic_action_route_direction_from_here).setOrder(DIRECTIONS_FROM_ITEM_ORDER).createItem());
    adapter.addItem(itemBuilder.setTitleId(R.string.context_menu_item_search, mapActivity).setId(MAP_CONTEXT_MENU_SEARCH_NEARBY).setIcon(R.drawable.ic_action_search_dark).setOrder(SEARCH_NEAR_ITEM_ORDER).createItem());
    OsmandPlugin.registerMapContextMenu(mapActivity, latitude, longitude, adapter, selectedObj, configureMenu);
    ItemClickListener listener = new ItemClickListener() {

        @Override
        public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int resId, int pos, boolean isChecked, int[] viewCoordinates) {
            if (resId == R.string.context_menu_item_add_waypoint) {
                mapActivity.getContextMenu().addWptPt();
            } else if (resId == R.string.context_menu_item_edit_waypoint) {
                mapActivity.getContextMenu().editWptPt();
            }
            return true;
        }
    };
    ContextMenuItem editGpxItem = new ItemBuilder().setTitleId(R.string.context_menu_item_edit_waypoint, mapActivity).setId(MAP_CONTEXT_MENU_ADD_GPX_WAYPOINT).setIcon(R.drawable.ic_action_edit_dark).setOrder(EDIT_GPX_WAYPOINT_ITEM_ORDER).setListener(listener).createItem();
    ContextMenuItem addGpxItem = new ItemBuilder().setTitleId(R.string.context_menu_item_add_waypoint, mapActivity).setId(MAP_CONTEXT_MENU_ADD_GPX_WAYPOINT).setIcon(R.drawable.ic_action_gnew_label_dark).setOrder(ADD_GPX_WAYPOINT_ITEM_ORDER).setListener(listener).createItem();
    if (configureMenu) {
        adapter.addItem(addGpxItem);
    } else if (selectedObj instanceof WptPt && app.getSelectedGpxHelper().getSelectedGPXFile((WptPt) selectedObj) != null) {
        adapter.addItem(editGpxItem);
    } else if (!app.getSelectedGpxHelper().getSelectedGPXFiles().isEmpty() || (OsmandPlugin.isActive(OsmandMonitoringPlugin.class))) {
        adapter.addItem(addGpxItem);
    }
    adapter.addItem(itemBuilder.setTitleId(R.string.plan_route, mapActivity).setId(MAP_CONTEXT_MENU_MEASURE_DISTANCE).setIcon(R.drawable.ic_action_ruler).setOrder(MEASURE_DISTANCE_ITEM_ORDER).createItem());
    adapter.addItem(itemBuilder.setTitleId(R.string.avoid_road, mapActivity).setId(MAP_CONTEXT_MENU_AVOID_ROAD).setIcon(R.drawable.ic_action_alert).setOrder(AVOID_ROAD_ITEM_ORDER).createItem());
}
Also used : WptPt(net.osmand.GPXUtilities.WptPt) ItemBuilder(net.osmand.plus.ContextMenuItem.ItemBuilder) ItemClickListener(net.osmand.plus.ContextMenuAdapter.ItemClickListener) ContextMenuItemClickListener(net.osmand.plus.mapcontextmenu.AdditionalActionsBottomSheetDialogFragment.ContextMenuItemClickListener) FavouritePoint(net.osmand.data.FavouritePoint) MapMarker(net.osmand.plus.mapmarkers.MapMarker) ContextMenuItem(net.osmand.plus.ContextMenuItem) ArrayAdapter(android.widget.ArrayAdapter)

Example 22 with MapMarker

use of net.osmand.plus.mapmarkers.MapMarker in project Osmand by osmandapp.

the class MapMarkerEditorFragment method delete.

private void delete() {
    Context context = getContext();
    if (editor != null && context != null) {
        MapMarker marker = editor.getMarker();
        new AlertDialog.Builder(context).setMessage(getString(R.string.markers_remove_dialog_msg, marker.getName(context))).setNegativeButton(R.string.shared_string_no, null).setPositiveButton(R.string.shared_string_yes, (dialog, which) -> {
            OsmandApplication app = getMyApplication();
            if (app != null) {
                app.getMapMarkersHelper().removeMarker(marker);
            }
            dismiss(true);
        }).create().show();
    }
}
Also used : Context(android.content.Context) AlertDialog(android.app.AlertDialog) MapMarker(net.osmand.plus.mapmarkers.MapMarker) OsmandApplication(net.osmand.plus.OsmandApplication)

Example 23 with MapMarker

use of net.osmand.plus.mapmarkers.MapMarker in project Osmand by osmandapp.

the class MapMarkersCard method updateContent.

@SuppressLint("DefaultLocale")
@Override
protected void updateContent() {
    LinearLayout root = (LinearLayout) view.findViewById(R.id.items);
    root.removeAllViews();
    int minCardHeight = getDimen(R.dimen.route_info_card_item_height);
    int listTextPadding = getDimen(R.dimen.route_info_list_text_padding);
    List<MapMarker> markers = getMarkers();
    int i = 0;
    boolean showLimitExceeds = markers.size() > 4;
    int mainFontColor = getMainFontColor();
    int descriptionColor = getSecondaryColor();
    int activeColor = getActiveColor();
    ContextThemeWrapper ctx = new ContextThemeWrapper(mapActivity, !nightMode ? R.style.OsmandLightTheme : R.style.OsmandDarkTheme);
    LayoutInflater inflater = LayoutInflater.from(ctx);
    for (final MapMarker marker : markers) {
        if (showLimitExceeds && i >= 3 && showLimited) {
            break;
        }
        View v = inflater.inflate(R.layout.map_marker_item, root, false);
        MapMarkerDialogHelper.updateMapMarkerInfo(ctx, v, loc, heading, useCenter, nightMode, screenOrientation, marker);
        final View remove = v.findViewById(R.id.info_close);
        remove.setVisibility(View.GONE);
        ((TextView) v.findViewById(R.id.waypoint_dist)).setTextColor(activeColor);
        ((TextView) v.findViewById(R.id.waypoint_text)).setTextColor(mainFontColor);
        ((TextView) v.findViewById(R.id.date_group_text)).setTextColor(descriptionColor);
        ImageView arrow = (ImageView) v.findViewById(R.id.direction);
        Drawable arrowIcon = arrow.getDrawable();
        if (arrowIcon instanceof DirectionDrawable) {
            ((DirectionDrawable) arrowIcon).setImage(R.drawable.ic_direction_arrow, ColorUtilities.getActiveColorId(nightMode));
        }
        v.setBackgroundResource(AndroidUtils.resolveAttribute(ctx, android.R.attr.selectableItemBackground));
        v.setMinimumHeight(minCardHeight);
        v.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                LatLon point = new LatLon(marker.getLatitude(), marker.getLongitude());
                app.getTargetPointsHelper().navigateToPoint(point, true, -1, marker.getPointDescription(mapActivity));
                app.getRoutingHelper().onSettingsChanged(true);
            }
        });
        if (i > 0) {
            View div = new View(ctx);
            LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, AndroidUtils.dpToPx(ctx, 1f));
            AndroidUtils.setMargins(p, listTextPadding, 0, 0, 0);
            div.setLayoutParams(p);
            AndroidUtils.setBackgroundColor(ctx, div, ColorUtilities.getDividerColorId(nightMode));
            div.setVisibility(View.VISIBLE);
            root.addView(div);
        }
        root.addView(v);
        i++;
    }
    View showAllButton = view.findViewById(R.id.show_all_button);
    if (showLimited && showLimitExceeds) {
        ((TextView) view.findViewById(R.id.show_all_title)).setText(String.format("%s — %d", app.getString(R.string.shared_string_show_all).toUpperCase(), markers.size()));
        showAllButton.setVisibility(View.VISIBLE);
        showAllButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                showLimited = false;
                updateContent();
                setLayoutNeeded();
            }
        });
    } else {
        showAllButton.setVisibility(View.GONE);
    }
    ((TextView) view.findViewById(R.id.gpx_card_title)).setText(R.string.map_markers);
}
Also used : MapMarker(net.osmand.plus.mapmarkers.MapMarker) Drawable(android.graphics.drawable.Drawable) DirectionDrawable(net.osmand.plus.views.DirectionDrawable) DirectionDrawable(net.osmand.plus.views.DirectionDrawable) ImageView(android.widget.ImageView) TextView(android.widget.TextView) View(android.view.View) SuppressLint(android.annotation.SuppressLint) LatLon(net.osmand.data.LatLon) ContextThemeWrapper(androidx.appcompat.view.ContextThemeWrapper) LayoutInflater(android.view.LayoutInflater) TextView(android.widget.TextView) ImageView(android.widget.ImageView) LinearLayout(android.widget.LinearLayout) SuppressLint(android.annotation.SuppressLint)

Example 24 with MapMarker

use of net.osmand.plus.mapmarkers.MapMarker in project Osmand by osmandapp.

the class MapMarkersWidgetsFactory method showMarkerOnMap.

private void showMarkerOnMap(int index) {
    if (helper.getMapMarkers().size() > index) {
        MapMarker marker = helper.getMapMarkers().get(index);
        AnimateDraggingMapThread thread = map.getMapView().getAnimatedDraggingThread();
        LatLon pointToNavigate = marker.point;
        if (pointToNavigate != null) {
            int fZoom = Math.max(map.getMapView().getZoom(), 15);
            thread.startMoving(pointToNavigate.getLatitude(), pointToNavigate.getLongitude(), fZoom, true);
        }
    // MapMarkerDialogHelper.showMarkerOnMap(map, marker);
    }
}
Also used : LatLon(net.osmand.data.LatLon) AnimateDraggingMapThread(net.osmand.plus.views.AnimateDraggingMapThread) MapMarker(net.osmand.plus.mapmarkers.MapMarker)

Example 25 with MapMarker

use of net.osmand.plus.mapmarkers.MapMarker in project Osmand by osmandapp.

the class MapMarkersWidgetsFactory method updateInfo.

public void updateInfo(LatLon customLocation, int zoom) {
    if (customLocation != null) {
        loc = customLocation;
    } else {
        Location l = map.getMyApplication().getLocationProvider().getLastStaleKnownLocation();
        if (l != null) {
            loc = new LatLon(l.getLatitude(), l.getLongitude());
        } else {
            loc = map.getMapLocation();
        }
    }
    List<MapMarker> markers = helper.getMapMarkers();
    WidgetsVisibilityHelper vh = map.getWidgetsVisibilityHelper();
    if (zoom < 3 || markers.size() == 0 || vh.shouldHideMapMarkersWidget()) {
        updateVisibility(false);
        return;
    }
    Float heading = map.getMapViewTrackingUtilities().getHeading();
    MapMarker marker = markers.get(0);
    updateUI(loc, heading, marker, arrowImg, distText, okButton, addressText, true, customLocation != null);
    if (markers.size() > 1 && map.getMyApplication().getSettings().DISPLAYED_MARKERS_WIDGETS_COUNT.get() == 2) {
        marker = markers.get(1);
        if (loc != null && customLocation == null) {
            for (int i = 1; i < markers.size(); i++) {
                MapMarker m = markers.get(i);
                m.dist = (int) (MapUtils.getDistance(m.getLatitude(), m.getLongitude(), loc.getLatitude(), loc.getLongitude()));
                if (m.dist < MIN_DIST_2ND_ROW_SHOW && marker.dist > m.dist) {
                    marker = m;
                }
            }
        }
        updateUI(loc, heading, marker, arrowImg2nd, distText2nd, okButton2nd, addressText2nd, false, customLocation != null);
        AndroidUiHelper.updateVisibility(topBar2nd, true);
    } else {
        AndroidUiHelper.updateVisibility(topBar2nd, false);
    }
    updateVisibility(true);
}
Also used : LatLon(net.osmand.data.LatLon) MapMarker(net.osmand.plus.mapmarkers.MapMarker) Location(net.osmand.Location)

Aggregations

MapMarker (net.osmand.plus.mapmarkers.MapMarker)106 LatLon (net.osmand.data.LatLon)42 ArrayList (java.util.ArrayList)30 OsmandApplication (net.osmand.plus.OsmandApplication)26 TargetPoint (net.osmand.plus.helpers.TargetPointsHelper.TargetPoint)24 MapMarkersHelper (net.osmand.plus.mapmarkers.MapMarkersHelper)20 GPXFile (net.osmand.GPXUtilities.GPXFile)18 PointDescription (net.osmand.data.PointDescription)18 File (java.io.File)16 FavouritePoint (net.osmand.data.FavouritePoint)16 MapMarkersGroup (net.osmand.plus.mapmarkers.MapMarkersGroup)16 View (android.view.View)14 MapActivity (net.osmand.plus.activities.MapActivity)14 Paint (android.graphics.Paint)12 NonNull (androidx.annotation.NonNull)12 Nullable (androidx.annotation.Nullable)12 RecyclerView (androidx.recyclerview.widget.RecyclerView)12 WptPt (net.osmand.GPXUtilities.WptPt)12 Location (net.osmand.Location)12 Amenity (net.osmand.data.Amenity)12