From 7156452f627cb49bfdb45456995ef9e56edfb775 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Tue, 16 Jun 2020 19:42:21 +0300 Subject: [PATCH 1/3] Fix track screen navigation --- .../controllers/SelectedGpxMenuController.java | 1 - .../plus/mapcontextmenu/other/TrackDetailsMenu.java | 8 ++++---- .../other/TrackDetailsMenuFragment.java | 11 +++++++---- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/SelectedGpxMenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/SelectedGpxMenuController.java index b2e2b72eb1..064806de12 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/SelectedGpxMenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/SelectedGpxMenuController.java @@ -37,7 +37,6 @@ public class SelectedGpxMenuController extends MenuController { public void buttonPressed() { Intent intent = new Intent(mapActivity, mapActivity.getMyApplication().getAppCustomization().getTrackActivity()); intent.putExtra(TrackActivity.TRACK_FILE_NAME, item.getGpxFile().path); - intent.putExtra(TrackActivity.OPEN_TRACKS_LIST, true); intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT); mapActivity.startActivity(intent); } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/TrackDetailsMenu.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/TrackDetailsMenu.java index 4e19df5fcf..9e0274d557 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/TrackDetailsMenu.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/TrackDetailsMenu.java @@ -212,8 +212,8 @@ public class TrackDetailsMenu { } } - public void updateInfo(final View main) { - updateView(main); + public void updateInfo(final View main, boolean forceFitTrackOnMap) { + updateView(main, forceFitTrackOnMap); } @Nullable @@ -485,7 +485,7 @@ public class TrackDetailsMenu { return xAxisPoints; } - private void updateView(final View parentView) { + private void updateView(final View parentView, boolean forceFitTrackOnMap) { MapActivity mapActivity = getMapActivity(); GpxDisplayItem gpxItem = getGpxItem(); if (mapActivity == null || gpxItem == null) { @@ -724,7 +724,7 @@ public class TrackDetailsMenu { xAxisArrow.setVisibility(View.GONE); } - refreshChart(chart, true); + refreshChart(chart, forceFitTrackOnMap); } private void updateChart(LineChart chart) { diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/TrackDetailsMenuFragment.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/TrackDetailsMenuFragment.java index 843992ec9f..9673498f48 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/TrackDetailsMenuFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/TrackDetailsMenuFragment.java @@ -91,14 +91,13 @@ public class TrackDetailsMenuFragment extends BaseOsmAndFragment { }); } - updateInfo(); + updateInfo(false); ViewTreeObserver vto = mainView.getViewTreeObserver(); vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { - ViewTreeObserver obs = mainView.getViewTreeObserver(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { obs.removeOnGlobalLayoutListener(this); @@ -106,7 +105,7 @@ public class TrackDetailsMenuFragment extends BaseOsmAndFragment { obs.removeGlobalOnLayoutListener(this); } if (getMapActivity() != null) { - updateInfo(); + updateInfo(false); } } }); @@ -165,7 +164,11 @@ public class TrackDetailsMenuFragment extends BaseOsmAndFragment { } public void updateInfo() { - menu.updateInfo(mainView); + updateInfo(true); + } + + public void updateInfo(boolean forceFitTrackOnMap) { + menu.updateInfo(mainView, forceFitTrackOnMap); applyDayNightMode(); } From e225ad7b03693623bbad7fac3a60700248aee43d Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Wed, 17 Jun 2020 16:42:05 +0300 Subject: [PATCH 2/3] Fix gpx context menu navigation and add check for segment bounds --- .../main/java/net/osmand/GPXUtilities.java | 18 +++++++++++++ .../src/net/osmand/data/PointDescription.java | 4 +++ .../osmand/plus/activities/MapActivity.java | 5 ++++ .../src/net/osmand/plus/views/GPXLayer.java | 4 +-- .../src/net/osmand/plus/views/Renderable.java | 26 +++++-------------- 5 files changed, 35 insertions(+), 22 deletions(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java b/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java index f3cb0f8b84..6eb20d0f15 100644 --- a/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java +++ b/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java @@ -957,6 +957,24 @@ public class GPXUtilities { return ls; } + public static QuadRect calculateBounds(List pts) { + QuadRect trackBounds = new QuadRect(Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY, + Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY); + updateBounds(trackBounds, pts, 0); + + return trackBounds; + } + + public static void updateBounds(QuadRect trackBounds, List pts, int startIndex) { + for (int i = startIndex; i < pts.size(); i++) { + WptPt pt = pts.get(i); + trackBounds.right = Math.max(trackBounds.right, pt.lon); + trackBounds.left = Math.min(trackBounds.left, pt.lon); + trackBounds.top = Math.max(trackBounds.top, pt.lat); + trackBounds.bottom = Math.min(trackBounds.bottom, pt.lat); + } + } + public static class GPXFile extends GPXExtensions { public String author; public Metadata metadata; diff --git a/OsmAnd/src/net/osmand/data/PointDescription.java b/OsmAnd/src/net/osmand/data/PointDescription.java index 79b4cfe9e7..3057678526 100644 --- a/OsmAnd/src/net/osmand/data/PointDescription.java +++ b/OsmAnd/src/net/osmand/data/PointDescription.java @@ -289,6 +289,10 @@ public class PointDescription { return POINT_TYPE_CUSTOM_POI_FILTER.equals(type); } + public boolean isGpxPoint() { + return POINT_TYPE_GPX.equals(type); + } + @Override public int hashCode() { final int prime = 31; diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index 9bc9d3e24b..e1b80ebf53 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -673,6 +673,11 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven } if (trackDetailsMenu.isVisible()) { trackDetailsMenu.hide(true); + if (mapContextMenu.isActive() && mapContextMenu.getPointDescription() != null + && mapContextMenu.getPointDescription().isGpxPoint()) { + mapContextMenu.show(); + return; + } if (prevActivityIntent == null) { return; } diff --git a/OsmAnd/src/net/osmand/plus/views/GPXLayer.java b/OsmAnd/src/net/osmand/plus/views/GPXLayer.java index ee73e581c9..ad6f8b89db 100644 --- a/OsmAnd/src/net/osmand/plus/views/GPXLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/GPXLayer.java @@ -604,8 +604,8 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM for (SelectedGpxFile selectedGpxFile : selectedGpxFiles) { List segments = selectedGpxFile.getPointsToDisplay(); for (TrkSegment segment : segments) { - boolean nearSegment = isPointNearSegment(tb, segment.points, r, mx, my); - if (nearSegment) { + QuadRect trackBounds = GPXUtilities.calculateBounds(segment.points); + if (QuadRect.trivialOverlap(tb.getLatLonBounds(), trackBounds) && isPointNearSegment(tb, segment.points, r, mx, my)) { res.add(selectedGpxFile); break; } diff --git a/OsmAnd/src/net/osmand/plus/views/Renderable.java b/OsmAnd/src/net/osmand/plus/views/Renderable.java index 5204ca9332..e8bd0e75be 100644 --- a/OsmAnd/src/net/osmand/plus/views/Renderable.java +++ b/OsmAnd/src/net/osmand/plus/views/Renderable.java @@ -5,6 +5,7 @@ import android.graphics.Paint; import androidx.annotation.NonNull; +import net.osmand.GPXUtilities; import net.osmand.GPXUtilities.WptPt; import net.osmand.data.QuadRect; import net.osmand.data.RotatedTileBox; @@ -61,10 +62,10 @@ public class Renderable { protected AsynchronousResampler culler = null; // The currently active resampler protected Paint paint = null; // MUST be set by 'updateLocalPaint' before use - public RenderableSegment(List points, double segmentSize) { + public RenderableSegment(List points, double segmentSize) { this.points = points; - calculateBounds(points); this.segmentSize = segmentSize; + trackBounds = GPXUtilities.calculateBounds(points); } protected void updateLocalPaint(Paint p) { @@ -90,23 +91,6 @@ public class Renderable { } } - private void calculateBounds(List pts) { - trackBounds = new QuadRect(Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY, - Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY); - updateBounds(pts, 0); - } - - protected void updateBounds(List pts, int startIndex) { - pointSize = pts.size(); - for (int i = startIndex; i < pointSize; i++) { - WptPt pt = pts.get(i); - trackBounds.right = Math.max(trackBounds.right, pt.lon); - trackBounds.left = Math.min(trackBounds.left, pt.lon); - trackBounds.top = Math.max(trackBounds.top, pt.lat); - trackBounds.bottom = Math.min(trackBounds.bottom, pt.lat); - } - } - public void setRDP(List cull) { culled = cull; } @@ -198,7 +182,9 @@ public class Renderable { @Override public void drawSegment(double zoom, Paint p, Canvas canvas, RotatedTileBox tileBox) { if (points.size() != pointSize) { - updateBounds(points, pointSize); + int prevSize = pointSize; + pointSize = points.size(); + GPXUtilities.updateBounds(trackBounds, points, prevSize); } drawSingleSegment(zoom, p, canvas, tileBox); } From 80381c1c226b259aa867c91175b69b1ff3f45d44 Mon Sep 17 00:00:00 2001 From: Vitaliy Date: Wed, 17 Jun 2020 17:20:59 +0300 Subject: [PATCH 3/3] Fix map zoom update for analyze track --- .../other/TrackDetailsMenuFragment.java | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/TrackDetailsMenuFragment.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/TrackDetailsMenuFragment.java index 9673498f48..7c63f9497e 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/TrackDetailsMenuFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/TrackDetailsMenuFragment.java @@ -23,6 +23,7 @@ import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.base.BaseOsmAndFragment; import net.osmand.plus.helpers.AndroidUiHelper; +import net.osmand.plus.mapcontextmenu.MapContextMenu; public class TrackDetailsMenuFragment extends BaseOsmAndFragment { public static final String TAG = "TrackDetailsMenuFragment"; @@ -91,7 +92,14 @@ public class TrackDetailsMenuFragment extends BaseOsmAndFragment { }); } - updateInfo(false); + MapContextMenu contextMenu = mapActivity.getContextMenu(); + final boolean forceFitTrackOnMap; + if (contextMenu.isActive()) { + forceFitTrackOnMap = !(contextMenu.getPointDescription() != null && contextMenu.getPointDescription().isGpxPoint()); + } else { + forceFitTrackOnMap = true; + } + updateInfo(forceFitTrackOnMap); ViewTreeObserver vto = mainView.getViewTreeObserver(); vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @@ -105,7 +113,7 @@ public class TrackDetailsMenuFragment extends BaseOsmAndFragment { obs.removeGlobalOnLayoutListener(this); } if (getMapActivity() != null) { - updateInfo(false); + updateInfo(forceFitTrackOnMap); } } });