Merge branch 'master' into fix_67
This commit is contained in:
commit
2a672eba84
8 changed files with 209 additions and 86 deletions
|
@ -1759,7 +1759,7 @@
|
||||||
<string name="poi_fuel_91ul">Топливо 91UL</string>
|
<string name="poi_fuel_91ul">Топливо 91UL</string>
|
||||||
<string name="poi_fuel_100ll">Топливо 100LL</string>
|
<string name="poi_fuel_100ll">Топливо 100LL</string>
|
||||||
<string name="poi_fuel_jeta1">Топливо Jet A-1</string>
|
<string name="poi_fuel_jeta1">Топливо Jet A-1</string>
|
||||||
<string name="poi_fuel_adblue">Топливо AdBlue</string>
|
<string name="poi_fuel_adblue">Дизельная выхлопная жидкость</string>
|
||||||
<string name="poi_fuel_wood">Топливо: дрова</string>
|
<string name="poi_fuel_wood">Топливо: дрова</string>
|
||||||
<string name="poi_fuel_charcoal">Топливо: древесный уголь</string>
|
<string name="poi_fuel_charcoal">Топливо: древесный уголь</string>
|
||||||
<string name="poi_fuel_coal">Топливо: каменный уголь</string>
|
<string name="poi_fuel_coal">Топливо: каменный уголь</string>
|
||||||
|
|
|
@ -671,17 +671,22 @@ public class OsmandAidlApi {
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
MapActivity mapActivity = mapActivityRef.get();
|
MapActivity mapActivity = mapActivityRef.get();
|
||||||
if (mapActivity != null) {
|
if (mapActivity != null) {
|
||||||
|
GPXFile gpx = loadGpxFileFromIntent(mapActivity, intent);
|
||||||
|
if (gpx != null) {
|
||||||
boolean force = intent.getBooleanExtra(AIDL_FORCE, false);
|
boolean force = intent.getBooleanExtra(AIDL_FORCE, false);
|
||||||
|
ExternalApiHelper.saveAndNavigateGpx(mapActivity, gpx, force);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private GPXFile loadGpxFileFromIntent(@NonNull MapActivity mapActivity, @NonNull Intent intent) {
|
||||||
GPXFile gpx = null;
|
GPXFile gpx = null;
|
||||||
if (intent.getStringExtra(AIDL_DATA) != null) {
|
|
||||||
String gpxStr = intent.getStringExtra(AIDL_DATA);
|
String gpxStr = intent.getStringExtra(AIDL_DATA);
|
||||||
if (!Algorithms.isEmpty(gpxStr)) {
|
if (!Algorithms.isEmpty(gpxStr)) {
|
||||||
gpx = GPXUtilities.loadGPXFile(new ByteArrayInputStream(gpxStr.getBytes()));
|
gpx = GPXUtilities.loadGPXFile(new ByteArrayInputStream(gpxStr.getBytes()));
|
||||||
}
|
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
|
||||||
} else if (intent.getParcelableExtra(AIDL_URI) != null) {
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
|
|
||||||
Uri gpxUri = intent.getParcelableExtra(AIDL_URI);
|
Uri gpxUri = intent.getParcelableExtra(AIDL_URI);
|
||||||
|
if (gpxUri != null) {
|
||||||
ParcelFileDescriptor gpxParcelDescriptor = null;
|
ParcelFileDescriptor gpxParcelDescriptor = null;
|
||||||
try {
|
try {
|
||||||
gpxParcelDescriptor = mapActivity.getContentResolver().openFileDescriptor(gpxUri, "r");
|
gpxParcelDescriptor = mapActivity.getContentResolver().openFileDescriptor(gpxUri, "r");
|
||||||
|
@ -694,27 +699,7 @@ public class OsmandAidlApi {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return gpx;
|
||||||
if (gpx != null) {
|
|
||||||
final RoutingHelper routingHelper = app.getRoutingHelper();
|
|
||||||
if (routingHelper.isFollowingMode() && !force) {
|
|
||||||
final GPXFile gpxFile = gpx;
|
|
||||||
AlertDialog dlg = mapActivity.getMapActions().stopNavigationActionConfirm();
|
|
||||||
dlg.setOnDismissListener(new DialogInterface.OnDismissListener() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDismiss(DialogInterface dialog) {
|
|
||||||
MapActivity mapActivity = mapActivityRef.get();
|
|
||||||
if (mapActivity != null && !routingHelper.isFollowingMode()) {
|
|
||||||
ExternalApiHelper.startNavigation(mapActivity, gpxFile);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
ExternalApiHelper.startNavigation(mapActivity, gpx);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
registerReceiver(navigateGpxReceiver, mapActivity, AIDL_NAVIGATE_GPX);
|
registerReceiver(navigateGpxReceiver, mapActivity, AIDL_NAVIGATE_GPX);
|
||||||
|
|
|
@ -30,15 +30,10 @@ import androidx.core.content.ContextCompat;
|
||||||
|
|
||||||
import com.google.android.material.slider.Slider;
|
import com.google.android.material.slider.Slider;
|
||||||
|
|
||||||
import net.osmand.plus.settings.backend.ApplicationMode;
|
|
||||||
import net.osmand.plus.ContextMenuAdapter;
|
import net.osmand.plus.ContextMenuAdapter;
|
||||||
import net.osmand.plus.ContextMenuItem;
|
import net.osmand.plus.ContextMenuItem;
|
||||||
import net.osmand.plus.OsmAndFormatter;
|
import net.osmand.plus.OsmAndFormatter;
|
||||||
import net.osmand.plus.OsmandApplication;
|
import net.osmand.plus.OsmandApplication;
|
||||||
import net.osmand.plus.settings.backend.OsmandSettings;
|
|
||||||
import net.osmand.plus.settings.backend.OsmandSettings.AutoZoomMap;
|
|
||||||
import net.osmand.plus.settings.backend.OsmandSettings.OsmandPreference;
|
|
||||||
import net.osmand.plus.settings.backend.OsmandSettings.SpeedConstants;
|
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
import net.osmand.plus.UiUtilities;
|
import net.osmand.plus.UiUtilities;
|
||||||
import net.osmand.plus.Version;
|
import net.osmand.plus.Version;
|
||||||
|
@ -48,6 +43,11 @@ import net.osmand.plus.helpers.FileNameTranslationHelper;
|
||||||
import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper;
|
import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper;
|
||||||
import net.osmand.plus.routing.RouteProvider.RouteService;
|
import net.osmand.plus.routing.RouteProvider.RouteService;
|
||||||
import net.osmand.plus.routing.RoutingHelper;
|
import net.osmand.plus.routing.RoutingHelper;
|
||||||
|
import net.osmand.plus.settings.backend.ApplicationMode;
|
||||||
|
import net.osmand.plus.settings.backend.OsmandSettings;
|
||||||
|
import net.osmand.plus.settings.backend.OsmandSettings.AutoZoomMap;
|
||||||
|
import net.osmand.plus.settings.backend.OsmandSettings.OsmandPreference;
|
||||||
|
import net.osmand.plus.settings.backend.OsmandSettings.SpeedConstants;
|
||||||
import net.osmand.plus.voice.CommandPlayer;
|
import net.osmand.plus.voice.CommandPlayer;
|
||||||
import net.osmand.router.GeneralRouter;
|
import net.osmand.router.GeneralRouter;
|
||||||
import net.osmand.router.GeneralRouter.GeneralRouterProfile;
|
import net.osmand.router.GeneralRouter.GeneralRouterProfile;
|
||||||
|
@ -749,22 +749,26 @@ public class SettingsNavigationActivity extends SettingsBaseActivity {
|
||||||
|
|
||||||
float settingsMinSpeed = mode.getMinSpeed();
|
float settingsMinSpeed = mode.getMinSpeed();
|
||||||
float settingsMaxSpeed = mode.getMaxSpeed();
|
float settingsMaxSpeed = mode.getMaxSpeed();
|
||||||
|
float settingsDefaultSpeed = mode.getDefaultSpeed();
|
||||||
|
|
||||||
final int[] defaultValue = {Math.round(mode.getDefaultSpeed() * ratio[0])};
|
final int[] defaultValue = {Math.round(settingsDefaultSpeed * ratio[0])};
|
||||||
final int[] minValue = new int[1];
|
final int[] minValue = new int[1];
|
||||||
final int[] maxValue = new int[1];
|
final int[] maxValue = new int[1];
|
||||||
final int min;
|
final int min;
|
||||||
final int max;
|
final int max;
|
||||||
if (defaultSpeedOnly) {
|
if (defaultSpeedOnly) {
|
||||||
minValue[0] = Math.round(1 * ratio[0]);
|
minValue[0] = Math.round(Math.min(1, settingsDefaultSpeed) * ratio[0]);
|
||||||
maxValue[0] = Math.round(300 * ratio[0]);
|
maxValue[0] = Math.round(Math.max(300, settingsDefaultSpeed) * ratio[0]);
|
||||||
min = minValue[0];
|
min = minValue[0];
|
||||||
max = maxValue[0];
|
max = maxValue[0];
|
||||||
} else {
|
} else {
|
||||||
minValue[0] = Math.round((settingsMinSpeed > 0 ? settingsMinSpeed : router.getMinSpeed()) * ratio[0]);
|
float minSpeedValue = settingsMinSpeed > 0 ? settingsMinSpeed : router.getMinSpeed();
|
||||||
maxValue[0] = Math.round((settingsMaxSpeed > 0 ? settingsMaxSpeed : router.getMaxSpeed()) * ratio[0]);
|
float maxSpeedValue = settingsMaxSpeed > 0 ? settingsMaxSpeed : router.getMaxSpeed();
|
||||||
min = Math.round(router.getMinSpeed() * ratio[0] / 2f);
|
minValue[0] = Math.round(Math.min(minSpeedValue, settingsDefaultSpeed) * ratio[0]);
|
||||||
max = Math.round(router.getMaxSpeed() * ratio[0] * 1.5f);
|
maxValue[0] = Math.round(Math.max(maxSpeedValue, settingsDefaultSpeed) * ratio[0]);
|
||||||
|
|
||||||
|
min = Math.round(Math.min(router.getMinSpeed(), settingsDefaultSpeed) * ratio[0] / 2f);
|
||||||
|
max = Math.round(Math.max(router.getMaxSpeed(), settingsDefaultSpeed) * ratio[0] * 1.5f);
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean nightMode = !app.getSettings().isLightContentForMode(mode);
|
boolean nightMode = !app.getSettings().isLightContentForMode(mode);
|
||||||
|
|
|
@ -5,6 +5,7 @@ import android.app.ProgressDialog;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
import android.os.AsyncTask;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.ParcelFileDescriptor;
|
import android.os.ParcelFileDescriptor;
|
||||||
|
|
||||||
|
@ -15,6 +16,7 @@ import androidx.appcompat.app.AlertDialog;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.reflect.TypeToken;
|
import com.google.gson.reflect.TypeToken;
|
||||||
|
|
||||||
|
import net.osmand.AndroidUtils;
|
||||||
import net.osmand.GPXUtilities;
|
import net.osmand.GPXUtilities;
|
||||||
import net.osmand.GPXUtilities.GPXFile;
|
import net.osmand.GPXUtilities.GPXFile;
|
||||||
import net.osmand.IndexConstants;
|
import net.osmand.IndexConstants;
|
||||||
|
@ -26,8 +28,9 @@ import net.osmand.aidl.search.SearchParams;
|
||||||
import net.osmand.data.FavouritePoint;
|
import net.osmand.data.FavouritePoint;
|
||||||
import net.osmand.data.LatLon;
|
import net.osmand.data.LatLon;
|
||||||
import net.osmand.data.PointDescription;
|
import net.osmand.data.PointDescription;
|
||||||
import net.osmand.plus.settings.backend.ApplicationMode;
|
|
||||||
import net.osmand.plus.FavouritesDbHelper;
|
import net.osmand.plus.FavouritesDbHelper;
|
||||||
|
import net.osmand.plus.GpxSelectionHelper;
|
||||||
|
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
|
||||||
import net.osmand.plus.MapMarkersHelper;
|
import net.osmand.plus.MapMarkersHelper;
|
||||||
import net.osmand.plus.MapMarkersHelper.MapMarker;
|
import net.osmand.plus.MapMarkersHelper.MapMarker;
|
||||||
import net.osmand.plus.OsmandApplication;
|
import net.osmand.plus.OsmandApplication;
|
||||||
|
@ -45,6 +48,9 @@ import net.osmand.plus.routing.RouteCalculationResult.NextDirectionInfo;
|
||||||
import net.osmand.plus.routing.RouteDirectionInfo;
|
import net.osmand.plus.routing.RouteDirectionInfo;
|
||||||
import net.osmand.plus.routing.RoutingHelper;
|
import net.osmand.plus.routing.RoutingHelper;
|
||||||
import net.osmand.plus.search.listitems.QuickSearchListItem;
|
import net.osmand.plus.search.listitems.QuickSearchListItem;
|
||||||
|
import net.osmand.plus.settings.backend.ApplicationMode;
|
||||||
|
import net.osmand.plus.track.SaveGpxAsyncTask;
|
||||||
|
import net.osmand.plus.track.SaveGpxAsyncTask.SaveGpxListener;
|
||||||
import net.osmand.router.TurnType;
|
import net.osmand.router.TurnType;
|
||||||
import net.osmand.search.SearchUICore;
|
import net.osmand.search.SearchUICore;
|
||||||
import net.osmand.search.core.ObjectType;
|
import net.osmand.search.core.ObjectType;
|
||||||
|
@ -202,7 +208,6 @@ public class ExternalApiHelper {
|
||||||
if (API_CMD_SHOW_GPX.equals(cmd) || API_CMD_NAVIGATE_GPX.equals(cmd)) {
|
if (API_CMD_SHOW_GPX.equals(cmd) || API_CMD_NAVIGATE_GPX.equals(cmd)) {
|
||||||
boolean navigate = API_CMD_NAVIGATE_GPX.equals(cmd);
|
boolean navigate = API_CMD_NAVIGATE_GPX.equals(cmd);
|
||||||
String path = uri.getQueryParameter(PARAM_PATH);
|
String path = uri.getQueryParameter(PARAM_PATH);
|
||||||
boolean force = uri.getBooleanQueryParameter(PARAM_FORCE, false);
|
|
||||||
|
|
||||||
GPXFile gpx = null;
|
GPXFile gpx = null;
|
||||||
if (path != null) {
|
if (path != null) {
|
||||||
|
@ -240,22 +245,8 @@ public class ExternalApiHelper {
|
||||||
|
|
||||||
if (gpx != null) {
|
if (gpx != null) {
|
||||||
if (navigate) {
|
if (navigate) {
|
||||||
final RoutingHelper routingHelper = app.getRoutingHelper();
|
boolean force = uri.getBooleanQueryParameter(PARAM_FORCE, false);
|
||||||
if (routingHelper.isFollowingMode() && !force) {
|
saveAndNavigateGpx(mapActivity, gpx, force);
|
||||||
final GPXFile gpxFile = gpx;
|
|
||||||
AlertDialog dlg = mapActivity.getMapActions().stopNavigationActionConfirm();
|
|
||||||
dlg.setOnDismissListener(new DialogInterface.OnDismissListener() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDismiss(DialogInterface dialog) {
|
|
||||||
if (!routingHelper.isFollowingMode()) {
|
|
||||||
startNavigation(mapActivity, gpxFile);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
startNavigation(mapActivity, gpx);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
app.getSelectedGpxHelper().setGpxFileToDisplay(gpx);
|
app.getSelectedGpxHelper().setGpxFileToDisplay(gpx);
|
||||||
}
|
}
|
||||||
|
@ -651,6 +642,60 @@ public class ExternalApiHelper {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void saveAndNavigateGpx(MapActivity mapActivity, final GPXFile gpxFile, final boolean force) {
|
||||||
|
final WeakReference<MapActivity> mapActivityRef = new WeakReference<>(mapActivity);
|
||||||
|
|
||||||
|
if (Algorithms.isEmpty(gpxFile.path)) {
|
||||||
|
OsmandApplication app = mapActivity.getMyApplication();
|
||||||
|
String destFileName = "route" + IndexConstants.GPX_FILE_EXT;
|
||||||
|
File destDir = app.getAppPath(IndexConstants.GPX_IMPORT_DIR);
|
||||||
|
File destFile = app.getAppPath(IndexConstants.GPX_IMPORT_DIR + destFileName);
|
||||||
|
while (destFile.exists()) {
|
||||||
|
destFileName = AndroidUtils.createNewFileName(destFileName);
|
||||||
|
destFile = new File(destDir, destFileName);
|
||||||
|
}
|
||||||
|
gpxFile.path = destFile.getAbsolutePath();
|
||||||
|
}
|
||||||
|
|
||||||
|
new SaveGpxAsyncTask(gpxFile, new SaveGpxListener() {
|
||||||
|
@Override
|
||||||
|
public void gpxSavingStarted() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void gpxSavingFinished(Exception errorMessage) {
|
||||||
|
MapActivity mapActivity = mapActivityRef.get();
|
||||||
|
if (errorMessage == null && mapActivity != null && AndroidUtils.isActivityNotDestroyed(mapActivity)) {
|
||||||
|
OsmandApplication app = mapActivity.getMyApplication();
|
||||||
|
GpxSelectionHelper helper = app.getSelectedGpxHelper();
|
||||||
|
SelectedGpxFile selectedGpx = helper.getSelectedFileByPath(gpxFile.path);
|
||||||
|
if (selectedGpx != null) {
|
||||||
|
selectedGpx.setGpxFile(gpxFile, app);
|
||||||
|
} else {
|
||||||
|
helper.selectGpxFile(gpxFile, true, false);
|
||||||
|
}
|
||||||
|
final RoutingHelper routingHelper = app.getRoutingHelper();
|
||||||
|
if (routingHelper.isFollowingMode() && !force) {
|
||||||
|
AlertDialog dlg = mapActivity.getMapActions().stopNavigationActionConfirm();
|
||||||
|
dlg.setOnDismissListener(new DialogInterface.OnDismissListener() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDismiss(DialogInterface dialog) {
|
||||||
|
MapActivity mapActivity = mapActivityRef.get();
|
||||||
|
if (mapActivity != null && !routingHelper.isFollowingMode()) {
|
||||||
|
ExternalApiHelper.startNavigation(mapActivity, gpxFile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
startNavigation(mapActivity, gpxFile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||||
|
}
|
||||||
|
|
||||||
private void updateTurnInfo(String prefix, Intent result, NextDirectionInfo ni) {
|
private void updateTurnInfo(String prefix, Intent result, NextDirectionInfo ni) {
|
||||||
result.putExtra(prefix + PARAM_NT_DISTANCE, ni.distanceTo);
|
result.putExtra(prefix + PARAM_NT_DISTANCE, ni.distanceTo);
|
||||||
result.putExtra(prefix + PARAM_NT_IMMINENT, ni.imminent);
|
result.putExtra(prefix + PARAM_NT_IMMINENT, ni.imminent);
|
||||||
|
|
|
@ -466,14 +466,16 @@ public class RoutingOptionsHelper {
|
||||||
List<LocalRoutingParameter> list = new ArrayList<LocalRoutingParameter>();
|
List<LocalRoutingParameter> list = new ArrayList<LocalRoutingParameter>();
|
||||||
RouteProvider.GPXRouteParamsBuilder rparams = routingHelper.getCurrentGPXRoute();
|
RouteProvider.GPXRouteParamsBuilder rparams = routingHelper.getCurrentGPXRoute();
|
||||||
boolean osmandRouter = am.getRouteService() == RouteProvider.RouteService.OSMAND;
|
boolean osmandRouter = am.getRouteService() == RouteProvider.RouteService.OSMAND;
|
||||||
if (rparams != null && !routingHelper.isCurrentGPXRouteV2() && osmandRouter) {
|
if (rparams != null && osmandRouter) {
|
||||||
GPXUtilities.GPXFile fl = rparams.getFile();
|
GPXUtilities.GPXFile fl = rparams.getFile();
|
||||||
if (fl.hasRtePt()) {
|
if (fl.hasRtePt()) {
|
||||||
list.add(new OtherLocalRoutingParameter(R.string.use_points_as_intermediates,
|
list.add(new OtherLocalRoutingParameter(R.string.use_points_as_intermediates,
|
||||||
app.getString(R.string.use_points_as_intermediates), rparams.isUseIntermediatePointsRTE()));
|
app.getString(R.string.use_points_as_intermediates), rparams.isUseIntermediatePointsRTE()));
|
||||||
}
|
}
|
||||||
|
if (!routingHelper.isCurrentGPXRouteV2()) {
|
||||||
list.add(new OtherLocalRoutingParameter(R.string.gpx_option_reverse_route,
|
list.add(new OtherLocalRoutingParameter(R.string.gpx_option_reverse_route,
|
||||||
app.getString(R.string.gpx_option_reverse_route), rparams.isReverse()));
|
app.getString(R.string.gpx_option_reverse_route), rparams.isReverse()));
|
||||||
|
}
|
||||||
if (!rparams.isUseIntermediatePointsRTE()) {
|
if (!rparams.isUseIntermediatePointsRTE()) {
|
||||||
list.add(new OtherLocalRoutingParameter(R.string.gpx_option_from_start_point,
|
list.add(new OtherLocalRoutingParameter(R.string.gpx_option_from_start_point,
|
||||||
app.getString(R.string.gpx_option_from_start_point), rparams.isPassWholeRoute()));
|
app.getString(R.string.gpx_option_from_start_point), rparams.isPassWholeRoute()));
|
||||||
|
|
|
@ -137,7 +137,7 @@ public class RouteCalculationResult {
|
||||||
}
|
}
|
||||||
|
|
||||||
public RouteCalculationResult(List<RouteSegmentResult> list, Location start, LatLon end, List<LatLon> intermediates,
|
public RouteCalculationResult(List<RouteSegmentResult> list, Location start, LatLon end, List<LatLon> intermediates,
|
||||||
OsmandApplication ctx, boolean leftSide, RoutingContext rctx, List<LocationPoint> waypoints, ApplicationMode mode) {
|
OsmandApplication ctx, boolean leftSide, RoutingContext rctx, List<LocationPoint> waypoints, ApplicationMode mode, boolean calculateFirstAndLastPoint) {
|
||||||
if (rctx != null) {
|
if (rctx != null) {
|
||||||
this.routingTime = rctx.routingTime;
|
this.routingTime = rctx.routingTime;
|
||||||
this.visitedSegments = rctx.getVisitedSegments();
|
this.visitedSegments = rctx.getVisitedSegments();
|
||||||
|
@ -162,7 +162,9 @@ public class RouteCalculationResult {
|
||||||
List<Location> locations = new ArrayList<Location>();
|
List<Location> locations = new ArrayList<Location>();
|
||||||
ArrayList<AlarmInfo> alarms = new ArrayList<AlarmInfo>();
|
ArrayList<AlarmInfo> alarms = new ArrayList<AlarmInfo>();
|
||||||
List<RouteSegmentResult> segments = convertVectorResult(computeDirections, locations, list, alarms, ctx);
|
List<RouteSegmentResult> segments = convertVectorResult(computeDirections, locations, list, alarms, ctx);
|
||||||
|
if (calculateFirstAndLastPoint) {
|
||||||
introduceFirstPointAndLastPoint(locations, computeDirections, segments, start, end, ctx);
|
introduceFirstPointAndLastPoint(locations, computeDirections, segments, start, end, ctx);
|
||||||
|
}
|
||||||
|
|
||||||
this.locations = Collections.unmodifiableList(locations);
|
this.locations = Collections.unmodifiableList(locations);
|
||||||
this.segments = Collections.unmodifiableList(segments);
|
this.segments = Collections.unmodifiableList(segments);
|
||||||
|
@ -300,6 +302,37 @@ public class RouteCalculationResult {
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<RouteSegmentResult> getRoute(int startIndex) {
|
||||||
|
if (segments.size() == 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
List<RouteSegmentResult> list = new ArrayList<RouteSegmentResult>();
|
||||||
|
int skippedPoints = 0;
|
||||||
|
for (int i = 1; i <= startIndex; i++) {
|
||||||
|
RouteSegmentResult seg = segments.get(i - 1);
|
||||||
|
if (seg != segments.get(i)) {
|
||||||
|
skippedPoints += Math.abs(seg.getEndPointIndex() - seg.getStartPointIndex());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
list.add(segments.get(startIndex++));
|
||||||
|
for (int i = startIndex; i < segments.size(); i++) {
|
||||||
|
if (segments.get(i - 1) != segments.get(i)) {
|
||||||
|
list.add(segments.get(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!list.isEmpty()) {
|
||||||
|
RouteSegmentResult seg = list.get(0);
|
||||||
|
if (seg.isForwardDirection()) {
|
||||||
|
int index = seg.getStartPointIndex() + startIndex - skippedPoints;
|
||||||
|
seg.setStartPointIndex(index);
|
||||||
|
} else {
|
||||||
|
int index = seg.getEndPointIndex() + startIndex - skippedPoints;
|
||||||
|
seg.setEndPointIndex(index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PREPARATION
|
* PREPARATION
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -79,6 +79,7 @@ public class RouteProvider {
|
||||||
private static final org.apache.commons.logging.Log log = PlatformUtil.getLog(RouteProvider.class);
|
private static final org.apache.commons.logging.Log log = PlatformUtil.getLog(RouteProvider.class);
|
||||||
private static final String OSMAND_ROUTER = "OsmAndRouter";
|
private static final String OSMAND_ROUTER = "OsmAndRouter";
|
||||||
private static final int MIN_DISTANCE_FOR_INSERTING_ROUTE_SEGMENT = 60;
|
private static final int MIN_DISTANCE_FOR_INSERTING_ROUTE_SEGMENT = 60;
|
||||||
|
private static final int ADDITIONAL_DISTANCE_FOR_START_POINT = 300;
|
||||||
private static final int MIN_STRAIGHT_DIST = 50000;
|
private static final int MIN_STRAIGHT_DIST = 50000;
|
||||||
|
|
||||||
public enum RouteService {
|
public enum RouteService {
|
||||||
|
@ -366,22 +367,51 @@ public class RouteProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
private RouteCalculationResult calculateGpxRoute(RouteCalculationParams routeParams) throws IOException {
|
private RouteCalculationResult calculateGpxRoute(RouteCalculationParams routeParams) throws IOException {
|
||||||
|
|
||||||
List<RouteSegmentResult> route = routeParams.gpxRoute.route;
|
|
||||||
if (!Algorithms.isEmpty(route)) {
|
|
||||||
return new RouteCalculationResult(route, routeParams.start, routeParams.end,
|
|
||||||
routeParams.intermediates, routeParams.ctx, routeParams.leftSide, null, null, routeParams.mode);
|
|
||||||
}
|
|
||||||
|
|
||||||
// get the closest point to start and to end
|
// get the closest point to start and to end
|
||||||
GPXRouteParams gpxParams = routeParams.gpxRoute;
|
GPXRouteParams gpxParams = routeParams.gpxRoute;
|
||||||
|
List<RouteSegmentResult> gpxRouteResult = routeParams.gpxRoute.route;
|
||||||
|
if (!Algorithms.isEmpty(gpxRouteResult)) {
|
||||||
|
boolean calculateOsmAndRouteParts = gpxParams.calculateOsmAndRouteParts;
|
||||||
|
if (routeParams.gpxRoute.passWholeRoute && !calculateOsmAndRouteParts) {
|
||||||
|
return new RouteCalculationResult(gpxRouteResult, routeParams.start, routeParams.end,
|
||||||
|
routeParams.intermediates, routeParams.ctx, routeParams.leftSide, null, null, routeParams.mode, true);
|
||||||
|
}
|
||||||
|
RouteCalculationResult result = new RouteCalculationResult(gpxRouteResult, routeParams.start, routeParams.end,
|
||||||
|
routeParams.intermediates, routeParams.ctx, routeParams.leftSide, null, null, routeParams.mode, false);
|
||||||
|
List<Location> gpxRouteLocations = result.getImmutableAllLocations();
|
||||||
|
int gpxNextIndex = routeParams.gpxRoute.passWholeRoute ? 0 : findStartIndexFromRoute(gpxRouteLocations, routeParams.start, calculateOsmAndRouteParts);
|
||||||
|
Location gpxNextLocation;
|
||||||
|
List<RouteSegmentResult> firstSegmentRoute = null;
|
||||||
|
List<RouteSegmentResult> gpxRoute;
|
||||||
|
if (gpxNextIndex > 0) {
|
||||||
|
gpxNextLocation = gpxRouteLocations.get(gpxNextIndex);
|
||||||
|
gpxRoute = result.getRoute(gpxNextIndex);
|
||||||
|
} else {
|
||||||
|
gpxNextLocation = gpxRouteLocations.get(0);
|
||||||
|
gpxRoute = result.getOriginalRoute();
|
||||||
|
}
|
||||||
|
if (calculateOsmAndRouteParts
|
||||||
|
&& routeParams.start != null && gpxNextLocation != null
|
||||||
|
&& gpxNextLocation.distanceTo(routeParams.start) > MIN_DISTANCE_FOR_INSERTING_ROUTE_SEGMENT) {
|
||||||
|
RouteCalculationResult firstSegmentResult = findOfflineRouteSegment(routeParams, routeParams.start, new LatLon(gpxNextLocation.getLatitude(), gpxNextLocation.getLongitude()));
|
||||||
|
firstSegmentRoute = firstSegmentResult.getOriginalRoute();
|
||||||
|
}
|
||||||
|
List<RouteSegmentResult> newGpxRoute = new ArrayList<>();
|
||||||
|
if (firstSegmentRoute != null && !firstSegmentRoute.isEmpty()) {
|
||||||
|
newGpxRoute.addAll(firstSegmentRoute);
|
||||||
|
}
|
||||||
|
newGpxRoute.addAll(gpxRoute);
|
||||||
|
return new RouteCalculationResult(newGpxRoute, routeParams.start, routeParams.end,
|
||||||
|
routeParams.intermediates, routeParams.ctx, routeParams.leftSide, null, null, routeParams.mode, true);
|
||||||
|
}
|
||||||
|
|
||||||
if(routeParams.gpxRoute.useIntermediatePointsRTE){
|
if(routeParams.gpxRoute.useIntermediatePointsRTE){
|
||||||
return calculateOsmAndRouteWithIntermediatePoints(routeParams, gpxParams.points);
|
return calculateOsmAndRouteWithIntermediatePoints(routeParams, gpxParams.points);
|
||||||
}
|
}
|
||||||
List<Location> gpxRoute ;
|
List<Location> gpxRoute ;
|
||||||
int[] startI = new int[]{0};
|
int[] startI = new int[]{0};
|
||||||
int[] endI = new int[]{gpxParams.points.size()};
|
int[] endI = new int[]{gpxParams.points.size()};
|
||||||
if(routeParams.gpxRoute.passWholeRoute) {
|
if (routeParams.gpxRoute.passWholeRoute) {
|
||||||
gpxRoute = gpxParams.points;
|
gpxRoute = gpxParams.points;
|
||||||
if (routeParams.previousToRecalculate != null && routeParams.onlyStartPointChanged) {
|
if (routeParams.previousToRecalculate != null && routeParams.onlyStartPointChanged) {
|
||||||
List<Location> routeLocations = routeParams.previousToRecalculate.getRouteLocations();
|
List<Location> routeLocations = routeParams.previousToRecalculate.getRouteLocations();
|
||||||
|
@ -389,7 +419,7 @@ public class RouteProvider {
|
||||||
gpxRoute = new ArrayList<>();
|
gpxRoute = new ArrayList<>();
|
||||||
Location trackStart = routeLocations.get(0);
|
Location trackStart = routeLocations.get(0);
|
||||||
Location realStart = routeParams.start;
|
Location realStart = routeParams.start;
|
||||||
//insert route segment from current location to next route location if user deviated from route
|
//insert gpxRouteResult segment from current location to next gpxRouteResult location if user deviated from gpxRouteResult
|
||||||
if (realStart != null && trackStart != null
|
if (realStart != null && trackStart != null
|
||||||
&& realStart.distanceTo(trackStart) > MIN_DISTANCE_FOR_INSERTING_ROUTE_SEGMENT
|
&& realStart.distanceTo(trackStart) > MIN_DISTANCE_FOR_INSERTING_ROUTE_SEGMENT
|
||||||
&& !gpxParams.calculateOsmAndRouteParts) {
|
&& !gpxParams.calculateOsmAndRouteParts) {
|
||||||
|
@ -625,6 +655,30 @@ public class RouteProvider {
|
||||||
return sublist;
|
return sublist;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int findStartIndexFromRoute(List<Location> route, Location startLoc, boolean calculateOsmAndRouteParts) {
|
||||||
|
float minDist = Integer.MAX_VALUE;
|
||||||
|
int start = 0;
|
||||||
|
if (startLoc != null) {
|
||||||
|
for (int i = 0; i < route.size(); i++) {
|
||||||
|
float d = route.get(i).distanceTo(startLoc);
|
||||||
|
if (d < minDist) {
|
||||||
|
start = i;
|
||||||
|
minDist = d;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (start > 0 && calculateOsmAndRouteParts) {
|
||||||
|
Location newStartLoc = route.get(start);
|
||||||
|
for (int i = start + 1; i < route.size(); i++) {
|
||||||
|
Location loc = route.get(i);
|
||||||
|
if (loc.distanceTo(newStartLoc) >= ADDITIONAL_DISTANCE_FOR_START_POINT) {
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return start;
|
||||||
|
}
|
||||||
|
|
||||||
protected String getString(Context ctx, int resId){
|
protected String getString(Context ctx, int resId){
|
||||||
if(ctx == null){
|
if(ctx == null){
|
||||||
return ""; //$NON-NLS-1$
|
return ""; //$NON-NLS-1$
|
||||||
|
@ -812,7 +866,7 @@ public class RouteProvider {
|
||||||
} else {
|
} else {
|
||||||
RouteCalculationResult res = new RouteCalculationResult(result, params.start, params.end,
|
RouteCalculationResult res = new RouteCalculationResult(result, params.start, params.end,
|
||||||
params.intermediates, params.ctx, params.leftSide, ctx, params.gpxRoute == null? null: params.gpxRoute.wpt,
|
params.intermediates, params.ctx, params.leftSide, ctx, params.gpxRoute == null? null: params.gpxRoute.wpt,
|
||||||
params.mode);
|
params.mode, true);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
} catch (RuntimeException e) {
|
} catch (RuntimeException e) {
|
||||||
|
|
Loading…
Reference in a new issue