Merge pull request #3946 from osmandapp/gpx_improvements

Gpx improvements
This commit is contained in:
Alexey 2017-06-21 12:25:08 +03:00 committed by GitHub
commit 11c35cf0e2
3 changed files with 49 additions and 19 deletions

View file

@ -10,7 +10,6 @@ import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
import com.github.mikephil.charting.charts.LineChart; import com.github.mikephil.charting.charts.LineChart;
import com.github.mikephil.charting.components.YAxis;
import com.github.mikephil.charting.data.Entry; import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.data.LineData; import com.github.mikephil.charting.data.LineData;
import com.github.mikephil.charting.highlight.Highlight; import com.github.mikephil.charting.highlight.Highlight;
@ -18,7 +17,6 @@ import com.github.mikephil.charting.interfaces.datasets.ILineDataSet;
import com.github.mikephil.charting.listener.ChartTouchListener.ChartGesture; import com.github.mikephil.charting.listener.ChartTouchListener.ChartGesture;
import com.github.mikephil.charting.listener.OnChartGestureListener; import com.github.mikephil.charting.listener.OnChartGestureListener;
import com.github.mikephil.charting.listener.OnChartValueSelectedListener; import com.github.mikephil.charting.listener.OnChartValueSelectedListener;
import com.github.mikephil.charting.utils.ViewPortHandler;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
import net.osmand.data.QuadRect; import net.osmand.data.QuadRect;
@ -288,11 +286,11 @@ public class TrackDetailsMenu {
Highlight[] highlights = chart.getHighlighted(); Highlight[] highlights = chart.getHighlighted();
LatLon location = null; LatLon location = null;
ViewPortHandler handler = chart.getViewPortHandler(); float minimumVisibleXValue = chart.getLowestVisibleX();
float minimumVisibleXValue = (float) chart.getValuesByTouchPoint(handler.contentLeft(), handler.contentBottom(), YAxis.AxisDependency.LEFT).x; float maximumVisibleXValue = chart.getHighestVisibleX();
float maximumVisibleXValue = (float) chart.getValuesByTouchPoint(handler.contentRight(), handler.contentBottom(), YAxis.AxisDependency.LEFT).x;
if (highlights != null && highlights.length > 0) { if (highlights != null && highlights.length > 0) {
if (minimumVisibleXValue != 0 && maximumVisibleXValue != 0) {
if (highlights[0].getX() < minimumVisibleXValue) { if (highlights[0].getX() < minimumVisibleXValue) {
gpxItem.chartHighlightPos = minimumVisibleXValue; gpxItem.chartHighlightPos = minimumVisibleXValue;
} else if (highlights[0].getX() > maximumVisibleXValue) { } else if (highlights[0].getX() > maximumVisibleXValue) {
@ -300,6 +298,9 @@ public class TrackDetailsMenu {
} else { } else {
gpxItem.chartHighlightPos = highlights[0].getX(); gpxItem.chartHighlightPos = highlights[0].getX();
} }
} else {
gpxItem.chartHighlightPos = highlights[0].getX();
}
WptPt wpt = getPoint(chart, gpxItem.chartHighlightPos); WptPt wpt = getPoint(chart, gpxItem.chartHighlightPos);
if (wpt != null) { if (wpt != null) {
if (trackChartPoints == null) { if (trackChartPoints == null) {
@ -572,7 +573,8 @@ public class TrackDetailsMenu {
if (gpxItem.chartHighlightPos != -1) { if (gpxItem.chartHighlightPos != -1) {
chart.highlightValue(gpxItem.chartHighlightPos, 0); chart.highlightValue(gpxItem.chartHighlightPos, 0);
} else { } else {
chart.highlightValue(null); gpxItem.chartHighlightPos = chart.getLowestVisibleX();
chart.highlightValue(chart.getLowestVisibleX(), 0);
} }
} }

View file

@ -12,6 +12,8 @@ import android.graphics.PointF;
import android.graphics.PorterDuff; import android.graphics.PorterDuff;
import android.graphics.PorterDuff.Mode; import android.graphics.PorterDuff.Mode;
import android.graphics.PorterDuffColorFilter; import android.graphics.PorterDuffColorFilter;
import android.graphics.Rect;
import android.graphics.RectF;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.support.annotation.ColorInt; import android.support.annotation.ColorInt;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
@ -81,8 +83,10 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
private Map<WptPt, SelectedGpxFile> pointFileMap = new HashMap<>(); private Map<WptPt, SelectedGpxFile> pointFileMap = new HashMap<>();
private MapTextLayer textLayer; private MapTextLayer textLayer;
private Paint paintOuterRect;
private Paint paintInnerRect; private Paint paintInnerRect;
private Paint paintGridOuterCircle;
private Paint paintGridCircle; private Paint paintGridCircle;
private Paint paintTextIcon; private Paint paintTextIcon;
@ -139,11 +143,22 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
textLayer = view.getLayerByClass(MapTextLayer.class); textLayer = view.getLayerByClass(MapTextLayer.class);
paintInnerRect = new Paint(); paintInnerRect = new Paint();
paintInnerRect.setStyle(Style.FILL_AND_STROKE); paintInnerRect.setStyle(Style.FILL);
paintInnerRect.setAntiAlias(true); paintInnerRect.setAntiAlias(true);
paintOuterRect = new Paint();
paintOuterRect.setStyle(Style.STROKE);
paintOuterRect.setAntiAlias(true);
paintOuterRect.setColor(Color.WHITE);
paintOuterRect.setStrokeWidth(3);
paintOuterRect.setAlpha(255);
paintGridCircle = new Paint(); paintGridCircle = new Paint();
paintGridCircle.setStyle(Style.FILL_AND_STROKE); paintGridCircle.setStyle(Style.FILL_AND_STROKE);
paintGridCircle.setAntiAlias(true); paintGridCircle.setAntiAlias(true);
paintGridOuterCircle = new Paint();
paintGridOuterCircle.setStyle(Style.FILL_AND_STROKE);
paintGridOuterCircle.setAntiAlias(true);
paintGridOuterCircle.setColor(Color.WHITE);
paintGridOuterCircle.setAlpha(204);
paintIcon = new Paint(); paintIcon = new Paint();
pointSmall = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_white_shield_small); pointSmall = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_white_shield_small);
@ -307,14 +322,17 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
if (ind > 0) { if (ind > 0) {
nm = nm.substring(0, ind); nm = nm.substring(0, ind);
} }
float nmWidth = paintTextIcon.measureText(nm); Rect bounds = new Rect();
canvas.drawRect( paintTextIcon.getTextBounds(nm, 0, nm.length(), bounds);
x - nmWidth / 2 - 2 * (float) Math.ceil(tileBox.getDensity()), int nmWidth = bounds.width();
y - r / 2 - 2 * (float) Math.ceil(tileBox.getDensity()), int nmHeight = bounds.height();
x + nmWidth / 2 + 2 * (float) Math.ceil(tileBox.getDensity()), RectF rect = new RectF(x - nmWidth / 2 - 2 * (float) Math.ceil(tileBox.getDensity()),
y + r / 2 + 3 * (float) Math.ceil(tileBox.getDensity()), y + nmHeight / 2 + 3 * (float) Math.ceil(tileBox.getDensity()),
paintInnerRect); x + nmWidth / 2 + 3 * (float) Math.ceil(tileBox.getDensity()),
canvas.drawText(nm, x, y + r / 2, paintTextIcon); y - nmHeight / 2 - 2 * (float) Math.ceil(tileBox.getDensity()));
canvas.drawRoundRect(rect, 5, 5, paintInnerRect);
canvas.drawRoundRect(rect, 5, 5, paintOuterRect);
canvas.drawText(nm, x, y + nmHeight / 2, paintTextIcon);
} }
} }
} }
@ -396,6 +414,7 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
trackChartPoints.setSegmentColor(color); trackChartPoints.setSegmentColor(color);
} }
paintGridCircle.setColor(color); paintGridCircle.setColor(color);
paintGridCircle.setAlpha(255);
QuadRect latLonBounds = tileBox.getLatLonBounds(); QuadRect latLonBounds = tileBox.getLatLonBounds();
List<WptPt> xAxisPoints = trackChartPoints.getXAxisPoints(); List<WptPt> xAxisPoints = trackChartPoints.getXAxisPoints();
float r = 3 * tileBox.getDensity(); float r = 3 * tileBox.getDensity();
@ -407,6 +426,7 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
&& axisPoint.getLongitude() <= latLonBounds.right) { && axisPoint.getLongitude() <= latLonBounds.right) {
float x = tileBox.getPixXFromLatLon(axisPoint.getLatitude(), axisPoint.getLongitude()); float x = tileBox.getPixXFromLatLon(axisPoint.getLatitude(), axisPoint.getLongitude());
float y = tileBox.getPixYFromLatLon(axisPoint.getLatitude(), axisPoint.getLongitude()); float y = tileBox.getPixYFromLatLon(axisPoint.getLatitude(), axisPoint.getLongitude());
canvas.drawCircle(x, y, r + 2 * (float) Math.ceil(tileBox.getDensity()), paintGridOuterCircle);
canvas.drawCircle(x, y, r + (float) Math.ceil(tileBox.getDensity()), paintGridCircle); canvas.drawCircle(x, y, r + (float) Math.ceil(tileBox.getDensity()), paintGridCircle);
} }
} }

