diff --git a/OsmAnd/src/net/osmand/data/PointDescription.java b/OsmAnd/src/net/osmand/data/PointDescription.java index dc7c77e169..a6dba0c26a 100644 --- a/OsmAnd/src/net/osmand/data/PointDescription.java +++ b/OsmAnd/src/net/osmand/data/PointDescription.java @@ -24,7 +24,7 @@ public class PointDescription { public static final String POINT_TYPE_FAVORITE = "favorite"; public static final String POINT_TYPE_WPT = "wpt"; - public static final String POINT_TYPE_ROUTE = "route_point"; + public static final String POINT_TYPE_RTE = "rte"; public static final String POINT_TYPE_POI = "poi"; public static final String POINT_TYPE_ADDRESS = "address"; public static final String POINT_TYPE_OSM_NOTE= "osm_note"; @@ -213,8 +213,8 @@ public class PointDescription { return POINT_TYPE_WPT.equals(type); } - public boolean isRoutePoint() { - return POINT_TYPE_ROUTE.equals(type); + public boolean isRte() { + return POINT_TYPE_RTE.equals(type); } public boolean isPoi() { diff --git a/OsmAnd/src/net/osmand/plus/GPXUtilities.java b/OsmAnd/src/net/osmand/plus/GPXUtilities.java index 8828982286..add5920fad 100644 --- a/OsmAnd/src/net/osmand/plus/GPXUtilities.java +++ b/OsmAnd/src/net/osmand/plus/GPXUtilities.java @@ -848,7 +848,7 @@ public class GPXUtilities { return false; } - public WptPt addWptPt(double lat, double lon, long time, String description, String name, String category, int color, PointDescription pointDescription) { + public WptPt addWptPt(double lat, double lon, long time, String description, String name, String category, int color) { double latAdjusted = Double.parseDouble(latLonFormat.format(lat)); double lonAdjusted = Double.parseDouble(latLonFormat.format(lon)); final WptPt pt = new WptPt(latAdjusted, lonAdjusted, time, Double.NaN, 0, Double.NaN); @@ -859,15 +859,30 @@ public class GPXUtilities { pt.setColor(color); } - if (pointDescription == null || pointDescription.isWpt()) { - points.add(pt); - } else if (pointDescription.isRoutePoint()) { - if (routes.size() == 0) { - routes.add(new Route()); - } - Route currentRoute = routes.get(routes.size() -1); - currentRoute.points.add(pt); + points.add(pt); + + modifiedTime = System.currentTimeMillis(); + + return pt; + } + + public WptPt addRtePt(double lat, double lon, long time, String description, String name, String category, int color) { + double latAdjusted = Double.parseDouble(latLonFormat.format(lat)); + double lonAdjusted = Double.parseDouble(latLonFormat.format(lon)); + final WptPt pt = new WptPt(latAdjusted, lonAdjusted, time, Double.NaN, 0, Double.NaN); + pt.name = name; + pt.category = category; + pt.desc = description; + if (color != 0) { + pt.setColor(color); } + + if (routes.size() == 0) { + routes.add(new Route()); + } + Route currentRoute = routes.get(routes.size() -1); + currentRoute.points.add(pt); + modifiedTime = System.currentTimeMillis(); return pt; diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index c1291862aa..1ebbaa3a57 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -103,7 +103,7 @@ import net.osmand.plus.routing.RoutingHelper.RouteCalculationProgressCallback; import net.osmand.plus.search.QuickSearchDialogFragment; import net.osmand.plus.search.QuickSearchDialogFragment.QuickSearchTab; import net.osmand.plus.search.QuickSearchDialogFragment.QuickSearchType; -import net.osmand.plus.views.AddGpxPointBottomSheetHelper.NewPoint; +import net.osmand.plus.views.AddGpxPointBottomSheetHelper.NewGpxPoint; import net.osmand.plus.views.AnimateDraggingMapThread; import net.osmand.plus.views.MapControlsLayer; import net.osmand.plus.views.MapInfoLayer; @@ -917,9 +917,9 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven } else if (toShow instanceof QuadRect) { QuadRect qr = (QuadRect) toShow; mapView.fitRectToMap(qr.left, qr.right, qr.top, qr.bottom, (int) qr.width(), (int) qr.height(), 0); - } else if (toShow instanceof NewPoint) { - NewPoint newPoint = (NewPoint) toShow; - getMapLayers().getContextMenuLayer().enterAddGpxPointMode(newPoint); + } else if (toShow instanceof NewGpxPoint) { + NewGpxPoint newGpxPoint = (NewGpxPoint) toShow; + getMapLayers().getContextMenuLayer().enterAddGpxPointMode(newGpxPoint); } else { mapContextMenu.show(latLonToShow, mapLabelToShow, toShow); } diff --git a/OsmAnd/src/net/osmand/plus/activities/TrackActivity.java b/OsmAnd/src/net/osmand/plus/activities/TrackActivity.java index 75ba250957..01b2b413e5 100644 --- a/OsmAnd/src/net/osmand/plus/activities/TrackActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/TrackActivity.java @@ -37,7 +37,6 @@ public class TrackActivity extends TabActivity { public static final String TRACK_FILE_NAME = "TRACK_FILE_NAME"; public static final String CURRENT_RECORDING = "CURRENT_RECORDING"; - public static boolean openPointsTab = false; protected List> fragList = new ArrayList<>(); protected PagerSlidingTabStrip slidingTabLayout; private File file = null; diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java index defbcb878b..a95257580a 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java @@ -40,6 +40,7 @@ import net.osmand.plus.mapcontextmenu.MenuController.TitleProgressController; import net.osmand.plus.mapcontextmenu.controllers.MapDataMenuController; import net.osmand.plus.mapcontextmenu.editors.FavoritePointEditor; import net.osmand.plus.mapcontextmenu.editors.PointEditor; +import net.osmand.plus.mapcontextmenu.editors.RtePtEditor; import net.osmand.plus.mapcontextmenu.editors.WptPtEditor; import net.osmand.plus.mapcontextmenu.other.MapMultiSelectionMenu; import net.osmand.plus.mapcontextmenu.other.ShareMenu; @@ -64,6 +65,7 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL private FavoritePointEditor favoritePointEditor; private WptPtEditor wptPtEditor; + private RtePtEditor rtePtEditor; private boolean active; private LatLon latLon; @@ -147,6 +149,9 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL if (wptPtEditor != null) { wptPtEditor.setMapActivity(mapActivity); } + if (rtePtEditor != null) { + rtePtEditor.setMapActivity(mapActivity); + } if (active) { acquireMenuController(false); @@ -196,11 +201,20 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL return wptPtEditor; } + public RtePtEditor getRtePtPointEditor() { + if (rtePtEditor == null) { + rtePtEditor = new RtePtEditor(mapActivity); + } + return rtePtEditor; + } + public PointEditor getPointEditor(String tag) { if (favoritePointEditor != null && favoritePointEditor.getFragmentTag().equals(tag)) { return favoritePointEditor; } else if (wptPtEditor != null && wptPtEditor.getFragmentTag().equals(tag)) { return wptPtEditor; + } else if (rtePtEditor != null && rtePtEditor.getFragmentTag().equals(tag)) { + return rtePtEditor; } return null; } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/GpxPointEditor.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/GpxPointEditor.java new file mode 100644 index 0000000000..50b0aa1513 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/GpxPointEditor.java @@ -0,0 +1,28 @@ +package net.osmand.plus.mapcontextmenu.editors; + +import net.osmand.plus.GPXUtilities.GPXFile; +import net.osmand.plus.GPXUtilities.WptPt; +import net.osmand.plus.activities.MapActivity; + +public abstract class GpxPointEditor extends PointEditor { + + protected GPXFile gpxFile; + protected WptPt wpt; + protected boolean gpxSelected; + + public GpxPointEditor(MapActivity mapActivity) { + super(mapActivity); + } + + public GPXFile getGpxFile() { + return gpxFile; + } + + public boolean isGpxSelected() { + return gpxSelected; + } + + public WptPt getWptPt() { + return wpt; + } +} diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/RtePtEditor.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/RtePtEditor.java new file mode 100644 index 0000000000..a585c47212 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/RtePtEditor.java @@ -0,0 +1,90 @@ +package net.osmand.plus.mapcontextmenu.editors; + +import net.osmand.data.LatLon; +import net.osmand.plus.FavouritesDbHelper; +import net.osmand.plus.GPXUtilities.GPXFile; +import net.osmand.plus.GPXUtilities.WptPt; +import net.osmand.plus.GpxSelectionHelper; +import net.osmand.plus.activities.MapActivity; + +public class RtePtEditor extends GpxPointEditor { + + public static final String TAG = "RtePtEditorFragment"; + + public RtePtEditor(MapActivity mapActivity) { + super(mapActivity); + } + + @Override + public String getFragmentTag() { + return TAG; + } + + public void add(GPXFile gpxFile, LatLon latLon, String title) { + if (latLon == null) { + return; + } + isNew = true; + + this.gpxFile = gpxFile; + GpxSelectionHelper.SelectedGpxFile selectedGpxFile = + mapActivity.getMyApplication().getSelectedGpxHelper().getSelectedFileByPath(gpxFile.path); + gpxSelected = selectedGpxFile != null; + + wpt = new WptPt(latLon.getLatitude(), latLon.getLongitude(), + System.currentTimeMillis(), Double.NaN, 0, Double.NaN); + wpt.name = title; + RtePtEditorFragment.showInstance(mapActivity); + } + + public void add(GPXFile gpxFile, LatLon latLon, String title, String categoryName, int categoryColor, boolean skipDialog) { + if (latLon == null) { + return; + } + isNew = true; + + this.gpxFile = gpxFile; + GpxSelectionHelper.SelectedGpxFile selectedGpxFile = + mapActivity.getMyApplication().getSelectedGpxHelper().getSelectedFileByPath(gpxFile.path); + gpxSelected = selectedGpxFile != null; + + wpt = new WptPt(latLon.getLatitude(), latLon.getLongitude(), + System.currentTimeMillis(), Double.NaN, 0, Double.NaN); + + wpt.name = title; + + if (categoryName != null && !categoryName.isEmpty()) { + + FavouritesDbHelper.FavoriteGroup category = mapActivity.getMyApplication() + .getFavorites() + .getGroup(categoryName); + + if (category == null) { + + mapActivity.getMyApplication() + .getFavorites() + .addEmptyCategory(categoryName, categoryColor); + } + + } else categoryName = ""; + + wpt.category = categoryName; + + RtePtEditorFragment.showInstance(mapActivity, skipDialog); + } + + public void edit(WptPt wpt) { + if (wpt == null) { + return; + } + isNew = false; + GpxSelectionHelper.SelectedGpxFile selectedGpxFile = + mapActivity.getMyApplication().getSelectedGpxHelper().getSelectedGPXFile(wpt); + if (selectedGpxFile != null) { + gpxSelected = true; + gpxFile = selectedGpxFile.getGpxFile(); + } + this.wpt = wpt; + RtePtEditorFragment.showInstance(mapActivity); + } +} diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/RtePtEditorFragment.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/RtePtEditorFragment.java new file mode 100644 index 0000000000..34fe2ed8a4 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/RtePtEditorFragment.java @@ -0,0 +1,281 @@ +package net.osmand.plus.mapcontextmenu.editors; + +import android.app.Activity; +import android.app.AlertDialog; +import android.content.DialogInterface; +import android.graphics.drawable.Drawable; +import android.os.AsyncTask; +import android.os.Bundle; +import android.support.annotation.Nullable; +import android.view.View; + +import net.osmand.data.LatLon; +import net.osmand.plus.FavouritesDbHelper; +import net.osmand.plus.GPXUtilities; +import net.osmand.plus.GPXUtilities.GPXFile; +import net.osmand.plus.GPXUtilities.WptPt; +import net.osmand.plus.GpxSelectionHelper; +import net.osmand.plus.OsmandApplication; +import net.osmand.plus.R; +import net.osmand.plus.activities.MapActivity; +import net.osmand.plus.activities.SavingTrackHelper; +import net.osmand.plus.base.FavoriteImageDrawable; +import net.osmand.plus.mapcontextmenu.MapContextMenu; +import net.osmand.util.Algorithms; + +import java.io.File; + +public class RtePtEditorFragment extends PointEditorFragment{ + private WptPtEditor editor; + private WptPt wpt; + private SavingTrackHelper savingTrackHelper; + private GpxSelectionHelper selectedGpxHelper; + + private boolean saved; + private int color; + private int defaultColor; + private boolean skipDialog; + + @Override + public void onAttach(Activity activity) { + super.onAttach(activity); + savingTrackHelper = getMapActivity().getMyApplication().getSavingTrackHelper(); + selectedGpxHelper = getMapActivity().getMyApplication().getSelectedGpxHelper(); + editor = getMapActivity().getContextMenu().getWptPtPointEditor(); + defaultColor = getResources().getColor(R.color.gpx_color_point); + } + + @Override + public void onCreate(final Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + wpt = editor.getWptPt(); + + FavouritesDbHelper.FavoriteGroup group = getMyApplication().getFavorites().getGroup(wpt.category); + + if (group == null) { + color = wpt.getColor(0); + } else { + color = group.color; + } + } + + @Override + public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); + + if (skipDialog) { + save(true); + } + } + + @Override + public PointEditor getEditor() { + return editor; + } + + @Override + public String getToolbarTitle() { + return getMapActivity().getResources().getString(R.string.save_route_point); + } + + public static void showInstance(final MapActivity mapActivity) { + RtePtEditor editor = mapActivity.getContextMenu().getRtePtPointEditor(); + //int slideInAnim = editor.getSlideInAnimation(); + //int slideOutAnim = editor.getSlideOutAnimation(); + + RtePtEditorFragment fragment = new RtePtEditorFragment(); + mapActivity.getSupportFragmentManager().beginTransaction() + //.setCustomAnimations(slideInAnim, slideOutAnim, slideInAnim, slideOutAnim) + .add(R.id.fragmentContainer, fragment, editor.getFragmentTag()) + .addToBackStack(null).commit(); + } + + public static void showInstance(final MapActivity mapActivity, boolean skipDialog) { + RtePtEditor editor = mapActivity.getContextMenu().getRtePtPointEditor(); + //int slideInAnim = editor.getSlideInAnimation(); + //int slideOutAnim = editor.getSlideOutAnimation(); + + RtePtEditorFragment fragment = new RtePtEditorFragment(); + fragment.skipDialog = skipDialog; + + mapActivity.getSupportFragmentManager().beginTransaction() + //.setCustomAnimations(slideInAnim, slideOutAnim, slideInAnim, slideOutAnim) + .add(R.id.fragmentContainer, fragment, editor.getFragmentTag()) + .addToBackStack(null).commit(); + } + + @Override + protected boolean wasSaved() { + return saved; + } + + @Override + protected void save(boolean needDismiss) { + String name = Algorithms.isEmpty(getNameTextValue()) ? null : getNameTextValue(); + String category = Algorithms.isEmpty(getCategoryTextValue()) ? null : getCategoryTextValue(); + String description = Algorithms.isEmpty(getDescriptionTextValue()) ? null : getDescriptionTextValue(); + if (editor.isNew()) { + doAddWpt(name, category, description); + } else { + doUpdateWpt(name, category, description); + } + getMapActivity().refreshMap(); + if (needDismiss) { + dismiss(false); + } + + MapContextMenu menu = getMapActivity().getContextMenu(); + + if (menu.getLatLon() != null) { + + LatLon latLon = new LatLon(wpt.getLatitude(), wpt.getLongitude()); + + if (menu.getLatLon().equals(latLon)) { + menu.update(latLon, wpt.getPointDescription(getMapActivity()), wpt); + } + } + + saved = true; + } + + private void doAddWpt(String name, String category, String description) { + wpt.name = name; + wpt.category = category; + wpt.desc = description; + if (color != 0) { + wpt.setColor(color); + } + + GPXFile gpx = editor.getGpxFile(); + if (gpx != null) { + if (gpx.showCurrentTrack) { + wpt = savingTrackHelper.insertPointData(wpt.getLatitude(), wpt.getLongitude(), + System.currentTimeMillis(), description, name, category, color); + if (!editor.isGpxSelected()) { + selectedGpxHelper.setGpxFileToDisplay(gpx); + } + } else { + wpt = gpx.addRtePt(wpt.getLatitude(), wpt.getLongitude(), + System.currentTimeMillis(), description, name, category, color); + new RtePtEditorFragment.SaveGpxAsyncTask(getMyApplication(), gpx, editor.isGpxSelected()).execute(); + } + } + } + + private void doUpdateWpt(String name, String category, String description) { + GPXFile gpx = editor.getGpxFile(); + if (gpx != null) { + if (gpx.showCurrentTrack) { + savingTrackHelper.updatePointData(wpt, wpt.getLatitude(), wpt.getLongitude(), + System.currentTimeMillis(), description, name, category, color); + if (!editor.isGpxSelected()) { + selectedGpxHelper.setGpxFileToDisplay(gpx); + } + } else { + gpx.updateWptPt(wpt, wpt.getLatitude(), wpt.getLongitude(), + System.currentTimeMillis(), description, name, category, color); + new RtePtEditorFragment.SaveGpxAsyncTask(getMyApplication(), gpx, editor.isGpxSelected()).execute(); + } + } + } + + @Override + protected void delete(final boolean needDismiss) { + AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); + builder.setMessage(getString(R.string.context_menu_item_delete_waypoint)); + builder.setNegativeButton(R.string.shared_string_no, null); + builder.setPositiveButton(R.string.shared_string_yes, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + + GPXFile gpx = editor.getGpxFile(); + if (gpx != null) { + if (gpx.showCurrentTrack) { + savingTrackHelper.deletePointData(wpt); + } else { + gpx.deleteWptPt(wpt); + new RtePtEditorFragment.SaveGpxAsyncTask(getMyApplication(), gpx, editor.isGpxSelected()).execute(); + } + } + saved = true; + + if (needDismiss) { + dismiss(true); + } else { + getMapActivity().refreshMap(); + } + } + }); + builder.create().show(); + } + + @Override + public void setCategory(String name) { + FavouritesDbHelper.FavoriteGroup group = getMyApplication().getFavorites().getGroup(name); + if (group != null) { + color = group.color; + } + super.setCategory(name); + } + + @Override + protected String getDefaultCategoryName() { + return getString(R.string.shared_string_favorites); + } + + @Override + public String getHeaderCaption() { + return getMapActivity().getResources().getString(R.string.gpx_wpt); + } + + @Override + public String getNameInitValue() { + return wpt.name; + } + + @Override + public String getCategoryInitValue() { + return Algorithms.isEmpty(wpt.category) ? "" : wpt.category; + } + + @Override + public String getDescriptionInitValue() { + return wpt.desc; + } + + @Override + public Drawable getNameIcon() { + return FavoriteImageDrawable.getOrCreate(getMapActivity(), color == 0 ? defaultColor : color, false); + } + + @Override + public Drawable getCategoryIcon() { + return getPaintedIcon(R.drawable.ic_action_folder_stroke, color == 0 ? defaultColor : color); + } + + private static class SaveGpxAsyncTask extends AsyncTask { + private final OsmandApplication app; + private final GPXFile gpx; + private final boolean gpxSelected; + + public SaveGpxAsyncTask(OsmandApplication app, GPXFile gpx, boolean gpxSelected) { + this.app = app; + this.gpx = gpx; + this.gpxSelected = gpxSelected; + } + + @Override + protected Void doInBackground(Void... params) { + GPXUtilities.writeGpxFile(new File(gpx.path), gpx, app); + return null; + } + + @Override + protected void onPostExecute(Void aVoid) { + if (!gpxSelected) { + app.getSelectedGpxHelper().setGpxFileToDisplay(gpx); + } + } + } +} diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/WptPtEditor.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/WptPtEditor.java index c657b8b2c0..1648cecdae 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/WptPtEditor.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/WptPtEditor.java @@ -1,19 +1,13 @@ package net.osmand.plus.mapcontextmenu.editors; import net.osmand.data.LatLon; -import net.osmand.data.PointDescription; import net.osmand.plus.FavouritesDbHelper; import net.osmand.plus.GPXUtilities.GPXFile; import net.osmand.plus.GPXUtilities.WptPt; import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile; import net.osmand.plus.activities.MapActivity; -public class WptPtEditor extends PointEditor { - - private GPXFile gpxFile; - private WptPt wpt; - private boolean gpxSelected; - private PointDescription pointDescription; +public class WptPtEditor extends GpxPointEditor { public static final String TAG = "WptPtEditorFragment"; @@ -26,26 +20,6 @@ public class WptPtEditor extends PointEditor { return TAG; } - public GPXFile getGpxFile() { - return gpxFile; - } - - public PointDescription getPointDescription() { - return pointDescription; - } - - public void setPointDescription(PointDescription pointDescription) { - this.pointDescription = pointDescription; - } - - public boolean isGpxSelected() { - return gpxSelected; - } - - public WptPt getWptPt() { - return wpt; - } - public void add(GPXFile gpxFile, LatLon latLon, String title) { if (latLon == null) { return; @@ -63,24 +37,6 @@ public class WptPtEditor extends PointEditor { WptPtEditorFragment.showInstance(mapActivity); } - public void add(GPXFile gpxFile, LatLon latLon, String title, PointDescription pointDescription) { - if (latLon == null) { - return; - } - isNew = true; - this.pointDescription = pointDescription; - - this.gpxFile = gpxFile; - SelectedGpxFile selectedGpxFile = - mapActivity.getMyApplication().getSelectedGpxHelper().getSelectedFileByPath(gpxFile.path); - gpxSelected = selectedGpxFile != null; - - wpt = new WptPt(latLon.getLatitude(), latLon.getLongitude(), - System.currentTimeMillis(), Double.NaN, 0, Double.NaN); - wpt.name = title; - WptPtEditorFragment.showInstance(mapActivity); - } - public void add(GPXFile gpxFile, LatLon latLon, String title, String categoryName, int categoryColor, boolean skipDialog) { if (latLon == null) { return; diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/WptPtEditorFragment.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/WptPtEditorFragment.java index 1e5b7c1930..b368541105 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/WptPtEditorFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/WptPtEditorFragment.java @@ -10,7 +10,6 @@ import android.support.annotation.Nullable; import android.view.View; import net.osmand.data.LatLon; -import net.osmand.data.PointDescription; import net.osmand.plus.FavouritesDbHelper.FavoriteGroup; import net.osmand.plus.GPXUtilities; import net.osmand.plus.GPXUtilities.GPXFile; @@ -77,14 +76,6 @@ public class WptPtEditorFragment extends PointEditorFragment { @Override public String getToolbarTitle() { - PointDescription pointDescription = editor.getPointDescription(); - if (pointDescription != null) { - if (pointDescription.isWpt()) { - return getMapActivity().getResources().getString(R.string.save_gpx_waypoint); - } else if (pointDescription.isRoutePoint()) { - return getMapActivity().getResources().getString(R.string.save_route_point); - } - } if (editor.isNew()) { return getMapActivity().getResources().getString(R.string.context_menu_item_add_waypoint); } else { @@ -123,12 +114,6 @@ public class WptPtEditorFragment extends PointEditorFragment { return saved; } - @Override - public void onDestroyView() { - super.onDestroyView(); - editor.setPointDescription(null); - } - @Override protected void save(final boolean needDismiss) { String name = Algorithms.isEmpty(getNameTextValue()) ? null : getNameTextValue(); @@ -167,7 +152,6 @@ public class WptPtEditorFragment extends PointEditorFragment { } GPXFile gpx = editor.getGpxFile(); - PointDescription pointDescription = editor.getPointDescription(); if (gpx != null) { if (gpx.showCurrentTrack) { wpt = savingTrackHelper.insertPointData(wpt.getLatitude(), wpt.getLongitude(), @@ -177,7 +161,7 @@ public class WptPtEditorFragment extends PointEditorFragment { } } else { wpt = gpx.addWptPt(wpt.getLatitude(), wpt.getLongitude(), - System.currentTimeMillis(), description, name, category, color, pointDescription); + System.currentTimeMillis(), description, name, category, color); new SaveGpxAsyncTask(getMyApplication(), gpx, editor.isGpxSelected()).execute(); } } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/MapMultiSelectionMenu.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/MapMultiSelectionMenu.java index 0ab833895c..277b0a5cfc 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/MapMultiSelectionMenu.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/MapMultiSelectionMenu.java @@ -196,15 +196,7 @@ public class MapMultiSelectionMenu extends BaseMenuController { IContextMenuProvider provider = selectedObjects.remove(menuObject.getObject()); hide(); ContextMenuLayer contextMenuLayer = getMapActivity().getMapLayers().getContextMenuLayer(); - if (contextMenuLayer.isInAddGpxWaypointMode()) { - PointDescription pointDescription = menuObject.getPointDescription(); - String title = pointDescription == null ? "" : pointDescription.getName(); - contextMenuLayer.getAddGpxPointBottomSheetHelper().setTitle(title); - OsmandMapTileView view = menuObject.getMapActivity().getMapView(); - view.getAnimatedDraggingThread().startMoving(latLon.getLatitude(), latLon.getLongitude(), view.getZoom(), true); - } else { - contextMenuLayer.showContextMenu(menuObject.getLatLon(), menuObject.getPointDescription(), menuObject.getObject(), provider); - } + contextMenuLayer.showContextMenu(menuObject.getLatLon(), menuObject.getPointDescription(), menuObject.getObject(), provider); } private void clearSelectedObjects() { diff --git a/OsmAnd/src/net/osmand/plus/myplaces/TrackPointFragment.java b/OsmAnd/src/net/osmand/plus/myplaces/TrackPointFragment.java index 9a7dacca90..6b2d684d39 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/TrackPointFragment.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/TrackPointFragment.java @@ -57,7 +57,7 @@ import net.osmand.plus.activities.TrackActivity; import net.osmand.plus.base.FavoriteImageDrawable; import net.osmand.plus.base.OsmandExpandableListFragment; import net.osmand.plus.dialogs.DirectionsDialogs; -import net.osmand.plus.views.AddGpxPointBottomSheetHelper.NewPoint; +import net.osmand.plus.views.AddGpxPointBottomSheetHelper.NewGpxPoint; import net.osmand.util.Algorithms; import java.io.File; @@ -160,7 +160,7 @@ public class TrackPointFragment extends OsmandExpandableListFragment { routePointFab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - PointDescription pointDescription = new PointDescription(PointDescription.POINT_TYPE_ROUTE, getString(R.string.add_route_point)); + PointDescription pointDescription = new PointDescription(PointDescription.POINT_TYPE_RTE, getString(R.string.add_route_point)); addPoint(pointDescription); } }); @@ -186,7 +186,7 @@ public class TrackPointFragment extends OsmandExpandableListFragment { settings.getLastKnownMapZoom(), pointDescription, false, - new NewPoint(gpx, pointDescription)); + new NewGpxPoint(gpx, pointDescription)); MapActivity.launchMapActivityMoveToTop(getActivity()); } diff --git a/OsmAnd/src/net/osmand/plus/views/AddGpxPointBottomSheetHelper.java b/OsmAnd/src/net/osmand/plus/views/AddGpxPointBottomSheetHelper.java index c22354a457..fa61ce4669 100644 --- a/OsmAnd/src/net/osmand/plus/views/AddGpxPointBottomSheetHelper.java +++ b/OsmAnd/src/net/osmand/plus/views/AddGpxPointBottomSheetHelper.java @@ -12,7 +12,6 @@ import net.osmand.data.PointDescription; import net.osmand.data.RotatedTileBox; import net.osmand.plus.GPXUtilities.GPXFile; import net.osmand.plus.IconsCache; -import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.mapcontextmenu.MapContextMenu; @@ -28,7 +27,7 @@ public class AddGpxPointBottomSheetHelper { private final IconsCache iconsCache; private String titleText; private boolean applyingPositionMode; - private NewPoint newPoint; + private NewGpxPoint newPoint; private PointDescription pointDescription; public AddGpxPointBottomSheetHelper(final MapActivity activity, ContextMenuLayer ctxMenuLayer) { @@ -47,7 +46,11 @@ public class AddGpxPointBottomSheetHelper { contextMenuLayer.createGpxPoint(); GPXFile gpx = newPoint.getGpx(); LatLon latLon = contextMenu.getLatLon(); - activity.getContextMenu().getWptPtPointEditor().add(gpx, latLon, titleText, pointDescription); + if (pointDescription.isWpt()) { + activity.getContextMenu().getWptPtPointEditor().add(gpx, latLon, titleText); + } else if (pointDescription.isRte()) { + activity.getContextMenu().getRtePtPointEditor().add(gpx, latLon, titleText); + } } }); view.findViewById(R.id.cancel_button).setOnClickListener(new View.OnClickListener() { @@ -70,7 +73,7 @@ public class AddGpxPointBottomSheetHelper { if (title.equals("")) { if (pointDescription.isWpt()) { title = context.getString(R.string.waypoint_one); - } else if (pointDescription.isRoutePoint()) { + } else if (pointDescription.isRte()) { title = context.getString(R.string.route_point_one); } } @@ -82,13 +85,13 @@ public class AddGpxPointBottomSheetHelper { return view.getVisibility() == View.VISIBLE; } - public void show(NewPoint newPoint) { + public void show(NewGpxPoint newPoint) { this.newPoint = newPoint; pointDescription = newPoint.getPointDescription(); if (pointDescription.isWpt()) { setTitle(context.getString(R.string.waypoint_one)); icon.setImageDrawable(iconsCache.getThemedIcon(R.drawable.ic_action_marker_dark)); - } else if (pointDescription.isRoutePoint()) { + } else if (pointDescription.isRte()) { setTitle(context.getString(R.string.route_point_one)); icon.setImageDrawable(iconsCache.getThemedIcon(R.drawable.ic_action_markers_dark)); } @@ -115,11 +118,11 @@ public class AddGpxPointBottomSheetHelper { } } - public static class NewPoint { + public static class NewGpxPoint { private PointDescription pointDescription; private GPXFile gpx; - public NewPoint(GPXFile gpx, PointDescription pointDescription) { + public NewGpxPoint(GPXFile gpx, PointDescription pointDescription) { this.gpx = gpx; this.pointDescription = pointDescription; } diff --git a/OsmAnd/src/net/osmand/plus/views/ContextMenuLayer.java b/OsmAnd/src/net/osmand/plus/views/ContextMenuLayer.java index c9403635c9..c40216f5cd 100644 --- a/OsmAnd/src/net/osmand/plus/views/ContextMenuLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/ContextMenuLayer.java @@ -41,7 +41,7 @@ import net.osmand.plus.mapcontextmenu.MapContextMenu; import net.osmand.plus.mapcontextmenu.other.MapMultiSelectionMenu; import net.osmand.plus.render.MapRenderRepositories; import net.osmand.plus.render.NativeOsmandLibrary; -import net.osmand.plus.views.AddGpxPointBottomSheetHelper.NewPoint; +import net.osmand.plus.views.AddGpxPointBottomSheetHelper.NewGpxPoint; import net.osmand.util.Algorithms; import net.osmand.util.MapUtils; @@ -304,7 +304,7 @@ public class ContextMenuLayer extends OsmandMapLayer { return mInGpxDetailsMode; } - public boolean isInAddGpxWaypointMode() { + public boolean isInAddGpxPointMode() { return mInAddGpxPointMode; } @@ -322,7 +322,7 @@ public class ContextMenuLayer extends OsmandMapLayer { } public void applyMovedObject(Object o, LatLon position, ApplyMovedObjectCallback callback) { - if (selectedObjectContextMenuProvider != null && !isInAddGpxWaypointMode()) { + if (selectedObjectContextMenuProvider != null && !isInAddGpxPointMode()) { if (selectedObjectContextMenuProvider instanceof IMoveObjectProvider) { final IMoveObjectProvider l = (IMoveObjectProvider) selectedObjectContextMenuProvider; if (l.isObjectMovable(o)) { @@ -460,14 +460,14 @@ public class ContextMenuLayer extends OsmandMapLayer { } } - public void enterAddGpxPointMode(NewPoint newPoint) { + public void enterAddGpxPointMode(NewGpxPoint newGpxPoint) { menu.updateMapCenter(null); menu.hide(); activity.disableDrawer(); mInAddGpxPointMode = true; - mAddGpxPointBottomSheetHelper.show(newPoint); + mAddGpxPointBottomSheetHelper.show(newGpxPoint); mark(View.INVISIBLE, R.id.map_ruler_layout, R.id.map_left_widgets_panel, R.id.map_right_widgets_panel, R.id.map_center_info); @@ -547,15 +547,21 @@ public class ContextMenuLayer extends OsmandMapLayer { @Nullable PointDescription pointDescription, @Nullable Object object, @Nullable IContextMenuProvider provider) { - selectedObjectContextMenuProvider = provider; - hideVisibleMenues(); - activity.getMapViewTrackingUtilities().setMapLinkedToLocation(false); - if (!activity.getMapView().getCurrentRotatedTileBox().containsLatLon(latLon)) { - menu.setMapCenter(latLon); - menu.setMapPosition(activity.getMapView().getMapPosition()); - menu.setCenterMarker(true); + if (mInAddGpxPointMode) { + String title = pointDescription == null ? "" : pointDescription.getName(); + mAddGpxPointBottomSheetHelper.setTitle(title); + view.getAnimatedDraggingThread().startMoving(latLon.getLatitude(), latLon.getLongitude(), view.getZoom(), true); + } else { + selectedObjectContextMenuProvider = provider; + hideVisibleMenues(); + activity.getMapViewTrackingUtilities().setMapLinkedToLocation(false); + if (!activity.getMapView().getCurrentRotatedTileBox().containsLatLon(latLon)) { + menu.setMapCenter(latLon); + menu.setMapPosition(activity.getMapView().getMapPosition()); + menu.setCenterMarker(true); + } + menu.show(latLon, pointDescription, object); } - menu.show(latLon, pointDescription, object); return true; } diff --git a/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java b/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java index 8c7dc0d5de..ca38a06a9c 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java @@ -1120,8 +1120,8 @@ public class MapControlsLayer extends OsmandMapLayer { } private boolean isInMovingMarkerMode(){ - return mapQuickActionLayer == null ? contextMenuLayer.isInChangeMarkerPositionMode() || contextMenuLayer.isInAddGpxWaypointMode(): - mapQuickActionLayer.isInMovingMarkerMode() || contextMenuLayer.isInChangeMarkerPositionMode() || contextMenuLayer.isInAddGpxWaypointMode(); + return mapQuickActionLayer == null ? contextMenuLayer.isInChangeMarkerPositionMode() || contextMenuLayer.isInAddGpxPointMode(): + mapQuickActionLayer.isInMovingMarkerMode() || contextMenuLayer.isInChangeMarkerPositionMode() || contextMenuLayer.isInAddGpxPointMode(); } private boolean isInGpxDetailsMode() {