Try to save favorite point

This commit is contained in:
Victor Shcherb 2016-05-06 19:52:22 +02:00
parent a2b45ca89b
commit 6c5a940c06
21 changed files with 154 additions and 123 deletions

View file

@ -110,6 +110,9 @@ public class MapActivityLayers {
mapTextLayer = new MapTextLayer(); mapTextLayer = new MapTextLayer();
// 5.95 all labels // 5.95 all labels
mapView.addLayer(mapTextLayer, 5.95f); mapView.addLayer(mapTextLayer, 5.95f);
// 8. context menu layer
contextMenuLayer = new ContextMenuLayer(activity);
mapView.addLayer(contextMenuLayer, 8);
// mapView.addLayer(underlayLayer, -0.5f); // mapView.addLayer(underlayLayer, -0.5f);
mapTileLayer = new MapTileLayer(true); mapTileLayer = new MapTileLayer(true);
mapView.addLayer(mapTileLayer, 0.0f); mapView.addLayer(mapTileLayer, 0.0f);
@ -156,8 +159,6 @@ public class MapActivityLayers {
impassableRoadsLayer = new ImpassableRoadsLayer(activity); impassableRoadsLayer = new ImpassableRoadsLayer(activity);
mapView.addLayer(impassableRoadsLayer, 7.5f); mapView.addLayer(impassableRoadsLayer, 7.5f);
// 8. context menu layer // 8. context menu layer
contextMenuLayer = new ContextMenuLayer(activity);
mapView.addLayer(contextMenuLayer, 8);
// 9. map info layer // 9. map info layer
mapInfoLayer = new MapInfoLayer(activity, routeLayer); mapInfoLayer = new MapInfoLayer(activity, routeLayer);
mapView.addLayer(mapInfoLayer, 9); mapView.addLayer(mapInfoLayer, 9);

View file

@ -7,7 +7,6 @@ import android.graphics.Color;
import android.graphics.Paint; import android.graphics.Paint;
import android.graphics.Paint.Style; import android.graphics.Paint.Style;
import android.graphics.PointF; import android.graphics.PointF;
import net.osmand.data.DataTileManager; import net.osmand.data.DataTileManager;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
import net.osmand.data.PointDescription; import net.osmand.data.PointDescription;
@ -202,4 +201,5 @@ public class AudioNotesLayer extends OsmandMapLayer implements IContextMenuProvi
} }
} }

View file

@ -24,7 +24,6 @@ import android.widget.EditText;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import net.osmand.CallbackWithObject; import net.osmand.CallbackWithObject;
import net.osmand.IndexConstants; import net.osmand.IndexConstants;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
@ -718,6 +717,7 @@ public class DistanceCalculatorPlugin extends OsmandPlugin {
return null; return null;
} }
} }

View file

@ -15,7 +15,6 @@ import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.widget.EditText; import android.widget.EditText;
import android.widget.Toast; import android.widget.Toast;
import net.osmand.AndroidUtils; import net.osmand.AndroidUtils;
import net.osmand.PlatformUtil; import net.osmand.PlatformUtil;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
@ -626,4 +625,5 @@ public class OsmBugsLayer extends OsmandMapLayer implements IContextMenuProvider
} }
} }
} }

View file

@ -5,7 +5,6 @@ import android.graphics.BitmapFactory;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.Paint; import android.graphics.Paint;
import android.graphics.PointF; import android.graphics.PointF;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
import net.osmand.data.PointDescription; import net.osmand.data.PointDescription;
import net.osmand.data.RotatedTileBox; import net.osmand.data.RotatedTileBox;
@ -184,4 +183,5 @@ public class OsmEditsLayer extends OsmandMapLayer implements ContextMenuLayer.IC
} }
return null; return null;
} }
} }

View file

@ -13,7 +13,6 @@ import android.graphics.PointF;
import android.os.Handler; import android.os.Handler;
import android.util.DisplayMetrics; import android.util.DisplayMetrics;
import android.view.WindowManager; import android.view.WindowManager;
import net.osmand.Location; import net.osmand.Location;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
import net.osmand.data.PointDescription; import net.osmand.data.PointDescription;

View file

@ -188,4 +188,5 @@ public class ParkingPositionLayer extends OsmandMapLayer implements ContextMenuL
} }
} }
} }

