Merge branch 'master' into track_appearance_fixes
This commit is contained in:
commit
ae850bde77
3 changed files with 103 additions and 69 deletions
|
@ -671,17 +671,22 @@ public class OsmandAidlApi {
|
|||
public void onReceive(Context context, Intent intent) {
|
||||
MapActivity mapActivity = mapActivityRef.get();
|
||||
if (mapActivity != null) {
|
||||
GPXFile gpx = loadGpxFileFromIntent(mapActivity, intent);
|
||||
if (gpx != null) {
|
||||
boolean force = intent.getBooleanExtra(AIDL_FORCE, false);
|
||||
ExternalApiHelper.saveAndNavigateGpx(mapActivity, gpx, force);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private GPXFile loadGpxFileFromIntent(@NonNull MapActivity mapActivity, @NonNull Intent intent) {
|
||||
GPXFile gpx = null;
|
||||
if (intent.getStringExtra(AIDL_DATA) != null) {
|
||||
String gpxStr = intent.getStringExtra(AIDL_DATA);
|
||||
if (!Algorithms.isEmpty(gpxStr)) {
|
||||
gpx = GPXUtilities.loadGPXFile(new ByteArrayInputStream(gpxStr.getBytes()));
|
||||
}
|
||||
} else if (intent.getParcelableExtra(AIDL_URI) != null) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
|
||||
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
|
||||
Uri gpxUri = intent.getParcelableExtra(AIDL_URI);
|
||||
|
||||
if (gpxUri != null) {
|
||||
ParcelFileDescriptor gpxParcelDescriptor = null;
|
||||
try {
|
||||
gpxParcelDescriptor = mapActivity.getContentResolver().openFileDescriptor(gpxUri, "r");
|
||||
|
@ -694,27 +699,7 @@ public class OsmandAidlApi {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
return gpx;
|
||||
}
|
||||
};
|
||||
registerReceiver(navigateGpxReceiver, mapActivity, AIDL_NAVIGATE_GPX);
|
||||
|
|
|
@ -30,15 +30,10 @@ import androidx.core.content.ContextCompat;
|
|||
|
||||
import com.google.android.material.slider.Slider;
|
||||
|
||||
import net.osmand.plus.settings.backend.ApplicationMode;
|
||||
import net.osmand.plus.ContextMenuAdapter;
|
||||
import net.osmand.plus.ContextMenuItem;
|
||||
import net.osmand.plus.OsmAndFormatter;
|
||||
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.UiUtilities;
|
||||
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.routing.RouteProvider.RouteService;
|
||||
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.router.GeneralRouter;
|
||||
import net.osmand.router.GeneralRouter.GeneralRouterProfile;
|
||||
|
@ -749,22 +749,26 @@ public class SettingsNavigationActivity extends SettingsBaseActivity {
|
|||
|
||||
float settingsMinSpeed = mode.getMinSpeed();
|
||||
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[] maxValue = new int[1];
|
||||
final int min;
|
||||
final int max;
|
||||
if (defaultSpeedOnly) {
|
||||
minValue[0] = Math.round(1 * ratio[0]);
|
||||
maxValue[0] = Math.round(300 * ratio[0]);
|
||||
minValue[0] = Math.round(Math.min(1, settingsDefaultSpeed) * ratio[0]);
|
||||
maxValue[0] = Math.round(Math.max(300, settingsDefaultSpeed) * ratio[0]);
|
||||
min = minValue[0];
|
||||
max = maxValue[0];
|
||||
} else {
|
||||
minValue[0] = Math.round((settingsMinSpeed > 0 ? settingsMinSpeed : router.getMinSpeed()) * ratio[0]);
|
||||
maxValue[0] = Math.round((settingsMaxSpeed > 0 ? settingsMaxSpeed : router.getMaxSpeed()) * ratio[0]);
|
||||
min = Math.round(router.getMinSpeed() * ratio[0] / 2f);
|
||||
max = Math.round(router.getMaxSpeed() * ratio[0] * 1.5f);
|
||||
float minSpeedValue = settingsMinSpeed > 0 ? settingsMinSpeed : router.getMinSpeed();
|
||||
float maxSpeedValue = settingsMaxSpeed > 0 ? settingsMaxSpeed : router.getMaxSpeed();
|
||||
minValue[0] = Math.round(Math.min(minSpeedValue, settingsDefaultSpeed) * ratio[0]);
|
||||
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);
|
||||
|
|
|
@ -5,6 +5,7 @@ import android.app.ProgressDialog;
|
|||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Build;
|
||||
import android.os.ParcelFileDescriptor;
|
||||
|
||||
|
@ -15,6 +16,7 @@ import androidx.appcompat.app.AlertDialog;
|
|||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
import net.osmand.AndroidUtils;
|
||||
import net.osmand.GPXUtilities;
|
||||
import net.osmand.GPXUtilities.GPXFile;
|
||||
import net.osmand.IndexConstants;
|
||||
|
@ -26,8 +28,9 @@ import net.osmand.aidl.search.SearchParams;
|
|||
import net.osmand.data.FavouritePoint;
|
||||
import net.osmand.data.LatLon;
|
||||
import net.osmand.data.PointDescription;
|
||||
import net.osmand.plus.settings.backend.ApplicationMode;
|
||||
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.MapMarker;
|
||||
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.RoutingHelper;
|
||||
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.search.SearchUICore;
|
||||
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)) {
|
||||
boolean navigate = API_CMD_NAVIGATE_GPX.equals(cmd);
|
||||
String path = uri.getQueryParameter(PARAM_PATH);
|
||||
boolean force = uri.getBooleanQueryParameter(PARAM_FORCE, false);
|
||||
|
||||
GPXFile gpx = null;
|
||||
if (path != null) {
|
||||
|
@ -240,22 +245,8 @@ public class ExternalApiHelper {
|
|||
|
||||
if (gpx != null) {
|
||||
if (navigate) {
|
||||
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) {
|
||||
if (!routingHelper.isFollowingMode()) {
|
||||
startNavigation(mapActivity, gpxFile);
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
startNavigation(mapActivity, gpx);
|
||||
}
|
||||
boolean force = uri.getBooleanQueryParameter(PARAM_FORCE, false);
|
||||
saveAndNavigateGpx(mapActivity, gpx, force);
|
||||
} else {
|
||||
app.getSelectedGpxHelper().setGpxFileToDisplay(gpx);
|
||||
}
|
||||
|
@ -651,6 +642,60 @@ public class ExternalApiHelper {
|
|||
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) {
|
||||
result.putExtra(prefix + PARAM_NT_DISTANCE, ni.distanceTo);
|
||||
result.putExtra(prefix + PARAM_NT_IMMINENT, ni.imminent);
|
||||
|
|
Loading…
Reference in a new issue