From 29db40747ae210f5f7955ac57a0afc884a40a3b7 Mon Sep 17 00:00:00 2001 From: Chumva Date: Sat, 13 Jul 2019 12:20:24 +0300 Subject: [PATCH 1/6] Fix #7233 --- .../plus/myplaces/TrackBitmapDrawer.java | 51 ++++++++++--------- 1 file changed, 28 insertions(+), 23 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/myplaces/TrackBitmapDrawer.java b/OsmAnd/src/net/osmand/plus/myplaces/TrackBitmapDrawer.java index 47ab04446b..627c72ca06 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/TrackBitmapDrawer.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/TrackBitmapDrawer.java @@ -12,13 +12,13 @@ import android.support.annotation.Nullable; import android.support.v4.content.ContextCompat; import net.osmand.AndroidUtils; +import net.osmand.GPXUtilities; +import net.osmand.GPXUtilities.GPXFile; +import net.osmand.GPXUtilities.TrkSegment; import net.osmand.data.LatLon; import net.osmand.data.QuadRect; import net.osmand.data.RotatedTileBox; import net.osmand.plus.GPXDatabase.GpxDataItem; -import net.osmand.GPXUtilities; -import net.osmand.GPXUtilities.GPXFile; -import net.osmand.GPXUtilities.TrkSegment; import net.osmand.plus.GpxSelectionHelper; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; @@ -30,6 +30,7 @@ import net.osmand.plus.views.Renderable; import java.util.ArrayList; import java.util.List; +import java.util.concurrent.RejectedExecutionException; public class TrackBitmapDrawer { @@ -225,30 +226,34 @@ public class TrackBitmapDrawer { } private void drawTrack(Canvas canvas, RotatedTileBox tileBox, GpxSelectionHelper.SelectedGpxFile g) { - GpxDataItem gpxDataItem = null; - if (!g.isShowCurrentTrack()) { - gpxDataItem = getGpxDataItem(); - } - List segments = g.getPointsToDisplay(); - for (TrkSegment ts : segments) { - int color = gpxDataItem != null ? gpxDataItem.getColor() : 0; - if (g.isShowCurrentTrack()) { - color = currentTrackColor; + try { + GpxDataItem gpxDataItem = null; + if (!g.isShowCurrentTrack()) { + gpxDataItem = getGpxDataItem(); } - if (color == 0) { - color = ts.getColor(trackColor); - } - if (ts.renderer == null && !ts.points.isEmpty()) { + List segments = g.getPointsToDisplay(); + for (TrkSegment ts : segments) { + int color = gpxDataItem != null ? gpxDataItem.getColor() : 0; if (g.isShowCurrentTrack()) { - ts.renderer = new Renderable.CurrentTrack(ts.points); - } else { - ts.renderer = new Renderable.StandardTrack(ts.points, 17.2); + color = currentTrackColor; + } + if (color == 0) { + color = ts.getColor(trackColor); + } + if (ts.renderer == null && !ts.points.isEmpty()) { + if (g.isShowCurrentTrack()) { + ts.renderer = new Renderable.CurrentTrack(ts.points); + } else { + ts.renderer = new Renderable.StandardTrack(ts.points, 17.2); + } + } + paint.setColor(color == 0 ? trackColor : color); + if (ts.renderer instanceof Renderable.RenderableSegment) { + ((Renderable.RenderableSegment) ts.renderer).drawSegment(tileBox.getZoom(), paint, canvas, tileBox); } } - paint.setColor(color == 0 ? trackColor : color); - if(ts.renderer instanceof Renderable.RenderableSegment) { - ((Renderable.RenderableSegment)ts.renderer).drawSegment(tileBox.getZoom(), paint, canvas, tileBox); - } + } catch (RejectedExecutionException e) { + // ignore } } From 272585149e34c2e7345a1ab746609f7f244a8673 Mon Sep 17 00:00:00 2001 From: crimean Date: Sat, 13 Jul 2019 12:30:37 +0300 Subject: [PATCH 2/6] Fix chart highlight --- .../plus/myplaces/TrackSegmentFragment.java | 202 +++++++++--------- 1 file changed, 105 insertions(+), 97 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/myplaces/TrackSegmentFragment.java b/OsmAnd/src/net/osmand/plus/myplaces/TrackSegmentFragment.java index cc9e5133ee..4d43794ebb 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/TrackSegmentFragment.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/TrackSegmentFragment.java @@ -39,24 +39,24 @@ import com.github.mikephil.charting.listener.OnChartGestureListener; import com.github.mikephil.charting.listener.OnChartValueSelectedListener; import net.osmand.AndroidUtils; -import net.osmand.data.LatLon; -import net.osmand.data.PointDescription; -import net.osmand.plus.GPXDatabase.GpxDataItem; import net.osmand.GPXUtilities; import net.osmand.GPXUtilities.GPXFile; import net.osmand.GPXUtilities.GPXTrackAnalysis; import net.osmand.GPXUtilities.Track; import net.osmand.GPXUtilities.TrkSegment; import net.osmand.GPXUtilities.WptPt; +import net.osmand.data.LatLon; +import net.osmand.data.PointDescription; +import net.osmand.plus.GPXDatabase.GpxDataItem; import net.osmand.plus.GpxSelectionHelper.GpxDisplayGroup; import net.osmand.plus.GpxSelectionHelper.GpxDisplayItem; import net.osmand.plus.GpxSelectionHelper.GpxDisplayItemType; import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile; -import net.osmand.plus.UiUtilities; import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; +import net.osmand.plus.UiUtilities; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.TrackActivity; import net.osmand.plus.base.OsmAndListFragment; @@ -68,7 +68,6 @@ import net.osmand.plus.measurementtool.NewGpxData; import net.osmand.plus.myplaces.TrackBitmapDrawer.TrackBitmapDrawerListener; import net.osmand.plus.views.controls.PagerSlidingTabStrip; import net.osmand.plus.views.controls.PagerSlidingTabStrip.CustomTabProvider; -import net.osmand.plus.views.controls.PagerSlidingTabStrip.TabSelectionType; import net.osmand.plus.views.controls.WrapContentHeightViewPager; import net.osmand.plus.views.controls.WrapContentHeightViewPager.ViewAtPositionInterface; import net.osmand.plus.widgets.IconPopupMenu; @@ -380,6 +379,7 @@ public class TrackSegmentFragment extends OsmAndListFragment implements TrackBit private Map> dataSetsMap = new HashMap<>(); private TrkSegment segment; private float listViewYPos; + private WptPt selectedWpt; GPXItemPagerAdapter(PagerSlidingTabStrip tabs, GpxDisplayItem gpxItem) { super(); @@ -554,7 +554,6 @@ public class TrackSegmentFragment extends OsmAndListFragment implements TrackBit @Override public Object instantiateItem(@NonNull ViewGroup container, int position) { - chartClicked = false; GPXTabItemType tabType = tabTypes[position]; final View view; LayoutInflater inflater = LayoutInflater.from(container.getContext()); @@ -576,109 +575,118 @@ public class TrackSegmentFragment extends OsmAndListFragment implements TrackBit if (gpxFile != null && gpxItem != null) { GPXTrackAnalysis analysis = gpxItem.analysis; final LineChart chart = (LineChart) view.findViewById(R.id.chart); - chart.setHighlightPerDragEnabled(false); + chart.setHighlightPerDragEnabled(chartClicked); chart.setOnClickListener(new View.OnClickListener() { @SuppressLint("ClickableViewAccessibility") @Override public void onClick(View view) { if (!chartClicked) { chartClicked = true; - chart.setHighlightPerDragEnabled(true); - chart.setOnTouchListener(new View.OnTouchListener() { - @Override - public boolean onTouch(View v, MotionEvent event) { - getListView().requestDisallowInterceptTouchEvent(true); - switch (event.getAction()) { - case android.view.MotionEvent.ACTION_DOWN: - listViewYPos = event.getRawY(); - break; - case android.view.MotionEvent.ACTION_MOVE: - scrollBy(Math.round(listViewYPos - event.getRawY())); - listViewYPos = event.getRawY(); - break; - } - return false; - } - }); - chart.setOnChartValueSelectedListener(new OnChartValueSelectedListener() { - @Override - public void onValueSelected(Entry e, Highlight h) { - WptPt wpt = getPoint(chart, h.getX()); - if (wpt != null && fragmentAdapter != null) { - fragmentAdapter.updateSelectedPoint(wpt.lat, wpt.lon); - } - } + if (selectedWpt != null && fragmentAdapter != null) { + fragmentAdapter.updateSelectedPoint(selectedWpt.lat, selectedWpt.lon); + } + } + } + }); + chart.setOnTouchListener(new View.OnTouchListener() { + @Override + public boolean onTouch(View v, MotionEvent event) { + if (chartClicked) { + getListView().requestDisallowInterceptTouchEvent(true); + if (!chart.isHighlightPerDragEnabled()) { + chart.setHighlightPerDragEnabled(true); + } + switch (event.getAction()) { + case android.view.MotionEvent.ACTION_DOWN: + listViewYPos = event.getRawY(); + break; + case android.view.MotionEvent.ACTION_MOVE: + scrollBy(Math.round(listViewYPos - event.getRawY())); + listViewYPos = event.getRawY(); + break; + } + } + return false; + } + }); + chart.setOnChartValueSelectedListener(new OnChartValueSelectedListener() { + @Override + public void onValueSelected(Entry e, Highlight h) { + WptPt wpt = getPoint(chart, h.getX()); + selectedWpt = wpt; + if (chartClicked && wpt != null && fragmentAdapter != null) { + fragmentAdapter.updateSelectedPoint(wpt.lat, wpt.lon); + } + } - @Override - public void onNothingSelected() { + @Override + public void onNothingSelected() { + } + }); + chart.setOnChartGestureListener(new OnChartGestureListener() { + + float highlightDrawX = -1; + + @Override + public void onChartGestureStart(MotionEvent me, ChartGesture lastPerformedGesture) { + if (chart.getHighlighted() != null && chart.getHighlighted().length > 0) { + highlightDrawX = chart.getHighlighted()[0].getDrawX(); + } else { + highlightDrawX = -1; + } + } + + @Override + public void onChartGestureEnd(MotionEvent me, ChartGesture lastPerformedGesture) { + gpxItem.chartMatrix = new Matrix(chart.getViewPortHandler().getMatrixTouch()); + Highlight[] highlights = chart.getHighlighted(); + if (highlights != null && highlights.length > 0) { + gpxItem.chartHighlightPos = highlights[0].getX(); + } else { + gpxItem.chartHighlightPos = -1; + } + if (chartClicked) { + for (int i = 0; i < getCount(); i++) { + View v = getViewAtPosition(i); + if (v != view) { + updateChart(i); } - }); - final View finalView = view; - chart.setOnChartGestureListener(new OnChartGestureListener() { + } + } + } - float highlightDrawX = -1; + @Override + public void onChartLongPressed(MotionEvent me) { + } - @Override - public void onChartGestureStart(MotionEvent me, ChartGesture lastPerformedGesture) { - if (chart.getHighlighted() != null && chart.getHighlighted().length > 0) { - highlightDrawX = chart.getHighlighted()[0].getDrawX(); - } else { - highlightDrawX = -1; - } + @Override + public void onChartDoubleTapped(MotionEvent me) { + } + + @Override + public void onChartSingleTapped(MotionEvent me) { + } + + @Override + public void onChartFling(MotionEvent me1, MotionEvent me2, float velocityX, float velocityY) { + } + + @Override + public void onChartScale(MotionEvent me, float scaleX, float scaleY) { + } + + @Override + public void onChartTranslate(MotionEvent me, float dX, float dY) { + if (chartClicked && highlightDrawX != -1) { + Highlight h = chart.getHighlightByTouchPoint(highlightDrawX, 0f); + if (h != null) { + chart.highlightValue(h); + WptPt wpt = getPoint(chart, h.getX()); + if (wpt != null && fragmentAdapter != null) { + fragmentAdapter.updateSelectedPoint(wpt.lat, wpt.lon); } - - @Override - public void onChartGestureEnd(MotionEvent me, ChartGesture lastPerformedGesture) { - gpxItem.chartMatrix = new Matrix(chart.getViewPortHandler().getMatrixTouch()); - Highlight[] highlights = chart.getHighlighted(); - if (highlights != null && highlights.length > 0) { - gpxItem.chartHighlightPos = highlights[0].getX(); - } else { - gpxItem.chartHighlightPos = -1; - } - for (int i = 0; i < getCount(); i++) { - View v = getViewAtPosition(i); - if (v != finalView) { - updateChart(i); - } - } - } - - @Override - public void onChartLongPressed(MotionEvent me) { - } - - @Override - public void onChartDoubleTapped(MotionEvent me) { - } - - @Override - public void onChartSingleTapped(MotionEvent me) { - } - - @Override - public void onChartFling(MotionEvent me1, MotionEvent me2, float velocityX, float velocityY) { - } - - @Override - public void onChartScale(MotionEvent me, float scaleX, float scaleY) { - } - - @Override - public void onChartTranslate(MotionEvent me, float dX, float dY) { - if (highlightDrawX != -1) { - Highlight h = chart.getHighlightByTouchPoint(highlightDrawX, 0f); - if (h != null) { - chart.highlightValue(h); - WptPt wpt = getPoint(chart, h.getX()); - if (wpt != null && fragmentAdapter != null) { - fragmentAdapter.updateSelectedPoint(wpt.lat, wpt.lon); - } - } - } - } - }); + } } } }); From 8680103926b980a9aab5c0b406610c78bc27d867 Mon Sep 17 00:00:00 2001 From: Chumva Date: Sat, 13 Jul 2019 12:56:25 +0300 Subject: [PATCH 3/6] Remove unnecessary changes and add thread pool executor for Renderable --- .../plus/myplaces/TrackBitmapDrawer.java | 45 +++++++++---------- .../src/net/osmand/plus/views/Renderable.java | 9 ++-- 2 files changed, 26 insertions(+), 28 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/myplaces/TrackBitmapDrawer.java b/OsmAnd/src/net/osmand/plus/myplaces/TrackBitmapDrawer.java index 627c72ca06..7a8738d47f 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/TrackBitmapDrawer.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/TrackBitmapDrawer.java @@ -30,7 +30,6 @@ import net.osmand.plus.views.Renderable; import java.util.ArrayList; import java.util.List; -import java.util.concurrent.RejectedExecutionException; public class TrackBitmapDrawer { @@ -226,34 +225,30 @@ public class TrackBitmapDrawer { } private void drawTrack(Canvas canvas, RotatedTileBox tileBox, GpxSelectionHelper.SelectedGpxFile g) { - try { - GpxDataItem gpxDataItem = null; - if (!g.isShowCurrentTrack()) { - gpxDataItem = getGpxDataItem(); + GpxDataItem gpxDataItem = null; + if (!g.isShowCurrentTrack()) { + gpxDataItem = getGpxDataItem(); + } + List segments = g.getPointsToDisplay(); + for (TrkSegment ts : segments) { + int color = gpxDataItem != null ? gpxDataItem.getColor() : 0; + if (g.isShowCurrentTrack()) { + color = currentTrackColor; } - List segments = g.getPointsToDisplay(); - for (TrkSegment ts : segments) { - int color = gpxDataItem != null ? gpxDataItem.getColor() : 0; + if (color == 0) { + color = ts.getColor(trackColor); + } + if (ts.renderer == null && !ts.points.isEmpty()) { if (g.isShowCurrentTrack()) { - color = currentTrackColor; - } - if (color == 0) { - color = ts.getColor(trackColor); - } - if (ts.renderer == null && !ts.points.isEmpty()) { - if (g.isShowCurrentTrack()) { - ts.renderer = new Renderable.CurrentTrack(ts.points); - } else { - ts.renderer = new Renderable.StandardTrack(ts.points, 17.2); - } - } - paint.setColor(color == 0 ? trackColor : color); - if (ts.renderer instanceof Renderable.RenderableSegment) { - ((Renderable.RenderableSegment) ts.renderer).drawSegment(tileBox.getZoom(), paint, canvas, tileBox); + ts.renderer = new Renderable.CurrentTrack(ts.points); + } else { + ts.renderer = new Renderable.StandardTrack(ts.points, 17.2); } } - } catch (RejectedExecutionException e) { - // ignore + paint.setColor(color == 0 ? trackColor : color); + if (ts.renderer instanceof Renderable.RenderableSegment) { + ((Renderable.RenderableSegment) ts.renderer).drawSegment(tileBox.getZoom(), paint, canvas, tileBox); + } } } diff --git a/OsmAnd/src/net/osmand/plus/views/Renderable.java b/OsmAnd/src/net/osmand/plus/views/Renderable.java index 162320f26d..ed721b4582 100644 --- a/OsmAnd/src/net/osmand/plus/views/Renderable.java +++ b/OsmAnd/src/net/osmand/plus/views/Renderable.java @@ -2,18 +2,21 @@ package net.osmand.plus.views; import android.graphics.Canvas; import android.graphics.Paint; -import android.os.AsyncTask; +import net.osmand.GPXUtilities.WptPt; import net.osmand.data.QuadRect; import net.osmand.data.RotatedTileBox; -import net.osmand.GPXUtilities.WptPt; import java.util.ArrayList; import java.util.List; +import java.util.concurrent.Executor; +import java.util.concurrent.Executors; public class Renderable { + public static final Executor THREAD_POOL_EXECUTOR = Executors.newFixedThreadPool(5); + public static abstract class RenderableSegment { public List points = null; // Original list of points @@ -139,7 +142,7 @@ public class Renderable { double cullDistance = Math.pow(2.0, segmentSize - zoom); // segmentSize == epsilon culler = new AsynchronousResampler.RamerDouglasPeucer(this, cullDistance); - culler.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, ""); + culler.executeOnExecutor(THREAD_POOL_EXECUTOR, ""); } } From c51df90e0514da884331444b140b9ca8a83b5c0d Mon Sep 17 00:00:00 2001 From: Chumva Date: Sat, 13 Jul 2019 13:08:28 +0300 Subject: [PATCH 4/6] Remove unnecessary changes --- .../net/osmand/plus/myplaces/TrackBitmapDrawer.java | 10 +++++----- OsmAnd/src/net/osmand/plus/views/Renderable.java | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/myplaces/TrackBitmapDrawer.java b/OsmAnd/src/net/osmand/plus/myplaces/TrackBitmapDrawer.java index 7a8738d47f..a1e46f7e38 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/TrackBitmapDrawer.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/TrackBitmapDrawer.java @@ -12,13 +12,13 @@ import android.support.annotation.Nullable; import android.support.v4.content.ContextCompat; import net.osmand.AndroidUtils; -import net.osmand.GPXUtilities; -import net.osmand.GPXUtilities.GPXFile; -import net.osmand.GPXUtilities.TrkSegment; import net.osmand.data.LatLon; import net.osmand.data.QuadRect; import net.osmand.data.RotatedTileBox; import net.osmand.plus.GPXDatabase.GpxDataItem; +import net.osmand.GPXUtilities; +import net.osmand.GPXUtilities.GPXFile; +import net.osmand.GPXUtilities.TrkSegment; import net.osmand.plus.GpxSelectionHelper; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; @@ -246,8 +246,8 @@ public class TrackBitmapDrawer { } } paint.setColor(color == 0 ? trackColor : color); - if (ts.renderer instanceof Renderable.RenderableSegment) { - ((Renderable.RenderableSegment) ts.renderer).drawSegment(tileBox.getZoom(), paint, canvas, tileBox); + if(ts.renderer instanceof Renderable.RenderableSegment) { + ((Renderable.RenderableSegment)ts.renderer).drawSegment(tileBox.getZoom(), paint, canvas, tileBox); } } } diff --git a/OsmAnd/src/net/osmand/plus/views/Renderable.java b/OsmAnd/src/net/osmand/plus/views/Renderable.java index ed721b4582..c4581c329e 100644 --- a/OsmAnd/src/net/osmand/plus/views/Renderable.java +++ b/OsmAnd/src/net/osmand/plus/views/Renderable.java @@ -15,7 +15,7 @@ import java.util.concurrent.Executors; public class Renderable { - public static final Executor THREAD_POOL_EXECUTOR = Executors.newFixedThreadPool(5); + private static final Executor THREAD_POOL_EXECUTOR = Executors.newFixedThreadPool(5); public static abstract class RenderableSegment { From e6dac60fca3d3439e093611a98af8b06f1a490ca Mon Sep 17 00:00:00 2001 From: Chumva Date: Sat, 13 Jul 2019 13:09:26 +0300 Subject: [PATCH 5/6] Fix formatting --- OsmAnd/src/net/osmand/plus/myplaces/TrackBitmapDrawer.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/myplaces/TrackBitmapDrawer.java b/OsmAnd/src/net/osmand/plus/myplaces/TrackBitmapDrawer.java index a1e46f7e38..efc0376ffa 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/TrackBitmapDrawer.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/TrackBitmapDrawer.java @@ -246,8 +246,8 @@ public class TrackBitmapDrawer { } } paint.setColor(color == 0 ? trackColor : color); - if(ts.renderer instanceof Renderable.RenderableSegment) { - ((Renderable.RenderableSegment)ts.renderer).drawSegment(tileBox.getZoom(), paint, canvas, tileBox); + if (ts.renderer instanceof Renderable.RenderableSegment) { + ((Renderable.RenderableSegment) ts.renderer).drawSegment(tileBox.getZoom(), paint, canvas, tileBox); } } } From 1d9f84295a7c81adc881dc9025d58f2f649e8aef Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Sat, 13 Jul 2019 12:42:46 +0200 Subject: [PATCH 6/6] Fix infinite loop --- OsmAnd/src/net/osmand/plus/routing/VoiceRouter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/routing/VoiceRouter.java b/OsmAnd/src/net/osmand/plus/routing/VoiceRouter.java index 2b4808929a..43aaff0668 100644 --- a/OsmAnd/src/net/osmand/plus/routing/VoiceRouter.java +++ b/OsmAnd/src/net/osmand/plus/routing/VoiceRouter.java @@ -901,7 +901,7 @@ public class VoiceRouter { } else if (type == ROUTE_RECALCULATED) { newCommand.routeRecalculated(left, time); } - play(newCommand); + VoiceRouter.play(newCommand); } } }