Merge pull request #6661 from osmandapp/gpx_issues
Gpx issues #6222, #6140
This commit is contained in:
commit
662dc8c8b9
4 changed files with 90 additions and 7 deletions
|
@ -414,7 +414,18 @@ public class MeasurementToolFragment extends BaseOsmAndFragment {
|
|||
@Override
|
||||
public void onClick(View v) {
|
||||
if (editingCtx.getPointsCount() > 0) {
|
||||
addToGpx(mapActivity);
|
||||
if (newGpxData != null && newGpxData.getActionType() == NewGpxData.ActionType.EDIT_SEGMENT
|
||||
&& editingCtx.isInSnapToRoadMode()) {
|
||||
if (mapActivity != null && measurementLayer != null) {
|
||||
if (editingCtx.getPointsCount() > 0) {
|
||||
openSaveAsNewTrackMenu(mapActivity);
|
||||
} else {
|
||||
Toast.makeText(mapActivity, getString(R.string.none_point_error), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
addToGpx(mapActivity);
|
||||
}
|
||||
} else {
|
||||
Toast.makeText(mapActivity, getString(R.string.none_point_error), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
@ -594,6 +605,17 @@ public class MeasurementToolFragment extends BaseOsmAndFragment {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void overwriteOldTrackOnClick() {
|
||||
if (mapActivity != null && measurementLayer != null) {
|
||||
if (editingCtx.getPointsCount() > 0) {
|
||||
overwriteGpx(mapActivity);
|
||||
} else {
|
||||
Toast.makeText(mapActivity, getString(R.string.none_point_error), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearAllOnClick() {
|
||||
editingCtx.getCommandManager().execute(new ClearPointsCommand(measurementLayer));
|
||||
|
@ -1116,6 +1138,14 @@ public class MeasurementToolFragment extends BaseOsmAndFragment {
|
|||
saveExistingGpx(gpx, showOnMap, actionType, true);
|
||||
}
|
||||
|
||||
private void overwriteGpx(MapActivity mapActivity) {
|
||||
GPXFile gpx = editingCtx.getNewGpxData().getGpxFile();
|
||||
SelectedGpxFile selectedGpxFile = mapActivity.getMyApplication().getSelectedGpxHelper().getSelectedFileByPath(gpx.path);
|
||||
boolean showOnMap = selectedGpxFile != null;
|
||||
ActionType actionType = ActionType.OVERWRITE_SEGMENT;
|
||||
saveExistingGpx(gpx, showOnMap, actionType, true);
|
||||
}
|
||||
|
||||
private void saveAsGpx(final SaveType saveType) {
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
if (mapActivity != null) {
|
||||
|
@ -1297,6 +1327,14 @@ public class MeasurementToolFragment extends BaseOsmAndFragment {
|
|||
segment.points.addAll(points);
|
||||
gpx.replaceSegment(editingCtx.getNewGpxData().getTrkSegment(), segment);
|
||||
break;
|
||||
case OVERWRITE_SEGMENT:
|
||||
List<WptPt> snappedPoints = new ArrayList<>();
|
||||
snappedPoints.addAll(before.points);
|
||||
snappedPoints.addAll(after.points);
|
||||
TrkSegment segment1 = new TrkSegment();
|
||||
segment1.points.addAll(snappedPoints);
|
||||
gpx.replaceSegment(editingCtx.getNewGpxData().getTrkSegment(), segment1);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
gpx.addRoutePoints(points);
|
||||
|
|
|
@ -8,7 +8,8 @@ public class NewGpxData {
|
|||
public enum ActionType {
|
||||
ADD_SEGMENT,
|
||||
ADD_ROUTE_POINTS,
|
||||
EDIT_SEGMENT
|
||||
EDIT_SEGMENT,
|
||||
OVERWRITE_SEGMENT
|
||||
}
|
||||
|
||||
private GPXUtilities.GPXFile gpxFile;
|
||||
|
|
|
@ -70,6 +70,39 @@ public class OptionsBottomSheetDialogFragment extends MenuBottomSheetDialogFragm
|
|||
})
|
||||
.create();
|
||||
items.add(saveAsNewSegmentItem);
|
||||
} else if (addLineMode) {
|
||||
|
||||
BaseBottomSheetItem saveAsNewTrackItem = new SimpleBottomSheetItem.Builder()
|
||||
.setIcon(getContentIcon(R.drawable.ic_action_polygom_dark))
|
||||
.setTitle(getString(R.string.shared_string_save_as_gpx))
|
||||
.setLayoutId(R.layout.bottom_sheet_item_simple)
|
||||
.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (listener != null) {
|
||||
listener.saveAsNewTrackOnClick();
|
||||
}
|
||||
dismiss();
|
||||
}
|
||||
})
|
||||
.create();
|
||||
items.add(saveAsNewTrackItem);
|
||||
|
||||
BaseBottomSheetItem saveAsNewSegmentItem = new SimpleBottomSheetItem.Builder()
|
||||
.setIcon(getContentIcon(R.drawable.ic_action_polygom_dark))
|
||||
.setTitle("Overwrite GPX")
|
||||
.setLayoutId(R.layout.bottom_sheet_item_simple)
|
||||
.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (listener != null) {
|
||||
listener.overwriteOldTrackOnClick();
|
||||
}
|
||||
dismiss();
|
||||
}
|
||||
})
|
||||
.create();
|
||||
items.add(saveAsNewSegmentItem);
|
||||
} else {
|
||||
BaseBottomSheetItem saveAsNewTrackItem = new SimpleBottomSheetItem.Builder()
|
||||
.setIcon(getContentIcon(R.drawable.ic_action_polygom_dark))
|
||||
|
@ -138,6 +171,8 @@ public class OptionsBottomSheetDialogFragment extends MenuBottomSheetDialogFragm
|
|||
|
||||
void addToTheTrackOnClick();
|
||||
|
||||
void overwriteOldTrackOnClick();
|
||||
|
||||
void clearAllOnClick();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
package net.osmand.plus.views;
|
||||
|
||||
import static net.osmand.plus.dialogs.ConfigureMapMenu.CURRENT_TRACK_COLOR_ATTR;
|
||||
import static net.osmand.plus.dialogs.ConfigureMapMenu.CURRENT_TRACK_WIDTH_ATTR;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Canvas;
|
||||
|
@ -108,12 +111,17 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
|
|||
@ColorInt
|
||||
private int grayColor;
|
||||
|
||||
private CommonPreference<String> currentTrackColorPref;
|
||||
private CommonPreference<String> currentTrackWidthPref;
|
||||
|
||||
@Override
|
||||
public void initLayer(OsmandMapTileView view) {
|
||||
this.view = view;
|
||||
selectedGpxHelper = view.getApplication().getSelectedGpxHelper();
|
||||
mapMarkersHelper = view.getApplication().getMapMarkersHelper();
|
||||
osmandRenderer = view.getApplication().getResourceManager().getRenderer().getRenderer();
|
||||
currentTrackColorPref = view.getSettings().getCustomRenderProperty(CURRENT_TRACK_COLOR_ATTR);
|
||||
currentTrackWidthPref = view.getSettings().getCustomRenderProperty(CURRENT_TRACK_WIDTH_ATTR);
|
||||
initUI();
|
||||
}
|
||||
|
||||
|
@ -214,23 +222,24 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
|
|||
private int updatePaints(int color, boolean routePoints, boolean currentTrack, DrawSettings nightMode, RotatedTileBox tileBox) {
|
||||
RenderingRulesStorage rrs = view.getApplication().getRendererRegistry().getCurrentSelectedRenderer();
|
||||
final boolean isNight = nightMode != null && nightMode.isNightMode();
|
||||
int hsh = calculateHash(rrs, routePoints, isNight, tileBox.getMapDensity(), tileBox.getZoom());
|
||||
int hsh = calculateHash(rrs, routePoints, isNight, tileBox.getMapDensity(), tileBox.getZoom(),
|
||||
currentTrackColorPref.get(), currentTrackWidthPref.get());
|
||||
if (hsh != cachedHash) {
|
||||
cachedHash = hsh;
|
||||
cachedColor = ContextCompat.getColor(view.getApplication(), R.color.gpx_track);
|
||||
if (rrs != null) {
|
||||
RenderingRuleSearchRequest req = new RenderingRuleSearchRequest(rrs);
|
||||
req.setBooleanFilter(rrs.PROPS.R_NIGHT_MODE, isNight);
|
||||
CommonPreference<String> p = view.getSettings().getCustomRenderProperty("currentTrackColor");
|
||||
CommonPreference<String> p = view.getSettings().getCustomRenderProperty(CURRENT_TRACK_COLOR_ATTR);
|
||||
if (p != null && p.isSet()) {
|
||||
RenderingRuleProperty ctColor = rrs.PROPS.get("currentTrackColor");
|
||||
RenderingRuleProperty ctColor = rrs.PROPS.get(CURRENT_TRACK_COLOR_ATTR);
|
||||
if (ctColor != null) {
|
||||
req.setStringFilter(ctColor, p.get());
|
||||
}
|
||||
}
|
||||
CommonPreference<String> p2 = view.getSettings().getCustomRenderProperty("currentTrackWidth");
|
||||
CommonPreference<String> p2 = view.getSettings().getCustomRenderProperty(CURRENT_TRACK_WIDTH_ATTR);
|
||||
if (p2 != null && p2.isSet()) {
|
||||
RenderingRuleProperty ctWidth = rrs.PROPS.get("currentTrackWidth");
|
||||
RenderingRuleProperty ctWidth = rrs.PROPS.get(CURRENT_TRACK_WIDTH_ATTR);
|
||||
if (ctWidth != null) {
|
||||
req.setStringFilter(ctWidth, p2.get());
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue