diff --git a/OsmAnd/res/layout/map_marker_item_new.xml b/OsmAnd/res/layout/map_marker_item_new.xml index 96c4cff626..3bdea75231 100644 --- a/OsmAnd/res/layout/map_marker_item_new.xml +++ b/OsmAnd/res/layout/map_marker_item_new.xml @@ -7,21 +7,14 @@ android:descendantFocusability="blocksDescendants" android:orientation="vertical"> - - - - - - - + tools:visibility="visible"/> Транспортное учреждение Законодательное учреждение + Глина + diff --git a/OsmAnd/res/values-ru/strings.xml b/OsmAnd/res/values-ru/strings.xml index 156a298ff9..a475a35b4e 100644 --- a/OsmAnd/res/values-ru/strings.xml +++ b/OsmAnd/res/values-ru/strings.xml @@ -2490,7 +2490,7 @@ %1$d из %2$d Список Группы - Последнее использование: %1$s + Пройдено: %1$s Сделать активным Сегодня Вчера diff --git a/OsmAnd/res/values/phrases.xml b/OsmAnd/res/values/phrases.xml index a90eb1cedf..048e7baa54 100644 --- a/OsmAnd/res/values/phrases.xml +++ b/OsmAnd/res/values/phrases.xml @@ -3485,4 +3485,14 @@ VHF channel + Gorge + Couloir + Mountain area + + Clay + Tartan + Artificial turf + DecoTurf + Metal grid + diff --git a/OsmAnd/src/net/osmand/plus/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/OsmandSettings.java index 3a6c93c897..d47e86a15c 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/OsmandSettings.java @@ -1337,6 +1337,7 @@ public class OsmandSettings { public final OsmandPreference ANIMATE_MY_LOCATION = new BooleanPreference("animate_my_location", true).makeGlobal().cache(); public final OsmandPreference ROUTE_MAP_MARKERS_START_MY_LOC = new BooleanPreference("route_map_markers_start_my_loc", false).makeGlobal().cache(); + public final OsmandPreference ROUTE_MAP_MARKERS_ROUND_TRIP = new BooleanPreference("route_map_markers_round_trip", false).makeGlobal().cache(); public ITileSource getMapTileSource(boolean warnWhenSelected) { String tileName = MAP_TILE_SOURCES.get(); diff --git a/OsmAnd/src/net/osmand/plus/helpers/GpxUiHelper.java b/OsmAnd/src/net/osmand/plus/helpers/GpxUiHelper.java index 0e25d29d7c..59f3a88b08 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/GpxUiHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/GpxUiHelper.java @@ -1440,7 +1440,7 @@ public class GpxUiHelper { calculatedH[k] = ph + (values.get(nextW).getY() - ph) / (values.get(nextW).getX() - pd) * (calculatedDist[k] - pd); } - double SLOPE_PROXIMITY = 150; + double SLOPE_PROXIMITY = 100; if (totalDistance - SLOPE_PROXIMITY < 0) { if (useRightAxis) { diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java index 7fd532ccf2..3f83428f8c 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenuFragment.java @@ -889,26 +889,31 @@ public class MapContextMenuFragment extends Fragment implements DownloadEvents { } int dp16 = dpToPx(16f); + boolean has16margin = false; int titleButtonHeight = 0; View titleButtonContainer = view.findViewById(R.id.title_button_container); if (titleButtonContainer.getVisibility() == View.VISIBLE) { titleButtonHeight = titleButtonContainer.getMeasuredHeight() - dp16; if (titleButtonHeight < 0) { titleButtonHeight = 0; + } else { + has16margin = true; } } int downloadButtonsHeight = 0; View downloadButtonsContainer = view.findViewById(R.id.download_buttons_container); if (downloadButtonsContainer.getVisibility() == View.VISIBLE) { - downloadButtonsHeight = downloadButtonsContainer.getMeasuredHeight() - dp16; + downloadButtonsHeight = downloadButtonsContainer.getMeasuredHeight() - (has16margin ? 0 : dp16); if (downloadButtonsHeight < 0) { downloadButtonsHeight = 0; + } else { + has16margin = true; } } int titleProgressHeight = 0; View titleProgressContainer = view.findViewById(R.id.title_progress_container); if (titleProgressContainer.getVisibility() == View.VISIBLE) { - titleProgressHeight = titleProgressContainer.getMeasuredHeight() - dp16; + titleProgressHeight = titleProgressContainer.getMeasuredHeight() - (has16margin ? 0 : dp16); if (titleProgressHeight < 0) { titleProgressHeight = 0; } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/AmenityMenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/AmenityMenuController.java index e9a988283b..55f712ba66 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/AmenityMenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/AmenityMenuController.java @@ -11,6 +11,7 @@ import net.osmand.data.TransportStop; import net.osmand.osm.PoiCategory; import net.osmand.osm.PoiFilter; import net.osmand.osm.PoiType; +import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.mapcontextmenu.MapContextMenu; @@ -104,6 +105,12 @@ public class AmenityMenuController extends MenuController { return true; } + @Override + public String getNameStr() { + OsmandSettings settings = getMapActivity().getMyApplication().getSettings(); + return amenity.getName(settings.MAP_PREFERRED_LOCALE.get(), settings.MAP_TRANSLITERATE_NAMES.get()); + } + @Override public String getTypeStr() { return getTypeStr(amenity); diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/RenderedObjectMenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/RenderedObjectMenuController.java index 92b64d4a1f..eac1f7675b 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/RenderedObjectMenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/RenderedObjectMenuController.java @@ -55,7 +55,7 @@ public class RenderedObjectMenuController extends MenuController { @Override public String getNameStr() { - if (!Algorithms.isEmpty(renderedObject.getName())) { + if (!Algorithms.isEmpty(renderedObject.getName()) && !isStartingWithRTLChar(renderedObject.getName())) { return renderedObject.getName(); } else if (renderedObject.getTags().size() > 0) { String lang = getMapActivity().getMyApplication().getSettings().MAP_PREFERRED_LOCALE.get().toLowerCase(); @@ -67,6 +67,8 @@ public class RenderedObjectMenuController extends MenuController { name = renderedObject.getTags().get("name"); } return name; + } else if (!Algorithms.isEmpty(renderedObject.getName())) { + return renderedObject.getName(); } return ""; } @@ -97,4 +99,13 @@ public class RenderedObjectMenuController extends MenuController { } addMyLocationToPlainItems(latLon); } + + private boolean isStartingWithRTLChar(String s) { + byte directionality = Character.getDirectionality(s.charAt(0)); + return directionality == Character.DIRECTIONALITY_RIGHT_TO_LEFT + || directionality == Character.DIRECTIONALITY_RIGHT_TO_LEFT_ARABIC + || directionality == Character.DIRECTIONALITY_RIGHT_TO_LEFT_EMBEDDING + || directionality == Character.DIRECTIONALITY_RIGHT_TO_LEFT_OVERRIDE; + } + } diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/MarkersPlanRouteContext.java b/OsmAnd/src/net/osmand/plus/mapmarkers/MarkersPlanRouteContext.java index 95f271880f..569b01afe0 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/MarkersPlanRouteContext.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/MarkersPlanRouteContext.java @@ -172,6 +172,10 @@ public class MarkersPlanRouteContext { for (LatLon l : markersHelper.getSelectedMarkersLatLon()) { addWptPt(points, l.getLatitude(), l.getLongitude()); } + if (app.getSettings().ROUTE_MAP_MARKERS_ROUND_TRIP.get() && !points.isEmpty()) { + WptPt l = points.get(0); + addWptPt(points, l.getLatitude(), l.getLongitude()); + } return points; } diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteFragment.java index a6cf75f02a..f71e2c3daa 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteFragment.java @@ -24,12 +24,12 @@ import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.ProgressBar; import android.widget.TextView; -import android.widget.Toast; import net.osmand.AndroidUtils; import net.osmand.Location; import net.osmand.TspAnt; import net.osmand.data.LatLon; +import net.osmand.data.PointDescription; import net.osmand.data.RotatedTileBox; import net.osmand.plus.ApplicationMode; import net.osmand.plus.GPXUtilities.TrkSegment; @@ -38,9 +38,12 @@ import net.osmand.plus.IconsCache; import net.osmand.plus.MapMarkersHelper; import net.osmand.plus.MapMarkersHelper.MapMarker; import net.osmand.plus.OsmAndFormatter; +import net.osmand.plus.OsmAndLocationProvider.OsmAndLocationListener; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; +import net.osmand.plus.TargetPointsHelper; +import net.osmand.plus.TargetPointsHelper.TargetPoint; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.mapmarkers.PlanRouteOptionsBottomSheetDialogFragment.PlanRouteOptionsFragmentListener; @@ -48,6 +51,7 @@ import net.osmand.plus.mapmarkers.adapters.MapMarkersItemTouchHelperCallback; import net.osmand.plus.mapmarkers.adapters.MapMarkersListAdapter; import net.osmand.plus.measurementtool.SnapToRoadBottomSheetDialogFragment; import net.osmand.plus.measurementtool.SnapToRoadBottomSheetDialogFragment.SnapToRoadFragmentListener; +import net.osmand.plus.routing.RoutingHelper; import net.osmand.plus.views.MapMarkersLayer; import net.osmand.plus.views.OsmandMapTileView; import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory; @@ -59,9 +63,10 @@ import java.util.List; import static net.osmand.plus.OsmandSettings.LANDSCAPE_MIDDLE_RIGHT_CONSTANT; -public class PlanRouteFragment extends Fragment { +public class PlanRouteFragment extends Fragment implements OsmAndLocationListener { public static final String TAG = "PlanRouteFragment"; + private static final int MIN_DISTANCE_FOR_RECALCULATE = 50; // in meters private MapMarkersHelper markersHelper; private MarkersPlanRouteContext planRouteContext; @@ -78,6 +83,9 @@ public class PlanRouteFragment extends Fragment { private boolean nightMode; private boolean portrait; private boolean wasCollapseButtonVisible; + private boolean cancelSnapToRoad = true; + + private Location location; private View mainView; private RecyclerView markersRv; @@ -251,7 +259,6 @@ public class PlanRouteFragment extends Fragment { adapter = new MapMarkersListAdapter(mapActivity); adapter.setHasStableIds(true); - adapter.calculateStartAndFinishPos(); adapter.setSnappedToRoadPoints(planRouteContext.getSnappedToRoadPoints()); final ItemTouchHelper touchHelper = new ItemTouchHelper(new MapMarkersItemTouchHelperCallback(adapter)); touchHelper.attachToRecyclerView(markersRv); @@ -266,10 +273,11 @@ public class PlanRouteFragment extends Fragment { if (pos == RecyclerView.NO_POSITION) { return; } - if (pos == 0) { + Object item = adapter.getItem(pos); + if (item instanceof Location) { markersHelper.setStartFromMyLocation(!mapActivity.getMyApplication().getSettings().ROUTE_MAP_MARKERS_START_MY_LOC.get()); - } else { - MapMarker marker = adapter.getItem(pos); + } else if (item instanceof MapMarker) { + MapMarker marker = (MapMarker) item; selectedCount = marker.selected ? selectedCount - 1 : selectedCount + 1; marker.selected = !marker.selected; markersHelper.updateMapMarker(marker, false); @@ -305,7 +313,7 @@ public class PlanRouteFragment extends Fragment { } }); boolean isSmartphone = getResources().getConfiguration().smallestScreenWidthDp < 600; - markersRv.setPadding(0, 0, 0, AndroidUtils.dpToPx(mapActivity, isSmartphone ? 72 : 108)); + markersRv.setPadding(0, AndroidUtils.dpToPx(mapActivity, isSmartphone ? 10 : 15), 0, AndroidUtils.dpToPx(mapActivity, isSmartphone ? 8 : 12)); markersRv.setClipToPadding(false); markersRv.setLayoutManager(new LinearLayoutManager(getContext())); markersRv.setAdapter(adapter); @@ -317,12 +325,59 @@ public class PlanRouteFragment extends Fragment { return view; } + @Override + public void onResume() { + super.onResume(); + MapActivity mapActivity = getMapActivity(); + if (mapActivity != null) { + mapActivity.getMyApplication().getLocationProvider().addLocationListener(this); + } + } + + @Override + public void onPause() { + super.onPause(); + MapActivity mapActivity = getMapActivity(); + if (mapActivity != null) { + mapActivity.getMyApplication().getLocationProvider().removeLocationListener(this); + } + } + @Override public void onDestroyView() { super.onDestroyView(); exitPlanRouteMode(); } + @Override + public void updateLocation(Location loc) { + MapActivity mapActivity = getMapActivity(); + if (mapActivity != null) { + final Location location = mapActivity.getMyApplication().getLocationProvider().getLastStaleKnownLocation(); + boolean newLocation = (this.location == null && location != null) || location == null; + boolean locationChanged = this.location != null && location != null + && this.location.getLatitude() != location.getLatitude() + && this.location.getLongitude() != location.getLongitude(); + boolean farEnough = locationChanged && MapUtils.getDistance(this.location.getLatitude(), this.location.getLongitude(), + location.getLatitude(), location.getLongitude()) >= MIN_DISTANCE_FOR_RECALCULATE; + if (newLocation || farEnough) { + mapActivity.getMyApplication().runInUIThread(new Runnable() { + @Override + public void run() { + PlanRouteFragment.this.location = location; + adapter.reloadData(); + try { + adapter.notifyDataSetChanged(); + } catch (Exception e) { + // to avoid crash because of: + // java.lang.IllegalStateException: Cannot call this method while RecyclerView is computing a layout or scrolling + } + } + }); + } + } + } + private MapActivity getMapActivity() { return (MapActivity) getActivity(); } @@ -353,6 +408,10 @@ public class PlanRouteFragment extends Fragment { @Override public void onApplicationModeItemClick(ApplicationMode mode) { if (planRouteContext.getSnappedMode() != mode) { + MapMarkersLayer layer = getMapMarkersLayer(); + if (layer != null) { + layer.setDefaultAppMode(mode == ApplicationMode.DEFAULT); + } planRouteContext.getSnappedToRoadPoints().clear(); planRouteContext.setSnappedMode(mode); planRouteContext.recreateSnapTrkSegment(); @@ -375,14 +434,58 @@ public class PlanRouteFragment extends Fragment { @Override public void navigateOnClick() { if (mapActivity != null) { - Toast.makeText(mapActivity, "navigate", Toast.LENGTH_SHORT).show(); + boolean hasTargets = false; + TargetPointsHelper targetPointsHelper = mapActivity.getMyApplication().getTargetPointsHelper(); + List markers = markersHelper.getSelectedMarkers(); + if (markers.size() > 0) { + int i = 0; + if (markersHelper.isStartFromMyLocation()) { + targetPointsHelper.clearStartPoint(false); + } else { + MapMarker m = markers.get(i++); + targetPointsHelper.setStartPoint(new LatLon(m.getLatitude(), m.getLongitude()), + false, m.getPointDescription(mapActivity)); + } + List targetPoints = new ArrayList<>(); + for (int k = i; k < markers.size(); k++) { + MapMarker m = markers.get(k); + TargetPoint t = new TargetPoint(new LatLon(m.getLatitude(), m.getLongitude()), + m.getPointDescription(mapActivity)); + targetPoints.add(t); + } + if (mapActivity.getMyApplication().getSettings().ROUTE_MAP_MARKERS_ROUND_TRIP.get()) { + TargetPoint end = targetPointsHelper.getPointToStart(); + if (end == null) { + Location loc = mapActivity.getMyApplication().getLocationProvider().getLastKnownLocation(); + if (loc != null) { + end = TargetPoint.createStartPoint(new LatLon(loc.getLatitude(), loc.getLongitude()), + new PointDescription(PointDescription.POINT_TYPE_MY_LOCATION, + getString(R.string.shared_string_my_location))); + } + } + if (end != null) { + targetPoints.add(end); + } + } + RoutingHelper routingHelper = mapActivity.getRoutingHelper(); + boolean updateRoute = routingHelper.isFollowingMode() || routingHelper.isRoutePlanningMode(); + targetPointsHelper.reorderAllTargetPoints(targetPoints, updateRoute); + hasTargets = true; + } else { + targetPointsHelper.clearStartPoint(false); + targetPointsHelper.clearPointToNavigate(false); + } + dismiss(); + mapActivity.getMapLayers().getMapControlsLayer().doRoute(hasTargets); } } @Override public void makeRoundTripOnClick() { if (mapActivity != null) { - Toast.makeText(mapActivity, "make round trip", Toast.LENGTH_SHORT).show(); + OsmandSettings settings = mapActivity.getMyApplication().getSettings(); + settings.ROUTE_MAP_MARKERS_ROUND_TRIP.set(!settings.ROUTE_MAP_MARKERS_ROUND_TRIP.get()); + planRouteContext.recreateSnapTrkSegment(); } } @@ -402,7 +505,7 @@ public class PlanRouteFragment extends Fragment { public void reverseOrderOnClick() { if (mapActivity != null) { markersHelper.reverseActiveMarkersOrder(); - adapter.calculateStartAndFinishPos(); + adapter.reloadData(); adapter.notifyDataSetChanged(); planRouteContext.recreateSnapTrkSegment(); } @@ -539,7 +642,9 @@ public class PlanRouteFragment extends Fragment { mapActivity.getMapView().setMapPosition(previousMapPosition); - planRouteContext.cancelSnapToRoad(); + if (cancelSnapToRoad) { + planRouteContext.cancelSnapToRoad(); + } markersLayer.setRoute(null); mapActivity.refreshMap(); } @@ -610,6 +715,7 @@ public class PlanRouteFragment extends Fragment { private void showHideMarkersList() { MapActivity mapActivity = getMapActivity(); if (mapActivity != null && portrait) { + cancelSnapToRoad = false; planRouteContext.setMarkersListOpened(!planRouteContext.isMarkersListOpened()); int containerRes = planRouteContext.isMarkersListOpened() ? R.id.fragmentContainer : R.id.bottomFragmentContainer; mapActivity.getSupportFragmentManager().beginTransaction() @@ -670,18 +776,21 @@ public class PlanRouteFragment extends Fragment { } public boolean quit(boolean hideMarkersListFirst) { - if (planRouteContext.isMarkersListOpened() && hideMarkersListFirst) { + if (portrait && planRouteContext.isMarkersListOpened() && hideMarkersListFirst) { showHideMarkersList(); return false; } else { - dismiss(getMapActivity()); + dismiss(); return true; } } - private void dismiss(MapActivity activity) { - planRouteContext.setFragmentVisible(false); - activity.getSupportFragmentManager().beginTransaction().remove(this).commitAllowingStateLoss(); + private void dismiss() { + MapActivity activity = getMapActivity(); + if (activity != null) { + planRouteContext.setFragmentVisible(false); + activity.getSupportFragmentManager().beginTransaction().remove(this).commitAllowingStateLoss(); + } } public static boolean showInstance(MapActivity mapActivity) { @@ -755,7 +864,7 @@ public class PlanRouteFragment extends Fragment { } mapActivity.getMyApplication().getMapMarkersHelper().addSelectedMarkersToTop(res); - adapter.calculateStartAndFinishPos(); + adapter.reloadData(); adapter.notifyDataSetChanged(); planRouteContext.recreateSnapTrkSegment(); } diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteOptionsBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteOptionsBottomSheetDialogFragment.java index 48ef2ffb51..42e3ed58f0 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteOptionsBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/PlanRouteOptionsBottomSheetDialogFragment.java @@ -13,6 +13,7 @@ import android.view.ViewGroup; import android.view.ViewTreeObserver; import android.view.Window; import android.view.WindowManager; +import android.widget.CompoundButton; import android.widget.ImageView; import android.widget.TextView; @@ -59,6 +60,8 @@ public class PlanRouteOptionsBottomSheetDialogFragment extends BottomSheetDialog ((ImageView) mainView.findViewById(R.id.door_to_door_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_sort_door_to_door)); ((ImageView) mainView.findViewById(R.id.reverse_icon)).setImageDrawable(getContentIcon(R.drawable.ic_action_sort_reverse_order)); + ((CompoundButton) mainView.findViewById(R.id.make_round_trip_switch)).setChecked(getMyApplication().getSettings().ROUTE_MAP_MARKERS_ROUND_TRIP.get()); + if (!portrait) { ((ImageView) mainView.findViewById(R.id.select_icon)) .setImageDrawable(getContentIcon(selectAll ? R.drawable.ic_action_select_all : R.drawable.ic_action_deselect_all)); diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersListAdapter.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersListAdapter.java index d906631937..92bfb3d868 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersListAdapter.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersListAdapter.java @@ -11,7 +11,10 @@ import android.view.ViewGroup; import net.osmand.Location; import net.osmand.data.LatLon; +import net.osmand.data.PointDescription; import net.osmand.plus.GPXUtilities.WptPt; +import net.osmand.plus.GeocodingLookupService.AddressLookupRequest; +import net.osmand.plus.GeocodingLookupService.OnAddressLookupResult; import net.osmand.plus.IconsCache; import net.osmand.plus.MapMarkersHelper.MapMarker; import net.osmand.plus.OsmAndFormatter; @@ -23,6 +26,7 @@ import net.osmand.util.MapUtils; import java.text.SimpleDateFormat; import java.util.Collections; import java.util.Date; +import java.util.LinkedList; import java.util.List; import java.util.Locale; import java.util.Map; @@ -33,13 +37,18 @@ public class MapMarkersListAdapter extends RecyclerView.Adapter markers; + private List items = new LinkedList<>(); private MapMarkersListAdapterListener listener; private int startPos = -1; private int finishPos = -1; private int firstSelectedMarkerPos = -1; + private boolean showLocationItem; + private Location myLoc; + private AddressLookupRequest locRequest; + private PointDescription locDescription; + private Map, List> snappedToRoadPoints; public void setAdapterListener(MapMarkersListAdapterListener listener) { @@ -51,8 +60,10 @@ public class MapMarkersListAdapter extends RecyclerView.Adapter= 0; i--) { - MapMarker m = markers.get(i); - if (m.selected) { - return m.point; + Object item = items.get(i); + if (item instanceof MapMarker) { + MapMarker m = (MapMarker) item; + if (m.selected) { + return m.point; + } } } return null; } + public void reloadData() { + items.clear(); + OsmandApplication app = mapActivity.getMyApplication(); + myLoc = app.getLocationProvider().getLastStaleKnownLocation(); + showLocationItem = myLoc != null; + if (showLocationItem) { + lookupLocationAddress(app); + items.add(myLoc); + } + items.addAll(mapActivity.getMyApplication().getMapMarkersHelper().getMapMarkers()); + calculateStartAndFinishPos(); + } + + private void lookupLocationAddress(OsmandApplication app) { + LatLon loc = new LatLon(myLoc.getLatitude(), myLoc.getLongitude()); + if (locRequest == null || !locRequest.getLatLon().equals(loc)) { + if (locRequest != null) { + app.getGeocodingLookupService().cancel(locRequest); + } + locRequest = new AddressLookupRequest(loc, new OnAddressLookupResult() { + @Override + public void geocodingDone(String address) { + locRequest = null; + locDescription.setName(address); + if (showLocationItem) { + notifyItemChanged(0); + } + } + }, null); + app.getGeocodingLookupService().lookupAddress(locRequest); + } + } + public void calculateStartAndFinishPos() { OsmandApplication app = mapActivity.getMyApplication(); boolean startCalculated = false; boolean finishCalculated = false; boolean firstSelectedMarkerCalculated = false; - if (app.getMapMarkersHelper().isStartFromMyLocation() && app.getLocationProvider().getLastStaleKnownLocation() != null) { + if (app.getMapMarkersHelper().isStartFromMyLocation() && showLocationItem) { startPos = 0; startCalculated = true; } - for (int i = 0; i < markers.size(); i++) { - if (markers.get(i).selected) { - if (!startCalculated) { - startPos = i + 1; - startCalculated = true; + for (int i = 0; i < items.size(); i++) { + Object item = items.get(i); + if (item instanceof MapMarker) { + MapMarker m = (MapMarker) item; + if (m.selected) { + if (!startCalculated) { + startPos = i; + startCalculated = true; + } + firstSelectedMarkerPos = i; + firstSelectedMarkerCalculated = true; + break; } - firstSelectedMarkerPos = i + 1; - firstSelectedMarkerCalculated = true; - break; } } - for (int i = markers.size() - 1; i >= 0; i--) { - if (markers.get(i).selected) { - finishPos = i + 1; - finishCalculated = true; - break; + for (int i = items.size() - 1; i >= 0; i--) { + Object item = items.get(i); + if (item instanceof MapMarker) { + MapMarker m = (MapMarker) item; + if (m.selected) { + finishPos = i; + finishCalculated = true; + break; + } } } if (!startCalculated) { diff --git a/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java b/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java index 22f0e3f17c..d1b750845f 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java @@ -817,7 +817,7 @@ public class MapControlsLayer extends OsmandMapLayer { backToLocationControl.iv.setContentDescription(mapActivity.getString(R.string.map_widget_back_to_loc)); } boolean visible = !(tracked && rh.isFollowingMode()); - backToLocationControl.updateVisibility(visible && !dialogOpened); + backToLocationControl.updateVisibility(visible && !dialogOpened && !isInPlanRouteMode()); if (app.accessibilityEnabled()) { backToLocationControl.iv.setClickable(enabled && visible); } diff --git a/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java b/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java index 02f6e11b29..4b8de11729 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/MapMarkersLayer.java @@ -71,7 +71,7 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi private final RenderingLineAttributes lineAttrs = new RenderingLineAttributes("measureDistanceLine"); private final RenderingLineAttributes textAttrs = new RenderingLineAttributes("rulerLineFont"); - private Paint paint; + private final RenderingLineAttributes planRouteAttrs = new RenderingLineAttributes("markerPlanRouteline"); private TrkSegment route; private TIntArrayList tx = new TIntArrayList(); @@ -81,6 +81,7 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi private ContextMenuLayer contextMenuLayer; private boolean inPlanRouteMode; + private boolean defaultAppMode = true; public MapMarkersLayer(MapActivity map) { this.map = map; @@ -98,6 +99,10 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi this.inPlanRouteMode = inPlanRouteMode; } + public void setDefaultAppMode(boolean defaultAppMode) { + this.defaultAppMode = defaultAppMode; + } + private void initUI() { bitmapPaint = new Paint(); bitmapPaint.setDither(true); @@ -120,15 +125,6 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi bitmapPaintDestTeal = createPaintDest(R.color.marker_teal); bitmapPaintDestPurple = createPaintDest(R.color.marker_purple); - paint = new Paint(); - paint.setStyle(Paint.Style.STROKE); - paint.setStrokeWidth(7 * view.getDensity()); - paint.setAntiAlias(true); - paint.setStrokeCap(Paint.Cap.ROUND); - paint.setStrokeJoin(Paint.Join.ROUND); - paint.setColor(ContextCompat.getColor(map, R.color.marker_red)); - paint.setAlpha(200); - float textSize = TEXT_SIZE * map.getResources().getDisplayMetrics().density; textAttrs.paint.setTextSize(textSize); textAttrs.paint2.setTextSize(textSize); @@ -207,12 +203,13 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi List activeMapMarkers = markersHelper.getMapMarkers(); if (route != null && route.points.size() > 0) { + planRouteAttrs.updatePaints(view, nightMode, tileBox); route.renders.clear(); route.renders.add(new Renderable.StandardTrack(new ArrayList<>(route.points), 17.2)); - route.drawRenderers(view.getZoom(), paint, canvas, tileBox); + route.drawRenderers(view.getZoom(), defaultAppMode ? planRouteAttrs.paint : planRouteAttrs.paint2, canvas, tileBox); } - if (markersHelper.isStartFromMyLocation() && myLoc != null) { + if (map.getMyApplication().getSettings().SHOW_LINES_TO_FIRST_MARKERS.get() && myLoc != null) { lineAttrs.updatePaints(view, nightMode, tileBox); textAttrs.updatePaints(view, nightMode, tileBox); textAttrs.paint.setStyle(Paint.Style.FILL); @@ -247,9 +244,9 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi float centerToMarkerDist = (float) MapUtils.getDistance(tileBox.getLatLonFromPixel(pos[0], pos[1]), marker.getLatitude(), marker.getLongitude()); String centerToMarkerDistSt = OsmAndFormatter.getFormattedDistance(centerToMarkerDist, view.getApplication()); if (locX >= markerX) { - distanceText = centerToMarkerDistSt + " | " + generalDistSt; + distanceText = centerToMarkerDistSt + " • " + generalDistSt; } else { - distanceText = generalDistSt + " | " + centerToMarkerDistSt; + distanceText = generalDistSt + " • " + centerToMarkerDistSt; } } else { distanceText = generalDistSt;