Moving parking position implemented.
This commit is contained in:
parent
62bd2a8e3f
commit
8fb5c9f250
1 changed files with 43 additions and 16 deletions
|
@ -1,15 +1,5 @@
|
|||
package net.osmand.plus.parkingpoint;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.osmand.data.LatLon;
|
||||
import net.osmand.data.PointDescription;
|
||||
import net.osmand.data.RotatedTileBox;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.views.ContextMenuLayer;
|
||||
import net.osmand.plus.views.OsmandMapLayer;
|
||||
import net.osmand.plus.views.OsmandMapTileView;
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
|
@ -19,13 +9,25 @@ import android.graphics.PointF;
|
|||
import android.util.DisplayMetrics;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import net.osmand.data.LatLon;
|
||||
import net.osmand.data.PointDescription;
|
||||
import net.osmand.data.RotatedTileBox;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.views.ContextMenuLayer;
|
||||
import net.osmand.plus.views.OsmandMapLayer;
|
||||
import net.osmand.plus.views.OsmandMapTileView;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Class represents a layer which depicts the position of the parked car
|
||||
* @author Alena Fedasenka
|
||||
* @see ParkingPositionPlugin
|
||||
*
|
||||
*/
|
||||
public class ParkingPositionLayer extends OsmandMapLayer implements ContextMenuLayer.IContextMenuProvider {
|
||||
public class ParkingPositionLayer extends OsmandMapLayer implements
|
||||
ContextMenuLayer.IContextMenuProvider, ContextMenuLayer.IMoveObjectProvider {
|
||||
/**
|
||||
* magic number so far
|
||||
*/
|
||||
|
@ -45,6 +47,8 @@ public class ParkingPositionLayer extends OsmandMapLayer implements ContextMenuL
|
|||
|
||||
private ParkingPositionPlugin plugin;
|
||||
|
||||
private ContextMenuLayer contextMenuLayer;
|
||||
|
||||
public ParkingPositionLayer(MapActivity map, ParkingPositionPlugin plugin) {
|
||||
this.map = map;
|
||||
this.plugin = plugin;
|
||||
|
@ -68,11 +72,14 @@ public class ParkingPositionLayer extends OsmandMapLayer implements ContextMenuL
|
|||
parkingNoLimitIcon = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_poi_parking_pos_no_limit);
|
||||
parkingLimitIcon = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_poi_parking_pos_limit);
|
||||
timeLimit = plugin.getParkingType();
|
||||
|
||||
contextMenuLayer = view.getLayerByClass(ContextMenuLayer.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDraw(Canvas canvas, RotatedTileBox tb, DrawSettings nightMode) {
|
||||
public void onDraw(Canvas canvas, RotatedTileBox tileBox, DrawSettings nightMode) {
|
||||
LatLon parkingPoint = getParkingPoint();
|
||||
boolean inMotion = parkingPoint == contextMenuLayer.getMoveableObject();
|
||||
if (parkingPoint == null)
|
||||
return;
|
||||
|
||||
|
@ -84,11 +91,19 @@ public class ParkingPositionLayer extends OsmandMapLayer implements ContextMenuL
|
|||
}
|
||||
double latitude = parkingPoint.getLatitude();
|
||||
double longitude = parkingPoint.getLongitude();
|
||||
if (isLocationVisible(tb, latitude, longitude)) {
|
||||
if (isLocationVisible(tileBox, latitude, longitude) || inMotion) {
|
||||
int marginX = parkingNoLimitIcon.getWidth() / 2;
|
||||
int marginY = parkingNoLimitIcon.getHeight() / 2;
|
||||
int locationX = tb.getPixXFromLonNoRot(longitude);
|
||||
int locationY = tb.getPixYFromLatNoRot(latitude);
|
||||
float locationX;
|
||||
float locationY;
|
||||
if (inMotion) {
|
||||
PointF pf = contextMenuLayer.getMoveableCenterPoint(tileBox);
|
||||
locationX = pf.x;
|
||||
locationY = pf.y;
|
||||
} else {
|
||||
locationX = tileBox.getPixXFromLonNoRot(longitude);
|
||||
locationY = tileBox.getPixYFromLatNoRot(latitude);
|
||||
}
|
||||
canvas.rotate(-view.getRotate(), locationX, locationY);
|
||||
canvas.drawBitmap(parkingIcon, locationX - marginX, locationY - marginY, bitmapPaint);
|
||||
}
|
||||
|
@ -183,5 +198,17 @@ public class ParkingPositionLayer extends OsmandMapLayer implements ContextMenuL
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isObjectMovable(Object o) {
|
||||
return o == getParkingPoint();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyNewObjectPosition(Object o, LatLon position, ContextMenuLayer.ApplyMovedObjectCallback callback) {
|
||||
if (o == getParkingPoint()) {
|
||||
plugin.setParkingPosition(position.getLatitude(), position.getLongitude());
|
||||
callback.onApplyMovedObject(true, getParkingPoint());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue