Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #21098 #21965

Merged
merged 3 commits into from
Feb 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions OsmAnd/src/net/osmand/data/PointDescription.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import net.osmand.plus.plugins.PluginsHelper;
import net.osmand.plus.plugins.osmedit.OsmEditingPlugin;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.utils.AndroidUtils;
import net.osmand.plus.utils.OsmAndFormatter;
import net.osmand.util.Algorithms;

Expand Down Expand Up @@ -248,11 +249,10 @@ public static Map<Integer, String> getLocationData(MapActivity ctx, double lat,
return results;
}

public static String getLocationNamePlain(Context ctx, double lat, double lon) {
OsmandSettings st = ((OsmandApplication) ctx.getApplicationContext()).getSettings();
int f = st.COORDINATES_FORMAT.get();
return OsmAndFormatter.getFormattedCoordinates(lat, lon, f);

public static String getLocationNamePlain(@NonNull Context ctx, double lat, double lon) {
OsmandApplication app = AndroidUtils.getApp(ctx);
int format = app.getSettings().COORDINATES_FORMAT.get();
return OsmAndFormatter.getFormattedCoordinates(lat, lon, format);
}

public static String getLocationOlcName(double lat, double lon) {
Expand Down
4 changes: 2 additions & 2 deletions OsmAnd/src/net/osmand/plus/OsmAndLocationProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
import net.osmand.plus.helpers.CurrentPositionHelper;
import net.osmand.plus.helpers.LocationCallback;
import net.osmand.plus.helpers.LocationServiceHelper;
import net.osmand.plus.helpers.TargetPointsHelper.TargetPoint;
import net.osmand.plus.helpers.TargetPoint;
import net.osmand.plus.plugins.PluginsHelper;
import net.osmand.plus.plugins.accessibility.NavigationInfo;
import net.osmand.plus.routing.RoutingHelper;
Expand Down Expand Up @@ -732,7 +732,7 @@ public NavigationInfo getNavigationInfo() {
}

public String getNavigationHint(TargetPoint point) {
String hint = navigationInfo.getDirectionString(point == null ? null : point.point, getHeading());
String hint = navigationInfo.getDirectionString(point == null ? null : point.getLatLon(), getHeading());
if (hint == null)
hint = app.getString(R.string.no_info);
return hint;
Expand Down
4 changes: 2 additions & 2 deletions OsmAnd/src/net/osmand/plus/activities/MapActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
import net.osmand.plus.firstusage.FirstUsageWizardFragment;
import net.osmand.plus.helpers.*;
import net.osmand.plus.helpers.LockHelper.LockUIAdapter;
import net.osmand.plus.helpers.TargetPointsHelper.TargetPoint;
import net.osmand.plus.helpers.TargetPoint;
import net.osmand.plus.importfiles.ImportHelper;
import net.osmand.plus.importfiles.ui.ImportGpxBottomSheetDialogFragment;
import net.osmand.plus.keyevent.KeyEventHelper;
Expand Down Expand Up @@ -637,7 +637,7 @@ protected void onResume() {
TargetPointsHelper targets = app.getTargetPointsHelper();
RoutingHelper routingHelper = app.getRoutingHelper();
if (routingHelper.isFollowingMode()
&& (!Algorithms.objectEquals(targets.getPointToNavigate().point, routingHelper.getFinalLocation()) || !Algorithms
&& (!Algorithms.objectEquals(targets.getPointToNavigate().getLatLon(), routingHelper.getFinalLocation()) || !Algorithms
.objectEquals(targets.getIntermediatePointsLatLonNavigation(), routingHelper.getIntermediatePoints()))) {
targets.updateRouteAndRefresh(true);
}
Expand Down
4 changes: 1 addition & 3 deletions OsmAnd/src/net/osmand/plus/auto/NavigationSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@
import android.content.res.Configuration;
import android.net.Uri;
import android.util.Log;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.car.app.CarContext;
import androidx.car.app.CarToast;
import androidx.car.app.Screen;
import androidx.car.app.ScreenManager;
import androidx.car.app.Session;
Expand Down Expand Up @@ -54,7 +52,7 @@
import net.osmand.plus.helpers.LocationServiceHelper;
import net.osmand.plus.helpers.RestoreNavigationHelper;
import net.osmand.plus.helpers.SearchHistoryHelper.HistoryEntry;
import net.osmand.plus.helpers.TargetPointsHelper.TargetPoint;
import net.osmand.plus.helpers.TargetPoint;
import net.osmand.plus.inapp.InAppPurchaseUtils;
import net.osmand.plus.routing.IRouteInformationListener;
import net.osmand.plus.routing.RoutingHelper;
Expand Down
2 changes: 1 addition & 1 deletion OsmAnd/src/net/osmand/plus/auto/TripHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.helpers.TargetPointsHelper;
import net.osmand.plus.helpers.TargetPointsHelper.TargetPoint;
import net.osmand.plus.helpers.TargetPoint;
import net.osmand.plus.routing.NextDirectionInfo;
import net.osmand.plus.routing.RoutingHelper;
import net.osmand.plus.routing.data.AnnounceTimeDistances;
Expand Down
24 changes: 17 additions & 7 deletions OsmAnd/src/net/osmand/plus/auto/screens/RoutePreviewScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@


import net.osmand.PlatformUtil;
import net.osmand.data.PointDescription;
import net.osmand.plus.auto.TripUtils;
import net.osmand.plus.helpers.TargetPoint;
import net.osmand.plus.helpers.TargetPointsHelper;
import net.osmand.plus.shared.SharedUtil;
import net.osmand.StateChangedListener;
import net.osmand.data.QuadRect;
Expand Down Expand Up @@ -122,22 +125,29 @@ private void buildRouteByGivenGpx(@NonNull GpxFile gpxFile) {

private void updateRoute(boolean newRoute) {
OsmandApplication app = getApp();
RoutingHelper rh = app.getRoutingHelper();
RoutingHelper routingHelper = app.getRoutingHelper();
TargetPointsHelper targetPointsHelper = app.getTargetPointsHelper();

Distance distance = null;
int leftTimeSec = 0;
if (newRoute && rh.isRoutePlanningMode()) {
distance = TripUtils.getDistance(app, rh.getLeftDistance());
leftTimeSec = rh.getLeftTime();
if (newRoute && routingHelper.isRoutePlanningMode()) {
distance = TripUtils.getDistance(app, routingHelper.getLeftDistance());
leftTimeSec = routingHelper.getLeftTime();
}
if (distance != null && leftTimeSec > 0) {
List<Row> routeRows = new ArrayList<>();
SpannableString description = new SpannableString(" • ");
description.setSpan(DistanceSpan.create(distance), 0, 1, 0);
description.setSpan(DurationSpan.create(leftTimeSec), 4, 5, 0);

String name = QuickSearchListItem.getName(app, searchResult);
String typeName = QuickSearchListItem.getTypeName(app, searchResult);
String title = Algorithms.isEmpty(name) ? typeName : name;
TargetPoint finish = targetPointsHelper.getPointToNavigate();
String title = finish != null ? finish.getRoutePointDescription(app) : null;

if (Algorithms.isEmpty(title)) {
String name = QuickSearchListItem.getName(app, searchResult);
String typeName = QuickSearchListItem.getTypeName(app, searchResult);
title = Algorithms.isEmpty(name) ? typeName : name;
}
routeRows.add(new Row.Builder().setTitle(title).addText(description).build());
this.routeRows = routeRows;
calculating = app.getRoutingHelper().isRouteBeingCalculated();
Expand Down
6 changes: 3 additions & 3 deletions OsmAnd/src/net/osmand/plus/auto/screens/SearchScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import net.osmand.plus.auto.SearchHelper.SearchHelperListener;
import net.osmand.plus.helpers.SearchHistoryHelper;
import net.osmand.plus.helpers.TargetPointsHelper;
import net.osmand.plus.helpers.TargetPointsHelper.TargetPoint;
import net.osmand.plus.helpers.TargetPoint;
import net.osmand.plus.mapmarkers.MapMarker;
import net.osmand.plus.poi.PoiUIFilter;
import net.osmand.plus.routing.RoutingHelper;
Expand Down Expand Up @@ -301,8 +301,8 @@ private String getPointName(TargetPoint targetPoint) {
!description.getName().equals(app.getString(R.string.no_address_found))) {
name = description.getName();
} else {
name = PointDescription.getLocationName(app, targetPoint.point.getLatitude(),
targetPoint.point.getLongitude(), true).replace('\n', ' ');
name = PointDescription.getLocationName(app, targetPoint.getLatLon().getLatitude(),
targetPoint.getLatLon().getLongitude(), true).replace('\n', ' ');
}
}
return name;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import net.osmand.plus.R;
import net.osmand.plus.dashboard.tools.DashFragmentData.DefaultShouldShow;
import net.osmand.plus.helpers.TargetPointsHelper;
import net.osmand.plus.helpers.TargetPointsHelper.TargetPoint;
import net.osmand.plus.helpers.TargetPoint;
import net.osmand.plus.utils.UiUtilities;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.dashboard.tools.DashFragmentData;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import net.osmand.plus.utils.ColorUtilities;
import net.osmand.plus.R;
import net.osmand.plus.helpers.TargetPointsHelper;
import net.osmand.plus.helpers.TargetPointsHelper.TargetPoint;
import net.osmand.plus.helpers.TargetPoint;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.base.MenuBottomSheetDialogFragment;
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import net.osmand.data.WptLocationPoint;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.helpers.TargetPointsHelper.TargetPoint;
import net.osmand.plus.render.RenderingIcons;
import net.osmand.plus.routing.AlarmInfo;
import net.osmand.plus.settings.enums.DrivingRegion;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import net.osmand.plus.shared.SharedUtil;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.helpers.TargetPointsHelper.TargetPoint;
import net.osmand.plus.measurementtool.GpxApproximationParams;
import net.osmand.plus.routing.GPXRouteParams.GPXRouteParamsBuilder;
import net.osmand.plus.routing.RoutingHelper;
Expand Down
136 changes: 136 additions & 0 deletions OsmAnd/src/net/osmand/plus/helpers/TargetPoint.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
package net.osmand.plus.helpers;

import static net.osmand.data.PointDescription.POINT_TYPE_TARGET;

import android.annotation.SuppressLint;
import android.content.Context;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import net.osmand.data.LatLon;
import net.osmand.data.LocationPoint;
import net.osmand.data.PointDescription;
import net.osmand.plus.R;
import net.osmand.util.Algorithms;

public class TargetPoint implements LocationPoint {

private final LatLon latLon;
private final PointDescription pointDescription;

public int index;
public boolean intermediate;
public boolean start;

public TargetPoint(@NonNull LatLon latLon, @Nullable PointDescription name) {
this.latLon = latLon;
this.pointDescription = name;
}

public TargetPoint(@NonNull LatLon latLon, @Nullable PointDescription name, int index) {
this.latLon = latLon;
this.pointDescription = name;
this.index = index;
this.intermediate = true;
}

@NonNull
public LatLon getLatLon() {
return latLon;
}

@Nullable
public PointDescription getOriginalPointDescription() {
return pointDescription;
}

@SuppressLint("StringFormatInvalid")
public PointDescription getPointDescription(@NonNull Context ctx) {
String name = getOnlyName();
if (intermediate) {
String type = (index + 1) + ". " + ctx.getString(R.string.intermediate_point, "");
return new PointDescription(POINT_TYPE_TARGET, type, name);
} else {
String type = ctx.getString(R.string.destination_point, "");
return new PointDescription(POINT_TYPE_TARGET, type, name);
}
}

public String getRoutePointDescription(@NonNull Context ctx) {
String name = getOnlyName();
if (!Algorithms.isEmpty(name)) {
return name.replace(':', ' ');
}
return PointDescription.getLocationNamePlain(ctx, latLon.getLatitude(), latLon.getLongitude());
}

@NonNull
public String getOnlyName() {
return pointDescription == null ? "" : pointDescription.getName();
}

public boolean isSearchingAddress(@NonNull Context ctx) {
return pointDescription != null && pointDescription.isSearchingAddress(ctx);
}

public double getLatitude() {
return latLon.getLatitude();
}

public double getLongitude() {
return latLon.getLongitude();
}

@Override
public int getColor() {
return 0;
}

@Override
public boolean isVisible() {
return false;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;

TargetPoint targetPoint = (TargetPoint) o;

if (start != targetPoint.start) return false;
if (intermediate != targetPoint.intermediate) return false;
if (index != targetPoint.index) return false;
return latLon.equals(targetPoint.latLon);

}

@Override
public int hashCode() {
int result = latLon.hashCode();
result = 31 * result + index;
result = 31 * result + (start ? 10 : 20);
result = 31 * result + (intermediate ? 100 : 200);
return result;
}

@Nullable
public static TargetPoint create(@Nullable LatLon point, @Nullable PointDescription name) {
if (point != null) {
return new TargetPoint(point, name);
}
return null;
}

@Nullable
public static TargetPoint createStartPoint(@Nullable LatLon point,
@Nullable PointDescription name) {
if (point != null) {
TargetPoint target = new TargetPoint(point, name);
target.start = true;
return target;
}
return null;
}
}
Loading
Loading