Fix moving object
This commit is contained in:
parent
598cf9385a
commit
f5717b63ed
1 changed files with 67 additions and 58 deletions
|
@ -18,8 +18,8 @@ import android.view.View;
|
||||||
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.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;
|
||||||
|
@ -30,15 +30,13 @@ import net.osmand.plus.activities.MapActivity;
|
||||||
import net.osmand.plus.mapcontextmenu.MapContextMenu;
|
import net.osmand.plus.mapcontextmenu.MapContextMenu;
|
||||||
import net.osmand.plus.mapcontextmenu.other.MapMultiSelectionMenu;
|
import net.osmand.plus.mapcontextmenu.other.MapMultiSelectionMenu;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class ContextMenuLayer extends OsmandMapLayer {
|
public class ContextMenuLayer extends OsmandMapLayer {
|
||||||
private static final Log LOG = PlatformUtil.getLog(ContextMenuLayer.class);
|
//private static final Log LOG = PlatformUtil.getLog(ContextMenuLayer.class);
|
||||||
public static final int VIBRATE_SHORT = 100;
|
public static final int VIBRATE_SHORT = 100;
|
||||||
|
|
||||||
private OsmandMapTileView view;
|
private OsmandMapTileView view;
|
||||||
|
@ -59,6 +57,7 @@ public class ContextMenuLayer extends OsmandMapLayer {
|
||||||
|
|
||||||
private final MoveMarkerBottomSheetHelper mMoveMarkerBottomSheetHelper;
|
private final MoveMarkerBottomSheetHelper mMoveMarkerBottomSheetHelper;
|
||||||
private boolean mInChangeMarkerPositionMode;
|
private boolean mInChangeMarkerPositionMode;
|
||||||
|
private IContextMenuProvider selectedObjectContextMenuProvider;
|
||||||
|
|
||||||
public ContextMenuLayer(MapActivity activity) {
|
public ContextMenuLayer(MapActivity activity) {
|
||||||
this.activity = activity;
|
this.activity = activity;
|
||||||
|
@ -108,11 +107,11 @@ public class ContextMenuLayer extends OsmandMapLayer {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mInChangeMarkerPositionMode) {
|
if (mInChangeMarkerPositionMode) {
|
||||||
// TODO draw marker if selection was only marker?
|
if (menu.getObject() == null) {
|
||||||
// int x = previousMarkerX;
|
canvas.translate(box.getPixWidth() / 2 - contextMarker.getWidth() / 2, box.getPixHeight() / 2 - contextMarker.getHeight());
|
||||||
// int y = previousMarkerY;
|
contextMarker.draw(canvas);
|
||||||
// canvas.translate(x - contextMarker.getWidth() / 2, y - contextMarker.getHeight());
|
}
|
||||||
// contextMarker.draw(canvas);
|
mMoveMarkerBottomSheetHelper.onDraw(box);
|
||||||
} 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());
|
||||||
|
@ -153,11 +152,13 @@ public class ContextMenuLayer extends OsmandMapLayer {
|
||||||
}
|
}
|
||||||
if (pressedContextMarker(tileBox, point.x, point.y)) {
|
if (pressedContextMarker(tileBox, point.x, point.y)) {
|
||||||
Object obj = menu.getObject();
|
Object obj = menu.getObject();
|
||||||
if (obj != null && isObjectMoveable(obj)) {
|
if (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);
|
||||||
|
|
||||||
activity.getContextMenu().hide();
|
menu.updateMapCenter(null);
|
||||||
|
menu.hide();
|
||||||
|
|
||||||
LatLon ll = menu.getLatLon();
|
LatLon ll = menu.getLatLon();
|
||||||
RotatedTileBox rb = new RotatedTileBox(tileBox);
|
RotatedTileBox rb = new RotatedTileBox(tileBox);
|
||||||
rb.setCenterLocation(0.5f, 0.5f);
|
rb.setCenterLocation(0.5f, 0.5f);
|
||||||
|
@ -179,7 +180,6 @@ public class ContextMenuLayer extends OsmandMapLayer {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public PointF getMoveableCenterPoint(RotatedTileBox tb) {
|
public PointF getMoveableCenterPoint(RotatedTileBox tb) {
|
||||||
return new PointF(tb.getPixWidth() / 2, tb.getPixHeight() / 2);
|
return new PointF(tb.getPixWidth() / 2, tb.getPixHeight() / 2);
|
||||||
}
|
}
|
||||||
|
@ -193,25 +193,24 @@ public class ContextMenuLayer extends OsmandMapLayer {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isObjectMoveable(Object o) {
|
public boolean isObjectMoveable(Object o) {
|
||||||
for (OsmandMapLayer lt : view.getLayers()) {
|
if (o == null) {
|
||||||
if (lt instanceof ContextMenuLayer.IMoveObjectProvider) {
|
return true;
|
||||||
final IMoveObjectProvider l = (ContextMenuLayer.IMoveObjectProvider) lt;
|
} else if (selectedObjectContextMenuProvider != null
|
||||||
|
&& selectedObjectContextMenuProvider instanceof ContextMenuLayer.IMoveObjectProvider) {
|
||||||
|
final IMoveObjectProvider l = (ContextMenuLayer.IMoveObjectProvider) selectedObjectContextMenuProvider;
|
||||||
if (l.isObjectMoveable(o)) {
|
if (l.isObjectMoveable(o)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void applyMovedObject(Object o, LatLon position) {
|
public void applyMovedObject(Object o, LatLon position) {
|
||||||
for (OsmandMapLayer lt : view.getLayers()) {
|
if (selectedObjectContextMenuProvider != null
|
||||||
if (lt instanceof ContextMenuLayer.IMoveObjectProvider) {
|
&& selectedObjectContextMenuProvider instanceof ContextMenuLayer.IMoveObjectProvider) {
|
||||||
final IMoveObjectProvider l = (ContextMenuLayer.IMoveObjectProvider) lt;
|
final IMoveObjectProvider l = (ContextMenuLayer.IMoveObjectProvider) selectedObjectContextMenuProvider;
|
||||||
if (l.isObjectMoveable(o)) {
|
if (l.isObjectMoveable(o)) {
|
||||||
l.applyNewObjectPosition(o, position);
|
l.applyNewObjectPosition(o, position);
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -220,14 +219,20 @@ public class ContextMenuLayer extends OsmandMapLayer {
|
||||||
if (!mInChangeMarkerPositionMode) {
|
if (!mInChangeMarkerPositionMode) {
|
||||||
throw new IllegalStateException("Not in change marker position mode");
|
throw new IllegalStateException("Not in change marker position mode");
|
||||||
}
|
}
|
||||||
Object obj = getMoveableObject();
|
|
||||||
quitMovingMarker();
|
|
||||||
RotatedTileBox tileBox = activity.getMapView().getCurrentRotatedTileBox();
|
RotatedTileBox tileBox = activity.getMapView().getCurrentRotatedTileBox();
|
||||||
PointF newMarkerPosition = getMoveableCenterPoint(tileBox);
|
PointF newMarkerPosition = getMoveableCenterPoint(tileBox);
|
||||||
LatLon ll = tileBox.getLatLonFromPixel(newMarkerPosition.x, newMarkerPosition.y);
|
LatLon ll = tileBox.getLatLonFromPixel(newMarkerPosition.x, newMarkerPosition.y);
|
||||||
|
|
||||||
|
Object obj = getMoveableObject();
|
||||||
applyMovedObject(obj, ll);
|
applyMovedObject(obj, ll);
|
||||||
// TODO pass object properly
|
quitMovingMarker();
|
||||||
showContextMenu(newMarkerPosition, tileBox, true);
|
|
||||||
|
PointDescription pointDescription = null;
|
||||||
|
if (selectedObjectContextMenuProvider != null) {
|
||||||
|
pointDescription = selectedObjectContextMenuProvider.getObjectName(obj);
|
||||||
|
}
|
||||||
|
menu.show(ll, pointDescription, obj);
|
||||||
view.refreshMap();
|
view.refreshMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -245,8 +250,8 @@ public class ContextMenuLayer extends OsmandMapLayer {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void mark(int status, int... widgets) {
|
private void mark(int status, int... widgets) {
|
||||||
for(int i = 0; i < widgets.length ; i++) {
|
for (int widget : widgets) {
|
||||||
View v = activity.findViewById(widgets[i]);
|
View v = activity.findViewById(widget);
|
||||||
if (v != null) {
|
if (v != null) {
|
||||||
v.setVisibility(status);
|
v.setVisibility(status);
|
||||||
}
|
}
|
||||||
|
@ -269,29 +274,30 @@ public class ContextMenuLayer extends OsmandMapLayer {
|
||||||
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();
|
Object selectedObj = selectedObjects.keySet().iterator().next();
|
||||||
IContextMenuProvider contextObject = selectedObjects.get(selectedObj);
|
selectedObjectContextMenuProvider = selectedObjects.get(selectedObj);
|
||||||
LatLon latLon = null;
|
LatLon latLon = null;
|
||||||
PointDescription pointDescription = null;
|
PointDescription pointDescription = null;
|
||||||
if (contextObject != null) {
|
if (selectedObjectContextMenuProvider != null) {
|
||||||
latLon = contextObject.getObjectLocation(selectedObj);
|
latLon = selectedObjectContextMenuProvider.getObjectLocation(selectedObj);
|
||||||
pointDescription = contextObject.getObjectName(selectedObj);
|
pointDescription = selectedObjectContextMenuProvider.getObjectName(selectedObj);
|
||||||
}
|
}
|
||||||
if (latLon == null) {
|
if (latLon == null) {
|
||||||
latLon = getLatLon(point, tileBox);
|
latLon = getLatLon(point, tileBox);
|
||||||
}
|
}
|
||||||
hideVisibleMenues();
|
hideVisibleMenues();
|
||||||
activity.getMapViewTrackingUtilities().locationChanged(latLon.getLatitude(), latLon.getLongitude(), this);
|
activity.getMapViewTrackingUtilities().setMapLinkedToLocation(false);
|
||||||
menu.show(latLon, pointDescription, selectedObj);
|
menu.show(latLon, pointDescription, selectedObj);
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
} else if (selectedObjects.size() > 1) {
|
} else if (selectedObjects.size() > 1) {
|
||||||
|
selectedObjectContextMenuProvider = null;
|
||||||
showContextMenuForSelectedObjects(getLatLon(point, tileBox), selectedObjects);
|
showContextMenuForSelectedObjects(getLatLon(point, tileBox), selectedObjects);
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
} else if (showUnknownLocation) {
|
} else if (showUnknownLocation) {
|
||||||
hideVisibleMenues();
|
hideVisibleMenues();
|
||||||
LatLon latLon = getLatLon(point, tileBox);
|
LatLon latLon = getLatLon(point, tileBox);
|
||||||
activity.getMapViewTrackingUtilities().locationChanged(latLon.getLatitude(), latLon.getLongitude(), this);
|
activity.getMapViewTrackingUtilities().setMapLinkedToLocation(false);
|
||||||
menu.show(latLon, null, null);
|
menu.show(latLon, null, null);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -308,9 +314,6 @@ public class ContextMenuLayer extends OsmandMapLayer {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean disableSingleTap() {
|
public boolean disableSingleTap() {
|
||||||
if (mInChangeMarkerPositionMode) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
boolean res = false;
|
boolean res = false;
|
||||||
for (OsmandMapLayer lt : view.getLayers()) {
|
for (OsmandMapLayer lt : view.getLayers()) {
|
||||||
if (lt instanceof ContextMenuLayer.IContextMenuProvider) {
|
if (lt instanceof ContextMenuLayer.IContextMenuProvider) {
|
||||||
|
@ -398,6 +401,10 @@ public class ContextMenuLayer extends OsmandMapLayer {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onSingleTap(PointF point, RotatedTileBox tileBox) {
|
public boolean onSingleTap(PointF point, RotatedTileBox tileBox) {
|
||||||
|
if (mInChangeMarkerPositionMode) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
if (pressedContextMarker(tileBox, point.x, point.y)) {
|
if (pressedContextMarker(tileBox, point.x, point.y)) {
|
||||||
hideVisibleMenues();
|
hideVisibleMenues();
|
||||||
menu.show();
|
menu.show();
|
||||||
|
@ -449,10 +456,12 @@ public class ContextMenuLayer extends OsmandMapLayer {
|
||||||
|
|
||||||
switch (event.getAction()) {
|
switch (event.getAction()) {
|
||||||
case MotionEvent.ACTION_DOWN:
|
case MotionEvent.ACTION_DOWN:
|
||||||
|
if (!mInChangeMarkerPositionMode) {
|
||||||
selectObjectsForContextMenu(tileBox, new PointF(event.getX(), event.getY()), true);
|
selectObjectsForContextMenu(tileBox, new PointF(event.getX(), event.getY()), true);
|
||||||
if (pressedLatLonFull.size() > 0 || pressedLatLonSmall.size() > 0) {
|
if (pressedLatLonFull.size() > 0 || pressedLatLonSmall.size() > 0) {
|
||||||
view.refreshMap();
|
view.refreshMap();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case MotionEvent.ACTION_UP:
|
case MotionEvent.ACTION_UP:
|
||||||
case MotionEvent.ACTION_CANCEL:
|
case MotionEvent.ACTION_CANCEL:
|
||||||
|
|
Loading…
Reference in a new issue