View file

@ -51,6 +51,7 @@ public class RouteLayer extends OsmandMapLayer {
private Paint paintIcon; private Paint paintIcon;
private Paint paintIconAction; private Paint paintIconAction;
private Paint paintGridOuterCircle;
private Paint paintGridCircle; private Paint paintGridCircle;
private Paint paintIconSelected; private Paint paintIconSelected;
@ -99,6 +100,12 @@ public class RouteLayer extends OsmandMapLayer {
paintGridCircle.setStyle(Paint.Style.FILL_AND_STROKE); paintGridCircle.setStyle(Paint.Style.FILL_AND_STROKE);
paintGridCircle.setAntiAlias(true); paintGridCircle.setAntiAlias(true);
paintGridCircle.setColor(attrs.defaultColor); paintGridCircle.setColor(attrs.defaultColor);
paintGridCircle.setAlpha(255);
paintGridOuterCircle = new Paint();
paintGridOuterCircle.setStyle(Paint.Style.FILL_AND_STROKE);
paintGridOuterCircle.setAntiAlias(true);
paintGridOuterCircle.setColor(Color.WHITE);
paintGridOuterCircle.setAlpha(204);
} }
@Override @Override
@ -179,6 +186,7 @@ public class RouteLayer extends OsmandMapLayer {
&& axisPoint.getLongitude() <= latLonBounds.right) { && axisPoint.getLongitude() <= latLonBounds.right) {
float x = tileBox.getPixXFromLatLon(axisPoint.getLatitude(), axisPoint.getLongitude()); float x = tileBox.getPixXFromLatLon(axisPoint.getLatitude(), axisPoint.getLongitude());
float y = tileBox.getPixYFromLatLon(axisPoint.getLatitude(), axisPoint.getLongitude()); float y = tileBox.getPixYFromLatLon(axisPoint.getLatitude(), axisPoint.getLongitude());
canvas.drawCircle(x, y, r + 2 * (float) Math.ceil(tileBox.getDensity()), paintGridOuterCircle);
canvas.drawCircle(x, y, r + (float) Math.ceil(tileBox.getDensity()), paintGridCircle); canvas.drawCircle(x, y, r + (float) Math.ceil(tileBox.getDensity()), paintGridCircle);
} }
} }