View file

@ -3,7 +3,6 @@ package net.osmand.plus.routepointsnavigation;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.PointF; import android.graphics.PointF;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
import net.osmand.data.PointDescription; import net.osmand.data.PointDescription;
import net.osmand.data.RotatedTileBox; import net.osmand.data.RotatedTileBox;
@ -142,5 +141,4 @@ public class RoutePointsLayer extends OsmandMapLayer implements ContextMenuLaye
} }
} }
} }

View file

@ -17,7 +17,6 @@ import android.view.MotionEvent;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.FrameLayout.LayoutParams; import android.widget.FrameLayout.LayoutParams;
import android.widget.ImageView; import android.widget.ImageView;
import net.osmand.CallbackWithObject; import net.osmand.CallbackWithObject;
import net.osmand.PlatformUtil; import net.osmand.PlatformUtil;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
@ -60,10 +59,6 @@ public class ContextMenuLayer extends OsmandMapLayer {
private final MoveMarkerBottomSheetHelper mMoveMarkerBottomSheetHelper; private final MoveMarkerBottomSheetHelper mMoveMarkerBottomSheetHelper;
private boolean mInChangeMarkerPositionMode; private boolean mInChangeMarkerPositionMode;
private int previousMarkerX;
private int previousMarkerY;
private Object selectedObj;
public ContextMenuLayer(MapActivity activity) { public ContextMenuLayer(MapActivity activity) {
this.activity = activity; this.activity = activity;
menu = activity.getContextMenu(); menu = activity.getContextMenu();
@ -112,16 +107,15 @@ public class ContextMenuLayer extends OsmandMapLayer {
} }
if (mInChangeMarkerPositionMode) { if (mInChangeMarkerPositionMode) {
int x = previousMarkerX; // TODO draw marker if selection was only marker?
int y = previousMarkerY; // int x = previousMarkerX;
canvas.translate(x - contextMarker.getWidth() / 2, y - contextMarker.getHeight()); // int y = previousMarkerY;
contextMarker.draw(canvas); // canvas.translate(x - contextMarker.getWidth() / 2, y - contextMarker.getHeight());
// contextMarker.draw(canvas);
} else if (menu.isActive()) { } else if (menu.isActive()) {
LatLon latLon = menu.getLatLon(); LatLon latLon = menu.getLatLon();
int x = (int) box.getPixXFromLatLon(latLon.getLatitude(), latLon.getLongitude()); int x = (int) box.getPixXFromLatLon(latLon.getLatitude(), latLon.getLongitude());
int y = (int) box.getPixYFromLatLon(latLon.getLatitude(), latLon.getLongitude()); int y = (int) box.getPixYFromLatLon(latLon.getLatitude(), latLon.getLongitude());
previousMarkerX = x;
previousMarkerY = y;
canvas.translate(x - contextMarker.getWidth() / 2, y - contextMarker.getHeight()); canvas.translate(x - contextMarker.getWidth() / 2, y - contextMarker.getHeight());
contextMarker.draw(canvas); contextMarker.draw(canvas);
} }
@ -157,32 +151,73 @@ public class ContextMenuLayer extends OsmandMapLayer {
return false; return false;
} }
if (pressedContextMarker(tileBox, point.x, point.y)) { if (pressedContextMarker(tileBox, point.x, point.y)) {
Object obj = menu.getObject() ;
if (obj != null && isObjectMoveable(obj)) {
Vibrator vibrator = (Vibrator) activity.getSystemService(Context.VIBRATOR_SERVICE); Vibrator vibrator = (Vibrator) activity.getSystemService(Context.VIBRATOR_SERVICE);
vibrator.vibrate(VIBRATE_SHORT); vibrator.vibrate(VIBRATE_SHORT);
mInChangeMarkerPositionMode = true; mInChangeMarkerPositionMode = true;
activity.getContextMenu().hide(); activity.getContextMenu().hide();
LatLon latLon = tileBox.getCenterLatLon(); LatLon ll = menu.getLatLon();
mMoveMarkerBottomSheetHelper.show(latLon.getLatitude(), latLon.getLongitude()); RotatedTileBox rb = new RotatedTileBox(tileBox);
PointF pf = getMoveableCenterPoint(rb);
view.tryMovingObject(selectedObj); rb.setCenterLocation(pf.x, pf.y);
rb.setLatLonCenter(ll.getLatitude(), ll.getLongitude());
double lat = rb.getLatFromPixel(tileBox.getCenterPixelX(), tileBox.getCenterPixelY());
double lon = rb.getLonFromPixel(tileBox.getCenterPixelX(), tileBox.getCenterPixelY());
view.setLatLon(lat, lon);
mMoveMarkerBottomSheetHelper.show(menu.getLeftIcon());
return true; return true;
} }
return false;
}
showContextMenu(point, tileBox, true); showContextMenu(point, tileBox, true);
view.refreshMap(); view.refreshMap();
return true; return true;
} }
public PointF getMoveableCenterPoint(RotatedTileBox tb) {
return new PointF(tb.getPixWidth() / 2, tb.getPixHeight() / 2);
}
public Object getMoveableObject() {
return mInChangeMarkerPositionMode ? menu.getObject() : null;
}
public boolean isObjectMoveable(Object o) {
for (OsmandMapLayer lt : view.getLayers()) {
if (lt instanceof ContextMenuLayer.IContextMenuProvider) {
final IMoveObjectProvider l = (ContextMenuLayer.IMoveObjectProvider) lt;
if(l.isObjectMoveable(o)) {
return true;
}
}
}
return false;
}
public void applyMovedObject(Object o, LatLon position) {
for (OsmandMapLayer lt : view.getLayers()) {
if (lt instanceof ContextMenuLayer.IContextMenuProvider) {
final IMoveObjectProvider l = (ContextMenuLayer.IMoveObjectProvider) lt;
if(l.isObjectMoveable(o)) {
l.applyNewObjectPosition(o, position);
return;
}
}
}
}
public void applyNewMarkerPosition() { public void applyNewMarkerPosition() {
if (!mInChangeMarkerPositionMode) { if (!mInChangeMarkerPositionMode) {
throw new IllegalStateException("Not in change marker position mode"); throw new IllegalStateException("Not in change marker position mode");
} }
mInChangeMarkerPositionMode = false; mInChangeMarkerPositionMode = false;
RotatedTileBox tileBox = activity.getMapView().getCurrentRotatedTileBox(); RotatedTileBox tileBox = activity.getMapView().getCurrentRotatedTileBox();
int newMarkerX = previousMarkerX; PointF newMarkerPosition = new PointF(tileBox.getPixWidth() / 2,
int newMarkerY = previousMarkerY; tileBox.getPixHeight() / 2);
PointF newMarkerPosition = new PointF(newMarkerX, newMarkerY); // TODO pass object properly
showContextMenu(newMarkerPosition, tileBox, true); showContextMenu(newMarkerPosition, tileBox, true);
view.refreshMap(); view.refreshMap();
} }
@ -202,7 +237,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) {
selectedObj = selectedObjects.keySet().iterator().next(); Object 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;
@ -405,8 +440,6 @@ public class ContextMenuLayer extends OsmandMapLayer {
LatLon getObjectLocation(Object o); LatLon getObjectLocation(Object o);
String getObjectDescription(Object o);
PointDescription getObjectName(Object o); PointDescription getObjectName(Object o);
boolean disableSingleTap(); boolean disableSingleTap();
@ -414,8 +447,18 @@ public class ContextMenuLayer extends OsmandMapLayer {
boolean disableLongPressOnMap(); boolean disableLongPressOnMap();
boolean isObjectClickable(Object o); boolean isObjectClickable(Object o);
} }
public interface IMoveObjectProvider {
boolean isObjectMoveable(Object o);
boolean applyNewObjectPosition(Object o, LatLon position);
}
public interface IContextMenuProviderSelection { public interface IContextMenuProviderSelection {
int getOrder(Object o); int getOrder(Object o);

View file

@ -11,7 +11,6 @@ import android.graphics.PointF;
import android.text.TextPaint; import android.text.TextPaint;
import android.util.DisplayMetrics; import android.util.DisplayMetrics;
import android.view.WindowManager; import android.view.WindowManager;
import net.osmand.IndexConstants; import net.osmand.IndexConstants;
import net.osmand.binary.BinaryMapDataObject; import net.osmand.binary.BinaryMapDataObject;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
@ -547,4 +546,5 @@ public class DownloadedRegionsLayer extends OsmandMapLayer implements IContextMe
public void clearSelectedObject() { public void clearSelectedObject() {
selectedObjects = new LinkedList<>(); selectedObjects = new LinkedList<>();
} }
} }

View file

@ -1,5 +1,19 @@
package net.osmand.plus.views; package net.osmand.plus.views;
import java.util.ArrayList;
import java.util.List;
import net.osmand.data.FavouritePoint;
import net.osmand.data.LatLon;
import net.osmand.data.PointDescription;
import net.osmand.data.QuadRect;
import net.osmand.data.QuadTree;
import net.osmand.data.RotatedTileBox;
import net.osmand.plus.FavouritesDbHelper;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.base.FavoriteImageDrawable;
import net.osmand.plus.views.MapTextLayer.MapTextProvider;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.BitmapFactory; import android.graphics.BitmapFactory;
import android.graphics.Canvas; import android.graphics.Canvas;
@ -10,50 +24,30 @@ import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter; import android.graphics.PorterDuffColorFilter;
import android.support.annotation.ColorInt; import android.support.annotation.ColorInt;
import net.osmand.data.FavouritePoint; public class FavoritesLayer extends OsmandMapLayer implements ContextMenuLayer.IContextMenuProvider,
import net.osmand.data.LatLon; ContextMenuLayer.IMoveObjectProvider, MapTextProvider<FavouritePoint> {
import net.osmand.data.LocationPoint;
import net.osmand.data.PointDescription;
import net.osmand.data.QuadRect;
import net.osmand.data.QuadTree;
import net.osmand.data.RotatedTileBox;
import net.osmand.plus.FavouritesDbHelper;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.base.FavoriteImageDrawable;
import net.osmand.plus.views.MapTextLayer.MapTextProvider;
import java.util.ArrayList;
import java.util.List;
public class FavoritesLayer extends OsmandMapLayer implements ContextMenuLayer.IContextMenuProvider, MapTextProvider<LocationPoint> {
protected int startZoom = 6; protected int startZoom = 6;
protected OsmandMapTileView view; protected OsmandMapTileView view;
private Paint paint; private Paint paint;
private FavouritesDbHelper favorites; private FavouritesDbHelper favorites;
protected List<LocationPoint> cache = new ArrayList<LocationPoint>(); protected List<FavouritePoint> cache = new ArrayList<FavouritePoint>();
private MapTextLayer textLayer; private MapTextLayer textLayer;
private ContextMenuLayer contextMenuLayer;
private Paint paintIcon; private Paint paintIcon;
private Bitmap pointSmall; private Bitmap pointSmall;
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() {
return (Class<? extends LocationPoint>) FavouritePoint.class;
}
protected String getObjName() { protected String getObjName() {
return view.getContext().getString(R.string.favorite); return view.getContext().getString(R.string.favorite);
} }
protected List<? extends LocationPoint> getPoints() { protected List<? extends FavouritePoint> getPoints() {
return favorites.getFavouritePoints(); return favorites.getFavouritePoints();
} }
@ -67,6 +61,7 @@ public class FavoritesLayer extends OsmandMapLayer implements ContextMenuLayer.
settings = view.getApplication().getSettings(); settings = view.getApplication().getSettings();
favorites = view.getApplication().getFavorites(); favorites = view.getApplication().getFavorites();
textLayer = view.getLayerByClass(MapTextLayer.class); textLayer = view.getLayerByClass(MapTextLayer.class);
contextMenuLayer = view.getLayerByClass(ContextMenuLayer.class);
paintIcon = new Paint(); paintIcon = new Paint();
pointSmall = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_white_shield_small); pointSmall = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_white_shield_small);
defaultColor = view.getResources().getColor(R.color.color_favorite); defaultColor = view.getResources().getColor(R.color.color_favorite);
@ -92,9 +87,11 @@ 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) { if (contextMenuLayer.getMoveableObject() instanceof FavouritePoint) {
FavoriteImageDrawable fid = FavoriteImageDrawable.getOrCreate(view.getContext(), objectInMotion.getColor(), true); FavouritePoint fp = (FavouritePoint) contextMenuLayer.getMoveableObject();
fid.drawBitmapInCenter(canvas, objectInMotionX, objectInMotionY); FavoriteImageDrawable fid = FavoriteImageDrawable.getOrCreate(view.getContext(), fp.getColor(), true);
PointF pf = contextMenuLayer.getMoveableCenterPoint(tileBox);
fid.drawBitmapInCenter(canvas, pf.x, pf.y);
} }
} }
@ -109,10 +106,10 @@ public class FavoritesLayer extends OsmandMapLayer implements ContextMenuLayer.
// request to load // request to load
final QuadRect latLonBounds = tileBox.getLatLonBounds(); final QuadRect latLonBounds = tileBox.getLatLonBounds();
List<LocationPoint> fullObjects = new ArrayList<>(); List<FavouritePoint> fullObjects = new ArrayList<>();
List<LatLon> fullObjectsLatLon = new ArrayList<>(); List<LatLon> fullObjectsLatLon = new ArrayList<>();
List<LatLon> smallObjectsLatLon = new ArrayList<>(); List<LatLon> smallObjectsLatLon = new ArrayList<>();
for (LocationPoint o : getPoints()) { for (FavouritePoint o : getPoints()) {
if (!o.isVisible()) { if (!o.isVisible()) {
continue; continue;
} }
@ -130,8 +127,8 @@ public class FavoritesLayer extends OsmandMapLayer implements ContextMenuLayer.
fullObjectsLatLon.add(new LatLon(o.getLatitude(), o.getLongitude())); fullObjectsLatLon.add(new LatLon(o.getLatitude(), o.getLongitude()));
} }
} }
for (LocationPoint o : fullObjects) { for (FavouritePoint o : fullObjects) {
if (o != objectInMotion) { if (o != contextMenuLayer.getMoveableObject()) {
drawPoint(canvas, tileBox, latLonBounds, o); drawPoint(canvas, tileBox, latLonBounds, o);
} }
} }
@ -146,7 +143,7 @@ public class FavoritesLayer extends OsmandMapLayer implements ContextMenuLayer.
} }
private void drawPoint(Canvas canvas, RotatedTileBox tileBox, final QuadRect latLonBounds, LocationPoint o) { private void drawPoint(Canvas canvas, RotatedTileBox tileBox, final QuadRect latLonBounds, FavouritePoint o) {
if (o.isVisible() && o.getLatitude() >= latLonBounds.bottom && o.getLatitude() <= latLonBounds.top && o.getLongitude() >= latLonBounds.left if (o.isVisible() && o.getLatitude() >= latLonBounds.bottom && o.getLatitude() <= latLonBounds.top && o.getLongitude() >= latLonBounds.left
&& o.getLongitude() <= latLonBounds.right ) { && o.getLongitude() <= latLonBounds.right ) {
cache.add(o); cache.add(o);
@ -163,17 +160,17 @@ public class FavoritesLayer extends OsmandMapLayer implements ContextMenuLayer.
return false; return false;
} }
public void getFavoriteFromPoint(RotatedTileBox tb, PointF point, List<? super LocationPoint> res) { public void getFavoriteFromPoint(RotatedTileBox tb, PointF point, List<? super FavouritePoint> res) {
int r = (int) (15 * tb.getDensity()); int r = (int) (15 * tb.getDensity());
int ex = (int) point.x; int ex = (int) point.x;
int ey = (int) point.y; int ey = (int) point.y;
for (LocationPoint n : getPoints()) { for (FavouritePoint n : getPoints()) {
getFavFromPoint(tb, res, r, ex, ey, n); getFavFromPoint(tb, res, r, ex, ey, n);
} }
} }
private void getFavFromPoint(RotatedTileBox tb, List<? super LocationPoint> res, int r, int ex, int ey, private void getFavFromPoint(RotatedTileBox tb, List<? super FavouritePoint> res, int r, int ex, int ey,
LocationPoint n) { FavouritePoint n) {
if (n.isVisible()) { if (n.isVisible()) {
int x = (int) tb.getPixXFromLatLon(n.getLatitude(), n.getLongitude()); int x = (int) tb.getPixXFromLatLon(n.getLatitude(), n.getLongitude());
int y = (int) tb.getPixYFromLatLon(n.getLatitude(), n.getLongitude()); int y = (int) tb.getPixYFromLatLon(n.getLatitude(), n.getLongitude());
@ -183,21 +180,11 @@ public class FavoritesLayer extends OsmandMapLayer implements ContextMenuLayer.
} }
} }
@Override
public String getObjectDescription(Object o) {
Class<? extends LocationPoint> fcl = getFavoriteClass();
if(o!= null && fcl.isInstance(o)) {
return PointDescription.getSimpleName((LocationPoint) o, view.getContext()) ;
}
return null;
}
@Override @Override
public PointDescription getObjectName(Object o) { public PointDescription getObjectName(Object o) {
if(o instanceof LocationPoint){ if(o instanceof FavouritePoint){
return ((LocationPoint) o).getPointDescription(view.getContext()); //$NON-NLS-1$ return ((FavouritePoint) o).getPointDescription(view.getContext()); //$NON-NLS-1$
} }
return null; return null;
} }
@ -214,7 +201,7 @@ public class FavoritesLayer extends OsmandMapLayer implements ContextMenuLayer.
@Override @Override
public boolean isObjectClickable(Object o) { public boolean isObjectClickable(Object o) {
return o instanceof LocationPoint && o != objectInMotion; return o instanceof FavouritePoint && o != contextMenuLayer.getMoveableObject();
} }
@Override @Override
@ -226,36 +213,40 @@ public class FavoritesLayer extends OsmandMapLayer implements ContextMenuLayer.
@Override @Override
public LatLon getObjectLocation(Object o) { public LatLon getObjectLocation(Object o) {
if(o instanceof LocationPoint){ if(o instanceof FavouritePoint){
return new LatLon(((LocationPoint)o).getLatitude(), ((LocationPoint)o).getLongitude()); return new LatLon(((FavouritePoint)o).getLatitude(), ((FavouritePoint)o).getLongitude());
} }
return null; return null;
} }
@Override @Override
public LatLon getTextLocation(LocationPoint o) { public LatLon getTextLocation(FavouritePoint o) {
return new LatLon(o.getLatitude(), o.getLongitude()); return new LatLon(o.getLatitude(), o.getLongitude());
} }
@Override @Override
public int getTextShift(LocationPoint o, RotatedTileBox rb) { public int getTextShift(FavouritePoint o, RotatedTileBox rb) {
return (int) (16 * rb.getDensity()); return (int) (16 * rb.getDensity());
} }
@Override @Override
public String getText(LocationPoint o) { public String getText(FavouritePoint o) {
return PointDescription.getSimpleName(o, view.getContext()); return PointDescription.getSimpleName(o, view.getContext());
} }
@Override @Override
public boolean onTryMovingObject(Object selectedObject, RotatedTileBox tileBox) { public boolean isObjectMoveable(Object o) {
if (selectedObject instanceof LocationPoint) { return o instanceof FavouritePoint;
objectInMotion = (LocationPoint) selectedObject; }
objectInMotionX = (int) tileBox.getPixXFromLatLon(objectInMotion.getLatitude(), objectInMotion.getLongitude());
objectInMotionY = (int) tileBox.getPixYFromLatLon(objectInMotion.getLatitude(), objectInMotion.getLongitude()); @Override
public boolean applyNewObjectPosition(Object o, LatLon position) {
if(o instanceof FavouritePoint) {
favorites.editFavourite((FavouritePoint) o, position.getLatitude(), position.getLongitude());
return true; return true;
} }
return super.onTryMovingObject(selectedObject, tileBox); return false;
} }
} }

