Merge remote-tracking branch 'origin/master'

This commit is contained in:
Weblate 2017-06-13 18:21:32 +02:00
commit ef50bfc4fd
4 changed files with 205 additions and 48 deletions

View file

@ -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;
@ -25,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;
@ -51,6 +53,7 @@ public class TrackDetailsMenu {
private GpxDisplayItem gpxItem;
private TrackDetailsBarController toolbarController;
private TrkSegment segment;
private TrackChartPoints trackChartPoints;
private static boolean VISIBLE;
@ -140,11 +143,12 @@ public class TrackDetailsMenu {
mapActivity.hideTopToolbar(toolbarController);
}
mapActivity.getMapLayers().getContextMenuLayer().exitGpxDetailsMode();
mapActivity.getMapLayers().getGpxLayer().setSelectedPointLatLon(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;
trackChartPoints = null;
}
public void updateInfo(final View main) {
@ -286,11 +290,20 @@ public class TrackDetailsMenu {
gpxItem.chartHighlightPos = highlights[0].getX();
WptPt wpt = getPoint(chart, gpxItem.chartHighlightPos);
if (wpt != null) {
if (trackChartPoints == null) {
trackChartPoints = new TrackChartPoints();
int segmentColor = getTrackSegment(chart).getColor(0);
trackChartPoints.setSegmentColor(segmentColor);
trackChartPoints.setGpx(getGpxItem().group.getGpx());
}
location = new LatLon(wpt.lat, wpt.lon);
List<Pair<String, WptPt>> xAxisPoints = getXAxisPoints(chart);
trackChartPoints.setHighlightedPoint(location);
trackChartPoints.setXAxisPoints(xAxisPoints);
if (gpxItem.route) {
mapActivity.getMapLayers().getMapInfoLayer().setSelectedPointLatLon(location);
mapActivity.getMapLayers().getMapInfoLayer().setTrackChartPoints(trackChartPoints);
} else {
mapActivity.getMapLayers().getGpxLayer().setSelectedPointLatLon(location);
mapActivity.getMapLayers().getGpxLayer().setTrackChartPoints(trackChartPoints);
}
}
} else {
@ -299,6 +312,17 @@ public class TrackDetailsMenu {
fitTrackOnMap(chart, location, forceFit);
}
private List<Pair<String, WptPt>> getXAxisPoints(LineChart chart) {
List<Pair<String, 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));
}
return xAxisPoints;
}
private void updateView(final View parentView) {
GPXTrackAnalysis analysis = gpxItem.analysis;
if (analysis == null || gpxItem.chartTypes == null) {
@ -560,4 +584,43 @@ public class TrackDetailsMenu {
view.getShadowView().setVisibility(View.GONE);
}
}
public class TrackChartPoints {
private List<Pair<String, WptPt>> xAxisPoints;
private LatLon highlightedPoint;
private int segmentColor;
private GPXFile gpx;
public List<Pair<String, WptPt>> getXAxisPoints() {
return xAxisPoints;
}
public LatLon getHighlightedPoint() {
return highlightedPoint;
}
public int getSegmentColor() {
return segmentColor;
}
public GPXFile getGpx() {
return gpx;
}
public void setXAxisPoints(List<Pair<String, WptPt>> xAxisPoints) {
this.xAxisPoints = xAxisPoints;
}
public void setHighlightedPoint(LatLon highlightedPoint) {
this.highlightedPoint = highlightedPoint;
}
public void setSegmentColor(int segmentColor) {
this.segmentColor = segmentColor;
}
public void setGpx(GPXFile gpx) {
this.gpx = gpx;
}
}
}

View file

@ -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,6 +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.TrackChartPoints;
import net.osmand.plus.render.OsmandRenderer;
import net.osmand.plus.render.OsmandRenderer.RenderingContext;
import net.osmand.plus.views.MapTextLayer.MapTextProvider;
@ -69,7 +71,7 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
private int currentTrackColor;
private Bitmap selectedPoint;
private LatLon selectedPointLatLon;
private TrackChartPoints trackChartPoints;
private static final int startZoom = 7;
@ -80,13 +82,16 @@ 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 paintGridTextIcon;
private OsmandRenderer osmandRenderer;
private List<TrkSegment> points;
@ -106,6 +111,10 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
initUI();
}
public void setTrackChartPoints(TrackChartPoints trackChartPoints) {
this.trackChartPoints = trackChartPoints;
}
private void initUI() {
paint = new Paint();
paint.setStyle(Style.STROKE);
@ -132,6 +141,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();
@ -142,6 +157,9 @@ 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);
paintInnerRect.setAntiAlias(true);
paintIcon = new Paint();
pointSmall = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_white_shield_small);
@ -345,21 +363,66 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
drawBigPoint(canvas, o, fileColor, x, y);
}
}
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);
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);
}
}
this.fullObjectsLatLon = fullObjectsLatLon;
this.smallObjectsLatLon = smallObjectsLatLon;
}
}
private void drawXAxisPoints(Canvas canvas, RotatedTileBox tileBox) {
int color = trackChartPoints.getSegmentColor();
if (color == 0) {
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;
}
trackChartPoints.setSegmentColor(color);
}
paintInnerRect.setColor(color);
QuadRect latLonBounds = tileBox.getLatLonBounds();
List<Pair<String, WptPt>> 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);
}
}
}
private int getFileColor(@NonNull SelectedGpxFile g) {
return g.getColor() == 0 ? defPointColor : g.getColor();
}
@ -420,14 +483,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;
}
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 ;

View file

@ -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;
@ -221,13 +221,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 {

View file

@ -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
@ -145,18 +158,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<Pair<String, WptPt>> 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) {}