From 1f65840dd4334f2f29e16007015668773d076bf1 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Wed, 23 Sep 2020 16:29:16 +0300 Subject: [PATCH 1/5] Fix button width in plan route and divider in follow track --- OsmAnd/res/layout/fragment_measurement_tool.xml | 6 ++++-- .../plus/routepreparationmenu/FollowTrackFragment.java | 8 +++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/OsmAnd/res/layout/fragment_measurement_tool.xml b/OsmAnd/res/layout/fragment_measurement_tool.xml index fe1ba9b1d7..d4b7f7ea57 100644 --- a/OsmAnd/res/layout/fragment_measurement_tool.xml +++ b/OsmAnd/res/layout/fragment_measurement_tool.xml @@ -216,10 +216,12 @@ + android:minWidth="@dimen/measurement_tool_button_width" /> + diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/FollowTrackFragment.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/FollowTrackFragment.java index ee2bf6b38e..42ff2f94e6 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/FollowTrackFragment.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/FollowTrackFragment.java @@ -205,7 +205,6 @@ public class FollowTrackFragment extends ContextMenuScrollFragment implements Ca SelectTrackCard selectTrackCard = new SelectTrackCard(mapActivity); selectTrackCard.setListener(this); cardsContainer.addView(selectTrackCard.build(mapActivity)); - cardsContainer.addView(buildDividerView(cardsContainer, false)); ApplicationMode mode = app.getRoutingHelper().getAppMode(); @@ -213,13 +212,16 @@ public class FollowTrackFragment extends ContextMenuScrollFragment implements Ca GPXRouteParamsBuilder rparams = routingHelper.getCurrentGPXRoute(); boolean osmandRouter = mode.getRouteService() == RouteProvider.RouteService.OSMAND; if (rparams != null && osmandRouter) { - if (!gpxFile.hasRoute() || gpxFile.hasRtePt()) { + boolean showReverseCard = !gpxFile.hasRoute() || gpxFile.hasRtePt(); + if (showReverseCard) { + cardsContainer.addView(buildDividerView(cardsContainer, false)); + ReverseTrackCard reverseTrackCard = new ReverseTrackCard(mapActivity, rparams.isReverse()); reverseTrackCard.setListener(this); cardsContainer.addView(reverseTrackCard.build(mapActivity)); } if (!gpxFile.hasRtePt() && !gpxFile.hasRoute()) { - cardsContainer.addView(buildDividerView(cardsContainer, true)); + cardsContainer.addView(buildDividerView(cardsContainer, showReverseCard)); AttachTrackToRoadsCard attachTrackCard = new AttachTrackToRoadsCard(mapActivity); attachTrackCard.setListener(this); From 95af82e531b5b00083072a0682a11ca0d25bdd4d Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Wed, 23 Sep 2020 23:18:44 +0300 Subject: [PATCH 2/5] Select current navigation profile in attach roads --- .../src/main/java/net/osmand/util/Algorithms.java | 8 +++++--- OsmAnd/src/net/osmand/AndroidUtils.java | 10 ---------- OsmAnd/src/net/osmand/plus/MapMarkersHelper.java | 3 +-- .../measurementtool/GpxApproximationFragment.java | 15 ++++++++++++--- .../measurementtool/MeasurementToolFragment.java | 8 ++++++-- 5 files changed, 24 insertions(+), 20 deletions(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/util/Algorithms.java b/OsmAnd-java/src/main/java/net/osmand/util/Algorithms.java index ea2869aaa3..bff9377ec3 100644 --- a/OsmAnd-java/src/main/java/net/osmand/util/Algorithms.java +++ b/OsmAnd-java/src/main/java/net/osmand/util/Algorithms.java @@ -119,9 +119,11 @@ public class Algorithms { } public static String getFileNameWithoutExtension(String name) { - int i = name.lastIndexOf('.'); - if (i >= 0) { - name = name.substring(0, i); + if (name != null) { + int index = name.lastIndexOf('.'); + if (index != -1) { + return name.substring(0, index); + } } return name; } diff --git a/OsmAnd/src/net/osmand/AndroidUtils.java b/OsmAnd/src/net/osmand/AndroidUtils.java index 740c826ab5..0efdd133f3 100644 --- a/OsmAnd/src/net/osmand/AndroidUtils.java +++ b/OsmAnd/src/net/osmand/AndroidUtils.java @@ -153,16 +153,6 @@ public class AndroidUtils { R.color.icon_color_default_light, R.color.wikivoyage_active_dark); } - public static String trimExtension(String src) { - if (src != null) { - int index = src.lastIndexOf('.'); - if (index != -1) { - return src.substring(0, index); - } - } - return src; - } - public static String addColon(OsmandApplication app, @StringRes int stringRes) { return app.getString(R.string.ltr_or_rtl_combine_via_colon, app.getString(stringRes), "").trim(); } diff --git a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java index 636fcddb72..c168047ba9 100644 --- a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java +++ b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java @@ -8,7 +8,6 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.core.content.ContextCompat; -import net.osmand.AndroidUtils; import net.osmand.FileUtils; import net.osmand.GPXUtilities; import net.osmand.GPXUtilities.GPXFile; @@ -526,7 +525,7 @@ public class MapMarkersHelper { private MapMarkersGroup createGPXMarkerGroup(File fl) { return new MapMarkersGroup(getMarkerGroupId(fl), - AndroidUtils.trimExtension(fl.getName()), + Algorithms.getFileNameWithoutExtension(fl.getName()), MapMarkersGroup.GPX_TYPE); } diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/GpxApproximationFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/GpxApproximationFragment.java index 87edaaf71b..924cea3ab0 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/GpxApproximationFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/GpxApproximationFragment.java @@ -298,13 +298,15 @@ public class GpxApproximationFragment extends ContextMenuScrollFragment return (menuState & (MenuState.HEADER_ONLY | MenuState.HALF_SCREEN)) != 0; } - public static void showInstance(@NonNull FragmentManager fm, @Nullable Fragment targetFragment, @NonNull LocationsHolder locationsHolder) { + public static void showInstance(@NonNull FragmentManager fm, @Nullable Fragment targetFragment, + @NonNull LocationsHolder locationsHolder, @Nullable ApplicationMode appMode) { try { if (!fm.isStateSaved()) { GpxApproximationFragment fragment = new GpxApproximationFragment(); fragment.setRetainInstance(true); fragment.setTargetFragment(targetFragment, REQUEST_CODE); fragment.setLocationsHolder(locationsHolder); + fragment.setSnapToRoadAppMode(appMode); fm.beginTransaction() .replace(R.id.fragmentContainer, fragment, TAG) .addToBackStack(TAG) @@ -348,12 +350,19 @@ public class GpxApproximationFragment extends ContextMenuScrollFragment @Override public void onProfileSelect(ApplicationMode applicationMode) { - if (snapToRoadAppMode != applicationMode) { - snapToRoadAppMode = applicationMode; + if (setSnapToRoadAppMode(applicationMode)) { calculateGpxApproximation(); } } + public boolean setSnapToRoadAppMode(ApplicationMode appMode) { + if (appMode != null && snapToRoadAppMode != appMode) { + snapToRoadAppMode = appMode; + return true; + } + return false; + } + public LocationsHolder getLocationsHolder() { return locationsHolder; } diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java index 7d6818a9d6..42b176201b 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java @@ -706,8 +706,12 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route case SnapTrackWarningFragment.CONTINUE_RESULT_CODE: MapActivity mapActivity = getMapActivity(); if (mapActivity != null) { + ApplicationMode mode = editingCtx.getAppMode(); + if (mode == ApplicationMode.DEFAULT || "public_transport".equals(mode.getRoutingProfile())) { + mode = null; + } GpxApproximationFragment.showInstance(mapActivity.getSupportFragmentManager(), - this, new LocationsHolder(editingCtx.getPoints())); + this, new LocationsHolder(editingCtx.getPoints()), mode); } break; } @@ -1522,7 +1526,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route String suggestedName = new SimpleDateFormat("EEE dd MMM yyyy", Locale.US).format(new Date()); displayedName = FileUtils.createUniqueFileName(requireMyApplication(), suggestedName, GPX_INDEX_DIR, GPX_FILE_EXT); } else { - displayedName = AndroidUtils.trimExtension(new File(gpxData.getGpxFile().path).getName()); + displayedName = Algorithms.getFileNameWithoutExtension(new File(gpxData.getGpxFile().path).getName()); } return displayedName; } From bd10c798f817b9b60df5c7e2b8b26c88cd7eeea3 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Fri, 25 Sep 2020 13:14:38 +0300 Subject: [PATCH 3/5] Fix track name and select app mode from gpx in follow track --- .../MeasurementToolFragment.java | 12 ++++++++-- .../ChooseRouteFragment.java | 2 +- .../FollowTrackFragment.java | 22 +++++++++++-------- 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java index 42b176201b..8089d3a012 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java @@ -1521,8 +1521,16 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route private String getSuggestedFileName() { GpxData gpxData = editingCtx.getGpxData(); - String displayedName; - if (gpxData == null) { + String displayedName = null; + if (gpxData != null) { + GPXFile gpxFile = gpxData.getGpxFile(); + if (!Algorithms.isEmpty(gpxFile.path)) { + displayedName = Algorithms.getFileNameWithoutExtension(new File(gpxFile.path).getName()); + } else if (!Algorithms.isEmpty(gpxFile.tracks)) { + displayedName = gpxFile.tracks.get(0).name; + } + } + if (gpxData == null || displayedName == null) { String suggestedName = new SimpleDateFormat("EEE dd MMM yyyy", Locale.US).format(new Date()); displayedName = FileUtils.createUniqueFileName(requireMyApplication(), suggestedName, GPX_INDEX_DIR, GPX_FILE_EXT); } else { diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/ChooseRouteFragment.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/ChooseRouteFragment.java index 407f65295f..62827e1e67 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/ChooseRouteFragment.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/ChooseRouteFragment.java @@ -487,7 +487,7 @@ public class ChooseRouteFragment extends BaseOsmAndFragment implements ContextMe String suggestedName = new SimpleDateFormat("EEE dd MMM yyyy", Locale.US).format(new Date()); fileName = FileUtils.createUniqueFileName(app, suggestedName, IndexConstants.GPX_INDEX_DIR, GPX_FILE_EXT); } else { - fileName = AndroidUtils.trimExtension(new File(paramsBuilder.getFile().path).getName()); + fileName = Algorithms.getFileNameWithoutExtension(new File(paramsBuilder.getFile().path).getName()); } SaveAsNewTrackBottomSheetDialogFragment.showInstance(mapActivity.getSupportFragmentManager(), ChooseRouteFragment.this, null, fileName, diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/FollowTrackFragment.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/FollowTrackFragment.java index 42ff2f94e6..8937f4ce5d 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/FollowTrackFragment.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/FollowTrackFragment.java @@ -25,6 +25,7 @@ import net.osmand.AndroidUtils; import net.osmand.CallbackWithObject; import net.osmand.GPXUtilities.GPXFile; import net.osmand.GPXUtilities.TrkSegment; +import net.osmand.GPXUtilities.WptPt; import net.osmand.IndexConstants; import net.osmand.PlatformUtil; import net.osmand.ValueHolder; @@ -433,14 +434,11 @@ public class FollowTrackFragment extends ContextMenuScrollFragment implements Ca if (mapActivity != null) { if (card instanceof ImportTrackCard) { importTrack(); - } else if (card instanceof TrackEditCard) { - openPlanRoute(true); + } else if (card instanceof TrackEditCard || card instanceof AttachTrackToRoadsCard) { + openPlanRoute(); close(); } else if (card instanceof SelectTrackCard) { updateSelectionMode(true); - } else if (card instanceof AttachTrackToRoadsCard) { - openPlanRoute(false); - close(); } else if (card instanceof ReverseTrackCard || card instanceof NavigateTrackOptionsCard) { updateMenu(); @@ -488,6 +486,14 @@ public class FollowTrackFragment extends ContextMenuScrollFragment implements Ca MapActivity mapActivity = getMapActivity(); if (mapActivity != null) { this.gpxFile = gpxFile; + List points = gpxFile.getRoutePoints(); + if (!points.isEmpty()) { + ApplicationMode mode = ApplicationMode.valueOfStringKey(points.get(0).getProfileType(), null); + if (mode != null) { + app.getRoutingHelper().setAppMode(mode); + app.initVoiceCommandPlayer(mapActivity, mode, true, null, false, false, true); + } + } mapActivity.getMapActions().setGPXRouteParams(gpxFile); app.getTargetPointsHelper().updateRouteAndRefresh(true); app.getRoutingHelper().recalculateRouteDueToSettingsChange(); @@ -544,7 +550,7 @@ public class FollowTrackFragment extends ContextMenuScrollFragment implements Ca } } - public void openPlanRoute(boolean useAppMode) { + public void openPlanRoute() { MapActivity mapActivity = getMapActivity(); if (mapActivity != null && gpxFile != null) { editingTrack = true; @@ -554,9 +560,7 @@ public class FollowTrackFragment extends ContextMenuScrollFragment implements Ca GpxData gpxData = new GpxData(gpxFile, rect, actionType, segment); MeasurementEditingContext editingContext = new MeasurementEditingContext(); editingContext.setGpxData(gpxData); - if (useAppMode) { - editingContext.setAppMode(app.getRoutingHelper().getAppMode()); - } + editingContext.setAppMode(app.getRoutingHelper().getAppMode()); MeasurementToolFragment.showInstance(mapActivity.getSupportFragmentManager(), editingContext, true); } } From 41e4654a626bf8d034ef9bb6daf2a7898beb83b9 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Fri, 25 Sep 2020 13:44:45 +0300 Subject: [PATCH 4/5] Fix saved track name --- .../routepreparationmenu/ChooseRouteFragment.java | 15 +++++++++++---- .../RouteOptionsBottomSheet.java | 11 +++++++++-- .../routepreparationmenu/cards/TracksCard.java | 10 ++++++++++ 3 files changed, 30 insertions(+), 6 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/ChooseRouteFragment.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/ChooseRouteFragment.java index 62827e1e67..5c283c670d 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/ChooseRouteFragment.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/ChooseRouteFragment.java @@ -37,6 +37,7 @@ import androidx.viewpager.widget.ViewPager; import net.osmand.AndroidUtils; import net.osmand.FileUtils; import net.osmand.GPXUtilities; +import net.osmand.GPXUtilities.GPXFile; import net.osmand.IndexConstants; import net.osmand.data.LatLon; import net.osmand.data.PointDescription; @@ -482,12 +483,18 @@ public class ChooseRouteFragment extends BaseOsmAndFragment implements ContextMe OsmandApplication app = mapActivity.getMyApplication(); GPXRouteParamsBuilder paramsBuilder = app.getRoutingHelper().getCurrentGPXRoute(); - String fileName; - if (paramsBuilder == null || paramsBuilder.getFile() == null || paramsBuilder.getFile().path == null) { + String fileName = null; + if (paramsBuilder != null && paramsBuilder.getFile() != null) { + GPXFile gpxFile = paramsBuilder.getFile(); + if (!Algorithms.isEmpty(gpxFile.path)) { + fileName = Algorithms.getFileNameWithoutExtension(new File(gpxFile.path).getName()); + } else if (!Algorithms.isEmpty(gpxFile.tracks)) { + fileName = gpxFile.tracks.get(0).name; + } + } + if (Algorithms.isEmpty(fileName)) { String suggestedName = new SimpleDateFormat("EEE dd MMM yyyy", Locale.US).format(new Date()); fileName = FileUtils.createUniqueFileName(app, suggestedName, IndexConstants.GPX_INDEX_DIR, GPX_FILE_EXT); - } else { - fileName = Algorithms.getFileNameWithoutExtension(new File(paramsBuilder.getFile().path).getName()); } SaveAsNewTrackBottomSheetDialogFragment.showInstance(mapActivity.getSupportFragmentManager(), ChooseRouteFragment.this, null, fileName, diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/RouteOptionsBottomSheet.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/RouteOptionsBottomSheet.java index 0d23e78673..d18537bfb8 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/RouteOptionsBottomSheet.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/RouteOptionsBottomSheet.java @@ -16,6 +16,7 @@ import androidx.core.content.ContextCompat; import androidx.fragment.app.FragmentManager; import net.osmand.AndroidUtils; +import net.osmand.GPXUtilities.GPXFile; import net.osmand.StateChangedListener; import net.osmand.plus.OsmAndLocationSimulation; import net.osmand.plus.OsmandApplication; @@ -47,6 +48,7 @@ import net.osmand.plus.settings.backend.ApplicationMode; import net.osmand.plus.settings.backend.OsmandSettings; import net.osmand.plus.settings.fragments.BaseSettingsFragment; import net.osmand.router.GeneralRouter; +import net.osmand.util.Algorithms; import java.io.File; import java.util.Arrays; @@ -342,14 +344,19 @@ public class RouteOptionsBottomSheet extends MenuBottomSheetDialogFragment { private BaseBottomSheetItem createGpxRoutingItem(final LocalRoutingParameter optionsItem) { RouteProvider.GPXRouteParamsBuilder routeParamsBuilder = mapActivity.getRoutingHelper().getCurrentGPXRoute(); - String description; + String description = null; int descriptionColorId; if (routeParamsBuilder == null) { descriptionColorId = nightMode ? R.color.text_color_secondary_dark : R.color.text_color_secondary_light; description = mapActivity.getString(R.string.follow_track_descr); } else { descriptionColorId = nightMode ? R.color.active_color_primary_dark : R.color.active_color_primary_light; - description = new File(routeParamsBuilder.getFile().path).getName(); + GPXFile gpxFile = routeParamsBuilder.getFile(); + if (!Algorithms.isEmpty(gpxFile.path)) { + description = new File(gpxFile.path).getName(); + } else if (!Algorithms.isEmpty(gpxFile.tracks)) { + description = gpxFile.tracks.get(0).name; + } } return new BottomSheetItemWithDescription.Builder() diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/TracksCard.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/TracksCard.java index 78bd52085e..3312371a56 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/TracksCard.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/TracksCard.java @@ -12,6 +12,7 @@ import androidx.appcompat.view.ContextThemeWrapper; import androidx.core.content.ContextCompat; import net.osmand.AndroidUtils; +import net.osmand.GPXUtilities; import net.osmand.GPXUtilities.GPXFile; import net.osmand.IndexConstants; import net.osmand.plus.GPXDatabase.GpxDataItem; @@ -19,6 +20,7 @@ import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.helpers.GpxUiHelper; import net.osmand.plus.helpers.GpxUiHelper.GPXInfo; +import net.osmand.plus.settings.backend.ApplicationMode; import java.io.File; import java.util.ArrayList; @@ -115,6 +117,14 @@ public class TracksCard extends BaseCard { v.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { + List points = item.file.getRoutePoints(); + if (!points.isEmpty()) { + ApplicationMode mode = ApplicationMode.valueOfStringKey(points.get(0).getProfileType(), null); + if (mode != null) { + app.getRoutingHelper().setAppMode(mode); + app.initVoiceCommandPlayer(mapActivity, mode, true, null, false, false, true); + } + } mapActivity.getMapActions().setGPXRouteParams(item.file); app.getTargetPointsHelper().updateRouteAndRefresh(true); } From db17418c4f7013e852ad3b29cfbf31910f6ac69b Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Fri, 25 Sep 2020 14:41:02 +0300 Subject: [PATCH 5/5] Fix reverse track availability --- .../osmand/plus/routepreparationmenu/FollowTrackFragment.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/FollowTrackFragment.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/FollowTrackFragment.java index 8937f4ce5d..fd0d22f6fc 100644 --- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/FollowTrackFragment.java +++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/FollowTrackFragment.java @@ -213,7 +213,7 @@ public class FollowTrackFragment extends ContextMenuScrollFragment implements Ca GPXRouteParamsBuilder rparams = routingHelper.getCurrentGPXRoute(); boolean osmandRouter = mode.getRouteService() == RouteProvider.RouteService.OSMAND; if (rparams != null && osmandRouter) { - boolean showReverseCard = !gpxFile.hasRoute() || gpxFile.hasRtePt(); + boolean showReverseCard = !routingHelper.isCurrentGPXRouteV2(); if (showReverseCard) { cardsContainer.addView(buildDividerView(cardsContainer, false));