commit
1efe021df2
8 changed files with 182 additions and 146 deletions
|
@ -11,6 +11,7 @@
|
|||
Thx - Hardy
|
||||
|
||||
-->
|
||||
<string name="overwrite_track">Overwrite track</string>
|
||||
<string name="shared_string_done">Done</string>
|
||||
<string name="plan_route_select_track_file_for_open">Select a track file for open.</string>
|
||||
<string name="plan_route_create_new_route">Create new route</string>
|
||||
|
|
|
@ -767,8 +767,8 @@ public class SettingsNavigationActivity extends SettingsBaseActivity {
|
|||
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);
|
||||
min = Math.round(Math.min(minValue[0], router.getMinSpeed() * ratio[0] / 2f));
|
||||
max = Math.round(Math.max(maxValue[0], router.getMaxSpeed() * ratio[0] * 1.5f));
|
||||
}
|
||||
|
||||
boolean nightMode = !app.getSettings().isLightContentForMode(mode);
|
||||
|
|
|
@ -1,15 +1,19 @@
|
|||
package net.osmand.plus.mapcontextmenu.controllers;
|
||||
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import net.osmand.AndroidUtils;
|
||||
import net.osmand.GPXUtilities;
|
||||
import net.osmand.GPXUtilities.GPXFile;
|
||||
import net.osmand.GPXUtilities.WptPt;
|
||||
import net.osmand.data.LatLon;
|
||||
import net.osmand.data.PointDescription;
|
||||
import net.osmand.plus.GpxSelectionHelper;
|
||||
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
|
||||
|
@ -20,7 +24,10 @@ import net.osmand.plus.activities.TrackActivity;
|
|||
import net.osmand.plus.helpers.GpxUiHelper;
|
||||
import net.osmand.plus.mapcontextmenu.MenuController;
|
||||
import net.osmand.plus.mapcontextmenu.builders.SelectedGpxMenuBuilder;
|
||||
import net.osmand.plus.myplaces.SaveCurrentTrackTask;
|
||||
import net.osmand.plus.settings.backend.OsmandSettings;
|
||||
import net.osmand.plus.track.SaveGpxAsyncTask.SaveGpxListener;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.ref.WeakReference;
|
||||
|
@ -191,6 +198,48 @@ public class SelectedGpxMenuController extends MenuController {
|
|||
return getIcon(R.drawable.ic_action_polygom_dark, color);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void share(LatLon latLon, String title, String address) {
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
if (mapActivity != null && selectedGpxPoint != null) {
|
||||
final GPXFile gpxFile = selectedGpxPoint.getSelectedGpxFile().getGpxFile();
|
||||
if (gpxFile != null) {
|
||||
if (Algorithms.isEmpty(gpxFile.path)) {
|
||||
SaveGpxListener saveGpxListener = new SaveGpxListener() {
|
||||
@Override
|
||||
public void gpxSavingStarted() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void gpxSavingFinished(Exception errorMessage) {
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
if (mapActivity != null) {
|
||||
shareGpx(mapActivity, gpxFile.path);
|
||||
}
|
||||
}
|
||||
};
|
||||
new SaveCurrentTrackTask(mapActivity.getMyApplication(), gpxFile, saveGpxListener).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
} else {
|
||||
shareGpx(mapActivity, gpxFile.path);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
super.share(latLon, title, "");
|
||||
}
|
||||
}
|
||||
|
||||
private void shareGpx(@NonNull Context context, @NonNull String path) {
|
||||
final Uri fileUri = AndroidUtils.getUriForFile(context, new File(path));
|
||||
final Intent sendIntent = new Intent(Intent.ACTION_SEND);
|
||||
sendIntent.putExtra(Intent.EXTRA_STREAM, fileUri);
|
||||
sendIntent.setType("application/gpx+xml");
|
||||
sendIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
||||
if (AndroidUtils.isIntentSafe(context, sendIntent)) {
|
||||
context.startActivity(sendIntent);
|
||||
}
|
||||
}
|
||||
|
||||
public static class SelectedGpxPoint {
|
||||
|
||||
private final WptPt selectedPoint;
|
||||
|
|
|
@ -95,7 +95,7 @@ public class OptionsBottomSheetDialogFragment extends MenuBottomSheetDialogFragm
|
|||
|
||||
BaseBottomSheetItem saveAsNewSegmentItem = new SimpleBottomSheetItem.Builder()
|
||||
.setIcon(getContentIcon(R.drawable.ic_action_polygom_dark))
|
||||
.setTitle("Overwrite GPX")
|
||||
.setTitle(getString(R.string.overwrite_track))
|
||||
.setLayoutId(R.layout.bottom_sheet_item_simple)
|
||||
.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
|
|
|
@ -0,0 +1,70 @@
|
|||
package net.osmand.plus.myplaces;
|
||||
|
||||
import android.os.AsyncTask;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import net.osmand.GPXUtilities;
|
||||
import net.osmand.GPXUtilities.GPXFile;
|
||||
import net.osmand.IndexConstants;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.activities.SavingTrackHelper;
|
||||
import net.osmand.plus.track.SaveGpxAsyncTask.SaveGpxListener;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Map;
|
||||
|
||||
public class SaveCurrentTrackTask extends AsyncTask<Void, Void, Boolean> {
|
||||
|
||||
private final OsmandApplication app;
|
||||
private final GPXFile gpx;
|
||||
|
||||
private final SaveGpxListener saveGpxListener;
|
||||
|
||||
public SaveCurrentTrackTask(@NonNull OsmandApplication app, @NonNull GPXFile gpx, @NonNull SaveGpxListener listener) {
|
||||
this.app = app;
|
||||
this.gpx = gpx;
|
||||
saveGpxListener = listener;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPreExecute() {
|
||||
if (saveGpxListener != null) {
|
||||
saveGpxListener.gpxSavingStarted();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Boolean doInBackground(Void... params) {
|
||||
SavingTrackHelper savingTrackHelper = app.getSavingTrackHelper();
|
||||
Map<String, GPXUtilities.GPXFile> files = savingTrackHelper.collectRecordedData();
|
||||
File dir;
|
||||
boolean shouldClearPath = false;
|
||||
if (gpx.path.isEmpty()) {
|
||||
dir = app.getCacheDir();
|
||||
shouldClearPath = true;
|
||||
} else {
|
||||
dir = app.getAppCustomization().getTracksDir();
|
||||
}
|
||||
if (!dir.exists()) {
|
||||
dir.mkdir();
|
||||
}
|
||||
for (final String f : files.keySet()) {
|
||||
File fout = new File(dir, f + IndexConstants.GPX_FILE_EXT);
|
||||
GPXUtilities.writeGpxFile(fout, gpx);
|
||||
}
|
||||
return shouldClearPath;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Boolean shouldClearPath) {
|
||||
if (gpx != null) {
|
||||
if (saveGpxListener != null) {
|
||||
saveGpxListener.gpxSavingFinished(null);
|
||||
}
|
||||
if (shouldClearPath) {
|
||||
gpx.path = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,49 +0,0 @@
|
|||
package net.osmand.plus.myplaces;
|
||||
|
||||
import android.os.AsyncTask;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import net.osmand.GPXUtilities;
|
||||
import net.osmand.GPXUtilities.GPXFile;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class SaveGpxAsyncTask extends AsyncTask<Void, Void, Exception> {
|
||||
|
||||
private final GPXFile gpx;
|
||||
private final SaveGpxListener saveGpxListener;
|
||||
|
||||
public SaveGpxAsyncTask(@NonNull GPXFile gpx,
|
||||
@Nullable SaveGpxListener saveGpxListener) {
|
||||
this.gpx = gpx;
|
||||
this.saveGpxListener = saveGpxListener;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPreExecute() {
|
||||
if (saveGpxListener != null) {
|
||||
saveGpxListener.gpxSavingStarted();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Exception doInBackground(Void... params) {
|
||||
return GPXUtilities.writeGpxFile(new File(gpx.path), gpx);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Exception errorMessage) {
|
||||
if (saveGpxListener != null) {
|
||||
saveGpxListener.gpxSavingFinished(errorMessage);
|
||||
}
|
||||
}
|
||||
|
||||
public interface SaveGpxListener {
|
||||
|
||||
void gpxSavingStarted();
|
||||
|
||||
void gpxSavingFinished(Exception errorMessage);
|
||||
}
|
||||
}
|
|
@ -46,7 +46,6 @@ import net.osmand.Collator;
|
|||
import net.osmand.GPXUtilities;
|
||||
import net.osmand.GPXUtilities.GPXFile;
|
||||
import net.osmand.GPXUtilities.WptPt;
|
||||
import net.osmand.IndexConstants;
|
||||
import net.osmand.OsmAndCollator;
|
||||
import net.osmand.data.FavouritePoint;
|
||||
import net.osmand.data.LatLon;
|
||||
|
@ -59,7 +58,6 @@ import net.osmand.plus.GpxSelectionHelper.GpxDisplayItemType;
|
|||
import net.osmand.plus.MapMarkersHelper;
|
||||
import net.osmand.plus.MapMarkersHelper.MapMarkersGroup;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.settings.backend.OsmandSettings;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.UiUtilities;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
|
@ -67,10 +65,12 @@ import net.osmand.plus.activities.OsmandActionBarActivity;
|
|||
import net.osmand.plus.activities.OsmandBaseExpandableListAdapter;
|
||||
import net.osmand.plus.activities.SavingTrackHelper;
|
||||
import net.osmand.plus.activities.TrackActivity;
|
||||
import net.osmand.plus.base.PointImageDrawable;
|
||||
import net.osmand.plus.base.OsmandExpandableListFragment;
|
||||
import net.osmand.plus.base.PointImageDrawable;
|
||||
import net.osmand.plus.mapmarkers.CoordinateInputDialogFragment;
|
||||
import net.osmand.plus.myplaces.TrackBitmapDrawer.TrackBitmapDrawerListener;
|
||||
import net.osmand.plus.settings.backend.OsmandSettings;
|
||||
import net.osmand.plus.track.SaveGpxAsyncTask.SaveGpxListener;
|
||||
import net.osmand.plus.widgets.TextViewEx;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
||||
|
@ -303,10 +303,24 @@ public class TrackPointFragment extends OsmandExpandableListFragment implements
|
|||
}
|
||||
|
||||
private void shareItems() {
|
||||
GPXFile gpxFile = getGpx();
|
||||
if (gpxFile != null) {
|
||||
if (gpxFile.path.isEmpty() && getTrackActivity() != null) {
|
||||
new SaveAndShareTask(this, gpxFile).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
final GPXFile gpxFile = getGpx();
|
||||
if (gpxFile != null && getTrackActivity() != null) {
|
||||
if (Algorithms.isEmpty(gpxFile.path)) {
|
||||
SaveGpxListener saveGpxListener = new SaveGpxListener() {
|
||||
@Override
|
||||
public void gpxSavingStarted() {
|
||||
showProgressBar();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void gpxSavingFinished(Exception errorMessage) {
|
||||
if (isResumed()) {
|
||||
hideProgressBar();
|
||||
shareGpx(gpxFile.path);
|
||||
}
|
||||
}
|
||||
};
|
||||
new SaveCurrentTrackTask(app, gpxFile, saveGpxListener).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
} else {
|
||||
shareGpx(gpxFile.path);
|
||||
}
|
||||
|
@ -1236,62 +1250,6 @@ public class TrackPointFragment extends OsmandExpandableListFragment implements
|
|||
}
|
||||
}
|
||||
|
||||
public static class SaveAndShareTask extends AsyncTask<Void, Void, Boolean> {
|
||||
private final GPXFile gpx;
|
||||
private final OsmandApplication app;
|
||||
private final WeakReference<TrackPointFragment> fragmentRef;
|
||||
|
||||
SaveAndShareTask(@NonNull TrackPointFragment fragment, @NonNull GPXFile gpx) {
|
||||
this.gpx = gpx;
|
||||
fragmentRef = new WeakReference<>(fragment);
|
||||
app = fragment.getMyApplication();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPreExecute() {
|
||||
TrackPointFragment fragment = fragmentRef.get();
|
||||
if (fragment != null) {
|
||||
fragment.showProgressBar();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Boolean doInBackground(Void... params) {
|
||||
SavingTrackHelper savingTrackHelper = app.getSavingTrackHelper();
|
||||
Map<String, GPXFile> files = savingTrackHelper.collectRecordedData();
|
||||
File dir;
|
||||
boolean shouldClearPath = false;
|
||||
if (gpx.path.isEmpty()) {
|
||||
dir = app.getCacheDir();
|
||||
shouldClearPath = true;
|
||||
} else {
|
||||
dir = app.getAppCustomization().getTracksDir();
|
||||
}
|
||||
if (!dir.exists()) {
|
||||
dir.mkdir();
|
||||
}
|
||||
for (final String f : files.keySet()) {
|
||||
File fout = new File(dir, f + IndexConstants.GPX_FILE_EXT);
|
||||
GPXUtilities.writeGpxFile(fout, gpx);
|
||||
}
|
||||
return shouldClearPath;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Boolean shouldClearPath) {
|
||||
TrackPointFragment fragment = fragmentRef.get();
|
||||
if (gpx != null) {
|
||||
if (fragment != null && fragment.isResumed()) {
|
||||
fragment.hideProgressBar();
|
||||
fragment.shareGpx(gpx.path);
|
||||
}
|
||||
if (shouldClearPath) {
|
||||
gpx.path = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static class DeletePointsTask extends AsyncTask<Void, Void, Void> {
|
||||
|
||||
private OsmandApplication app;
|
||||
|
|
|
@ -32,6 +32,7 @@ import androidx.core.view.ViewPropertyAnimatorListener;
|
|||
import com.google.android.material.slider.Slider;
|
||||
|
||||
import net.osmand.AndroidUtils;
|
||||
import net.osmand.GPXUtilities.GPXFile;
|
||||
import net.osmand.Location;
|
||||
import net.osmand.core.android.MapRendererContext;
|
||||
import net.osmand.data.LatLon;
|
||||
|
@ -52,6 +53,7 @@ import net.osmand.plus.dashboard.DashboardOnMap.DashboardType;
|
|||
import net.osmand.plus.dialogs.DirectionsDialogs;
|
||||
import net.osmand.plus.helpers.AndroidUiHelper;
|
||||
import net.osmand.plus.mapcontextmenu.MapContextMenu;
|
||||
import net.osmand.plus.mapcontextmenu.controllers.SelectedGpxMenuController.SelectedGpxPoint;
|
||||
import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin;
|
||||
import net.osmand.plus.routepreparationmenu.MapRouteInfoMenu;
|
||||
import net.osmand.plus.routepreparationmenu.MapRouteInfoMenu.PointType;
|
||||
|
@ -440,7 +442,7 @@ public class MapControlsLayer extends OsmandMapLayer {
|
|||
public void navigateButton() {
|
||||
if (!OsmAndLocationProvider.isLocationPermissionAvailable(mapActivity)) {
|
||||
ActivityCompat.requestPermissions(mapActivity,
|
||||
new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
|
||||
new String[] {Manifest.permission.ACCESS_FINE_LOCATION},
|
||||
REQUEST_LOCATION_FOR_NAVIGATION_FAB_PERMISSION);
|
||||
} else {
|
||||
final MapContextMenu menu = mapActivity.getContextMenu();
|
||||
|
@ -449,43 +451,48 @@ public class MapControlsLayer extends OsmandMapLayer {
|
|||
menu.hide();
|
||||
final TargetPointsHelper targets = mapActivity.getMyApplication().getTargetPointsHelper();
|
||||
RoutingHelper routingHelper = mapActivity.getMyApplication().getRoutingHelper();
|
||||
if (routingHelper.isFollowingMode() || routingHelper.isRoutePlanningMode()) {
|
||||
DirectionsDialogs.addWaypointDialogAndLaunchMap(mapActivity, latLon.getLatitude(),
|
||||
latLon.getLongitude(), pointDescription);
|
||||
} else if (targets.getIntermediatePoints().isEmpty()) {
|
||||
startRoutePlanningWithDestination(latLon, pointDescription, targets);
|
||||
|
||||
Object object = menu.getObject();
|
||||
if (object instanceof SelectedGpxPoint && !((SelectedGpxPoint) object).getSelectedGpxFile().isShowCurrentTrack()) {
|
||||
GPXFile gpxFile = ((SelectedGpxPoint) object).getSelectedGpxFile().getGpxFile();
|
||||
mapActivity.getMapActions().enterRoutePlanningModeGivenGpx(gpxFile, null, null, true, true, MenuState.HEADER_ONLY);
|
||||
routingHelper.recalculateRouteDueToSettingsChange();
|
||||
menu.close();
|
||||
} else {
|
||||
AlertDialog.Builder bld = new AlertDialog.Builder(mapActivity);
|
||||
bld.setTitle(R.string.new_directions_point_dialog);
|
||||
final int[] defaultVls = new int[]{0};
|
||||
bld.setSingleChoiceItems(new String[]{
|
||||
mapActivity.getString(R.string.clear_intermediate_points),
|
||||
mapActivity.getString(R.string.keep_intermediate_points)
|
||||
}, 0, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
defaultVls[0] = which;
|
||||
}
|
||||
});
|
||||
bld.setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() {
|
||||
if (routingHelper.isFollowingMode() || routingHelper.isRoutePlanningMode()) {
|
||||
DirectionsDialogs.addWaypointDialogAndLaunchMap(mapActivity, latLon.getLatitude(),
|
||||
latLon.getLongitude(), pointDescription);
|
||||
} else if (targets.getIntermediatePoints().isEmpty()) {
|
||||
startRoutePlanningWithDestination(latLon, pointDescription, targets);
|
||||
menu.close();
|
||||
} else {
|
||||
AlertDialog.Builder bld = new AlertDialog.Builder(mapActivity);
|
||||
bld.setTitle(R.string.new_directions_point_dialog);
|
||||
final int[] defaultVls = new int[] {0};
|
||||
bld.setSingleChoiceItems(new String[] {
|
||||
mapActivity.getString(R.string.clear_intermediate_points),
|
||||
mapActivity.getString(R.string.keep_intermediate_points)
|
||||
}, 0, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
defaultVls[0] = which;
|
||||
}
|
||||
});
|
||||
bld.setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
if (defaultVls[0] == 0) {
|
||||
targets.removeAllWayPoints(false, true);
|
||||
targets.navigateToPoint(latLon, true, -1, pointDescription);
|
||||
mapActivity.getMapActions().enterRoutePlanningModeGivenGpx(null, null, null, true, true, MenuState.HEADER_ONLY);
|
||||
menu.close();
|
||||
} else {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
if (defaultVls[0] == 0) {
|
||||
targets.removeAllWayPoints(false, true);
|
||||
}
|
||||
targets.navigateToPoint(latLon, true, -1, pointDescription);
|
||||
mapActivity.getMapActions().enterRoutePlanningModeGivenGpx(null, null, null, true, true, MenuState.HEADER_ONLY);
|
||||
menu.close();
|
||||
}
|
||||
}
|
||||
});
|
||||
bld.setNegativeButton(R.string.shared_string_cancel, null);
|
||||
bld.show();
|
||||
});
|
||||
bld.setNegativeButton(R.string.shared_string_cancel, null);
|
||||
bld.show();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue