From b610a7027b3a59a8a7185c9a3db038c24a4d0ea6 Mon Sep 17 00:00:00 2001 From: vshcherb Date: Wed, 6 Nov 2024 17:11:45 +0200 Subject: [PATCH 01/10] Fix aa zoom --- .../net/osmand/plus/auto/SurfaceRenderer.java | 6 ++ .../auto/screens/BaseAndroidAutoScreen.kt | 42 +++++++----- .../plus/auto/screens/RoutePreviewScreen.java | 6 ++ .../osmand/plus/views/OsmandMapTileView.java | 66 ++++++++++++------- 4 files changed, 81 insertions(+), 39 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/auto/SurfaceRenderer.java b/OsmAnd/src/net/osmand/plus/auto/SurfaceRenderer.java index 00618ad37e7..6233fd9daab 100644 --- a/OsmAnd/src/net/osmand/plus/auto/SurfaceRenderer.java +++ b/OsmAnd/src/net/osmand/plus/auto/SurfaceRenderer.java @@ -461,6 +461,12 @@ public void renderFrame(RotatedTileBox tileBox, DrawSettings drawSettings) { } } + + @Nullable + public Rect getVisibleArea() { + return visibleArea; + } + public double getVisibleAreaWidth() { return visibleArea != null ? visibleArea.width() : 0f; } diff --git a/OsmAnd/src/net/osmand/plus/auto/screens/BaseAndroidAutoScreen.kt b/OsmAnd/src/net/osmand/plus/auto/screens/BaseAndroidAutoScreen.kt index e72e4bdeab7..774face8359 100644 --- a/OsmAnd/src/net/osmand/plus/auto/screens/BaseAndroidAutoScreen.kt +++ b/OsmAnd/src/net/osmand/plus/auto/screens/BaseAndroidAutoScreen.kt @@ -1,5 +1,7 @@ package net.osmand.plus.auto.screens +import android.graphics.Rect +import android.util.Log import androidx.car.app.CarContext import androidx.car.app.Screen import androidx.car.app.constraints.ConstraintManager @@ -93,21 +95,31 @@ abstract class BaseAndroidAutoScreen(carContext: CarContext) : Screen(carContext app.carNavigationSession?.navigationCarSurface?.let { surfaceRenderer -> if (!mapRect.hasInitialState()) { val mapView = app.osmandMap.mapView - val tileBox = mapView.rotatedTileBox - val rectWidth = mapRect.right - mapRect.left - val coef: Double = surfaceRenderer.visibleAreaWidth / tileBox.pixWidth - val left = mapRect.left - rectWidth * coef - val right = mapRect.right + rectWidth * coef - mapView.fitRectToMap( - left, - right, - mapRect.top, - mapRect.bottom, - tileBox.pixWidth, - tileBox.pixHeight, - 0, - 0, - true + // FIXME revert after start + // val prevElevationAngle: Float = mapView.normalizeElevationAngle(mapView.elevationAngle) + mapView.setElevationAngle(90f) + mapView.setRotate(0f, true) + // DELETE +// val tileBox = mapView.rotatedTileBox +// val vArea = surfaceRenderer.visibleArea +// val rectWidth = mapRect.right - mapRect.left +// val coef: Double = surfaceRenderer.visibleAreaWidth / tileBox.pixWidth +// mapRect.left -= rectWidth * coef +// mapRect.right += rectWidth * coef +// Log.i("net.osmand.dev", "ZOOM " + coef + " map rect" + mapRect) +// var dx = 0 +// if (vArea != null) { +// val ltr = vArea.left > (vArea.width() - vArea.right) +// if (ltr) { +// dx = vArea.left +// } else { +// dx = -(vArea.width() - vArea.right) +// } +// } + val tb = mapView.getRotatedTileBox() + mapView.fitRectToMap(tb, + mapRect.left, mapRect.right, mapRect.top, mapRect.bottom, + 0, 0, true ) mapView.refreshMap() } diff --git a/OsmAnd/src/net/osmand/plus/auto/screens/RoutePreviewScreen.java b/OsmAnd/src/net/osmand/plus/auto/screens/RoutePreviewScreen.java index 037d0db7bb2..8b3a3af79ee 100644 --- a/OsmAnd/src/net/osmand/plus/auto/screens/RoutePreviewScreen.java +++ b/OsmAnd/src/net/osmand/plus/auto/screens/RoutePreviewScreen.java @@ -3,6 +3,7 @@ import static net.osmand.search.core.ObjectType.GPX_TRACK; import android.text.SpannableString; +import android.util.Log; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -19,6 +20,7 @@ import androidx.lifecycle.DefaultLifecycleObserver; import androidx.lifecycle.LifecycleOwner; +import net.osmand.PlatformUtil; import net.osmand.plus.shared.SharedUtil; import net.osmand.StateChangedListener; import net.osmand.data.QuadRect; @@ -47,6 +49,8 @@ public final class RoutePreviewScreen extends BaseAndroidAutoScreen implements IRouteInformationListener, DefaultLifecycleObserver { + private static final org.apache.commons.logging.Log LOG = PlatformUtil.getLog(RoutePreviewScreen.class); + @NonNull private final Action settingsAction; @NonNull @@ -64,6 +68,7 @@ public void stateChanged(Void change) { if (routeGpxFile != null) { QuadRect mapRect = new QuadRect(); Algorithms.extendRectToContainRect(mapRect, SharedUtil.jQuadRect(routeGpxFile.getRect())); + adjustMapToRect(getApp().getMapViewTrackingUtilities().getDefaultLocation(), mapRect); } } @@ -207,6 +212,7 @@ public void newRouteIsCalculated(boolean newRoute, ValueHolder showToas RoutingHelper rh = getApp().getRoutingHelper(); QuadRect mapRect = RoutingHelperUtils.getRouteRect(getApp(), rh.getRoute()); if (mapRect != null) { + LOG.info("ZOOM Route " + mapRect); adjustMapToRect(getApp().getMapViewTrackingUtilities().getDefaultLocation(), mapRect); } updateRoute(newRoute); diff --git a/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java b/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java index 3a25feca2d7..23a4e175c2e 100644 --- a/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java +++ b/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java @@ -1682,28 +1682,8 @@ public void fitRectToMap(double left, double right, double top, double bottom, public void fitRectToMap(double left, double right, double top, double bottom, int tileBoxWidthPx, int tileBoxHeightPx, int marginTopPx, int marginLeftPx) { - fitRectToMap(left, right, top, bottom, tileBoxWidthPx, tileBoxHeightPx, marginTopPx, marginLeftPx, true); - } - - public boolean fullyContains(RotatedTileBox tb, double left, double top, double right, double bottom) { - // if at least one point is not inside the boundary, return false - if (!tb.containsLatLon(top, left)) { - return false; - } else if (!tb.containsLatLon(bottom, left)) { - return false; - } else if (!tb.containsLatLon(top, right)) { - return false; - } else if (!tb.containsLatLon(bottom, right)) { - return false; - } - return true; - } - - public void fitRectToMap(double left, double right, double top, double bottom, - int tileBoxWidthPx, int tileBoxHeightPx, int marginTopPx, int marginLeftPx, boolean useSmallZoom) { RotatedTileBox tb = currentViewport.copy(); - float zoomStep = useSmallZoom ? 0.1f : 1f; - double border = 0.8; + double border = 0.9; int dx = 0; int dy = 0; int tbw = (int) (tb.getPixWidth() * border); @@ -1720,7 +1700,32 @@ public void fitRectToMap(double left, double right, double top, double bottom, } dy += tb.getCenterPixelY() - tb.getPixHeight() / 2; tb.setPixelDimensions(tbw, tbh); + fitRectToMap(tb, left, right, top, bottom, dx, dy, true); + } + public boolean fullyContains(RotatedTileBox tb, double left, double top, double right, double bottom) { + // if at least one point is not inside the boundary, return false + if (!tb.containsLatLon(top, left)) { + return false; + } else if (!tb.containsLatLon(bottom, left)) { + return false; + } else if (!tb.containsLatLon(top, right)) { + return false; + } else if (!tb.containsLatLon(bottom, right)) { + return false; + } + return true; + } + + public void fitRectToMap(RotatedTileBox tb, double left, double right, double top, double bottom, + int dx, int dy, boolean useSmallZoom) { + float zoomStep = useSmallZoom ? 0.1f : 1f; + LOG.info(String.format(Locale.ENGLISH, + "FIXME ZOOM 1 FROM %.6f, %.6f - %.6f, %.6f - z=%.2f - fit %.6f, %.6f - %.6f, %.6f ", + tb.getLeftTopLatLon().getLatitude(), tb.getLeftTopLatLon().getLongitude(), + tb.getRightBottomLatLon().getLatitude(), tb.getRightBottomLatLon().getLongitude(), + tb.getZoom() + tb.getZoomFloatPart(), + top, left, bottom, right)); double clat = bottom / 2 + top / 2; double clon = left / 2 + right / 2; tb.setLatLonCenter(clat, clon); @@ -1731,13 +1736,26 @@ public void fitRectToMap(double left, double right, double top, double bottom, zoom.partialChangeZoom(-zoomStep); tb.setZoomAndAnimation(zoom.getBaseZoom(), 0, zoom.getZoomFloatPart()); } - zoom.partialChangeZoom(zoomStep); while (zoom.isZoomInAllowed() && fullyContains(tb, left, top, right, bottom)) { zoom.partialChangeZoom(zoomStep); tb.setZoomAndAnimation(zoom.getBaseZoom(), 0, zoom.getZoomFloatPart()); } - zoom.partialChangeZoom(-zoomStep); - tb.setZoomAndAnimation(zoom.getBaseZoom(), 0, zoom.getZoomFloatPart()); + LOG.info(String.format(Locale.ENGLISH, + "FIXME ZOOM LAST %.6f, %.6f - %.6f, %.6f - z=%.2f - fit %.6f, %.6f - %.6f, %.6f ", + tb.getLeftTopLatLon().getLatitude(), tb.getLeftTopLatLon().getLongitude(), + tb.getRightBottomLatLon().getLatitude(), tb.getRightBottomLatLon().getLongitude(), + tb.getZoom() + tb.getZoomFloatPart(), + top, left, bottom, right)); + if (zoom.isZoomOutAllowed()) { + zoom.partialChangeZoom(-zoomStep); + tb.setZoomAndAnimation(zoom.getBaseZoom(), 0, zoom.getZoomFloatPart()); + } + LOG.info(String.format(Locale.ENGLISH, + "FIXME ZOOM TO %.6f, %.6f - %.6f, %.6f - z=%.2f - fit %.6f, %.6f - %.6f, %.6f ", + tb.getLeftTopLatLon().getLatitude(), tb.getLeftTopLatLon().getLongitude(), + tb.getRightBottomLatLon().getLatitude(), tb.getRightBottomLatLon().getLongitude(), + tb.getZoom() + tb.getZoomFloatPart(), + top, left, bottom, right)); if (dy != 0 || dx != 0) { float x = tb.getPixWidth() / 2f + dx; float y = tb.getPixHeight() / 2f + dy; From 93b551b511aa79110810798fd5af3ce5588fb4ab Mon Sep 17 00:00:00 2001 From: vshcherb Date: Wed, 6 Nov 2024 17:44:43 +0200 Subject: [PATCH 02/10] Fix aa zoom --- .../auto/screens/BaseAndroidAutoScreen.kt | 21 ++++--------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/auto/screens/BaseAndroidAutoScreen.kt b/OsmAnd/src/net/osmand/plus/auto/screens/BaseAndroidAutoScreen.kt index 774face8359..44a101ad3a9 100644 --- a/OsmAnd/src/net/osmand/plus/auto/screens/BaseAndroidAutoScreen.kt +++ b/OsmAnd/src/net/osmand/plus/auto/screens/BaseAndroidAutoScreen.kt @@ -98,25 +98,12 @@ abstract class BaseAndroidAutoScreen(carContext: CarContext) : Screen(carContext // FIXME revert after start // val prevElevationAngle: Float = mapView.normalizeElevationAngle(mapView.elevationAngle) mapView.setElevationAngle(90f) + app.mapViewTrackingUtilities.isMapLinkedToLocation = false mapView.setRotate(0f, true) - // DELETE -// val tileBox = mapView.rotatedTileBox -// val vArea = surfaceRenderer.visibleArea -// val rectWidth = mapRect.right - mapRect.left -// val coef: Double = surfaceRenderer.visibleAreaWidth / tileBox.pixWidth -// mapRect.left -= rectWidth * coef -// mapRect.right += rectWidth * coef -// Log.i("net.osmand.dev", "ZOOM " + coef + " map rect" + mapRect) -// var dx = 0 -// if (vArea != null) { -// val ltr = vArea.left > (vArea.width() - vArea.right) -// if (ltr) { -// dx = vArea.left -// } else { -// dx = -(vArea.width() - vArea.right) -// } -// } + val vArea = surfaceRenderer.visibleArea val tb = mapView.getRotatedTileBox() + tb.rotate = 0f + tb.setCenterLocation(tb.centerPixelX.toFloat() / tb.pixWidth, 0.5f ) mapView.fitRectToMap(tb, mapRect.left, mapRect.right, mapRect.top, mapRect.bottom, 0, 0, true From cd705c1f2c16f597b7f2a9dead88ab835585eb8a Mon Sep 17 00:00:00 2001 From: Corwin-Kh Date: Thu, 7 Nov 2024 00:36:41 +0200 Subject: [PATCH 03/10] Improved ajustMapToRect for preview screen --- .../auto/screens/BaseAndroidAutoScreen.kt | 10 ++----- .../plus/auto/screens/RoutePreviewScreen.java | 27 ++++++++++++++++--- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/auto/screens/BaseAndroidAutoScreen.kt b/OsmAnd/src/net/osmand/plus/auto/screens/BaseAndroidAutoScreen.kt index 44a101ad3a9..544345c09b4 100644 --- a/OsmAnd/src/net/osmand/plus/auto/screens/BaseAndroidAutoScreen.kt +++ b/OsmAnd/src/net/osmand/plus/auto/screens/BaseAndroidAutoScreen.kt @@ -90,19 +90,13 @@ abstract class BaseAndroidAutoScreen(carContext: CarContext) : Screen(carContext } } - protected fun adjustMapToRect(location: LatLon, mapRect: QuadRect) { + protected open fun adjustMapToRect(location: LatLon, mapRect: QuadRect) { Algorithms.extendRectToContainPoint(mapRect, location.longitude, location.latitude) app.carNavigationSession?.navigationCarSurface?.let { surfaceRenderer -> if (!mapRect.hasInitialState()) { val mapView = app.osmandMap.mapView - // FIXME revert after start - // val prevElevationAngle: Float = mapView.normalizeElevationAngle(mapView.elevationAngle) - mapView.setElevationAngle(90f) app.mapViewTrackingUtilities.isMapLinkedToLocation = false - mapView.setRotate(0f, true) - val vArea = surfaceRenderer.visibleArea - val tb = mapView.getRotatedTileBox() - tb.rotate = 0f + val tb = mapView.rotatedTileBox tb.setCenterLocation(tb.centerPixelX.toFloat() / tb.pixWidth, 0.5f ) mapView.fitRectToMap(tb, mapRect.left, mapRect.right, mapRect.top, mapRect.bottom, diff --git a/OsmAnd/src/net/osmand/plus/auto/screens/RoutePreviewScreen.java b/OsmAnd/src/net/osmand/plus/auto/screens/RoutePreviewScreen.java index 8b3a3af79ee..54b24b719f3 100644 --- a/OsmAnd/src/net/osmand/plus/auto/screens/RoutePreviewScreen.java +++ b/OsmAnd/src/net/osmand/plus/auto/screens/RoutePreviewScreen.java @@ -3,7 +3,6 @@ import static net.osmand.search.core.ObjectType.GPX_TRACK; import android.text.SpannableString; -import android.util.Log; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -21,11 +20,10 @@ import androidx.lifecycle.LifecycleOwner; import net.osmand.PlatformUtil; -import net.osmand.plus.shared.SharedUtil; import net.osmand.StateChangedListener; +import net.osmand.data.LatLon; import net.osmand.data.QuadRect; import net.osmand.data.ValueHolder; -import net.osmand.shared.gpx.GpxFile; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.auto.TripHelper; @@ -33,10 +31,14 @@ import net.osmand.plus.routing.RoutingHelper; import net.osmand.plus.routing.RoutingHelperUtils; import net.osmand.plus.search.listitems.QuickSearchListItem; +import net.osmand.plus.settings.enums.CompassMode; +import net.osmand.plus.shared.SharedUtil; import net.osmand.plus.track.data.GPXInfo; import net.osmand.plus.track.helpers.GpxFileLoaderTask; import net.osmand.plus.track.helpers.SelectedGpxFile; +import net.osmand.plus.views.OsmandMapTileView; import net.osmand.search.core.SearchResult; +import net.osmand.shared.gpx.GpxFile; import net.osmand.util.Algorithms; import java.io.File; @@ -61,6 +63,9 @@ public final class RoutePreviewScreen extends BaseAndroidAutoScreen implements I @Nullable private GpxFile routeGpxFile; + private CompassMode savedCompassMode = CompassMode.NORTH_IS_UP; + private float prevElevationAngle = 90; + private final StateChangedListener stateChangedListener = new StateChangedListener() { @Override @@ -141,6 +146,10 @@ private void updateRoute(boolean newRoute) { public void onCreate(@NonNull LifecycleOwner owner) { getApp().getRoutingHelper().addListener(this); getApp().getTargetPointsHelper().addListener(stateChangedListener); + savedCompassMode = getApp().getSettings().getCompassMode(); + getApp().getSettings().setCompassMode(CompassMode.NORTH_IS_UP); + OsmandMapTileView mapView = getApp().getOsmandMap().getMapView(); + prevElevationAngle = mapView.normalizeElevationAngle(mapView.getElevationAngle()); if (getApp().getRoutingHelper().isRouteCalculated()) { updateRoute(true); } else { @@ -153,6 +162,9 @@ public void onDestroy(@NonNull LifecycleOwner owner) { OsmandApplication app = getApp(); RoutingHelper routingHelper = app.getRoutingHelper(); routingHelper.removeListener(this); + app.getSettings().setCompassMode(savedCompassMode); + OsmandMapTileView mapView = getApp().getOsmandMap().getMapView(); + mapView.setElevationAngle(prevElevationAngle); if (routingHelper.isRoutePlanningMode()) { app.stopNavigation(); } @@ -234,4 +246,13 @@ public void tryToStartNavigation() { onNavigate(); } } + + @Override + protected void adjustMapToRect(@NonNull LatLon location, @NonNull QuadRect mapRect) { + OsmandMapTileView mapView = getApp().getOsmandMap().getMapView(); + mapView.setElevationAngle(90f); + getApp().getMapViewTrackingUtilities().setMapLinkedToLocation(false); + mapView.setRotate(0f, true); + super.adjustMapToRect(location, mapRect); + } } From da13646a7ed16e70ccedfdda4ce0108869a3e00d Mon Sep 17 00:00:00 2001 From: Corwin-Kh Date: Tue, 12 Nov 2024 23:13:28 +0200 Subject: [PATCH 04/10] Removed debug logs --- .../osmand/plus/views/OsmandMapTileView.java | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java b/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java index 23a4e175c2e..917763c8d1b 100644 --- a/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java +++ b/OsmAnd/src/net/osmand/plus/views/OsmandMapTileView.java @@ -1720,12 +1720,6 @@ public boolean fullyContains(RotatedTileBox tb, double left, double top, double public void fitRectToMap(RotatedTileBox tb, double left, double right, double top, double bottom, int dx, int dy, boolean useSmallZoom) { float zoomStep = useSmallZoom ? 0.1f : 1f; - LOG.info(String.format(Locale.ENGLISH, - "FIXME ZOOM 1 FROM %.6f, %.6f - %.6f, %.6f - z=%.2f - fit %.6f, %.6f - %.6f, %.6f ", - tb.getLeftTopLatLon().getLatitude(), tb.getLeftTopLatLon().getLongitude(), - tb.getRightBottomLatLon().getLatitude(), tb.getRightBottomLatLon().getLongitude(), - tb.getZoom() + tb.getZoomFloatPart(), - top, left, bottom, right)); double clat = bottom / 2 + top / 2; double clon = left / 2 + right / 2; tb.setLatLonCenter(clat, clon); @@ -1740,22 +1734,10 @@ public void fitRectToMap(RotatedTileBox tb, double left, double right, double to zoom.partialChangeZoom(zoomStep); tb.setZoomAndAnimation(zoom.getBaseZoom(), 0, zoom.getZoomFloatPart()); } - LOG.info(String.format(Locale.ENGLISH, - "FIXME ZOOM LAST %.6f, %.6f - %.6f, %.6f - z=%.2f - fit %.6f, %.6f - %.6f, %.6f ", - tb.getLeftTopLatLon().getLatitude(), tb.getLeftTopLatLon().getLongitude(), - tb.getRightBottomLatLon().getLatitude(), tb.getRightBottomLatLon().getLongitude(), - tb.getZoom() + tb.getZoomFloatPart(), - top, left, bottom, right)); if (zoom.isZoomOutAllowed()) { zoom.partialChangeZoom(-zoomStep); tb.setZoomAndAnimation(zoom.getBaseZoom(), 0, zoom.getZoomFloatPart()); } - LOG.info(String.format(Locale.ENGLISH, - "FIXME ZOOM TO %.6f, %.6f - %.6f, %.6f - z=%.2f - fit %.6f, %.6f - %.6f, %.6f ", - tb.getLeftTopLatLon().getLatitude(), tb.getLeftTopLatLon().getLongitude(), - tb.getRightBottomLatLon().getLatitude(), tb.getRightBottomLatLon().getLongitude(), - tb.getZoom() + tb.getZoomFloatPart(), - top, left, bottom, right)); if (dy != 0 || dx != 0) { float x = tb.getPixWidth() / 2f + dx; float y = tb.getPixHeight() / 2f + dy; From 4bc33f1cde02f3720354b51df27429c8fb9358b0 Mon Sep 17 00:00:00 2001 From: Corwin-Kh Date: Thu, 14 Nov 2024 14:45:55 +0200 Subject: [PATCH 05/10] Fixed restore map state when opening RoutePreviewScreen from phone --- .../plus/auto/screens/RoutePreviewScreen.java | 33 ++++++++++++++++--- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/auto/screens/RoutePreviewScreen.java b/OsmAnd/src/net/osmand/plus/auto/screens/RoutePreviewScreen.java index 54b24b719f3..1ed0ce115b7 100644 --- a/OsmAnd/src/net/osmand/plus/auto/screens/RoutePreviewScreen.java +++ b/OsmAnd/src/net/osmand/plus/auto/screens/RoutePreviewScreen.java @@ -2,6 +2,8 @@ import static net.osmand.search.core.ObjectType.GPX_TRACK; +import android.os.Handler; +import android.os.Looper; import android.text.SpannableString; import androidx.annotation.NonNull; @@ -65,6 +67,7 @@ public final class RoutePreviewScreen extends BaseAndroidAutoScreen implements I private CompassMode savedCompassMode = CompassMode.NORTH_IS_UP; private float prevElevationAngle = 90; + private float prevRotationAngle = 0; private final StateChangedListener stateChangedListener = new StateChangedListener() { @@ -146,9 +149,10 @@ private void updateRoute(boolean newRoute) { public void onCreate(@NonNull LifecycleOwner owner) { getApp().getRoutingHelper().addListener(this); getApp().getTargetPointsHelper().addListener(stateChangedListener); + OsmandMapTileView mapView = getApp().getOsmandMap().getMapView(); savedCompassMode = getApp().getSettings().getCompassMode(); + prevRotationAngle = mapView.getRotate(); getApp().getSettings().setCompassMode(CompassMode.NORTH_IS_UP); - OsmandMapTileView mapView = getApp().getOsmandMap().getMapView(); prevElevationAngle = mapView.normalizeElevationAngle(mapView.getElevationAngle()); if (getApp().getRoutingHelper().isRouteCalculated()) { updateRoute(true); @@ -162,9 +166,6 @@ public void onDestroy(@NonNull LifecycleOwner owner) { OsmandApplication app = getApp(); RoutingHelper routingHelper = app.getRoutingHelper(); routingHelper.removeListener(this); - app.getSettings().setCompassMode(savedCompassMode); - OsmandMapTileView mapView = getApp().getOsmandMap().getMapView(); - mapView.setElevationAngle(prevElevationAngle); if (routingHelper.isRoutePlanningMode()) { app.stopNavigation(); } @@ -177,6 +178,24 @@ public void onStart(@NonNull LifecycleOwner owner) { recenterMap(); } + @Override + public void onResume(@NonNull LifecycleOwner owner) { + if (getApp().getRoutingHelper().isRouteCalculated()) { + new Handler(Looper.getMainLooper()).postDelayed(() -> { + zoomMapToRoute(); + }, 500); + zoomMapToRoute(); + } + } + + @Override + public void onStop(@NonNull LifecycleOwner owner) { + getApp().getSettings().setCompassMode(savedCompassMode); + OsmandMapTileView mapView = getApp().getOsmandMap().getMapView(); + mapView.setElevationAngle(prevElevationAngle); + mapView.setRotate(prevRotationAngle, true); + } + @NonNull @Override public Template onGetTemplate() { @@ -221,13 +240,17 @@ private void onNavigate() { @Override public void newRouteIsCalculated(boolean newRoute, ValueHolder showToast) { + zoomMapToRoute(); + updateRoute(newRoute); + } + + private void zoomMapToRoute() { RoutingHelper rh = getApp().getRoutingHelper(); QuadRect mapRect = RoutingHelperUtils.getRouteRect(getApp(), rh.getRoute()); if (mapRect != null) { LOG.info("ZOOM Route " + mapRect); adjustMapToRect(getApp().getMapViewTrackingUtilities().getDefaultLocation(), mapRect); } - updateRoute(newRoute); } @Override From 6180ccc8ac3282eee9848eed9e6e0e67278fde52 Mon Sep 17 00:00:00 2001 From: Corwin-Kh Date: Thu, 14 Nov 2024 15:02:21 +0200 Subject: [PATCH 06/10] Removed dublicate code --- OsmAnd/src/net/osmand/plus/auto/screens/RoutePreviewScreen.java | 1 - 1 file changed, 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/auto/screens/RoutePreviewScreen.java b/OsmAnd/src/net/osmand/plus/auto/screens/RoutePreviewScreen.java index 0c14cb28fcd..ed4578d1e4b 100644 --- a/OsmAnd/src/net/osmand/plus/auto/screens/RoutePreviewScreen.java +++ b/OsmAnd/src/net/osmand/plus/auto/screens/RoutePreviewScreen.java @@ -186,7 +186,6 @@ public void onResume(@NonNull LifecycleOwner owner) { new Handler(Looper.getMainLooper()).postDelayed(() -> { zoomMapToRoute(); }, 500); - zoomMapToRoute(); } } From 362b0bb48b38892c46319da21c04af2a531e8343 Mon Sep 17 00:00:00 2001 From: Corwin-Kh Date: Thu, 14 Nov 2024 16:00:27 +0200 Subject: [PATCH 07/10] Fixes after review --- .../plus/auto/screens/RoutePreviewScreen.java | 25 +++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/auto/screens/RoutePreviewScreen.java b/OsmAnd/src/net/osmand/plus/auto/screens/RoutePreviewScreen.java index ed4578d1e4b..d1aafd12fae 100644 --- a/OsmAnd/src/net/osmand/plus/auto/screens/RoutePreviewScreen.java +++ b/OsmAnd/src/net/osmand/plus/auto/screens/RoutePreviewScreen.java @@ -23,6 +23,7 @@ import net.osmand.PlatformUtil; +import net.osmand.plus.auto.NavigationSession; import net.osmand.plus.auto.TripUtils; import net.osmand.plus.shared.SharedUtil; import net.osmand.StateChangedListener; @@ -70,6 +71,7 @@ public final class RoutePreviewScreen extends BaseAndroidAutoScreen implements I private CompassMode savedCompassMode = CompassMode.NORTH_IS_UP; private float prevElevationAngle = 90; private float prevRotationAngle = 0; + private boolean prevMapLinkedToLocation = false; private final StateChangedListener stateChangedListener = new StateChangedListener() { @@ -151,12 +153,14 @@ private void updateRoute(boolean newRoute) { public void onCreate(@NonNull LifecycleOwner owner) { getApp().getRoutingHelper().addListener(this); getApp().getTargetPointsHelper().addListener(stateChangedListener); + prevMapLinkedToLocation = getApp().getMapViewTrackingUtilities().isMapLinkedToLocation(); OsmandMapTileView mapView = getApp().getOsmandMap().getMapView(); savedCompassMode = getApp().getSettings().getCompassMode(); prevRotationAngle = mapView.getRotate(); getApp().getSettings().setCompassMode(CompassMode.NORTH_IS_UP); prevElevationAngle = mapView.normalizeElevationAngle(mapView.getElevationAngle()); - if (getApp().getRoutingHelper().isRouteCalculated()) { + NavigationSession navigationSession = getSession(); + if (getApp().getRoutingHelper().isRouteCalculated() && navigationSession != null && navigationSession.isCarNavigationActive()) { updateRoute(true); } else { prepareRoute(); @@ -183,18 +187,25 @@ public void onStart(@NonNull LifecycleOwner owner) { @Override public void onResume(@NonNull LifecycleOwner owner) { if (getApp().getRoutingHelper().isRouteCalculated()) { - new Handler(Looper.getMainLooper()).postDelayed(() -> { - zoomMapToRoute(); - }, 500); + zoomMapToRoute(); } } @Override public void onStop(@NonNull LifecycleOwner owner) { - getApp().getSettings().setCompassMode(savedCompassMode); + if(getApp().getSettings().getCompassMode() != savedCompassMode) { + getApp().getSettings().setCompassMode(savedCompassMode); + } OsmandMapTileView mapView = getApp().getOsmandMap().getMapView(); - mapView.setElevationAngle(prevElevationAngle); - mapView.setRotate(prevRotationAngle, true); + if(mapView.getElevationAngle() != prevElevationAngle) { + mapView.setElevationAngle(prevElevationAngle); + } + if(mapView.getRotate() != prevRotationAngle) { + mapView.setRotate(prevRotationAngle, true); + } + if(prevMapLinkedToLocation != getApp().getMapViewTrackingUtilities().isMapLinkedToLocation()) { + getApp().getMapViewTrackingUtilities().setMapLinkedToLocation(prevMapLinkedToLocation); + } } @NonNull From 1f205edf0587e18f70f646d178213194ff8a4ed6 Mon Sep 17 00:00:00 2001 From: vshcherb Date: Thu, 14 Nov 2024 19:58:37 +0100 Subject: [PATCH 08/10] Fix android auto --- .../osmand/plus/auto/NavigationSession.java | 4 +-- .../auto/screens/BaseAndroidAutoScreen.kt | 2 +- .../plus/auto/screens/RoutePreviewScreen.java | 34 ++++++++++--------- 3 files changed, 21 insertions(+), 19 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/auto/NavigationSession.java b/OsmAnd/src/net/osmand/plus/auto/NavigationSession.java index 52f94ae2116..3a143d81c5f 100644 --- a/OsmAnd/src/net/osmand/plus/auto/NavigationSession.java +++ b/OsmAnd/src/net/osmand/plus/auto/NavigationSession.java @@ -368,7 +368,7 @@ private void processNavigationIntent(@NonNull Uri uri) { } else { result.localeName = label; } - screenManager.pushForResult(new RoutePreviewScreen(context, settingsAction, result), (obj) -> { + screenManager.pushForResult(new RoutePreviewScreen(context, settingsAction, result, true), (obj) -> { if (obj != null) { getApp().getOsmandMap().getMapLayers().getMapActionsHelper().startNavigation(); if (hasStarted()) { @@ -495,7 +495,7 @@ private void showRoutePreview() { } screenManager.popToRoot(); - screenManager.pushForResult(new RoutePreviewScreen(context, settingsAction, result), (obj) -> { + screenManager.pushForResult(new RoutePreviewScreen(context, settingsAction, result, false), (obj) -> { if (obj != null) { app.getOsmandMap().getMapLayers().getMapActionsHelper().startNavigation(); if (hasStarted()) { diff --git a/OsmAnd/src/net/osmand/plus/auto/screens/BaseAndroidAutoScreen.kt b/OsmAnd/src/net/osmand/plus/auto/screens/BaseAndroidAutoScreen.kt index 544345c09b4..42ba4ea2ece 100644 --- a/OsmAnd/src/net/osmand/plus/auto/screens/BaseAndroidAutoScreen.kt +++ b/OsmAnd/src/net/osmand/plus/auto/screens/BaseAndroidAutoScreen.kt @@ -47,7 +47,7 @@ abstract class BaseAndroidAutoScreen(carContext: CarContext) : Screen(carContext result: SearchResult ) { screenManager.pushForResult( - RoutePreviewScreen(carContext, settingsAction, result) + RoutePreviewScreen(carContext, settingsAction, result, true) ) { obj: Any? -> obj?.let { onSearchResultSelected(result) diff --git a/OsmAnd/src/net/osmand/plus/auto/screens/RoutePreviewScreen.java b/OsmAnd/src/net/osmand/plus/auto/screens/RoutePreviewScreen.java index d1aafd12fae..0b0d7f1a1f4 100644 --- a/OsmAnd/src/net/osmand/plus/auto/screens/RoutePreviewScreen.java +++ b/OsmAnd/src/net/osmand/plus/auto/screens/RoutePreviewScreen.java @@ -71,8 +71,12 @@ public final class RoutePreviewScreen extends BaseAndroidAutoScreen implements I private CompassMode savedCompassMode = CompassMode.NORTH_IS_UP; private float prevElevationAngle = 90; private float prevRotationAngle = 0; + private int prevZoom = 15; private boolean prevMapLinkedToLocation = false; + private boolean calculateRoute = false; + + private boolean calculating; private final StateChangedListener stateChangedListener = new StateChangedListener() { @Override @@ -86,16 +90,15 @@ public void stateChanged(Void change) { } }; - private boolean calculating; public RoutePreviewScreen(@NonNull CarContext carContext, @NonNull Action settingsAction, - @NonNull SearchResult searchResult) { + @NonNull SearchResult searchResult, boolean calculateRoute) { super(carContext); this.settingsAction = settingsAction; this.searchResult = searchResult; - + this.calculateRoute = calculateRoute; getLifecycle().addObserver(this); - calculating = true; + calculating = calculateRoute; } private void prepareRoute() { @@ -144,7 +147,7 @@ private void updateRoute(boolean newRoute) { String title = Algorithms.isEmpty(name) ? typeName : name; routeRows.add(new Row.Builder().setTitle(title).addText(description).build()); this.routeRows = routeRows; - calculating = false; + calculating = app.getRoutingHelper().isRouteBeingCalculated(); invalidate(); } } @@ -156,14 +159,15 @@ public void onCreate(@NonNull LifecycleOwner owner) { prevMapLinkedToLocation = getApp().getMapViewTrackingUtilities().isMapLinkedToLocation(); OsmandMapTileView mapView = getApp().getOsmandMap().getMapView(); savedCompassMode = getApp().getSettings().getCompassMode(); + prevZoom = mapView.getBaseZoom(); prevRotationAngle = mapView.getRotate(); getApp().getSettings().setCompassMode(CompassMode.NORTH_IS_UP); prevElevationAngle = mapView.normalizeElevationAngle(mapView.getElevationAngle()); NavigationSession navigationSession = getSession(); - if (getApp().getRoutingHelper().isRouteCalculated() && navigationSession != null && navigationSession.isCarNavigationActive()) { - updateRoute(true); - } else { + if (calculateRoute) { prepareRoute(); + } else { + updateRoute(true); } } @@ -197,13 +201,16 @@ public void onStop(@NonNull LifecycleOwner owner) { getApp().getSettings().setCompassMode(savedCompassMode); } OsmandMapTileView mapView = getApp().getOsmandMap().getMapView(); - if(mapView.getElevationAngle() != prevElevationAngle) { + if (mapView.getElevationAngle() != prevElevationAngle) { mapView.setElevationAngle(prevElevationAngle); } - if(mapView.getRotate() != prevRotationAngle) { + if (mapView.getRotate() != prevRotationAngle) { mapView.setRotate(prevRotationAngle, true); } - if(prevMapLinkedToLocation != getApp().getMapViewTrackingUtilities().isMapLinkedToLocation()) { + if (mapView.getZoom() != prevZoom) { + mapView.setIntZoom(prevZoom); + } + if (prevMapLinkedToLocation != getApp().getMapViewTrackingUtilities().isMapLinkedToLocation()) { getApp().getMapViewTrackingUtilities().setMapLinkedToLocation(prevMapLinkedToLocation); } } @@ -275,11 +282,6 @@ public void routeWasCancelled() { public void routeWasFinished() { } - public void tryToStartNavigation() { - if (!calculating) { - onNavigate(); - } - } @Override protected void adjustMapToRect(@NonNull LatLon location, @NonNull QuadRect mapRect) { From 3337036c79f765026deaaf6c135d7c38fb9da8a6 Mon Sep 17 00:00:00 2001 From: Corwin-Kh Date: Fri, 15 Nov 2024 03:26:11 +0200 Subject: [PATCH 09/10] UpdateMapPosition after fit mpa to route --- .../net/osmand/plus/auto/screens/RoutePreviewScreen.java | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/auto/screens/RoutePreviewScreen.java b/OsmAnd/src/net/osmand/plus/auto/screens/RoutePreviewScreen.java index 0b0d7f1a1f4..53f8f6ca0a9 100644 --- a/OsmAnd/src/net/osmand/plus/auto/screens/RoutePreviewScreen.java +++ b/OsmAnd/src/net/osmand/plus/auto/screens/RoutePreviewScreen.java @@ -2,8 +2,6 @@ import static net.osmand.search.core.ObjectType.GPX_TRACK; -import android.os.Handler; -import android.os.Looper; import android.text.SpannableString; import androidx.annotation.NonNull; @@ -37,7 +35,6 @@ import net.osmand.plus.routing.RoutingHelperUtils; import net.osmand.plus.search.listitems.QuickSearchListItem; import net.osmand.plus.settings.enums.CompassMode; -import net.osmand.plus.shared.SharedUtil; import net.osmand.plus.track.data.GPXInfo; import net.osmand.plus.track.helpers.GpxFileLoaderTask; import net.osmand.plus.track.helpers.SelectedGpxFile; @@ -98,7 +95,6 @@ public RoutePreviewScreen(@NonNull CarContext carContext, @NonNull Action settin this.searchResult = searchResult; this.calculateRoute = calculateRoute; getLifecycle().addObserver(this); - calculating = calculateRoute; } private void prepareRoute() { @@ -226,7 +222,7 @@ public Template onGetTemplate() { listBuilder.addItem(row); } RoutePreviewNavigationTemplate.Builder builder = new RoutePreviewNavigationTemplate.Builder(); - if (calculating) { + if (getApp().getRoutingHelper().isRouteBeingCalculated()) { builder.setLoading(true); } else { builder.setLoading(false); @@ -282,7 +278,6 @@ public void routeWasCancelled() { public void routeWasFinished() { } - @Override protected void adjustMapToRect(@NonNull LatLon location, @NonNull QuadRect mapRect) { OsmandMapTileView mapView = getApp().getOsmandMap().getMapView(); @@ -290,5 +285,6 @@ protected void adjustMapToRect(@NonNull LatLon location, @NonNull QuadRect mapRe getApp().getMapViewTrackingUtilities().setMapLinkedToLocation(false); mapView.setRotate(0f, true); super.adjustMapToRect(location, mapRect); + getApp().getMapViewTrackingUtilities().getMapDisplayPositionManager().updateMapDisplayPosition(); } } From 254766315e06da55efeacf108db9540a864a1ff4 Mon Sep 17 00:00:00 2001 From: Corwin-Kh Date: Fri, 15 Nov 2024 17:23:43 +0200 Subject: [PATCH 10/10] fix start navigation from history --- .../osmand/plus/auto/screens/BaseAndroidAutoScreen.kt | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/auto/screens/BaseAndroidAutoScreen.kt b/OsmAnd/src/net/osmand/plus/auto/screens/BaseAndroidAutoScreen.kt index 63b17a67fa9..68edb601a8f 100644 --- a/OsmAnd/src/net/osmand/plus/auto/screens/BaseAndroidAutoScreen.kt +++ b/OsmAnd/src/net/osmand/plus/auto/screens/BaseAndroidAutoScreen.kt @@ -51,7 +51,6 @@ abstract class BaseAndroidAutoScreen(carContext: CarContext) : Screen(carContext RoutePreviewScreen(carContext, settingsAction, result, true) ) { obj: Any? -> obj?.let { - onSearchResultSelected(result) startNavigation() finish() } @@ -64,9 +63,7 @@ abstract class BaseAndroidAutoScreen(carContext: CarContext) : Screen(carContext private fun startNavigation() { app.osmandMap.mapLayers.mapActionsHelper.startNavigation() val session = app.carNavigationSession - if (session != null && session.hasStarted()) { - session.startNavigation() - } + session?.startNavigation() } protected fun createSearchAction() = Action.Builder() @@ -99,9 +96,10 @@ abstract class BaseAndroidAutoScreen(carContext: CarContext) : Screen(carContext if (!mapRect.hasInitialState()) { val mapView = app.osmandMap.mapView val tb = mapView.rotatedTileBox - tb.setCenterLocation(tb.centerPixelX.toFloat() / tb.pixWidth, 0.5f ) + tb.setCenterLocation(tb.centerPixelX.toFloat() / tb.pixWidth, 0.5f) tb.rotate = 0f; - mapView.fitRectToMap(tb, + mapView.fitRectToMap( + tb, mapRect.left, mapRect.right, mapRect.top, mapRect.bottom, 0, 0, true, true )