Move newGpxData to context
This commit is contained in:
parent
d11043ea79
commit
f3319f6062
6 changed files with 55 additions and 29 deletions
|
@ -95,6 +95,7 @@ import net.osmand.plus.mapcontextmenu.other.DestinationReachedMenu;
|
||||||
import net.osmand.plus.mapcontextmenu.other.MapRouteInfoMenu;
|
import net.osmand.plus.mapcontextmenu.other.MapRouteInfoMenu;
|
||||||
import net.osmand.plus.mapcontextmenu.other.MapRouteInfoMenuFragment;
|
import net.osmand.plus.mapcontextmenu.other.MapRouteInfoMenuFragment;
|
||||||
import net.osmand.plus.mapcontextmenu.other.TrackDetailsMenu;
|
import net.osmand.plus.mapcontextmenu.other.TrackDetailsMenu;
|
||||||
|
import net.osmand.plus.measurementtool.MeasurementEditingContext;
|
||||||
import net.osmand.plus.measurementtool.MeasurementToolFragment;
|
import net.osmand.plus.measurementtool.MeasurementToolFragment;
|
||||||
import net.osmand.plus.measurementtool.NewGpxData;
|
import net.osmand.plus.measurementtool.NewGpxData;
|
||||||
import net.osmand.plus.render.RendererRegistry;
|
import net.osmand.plus.render.RendererRegistry;
|
||||||
|
@ -944,7 +945,9 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
|
||||||
NewGpxData newGpxData = (NewGpxData) toShow;
|
NewGpxData newGpxData = (NewGpxData) toShow;
|
||||||
QuadRect qr = newGpxData.getRect();
|
QuadRect qr = newGpxData.getRect();
|
||||||
mapView.fitRectToMap(qr.left, qr.right, qr.top, qr.bottom, (int) qr.width(), (int) qr.height(), 0);
|
mapView.fitRectToMap(qr.left, qr.right, qr.top, qr.bottom, (int) qr.width(), (int) qr.height(), 0);
|
||||||
MeasurementToolFragment.showInstance(getSupportFragmentManager(), newGpxData);
|
MeasurementEditingContext editingContext = new MeasurementEditingContext();
|
||||||
|
editingContext.setNewGpxData(newGpxData);
|
||||||
|
MeasurementToolFragment.showInstance(getSupportFragmentManager(), editingContext);
|
||||||
} else {
|
} else {
|
||||||
mapContextMenu.show(latLonToShow, mapLabelToShow, toShow);
|
mapContextMenu.show(latLonToShow, mapLabelToShow, toShow);
|
||||||
}
|
}
|
||||||
|
|
|
@ -764,7 +764,7 @@ public class MapActivityActions implements DialogProvider {
|
||||||
.setListener(new ContextMenuAdapter.ItemClickListener() {
|
.setListener(new ContextMenuAdapter.ItemClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int position, boolean isChecked) {
|
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int position, boolean isChecked) {
|
||||||
MeasurementToolFragment.showInstance(mapActivity.getSupportFragmentManager(), null);
|
MeasurementToolFragment.showInstance(mapActivity.getSupportFragmentManager());
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}).createItem());
|
}).createItem());
|
||||||
|
|
|
@ -35,6 +35,8 @@ public class MeasurementEditingContext {
|
||||||
// cache should be deleted if after changed or snappedToRoadPoints
|
// cache should be deleted if after changed or snappedToRoadPoints
|
||||||
private TrkSegment afterCacheForSnap;
|
private TrkSegment afterCacheForSnap;
|
||||||
|
|
||||||
|
private NewGpxData newGpxData;
|
||||||
|
|
||||||
private int selectedPointPosition = -1;
|
private int selectedPointPosition = -1;
|
||||||
private WptPt originalPointToMove;
|
private WptPt originalPointToMove;
|
||||||
|
|
||||||
|
@ -77,6 +79,14 @@ public class MeasurementEditingContext {
|
||||||
this.inSnapToRoadMode = inSnapToRoadMode;
|
this.inSnapToRoadMode = inSnapToRoadMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public NewGpxData getNewGpxData() {
|
||||||
|
return newGpxData;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNewGpxData(NewGpxData newGpxData) {
|
||||||
|
this.newGpxData = newGpxData;
|
||||||
|
}
|
||||||
|
|
||||||
public void setProgressListener(SnapToRoadProgressListener progressListener) {
|
public void setProgressListener(SnapToRoadProgressListener progressListener) {
|
||||||
this.progressListener = progressListener;
|
this.progressListener = progressListener;
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,6 +60,7 @@ import net.osmand.plus.measurementtool.command.ClearPointsCommand;
|
||||||
import net.osmand.plus.measurementtool.command.MovePointCommand;
|
import net.osmand.plus.measurementtool.command.MovePointCommand;
|
||||||
import net.osmand.plus.measurementtool.command.RemovePointCommand;
|
import net.osmand.plus.measurementtool.command.RemovePointCommand;
|
||||||
import net.osmand.plus.measurementtool.command.ReorderPointCommand;
|
import net.osmand.plus.measurementtool.command.ReorderPointCommand;
|
||||||
|
import net.osmand.plus.measurementtool.NewGpxData.ActionType;
|
||||||
import net.osmand.plus.views.OsmandMapTileView;
|
import net.osmand.plus.views.OsmandMapTileView;
|
||||||
import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory;
|
import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory;
|
||||||
import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarController;
|
import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarController;
|
||||||
|
@ -105,7 +106,6 @@ public class MeasurementToolFragment extends Fragment {
|
||||||
private boolean portrait;
|
private boolean portrait;
|
||||||
private boolean nightMode;
|
private boolean nightMode;
|
||||||
private int previousMapPosition;
|
private int previousMapPosition;
|
||||||
private NewGpxData newGpxData;
|
|
||||||
private boolean gpxPointsAdded;
|
private boolean gpxPointsAdded;
|
||||||
|
|
||||||
private MeasurementEditingContext editingCtx = new MeasurementEditingContext();
|
private MeasurementEditingContext editingCtx = new MeasurementEditingContext();
|
||||||
|
@ -115,8 +115,8 @@ public class MeasurementToolFragment extends Fragment {
|
||||||
LINE
|
LINE
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setNewGpxData(NewGpxData newGpxData) {
|
public void setEditingCtx(MeasurementEditingContext editingCtx) {
|
||||||
this.newGpxData = newGpxData;
|
this.editingCtx = editingCtx;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
|
@ -156,7 +156,6 @@ public class MeasurementToolFragment extends Fragment {
|
||||||
Fragment selectedPointFragment = fragmentManager.findFragmentByTag(SelectedPointBottomSheetDialogFragment.TAG);
|
Fragment selectedPointFragment = fragmentManager.findFragmentByTag(SelectedPointBottomSheetDialogFragment.TAG);
|
||||||
if (selectedPointFragment != null) {
|
if (selectedPointFragment != null) {
|
||||||
SelectedPointBottomSheetDialogFragment fragment = (SelectedPointBottomSheetDialogFragment) selectedPointFragment;
|
SelectedPointBottomSheetDialogFragment fragment = (SelectedPointBottomSheetDialogFragment) selectedPointFragment;
|
||||||
fragment.setActionType(newGpxData != null ? newGpxData.getActionType() : null);
|
|
||||||
fragment.setListener(createSelectedPointFragmentListener());
|
fragment.setListener(createSelectedPointFragmentListener());
|
||||||
}
|
}
|
||||||
Fragment optionsFragment = fragmentManager.findFragmentByTag(OptionsBottomSheetDialogFragment.TAG);
|
Fragment optionsFragment = fragmentManager.findFragmentByTag(OptionsBottomSheetDialogFragment.TAG);
|
||||||
|
@ -207,9 +206,10 @@ public class MeasurementToolFragment extends Fragment {
|
||||||
distanceToCenterTv = (TextView) mainView.findViewById(R.id.distance_to_center_text_view);
|
distanceToCenterTv = (TextView) mainView.findViewById(R.id.distance_to_center_text_view);
|
||||||
|
|
||||||
mainIcon = (ImageView) mainView.findViewById(R.id.main_icon);
|
mainIcon = (ImageView) mainView.findViewById(R.id.main_icon);
|
||||||
if (newGpxData != null) {
|
final NewGpxData newGpxData = editingCtx.getNewGpxData();
|
||||||
NewGpxData.ActionType actionType = newGpxData.getActionType();
|
if (editingCtx.getNewGpxData() != null) {
|
||||||
if (actionType == NewGpxData.ActionType.ADD_SEGMENT || actionType == NewGpxData.ActionType.EDIT_SEGMENT) {
|
ActionType actionType = newGpxData.getActionType();
|
||||||
|
if (actionType == ActionType.ADD_SEGMENT || actionType == ActionType.EDIT_SEGMENT) {
|
||||||
mainIcon.setImageDrawable(getActiveIcon(R.drawable.ic_action_polygom_dark));
|
mainIcon.setImageDrawable(getActiveIcon(R.drawable.ic_action_polygom_dark));
|
||||||
} else {
|
} else {
|
||||||
mainIcon.setImageDrawable(getActiveIcon(R.drawable.ic_action_markers_dark));
|
mainIcon.setImageDrawable(getActiveIcon(R.drawable.ic_action_markers_dark));
|
||||||
|
@ -781,7 +781,7 @@ public class MeasurementToolFragment extends Fragment {
|
||||||
private void displayRoutePoints() {
|
private void displayRoutePoints() {
|
||||||
final MeasurementToolLayer measurementLayer = getMeasurementLayer();
|
final MeasurementToolLayer measurementLayer = getMeasurementLayer();
|
||||||
|
|
||||||
GPXFile gpx = newGpxData.getGpxFile();
|
GPXFile gpx = editingCtx.getNewGpxData().getGpxFile();
|
||||||
List<WptPt> points = gpx.getRoutePoints();
|
List<WptPt> points = gpx.getRoutePoints();
|
||||||
if (measurementLayer != null) {
|
if (measurementLayer != null) {
|
||||||
editingCtx.addPoints(points);
|
editingCtx.addPoints(points);
|
||||||
|
@ -793,7 +793,7 @@ public class MeasurementToolFragment extends Fragment {
|
||||||
private void displaySegmentPoints() {
|
private void displaySegmentPoints() {
|
||||||
final MeasurementToolLayer measurementLayer = getMeasurementLayer();
|
final MeasurementToolLayer measurementLayer = getMeasurementLayer();
|
||||||
|
|
||||||
TrkSegment segment = newGpxData.getTrkSegment();
|
TrkSegment segment = editingCtx.getNewGpxData().getTrkSegment();
|
||||||
List<WptPt> points = segment.points;
|
List<WptPt> points = segment.points;
|
||||||
if (measurementLayer != null) {
|
if (measurementLayer != null) {
|
||||||
editingCtx.addPoints(points);
|
editingCtx.addPoints(points);
|
||||||
|
@ -804,7 +804,6 @@ public class MeasurementToolFragment extends Fragment {
|
||||||
|
|
||||||
private void openSelectedPointMenu(MapActivity mapActivity) {
|
private void openSelectedPointMenu(MapActivity mapActivity) {
|
||||||
SelectedPointBottomSheetDialogFragment fragment = new SelectedPointBottomSheetDialogFragment();
|
SelectedPointBottomSheetDialogFragment fragment = new SelectedPointBottomSheetDialogFragment();
|
||||||
fragment.setActionType(newGpxData != null ? newGpxData.getActionType() : null);
|
|
||||||
fragment.setListener(createSelectedPointFragmentListener());
|
fragment.setListener(createSelectedPointFragmentListener());
|
||||||
fragment.show(mapActivity.getSupportFragmentManager(), SelectedPointBottomSheetDialogFragment.TAG);
|
fragment.show(mapActivity.getSupportFragmentManager(), SelectedPointBottomSheetDialogFragment.TAG);
|
||||||
}
|
}
|
||||||
|
@ -1049,10 +1048,10 @@ public class MeasurementToolFragment extends Fragment {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addToGpx(MapActivity mapActivity) {
|
private void addToGpx(MapActivity mapActivity) {
|
||||||
GPXFile gpx = newGpxData.getGpxFile();
|
GPXFile gpx = editingCtx.getNewGpxData().getGpxFile();
|
||||||
SelectedGpxFile selectedGpxFile = mapActivity.getMyApplication().getSelectedGpxHelper().getSelectedFileByPath(gpx.path);
|
SelectedGpxFile selectedGpxFile = mapActivity.getMyApplication().getSelectedGpxHelper().getSelectedFileByPath(gpx.path);
|
||||||
boolean showOnMap = selectedGpxFile != null;
|
boolean showOnMap = selectedGpxFile != null;
|
||||||
NewGpxData.ActionType actionType = newGpxData.getActionType();
|
ActionType actionType = editingCtx.getNewGpxData().getActionType();
|
||||||
saveExistingGpx(gpx, showOnMap, actionType, true);
|
saveExistingGpx(gpx, showOnMap, actionType, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1200,7 +1199,7 @@ public class MeasurementToolFragment extends Fragment {
|
||||||
case EDIT_SEGMENT:
|
case EDIT_SEGMENT:
|
||||||
TrkSegment segment = new TrkSegment();
|
TrkSegment segment = new TrkSegment();
|
||||||
segment.points.addAll(points);
|
segment.points.addAll(points);
|
||||||
gpx.replaceSegment(newGpxData.getTrkSegment(), segment);
|
gpx.replaceSegment(editingCtx.getNewGpxData().getTrkSegment(), segment);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -1390,8 +1389,8 @@ public class MeasurementToolFragment extends Fragment {
|
||||||
if (editingCtx.isInSnapToRoadMode()) {
|
if (editingCtx.isInSnapToRoadMode()) {
|
||||||
disableSnapToRoadMode();
|
disableSnapToRoadMode();
|
||||||
}
|
}
|
||||||
if (newGpxData != null) {
|
if (editingCtx.getNewGpxData() != null) {
|
||||||
GPXFile gpx = newGpxData.getGpxFile();
|
GPXFile gpx = editingCtx.getNewGpxData().getGpxFile();
|
||||||
Intent newIntent = new Intent(mapActivity, mapActivity.getMyApplication().getAppCustomization().getTrackActivity());
|
Intent newIntent = new Intent(mapActivity, mapActivity.getMyApplication().getAppCustomization().getTrackActivity());
|
||||||
newIntent.putExtra(TrackActivity.TRACK_FILE_NAME, gpx.path);
|
newIntent.putExtra(TrackActivity.TRACK_FILE_NAME, gpx.path);
|
||||||
newIntent.putExtra(TrackActivity.OPEN_TRACKS_LIST, true);
|
newIntent.putExtra(TrackActivity.OPEN_TRACKS_LIST, true);
|
||||||
|
@ -1404,10 +1403,23 @@ public class MeasurementToolFragment extends Fragment {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean showInstance(FragmentManager fragmentManager, NewGpxData newGpxData) {
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean showInstance(FragmentManager fragmentManager) {
|
||||||
try {
|
try {
|
||||||
MeasurementToolFragment fragment = new MeasurementToolFragment();
|
MeasurementToolFragment fragment = new MeasurementToolFragment();
|
||||||
fragment.setNewGpxData(newGpxData);
|
|
||||||
fragment.setRetainInstance(true);
|
fragment.setRetainInstance(true);
|
||||||
fragmentManager.beginTransaction()
|
fragmentManager.beginTransaction()
|
||||||
.add(R.id.bottomFragmentContainer, fragment, MeasurementToolFragment.TAG)
|
.add(R.id.bottomFragmentContainer, fragment, MeasurementToolFragment.TAG)
|
||||||
|
|
|
@ -185,12 +185,12 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
|
||||||
|
|
||||||
TrkSegment before = editingCtx.getBeforeTrkSegmentLine();
|
TrkSegment before = editingCtx.getBeforeTrkSegmentLine();
|
||||||
before.renders.clear();
|
before.renders.clear();
|
||||||
before.renders.add(new Renderable.StandardTrack(before.points, 17.2));
|
before.renders.add(new Renderable.StandardTrack(new ArrayList<>(before.points), 17.2));
|
||||||
before.drawRenderers(view.getZoom(), lineAttrs.paint, canvas, tb);
|
before.drawRenderers(view.getZoom(), lineAttrs.paint, canvas, tb);
|
||||||
|
|
||||||
TrkSegment after = editingCtx.getAfterTrkSegmentLine();
|
TrkSegment after = editingCtx.getAfterTrkSegmentLine();
|
||||||
after.renders.clear();
|
after.renders.clear();
|
||||||
after.renders.add(new Renderable.StandardTrack(after.points, 17.2));
|
after.renders.add(new Renderable.StandardTrack(new ArrayList<>(after.points), 17.2));
|
||||||
after.drawRenderers(view.getZoom(), lineAttrs.paint, canvas, tb);
|
after.drawRenderers(view.getZoom(), lineAttrs.paint, canvas, tb);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,9 +23,9 @@ import net.osmand.plus.IconsCache;
|
||||||
import net.osmand.plus.OsmAndFormatter;
|
import net.osmand.plus.OsmAndFormatter;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
import net.osmand.plus.activities.MapActivity;
|
import net.osmand.plus.activities.MapActivity;
|
||||||
import net.osmand.plus.activities.TrackActivity;
|
|
||||||
import net.osmand.plus.base.BottomSheetDialogFragment;
|
import net.osmand.plus.base.BottomSheetDialogFragment;
|
||||||
import net.osmand.plus.helpers.AndroidUiHelper;
|
import net.osmand.plus.helpers.AndroidUiHelper;
|
||||||
|
import net.osmand.plus.measurementtool.NewGpxData.ActionType;
|
||||||
import net.osmand.util.MapUtils;
|
import net.osmand.util.MapUtils;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -37,16 +37,11 @@ public class SelectedPointBottomSheetDialogFragment extends BottomSheetDialogFra
|
||||||
private SelectedPointFragmentListener listener;
|
private SelectedPointFragmentListener listener;
|
||||||
private boolean nightMode;
|
private boolean nightMode;
|
||||||
private boolean portrait;
|
private boolean portrait;
|
||||||
private NewGpxData.ActionType actionType;
|
|
||||||
|
|
||||||
public void setListener(SelectedPointFragmentListener listener) {
|
public void setListener(SelectedPointFragmentListener listener) {
|
||||||
this.listener = listener;
|
this.listener = listener;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setActionType(NewGpxData.ActionType actionType) {
|
|
||||||
this.actionType = actionType;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
|
@ -122,8 +117,14 @@ public class SelectedPointBottomSheetDialogFragment extends BottomSheetDialogFra
|
||||||
if (!TextUtils.isEmpty(pointTitle)) {
|
if (!TextUtils.isEmpty(pointTitle)) {
|
||||||
((TextView) mainView.findViewById(R.id.selected_point_title)).setText(pointTitle);
|
((TextView) mainView.findViewById(R.id.selected_point_title)).setText(pointTitle);
|
||||||
} else {
|
} else {
|
||||||
if (actionType == NewGpxData.ActionType.ADD_ROUTE_POINTS) {
|
NewGpxData newGpxData = measurementLayer.getEditingCtx().getNewGpxData();
|
||||||
((TextView) mainView.findViewById(R.id.selected_point_title)).setText(mapActivity.getString(R.string.route_point) + " - " + (pos + 1));
|
if (newGpxData != null) {
|
||||||
|
ActionType actionType = measurementLayer.getEditingCtx().getNewGpxData().getActionType();
|
||||||
|
if (actionType == ActionType.ADD_ROUTE_POINTS) {
|
||||||
|
((TextView) mainView.findViewById(R.id.selected_point_title)).setText(mapActivity.getString(R.string.route_point) + " - " + (pos + 1));
|
||||||
|
} else {
|
||||||
|
((TextView) mainView.findViewById(R.id.selected_point_title)).setText(mapActivity.getString(R.string.plugin_distance_point) + " - " + (pos + 1));
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
((TextView) mainView.findViewById(R.id.selected_point_title)).setText(mapActivity.getString(R.string.plugin_distance_point) + " - " + (pos + 1));
|
((TextView) mainView.findViewById(R.id.selected_point_title)).setText(mapActivity.getString(R.string.plugin_distance_point) + " - " + (pos + 1));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue