Merge remote-tracking branch 'origin/master'

This commit is contained in:
Weblate 2017-06-19 10:31:05 +02:00
commit 159a9a46f1
3 changed files with 60 additions and 77 deletions

View file

@ -2,7 +2,6 @@ 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;
@ -11,6 +10,7 @@ import android.widget.ImageView;
import android.widget.TextView;
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.LineData;
import com.github.mikephil.charting.highlight.Highlight;
@ -18,6 +18,7 @@ import com.github.mikephil.charting.interfaces.datasets.ILineDataSet;
import com.github.mikephil.charting.listener.ChartTouchListener.ChartGesture;
import com.github.mikephil.charting.listener.OnChartGestureListener;
import com.github.mikephil.charting.listener.OnChartValueSelectedListener;
import com.github.mikephil.charting.utils.ViewPortHandler;
import net.osmand.data.LatLon;
import net.osmand.data.QuadRect;
@ -286,8 +287,19 @@ public class TrackDetailsMenu {
private void refreshChart(LineChart chart, boolean forceFit) {
Highlight[] highlights = chart.getHighlighted();
LatLon location = null;
ViewPortHandler handler = chart.getViewPortHandler();
float minimumVisibleXValue = (float) chart.getValuesByTouchPoint(handler.contentLeft(), handler.contentBottom(), YAxis.AxisDependency.LEFT).x;
float maximumVisibleXValue = (float) chart.getValuesByTouchPoint(handler.contentRight(), handler.contentBottom(), YAxis.AxisDependency.LEFT).x;
if (highlights != null && highlights.length > 0) {
if (highlights[0].getX() < minimumVisibleXValue) {
gpxItem.chartHighlightPos = minimumVisibleXValue;
} else if (highlights[0].getX() > maximumVisibleXValue) {
gpxItem.chartHighlightPos = maximumVisibleXValue;
} else {
gpxItem.chartHighlightPos = highlights[0].getX();
}
WptPt wpt = getPoint(chart, gpxItem.chartHighlightPos);
if (wpt != null) {
if (trackChartPoints == null) {
@ -297,7 +309,7 @@ public class TrackDetailsMenu {
trackChartPoints.setGpx(getGpxItem().group.getGpx());
}
location = new LatLon(wpt.lat, wpt.lon);
List<Pair<String, WptPt>> xAxisPoints = getXAxisPoints(chart);
List<WptPt> xAxisPoints = getXAxisPoints(chart);
trackChartPoints.setHighlightedPoint(location);
trackChartPoints.setXAxisPoints(xAxisPoints);
if (gpxItem.route) {
@ -312,13 +324,12 @@ public class TrackDetailsMenu {
fitTrackOnMap(chart, location, forceFit);
}
private List<Pair<String, WptPt>> getXAxisPoints(LineChart chart) {
List<Pair<String, WptPt>> xAxisPoints = new ArrayList<>();
private List<WptPt> getXAxisPoints(LineChart chart) {
List<WptPt> xAxisPoints = new ArrayList<>();
float[] entries = chart.getXAxis().mEntries;
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));
xAxisPoints.add(pointToAdd);
}
return xAxisPoints;
}
@ -586,12 +597,12 @@ public class TrackDetailsMenu {
}
public class TrackChartPoints {
private List<Pair<String, WptPt>> xAxisPoints;
private List<WptPt> xAxisPoints;
private LatLon highlightedPoint;
private int segmentColor;
private GPXFile gpx;
public List<Pair<String, WptPt>> getXAxisPoints() {
public List<WptPt> getXAxisPoints() {
return xAxisPoints;
}
@ -607,7 +618,7 @@ public class TrackDetailsMenu {
return gpx;
}
public void setXAxisPoints(List<Pair<String, WptPt>> xAxisPoints) {
public void setXAxisPoints(List<WptPt> xAxisPoints) {
this.xAxisPoints = xAxisPoints;
}

View file

@ -17,7 +17,6 @@ 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;
@ -82,15 +81,11 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
private Map<WptPt, SelectedGpxFile> pointFileMap = new HashMap<>();
private MapTextLayer textLayer;
private Paint paintOuter;
private Paint paintInnerCircle;
private Paint paintInnerRect;
private Paint paintTextIcon;
private Paint paintGridCircle;
private Paint paintGridTextIcon;
private Paint paintTextIcon;
private OsmandRenderer osmandRenderer;
@ -138,28 +133,17 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
paintTextIcon.setTextSize(10 * view.getDensity());
paintTextIcon.setTextAlign(Align.CENTER);
paintTextIcon.setFakeBoldText(true);
paintTextIcon.setColor(Color.BLACK);
paintTextIcon.setColor(Color.WHITE);
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();
paintOuter.setColor(0x88555555);
paintOuter.setAntiAlias(true);
paintOuter.setStyle(Style.FILL_AND_STROKE);
paintInnerCircle = new Paint();
paintInnerCircle.setStyle(Style.FILL_AND_STROKE);
paintInnerCircle.setColor(0xddFFFFFF);
paintInnerCircle.setAntiAlias(true);
paintInnerRect = new Paint();
paintInnerRect.setStyle(Style.FILL_AND_STROKE);
paintInnerRect.setAntiAlias(true);
paintGridCircle = new Paint();
paintGridCircle.setStyle(Style.FILL_AND_STROKE);
paintGridCircle.setAntiAlias(true);
paintIcon = new Paint();
pointSmall = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_white_shield_small);
@ -196,6 +180,9 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
if (!selectedGPXFiles.isEmpty()) {
drawSelectedFilesSegments(canvas, tileBox, selectedGPXFiles, settings);
canvas.rotate(-tileBox.getRotate(), tileBox.getCenterPixelX(), tileBox.getCenterPixelY());
if (trackChartPoints != null) {
drawXAxisPoints(canvas, tileBox);
}
drawSelectedFilesSplits(canvas, tileBox, selectedGPXFiles, settings);
drawSelectedFilesPoints(canvas, tileBox, selectedGPXFiles);
}
@ -278,6 +265,13 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
List<GpxDisplayGroup> groups = g.getDisplayGroups();
if (groups != null) {
for (GpxDisplayGroup group : groups) {
int color = g.getModifiableGpxFile().getColor(0);
if (color == 0 || color == Color.RED) {
GpxDataItem gpxDataItem = view.getApplication().getGpxDatabase().getItem(new File(g.getGpxFile().path));
color = gpxDataItem.getColor();
}
paintInnerRect.setColor(color);
paintInnerRect.setAlpha(179);
List<GpxDisplayItem> items = group.getModifiableList();
drawSplitItems(canvas, tileBox, items, settings);
}
@ -289,6 +283,7 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
private void drawSplitItems(Canvas canvas, RotatedTileBox tileBox, List<GpxDisplayItem> items, DrawSettings settings) {
final QuadRect latLonBounds = tileBox.getLatLonBounds();
int r = (int) (12 * tileBox.getDensity());
paintTextIcon.setTextSize(r);
int dr = r * 3 / 2;
int px = -1;
int py = -1;
@ -312,9 +307,13 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
if (ind > 0) {
nm = nm.substring(0, ind);
}
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);
float nmWidth = paintTextIcon.measureText(nm);
canvas.drawRect(
x - nmWidth / 2 - 2 * (float) Math.ceil(tileBox.getDensity()),
y - r / 2 - 2 * (float) Math.ceil(tileBox.getDensity()),
x + nmWidth / 2 + 2 * (float) Math.ceil(tileBox.getDensity()),
y + r / 2 + 3 * (float) Math.ceil(tileBox.getDensity()),
paintInnerRect);
canvas.drawText(nm, x, y + r / 2, paintTextIcon);
}
}
@ -364,7 +363,6 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
}
}
if (trackChartPoints != null) {
drawXAxisPoints(canvas, tileBox);
LatLon highlightedPoint = trackChartPoints.getHighlightedPoint();
if (highlightedPoint.getLatitude() >= latLonBounds.bottom
&& highlightedPoint.getLatitude() <= latLonBounds.top
@ -397,28 +395,19 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
}
trackChartPoints.setSegmentColor(color);
}
paintInnerRect.setColor(color);
paintGridCircle.setColor(color);
QuadRect latLonBounds = tileBox.getLatLonBounds();
List<Pair<String, WptPt>> xAxisPoints = trackChartPoints.getXAxisPoints();
float r = 12 * tileBox.getDensity();
paintGridTextIcon.setTextSize(r);
List<WptPt> xAxisPoints = trackChartPoints.getXAxisPoints();
float r = 3 * tileBox.getDensity();
for (int i = 0; i < xAxisPoints.size(); i++) {
WptPt axisPoint = xAxisPoints.get(i).second;
WptPt axisPoint = xAxisPoints.get(i);
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);
canvas.drawCircle(x, y, r + (float) Math.ceil(tileBox.getDensity()), paintGridCircle);
}
}
}

