Moving gpx point partially implemented.

This commit is contained in:
GaidamakUA 2016-05-17 22:00:02 +03:00
parent d77ec13d34
commit 160caac18a
2 changed files with 90 additions and 59 deletions

View file

@ -5,6 +5,7 @@ import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.support.annotation.ColorInt;
import net.osmand.Location;
import net.osmand.PlatformUtil;
@ -65,7 +66,8 @@ public class GPXUtilities {
return extensions;
}
public int getColor(int defColor) {
@ColorInt
public int getColor(@ColorInt int defColor) {
if(extensions != null && extensions.containsKey("color")) {
try {
return Color.parseColor(extensions.get("color").toUpperCase());
@ -1224,7 +1226,5 @@ public class GPXUtilities {
if (from.warning != null) {
to.warning = from.warning;
}
}
}

View file

@ -12,6 +12,11 @@ import android.graphics.PointF;
import android.graphics.PorterDuff;
import android.graphics.PorterDuff.Mode;
import android.graphics.PorterDuffColorFilter;
import android.support.annotation.ColorInt;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import net.osmand.data.LatLon;
import net.osmand.data.PointDescription;
import net.osmand.data.QuadRect;
@ -39,7 +44,7 @@ import java.util.Arrays;
import java.util.List;
public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContextMenuProvider,
MapTextProvider<WptPt> {
ContextMenuLayer.IMoveObjectProvider, MapTextProvider<WptPt> {
private OsmandMapTileView view;
@ -75,6 +80,19 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
private List<TrkSegment> points;
private GPXFile gpx;
private ContextMenuLayer contextMenuLayer;
@ColorInt
private int visitedColor;
@ColorInt
private int defPointColor;
@Override
public void initLayer(OsmandMapTileView view) {
this.view = view;
selectedGpxHelper = view.getApplication().getSelectedGpxHelper();
osmandRenderer = view.getApplication().getResourceManager().getRenderer().getRenderer();
initUI();
}
private void initUI() {
paint = new Paint();
@ -90,8 +108,6 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
paint_1.setStyle(Style.STROKE);
paint_1.setAntiAlias(true);
paintBmp = new Paint();
paintBmp.setAntiAlias(true);
paintBmp.setFilterBitmap(true);
@ -117,17 +133,42 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
paintIcon = new Paint();
pointSmall = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_white_shield_small);
}
contextMenuLayer = view.getLayerByClass(ContextMenuLayer.class);
visitedColor = ContextCompat.getColor(view.getApplication(), R.color.color_ok);
defPointColor = ContextCompat.getColor(view.getApplication(), R.color.gpx_color_point);
}
@Override
public void initLayer(OsmandMapTileView view) {
this.view = view;
selectedGpxHelper = view.getApplication().getSelectedGpxHelper();
osmandRenderer = view.getApplication().getResourceManager().getRenderer().getRenderer();
initUI();
public void onDraw(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) {
if (contextMenuLayer.getMoveableObject() instanceof WptPt) {
WptPt objectInMotion = (WptPt) contextMenuLayer.getMoveableObject();
PointF pf = contextMenuLayer.getMoveableCenterPoint(tileBox);
drawBigPoint(canvas, objectInMotion, defPointColor, pf.x, pf.y);
}
}
@Override
public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) {
if(points != null) {
updatePaints(0, false, false, settings, tileBox);
for (TrkSegment ts : points)
ts.drawRenderers(view.getZoom(), paint, canvas, tileBox);
} else {
List<SelectedGpxFile> selectedGPXFiles = selectedGpxHelper.getSelectedGPXFiles();
cache.clear();
if (!selectedGPXFiles.isEmpty()) {
drawSelectedFilesSegments(canvas, tileBox, selectedGPXFiles, settings);
canvas.rotate(-tileBox.getRotate(), tileBox.getCenterPixelX(), tileBox.getCenterPixelY());
drawSelectedFilesSplits(canvas, tileBox, selectedGPXFiles, settings);
drawSelectedFilesPoints(canvas, tileBox, selectedGPXFiles);
}
if (textLayer != null && textLayer.isVisible()) {
textLayer.putData(this, cache);
}
}
}
public void updateLayerStyle() {
cachedHash = -1;
@ -198,28 +239,6 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
return Arrays.hashCode(o);
}
@Override
public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) {
if(points != null) {
updatePaints(0, false, false, settings, tileBox);
for (TrkSegment ts : points)
ts.drawRenderers(view.getZoom(), paint, canvas, tileBox);
} else {
List<SelectedGpxFile> selectedGPXFiles = selectedGpxHelper.getSelectedGPXFiles();
cache.clear();
if (!selectedGPXFiles.isEmpty()) {
drawSelectedFilesSegments(canvas, tileBox, selectedGPXFiles, settings);
canvas.rotate(-tileBox.getRotate(), tileBox.getCenterPixelX(), tileBox.getCenterPixelY());
drawSelectedFilesSplits(canvas, tileBox, selectedGPXFiles, settings);
drawSelectedFilesPoints(canvas, tileBox, selectedGPXFiles);
}
if (textLayer != null && textLayer.isVisible()) {
textLayer.putData(this, cache);
}
}
}
private void drawSelectedFilesSplits(Canvas canvas, RotatedTileBox tileBox, List<SelectedGpxFile> selectedGPXFiles,
DrawSettings settings) {
if (tileBox.getZoom() >= startZoom) {
@ -272,8 +291,6 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
}
private void drawSelectedFilesPoints(Canvas canvas, RotatedTileBox tileBox, List<SelectedGpxFile> selectedGPXFiles) {
int defPointColor = view.getResources().getColor(R.color.gpx_color_point);
int visitedColor = view.getContext().getResources().getColor(R.color.color_ok);
if (tileBox.getZoom() >= startZoom) {
float iconSize = FavoriteImageDrawable.getOrCreate(view.getContext(), 0,
true).getIntrinsicWidth() * 3 / 2.5f;
@ -286,18 +303,20 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
for (SelectedGpxFile g : selectedGPXFiles) {
List<WptPt> pts = getListStarPoints(g);
List<WptPt> fullObjects = new ArrayList<>();
int fcolor = g.getColor() == 0 ? defPointColor : g.getColor();
@ColorInt
int fileColor = g.getColor() == 0 ? defPointColor : g.getColor();
for (WptPt o : pts) {
if (o.lat >= latLonBounds.bottom && o.lat <= latLonBounds.top
&& o.lon >= latLonBounds.left && o.lon <= latLonBounds.right) {
&& o.lon >= latLonBounds.left && o.lon <= latLonBounds.right
&& o != contextMenuLayer.getMoveableObject()) {
cache.add(o);
float x = tileBox.getPixXFromLatLon(o.lat, o.lon);
float y = tileBox.getPixYFromLatLon(o.lat, o.lon);
if (intersects(boundIntersections, x, y, iconSize, iconSize)) {
boolean visit = isPointVisited(o);
int col = visit ? visitedColor : o.getColor(fcolor);
paintIcon.setColorFilter(new PorterDuffColorFilter(col, PorterDuff.Mode.MULTIPLY));
@ColorInt
int pointColor = getPointColor(o, fileColor);
paintIcon.setColorFilter(new PorterDuffColorFilter(pointColor, PorterDuff.Mode.MULTIPLY));
canvas.drawBitmap(pointSmall, x - pointSmall.getWidth() / 2, y - pointSmall.getHeight() / 2, paintIcon);
smallObjectsLatLon.add(new LatLon(o.lat, o.lon));
} else {
@ -309,10 +328,7 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
for (WptPt o : fullObjects) {
float x = tileBox.getPixXFromLatLon(o.lat, o.lon);
float y = tileBox.getPixYFromLatLon(o.lat, o.lon);
boolean visit = isPointVisited(o);
int pointColor = visit ? visitedColor : o.getColor(fcolor);
FavoriteImageDrawable fid = FavoriteImageDrawable.getOrCreate(view.getContext(), pointColor, true);
fid.drawBitmapInCenter(canvas, x, y);
drawBigPoint(canvas, o, fileColor, x, y);
}
}
this.fullObjectsLatLon = fullObjectsLatLon;
@ -320,6 +336,18 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
}
}
private void drawBigPoint(Canvas canvas, WptPt o, int fileColor, float x, float y) {
int pointColor = getPointColor(o, fileColor);
FavoriteImageDrawable fid = FavoriteImageDrawable.getOrCreate(view.getContext(), pointColor, true);
fid.drawBitmapInCenter(canvas, x, y);
}
@ColorInt
private int getPointColor(WptPt o, @ColorInt int fileColor) {
boolean visit = isPointVisited(o);
return visit ? visitedColor : o.getColor(fileColor);
}
private void drawSelectedFilesSegments(Canvas canvas, RotatedTileBox tileBox,
List<SelectedGpxFile> selectedGPXFiles, DrawSettings settings) {
@ -343,7 +371,6 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
}
}
private boolean isPointVisited(WptPt o) {
boolean visit = false;
String visited = o.getExtensionsToRead().get("VISITED_KEY");
@ -362,11 +389,6 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
return pts;
}
@Override
public void onDraw(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) {
}
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 ;
@ -464,4 +486,13 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
}
@Override
public boolean isObjectMovable(Object o) {
return o instanceof WptPt;
}
@Override
public void applyNewObjectPosition(@NonNull Object o, @NonNull LatLon position, @Nullable ContextMenuLayer.ApplyMovedObjectCallback callback) {
}
}