Fix #5781
This commit is contained in:
parent
5d0578b57e
commit
b4d79ee28c
3 changed files with 62 additions and 15 deletions
|
@ -90,6 +90,7 @@ public class MapActivityActions implements DialogProvider {
|
|||
public static final int CHANGE_POSITION_ITEM_ORDER = 3000;
|
||||
public static final int EDIT_GPX_WAYPOINT_ITEM_ORDER = 9000;
|
||||
public static final int ADD_GPX_WAYPOINT_ITEM_ORDER = 9000;
|
||||
public static final int MEASURE_DISTANCE_ITEM_ORDER = 13000;
|
||||
|
||||
private static final int DIALOG_ADD_FAVORITE = 100;
|
||||
private static final int DIALOG_REPLACE_FAVORITE = 101;
|
||||
|
@ -327,6 +328,12 @@ public class MapActivityActions implements DialogProvider {
|
|||
.setListener(listener).createItem());
|
||||
}
|
||||
|
||||
adapter.addItem(itemBuilder
|
||||
.setTitleId(R.string.measurement_tool, mapActivity)
|
||||
.setIcon(R.drawable.ic_action_ruler)
|
||||
.setOrder(MEASURE_DISTANCE_ITEM_ORDER)
|
||||
.createItem());
|
||||
|
||||
adapter.sortItemsByOrder();
|
||||
|
||||
final ArrayAdapter<ContextMenuItem> listAdapter =
|
||||
|
@ -355,6 +362,9 @@ public class MapActivityActions implements DialogProvider {
|
|||
getMyApplication().getTargetPointsHelper().setStartPoint(new LatLon(latitude, longitude),
|
||||
true, mapActivity.getContextMenu().getPointDescription());
|
||||
}
|
||||
} else if (standardId == R.string.measurement_tool) {
|
||||
mapActivity.getContextMenu().close();
|
||||
MeasurementToolFragment.showInstance(mapActivity.getSupportFragmentManager(), new LatLon(latitude, longitude));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
@ -35,6 +35,7 @@ import android.widget.Toast;
|
|||
import net.osmand.AndroidUtils;
|
||||
import net.osmand.CallbackWithObject;
|
||||
import net.osmand.IndexConstants;
|
||||
import net.osmand.data.LatLon;
|
||||
import net.osmand.plus.ApplicationMode;
|
||||
import net.osmand.plus.GPXUtilities;
|
||||
import net.osmand.plus.GPXUtilities.GPXFile;
|
||||
|
@ -110,6 +111,8 @@ public class MeasurementToolFragment extends BaseOsmAndFragment {
|
|||
|
||||
private MeasurementEditingContext editingCtx = new MeasurementEditingContext();
|
||||
|
||||
private LatLon initialPoint;
|
||||
|
||||
private enum SaveType {
|
||||
ROUTE_POINT,
|
||||
LINE
|
||||
|
@ -119,6 +122,10 @@ public class MeasurementToolFragment extends BaseOsmAndFragment {
|
|||
this.editingCtx = editingCtx;
|
||||
}
|
||||
|
||||
private void setInitialPoint(LatLon initialPoint) {
|
||||
this.initialPoint = initialPoint;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
|
@ -464,6 +471,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment {
|
|||
getMapActivity().getMapLayers().getMapControlsLayer().showMapControlsIfHidden();
|
||||
cachedMapPosition = getMapActivity().getMapView().getMapPosition();
|
||||
setDefaultMapPosition();
|
||||
addInitialPoint();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -978,6 +986,17 @@ public class MeasurementToolFragment extends BaseOsmAndFragment {
|
|||
R.id.measure_mode_controls);
|
||||
}
|
||||
|
||||
private void addInitialPoint() {
|
||||
if (initialPoint != null) {
|
||||
MeasurementToolLayer layer = getMeasurementLayer();
|
||||
if (layer != null) {
|
||||
editingCtx.getCommandManager().execute(new AddPointCommand(layer, initialPoint));
|
||||
doAddOrMovePointCommonStuff();
|
||||
initialPoint = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void addPoint() {
|
||||
MeasurementToolLayer measurementLayer = getMeasurementLayer();
|
||||
if (measurementLayer != null) {
|
||||
|
@ -1508,23 +1527,24 @@ public class MeasurementToolFragment extends BaseOsmAndFragment {
|
|||
}
|
||||
}
|
||||
|
||||
public static boolean showInstance(FragmentManager fragmentManager, LatLon initialPoint) {
|
||||
MeasurementToolFragment fragment = new MeasurementToolFragment();
|
||||
fragment.setInitialPoint(initialPoint);
|
||||
return showFragment(fragment, fragmentManager);
|
||||
}
|
||||
|
||||
public static boolean showInstance(FragmentManager fragmentManager, MeasurementEditingContext editingCtx) {
|
||||
try {
|
||||
MeasurementToolFragment fragment = new MeasurementToolFragment();
|
||||
fragment.setEditingCtx(editingCtx);
|
||||
fragment.setRetainInstance(true);
|
||||
fragmentManager.beginTransaction()
|
||||
.add(R.id.bottomFragmentContainer, fragment, MeasurementToolFragment.TAG)
|
||||
.commitAllowingStateLoss();
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
MeasurementToolFragment fragment = new MeasurementToolFragment();
|
||||
fragment.setEditingCtx(editingCtx);
|
||||
return showFragment(fragment, fragmentManager);
|
||||
}
|
||||
|
||||
public static boolean showInstance(FragmentManager fragmentManager) {
|
||||
return showFragment(new MeasurementToolFragment(), fragmentManager);
|
||||
}
|
||||
|
||||
private static boolean showFragment(MeasurementToolFragment fragment, FragmentManager fragmentManager) {
|
||||
try {
|
||||
MeasurementToolFragment fragment = new MeasurementToolFragment();
|
||||
fragment.setRetainInstance(true);
|
||||
fragmentManager.beginTransaction()
|
||||
.add(R.id.bottomFragmentContainer, fragment, MeasurementToolFragment.TAG)
|
||||
|
|
|
@ -1,23 +1,40 @@
|
|||
package net.osmand.plus.measurementtool.command;
|
||||
|
||||
import net.osmand.data.LatLon;
|
||||
import net.osmand.plus.GPXUtilities.WptPt;
|
||||
import net.osmand.plus.measurementtool.MeasurementToolLayer;
|
||||
|
||||
public class AddPointCommand extends MeasurementModeCommand {
|
||||
|
||||
private final int position;
|
||||
private int position;
|
||||
private WptPt point;
|
||||
private final boolean center;
|
||||
private boolean center;
|
||||
|
||||
public AddPointCommand(MeasurementToolLayer measurementLayer, boolean center) {
|
||||
init(measurementLayer, null, center);
|
||||
}
|
||||
|
||||
public AddPointCommand(MeasurementToolLayer measurementLayer, LatLon latLon) {
|
||||
init(measurementLayer, latLon, false);
|
||||
}
|
||||
|
||||
private void init(MeasurementToolLayer measurementLayer, LatLon latLon, boolean center) {
|
||||
this.measurementLayer = measurementLayer;
|
||||
if (latLon != null) {
|
||||
point = new WptPt();
|
||||
point.lat = latLon.getLatitude();
|
||||
point.lon = latLon.getLongitude();
|
||||
}
|
||||
this.center = center;
|
||||
position = measurementLayer.getEditingCtx().getPointsCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute() {
|
||||
if (center) {
|
||||
if (point != null) {
|
||||
measurementLayer.getEditingCtx().addPoint(point);
|
||||
measurementLayer.moveMapToPoint(position);
|
||||
} else if (center) {
|
||||
point = measurementLayer.addCenterPoint();
|
||||
} else {
|
||||
point = measurementLayer.addPoint();
|
||||
|
|
Loading…
Reference in a new issue