Search in sources :

Example 26 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 27 with MapMarker

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

the class OsmandAidlApi method updateMapMarker.

boolean updateMapMarker(String prevName, LatLon prevLatLon, String newName, LatLon newLatLon, boolean ignoreCoordinates) {
    LatLon latLon = new LatLon(prevLatLon.getLatitude(), prevLatLon.getLongitude());
    LatLon latLonNew = new LatLon(newLatLon.getLatitude(), newLatLon.getLongitude());
    MapMarkersHelper markersHelper = app.getMapMarkersHelper();
    List<MapMarker> mapMarkers = markersHelper.getMapMarkers();
    for (MapMarker m : mapMarkers) {
        if (m.getOnlyName().equals(prevName)) {
            if (ignoreCoordinates || latLon.equals(new LatLon(m.getLatitude(), m.getLongitude()))) {
                PointDescription pd = new PointDescription(PointDescription.POINT_TYPE_MAP_MARKER, newName != null ? newName : "");
                MapMarker marker = new MapMarker(m.point, pd, m.colorIndex);
                marker.id = m.id;
                marker.selected = m.selected;
                marker.visitedDate = m.visitedDate;
                marker.creationDate = m.creationDate;
                markersHelper.moveMapMarker(marker, latLonNew);
                refreshMap();
                return true;
            }
        }
    }
    return false;
}
Also used : LatLon(net.osmand.data.LatLon) ALatLon(net.osmand.aidlapi.map.ALatLon) MapMarkersHelper(net.osmand.plus.mapmarkers.MapMarkersHelper) MapMarker(net.osmand.plus.mapmarkers.MapMarker) PointDescription(net.osmand.data.PointDescription)

Example 28 with MapMarker

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

the class MapMarkersActiveAdapter method onItemSwiped.

@Override
public void onItemSwiped(RecyclerView.ViewHolder holder) {
    final int pos = holder.getAdapterPosition();
    final MapMarker marker = getItem(pos);
    mapActivity.getMyApplication().getMapMarkersHelper().moveMapMarkerToHistory(marker);
    MapMarkersGroup group = mapActivity.getMyApplication().getMapMarkersHelper().getMapMarkerGroupById(marker.groupKey, ItineraryType.MARKERS);
    if (group != null) {
        mapActivity.getMyApplication().getMapMarkersHelper().updateGroup(group);
    }
    changeMarkers();
    notifyDataSetChanged();
    snackbar = Snackbar.make(holder.itemView, R.string.marker_moved_to_history, Snackbar.LENGTH_LONG).setAction(R.string.shared_string_undo, new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            mapActivity.getMyApplication().getMapMarkersHelper().restoreMarkerFromHistory(marker, pos);
            changeMarkers();
            notifyDataSetChanged();
        }
    });
    UiUtilities.setupSnackbar(snackbar, night);
    snackbar.show();
}
Also used : MapMarker(net.osmand.plus.mapmarkers.MapMarker) MapMarkersGroup(net.osmand.plus.mapmarkers.MapMarkersGroup) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView)

Example 29 with MapMarker

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

the class MapMarkersActiveAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(final MapMarkerItemViewHolder holder, final int pos) {
    UiUtilities iconsCache = mapActivity.getMyApplication().getUIUtilities();
    MapMarker marker = markers.get(pos);
    ImageView markerImageViewToUpdate;
    int drawableResToUpdate;
    int markerColor = MapMarker.getColorId(marker.colorIndex);
    int actionIconColor = night ? R.color.icon_color_primary_dark : R.color.icon_color_primary_light;
    LatLon markerLatLon = new LatLon(marker.getLatitude(), marker.getLongitude());
    final boolean displayedInWidget = pos < mapActivity.getMyApplication().getSettings().DISPLAYED_MARKERS_WIDGETS_COUNT.get();
    if (showDirectionEnabled && displayedInWidget) {
        holder.iconDirection.setVisibility(View.GONE);
        holder.icon.setImageDrawable(iconsCache.getIcon(R.drawable.ic_arrow_marker_diretion, markerColor));
        holder.mainLayout.setBackgroundColor(ContextCompat.getColor(mapActivity, night ? R.color.list_divider_dark : R.color.markers_top_bar_background));
        holder.title.setTextColor(ContextCompat.getColor(mapActivity, night ? R.color.text_color_primary_dark : R.color.color_white));
        holder.divider.setBackgroundColor(ContextCompat.getColor(mapActivity, R.color.map_markers_on_map_divider_color));
        holder.optionsBtn.setBackgroundDrawable(AppCompatResources.getDrawable(mapActivity, R.drawable.marker_circle_background_on_map_with_inset));
        holder.optionsBtn.setImageDrawable(iconsCache.getIcon(R.drawable.ic_action_marker_passed, R.color.color_white));
        holder.iconReorder.setImageDrawable(iconsCache.getIcon(R.drawable.ic_action_item_move, R.color.icon_color_default_light));
        holder.description.setTextColor(ContextCompat.getColor(mapActivity, R.color.map_markers_on_map_color));
        drawableResToUpdate = R.drawable.ic_arrow_marker_diretion;
        markerImageViewToUpdate = holder.icon;
    } else {
        holder.iconDirection.setVisibility(View.VISIBLE);
        holder.icon.setImageDrawable(iconsCache.getIcon(R.drawable.ic_action_flag, markerColor));
        holder.mainLayout.setBackgroundColor(ColorUtilities.getListBgColor(mapActivity, night));
        holder.title.setTextColor(ColorUtilities.getPrimaryTextColor(mapActivity, night));
        holder.divider.setBackgroundColor(ContextCompat.getColor(mapActivity, night ? R.color.app_bar_color_dark : R.color.divider_color_light));
        holder.optionsBtn.setBackgroundDrawable(AppCompatResources.getDrawable(mapActivity, night ? R.drawable.marker_circle_background_dark_with_inset : R.drawable.marker_circle_background_light_with_inset));
        holder.optionsBtn.setImageDrawable(iconsCache.getIcon(R.drawable.ic_action_marker_passed, actionIconColor));
        holder.iconReorder.setImageDrawable(iconsCache.getThemedIcon(R.drawable.ic_action_item_move));
        holder.description.setTextColor(ColorUtilities.getDefaultIconColor(mapActivity, night));
        drawableResToUpdate = R.drawable.ic_direction_arrow;
        markerImageViewToUpdate = holder.iconDirection;
    }
    if (pos == getItemCount() - 1) {
        holder.bottomShadow.setVisibility(View.VISIBLE);
        holder.divider.setVisibility(View.GONE);
    } else {
        holder.bottomShadow.setVisibility(View.GONE);
        holder.divider.setVisibility(View.VISIBLE);
    }
    holder.point.setVisibility(View.VISIBLE);
    holder.iconReorder.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View view, MotionEvent event) {
            if (event.getActionMasked() == MotionEvent.ACTION_DOWN) {
                listener.onDragStarted(holder);
            }
            return false;
        }
    });
    holder.title.setText(marker.getName(mapActivity));
    String descr;
    if ((descr = marker.groupName) != null) {
        if (descr.isEmpty()) {
            descr = mapActivity.getString(R.string.shared_string_favorites);
        }
    } else {
        descr = OsmAndFormatter.getFormattedDate(mapActivity, marker.creationDate);
    }
    if (marker.wptPt != null && !Algorithms.isEmpty(marker.wptPt.category)) {
        descr = marker.wptPt.category + ", " + descr;
    }
    holder.description.setText(descr);
    holder.optionsBtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            final int position = holder.getAdapterPosition();
            if (position < 0) {
                return;
            }
            final MapMarker marker = markers.get(position);
            mapActivity.getMyApplication().getMapMarkersHelper().moveMapMarkerToHistory(marker);
            changeMarkers();
            notifyDataSetChanged();
            snackbar = Snackbar.make(holder.itemView, mapActivity.getString(R.string.marker_moved_to_history), Snackbar.LENGTH_LONG).setAction(R.string.shared_string_undo, new View.OnClickListener() {

                @Override
                public void onClick(View view) {
                    mapActivity.getMyApplication().getMapMarkersHelper().restoreMarkerFromHistory(marker, position);
                    changeMarkers();
                    notifyDataSetChanged();
                }
            });
            UiUtilities.setupSnackbar(snackbar, night);
            snackbar.show();
        }
    });
    updateLocationViewCache.arrowResId = drawableResToUpdate;
    updateLocationViewCache.arrowColor = showDirectionEnabled && displayedInWidget ? markerColor : 0;
    uiUtilities.updateLocationView(updateLocationViewCache, markerImageViewToUpdate, holder.distance, markerLatLon);
}
Also used : UiUtilities(net.osmand.plus.utils.UiUtilities) LatLon(net.osmand.data.LatLon) MapMarker(net.osmand.plus.mapmarkers.MapMarker) ImageView(android.widget.ImageView) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) MotionEvent(android.view.MotionEvent)

Example 30 with MapMarker

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

the class MapRouteInfoMenu method selectMapMarker.

public void selectMapMarker(final int index, final PointType pointType) {
    MapActivity mapActivity = getMapActivity();
    if (mapActivity != null) {
        MapMarker m = null;
        List<MapMarker> mapMarkers = mapActivity.getMyApplication().getMapMarkersHelper().getMapMarkers();
        if (index != -1 && mapMarkers.size() > index) {
            m = mapMarkers.get(index);
        }
        selectMapMarker(m, pointType);
    }
}
Also used : MapMarker(net.osmand.plus.mapmarkers.MapMarker) MapActivity(net.osmand.plus.activities.MapActivity)

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