View file

@ -12,7 +12,6 @@ import android.graphics.PointF;
import android.graphics.PorterDuff; import android.graphics.PorterDuff;
import android.graphics.PorterDuff.Mode; import android.graphics.PorterDuff.Mode;
import android.graphics.PorterDuffColorFilter; import android.graphics.PorterDuffColorFilter;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
import net.osmand.data.PointDescription; import net.osmand.data.PointDescription;
import net.osmand.data.QuadRect; import net.osmand.data.QuadRect;
@ -473,6 +472,4 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
} }
} }

View file

@ -6,7 +6,6 @@ import android.graphics.Canvas;
import android.graphics.Paint; import android.graphics.Paint;
import android.graphics.PointF; import android.graphics.PointF;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import net.osmand.Location; import net.osmand.Location;
import net.osmand.binary.RouteDataObject; import net.osmand.binary.RouteDataObject;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;

View file

@ -12,7 +12,6 @@ import android.os.Handler;
import android.os.Message; import android.os.Message;
import android.view.GestureDetector; import android.view.GestureDetector;
import android.view.MotionEvent; import android.view.MotionEvent;
import net.osmand.Location; import net.osmand.Location;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
import net.osmand.data.PointDescription; import net.osmand.data.PointDescription;
@ -489,4 +488,5 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi
@Override @Override
public void clearSelectedObject() { public void clearSelectedObject() {
} }
} }

