Review fixes

This commit is contained in:
cepprice 2021-04-05 11:44:55 +05:00
parent 4d9d1fd18f
commit eb4a1108f8
6 changed files with 54 additions and 45 deletions

View file

@ -2,9 +2,6 @@ package net.osmand.plus.measurementtool;
import android.util.Pair;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import net.osmand.GPXUtilities.GPXFile;
import net.osmand.GPXUtilities.TrkSegment;
import net.osmand.GPXUtilities.WptPt;
@ -38,12 +35,18 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import static net.osmand.plus.measurementtool.MeasurementEditingContext.CalculationMode.NEXT_SEGMENT;
import static net.osmand.plus.measurementtool.MeasurementEditingContext.CalculationMode.WHOLE_TRACK;
import static net.osmand.plus.measurementtool.command.MeasurementModeCommand.MeasurementCommandType.APPROXIMATE_POINTS;
@ -1112,7 +1115,25 @@ public class MeasurementEditingContext implements IRouteSettingsListener {
}
public boolean isInMultiProfileMode() {
return lastCalculationMode == CalculationMode.NEXT_SEGMENT;
if (lastCalculationMode == CalculationMode.NEXT_SEGMENT) {
return true;
}
Set<String> profiles = new HashSet<>();
List<TrkSegment> segments = new ArrayList<>();
segments.addAll(beforeSegments);
segments.addAll(afterSegments);
for (TrkSegment segment : segments) {
if (Algorithms.isEmpty(segment.points)) {
continue;
}
for (WptPt pt : segment.points) {
if (!pt.isGap()) {
profiles.add(pt.getProfileType());
}
}
}
lastCalculationMode = profiles.size() >= 2 ? NEXT_SEGMENT : WHOLE_TRACK;
return profiles.size() >= 2;
}
@Override

View file

