From be242bfea4bab4b6ae5de8e8220346b633eda94d Mon Sep 17 00:00:00 2001 From: PavelRatushny Date: Wed, 7 Jun 2017 18:54:03 +0300 Subject: [PATCH 01/11] Test adding points from chart --- .../other/TrackDetailsMenu.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/TrackDetailsMenu.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/TrackDetailsMenu.java index 31b6b59484..f472076cbc 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/TrackDetailsMenu.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/TrackDetailsMenu.java @@ -1,7 +1,14 @@ package net.osmand.plus.mapcontextmenu.other; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.graphics.Canvas; import android.graphics.Matrix; +import android.graphics.Paint; +import android.graphics.PorterDuff; +import android.graphics.PorterDuffColorFilter; import android.support.v4.app.Fragment; +import android.support.v4.content.ContextCompat; import android.support.v7.widget.PopupMenu; import android.view.MenuItem; import android.view.MotionEvent; @@ -36,6 +43,7 @@ import net.osmand.plus.helpers.GpxUiHelper; import net.osmand.plus.helpers.GpxUiHelper.GPXDataSetAxisType; import net.osmand.plus.helpers.GpxUiHelper.GPXDataSetType; import net.osmand.plus.helpers.GpxUiHelper.OrderedLineDataSet; +import net.osmand.plus.render.MapRenderRepositories; import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory; import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarController; @@ -51,6 +59,7 @@ public class TrackDetailsMenu { private GpxDisplayItem gpxItem; private TrackDetailsBarController toolbarController; private TrkSegment segment; + private Bitmap mapBitmap; private static boolean VISIBLE; @@ -276,9 +285,28 @@ public class TrackDetailsMenu { mapActivity.refreshMap(); } + MapRenderRepositories renderer = mapActivity.getMyApplication().getResourceManager().getRenderer(); + mapBitmap = renderer.getBitmap(); + drawPoints(tb, chart); } } + private void drawPoints(RotatedTileBox rotatedTileBox, LineChart chart) { + if (mapBitmap != null) { + Canvas canvas = new Canvas(mapBitmap); + Paint paintIcon = new Paint(); + Bitmap pointSmall = BitmapFactory.decodeResource(mapActivity.getResources(), R.drawable.map_white_shield_small); + int pointColor = ContextCompat.getColor(mapActivity.getMyApplication(), R.color.gpx_color_point); + paintIcon.setColorFilter(new PorterDuffColorFilter(pointColor, PorterDuff.Mode.MULTIPLY)); + for (int i = 0; i < segment.points.size(); i++) { + float x = rotatedTileBox.getPixXFromLatLon(segment.points.get(i).lat, segment.points.get(i).lon); + float y = rotatedTileBox.getPixYFromLatLon(segment.points.get(i).lat, segment.points.get(i).lon); + canvas.drawBitmap(pointSmall, x + 400 - pointSmall.getWidth() / 2, y + 400 - pointSmall.getHeight() / 2, paintIcon); + } + } + + } + private void refreshChart(LineChart chart, boolean forceFit) { Highlight[] highlights = chart.getHighlighted(); LatLon location = null; From 27ca6f24d4374fb2cc0037b7ff9b990bccb7ba51 Mon Sep 17 00:00:00 2001 From: PavelRatushny Date: Thu, 8 Jun 2017 14:53:57 +0300 Subject: [PATCH 02/11] Add points from chart --- .../other/TrackDetailsMenu.java | 39 ++++++------------- .../src/net/osmand/plus/views/GPXLayer.java | 15 +++++++ 2 files changed, 26 insertions(+), 28 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/TrackDetailsMenu.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/TrackDetailsMenu.java index f472076cbc..297ddd173b 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/TrackDetailsMenu.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/TrackDetailsMenu.java @@ -1,14 +1,7 @@ package net.osmand.plus.mapcontextmenu.other; -import android.graphics.Bitmap; -import android.graphics.BitmapFactory; -import android.graphics.Canvas; import android.graphics.Matrix; -import android.graphics.Paint; -import android.graphics.PorterDuff; -import android.graphics.PorterDuffColorFilter; import android.support.v4.app.Fragment; -import android.support.v4.content.ContextCompat; import android.support.v7.widget.PopupMenu; import android.view.MenuItem; import android.view.MotionEvent; @@ -43,7 +36,6 @@ import net.osmand.plus.helpers.GpxUiHelper; import net.osmand.plus.helpers.GpxUiHelper.GPXDataSetAxisType; import net.osmand.plus.helpers.GpxUiHelper.GPXDataSetType; import net.osmand.plus.helpers.GpxUiHelper.OrderedLineDataSet; -import net.osmand.plus.render.MapRenderRepositories; import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory; import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarController; @@ -59,7 +51,6 @@ public class TrackDetailsMenu { private GpxDisplayItem gpxItem; private TrackDetailsBarController toolbarController; private TrkSegment segment; - private Bitmap mapBitmap; private static boolean VISIBLE; @@ -150,6 +141,7 @@ public class TrackDetailsMenu { } mapActivity.getMapLayers().getContextMenuLayer().exitGpxDetailsMode(); mapActivity.getMapLayers().getGpxLayer().setSelectedPointLatLon(null); + mapActivity.getMapLayers().getGpxLayer().setPointsOnChart(null); mapActivity.getMapLayers().getMapInfoLayer().setSelectedPointLatLon(null); mapActivity.getMapView().setMapPositionX(0); mapActivity.getMapView().refreshMap(); @@ -285,28 +277,9 @@ public class TrackDetailsMenu { mapActivity.refreshMap(); } - MapRenderRepositories renderer = mapActivity.getMyApplication().getResourceManager().getRenderer(); - mapBitmap = renderer.getBitmap(); - drawPoints(tb, chart); } } - private void drawPoints(RotatedTileBox rotatedTileBox, LineChart chart) { - if (mapBitmap != null) { - Canvas canvas = new Canvas(mapBitmap); - Paint paintIcon = new Paint(); - Bitmap pointSmall = BitmapFactory.decodeResource(mapActivity.getResources(), R.drawable.map_white_shield_small); - int pointColor = ContextCompat.getColor(mapActivity.getMyApplication(), R.color.gpx_color_point); - paintIcon.setColorFilter(new PorterDuffColorFilter(pointColor, PorterDuff.Mode.MULTIPLY)); - for (int i = 0; i < segment.points.size(); i++) { - float x = rotatedTileBox.getPixXFromLatLon(segment.points.get(i).lat, segment.points.get(i).lon); - float y = rotatedTileBox.getPixYFromLatLon(segment.points.get(i).lat, segment.points.get(i).lon); - canvas.drawBitmap(pointSmall, x + 400 - pointSmall.getWidth() / 2, y + 400 - pointSmall.getHeight() / 2, paintIcon); - } - } - - } - private void refreshChart(LineChart chart, boolean forceFit) { Highlight[] highlights = chart.getHighlighted(); LatLon location = null; @@ -325,6 +298,16 @@ public class TrackDetailsMenu { gpxItem.chartHighlightPos = -1; } fitTrackOnMap(chart, location, forceFit); + + if (segment != null) { + List pointsOnChart = new ArrayList<>(); + float[] entries = chart.getXAxis().mEntries; + for (int i = 0; i < entries.length; i++) { + WptPt pointToAdd = getPoint(chart, entries[i]); + pointsOnChart.add(pointToAdd); + } + mapActivity.getMapLayers().getGpxLayer().setPointsOnChart(pointsOnChart); + } } private void updateView(final View parentView) { diff --git a/OsmAnd/src/net/osmand/plus/views/GPXLayer.java b/OsmAnd/src/net/osmand/plus/views/GPXLayer.java index 6487087751..834e7b1b28 100644 --- a/OsmAnd/src/net/osmand/plus/views/GPXLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/GPXLayer.java @@ -71,6 +71,8 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex private Bitmap selectedPoint; private LatLon selectedPointLatLon; + private List pointsOnChart; + private static final int startZoom = 7; @@ -349,6 +351,15 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex drawBigPoint(canvas, o, fileColor, x, y); } } + if (pointsOnChart != null) { + for (WptPt pointOnChart : pointsOnChart) { + float x = tileBox.getPixXFromLatLon(pointOnChart.getLatitude(), pointOnChart.getLongitude()); + float y = tileBox.getPixYFromLatLon(pointOnChart.getLatitude(), pointOnChart.getLongitude()); + int pointColor = ContextCompat.getColor(view.getApplication(), R.color.gpx_color_point); + paintIcon.setColorFilter(new PorterDuffColorFilter(pointColor, PorterDuff.Mode.MULTIPLY)); + canvas.drawBitmap(pointSmall, x - pointSmall.getWidth() / 2, y - pointSmall.getHeight() / 2, paintIcon); + } + } if (selectedPointLatLon != null && selectedPointLatLon.getLatitude() >= latLonBounds.bottom && selectedPointLatLon.getLatitude() <= latLonBounds.top @@ -432,6 +443,10 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex this.selectedPointLatLon = selectedPointLatLon; } + public void setPointsOnChart(List pointsOnChart) { + this.pointsOnChart = pointsOnChart; + } + private boolean calculateBelongs(int ex, int ey, int objx, int objy, int radius) { return (Math.abs(objx - ex) <= radius * 2 && Math.abs(objy - ey) <= radius * 2); // return Math.abs(objx - ex) <= radius && (ey - objy) <= radius / 2 && (objy - ey) <= 3 * radius ; From a6520c3f3ff1bd1ffd2a804726c9d18869e925a3 Mon Sep 17 00:00:00 2001 From: PavelRatushny Date: Thu, 8 Jun 2017 15:48:09 +0300 Subject: [PATCH 03/11] Add check for point if null --- .../osmand/plus/mapcontextmenu/other/TrackDetailsMenu.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/TrackDetailsMenu.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/TrackDetailsMenu.java index 297ddd173b..01f654f0e7 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/TrackDetailsMenu.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/TrackDetailsMenu.java @@ -304,7 +304,9 @@ public class TrackDetailsMenu { float[] entries = chart.getXAxis().mEntries; for (int i = 0; i < entries.length; i++) { WptPt pointToAdd = getPoint(chart, entries[i]); - pointsOnChart.add(pointToAdd); + if (pointToAdd != null) { + pointsOnChart.add(pointToAdd); + } } mapActivity.getMapLayers().getGpxLayer().setPointsOnChart(pointsOnChart); } From 77c568b328ceb2eb18a1cb125719104bd67b55b7 Mon Sep 17 00:00:00 2001 From: PavelRatushny Date: Thu, 8 Jun 2017 17:52:06 +0300 Subject: [PATCH 04/11] Add text on points from chart --- .../other/TrackDetailsMenu.java | 33 +++++++++++++------ .../src/net/osmand/plus/views/GPXLayer.java | 28 +++++++++------- 2 files changed, 40 insertions(+), 21 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/TrackDetailsMenu.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/TrackDetailsMenu.java index 01f654f0e7..37b2684f90 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/TrackDetailsMenu.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/TrackDetailsMenu.java @@ -12,6 +12,7 @@ import android.widget.TextView; import com.github.mikephil.charting.charts.LineChart; import com.github.mikephil.charting.data.Entry; import com.github.mikephil.charting.data.LineData; +import com.github.mikephil.charting.formatter.IAxisValueFormatter; import com.github.mikephil.charting.highlight.Highlight; import com.github.mikephil.charting.interfaces.datasets.ILineDataSet; import com.github.mikephil.charting.listener.ChartTouchListener.ChartGesture; @@ -43,7 +44,9 @@ import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; +import java.util.HashMap; import java.util.List; +import java.util.Map; public class TrackDetailsMenu { @@ -141,7 +144,7 @@ public class TrackDetailsMenu { } mapActivity.getMapLayers().getContextMenuLayer().exitGpxDetailsMode(); mapActivity.getMapLayers().getGpxLayer().setSelectedPointLatLon(null); - mapActivity.getMapLayers().getGpxLayer().setPointsOnChart(null); + mapActivity.getMapLayers().getGpxLayer().setPointsOfChart(null); mapActivity.getMapLayers().getMapInfoLayer().setSelectedPointLatLon(null); mapActivity.getMapView().setMapPositionX(0); mapActivity.getMapView().refreshMap(); @@ -300,18 +303,28 @@ public class TrackDetailsMenu { fitTrackOnMap(chart, location, forceFit); if (segment != null) { - List pointsOnChart = new ArrayList<>(); - float[] entries = chart.getXAxis().mEntries; - for (int i = 0; i < entries.length; i++) { - WptPt pointToAdd = getPoint(chart, entries[i]); - if (pointToAdd != null) { - pointsOnChart.add(pointToAdd); - } - } - mapActivity.getMapLayers().getGpxLayer().setPointsOnChart(pointsOnChart); + Map pointsOfChart = getPointsOfChart(chart); + mapActivity.getMapLayers().getGpxLayer().setPointsOfChart(pointsOfChart); } } + private Map getPointsOfChart(LineChart chart) { + Map pointsOfChart = new HashMap<>(); + float[] entries = chart.getXAxis().mEntries; + for (int i = 0; i < entries.length; i++) { + WptPt pointToAdd = getPoint(chart, entries[i]); + if (pointToAdd != null) { + if (gpxItem.chartAxisType == GPXDataSetAxisType.DISTANCE) { + pointsOfChart.put(String.format("%.1f", entries[i]), pointToAdd); + } else if (gpxItem.chartAxisType == GPXDataSetAxisType.TIME) { + IAxisValueFormatter formatter = chart.getXAxis().getValueFormatter(); + pointsOfChart.put(formatter.getFormattedValue(entries[i], chart.getXAxis()), pointToAdd); + } + } + } + return pointsOfChart; + } + private void updateView(final View parentView) { GPXTrackAnalysis analysis = gpxItem.analysis; if (analysis == null || gpxItem.chartTypes == null) { diff --git a/OsmAnd/src/net/osmand/plus/views/GPXLayer.java b/OsmAnd/src/net/osmand/plus/views/GPXLayer.java index 834e7b1b28..89e023b8ff 100644 --- a/OsmAnd/src/net/osmand/plus/views/GPXLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/GPXLayer.java @@ -71,7 +71,7 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex private Bitmap selectedPoint; private LatLon selectedPointLatLon; - private List pointsOnChart; + private Map pointsOfChart; private static final int startZoom = 7; @@ -351,14 +351,8 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex drawBigPoint(canvas, o, fileColor, x, y); } } - if (pointsOnChart != null) { - for (WptPt pointOnChart : pointsOnChart) { - float x = tileBox.getPixXFromLatLon(pointOnChart.getLatitude(), pointOnChart.getLongitude()); - float y = tileBox.getPixYFromLatLon(pointOnChart.getLatitude(), pointOnChart.getLongitude()); - int pointColor = ContextCompat.getColor(view.getApplication(), R.color.gpx_color_point); - paintIcon.setColorFilter(new PorterDuffColorFilter(pointColor, PorterDuff.Mode.MULTIPLY)); - canvas.drawBitmap(pointSmall, x - pointSmall.getWidth() / 2, y - pointSmall.getHeight() / 2, paintIcon); - } + if (pointsOfChart != null) { + drawPointsOfChart(canvas, tileBox); } if (selectedPointLatLon != null && selectedPointLatLon.getLatitude() >= latLonBounds.bottom @@ -375,6 +369,18 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex } } + private void drawPointsOfChart(Canvas canvas, RotatedTileBox tileBox) { + for (Map.Entry pointOfChart : pointsOfChart.entrySet()) { + float r = 12 * tileBox.getDensity(); + float x = tileBox.getPixXFromLatLon(pointOfChart.getValue().getLatitude(), pointOfChart.getValue().getLongitude()); + float y = tileBox.getPixYFromLatLon(pointOfChart.getValue().getLatitude(), pointOfChart.getValue().getLongitude()); + canvas.drawCircle(x, y, r + (float) Math.ceil(tileBox.getDensity()), paintOuter); + canvas.drawCircle(x, y, r - (float) Math.ceil(tileBox.getDensity()), paintInnerCircle); + paintTextIcon.setTextSize(r); + canvas.drawText(pointOfChart.getKey(), x, y + r / 2, paintTextIcon); + } + } + private int getFileColor(@NonNull SelectedGpxFile g) { return g.getColor() == 0 ? defPointColor : g.getColor(); } @@ -443,8 +449,8 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex this.selectedPointLatLon = selectedPointLatLon; } - public void setPointsOnChart(List pointsOnChart) { - this.pointsOnChart = pointsOnChart; + public void setPointsOfChart(Map pointsOfChart) { + this.pointsOfChart = pointsOfChart; } private boolean calculateBelongs(int ex, int ey, int objx, int objy, int radius) { From 98b739b224a18004fbc93de5a9a833deca2fe21d Mon Sep 17 00:00:00 2001 From: PavelRatushny Date: Thu, 8 Jun 2017 18:57:17 +0300 Subject: [PATCH 05/11] Test replacing circle with rect --- .../src/net/osmand/plus/views/GPXLayer.java | 26 +++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/views/GPXLayer.java b/OsmAnd/src/net/osmand/plus/views/GPXLayer.java index 89e023b8ff..b1c5ff0d47 100644 --- a/OsmAnd/src/net/osmand/plus/views/GPXLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/GPXLayer.java @@ -87,6 +87,8 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex private Paint paintInnerCircle; + private Paint paintInnerRect; + private Paint paintTextIcon; private OsmandRenderer osmandRenderer; @@ -144,6 +146,10 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex paintInnerCircle.setStyle(Style.FILL_AND_STROKE); paintInnerCircle.setColor(0xddFFFFFF); paintInnerCircle.setAntiAlias(true); + paintInnerRect = new Paint(); + paintInnerRect.setStyle(Style.FILL_AND_STROKE); + paintInnerCircle.setColor(0xddFFFFFF); + paintInnerRect.setAntiAlias(true); paintIcon = new Paint(); pointSmall = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_white_shield_small); @@ -372,10 +378,26 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex private void drawPointsOfChart(Canvas canvas, RotatedTileBox tileBox) { for (Map.Entry pointOfChart : pointsOfChart.entrySet()) { float r = 12 * tileBox.getDensity(); + + String stringToDisplay = pointOfChart.getKey(); + + float textWidth = paintTextIcon.measureText(stringToDisplay); + float x = tileBox.getPixXFromLatLon(pointOfChart.getValue().getLatitude(), pointOfChart.getValue().getLongitude()); float y = tileBox.getPixYFromLatLon(pointOfChart.getValue().getLatitude(), pointOfChart.getValue().getLongitude()); - canvas.drawCircle(x, y, r + (float) Math.ceil(tileBox.getDensity()), paintOuter); - canvas.drawCircle(x, y, r - (float) Math.ceil(tileBox.getDensity()), paintInnerCircle); + +// canvas.drawCircle(x, y, r + (float) Math.ceil(tileBox.getDensity()), paintOuter); + +// canvas.drawCircle(x, y, r - (float) Math.ceil(tileBox.getDensity()), paintInnerCircle); +// paintTextIcon.setTextSize(r); +// canvas.drawText(pointOfChart.getKey(), x, y + r / 2, paintTextIcon); + +// paintInnerRect.setColor(); + canvas.drawRect( + x + (float) Math.ceil(tileBox.getDensity()) - textWidth / 2, + y + (float) Math.ceil(tileBox.getDensity()) - r /2, + x + (float) Math.ceil(tileBox.getDensity()) + textWidth / 2, + y + (float) Math.ceil(tileBox.getDensity()) + r / 2, paintInnerRect); paintTextIcon.setTextSize(r); canvas.drawText(pointOfChart.getKey(), x, y + r / 2, paintTextIcon); } From 136cc2ff0181a301ef119cf9a6b8cbf749411653 Mon Sep 17 00:00:00 2001 From: PavelRatushny Date: Thu, 8 Jun 2017 19:04:56 +0300 Subject: [PATCH 06/11] Fix replacing color for rect --- OsmAnd/src/net/osmand/plus/views/GPXLayer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/views/GPXLayer.java b/OsmAnd/src/net/osmand/plus/views/GPXLayer.java index b1c5ff0d47..f4afdb37d2 100644 --- a/OsmAnd/src/net/osmand/plus/views/GPXLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/GPXLayer.java @@ -148,7 +148,7 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex paintInnerCircle.setAntiAlias(true); paintInnerRect = new Paint(); paintInnerRect.setStyle(Style.FILL_AND_STROKE); - paintInnerCircle.setColor(0xddFFFFFF); + paintInnerRect.setColor(0xddFFFFFF); paintInnerRect.setAntiAlias(true); paintIcon = new Paint(); From f6408a44ba0b029b4e1c416c767d188228f4de23 Mon Sep 17 00:00:00 2001 From: PavelRatushny Date: Fri, 9 Jun 2017 10:19:24 +0300 Subject: [PATCH 07/11] Change naming to axis grid points --- .../other/TrackDetailsMenu.java | 16 +++++++------- .../src/net/osmand/plus/views/GPXLayer.java | 22 +++++++++---------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/TrackDetailsMenu.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/TrackDetailsMenu.java index 37b2684f90..60d2822bab 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/TrackDetailsMenu.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/TrackDetailsMenu.java @@ -144,7 +144,7 @@ public class TrackDetailsMenu { } mapActivity.getMapLayers().getContextMenuLayer().exitGpxDetailsMode(); mapActivity.getMapLayers().getGpxLayer().setSelectedPointLatLon(null); - mapActivity.getMapLayers().getGpxLayer().setPointsOfChart(null); + mapActivity.getMapLayers().getGpxLayer().setAxisGridPoints(null); mapActivity.getMapLayers().getMapInfoLayer().setSelectedPointLatLon(null); mapActivity.getMapView().setMapPositionX(0); mapActivity.getMapView().refreshMap(); @@ -303,26 +303,26 @@ public class TrackDetailsMenu { fitTrackOnMap(chart, location, forceFit); if (segment != null) { - Map pointsOfChart = getPointsOfChart(chart); - mapActivity.getMapLayers().getGpxLayer().setPointsOfChart(pointsOfChart); + Map axisGridPoints = getAxisGridPoints(chart); + mapActivity.getMapLayers().getGpxLayer().setAxisGridPoints(axisGridPoints); } } - private Map getPointsOfChart(LineChart chart) { - Map pointsOfChart = new HashMap<>(); + private Map getAxisGridPoints(LineChart chart) { + Map axisGridPoints = new HashMap<>(); float[] entries = chart.getXAxis().mEntries; for (int i = 0; i < entries.length; i++) { WptPt pointToAdd = getPoint(chart, entries[i]); if (pointToAdd != null) { if (gpxItem.chartAxisType == GPXDataSetAxisType.DISTANCE) { - pointsOfChart.put(String.format("%.1f", entries[i]), pointToAdd); + axisGridPoints.put(String.format("%.1f", entries[i]), pointToAdd); } else if (gpxItem.chartAxisType == GPXDataSetAxisType.TIME) { IAxisValueFormatter formatter = chart.getXAxis().getValueFormatter(); - pointsOfChart.put(formatter.getFormattedValue(entries[i], chart.getXAxis()), pointToAdd); + axisGridPoints.put(formatter.getFormattedValue(entries[i], chart.getXAxis()), pointToAdd); } } } - return pointsOfChart; + return axisGridPoints; } private void updateView(final View parentView) { diff --git a/OsmAnd/src/net/osmand/plus/views/GPXLayer.java b/OsmAnd/src/net/osmand/plus/views/GPXLayer.java index f4afdb37d2..57b51caefb 100644 --- a/OsmAnd/src/net/osmand/plus/views/GPXLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/GPXLayer.java @@ -71,7 +71,7 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex private Bitmap selectedPoint; private LatLon selectedPointLatLon; - private Map pointsOfChart; + private Map axisGridPoints; private static final int startZoom = 7; @@ -357,8 +357,8 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex drawBigPoint(canvas, o, fileColor, x, y); } } - if (pointsOfChart != null) { - drawPointsOfChart(canvas, tileBox); + if (axisGridPoints != null) { + drawAxisGridPoints(canvas, tileBox); } if (selectedPointLatLon != null && selectedPointLatLon.getLatitude() >= latLonBounds.bottom @@ -375,16 +375,16 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex } } - private void drawPointsOfChart(Canvas canvas, RotatedTileBox tileBox) { - for (Map.Entry pointOfChart : pointsOfChart.entrySet()) { + private void drawAxisGridPoints(Canvas canvas, RotatedTileBox tileBox) { + for (Map.Entry axisGridPoint : axisGridPoints.entrySet()) { float r = 12 * tileBox.getDensity(); - String stringToDisplay = pointOfChart.getKey(); + String stringToDisplay = axisGridPoint.getKey(); float textWidth = paintTextIcon.measureText(stringToDisplay); - float x = tileBox.getPixXFromLatLon(pointOfChart.getValue().getLatitude(), pointOfChart.getValue().getLongitude()); - float y = tileBox.getPixYFromLatLon(pointOfChart.getValue().getLatitude(), pointOfChart.getValue().getLongitude()); + float x = tileBox.getPixXFromLatLon(axisGridPoint.getValue().getLatitude(), axisGridPoint.getValue().getLongitude()); + float y = tileBox.getPixYFromLatLon(axisGridPoint.getValue().getLatitude(), axisGridPoint.getValue().getLongitude()); // canvas.drawCircle(x, y, r + (float) Math.ceil(tileBox.getDensity()), paintOuter); @@ -399,7 +399,7 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex x + (float) Math.ceil(tileBox.getDensity()) + textWidth / 2, y + (float) Math.ceil(tileBox.getDensity()) + r / 2, paintInnerRect); paintTextIcon.setTextSize(r); - canvas.drawText(pointOfChart.getKey(), x, y + r / 2, paintTextIcon); + canvas.drawText(axisGridPoint.getKey(), x, y + r / 2, paintTextIcon); } } @@ -471,8 +471,8 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex this.selectedPointLatLon = selectedPointLatLon; } - public void setPointsOfChart(Map pointsOfChart) { - this.pointsOfChart = pointsOfChart; + public void setAxisGridPoints(Map axisGridPoints) { + this.axisGridPoints = axisGridPoints; } private boolean calculateBelongs(int ex, int ey, int objx, int objy, int radius) { From 10650ed041bcb700b4e583c172018bc92157c72e Mon Sep 17 00:00:00 2001 From: PavelRatushny Date: Fri, 9 Jun 2017 17:50:47 +0300 Subject: [PATCH 08/11] Change rect color --- .../net/osmand/plus/GpxSelectionHelper.java | 13 +++ .../other/TrackDetailsMenu.java | 71 ++++++++++---- .../src/net/osmand/plus/views/GPXLayer.java | 98 +++++++++---------- 3 files changed, 113 insertions(+), 69 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java b/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java index 0054d1bcaf..2184800571 100644 --- a/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java +++ b/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java @@ -347,6 +347,19 @@ public class GpxSelectionHelper { return null; } + public SelectedGpxFile getSelectedFileFromDisplayItemByName(String name) { + SelectedGpxFile selectedGpxFile = null; + name = name.replaceAll(" ", "_").concat(".gpx"); + for (SelectedGpxFile s : selectedGPXFiles) { + String nameOfSelectedGpx = s.getGpxFile().path.replaceAll(" ", "_"); + nameOfSelectedGpx = nameOfSelectedGpx.substring(nameOfSelectedGpx.lastIndexOf("/") + 1, nameOfSelectedGpx.length()); + if (nameOfSelectedGpx.equals(name)) { + selectedGpxFile = s; + } + } + return selectedGpxFile; + } + public SelectedGpxFile getSelectedCurrentRecordingTrack() { for (SelectedGpxFile s : selectedGPXFiles) { if (s.isShowCurrentTrack()) { diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/TrackDetailsMenu.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/TrackDetailsMenu.java index 60d2822bab..f41dcea474 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/TrackDetailsMenu.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/TrackDetailsMenu.java @@ -143,8 +143,7 @@ public class TrackDetailsMenu { mapActivity.hideTopToolbar(toolbarController); } mapActivity.getMapLayers().getContextMenuLayer().exitGpxDetailsMode(); - mapActivity.getMapLayers().getGpxLayer().setSelectedPointLatLon(null); - mapActivity.getMapLayers().getGpxLayer().setAxisGridPoints(null); + mapActivity.getMapLayers().getGpxLayer().setAxisValueDetails(null); mapActivity.getMapLayers().getMapInfoLayer().setSelectedPointLatLon(null); mapActivity.getMapView().setMapPositionX(0); mapActivity.getMapView().refreshMap(); @@ -291,40 +290,46 @@ public class TrackDetailsMenu { WptPt wpt = getPoint(chart, gpxItem.chartHighlightPos); if (wpt != null) { location = new LatLon(wpt.lat, wpt.lon); + List formattedAxisEntries = getFormattedAxisEntries(chart); + List axisGridPoints = getAxisGridPoints(chart); + AxisValueDetails axisValueDetails = new AxisValueDetails(axisGridPoints, formattedAxisEntries, location, getGpxItem()); if (gpxItem.route) { mapActivity.getMapLayers().getMapInfoLayer().setSelectedPointLatLon(location); } else { - mapActivity.getMapLayers().getGpxLayer().setSelectedPointLatLon(location); + mapActivity.getMapLayers().getGpxLayer().setAxisValueDetails(axisValueDetails); } } } else { gpxItem.chartHighlightPos = -1; } fitTrackOnMap(chart, location, forceFit); - - if (segment != null) { - Map axisGridPoints = getAxisGridPoints(chart); - mapActivity.getMapLayers().getGpxLayer().setAxisGridPoints(axisGridPoints); - } } - private Map getAxisGridPoints(LineChart chart) { - Map axisGridPoints = new HashMap<>(); + private List getAxisGridPoints (LineChart chart) { + List axisGridPoints = new ArrayList<>(); float[] entries = chart.getXAxis().mEntries; for (int i = 0; i < entries.length; i++) { WptPt pointToAdd = getPoint(chart, entries[i]); - if (pointToAdd != null) { - if (gpxItem.chartAxisType == GPXDataSetAxisType.DISTANCE) { - axisGridPoints.put(String.format("%.1f", entries[i]), pointToAdd); - } else if (gpxItem.chartAxisType == GPXDataSetAxisType.TIME) { - IAxisValueFormatter formatter = chart.getXAxis().getValueFormatter(); - axisGridPoints.put(formatter.getFormattedValue(entries[i], chart.getXAxis()), pointToAdd); - } - } + axisGridPoints.add(pointToAdd); } return axisGridPoints; } + private List getFormattedAxisEntries (LineChart chart) { + float[] entries = chart.getXAxis().mEntries; + List formattedAxisEntries = new ArrayList<>(); + for (int i = 0; i < entries.length; i++) { + String formattedAxisEntry = ""; + if (gpxItem.chartAxisType == GPXDataSetAxisType.DISTANCE) { + formattedAxisEntry = String.format("%.1f", entries[i]); + } else if (gpxItem.chartAxisType == GPXDataSetAxisType.TIME) { + formattedAxisEntry = chart.getXAxis().getValueFormatter().getFormattedValue(entries[i], chart.getXAxis()); + } + formattedAxisEntries.add(formattedAxisEntry); + } + return formattedAxisEntries; + } + private void updateView(final View parentView) { GPXTrackAnalysis analysis = gpxItem.analysis; if (analysis == null || gpxItem.chartTypes == null) { @@ -586,4 +591,34 @@ public class TrackDetailsMenu { view.getShadowView().setVisibility(View.GONE); } } + + public class AxisValueDetails { + private List axisGridPoints; + private List formattedAxisGridEntries; + private LatLon selectedPointLatLon; + private GpxDisplayItem gpxDisplayItem; + + public AxisValueDetails(List axisGridPoints, List formattedAxisGridEntries, LatLon selectedPointLatLon, GpxDisplayItem gpxDisplayItem) { + this.axisGridPoints = axisGridPoints; + this.formattedAxisGridEntries = formattedAxisGridEntries; + this.selectedPointLatLon = selectedPointLatLon; + this.gpxDisplayItem = gpxDisplayItem; + } + + public List getAxisGridPoints() { + return axisGridPoints; + } + + public List getFormattedAxisGridEntries() { + return formattedAxisGridEntries; + } + + public LatLon getSelectedPointLatLon() { + return selectedPointLatLon; + } + + public GpxDisplayItem getGpxDisplayItem() { + return gpxDisplayItem; + } + } } diff --git a/OsmAnd/src/net/osmand/plus/views/GPXLayer.java b/OsmAnd/src/net/osmand/plus/views/GPXLayer.java index 57b51caefb..b2fbb37c06 100644 --- a/OsmAnd/src/net/osmand/plus/views/GPXLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/GPXLayer.java @@ -36,6 +36,7 @@ import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandSettings.CommonPreference; import net.osmand.plus.R; import net.osmand.plus.base.FavoriteImageDrawable; +import net.osmand.plus.mapcontextmenu.other.TrackDetailsMenu.AxisValueDetails; import net.osmand.plus.render.OsmandRenderer; import net.osmand.plus.render.OsmandRenderer.RenderingContext; import net.osmand.plus.views.MapTextLayer.MapTextProvider; @@ -69,9 +70,7 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex private int currentTrackColor; private Bitmap selectedPoint; - private LatLon selectedPointLatLon; - - private Map axisGridPoints; + private AxisValueDetails axisValueDetails; private static final int startZoom = 7; @@ -82,7 +81,6 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex private Map pointFileMap = new HashMap<>(); private MapTextLayer textLayer; - private Paint paintOuter; private Paint paintInnerCircle; @@ -91,6 +89,8 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex private Paint paintTextIcon; + private Paint paintGridTextIcon; + private OsmandRenderer osmandRenderer; private List points; @@ -110,6 +110,10 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex initUI(); } + public void setAxisValueDetails(AxisValueDetails axisValueDetails) { + this.axisValueDetails = axisValueDetails; + } + private void initUI() { paint = new Paint(); paint.setStyle(Style.STROKE); @@ -136,6 +140,12 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex paintTextIcon.setColor(Color.BLACK); paintTextIcon.setAntiAlias(true); + paintGridTextIcon = new Paint(); + paintGridTextIcon.setTextAlign(Align.CENTER); + paintGridTextIcon.setFakeBoldText(true); + paintGridTextIcon.setColor(Color.WHITE); + paintGridTextIcon.setAntiAlias(true); + textLayer = view.getLayerByClass(MapTextLayer.class); paintOuter = new Paint(); @@ -148,7 +158,6 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex paintInnerCircle.setAntiAlias(true); paintInnerRect = new Paint(); paintInnerRect.setStyle(Style.FILL_AND_STROKE); - paintInnerRect.setColor(0xddFFFFFF); paintInnerRect.setAntiAlias(true); paintIcon = new Paint(); @@ -357,18 +366,20 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex drawBigPoint(canvas, o, fileColor, x, y); } } - if (axisGridPoints != null) { + if (axisValueDetails != null) { drawAxisGridPoints(canvas, tileBox); - } - if (selectedPointLatLon != null - && selectedPointLatLon.getLatitude() >= latLonBounds.bottom - && selectedPointLatLon.getLatitude() <= latLonBounds.top - && selectedPointLatLon.getLongitude() >= latLonBounds.left - && selectedPointLatLon.getLongitude() <= latLonBounds.right) { - float x = tileBox.getPixXFromLatLon(selectedPointLatLon.getLatitude(), selectedPointLatLon.getLongitude()); - float y = tileBox.getPixYFromLatLon(selectedPointLatLon.getLatitude(), selectedPointLatLon.getLongitude()); - paintIcon.setColorFilter(null); - canvas.drawBitmap(selectedPoint, x - selectedPoint.getWidth() / 2, y - selectedPoint.getHeight() / 2, paintIcon); + LatLon selectedPointLatLon = axisValueDetails.getSelectedPointLatLon(); + if (selectedPointLatLon.getLatitude() >= latLonBounds.bottom + && selectedPointLatLon.getLatitude() <= latLonBounds.top + && selectedPointLatLon.getLongitude() >= latLonBounds.left + && selectedPointLatLon.getLongitude() <= latLonBounds.right) { + float x = tileBox.getPixXFromLatLon(selectedPointLatLon.getLatitude(), selectedPointLatLon.getLongitude()); + float y = tileBox.getPixYFromLatLon(selectedPointLatLon.getLatitude(), selectedPointLatLon.getLongitude()); + paintIcon.setColorFilter(null); + canvas.drawBitmap(selectedPoint, x - selectedPoint.getWidth() / 2, y - selectedPoint.getHeight() / 2, paintIcon); + } + } else if (paintInnerRect.getColor() != 0){ + paintInnerRect.setColor(0); } this.fullObjectsLatLon = fullObjectsLatLon; this.smallObjectsLatLon = smallObjectsLatLon; @@ -376,30 +387,27 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex } private void drawAxisGridPoints(Canvas canvas, RotatedTileBox tileBox) { - for (Map.Entry axisGridPoint : axisGridPoints.entrySet()) { - float r = 12 * tileBox.getDensity(); - - String stringToDisplay = axisGridPoint.getKey(); - - float textWidth = paintTextIcon.measureText(stringToDisplay); - - float x = tileBox.getPixXFromLatLon(axisGridPoint.getValue().getLatitude(), axisGridPoint.getValue().getLongitude()); - float y = tileBox.getPixYFromLatLon(axisGridPoint.getValue().getLatitude(), axisGridPoint.getValue().getLongitude()); - -// canvas.drawCircle(x, y, r + (float) Math.ceil(tileBox.getDensity()), paintOuter); - -// canvas.drawCircle(x, y, r - (float) Math.ceil(tileBox.getDensity()), paintInnerCircle); -// paintTextIcon.setTextSize(r); -// canvas.drawText(pointOfChart.getKey(), x, y + r / 2, paintTextIcon); - -// paintInnerRect.setColor(); + if (paintInnerRect.getColor() == 0) { + SelectedGpxFile selectedGpxFile = selectedGpxHelper.getSelectedFileFromDisplayItemByName((axisValueDetails.getGpxDisplayItem().group.getGpxName())); + GpxDataItem gpxDataItem = view.getApplication().getGpxDatabase().getItem(new File(selectedGpxFile.getGpxFile().path)); + paintInnerRect.setColor(gpxDataItem.getColor()); + } + List axisGridPoints = axisValueDetails.getAxisGridPoints(); + List formattedAxisGridEntries = axisValueDetails.getFormattedAxisGridEntries(); + float r = 12 * tileBox.getDensity(); + paintGridTextIcon.setTextSize(r); + for (int i = 0; i < axisGridPoints.size(); i++) { + String textOnPoint = formattedAxisGridEntries.get(i); + float textWidth = paintGridTextIcon.measureText(textOnPoint); + float x = tileBox.getPixXFromLatLon(axisGridPoints.get(i).getLatitude(), axisGridPoints.get(i).getLongitude()); + float y = tileBox.getPixYFromLatLon(axisGridPoints.get(i).getLatitude(), axisGridPoints.get(i).getLongitude()); canvas.drawRect( - x + (float) Math.ceil(tileBox.getDensity()) - textWidth / 2, - y + (float) Math.ceil(tileBox.getDensity()) - r /2, - x + (float) Math.ceil(tileBox.getDensity()) + textWidth / 2, - y + (float) Math.ceil(tileBox.getDensity()) + r / 2, paintInnerRect); - paintTextIcon.setTextSize(r); - canvas.drawText(axisGridPoint.getKey(), x, y + r / 2, paintTextIcon); + x - textWidth / 2 - 2 * (float) Math.ceil(tileBox.getDensity()), + y - r / 2 - 2 * (float) Math.ceil(tileBox.getDensity()), + x + textWidth / 2 + 2 * (float) Math.ceil(tileBox.getDensity()), + y + r / 2 + 3 * (float) Math.ceil(tileBox.getDensity()), + paintInnerRect); + canvas.drawText(textOnPoint, x, y + r / 2, paintGridTextIcon); } } @@ -463,18 +471,6 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex return g.getGpxFile().points; } - public LatLon getSelectedPointLatLon() { - return selectedPointLatLon; - } - - public void setSelectedPointLatLon(LatLon selectedPointLatLon) { - this.selectedPointLatLon = selectedPointLatLon; - } - - public void setAxisGridPoints(Map axisGridPoints) { - this.axisGridPoints = axisGridPoints; - } - private boolean calculateBelongs(int ex, int ey, int objx, int objy, int radius) { return (Math.abs(objx - ex) <= radius * 2 && Math.abs(objy - ey) <= radius * 2); // return Math.abs(objx - ex) <= radius && (ey - objy) <= radius / 2 && (objy - ey) <= 3 * radius ; From dbd5da99ab9003c3679c3ed05203c13416ca05f3 Mon Sep 17 00:00:00 2001 From: PavelRatushny Date: Mon, 12 Jun 2017 14:36:37 +0300 Subject: [PATCH 09/11] Add points of chart for route --- .../net/osmand/plus/GpxSelectionHelper.java | 13 --- .../other/TrackDetailsMenu.java | 82 +++++++------------ .../src/net/osmand/plus/views/GPXLayer.java | 79 +++++++++++------- .../net/osmand/plus/views/MapInfoLayer.java | 14 ++-- .../src/net/osmand/plus/views/RouteLayer.java | 75 +++++++++++++---- 5 files changed, 142 insertions(+), 121 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java b/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java index 2184800571..0054d1bcaf 100644 --- a/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java +++ b/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java @@ -347,19 +347,6 @@ public class GpxSelectionHelper { return null; } - public SelectedGpxFile getSelectedFileFromDisplayItemByName(String name) { - SelectedGpxFile selectedGpxFile = null; - name = name.replaceAll(" ", "_").concat(".gpx"); - for (SelectedGpxFile s : selectedGPXFiles) { - String nameOfSelectedGpx = s.getGpxFile().path.replaceAll(" ", "_"); - nameOfSelectedGpx = nameOfSelectedGpx.substring(nameOfSelectedGpx.lastIndexOf("/") + 1, nameOfSelectedGpx.length()); - if (nameOfSelectedGpx.equals(name)) { - selectedGpxFile = s; - } - } - return selectedGpxFile; - } - public SelectedGpxFile getSelectedCurrentRecordingTrack() { for (SelectedGpxFile s : selectedGPXFiles) { if (s.isShowCurrentTrack()) { diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/TrackDetailsMenu.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/TrackDetailsMenu.java index f41dcea474..2bda41dd35 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/TrackDetailsMenu.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/TrackDetailsMenu.java @@ -2,6 +2,7 @@ package net.osmand.plus.mapcontextmenu.other; import android.graphics.Matrix; import android.support.v4.app.Fragment; +import android.support.v4.util.Pair; import android.support.v7.widget.PopupMenu; import android.view.MenuItem; import android.view.MotionEvent; @@ -12,7 +13,6 @@ import android.widget.TextView; import com.github.mikephil.charting.charts.LineChart; import com.github.mikephil.charting.data.Entry; import com.github.mikephil.charting.data.LineData; -import com.github.mikephil.charting.formatter.IAxisValueFormatter; import com.github.mikephil.charting.highlight.Highlight; import com.github.mikephil.charting.interfaces.datasets.ILineDataSet; import com.github.mikephil.charting.listener.ChartTouchListener.ChartGesture; @@ -26,6 +26,7 @@ import net.osmand.plus.GPXUtilities; import net.osmand.plus.GPXUtilities.GPXTrackAnalysis; import net.osmand.plus.GPXUtilities.TrkSegment; import net.osmand.plus.GPXUtilities.WptPt; +import net.osmand.plus.GPXUtilities.GPXFile; import net.osmand.plus.GpxSelectionHelper.GpxDisplayItem; import net.osmand.plus.IconsCache; import net.osmand.plus.OsmandApplication; @@ -44,9 +45,7 @@ import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; -import java.util.HashMap; import java.util.List; -import java.util.Map; public class TrackDetailsMenu { @@ -143,8 +142,8 @@ public class TrackDetailsMenu { mapActivity.hideTopToolbar(toolbarController); } mapActivity.getMapLayers().getContextMenuLayer().exitGpxDetailsMode(); - mapActivity.getMapLayers().getGpxLayer().setAxisValueDetails(null); - mapActivity.getMapLayers().getMapInfoLayer().setSelectedPointLatLon(null); + mapActivity.getMapLayers().getGpxLayer().setTrackChartPoints(null); + mapActivity.getMapLayers().getMapInfoLayer().setTrackChartPoints(null); mapActivity.getMapView().setMapPositionX(0); mapActivity.getMapView().refreshMap(); segment = null; @@ -290,13 +289,12 @@ public class TrackDetailsMenu { WptPt wpt = getPoint(chart, gpxItem.chartHighlightPos); if (wpt != null) { location = new LatLon(wpt.lat, wpt.lon); - List formattedAxisEntries = getFormattedAxisEntries(chart); - List axisGridPoints = getAxisGridPoints(chart); - AxisValueDetails axisValueDetails = new AxisValueDetails(axisGridPoints, formattedAxisEntries, location, getGpxItem()); + List> xAxisPoints = getXAxisPoints(chart); + TrackChartPoints trackChartPoints = new TrackChartPoints(xAxisPoints, location, getGpxItem().group.getGpx()); if (gpxItem.route) { - mapActivity.getMapLayers().getMapInfoLayer().setSelectedPointLatLon(location); + mapActivity.getMapLayers().getMapInfoLayer().setTrackChartPoints(trackChartPoints); } else { - mapActivity.getMapLayers().getGpxLayer().setAxisValueDetails(axisValueDetails); + mapActivity.getMapLayers().getGpxLayer().setTrackChartPoints(trackChartPoints); } } } else { @@ -305,29 +303,15 @@ public class TrackDetailsMenu { fitTrackOnMap(chart, location, forceFit); } - private List getAxisGridPoints (LineChart chart) { - List axisGridPoints = new ArrayList<>(); - float[] entries = chart.getXAxis().mEntries; - for (int i = 0; i < entries.length; i++) { - WptPt pointToAdd = getPoint(chart, entries[i]); - axisGridPoints.add(pointToAdd); - } - return axisGridPoints; - } - - private List getFormattedAxisEntries (LineChart chart) { + private List> getXAxisPoints(LineChart chart) { + List> xAxisPoints = new ArrayList<>(); float[] entries = chart.getXAxis().mEntries; - List formattedAxisEntries = new ArrayList<>(); - for (int i = 0; i < entries.length; i++) { - String formattedAxisEntry = ""; - if (gpxItem.chartAxisType == GPXDataSetAxisType.DISTANCE) { - formattedAxisEntry = String.format("%.1f", entries[i]); - } else if (gpxItem.chartAxisType == GPXDataSetAxisType.TIME) { - formattedAxisEntry = chart.getXAxis().getValueFormatter().getFormattedValue(entries[i], chart.getXAxis()); - } - formattedAxisEntries.add(formattedAxisEntry); - } - return formattedAxisEntries; + for (int i = 0; i < entries.length; i++) { + String formattedEntry = chart.getXAxis().getValueFormatter().getFormattedValue(entries[i], chart.getXAxis()); + WptPt pointToAdd = getPoint(chart, entries[i]); + xAxisPoints.add(new Pair<>(formattedEntry, pointToAdd)); + } + return xAxisPoints; } private void updateView(final View parentView) { @@ -592,33 +576,27 @@ public class TrackDetailsMenu { } } - public class AxisValueDetails { - private List axisGridPoints; - private List formattedAxisGridEntries; - private LatLon selectedPointLatLon; - private GpxDisplayItem gpxDisplayItem; + public class TrackChartPoints { + private List> xAxisPoints; + private LatLon highlightedPoint; + private GPXFile gpx; - public AxisValueDetails(List axisGridPoints, List formattedAxisGridEntries, LatLon selectedPointLatLon, GpxDisplayItem gpxDisplayItem) { - this.axisGridPoints = axisGridPoints; - this.formattedAxisGridEntries = formattedAxisGridEntries; - this.selectedPointLatLon = selectedPointLatLon; - this.gpxDisplayItem = gpxDisplayItem; + public TrackChartPoints(List> xAxisPoints, LatLon highlightedPoint, GPXFile gpx) { + this.xAxisPoints = xAxisPoints; + this.highlightedPoint = highlightedPoint; + this.gpx = gpx; } - public List getAxisGridPoints() { - return axisGridPoints; + public List> getXAxisPoints() { + return xAxisPoints; } - public List getFormattedAxisGridEntries() { - return formattedAxisGridEntries; + public LatLon getHighlightedPoint() { + return highlightedPoint; } - public LatLon getSelectedPointLatLon() { - return selectedPointLatLon; - } - - public GpxDisplayItem getGpxDisplayItem() { - return gpxDisplayItem; + public GPXFile getGpx() { + return gpx; } } } diff --git a/OsmAnd/src/net/osmand/plus/views/GPXLayer.java b/OsmAnd/src/net/osmand/plus/views/GPXLayer.java index b2fbb37c06..bd6f0de0e5 100644 --- a/OsmAnd/src/net/osmand/plus/views/GPXLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/GPXLayer.java @@ -17,6 +17,7 @@ import android.support.annotation.ColorInt; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v4.content.ContextCompat; +import android.support.v4.util.Pair; import net.osmand.data.LatLon; import net.osmand.data.PointDescription; @@ -36,7 +37,7 @@ import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandSettings.CommonPreference; import net.osmand.plus.R; import net.osmand.plus.base.FavoriteImageDrawable; -import net.osmand.plus.mapcontextmenu.other.TrackDetailsMenu.AxisValueDetails; +import net.osmand.plus.mapcontextmenu.other.TrackDetailsMenu.TrackChartPoints; import net.osmand.plus.render.OsmandRenderer; import net.osmand.plus.render.OsmandRenderer.RenderingContext; import net.osmand.plus.views.MapTextLayer.MapTextProvider; @@ -70,7 +71,7 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex private int currentTrackColor; private Bitmap selectedPoint; - private AxisValueDetails axisValueDetails; + private TrackChartPoints trackChartPoints; private static final int startZoom = 7; @@ -110,8 +111,8 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex initUI(); } - public void setAxisValueDetails(AxisValueDetails axisValueDetails) { - this.axisValueDetails = axisValueDetails; + public void setTrackChartPoints(TrackChartPoints trackChartPoints) { + this.trackChartPoints = trackChartPoints; } private void initUI() { @@ -366,15 +367,15 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex drawBigPoint(canvas, o, fileColor, x, y); } } - if (axisValueDetails != null) { - drawAxisGridPoints(canvas, tileBox); - LatLon selectedPointLatLon = axisValueDetails.getSelectedPointLatLon(); - if (selectedPointLatLon.getLatitude() >= latLonBounds.bottom - && selectedPointLatLon.getLatitude() <= latLonBounds.top - && selectedPointLatLon.getLongitude() >= latLonBounds.left - && selectedPointLatLon.getLongitude() <= latLonBounds.right) { - float x = tileBox.getPixXFromLatLon(selectedPointLatLon.getLatitude(), selectedPointLatLon.getLongitude()); - float y = tileBox.getPixYFromLatLon(selectedPointLatLon.getLatitude(), selectedPointLatLon.getLongitude()); + if (trackChartPoints != null) { + drawXAxisPoints(canvas, tileBox); + LatLon highlightedPoint = trackChartPoints.getHighlightedPoint(); + if (highlightedPoint.getLatitude() >= latLonBounds.bottom + && highlightedPoint.getLatitude() <= latLonBounds.top + && highlightedPoint.getLongitude() >= latLonBounds.left + && highlightedPoint.getLongitude() <= latLonBounds.right) { + float x = tileBox.getPixXFromLatLon(highlightedPoint.getLatitude(), highlightedPoint.getLongitude()); + float y = tileBox.getPixYFromLatLon(highlightedPoint.getLatitude(), highlightedPoint.getLongitude()); paintIcon.setColorFilter(null); canvas.drawBitmap(selectedPoint, x - selectedPoint.getWidth() / 2, y - selectedPoint.getHeight() / 2, paintIcon); } @@ -386,28 +387,44 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex } } - private void drawAxisGridPoints(Canvas canvas, RotatedTileBox tileBox) { + private void drawXAxisPoints(Canvas canvas, RotatedTileBox tileBox) { if (paintInnerRect.getColor() == 0) { - SelectedGpxFile selectedGpxFile = selectedGpxHelper.getSelectedFileFromDisplayItemByName((axisValueDetails.getGpxDisplayItem().group.getGpxName())); - GpxDataItem gpxDataItem = view.getApplication().getGpxDatabase().getItem(new File(selectedGpxFile.getGpxFile().path)); - paintInnerRect.setColor(gpxDataItem.getColor()); + SelectedGpxFile selectedGpxFile = selectedGpxHelper.getSelectedFileByPath((trackChartPoints.getGpx().path)); + GpxDataItem gpxDataItem = null; + if (!selectedGpxFile.isShowCurrentTrack()) { + gpxDataItem = view.getApplication().getGpxDatabase().getItem(new File(selectedGpxFile.getGpxFile().path)); + } + int color = gpxDataItem != null ? gpxDataItem.getColor() : 0; + if (selectedGpxFile.isShowCurrentTrack()) { + color = currentTrackColor; + } + if (color == 0) { + color = cachedColor; + } + paintInnerRect.setColor(color); } - List axisGridPoints = axisValueDetails.getAxisGridPoints(); - List formattedAxisGridEntries = axisValueDetails.getFormattedAxisGridEntries(); + QuadRect latLonBounds = tileBox.getLatLonBounds(); + List> xAxisPoints = trackChartPoints.getXAxisPoints(); float r = 12 * tileBox.getDensity(); paintGridTextIcon.setTextSize(r); - for (int i = 0; i < axisGridPoints.size(); i++) { - String textOnPoint = formattedAxisGridEntries.get(i); - float textWidth = paintGridTextIcon.measureText(textOnPoint); - float x = tileBox.getPixXFromLatLon(axisGridPoints.get(i).getLatitude(), axisGridPoints.get(i).getLongitude()); - float y = tileBox.getPixYFromLatLon(axisGridPoints.get(i).getLatitude(), axisGridPoints.get(i).getLongitude()); - canvas.drawRect( - x - textWidth / 2 - 2 * (float) Math.ceil(tileBox.getDensity()), - y - r / 2 - 2 * (float) Math.ceil(tileBox.getDensity()), - x + textWidth / 2 + 2 * (float) Math.ceil(tileBox.getDensity()), - y + r / 2 + 3 * (float) Math.ceil(tileBox.getDensity()), - paintInnerRect); - canvas.drawText(textOnPoint, x, y + r / 2, paintGridTextIcon); + for (int i = 0; i < xAxisPoints.size(); i++) { + WptPt axisPoint = xAxisPoints.get(i).second; + if (axisPoint.getLatitude() >= latLonBounds.bottom + && axisPoint.getLatitude() <= latLonBounds.top + && axisPoint.getLongitude() >= latLonBounds.left + && axisPoint.getLongitude() <= latLonBounds.right) { + String textOnPoint = xAxisPoints.get(i).first; + float textWidth = paintGridTextIcon.measureText(textOnPoint); + float x = tileBox.getPixXFromLatLon(axisPoint.getLatitude(), axisPoint.getLongitude()); + float y = tileBox.getPixYFromLatLon(axisPoint.getLatitude(), axisPoint.getLongitude()); + canvas.drawRect( + x - textWidth / 2 - 2 * (float) Math.ceil(tileBox.getDensity()), + y - r / 2 - 2 * (float) Math.ceil(tileBox.getDensity()), + x + textWidth / 2 + 2 * (float) Math.ceil(tileBox.getDensity()), + y + r / 2 + 3 * (float) Math.ceil(tileBox.getDensity()), + paintInnerRect); + canvas.drawText(textOnPoint, x, y + r / 2, paintGridTextIcon); + } } } diff --git a/OsmAnd/src/net/osmand/plus/views/MapInfoLayer.java b/OsmAnd/src/net/osmand/plus/views/MapInfoLayer.java index 8fdd297411..51d3b5a989 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapInfoLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/MapInfoLayer.java @@ -10,13 +10,13 @@ import android.view.View.OnClickListener; import android.widget.ImageButton; import android.widget.LinearLayout; -import net.osmand.data.LatLon; import net.osmand.data.RotatedTileBox; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.helpers.AndroidUiHelper; +import net.osmand.plus.mapcontextmenu.other.TrackDetailsMenu.TrackChartPoints; import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory; import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopTextView; import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarController; @@ -57,7 +57,7 @@ public class MapInfoLayer extends OsmandMapLayer { private TopTextView streetNameView; private TopToolbarView topToolbarView; - private LatLon selectedPointLatLon; + private TrackChartPoints trackChartPoints; public MapInfoLayer(MapActivity map, RouteLayer layer){ this.map = map; @@ -219,13 +219,9 @@ public class MapInfoLayer extends OsmandMapLayer { }); } - public LatLon getSelectedPointLatLon() { - return selectedPointLatLon; - } - - public void setSelectedPointLatLon(LatLon selectedPointLatLon) { - this.selectedPointLatLon = selectedPointLatLon; - routeLayer.setSelectedPointLatLon(selectedPointLatLon); + public void setTrackChartPoints(TrackChartPoints trackChartPoints) { + this.trackChartPoints = trackChartPoints; + routeLayer.setTrackChartPoints(trackChartPoints); } private static class TextState { diff --git a/OsmAnd/src/net/osmand/plus/views/RouteLayer.java b/OsmAnd/src/net/osmand/plus/views/RouteLayer.java index cd7670a738..0275bb574b 100644 --- a/OsmAnd/src/net/osmand/plus/views/RouteLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/RouteLayer.java @@ -13,7 +13,10 @@ import net.osmand.Location; import net.osmand.data.LatLon; import net.osmand.data.QuadRect; import net.osmand.data.RotatedTileBox; +import net.osmand.plus.GPXUtilities.WptPt; import net.osmand.plus.R; +import net.osmand.plus.mapcontextmenu.other.TrackDetailsMenu; +import net.osmand.plus.mapcontextmenu.other.TrackDetailsMenu.TrackChartPoints; import net.osmand.plus.routing.RouteCalculationResult; import net.osmand.plus.routing.RouteDirectionInfo; import net.osmand.plus.routing.RoutingHelper; @@ -29,6 +32,7 @@ import android.graphics.Path; import android.graphics.PointF; import android.graphics.PorterDuff.Mode; import android.graphics.PorterDuffColorFilter; +import android.support.v4.util.Pair; public class RouteLayer extends OsmandMapLayer { @@ -48,10 +52,12 @@ public class RouteLayer extends OsmandMapLayer { private Paint paintIcon; private Paint paintIconAction; + private Paint paintGridTextIcon; + private Paint paintInnerRect; private Paint paintIconSelected; private Bitmap selectedPoint; - private LatLon selectedPointLatLon; + private TrackChartPoints trackChartPoints; private RenderingLineAttributes attrs; @@ -60,12 +66,8 @@ public class RouteLayer extends OsmandMapLayer { this.helper = helper; } - public LatLon getSelectedPointLatLon() { - return selectedPointLatLon; - } - - public void setSelectedPointLatLon(LatLon selectedPointLatLon) { - this.selectedPointLatLon = selectedPointLatLon; + public void setTrackChartPoints(TrackDetailsMenu.TrackChartPoints trackChartPoints) { + this.trackChartPoints = trackChartPoints; } private void initUI() { @@ -77,7 +79,13 @@ public class RouteLayer extends OsmandMapLayer { paintIcon.setAntiAlias(true); paintIcon.setColor(Color.BLACK); paintIcon.setStrokeWidth(3); - + + paintGridTextIcon = new Paint(); + paintGridTextIcon.setTextAlign(Paint.Align.CENTER); + paintGridTextIcon.setFakeBoldText(true); + paintGridTextIcon.setColor(Color.WHITE); + paintGridTextIcon.setAntiAlias(true); + paintIconAction = new Paint(); paintIconAction.setFilterBitmap(true); paintIconAction.setAntiAlias(true); @@ -94,6 +102,11 @@ public class RouteLayer extends OsmandMapLayer { paintIconSelected = new Paint(); selectedPoint = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_default_location); + + paintInnerRect = new Paint(); + paintInnerRect.setStyle(Paint.Style.FILL_AND_STROKE); + paintInnerRect.setAntiAlias(true); + paintInnerRect.setColor(attrs.defaultColor); } @Override @@ -149,18 +162,48 @@ public class RouteLayer extends OsmandMapLayer { double lon = rightLongitude - leftLongitude + 0.1; drawLocations(tileBox, canvas, topLatitude + lat, leftLongitude - lon, bottomLatitude - lat, rightLongitude + lon); - if (selectedPointLatLon != null - && selectedPointLatLon.getLatitude() >= latlonRect.bottom - && selectedPointLatLon.getLatitude() <= latlonRect.top - && selectedPointLatLon.getLongitude() >= latlonRect.left - && selectedPointLatLon.getLongitude() <= latlonRect.right) { - float x = tileBox.getPixXFromLatLon(selectedPointLatLon.getLatitude(), selectedPointLatLon.getLongitude()); - float y = tileBox.getPixYFromLatLon(selectedPointLatLon.getLatitude(), selectedPointLatLon.getLongitude()); - canvas.drawBitmap(selectedPoint, x - selectedPoint.getWidth() / 2, y - selectedPoint.getHeight() / 2, paintIconSelected); + if (trackChartPoints != null) { + drawXAxisPoints(canvas, tileBox); + LatLon highlightedPoint = trackChartPoints.getHighlightedPoint(); + if (highlightedPoint != null + && highlightedPoint.getLatitude() >= latlonRect.bottom + && highlightedPoint.getLatitude() <= latlonRect.top + && highlightedPoint.getLongitude() >= latlonRect.left + && highlightedPoint.getLongitude() <= latlonRect.right) { + float x = tileBox.getPixXFromLatLon(highlightedPoint.getLatitude(), highlightedPoint.getLongitude()); + float y = tileBox.getPixYFromLatLon(highlightedPoint.getLatitude(), highlightedPoint.getLongitude()); + canvas.drawBitmap(selectedPoint, x - selectedPoint.getWidth() / 2, y - selectedPoint.getHeight() / 2, paintIconSelected); + } } } } + + private void drawXAxisPoints(Canvas canvas, RotatedTileBox tileBox) { + QuadRect latLonBounds = tileBox.getLatLonBounds(); + List> xAxisPoints = trackChartPoints.getXAxisPoints(); + float r = 12 * tileBox.getDensity(); + paintGridTextIcon.setTextSize(r); + for (int i = 0; i < xAxisPoints.size(); i++) { + WptPt axisPoint = xAxisPoints.get(i).second; + if (axisPoint.getLatitude() >= latLonBounds.bottom + && axisPoint.getLatitude() <= latLonBounds.top + && axisPoint.getLongitude() >= latLonBounds.left + && axisPoint.getLongitude() <= latLonBounds.right) { + String textOnPoint = xAxisPoints.get(i).first; + float textWidth = paintGridTextIcon.measureText(textOnPoint); + float x = tileBox.getPixXFromLatLon(axisPoint.getLatitude(), axisPoint.getLongitude()); + float y = tileBox.getPixYFromLatLon(axisPoint.getLatitude(), axisPoint.getLongitude()); + canvas.drawRect( + x - textWidth / 2 - 2 * (float) Math.ceil(tileBox.getDensity()), + y - r / 2 - 2 * (float) Math.ceil(tileBox.getDensity()), + x + textWidth / 2 + 2 * (float) Math.ceil(tileBox.getDensity()), + y + r / 2 + 3 * (float) Math.ceil(tileBox.getDensity()), + paintInnerRect); + canvas.drawText(textOnPoint, x, y + r / 2, paintGridTextIcon); + } + } + } @Override public void onDraw(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) {} From b1630e017f06aa42e3de3ef61dd4a526dd2f0228 Mon Sep 17 00:00:00 2001 From: PavelRatushny Date: Mon, 12 Jun 2017 17:37:55 +0300 Subject: [PATCH 10/11] Fix segment color --- .../other/TrackDetailsMenu.java | 18 ++++++++---- .../src/net/osmand/plus/views/GPXLayer.java | 28 ++++++++----------- 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/TrackDetailsMenu.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/TrackDetailsMenu.java index 2bda41dd35..41d9a4ecdd 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/TrackDetailsMenu.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/TrackDetailsMenu.java @@ -290,7 +290,7 @@ public class TrackDetailsMenu { if (wpt != null) { location = new LatLon(wpt.lat, wpt.lon); List> xAxisPoints = getXAxisPoints(chart); - TrackChartPoints trackChartPoints = new TrackChartPoints(xAxisPoints, location, getGpxItem().group.getGpx()); + TrackChartPoints trackChartPoints = new TrackChartPoints(xAxisPoints, location, getTrackSegment(chart), getGpxItem().group.getGpx().path); if (gpxItem.route) { mapActivity.getMapLayers().getMapInfoLayer().setTrackChartPoints(trackChartPoints); } else { @@ -579,12 +579,14 @@ public class TrackDetailsMenu { public class TrackChartPoints { private List> xAxisPoints; private LatLon highlightedPoint; - private GPXFile gpx; + private TrkSegment chartSegment; + private String gpxPath; - public TrackChartPoints(List> xAxisPoints, LatLon highlightedPoint, GPXFile gpx) { + public TrackChartPoints(List> xAxisPoints, LatLon highlightedPoint, TrkSegment chartSegment, String gpxPath) { this.xAxisPoints = xAxisPoints; this.highlightedPoint = highlightedPoint; - this.gpx = gpx; + this.chartSegment = chartSegment; + this.gpxPath = gpxPath; } public List> getXAxisPoints() { @@ -595,8 +597,12 @@ public class TrackDetailsMenu { return highlightedPoint; } - public GPXFile getGpx() { - return gpx; + public TrkSegment getChartSegment() { + return chartSegment; + } + + public String getGpxPath() { + return gpxPath; } } } diff --git a/OsmAnd/src/net/osmand/plus/views/GPXLayer.java b/OsmAnd/src/net/osmand/plus/views/GPXLayer.java index bd6f0de0e5..6e71985779 100644 --- a/OsmAnd/src/net/osmand/plus/views/GPXLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/GPXLayer.java @@ -379,8 +379,6 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex paintIcon.setColorFilter(null); canvas.drawBitmap(selectedPoint, x - selectedPoint.getWidth() / 2, y - selectedPoint.getHeight() / 2, paintIcon); } - } else if (paintInnerRect.getColor() != 0){ - paintInnerRect.setColor(0); } this.fullObjectsLatLon = fullObjectsLatLon; this.smallObjectsLatLon = smallObjectsLatLon; @@ -388,21 +386,19 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex } private void drawXAxisPoints(Canvas canvas, RotatedTileBox tileBox) { - if (paintInnerRect.getColor() == 0) { - SelectedGpxFile selectedGpxFile = selectedGpxHelper.getSelectedFileByPath((trackChartPoints.getGpx().path)); - GpxDataItem gpxDataItem = null; - if (!selectedGpxFile.isShowCurrentTrack()) { - gpxDataItem = view.getApplication().getGpxDatabase().getItem(new File(selectedGpxFile.getGpxFile().path)); - } - int color = gpxDataItem != null ? gpxDataItem.getColor() : 0; - if (selectedGpxFile.isShowCurrentTrack()) { - color = currentTrackColor; - } - if (color == 0) { - color = cachedColor; - } - paintInnerRect.setColor(color); + SelectedGpxFile selectedGpxFile = selectedGpxHelper.getSelectedFileByPath((trackChartPoints.getGpxPath())); + GpxDataItem gpxDataItem = null; + if (!selectedGpxFile.isShowCurrentTrack()) { + gpxDataItem = view.getApplication().getGpxDatabase().getItem(new File(selectedGpxFile.getGpxFile().path)); } + int color = gpxDataItem != null ? gpxDataItem.getColor() : 0; + if (selectedGpxFile.isShowCurrentTrack()) { + color = currentTrackColor; + } + if (color == 0) { + color = trackChartPoints.getChartSegment().getColor(cachedColor); + } + paintInnerRect.setColor(color); QuadRect latLonBounds = tileBox.getLatLonBounds(); List> xAxisPoints = trackChartPoints.getXAxisPoints(); float r = 12 * tileBox.getDensity(); From 774fcd0c8f858f42c910c4508dfef11065428892 Mon Sep 17 00:00:00 2001 From: PavelRatushny Date: Mon, 12 Jun 2017 18:59:20 +0300 Subject: [PATCH 11/11] Add color to track chart points --- .../other/TrackDetailsMenu.java | 24 +++++++++++-------- .../src/net/osmand/plus/views/GPXLayer.java | 22 +++++++++-------- 2 files changed, 26 insertions(+), 20 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/TrackDetailsMenu.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/TrackDetailsMenu.java index 41d9a4ecdd..20ce9dee7e 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/TrackDetailsMenu.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/TrackDetailsMenu.java @@ -53,6 +53,7 @@ public class TrackDetailsMenu { private GpxDisplayItem gpxItem; private TrackDetailsBarController toolbarController; private TrkSegment segment; + private int segmentColor; private static boolean VISIBLE; @@ -290,7 +291,10 @@ public class TrackDetailsMenu { if (wpt != null) { location = new LatLon(wpt.lat, wpt.lon); List> xAxisPoints = getXAxisPoints(chart); - TrackChartPoints trackChartPoints = new TrackChartPoints(xAxisPoints, location, getTrackSegment(chart), getGpxItem().group.getGpx().path); + if (segmentColor == 0) { + segmentColor = getTrackSegment(chart).getColor(0); + } + TrackChartPoints trackChartPoints = new TrackChartPoints(xAxisPoints, location, segmentColor, getGpxItem().group.getGpx()); if (gpxItem.route) { mapActivity.getMapLayers().getMapInfoLayer().setTrackChartPoints(trackChartPoints); } else { @@ -579,14 +583,14 @@ public class TrackDetailsMenu { public class TrackChartPoints { private List> xAxisPoints; private LatLon highlightedPoint; - private TrkSegment chartSegment; - private String gpxPath; + private int segmentColor; + private GPXFile gpx; - public TrackChartPoints(List> xAxisPoints, LatLon highlightedPoint, TrkSegment chartSegment, String gpxPath) { + public TrackChartPoints(List> xAxisPoints, LatLon highlightedPoint, int segmentColor, GPXFile gpx) { this.xAxisPoints = xAxisPoints; this.highlightedPoint = highlightedPoint; - this.chartSegment = chartSegment; - this.gpxPath = gpxPath; + this.segmentColor = segmentColor; + this.gpx = gpx; } public List> getXAxisPoints() { @@ -597,12 +601,12 @@ public class TrackDetailsMenu { return highlightedPoint; } - public TrkSegment getChartSegment() { - return chartSegment; + public int getSegmentColor() { + return segmentColor; } - public String getGpxPath() { - return gpxPath; + public GPXFile getGpx() { + return gpx; } } } diff --git a/OsmAnd/src/net/osmand/plus/views/GPXLayer.java b/OsmAnd/src/net/osmand/plus/views/GPXLayer.java index 6e71985779..5b3fad2a66 100644 --- a/OsmAnd/src/net/osmand/plus/views/GPXLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/GPXLayer.java @@ -386,17 +386,19 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex } private void drawXAxisPoints(Canvas canvas, RotatedTileBox tileBox) { - SelectedGpxFile selectedGpxFile = selectedGpxHelper.getSelectedFileByPath((trackChartPoints.getGpxPath())); - GpxDataItem gpxDataItem = null; - if (!selectedGpxFile.isShowCurrentTrack()) { - gpxDataItem = view.getApplication().getGpxDatabase().getItem(new File(selectedGpxFile.getGpxFile().path)); - } - int color = gpxDataItem != null ? gpxDataItem.getColor() : 0; - if (selectedGpxFile.isShowCurrentTrack()) { - color = currentTrackColor; - } + int color = trackChartPoints.getSegmentColor(); if (color == 0) { - color = trackChartPoints.getChartSegment().getColor(cachedColor); + GpxDataItem gpxDataItem = null; + if (!trackChartPoints.getGpx().showCurrentTrack) { + gpxDataItem = view.getApplication().getGpxDatabase().getItem(new File(trackChartPoints.getGpx().path)); + } + color = gpxDataItem != null ? gpxDataItem.getColor() : 0; + if (trackChartPoints.getGpx().showCurrentTrack) { + color = currentTrackColor; + } + if (color == 0) { + color = cachedColor; + } } paintInnerRect.setColor(color); QuadRect latLonBounds = tileBox.getLatLonBounds();