View file

@ -1,10 +1,11 @@
package net.osmand.plus.views; package net.osmand.plus.views;
import android.content.Context; import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.View; import android.view.View;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
import net.osmand.data.RotatedTileBox;
import net.osmand.plus.IconsCache; import net.osmand.plus.IconsCache;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
@ -40,11 +41,21 @@ public class MoveMarkerBottomSheetHelper {
}); });
} }
public void show(double lat, double lon) { public void onDraw(RotatedTileBox rt) {
mView.setVisibility(View.VISIBLE); double lat = rt.getLatFromPixel(rt.getPixWidth() / 2, rt.getPixHeight() / 2);
double lon = rt.getLonFromPixel(rt.getPixWidth() / 2, rt.getPixHeight() / 2);
mDescription.setText(mContext.getString(R.string.lat_lon_pattern, lat, lon)); mDescription.setText(mContext.getString(R.string.lat_lon_pattern, lat, lon));
} }
public boolean isVisible() {
return mView.getVisibility() == View.VISIBLE;
}
public void show(Drawable drawable) {
mView.setVisibility(View.VISIBLE);
((ImageView) mView.findViewById(R.id.icon)).setImageDrawable(drawable);
}
public void hide() { public void hide() {
mView.setVisibility(View.GONE); mView.setVisibility(View.GONE);
} }

