Moving favourite object.
This commit is contained in:
parent
a31c40e349
commit
a2b45ca89b
4 changed files with 43 additions and 8 deletions
|
@ -62,6 +62,7 @@ public class ContextMenuLayer extends OsmandMapLayer {
|
||||||
|
|
||||||
private int previousMarkerX;
|
private int previousMarkerX;
|
||||||
private int previousMarkerY;
|
private int previousMarkerY;
|
||||||
|
private Object selectedObj;
|
||||||
|
|
||||||
public ContextMenuLayer(MapActivity activity) {
|
public ContextMenuLayer(MapActivity activity) {
|
||||||
this.activity = activity;
|
this.activity = activity;
|
||||||
|
@ -163,6 +164,8 @@ public class ContextMenuLayer extends OsmandMapLayer {
|
||||||
activity.getContextMenu().hide();
|
activity.getContextMenu().hide();
|
||||||
LatLon latLon = tileBox.getCenterLatLon();
|
LatLon latLon = tileBox.getCenterLatLon();
|
||||||
mMoveMarkerBottomSheetHelper.show(latLon.getLatitude(), latLon.getLongitude());
|
mMoveMarkerBottomSheetHelper.show(latLon.getLatitude(), latLon.getLongitude());
|
||||||
|
|
||||||
|
view.tryMovingObject(selectedObj);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -199,7 +202,7 @@ public class ContextMenuLayer extends OsmandMapLayer {
|
||||||
private boolean showContextMenu(PointF point, RotatedTileBox tileBox, boolean showUnknownLocation) {
|
private boolean showContextMenu(PointF point, RotatedTileBox tileBox, boolean showUnknownLocation) {
|
||||||
Map<Object, IContextMenuProvider> selectedObjects = selectObjectsForContextMenu(tileBox, point, false);
|
Map<Object, IContextMenuProvider> selectedObjects = selectObjectsForContextMenu(tileBox, point, false);
|
||||||
if (selectedObjects.size() == 1) {
|
if (selectedObjects.size() == 1) {
|
||||||
Object selectedObj = selectedObjects.keySet().iterator().next();
|
selectedObj = selectedObjects.keySet().iterator().next();
|
||||||
IContextMenuProvider contextObject = selectedObjects.get(selectedObj);
|
IContextMenuProvider contextObject = selectedObjects.get(selectedObj);
|
||||||
LatLon latLon = null;
|
LatLon latLon = null;
|
||||||
PointDescription pointDescription = null;
|
PointDescription pointDescription = null;
|
||||||
|
|
|
@ -8,6 +8,7 @@ import android.graphics.Paint;
|
||||||
import android.graphics.PointF;
|
import android.graphics.PointF;
|
||||||
import android.graphics.PorterDuff;
|
import android.graphics.PorterDuff;
|
||||||
import android.graphics.PorterDuffColorFilter;
|
import android.graphics.PorterDuffColorFilter;
|
||||||
|
import android.support.annotation.ColorInt;
|
||||||
|
|
||||||
import net.osmand.data.FavouritePoint;
|
import net.osmand.data.FavouritePoint;
|
||||||
import net.osmand.data.LatLon;
|
import net.osmand.data.LatLon;
|
||||||
|
@ -39,7 +40,11 @@ public class FavoritesLayer extends OsmandMapLayer implements ContextMenuLayer.
|
||||||
private int defaultColor;
|
private int defaultColor;
|
||||||
|
|
||||||
private OsmandSettings settings;
|
private OsmandSettings settings;
|
||||||
|
|
||||||
|
private LocationPoint objectInMotion;
|
||||||
|
private int objectInMotionX;
|
||||||
|
private int objectInMotionY;
|
||||||
|
|
||||||
protected Class<? extends LocationPoint> getFavoriteClass() {
|
protected Class<? extends LocationPoint> getFavoriteClass() {
|
||||||
return (Class<? extends LocationPoint>) FavouritePoint.class;
|
return (Class<? extends LocationPoint>) FavouritePoint.class;
|
||||||
}
|
}
|
||||||
|
@ -87,6 +92,10 @@ public class FavoritesLayer extends OsmandMapLayer implements ContextMenuLayer.
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDraw(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) {
|
public void onDraw(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) {
|
||||||
|
if (objectInMotion != null) {
|
||||||
|
FavoriteImageDrawable fid = FavoriteImageDrawable.getOrCreate(view.getContext(), objectInMotion.getColor(), true);
|
||||||
|
fid.drawBitmapInCenter(canvas, objectInMotionX, objectInMotionY);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -111,6 +120,7 @@ public class FavoritesLayer extends OsmandMapLayer implements ContextMenuLayer.
|
||||||
float y = tileBox.getPixYFromLatLon(o.getLatitude(), o.getLongitude());
|
float y = tileBox.getPixYFromLatLon(o.getLatitude(), o.getLongitude());
|
||||||
|
|
||||||
if (intersects(boundIntersections, x, y, iconSize, iconSize)) {
|
if (intersects(boundIntersections, x, y, iconSize, iconSize)) {
|
||||||
|
@ColorInt
|
||||||
int col = o.getColor() == 0 || o.getColor() == Color.BLACK ? defaultColor : o.getColor();
|
int col = o.getColor() == 0 || o.getColor() == Color.BLACK ? defaultColor : o.getColor();
|
||||||
paintIcon.setColorFilter(new PorterDuffColorFilter(col, PorterDuff.Mode.MULTIPLY));
|
paintIcon.setColorFilter(new PorterDuffColorFilter(col, PorterDuff.Mode.MULTIPLY));
|
||||||
canvas.drawBitmap(pointSmall, x - pointSmall.getWidth() / 2, y - pointSmall.getHeight() / 2, paintIcon);
|
canvas.drawBitmap(pointSmall, x - pointSmall.getWidth() / 2, y - pointSmall.getHeight() / 2, paintIcon);
|
||||||
|
@ -121,7 +131,9 @@ public class FavoritesLayer extends OsmandMapLayer implements ContextMenuLayer.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (LocationPoint o : fullObjects) {
|
for (LocationPoint o : fullObjects) {
|
||||||
drawPoint(canvas, tileBox, latLonBounds, o);
|
if (o != objectInMotion) {
|
||||||
|
drawPoint(canvas, tileBox, latLonBounds, o);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
this.fullObjectsLatLon = fullObjectsLatLon;
|
this.fullObjectsLatLon = fullObjectsLatLon;
|
||||||
this.smallObjectsLatLon = smallObjectsLatLon;
|
this.smallObjectsLatLon = smallObjectsLatLon;
|
||||||
|
@ -142,8 +154,6 @@ public class FavoritesLayer extends OsmandMapLayer implements ContextMenuLayer.
|
||||||
int y = (int) tileBox.getPixYFromLatLon(o.getLatitude(), o.getLongitude());
|
int y = (int) tileBox.getPixYFromLatLon(o.getLatitude(), o.getLongitude());
|
||||||
FavoriteImageDrawable fid = FavoriteImageDrawable.getOrCreate(view.getContext(), o.getColor(), true);
|
FavoriteImageDrawable fid = FavoriteImageDrawable.getOrCreate(view.getContext(), o.getColor(), true);
|
||||||
fid.drawBitmapInCenter(canvas, x, y);
|
fid.drawBitmapInCenter(canvas, x, y);
|
||||||
// canvas.drawBitmap(favoriteIcon, x - favoriteIcon.getWidth() / 2,
|
|
||||||
// y - favoriteIcon.getHeight(), paint);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -204,7 +214,7 @@ public class FavoritesLayer extends OsmandMapLayer implements ContextMenuLayer.
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isObjectClickable(Object o) {
|
public boolean isObjectClickable(Object o) {
|
||||||
return o instanceof LocationPoint;
|
return o instanceof LocationPoint && o != objectInMotion;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -236,8 +246,17 @@ public class FavoritesLayer extends OsmandMapLayer implements ContextMenuLayer.
|
||||||
public String getText(LocationPoint o) {
|
public String getText(LocationPoint o) {
|
||||||
return PointDescription.getSimpleName(o, view.getContext());
|
return PointDescription.getSimpleName(o, view.getContext());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onTryMovingObject(Object selectedObject, RotatedTileBox tileBox) {
|
||||||
|
if (selectedObject instanceof LocationPoint) {
|
||||||
|
objectInMotion = (LocationPoint) selectedObject;
|
||||||
|
objectInMotionX = (int) tileBox.getPixXFromLatLon(objectInMotion.getLatitude(), objectInMotion.getLongitude());
|
||||||
|
objectInMotionY = (int) tileBox.getPixYFromLatLon(objectInMotion.getLatitude(), objectInMotion.getLongitude());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return super.onTryMovingObject(selectedObject, tileBox);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -52,6 +52,10 @@ public abstract class OsmandMapLayer {
|
||||||
public boolean onTouchEvent(MotionEvent event, RotatedTileBox tileBox) {
|
public boolean onTouchEvent(MotionEvent event, RotatedTileBox tileBox) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean onTryMovingObject(Object selectedObject, RotatedTileBox tileBox) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public <Params> void executeTaskInBackground(AsyncTask<Params, ?, ?> task, Params... params) {
|
public <Params> void executeTaskInBackground(AsyncTask<Params, ?, ?> task, Params... params) {
|
||||||
task.execute(params);
|
task.execute(params);
|
||||||
|
|
|
@ -133,7 +133,7 @@ public class OsmandMapTileView implements IMapDownloaderCallback {
|
||||||
|
|
||||||
private AccessibilityActionsProvider accessibilityActions;
|
private AccessibilityActionsProvider accessibilityActions;
|
||||||
|
|
||||||
private List<OsmandMapLayer> layers = new ArrayList<OsmandMapLayer>();
|
private List<OsmandMapLayer> layers = new ArrayList<>();
|
||||||
|
|
||||||
private BaseMapLayer mainLayer;
|
private BaseMapLayer mainLayer;
|
||||||
|
|
||||||
|
@ -604,6 +604,15 @@ public class OsmandMapTileView implements IMapDownloaderCallback {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean tryMovingObject(Object selectedObject) {
|
||||||
|
for (OsmandMapLayer layer : layers) {
|
||||||
|
if (layer.onTryMovingObject(selectedObject, getCurrentRotatedTileBox())) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
protected void drawMapPosition(Canvas canvas, float x, float y) {
|
protected void drawMapPosition(Canvas canvas, float x, float y) {
|
||||||
canvas.drawCircle(x, y, 3 * dm.density, paintCenter);
|
canvas.drawCircle(x, y, 3 * dm.density, paintCenter);
|
||||||
canvas.drawCircle(x, y, 7 * dm.density, paintCenter);
|
canvas.drawCircle(x, y, 7 * dm.density, paintCenter);
|
||||||
|
|
Loading…
Reference in a new issue