This commit is contained in:
Alexey Kulish 2016-05-12 23:32:09 +03:00 committed by GaidamakUA
parent be674d94b8
commit 62bd2a8e3f
7 changed files with 210 additions and 65 deletions

View file

@ -1857,20 +1857,24 @@ public class OsmandSettings {
List<Integer> ns = getPositions(ps.size());
List<Boolean> bs = getSelections(ps.size());
int index = ps.indexOf(new LatLon(latitude, longitude));
ds.set(index, PointDescription.serializeToString(historyDescription));
if (cs.size() > index) {
cs.set(index, colorIndex);
if (index != -1) {
ds.set(index, PointDescription.serializeToString(historyDescription));
if (cs.size() > index) {
cs.set(index, colorIndex);
}
if (ns.size() > index) {
ns.set(index, pos);
}
if (bs.size() > index) {
bs.set(index, selected);
}
if (historyDescription != null && !historyDescription.isSearchingAddress(ctx)) {
SearchHistoryHelper.getInstance(ctx).addNewItemToHistory(latitude, longitude, historyDescription);
}
return savePoints(ps, ds, cs, ns, bs);
} else {
return false;
}
if (ns.size() > index) {
ns.set(index, pos);
}
if (bs.size() > index) {
bs.set(index, selected);
}
if (historyDescription != null && !historyDescription.isSearchingAddress(ctx)) {
SearchHistoryHelper.getInstance(ctx).addNewItemToHistory(latitude, longitude, historyDescription);
}
return savePoints(ps, ds, cs, ns, bs);
}
public boolean movePoint(LatLon latLonEx, LatLon latLonNew) {
@ -1880,11 +1884,14 @@ public class OsmandSettings {
List<Integer> ns = getPositions(ps.size());
List<Boolean> bs = getSelections(ps.size());
int index = ps.indexOf(latLonEx);
if (ps.size() > index) {
ps.set(index, latLonNew);
if (index != -1) {
if (ps.size() > index) {
ps.set(index, latLonNew);
}
return savePoints(ps, ds, cs, ns, bs);
} else {
return false;
}
return savePoints(ps, ds, cs, ns, bs);
}
@Override

View file

@ -138,14 +138,15 @@ public class AvoidSpecificRoads {
@Override
public boolean processResult(LatLon result) {
addImpassableRoad(mapActivity, result, true);
addImpassableRoad(mapActivity, result, true, null);
return true;
}
});
}
public void addImpassableRoad(final MapActivity activity, final LatLon loc, final boolean showDialog) {
public void addImpassableRoad(final MapActivity activity, final LatLon loc,
final boolean showDialog, final AvoidSpecificRoadsCallback callback) {
final Location ll = new Location("");
ll.setLatitude(loc.getLatitude());
ll.setLongitude(loc.getLongitude());
@ -153,34 +154,85 @@ public class AvoidSpecificRoads {
@Override
public boolean publish(RouteDataObject object) {
if(object == null) {
if (object == null) {
Toast.makeText(activity, R.string.error_avoid_specific_road, Toast.LENGTH_LONG).show();
if (callback != null) {
callback.onAddImpassableRoad(false, null);
}
} else {
getBuilder().addImpassableRoad(object, ll);
RoutingHelper rh = app.getRoutingHelper();
if(rh.isRouteCalculated() || rh.isRouteBeingCalculated()) {
rh.recalculateRouteDueToSettingsChange();
addImpassableRoadInternal(object, ll, showDialog, activity, loc);
if (callback != null) {
callback.onAddImpassableRoad(true, object);
}
if (showDialog) {
showDialog(activity);
}
MapContextMenu menu = activity.getContextMenu();
if (menu.isActive() && menu.getLatLon().equals(loc)) {
menu.close();
}
activity.refreshMap();
}
return true;
}
@Override
public boolean isCancelled() {
if (callback != null) {
return callback.isCancelled();
}
return false;
}
});
}
public void replaceImpassableRoad(final MapActivity activity, final RouteDataObject currentObject,
final LatLon loc, final boolean showDialog,
final AvoidSpecificRoadsCallback callback) {
final Location ll = new Location("");
ll.setLatitude(loc.getLatitude());
ll.setLongitude(loc.getLongitude());
app.getLocationProvider().getRouteSegment(ll, new ResultMatcher<RouteDataObject>() {
@Override
public boolean publish(RouteDataObject object) {
if (object == null) {
Toast.makeText(activity, R.string.error_avoid_specific_road, Toast.LENGTH_LONG).show();
if (callback != null) {
callback.onAddImpassableRoad(false, null);
}
} else {
getBuilder().removeImpassableRoad(currentObject);
addImpassableRoadInternal(object, ll, showDialog, activity, loc);
if (callback != null) {
callback.onAddImpassableRoad(true, object);
}
}
return true;
}
@Override
public boolean isCancelled() {
if (callback != null) {
return callback.isCancelled();
}
return false;
}
});
}
private void addImpassableRoadInternal(RouteDataObject object, Location ll, boolean showDialog, MapActivity activity, LatLon loc) {
getBuilder().addImpassableRoad(object, ll);
RoutingHelper rh = app.getRoutingHelper();
if(rh.isRouteCalculated() || rh.isRouteBeingCalculated()) {
rh.recalculateRouteDueToSettingsChange();
}
if (showDialog) {
showDialog(activity);
}
MapContextMenu menu = activity.getContextMenu();
if (menu.isActive() && menu.getLatLon().equals(loc)) {
menu.close();
}
activity.refreshMap();
}
private void showOnMap(MapActivity ctx, double lat, double lon, String name,
DialogInterface dialog) {
AnimateDraggingMapThread thread = ctx.getMapView().getAnimatedDraggingThread();
@ -195,4 +247,10 @@ public class AvoidSpecificRoads {
dialog.dismiss();
}
public interface AvoidSpecificRoadsCallback {
void onAddImpassableRoad(boolean success, RouteDataObject newObject);
boolean isCancelled();
}
}

View file

@ -58,6 +58,8 @@ public class ContextMenuLayer extends OsmandMapLayer {
private final MoveMarkerBottomSheetHelper mMoveMarkerBottomSheetHelper;
private boolean mInChangeMarkerPositionMode;
private IContextMenuProvider selectedObjectContextMenuProvider;
private boolean cancelApplyingNewMarkerPosition;
private LatLon applyingMarkerLatLon;
public ContextMenuLayer(MapActivity activity) {
this.activity = activity;
@ -181,7 +183,13 @@ public class ContextMenuLayer extends OsmandMapLayer {
public PointF getMoveableCenterPoint(RotatedTileBox tb) {
return new PointF(tb.getPixWidth() / 2, tb.getPixHeight() / 2);
if (applyingMarkerLatLon != null) {
float x = tb.getPixXFromLatLon(applyingMarkerLatLon.getLatitude(), applyingMarkerLatLon.getLongitude());
float y = tb.getPixYFromLatLon(applyingMarkerLatLon.getLatitude(), applyingMarkerLatLon.getLongitude());
return new PointF(x, y);
} else {
return new PointF(tb.getPixWidth() / 2, tb.getPixHeight() / 2);
}
}
public Object getMoveableObject() {
@ -205,12 +213,12 @@ public class ContextMenuLayer extends OsmandMapLayer {
return false;
}
public void applyMovedObject(Object o, LatLon position) {
public void applyMovedObject(Object o, LatLon position, ApplyMovedObjectCallback callback) {
if (selectedObjectContextMenuProvider != null
&& selectedObjectContextMenuProvider instanceof ContextMenuLayer.IMoveObjectProvider) {
final IMoveObjectProvider l = (ContextMenuLayer.IMoveObjectProvider) selectedObjectContextMenuProvider;
if (l.isObjectMovable(o)) {
l.applyNewObjectPosition(o, position);
l.applyNewObjectPosition(o, position, callback);
}
}
}
@ -222,18 +230,35 @@ public class ContextMenuLayer extends OsmandMapLayer {
RotatedTileBox tileBox = activity.getMapView().getCurrentRotatedTileBox();
PointF newMarkerPosition = getMoveableCenterPoint(tileBox);
LatLon ll = tileBox.getLatLonFromPixel(newMarkerPosition.x, newMarkerPosition.y);
final LatLon ll = tileBox.getLatLonFromPixel(newMarkerPosition.x, newMarkerPosition.y);
applyingMarkerLatLon = ll;
Object obj = getMoveableObject();
applyMovedObject(obj, ll);
quitMovingMarker();
cancelApplyingNewMarkerPosition = false;
mMoveMarkerBottomSheetHelper.enterApplyPositionMode();
applyMovedObject(obj, ll, new ApplyMovedObjectCallback() {
@Override
public void onApplyMovedObject(boolean success, Object newObject) {
mMoveMarkerBottomSheetHelper.exitApplyPositionMode();
if (success && !cancelApplyingNewMarkerPosition) {
mMoveMarkerBottomSheetHelper.hide();
quitMovingMarker();
PointDescription pointDescription = null;
if (selectedObjectContextMenuProvider != null) {
pointDescription = selectedObjectContextMenuProvider.getObjectName(obj);
}
menu.show(ll, pointDescription, obj);
view.refreshMap();
PointDescription pointDescription = null;
if (selectedObjectContextMenuProvider != null) {
pointDescription = selectedObjectContextMenuProvider.getObjectName(newObject);
}
menu.show(ll, pointDescription, newObject);
view.refreshMap();
}
applyingMarkerLatLon = null;
}
@Override
public boolean isCancelled() {
return cancelApplyingNewMarkerPosition;
}
});
}
private void quitMovingMarker() {
@ -259,8 +284,10 @@ public class ContextMenuLayer extends OsmandMapLayer {
}
public void cancelMovingMarker() {
cancelApplyingNewMarkerPosition = true;
quitMovingMarker();
activity.getContextMenu().show();
applyingMarkerLatLon = null;
}
public boolean showContextMenu(double latitude, double longitude, boolean showUnknownLocation) {
@ -494,10 +521,16 @@ public class ContextMenuLayer extends OsmandMapLayer {
boolean isObjectMovable(Object o);
boolean applyNewObjectPosition(Object o, LatLon position);
void applyNewObjectPosition(Object o, LatLon position, ApplyMovedObjectCallback callback);
}
public interface ApplyMovedObjectCallback {
void onApplyMovedObject(boolean success, Object newObject);
boolean isCancelled();
}
public interface IContextMenuProviderSelection {

View file

@ -21,6 +21,7 @@ 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.ContextMenuLayer.ApplyMovedObjectCallback;
import net.osmand.plus.views.MapTextLayer.MapTextProvider;
import java.util.ArrayList;
@ -243,12 +244,15 @@ public class FavoritesLayer extends OsmandMapLayer implements ContextMenuLayer.
}
@Override
public boolean applyNewObjectPosition(Object o, LatLon position) {
if(o instanceof FavouritePoint) {
favorites.editFavourite((FavouritePoint) o, position.getLatitude(), position.getLongitude());
return true;
public void applyNewObjectPosition(Object o, LatLon position, ApplyMovedObjectCallback callback) {
boolean result = false;
if (o instanceof FavouritePoint) {
favorites.editFavourite((FavouritePoint) o, position.getLatitude(), position.getLongitude());
result = true;
}
if (callback != null) {
callback.onApplyMovedObject(result, o);
}
return false;
}
}

View file

@ -17,7 +17,9 @@ import net.osmand.plus.ContextMenuItem;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.helpers.AvoidSpecificRoads.AvoidSpecificRoadsCallback;
import net.osmand.plus.routing.RoutingHelper;
import net.osmand.plus.views.ContextMenuLayer.ApplyMovedObjectCallback;
import java.util.List;
import java.util.Map;
@ -182,7 +184,7 @@ public class ImpassableRoadsLayer extends OsmandMapLayer implements
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int pos, boolean isChecked) {
if (itemId == R.string.avoid_road) {
activity.getMyApplication().getAvoidSpecificRoads().addImpassableRoad(
activity, latLon, false);
activity, latLon, false, null);
}
return true;
}
@ -201,13 +203,26 @@ public class ImpassableRoadsLayer extends OsmandMapLayer implements
}
@Override
public boolean applyNewObjectPosition(Object o, LatLon position) {
public void applyNewObjectPosition(Object o, LatLon position, final ApplyMovedObjectCallback callback) {
if (o instanceof RouteDataObject) {
RouteDataObject object = (RouteDataObject) o;
OsmandApplication application = activity.getMyApplication();
application.getDefaultRoutingConfig().removeImpassableRoad(object);
application.getAvoidSpecificRoads().addImpassableRoad(activity, position, false);
final RouteDataObject object = (RouteDataObject) o;
final OsmandApplication application = activity.getMyApplication();
application.getAvoidSpecificRoads().replaceImpassableRoad(activity, object, position, false, new AvoidSpecificRoadsCallback() {
@Override
public void onAddImpassableRoad(boolean success, RouteDataObject newObject) {
if (callback != null) {
callback.onApplyMovedObject(success, newObject);
}
}
@Override
public boolean isCancelled() {
if (callback != null) {
return callback.isCancelled();
}
return false;
}
});
}
return false;
}
}

View file

@ -27,6 +27,7 @@ import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.TargetPointsHelper.TargetPoint;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.views.ContextMenuLayer.ApplyMovedObjectCallback;
import net.osmand.plus.views.ContextMenuLayer.IContextMenuProvider;
import net.osmand.plus.views.ContextMenuLayer.IContextMenuProviderSelection;
import net.osmand.plus.views.mapwidgets.MapMarkersWidgetsFactory;
@ -513,13 +514,21 @@ public class MapMarkersLayer extends OsmandMapLayer implements IContextMenuProvi
}
@Override
public boolean applyNewObjectPosition(Object o, LatLon position) {
public void applyNewObjectPosition(Object o, LatLon position, ApplyMovedObjectCallback callback) {
boolean result = false;
Object newObject = null;
if (o instanceof MapMarker) {
MapMarkersHelper markersHelper = map.getMyApplication().getMapMarkersHelper();
MapMarker marker = (MapMarker) o;
int index = markersHelper.getActiveMapMarkers().indexOf(marker);
markersHelper.moveMapMarker(marker, position);
return true;
if (index != -1) {
newObject = markersHelper.getActiveMapMarkers().get(index);
}
result = true;
}
if (callback != null) {
callback.onApplyMovedObject(result, newObject == null ? o : newObject);
}
return false;
}
}

View file

@ -1,10 +1,12 @@
package net.osmand.plus.views;
import android.content.Context;
import android.graphics.PointF;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import net.osmand.data.RotatedTileBox;
import net.osmand.plus.IconsCache;
import net.osmand.plus.R;
@ -15,6 +17,7 @@ public class MoveMarkerBottomSheetHelper {
private final TextView mDescription;
private final Context mContext;
private final ContextMenuLayer mContextMenuLayer;
private boolean applyingPositionMode;
public MoveMarkerBottomSheetHelper(MapActivity activity, ContextMenuLayer contextMenuLayer) {
mContextMenuLayer = contextMenuLayer;
@ -28,7 +31,6 @@ public class MoveMarkerBottomSheetHelper {
mView.findViewById(R.id.apply_button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
hide();
mContextMenuLayer.applyNewMarkerPosition();
}
});
@ -42,8 +44,9 @@ public class MoveMarkerBottomSheetHelper {
}
public void onDraw(RotatedTileBox rt) {
double lat = rt.getLatFromPixel(rt.getPixWidth() / 2, rt.getPixHeight() / 2);
double lon = rt.getLonFromPixel(rt.getPixWidth() / 2, rt.getPixHeight() / 2);
PointF point = mContextMenuLayer.getMoveableCenterPoint(rt);
double lat = rt.getLatFromPixel(point.x, point.y);
double lon = rt.getLonFromPixel(point.x, point.y);
mDescription.setText(mContext.getString(R.string.lat_lon_pattern, lat, lon));
}
@ -52,11 +55,27 @@ public class MoveMarkerBottomSheetHelper {
}
public void show(Drawable drawable) {
exitApplyPositionMode();
mView.setVisibility(View.VISIBLE);
((ImageView) mView.findViewById(R.id.icon)).setImageDrawable(drawable);
}
public void hide() {
exitApplyPositionMode();
mView.setVisibility(View.GONE);
}
public void enterApplyPositionMode() {
if (!applyingPositionMode) {
applyingPositionMode = true;
mView.findViewById(R.id.apply_button).setEnabled(false);
}
}
public void exitApplyPositionMode() {
if (applyingPositionMode) {
applyingPositionMode = false;
mView.findViewById(R.id.apply_button).setEnabled(true);
}
}
}