View file

@ -53,9 +53,6 @@ public abstract class OsmandMapLayer {
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);

View file

@ -604,14 +604,6 @@ 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);

View file

@ -33,7 +33,6 @@ import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams; import android.widget.LinearLayout.LayoutParams;
import android.widget.ScrollView; import android.widget.ScrollView;
import android.widget.TextView; import android.widget.TextView;
import net.osmand.PlatformUtil; import net.osmand.PlatformUtil;
import net.osmand.ResultMatcher; import net.osmand.ResultMatcher;
import net.osmand.ValueHolder; import net.osmand.ValueHolder;
@ -558,4 +557,6 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon
r.getDisplayMetrics() r.getDisplayMetrics()
); );
} }
} }

View file

@ -8,7 +8,6 @@ import android.graphics.Paint;
import android.graphics.Paint.Style; import android.graphics.Paint.Style;
import android.graphics.PointF; import android.graphics.PointF;
import android.graphics.RectF; import android.graphics.RectF;
import net.osmand.Location; import net.osmand.Location;
import net.osmand.PlatformUtil; import net.osmand.PlatformUtil;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
@ -223,4 +222,5 @@ public class PointLocationLayer extends OsmandMapLayer implements ContextMenuLay
} }
} }
} }
} }

View file

@ -8,7 +8,6 @@ import android.graphics.Paint;
import android.graphics.Paint.Align; import android.graphics.Paint.Align;
import android.graphics.Paint.Style; import android.graphics.Paint.Style;
import android.graphics.PointF; import android.graphics.PointF;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
import net.osmand.data.PointDescription; import net.osmand.data.PointDescription;
import net.osmand.data.QuadPoint; import net.osmand.data.QuadPoint;
@ -242,4 +241,6 @@ public class PointNavigationLayer extends OsmandMapLayer implements IContextMenu
} }
return null; return null;
} }
} }

View file

@ -8,7 +8,6 @@ import android.graphics.Paint;
import android.graphics.PointF; import android.graphics.PointF;
import android.util.DisplayMetrics; import android.util.DisplayMetrics;
import android.view.WindowManager; import android.view.WindowManager;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
import net.osmand.data.PointDescription; import net.osmand.data.PointDescription;
import net.osmand.data.QuadRect; import net.osmand.data.QuadRect;
@ -217,4 +216,5 @@ public class TransportStopsLayer extends OsmandMapLayer implements ContextMenuLa
} }
return null; return null;
} }
} }