View file

@ -32,7 +32,6 @@ 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 {
@ -52,8 +51,7 @@ public class RouteLayer extends OsmandMapLayer {
private Paint paintIcon;
private Paint paintIconAction;
private Paint paintGridTextIcon;
private Paint paintInnerRect;
private Paint paintGridCircle;
private Paint paintIconSelected;
private Bitmap selectedPoint;
@ -80,12 +78,6 @@ public class RouteLayer extends OsmandMapLayer {
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);
@ -103,10 +95,10 @@ 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);
paintGridCircle = new Paint();
paintGridCircle.setStyle(Paint.Style.FILL_AND_STROKE);
paintGridCircle.setAntiAlias(true);
paintGridCircle.setColor(attrs.defaultColor);
}
@Override
@ -177,26 +169,17 @@ public class RouteLayer extends OsmandMapLayer {
private void drawXAxisPoints(Canvas canvas, RotatedTileBox tileBox) {
QuadRect latLonBounds = tileBox.getLatLonBounds();
List<Pair<String, WptPt>> xAxisPoints = trackChartPoints.getXAxisPoints();
float r = 12 * tileBox.getDensity();
paintGridTextIcon.setTextSize(r);
List<WptPt> xAxisPoints = trackChartPoints.getXAxisPoints();
float r = 3 * tileBox.getDensity();
for (int i = 0; i < xAxisPoints.size(); i++) {
WptPt axisPoint = xAxisPoints.get(i).second;
WptPt axisPoint = xAxisPoints.get(i);
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);
canvas.drawCircle(x, y, r + (float) Math.ceil(tileBox.getDensity()), paintGridCircle);
}
}
}