@ -11,6 +11,8 @@ import net.osmand.Location;
import net.osmand.data.RotatedTileBox;
import net.osmand.util.MapAlgorithms;
import net.osmand.util.MapUtils;
import net.osmand.plus.views.layers.geometry.MultiProfileGeometryWay.GeometryMultiProfileWayStyle;
import java.util.ArrayList;
import java.util.Collections;
@ -188,7 +190,9 @@ public abstract class GeometryWay<T extends GeometryWayContext, D extends Geomet
prevLon = lastProjection.getLongitude();
}
if (!Double.isNaN(prevLat) && !Double.isNaN(prevLon)) {
addLocation(tb, prevLat, prevLon, getStyle(i - 1, defaultWayStyle), tx, ty, angles, distances, dist, styles); // first point
GeometryWayStyle<?> prevStyle = style instanceof GeometryMultiProfileWayStyle ?
getStyle(i - 1, style) : style;
addLocation(tb, prevLat, prevLon, prevStyle, tx, ty, angles, distances, dist, styles); // first point
}
}
addLocation(tb, lat, lon, style, tx, ty, angles, distances, dist, styles);
@ -360,7 +364,7 @@ public abstract class GeometryWay<T extends GeometryWayContext, D extends Geomet
if (hasPathLine) {
List<Pair<Path, GeometryWayStyle<?>>> paths = new ArrayList<>();
canvas.rotate(-tb.getRotate(), tb.getCenterPixelX(), tb.getCenterPixelY());
calculatePath(tb, tx, ty, 0, styles, paths);
calculatePath(tb, tx, ty, getOutMargin(), styles, paths);
for (Pair<Path, GeometryWayStyle<?>> pc : paths) {
GeometryWayStyle<?> style = pc.second;
if (style.hasPathLine()) {
@ -377,6 +381,10 @@ public abstract class GeometryWay<T extends GeometryWayContext, D extends Geomet
}
}
protected float getOutMargin() {
return 0;
}
private static class PathGeometryZoom {
private static final float EPSILON_IN_DPI = 2;

View file

@ -47,8 +47,7 @@ public abstract class GeometryWayContext {
paintIconCustom.setColor(Color.BLACK);
paintIconCustom.setStrokeWidth(1f * density);
arrowBitmap = getArrowBitmapResId() == 0 ?
null : RenderingIcons.getBitmapFromVectorDrawable(ctx, getArrowBitmapResId());
arrowBitmap = RenderingIcons.getBitmapFromVectorDrawable(ctx, getArrowBitmapResId());
}
public OsmandApplication getApp() {

View file

@ -49,29 +49,6 @@ public class MultiProfileGeometryWay extends GeometryWay<MultiProfileGeometryWay
drawSegments(tileBox, canvas, bounds.top, bounds.left, bounds.bottom, bounds.right, null, 0);
}
@Override
protected void drawRouteSegment(RotatedTileBox tb, Canvas canvas, List<Float> tx, List<Float> ty, List<Double> angles, List<Double> distances, double distToFinish, List<GeometryWayStyle<?>> styles) {
if (tx.size() < 2) {
return;
}
try {
List<Pair<Path, GeometryWayStyle<?>>> pathStyles = new ArrayList<>();
canvas.rotate(-tb.getRotate(), tb.getCenterPixelX(), tb.getCenterPixelY());
calculatePath(tb, tx, ty, getContext().circleSize, styles, pathStyles);
for (int i = 0; i < pathStyles.size(); i++) {
Pair<Path, GeometryWayStyle<?>> currPathStyle = pathStyles.get(i);
if (!((GeometryMultiProfileWayStyle) currPathStyle.second).isGap) {
getDrawer().drawPathBorder(canvas, currPathStyle.first, currPathStyle.second);
getDrawer().drawPath(canvas, currPathStyle.first, currPathStyle.second);
}
}
getDrawer().drawArrowsOverPath(canvas, tb, tx, ty, angles, distances, distToFinish, styles);
} finally {
canvas.rotate(tb.getRotate(), tb.getCenterPixelX(), tb.getCenterPixelY());
}
}
public void updateRoute(RotatedTileBox tileBox, Map<Pair<WptPt, WptPt>, RoadSegmentData> segmentData,
List<TrkSegment> beforeSegments, List<TrkSegment> afterSegments) {
boolean shouldUpdateRoute = tileBox.getMapDensity() != getMapDensity() || segmentDataChanged(segmentData)
@ -231,6 +208,11 @@ public class MultiProfileGeometryWay extends GeometryWay<MultiProfileGeometryWay
new Pair<>(mode.getProfileColor(night), mode.getIconRes());
}
@Override
protected float getOutMargin() {
return getContext().getAttrs().paint.getStrokeWidth() * 2;
}
@NonNull
@Override
public GeometryWayStyle<?> getDefaultWayStyle() {

View file

@ -7,6 +7,7 @@ import android.graphics.Color;
import android.graphics.Paint;
import net.osmand.AndroidUtils;
import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.views.OsmandMapLayer.RenderingLineAttributes;
import net.osmand.util.Algorithms;
@ -26,6 +27,8 @@ public class MultiProfileGeometryWayContext extends GeometryWayContext {
public final float circleSize;
public final float pointIconSize;
private static final String pointColorHex = "#637EFB";
private RenderingLineAttributes multiProfileAttrs;
private Bitmap pointIcon;
@ -64,15 +67,10 @@ public class MultiProfileGeometryWayContext extends GeometryWayContext {
paint.setColor(Color.WHITE);
canvas.drawCircle(centerXY, centerXY, centerRadius, paint);
paint.setColor(Algorithms.parseColor("#637EFB"));
paint.setColor(Algorithms.parseColor(pointColorHex));
canvas.drawCircle(centerXY, centerXY, innerRadius, paint);
}
@Override
protected int getArrowBitmapResId() {
return 0;
}
@NonNull
public Bitmap getProfileIconBitmap(@DrawableRes int iconRes, @ColorInt int color) {
String key = iconRes + "_" + color;
@ -100,4 +98,9 @@ public class MultiProfileGeometryWayContext extends GeometryWayContext {
public Bitmap getPointIcon() {
return pointIcon;
}
@Override
protected int getArrowBitmapResId() {
return R.drawable.ic_action_split_interval;
}
}

View file

@ -19,6 +19,10 @@ public class MultiProfileGeometryWayDrawer extends GeometryWayDrawer<MultiProfil
public void drawPath(Canvas canvas, Path path, GeometryWayStyle<?> style) {
if (style instanceof GeometryMultiProfileWayStyle) {
RenderingLineAttributes attrs = getContext().getAttrs();
attrs.paint.setColor(((GeometryMultiProfileWayStyle) style).getBorderColor());
canvas.drawPath(path, attrs.paint);
attrs.paint2.setColor(((GeometryMultiProfileWayStyle) style).getLineColor());
canvas.drawPath(path, attrs.paint2);
}
@ -42,12 +46,4 @@ public class MultiProfileGeometryWayDrawer extends GeometryWayDrawer<MultiProfil
}
}
}
public void drawPathBorder(Canvas canvas, Path path, GeometryWayStyle<?> style) {
if (style instanceof GeometryMultiProfileWayStyle) {
RenderingLineAttributes attrs = getContext().getAttrs();
attrs.paint.setColor(((GeometryMultiProfileWayStyle) style).getBorderColor());
canvas.drawPath(path, attrs.paint);
}
}
}