From 2ad0fe821da527f8f49f03524f69ff65b50b1e11 Mon Sep 17 00:00:00 2001 From: PavelRatushny Date: Wed, 2 Aug 2017 12:24:53 +0300 Subject: [PATCH 01/22] Fix last known location --- OsmAnd/src/net/osmand/plus/myplaces/TrackPointFragment.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/myplaces/TrackPointFragment.java b/OsmAnd/src/net/osmand/plus/myplaces/TrackPointFragment.java index 9a2fcecd5b..e2f61670ca 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/TrackPointFragment.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/TrackPointFragment.java @@ -122,7 +122,7 @@ public class TrackPointFragment extends OsmandExpandableListFragment { public void onClick(View view) { final OsmandSettings settings = app.getSettings(); GPXFile gpx = getGpx(); - Location location = app.getLocationProvider().getLastKnownLocation(); + LatLon location = settings.getLastKnownMapLocation(); if (location != null) { settings.setMapLocationToShow(location.getLatitude(), location.getLongitude(), settings.getLastKnownMapZoom(), From 2a34c6a5aa2fabb47a988fd92559111937df07b6 Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Thu, 3 Aug 2017 11:48:26 +0300 Subject: [PATCH 02/22] Rename menu item, move menu divider; add some code for save as gpx --- OsmAnd/res/layout/save_gpx_dialog.xml | 61 +++++++++++++++++++ OsmAnd/res/values/strings.xml | 4 +- .../plus/activities/MapActivityActions.java | 38 ++++++------ .../MeasurementToolFragment.java | 23 ++++++- .../measurementtool/MeasurementToolLayer.java | 2 +- 5 files changed, 106 insertions(+), 22 deletions(-) create mode 100644 OsmAnd/res/layout/save_gpx_dialog.xml diff --git a/OsmAnd/res/layout/save_gpx_dialog.xml b/OsmAnd/res/layout/save_gpx_dialog.xml new file mode 100644 index 0000000000..38ab5265d7 --- /dev/null +++ b/OsmAnd/res/layout/save_gpx_dialog.xml @@ -0,0 +1,61 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 03eeb868bc..32fe5e257c 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -9,8 +9,10 @@ 3. All your modified/created strings are in the top of the file (to make easier find what\'s translated). PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy --> + Enter name for GPX + Show on map after saving Select a location on the map and click "Add" to add a point to the ruler. - Measurement tool + Measure distance Resume/Pause Navigation Press this button to pause the navigation, or to resume it if it was already paused. Show Finish navigation dialog diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java index 19a617f998..31d29d860b 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java @@ -696,21 +696,6 @@ public class MapActivityActions implements DialogProvider { } }).createItem()); - optionsMenuHelper.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.measurement_tool, mapActivity) - .setIcon(R.drawable.ic_action_ruler) - .setListener(new ContextMenuAdapter.ItemClickListener() { - @Override - public boolean onContextMenuClick(ArrayAdapter adapter, int itemId, int position, boolean isChecked) { - MeasurementToolFragment fragment = new MeasurementToolFragment(); - mapActivity.getSupportFragmentManager() - .beginTransaction() - .add(R.id.bottomFragmentContainer, fragment, MeasurementToolFragment.TAG) - .addToBackStack(MeasurementToolFragment.TAG) - .commitAllowingStateLoss(); - return true; - } - }).createItem()); - optionsMenuHelper.addItem(new ItemBuilder().setTitleId(R.string.get_directions, mapActivity) .setIcon(R.drawable.ic_action_gdirections_dark) .setListener(new ContextMenuAdapter.ItemClickListener() { @@ -774,6 +759,21 @@ public class MapActivityActions implements DialogProvider { }).createItem()); */ + optionsMenuHelper.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.measurement_tool, mapActivity) + .setIcon(R.drawable.ic_action_ruler) + .setListener(new ContextMenuAdapter.ItemClickListener() { + @Override + public boolean onContextMenuClick(ArrayAdapter adapter, int itemId, int position, boolean isChecked) { + MeasurementToolFragment fragment = new MeasurementToolFragment(); + mapActivity.getSupportFragmentManager() + .beginTransaction() + .add(R.id.bottomFragmentContainer, fragment, MeasurementToolFragment.TAG) + .addToBackStack(MeasurementToolFragment.TAG) + .commitAllowingStateLoss(); + return true; + } + }).createItem()); + optionsMenuHelper.addItem(new ItemBuilder().setTitleId(R.string.prefs_plugins, mapActivity) .setIcon(R.drawable.ic_extension_dark) .setListener(new ItemClickListener() { @@ -843,16 +843,16 @@ public class MapActivityActions implements DialogProvider { //////////// Others OsmandPlugin.registerOptionsMenu(mapActivity, optionsMenuHelper); - int pluginsItemIndex = -1; + int measureDistanceItemIndex = -1; for (int i = 0; i < optionsMenuHelper.length(); i++) { - if (optionsMenuHelper.getItem(i).getTitleId() == R.string.prefs_plugins) { - pluginsItemIndex = i; + if (optionsMenuHelper.getItem(i).getTitleId() == R.string.measurement_tool) { + measureDistanceItemIndex = i; break; } } ItemBuilder divider = new ItemBuilder().setLayout(R.layout.drawer_divider); - divider.setPosition(pluginsItemIndex >= 0 ? pluginsItemIndex : 7); + divider.setPosition(measureDistanceItemIndex >= 0 ? measureDistanceItemIndex : 8); optionsMenuHelper.addItem(divider.createItem()); getMyApplication().getAppCustomization().prepareOptionsMenu(mapActivity, optionsMenuHelper); diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java index 5e1d1fbd87..a7114d815f 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java @@ -1,14 +1,17 @@ package net.osmand.plus.measurementtool; +import android.content.DialogInterface; import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; +import android.support.v7.app.AlertDialog; import android.view.ContextThemeWrapper; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; +import android.widget.EditText; import android.widget.ImageButton; import android.widget.ImageView; import android.widget.TextView; @@ -134,7 +137,7 @@ public class MeasurementToolFragment extends Fragment { public boolean onMenuItemClick(MenuItem menuItem) { switch (menuItem.getItemId()) { case R.id.action_save_as_gpx: - Toast.makeText(mapActivity, "Save as gpx", Toast.LENGTH_SHORT).show(); + saveAsGpxOnClick(mapActivity); return true; case R.id.action_clear_all: measurementLayer.clearPoints(); @@ -154,6 +157,24 @@ public class MeasurementToolFragment extends Fragment { return view; } + private void saveAsGpxOnClick(MapActivity mapActivity) { + LayoutInflater inflater = getLayoutInflater(); + final View view = inflater.inflate(R.layout.save_gpx_dialog, null); + EditText nameEt = view.findViewById(R.id.gpx_name_et); + + new AlertDialog.Builder(mapActivity) + .setTitle(R.string.enter_gpx_name) + .setView(view) + .setPositiveButton(R.string.shared_string_save, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + + } + }) + .setNegativeButton(R.string.shared_string_cancel, null) + .show(); + } + @Override public void onDestroyView() { super.onDestroyView(); diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolLayer.java b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolLayer.java index a0b9af50dc..451fa60093 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolLayer.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolLayer.java @@ -25,7 +25,7 @@ public class MeasurementToolLayer extends OsmandMapLayer { private OsmandMapTileView view; private boolean inMeasurementMode; private LinkedList measurementPoints = new LinkedList<>(); - private LinkedList cacheMeasurementPoints; + private LinkedList cacheMeasurementPoints = new LinkedList<>(); private Bitmap centerIconDay; private Bitmap centerIconNight; private Bitmap pointIcon; From 0122d0faa1b01407b40295b2bc93610326f16734 Mon Sep 17 00:00:00 2001 From: PavelRatushny Date: Thu, 3 Aug 2017 11:54:09 +0300 Subject: [PATCH 03/22] Add route points and styling --- ...eet.xml => add_gpx_point_bottom_sheet.xml} | 2 +- OsmAnd/res/layout-land/map_hud_bottom.xml | 2 +- ...eet.xml => add_gpx_point_bottom_sheet.xml} | 2 +- OsmAnd/res/layout/map_hud_bottom.xml | 2 +- OsmAnd/res/layout/points_tree.xml | 99 +++++++++++++++++-- OsmAnd/res/values/strings.xml | 4 +- .../src/net/osmand/data/PointDescription.java | 5 + OsmAnd/src/net/osmand/plus/GPXUtilities.java | 24 ++--- .../osmand/plus/activities/MapActivity.java | 9 +- .../mapcontextmenu/editors/WptPtEditor.java | 24 +++++ .../editors/WptPtEditorFragment.java | 4 +- .../other/MapMultiSelectionMenu.java | 13 ++- .../plus/myplaces/TrackPointFragment.java | 85 ++++++++++++---- ...java => AddGpxPointBottomSheetHelper.java} | 47 ++++++--- .../osmand/plus/views/ContextMenuLayer.java | 74 +++++++------- 15 files changed, 295 insertions(+), 101 deletions(-) rename OsmAnd/res/layout-land/{add_gpx_waypoint_bottom_sheet.xml => add_gpx_point_bottom_sheet.xml} (97%) rename OsmAnd/res/layout/{add_gpx_waypoint_bottom_sheet.xml => add_gpx_point_bottom_sheet.xml} (97%) rename OsmAnd/src/net/osmand/plus/views/{AddWaypointBottomSheetHelper.java => AddGpxPointBottomSheetHelper.java} (72%) diff --git a/OsmAnd/res/layout-land/add_gpx_waypoint_bottom_sheet.xml b/OsmAnd/res/layout-land/add_gpx_point_bottom_sheet.xml similarity index 97% rename from OsmAnd/res/layout-land/add_gpx_waypoint_bottom_sheet.xml rename to OsmAnd/res/layout-land/add_gpx_point_bottom_sheet.xml index 541d8c347f..3fedb741c8 100644 --- a/OsmAnd/res/layout-land/add_gpx_waypoint_bottom_sheet.xml +++ b/OsmAnd/res/layout-land/add_gpx_point_bottom_sheet.xml @@ -32,7 +32,7 @@ android:layout_marginLeft="16dp" android:layout_marginRight="16dp" android:layout_marginTop="16dp" - android:text="@string/add_gpx_waypoint_bottom_sheet_title"/> + android:text="@string/add_gpx_waypoint"/> + tools:text="@string/add_gpx_waypoint"/> - + xmlns:app="http://schemas.android.com/apk/res-auto" + xmlns:tools="http://schemas.android.com/tools" + xmlns:osmand="http://schemas.android.com/apk/res-auto" + android:id="@+id/MainLayout" + android:layout_width="match_parent" + android:layout_height="match_parent" + android:orientation="vertical"> + android:groupIndicator="@android:color/transparent"/> + android:src="@drawable/ic_action_plus" + app:backgroundTint="@color/dashboard_blue" + app:fabSize="normal"/> + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 63db5a2b13..56972d8a22 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -2659,6 +2659,8 @@ Action name You need internet to view photos from Mapillary Retry - Add gpx waypoint + Add GPX waypoint Create + Route point + Add route point diff --git a/OsmAnd/src/net/osmand/data/PointDescription.java b/OsmAnd/src/net/osmand/data/PointDescription.java index cc778e0a0e..dc7c77e169 100644 --- a/OsmAnd/src/net/osmand/data/PointDescription.java +++ b/OsmAnd/src/net/osmand/data/PointDescription.java @@ -24,6 +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_POI = "poi"; public static final String POINT_TYPE_ADDRESS = "address"; public static final String POINT_TYPE_OSM_NOTE= "osm_note"; @@ -211,6 +212,10 @@ public class PointDescription { public boolean isWpt() { return POINT_TYPE_WPT.equals(type); } + + public boolean isRoutePoint() { + return POINT_TYPE_ROUTE.equals(type); + } public boolean isPoi() { return POINT_TYPE_POI.equals(type); diff --git a/OsmAnd/src/net/osmand/plus/GPXUtilities.java b/OsmAnd/src/net/osmand/plus/GPXUtilities.java index deca20637b..87008bee74 100644 --- a/OsmAnd/src/net/osmand/plus/GPXUtilities.java +++ b/OsmAnd/src/net/osmand/plus/GPXUtilities.java @@ -102,18 +102,6 @@ public class GPXUtilities { public float speed; } - public static class NewGpxWaypoint { - private GPXFile gpx; - - public NewGpxWaypoint(GPXFile gpx) { - this.gpx = gpx; - } - - public GPXFile getGpx() { - return gpx; - } - } - public static class WptPt extends GPXExtensions implements LocationPoint { public boolean firstPoint = false; public boolean lastPoint = false; @@ -860,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) { + public WptPt addWptPt(double lat, double lon, long time, String description, String name, String category, int color, PointDescription pointDescription) { 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); @@ -871,7 +859,15 @@ public class GPXUtilities { pt.setColor(color); } - points.add(pt); + if (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); + } 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 c67aaab288..c1291862aa 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -57,8 +57,6 @@ import net.osmand.plus.AppInitializer; import net.osmand.plus.AppInitializer.AppInitializeListener; import net.osmand.plus.AppInitializer.InitEvents; import net.osmand.plus.ApplicationMode; -import net.osmand.plus.GPXUtilities; -import net.osmand.plus.GPXUtilities.NewGpxWaypoint; import net.osmand.plus.GpxSelectionHelper.GpxDisplayItem; import net.osmand.plus.MapMarkersHelper.MapMarker; import net.osmand.plus.MapMarkersHelper.MapMarkerChangedListener; @@ -105,6 +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.AnimateDraggingMapThread; import net.osmand.plus.views.MapControlsLayer; import net.osmand.plus.views.MapInfoLayer; @@ -918,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 NewGpxWaypoint) { - NewGpxWaypoint newGpxWaypoint = (NewGpxWaypoint) toShow; - getMapLayers().getContextMenuLayer().enterAddGpxWaypointMode(newGpxWaypoint); + } else if (toShow instanceof NewPoint) { + NewPoint newPoint = (NewPoint) toShow; + getMapLayers().getContextMenuLayer().enterAddGpxPointMode(newPoint); } else { mapContextMenu.show(latLonToShow, mapLabelToShow, toShow); } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/WptPtEditor.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/WptPtEditor.java index 71c49650bf..e8eda3c181 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/WptPtEditor.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/WptPtEditor.java @@ -1,6 +1,7 @@ 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; @@ -12,6 +13,7 @@ public class WptPtEditor extends PointEditor { private GPXFile gpxFile; private WptPt wpt; private boolean gpxSelected; + private PointDescription pointDescription; public static final String TAG = "WptPtEditorFragment"; @@ -28,6 +30,10 @@ public class WptPtEditor extends PointEditor { return gpxFile; } + public PointDescription getPointDescription() { + return pointDescription; + } + public boolean isGpxSelected() { return gpxSelected; } @@ -53,6 +59,24 @@ 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 b368541105..67eb79dd2a 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/WptPtEditorFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/WptPtEditorFragment.java @@ -10,6 +10,7 @@ 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; @@ -152,6 +153,7 @@ 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(), @@ -161,7 +163,7 @@ public class WptPtEditorFragment extends PointEditorFragment { } } else { wpt = gpx.addWptPt(wpt.getLatitude(), wpt.getLongitude(), - System.currentTimeMillis(), description, name, category, color); + System.currentTimeMillis(), description, name, category, color, pointDescription); 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 6fd4ffbf63..0ab833895c 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/MapMultiSelectionMenu.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/MapMultiSelectionMenu.java @@ -12,6 +12,7 @@ import net.osmand.plus.mapcontextmenu.MenuController.MenuType; import net.osmand.plus.mapcontextmenu.MenuTitleController; import net.osmand.plus.views.ContextMenuLayer; import net.osmand.plus.views.ContextMenuLayer.IContextMenuProvider; +import net.osmand.plus.views.OsmandMapTileView; import java.util.Collections; import java.util.Comparator; @@ -194,8 +195,16 @@ public class MapMultiSelectionMenu extends BaseMenuController { public void openContextMenu(@NonNull MenuObject menuObject) { IContextMenuProvider provider = selectedObjects.remove(menuObject.getObject()); hide(); - getMapActivity().getMapLayers().getContextMenuLayer().showContextMenu( - menuObject.getLatLon(), menuObject.getPointDescription(), menuObject.getObject(), provider); + 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); + } } private void clearSelectedObjects() { diff --git a/OsmAnd/src/net/osmand/plus/myplaces/TrackPointFragment.java b/OsmAnd/src/net/osmand/plus/myplaces/TrackPointFragment.java index e2f61670ca..dc425d3616 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/TrackPointFragment.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/TrackPointFragment.java @@ -9,6 +9,7 @@ import android.os.Handler; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.design.widget.FloatingActionButton; +import android.support.v4.content.ContextCompat; import android.support.v4.view.MenuItemCompat; import android.support.v7.app.AlertDialog; import android.support.v7.view.ActionMode; @@ -30,16 +31,13 @@ import android.widget.ListView; import android.widget.TextView; import net.osmand.AndroidUtils; -import net.osmand.Location; import net.osmand.data.FavouritePoint; import net.osmand.data.LatLon; import net.osmand.data.PointDescription; import net.osmand.plus.FavouritesDbHelper; import net.osmand.plus.GPXDatabase.GpxDataItem; import net.osmand.plus.GPXUtilities; -import net.osmand.plus.GPXUtilities.WptPt; import net.osmand.plus.GPXUtilities.GPXFile; -import net.osmand.plus.GPXUtilities.NewGpxWaypoint; import net.osmand.plus.GpxSelectionHelper.GpxDisplayGroup; import net.osmand.plus.GpxSelectionHelper.GpxDisplayItem; import net.osmand.plus.GpxSelectionHelper.GpxDisplayItemType; @@ -58,6 +56,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.util.Algorithms; import java.io.File; @@ -93,7 +92,12 @@ public class TrackPointFragment extends OsmandExpandableListFragment { private Set selectedGroups = new LinkedHashSet<>(); private ActionMode actionMode; private SearchView searchView; - private FloatingActionButton fab; + private boolean menuOpened = false; + private FloatingActionButton menuFab; + private FloatingActionButton waypointFab; + private View waypointTextLayout; + private FloatingActionButton routePointFab; + private View routePointTextLayout; @Override public void onCreate(@Nullable Bundle savedInstanceState) { @@ -115,26 +119,38 @@ public class TrackPointFragment extends OsmandExpandableListFragment { ExpandableListView listView = (ExpandableListView) view.findViewById(android.R.id.list); setHasOptionsMenu(true); - fab = (FloatingActionButton) view.findViewById(R.id.fabButton); - - fab.setOnClickListener(new View.OnClickListener() { + menuFab = (FloatingActionButton) view.findViewById(R.id.menu_fab); + menuFab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - final OsmandSettings settings = app.getSettings(); - GPXFile gpx = getGpx(); - LatLon location = settings.getLastKnownMapLocation(); - if (location != null) { - settings.setMapLocationToShow(location.getLatitude(), location.getLongitude(), - settings.getLastKnownMapZoom(), - new PointDescription(PointDescription.POINT_TYPE_WPT, getString(R.string.context_menu_item_add_waypoint)), - false, - new NewGpxWaypoint(gpx)); - - MapActivity.launchMapActivityMoveToTop(getActivity()); + if (menuOpened) { + closeMenu(); + } else { + openMenu(); } } }); + waypointFab = (FloatingActionButton) view.findViewById(R.id.waypoint_fab); + waypointFab.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + PointDescription pointDescription = new PointDescription(PointDescription.POINT_TYPE_WPT, getString(R.string.context_menu_item_add_waypoint)); + addPoint(pointDescription); + } + }); + waypointTextLayout = view.findViewById(R.id.waypoint_text_layout); + + routePointFab = (FloatingActionButton) view.findViewById(R.id.route_fab); + 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)); + addPoint(pointDescription); + } + }); + routePointTextLayout = view.findViewById(R.id.route_text_layout); + TextView tv = new TextView(getActivity()); tv.setText(R.string.none_selected_gpx); tv.setTextSize(24); @@ -146,6 +162,39 @@ public class TrackPointFragment extends OsmandExpandableListFragment { return view; } + private void addPoint(PointDescription pointDescription) { + final OsmandSettings settings = app.getSettings(); + GPXFile gpx = getGpx(); + LatLon location = settings.getLastKnownMapLocation(); + if (gpx != null && location != null) { + settings.setMapLocationToShow(location.getLatitude(), location.getLongitude(), + settings.getLastKnownMapZoom(), + pointDescription, + false, + new NewPoint(gpx, pointDescription)); + + MapActivity.launchMapActivityMoveToTop(getActivity()); + } + } + + private void openMenu() { + menuFab.setImageDrawable(ContextCompat.getDrawable(getContext(), R.drawable.ic_action_remove_dark)); + waypointFab.setVisibility(View.VISIBLE); + waypointTextLayout.setVisibility(View.VISIBLE); + routePointFab.setVisibility(View.VISIBLE); + routePointTextLayout.setVisibility(View.VISIBLE); + menuOpened = true; + } + + private void closeMenu() { + menuFab.setImageDrawable(ContextCompat.getDrawable(getContext(), R.drawable.ic_action_plus)); + waypointFab.setVisibility(View.GONE); + waypointTextLayout.setVisibility(View.GONE); + routePointFab.setVisibility(View.GONE); + routePointTextLayout.setVisibility(View.GONE); + menuOpened = false; + } + public TrackActivity getTrackActivity() { return (TrackActivity) getActivity(); } diff --git a/OsmAnd/src/net/osmand/plus/views/AddWaypointBottomSheetHelper.java b/OsmAnd/src/net/osmand/plus/views/AddGpxPointBottomSheetHelper.java similarity index 72% rename from OsmAnd/src/net/osmand/plus/views/AddWaypointBottomSheetHelper.java rename to OsmAnd/src/net/osmand/plus/views/AddGpxPointBottomSheetHelper.java index 27eddc58ac..03a4285edc 100644 --- a/OsmAnd/src/net/osmand/plus/views/AddWaypointBottomSheetHelper.java +++ b/OsmAnd/src/net/osmand/plus/views/AddGpxPointBottomSheetHelper.java @@ -10,26 +10,25 @@ import android.widget.TextView; import net.osmand.data.LatLon; import net.osmand.data.PointDescription; import net.osmand.data.RotatedTileBox; -import net.osmand.plus.GPXUtilities; import net.osmand.plus.GPXUtilities.GPXFile; -import net.osmand.plus.GPXUtilities.NewGpxWaypoint; import net.osmand.plus.IconsCache; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.mapcontextmenu.MapContextMenu; -public class AddWaypointBottomSheetHelper { +public class AddGpxPointBottomSheetHelper { private final View view; private final TextView title; - private String titleText = ""; + private String titleText; private final TextView description; private final Context context; private final MapContextMenu contextMenu; private final ContextMenuLayer contextMenuLayer; private boolean applyingPositionMode; - private NewGpxWaypoint newGpxWaypoint; + private NewPoint newPoint; + private PointDescription pointDescription; - public AddWaypointBottomSheetHelper(final MapActivity activity, ContextMenuLayer ctxMenuLayer) { + public AddGpxPointBottomSheetHelper(final MapActivity activity, ContextMenuLayer ctxMenuLayer) { this.contextMenuLayer = ctxMenuLayer; view = activity.findViewById(R.id.add_gpx_waypoint_bottom_sheet); title = (TextView) view.findViewById(R.id.add_gpx_waypoint_bottom_sheet_title); @@ -43,17 +42,17 @@ public class AddWaypointBottomSheetHelper { view.findViewById(R.id.create_button).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - contextMenuLayer.createGpxWaypoint(); - GPXFile gpx = newGpxWaypoint.getGpx(); + contextMenuLayer.createGpxPoint(); + GPXFile gpx = newPoint.getGpx(); LatLon latLon = contextMenu.getLatLon(); - activity.getContextMenu().getWptPtPointEditor().add(gpx, latLon, titleText); + activity.getContextMenu().getWptPtPointEditor().add(gpx, latLon, titleText, pointDescription); } }); view.findViewById(R.id.cancel_button).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { hide(); - contextMenuLayer.cancelAddGpxWaypoint(); + contextMenuLayer.cancelAddGpxPoint(); } }); } @@ -74,8 +73,14 @@ public class AddWaypointBottomSheetHelper { return view.getVisibility() == View.VISIBLE; } - public void show(Drawable drawable, NewGpxWaypoint newGpxWaypoint) { - this.newGpxWaypoint = newGpxWaypoint; + public void show(Drawable drawable, NewPoint newPoint) { + this.newPoint = newPoint; + pointDescription = newPoint.getPointDescription(); + if (pointDescription.isWpt()) { + setTitle(context.getString(R.string.add_gpx_waypoint)); + } else if (pointDescription.isRoutePoint()) { + setTitle(context.getString(R.string.add_route_point)); + } exitApplyPositionMode(); view.setVisibility(View.VISIBLE); ((ImageView) view.findViewById(R.id.icon)).setImageDrawable(drawable); @@ -99,4 +104,22 @@ public class AddWaypointBottomSheetHelper { view.findViewById(R.id.create_button).setEnabled(true); } } + + public static class NewPoint { + private PointDescription pointDescription; + private GPXFile gpx; + + public NewPoint(GPXFile gpx, PointDescription pointDescription) { + this.gpx = gpx; + this.pointDescription = pointDescription; + } + + public GPXFile getGpx() { + return gpx; + } + + public PointDescription getPointDescription() { + return pointDescription; + } + } } diff --git a/OsmAnd/src/net/osmand/plus/views/ContextMenuLayer.java b/OsmAnd/src/net/osmand/plus/views/ContextMenuLayer.java index d83e382a23..91c7a1d80e 100644 --- a/OsmAnd/src/net/osmand/plus/views/ContextMenuLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/ContextMenuLayer.java @@ -35,13 +35,13 @@ import net.osmand.osm.PoiFilter; import net.osmand.osm.PoiType; import net.osmand.plus.ContextMenuAdapter; import net.osmand.plus.ContextMenuItem; -import net.osmand.plus.GPXUtilities.NewGpxWaypoint; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; 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.util.Algorithms; import net.osmand.util.MapUtils; @@ -76,14 +76,14 @@ public class ContextMenuLayer extends OsmandMapLayer { private GestureDetector movementListener; private final MoveMarkerBottomSheetHelper mMoveMarkerBottomSheetHelper; - private final AddWaypointBottomSheetHelper mAddWaypointBottomSheetHelper; + private final AddGpxPointBottomSheetHelper mAddGpxPointBottomSheetHelper; private boolean mInChangeMarkerPositionMode; private IContextMenuProvider selectedObjectContextMenuProvider; private boolean cancelApplyingNewMarkerPosition; private LatLon applyingMarkerLatLon; private boolean wasCollapseButtonVisible; private boolean mInGpxDetailsMode; - private boolean mInAddGpxWaypointMode; + private boolean mInAddGpxPointMode; private List publicTransportTypes; private Object selectedObject; @@ -94,7 +94,11 @@ public class ContextMenuLayer extends OsmandMapLayer { multiSelectionMenu = menu.getMultiSelectionMenu(); movementListener = new GestureDetector(activity, new MenuLayerOnGestureListener()); mMoveMarkerBottomSheetHelper = new MoveMarkerBottomSheetHelper(activity, this); - mAddWaypointBottomSheetHelper = new AddWaypointBottomSheetHelper(activity, this); + mAddGpxPointBottomSheetHelper = new AddGpxPointBottomSheetHelper(activity, this); + } + + public AddGpxPointBottomSheetHelper getAddGpxPointBottomSheetHelper() { + return mAddGpxPointBottomSheetHelper; } @Override @@ -207,10 +211,10 @@ public class ContextMenuLayer extends OsmandMapLayer { contextMarker.draw(canvas); } mMoveMarkerBottomSheetHelper.onDraw(box); - } else if (mInAddGpxWaypointMode) { + } else if (mInAddGpxPointMode) { canvas.translate(box.getPixWidth() / 2 - contextMarker.getWidth() / 2, box.getPixHeight() / 2 - contextMarker.getHeight()); contextMarker.draw(canvas); - mAddWaypointBottomSheetHelper.onDraw(box); + mAddGpxPointBottomSheetHelper.onDraw(box); } else if (menu.isActive()) { LatLon latLon = menu.getLatLon(); int x = (int) box.getPixXFromLatLon(latLon.getLatitude(), latLon.getLongitude()); @@ -289,7 +293,7 @@ public class ContextMenuLayer extends OsmandMapLayer { } public Object getMoveableObject() { - return mInChangeMarkerPositionMode || mInAddGpxWaypointMode ? menu.getObject() : null; + return mInChangeMarkerPositionMode ? menu.getObject() : null; } public boolean isInChangeMarkerPositionMode() { @@ -301,7 +305,7 @@ public class ContextMenuLayer extends OsmandMapLayer { } public boolean isInAddGpxWaypointMode() { - return mInAddGpxWaypointMode; + return mInAddGpxPointMode; } public boolean isObjectMoveable(Object o) { @@ -318,14 +322,14 @@ public class ContextMenuLayer extends OsmandMapLayer { } public void applyMovedObject(Object o, LatLon position, ApplyMovedObjectCallback callback) { - if (selectedObjectContextMenuProvider != null) { + if (selectedObjectContextMenuProvider != null && !isInAddGpxWaypointMode()) { if (selectedObjectContextMenuProvider instanceof IMoveObjectProvider) { final IMoveObjectProvider l = (IMoveObjectProvider) selectedObjectContextMenuProvider; if (l.isObjectMovable(o)) { l.applyNewObjectPosition(o, position, callback); } } - } else if (mInChangeMarkerPositionMode || mInAddGpxWaypointMode) { + } else if (mInChangeMarkerPositionMode || mInAddGpxPointMode) { callback.onApplyMovedObject(true, null); } } @@ -351,11 +355,7 @@ public class ContextMenuLayer extends OsmandMapLayer { mMoveMarkerBottomSheetHelper.hide(); quitMovingMarker(); - PointDescription pointDescription = null; - if (selectedObjectContextMenuProvider != null) { - pointDescription = selectedObjectContextMenuProvider.getObjectName(newObject); - } - menu.show(ll, pointDescription, newObject); + view.refreshMap(); } selectedObjectContextMenuProvider = null; @@ -369,9 +369,9 @@ public class ContextMenuLayer extends OsmandMapLayer { }); } - public void createGpxWaypoint() { - if (!mInAddGpxWaypointMode) { - throw new IllegalStateException("Not in add gpx waypoint mode"); + public void createGpxPoint() { + if (!mInAddGpxPointMode) { + throw new IllegalStateException("Not in add gpx point mode"); } RotatedTileBox tileBox = activity.getMapView().getCurrentRotatedTileBox(); @@ -381,14 +381,14 @@ public class ContextMenuLayer extends OsmandMapLayer { Object obj = getMoveableObject(); cancelApplyingNewMarkerPosition = false; - mAddWaypointBottomSheetHelper.enterApplyPositionMode(); + mAddGpxPointBottomSheetHelper.enterApplyPositionMode(); applyMovedObject(obj, ll, new ApplyMovedObjectCallback() { @Override public void onApplyMovedObject(boolean success, @Nullable Object newObject) { - mAddWaypointBottomSheetHelper.exitApplyPositionMode(); + mAddGpxPointBottomSheetHelper.exitApplyPositionMode(); if (success && !cancelApplyingNewMarkerPosition) { - mAddWaypointBottomSheetHelper.hide(); - quitAddGpxWaipoint(); + mAddGpxPointBottomSheetHelper.hide(); + quitAddGpxPoint(); PointDescription pointDescription = null; if (selectedObjectContextMenuProvider != null) { @@ -449,8 +449,8 @@ public class ContextMenuLayer extends OsmandMapLayer { } } - private void quitAddGpxWaipoint() { - mInAddGpxWaypointMode = false; + private void quitAddGpxPoint() { + mInAddGpxPointMode = false; mark(View.VISIBLE, R.id.map_ruler_layout, R.id.map_left_widgets_panel, R.id.map_right_widgets_panel, R.id.map_center_info); @@ -460,14 +460,14 @@ public class ContextMenuLayer extends OsmandMapLayer { } } - public void enterAddGpxWaypointMode(NewGpxWaypoint newGpxWaypoint) { + public void enterAddGpxPointMode(NewPoint newPoint) { menu.updateMapCenter(null); menu.hide(); activity.disableDrawer(); - mInAddGpxWaypointMode = true; - mAddWaypointBottomSheetHelper.show(menu.getLeftIcon(), newGpxWaypoint); + mInAddGpxPointMode = true; + mAddGpxPointBottomSheetHelper.show(menu.getLeftIcon(), newPoint); 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); @@ -529,9 +529,9 @@ public class ContextMenuLayer extends OsmandMapLayer { applyingMarkerLatLon = null; } - public void cancelAddGpxWaypoint() { + public void cancelAddGpxPoint() { cancelApplyingNewMarkerPosition = true; - quitAddGpxWaipoint(); + quitAddGpxPoint(); activity.getContextMenu().show(); applyingMarkerLatLon = null; } @@ -648,10 +648,9 @@ public class ContextMenuLayer extends OsmandMapLayer { if (latLon == null) { latLon = getLatLon(point, tileBox); } - if (mInAddGpxWaypointMode) { - if (pointDescription != null) { - mAddWaypointBottomSheetHelper.setTitle(pointDescription.getName()); - } + if (mInAddGpxPointMode) { + String title = pointDescription == null ? "" : pointDescription.getName(); + mAddGpxPointBottomSheetHelper.setTitle(title); view.getAnimatedDraggingThread().startMoving(latLon.getLatitude(), latLon.getLongitude(), view.getZoom(), true); } else { showContextMenu(latLon, pointDescription, selectedObj, provider); @@ -668,7 +667,12 @@ public class ContextMenuLayer extends OsmandMapLayer { selectedObjectContextMenuProvider = null; LatLon latLon = getLatLon(point, tileBox); activity.getMapViewTrackingUtilities().setMapLinkedToLocation(false); - menu.show(latLon, null, null); + if (mInAddGpxPointMode) { + mAddGpxPointBottomSheetHelper.setTitle(""); + view.getAnimatedDraggingThread().startMoving(latLon.getLatitude(), latLon.getLongitude(), view.getZoom(), true); + } else { + menu.show(latLon, null, null); + } return true; } return false; @@ -697,7 +701,7 @@ public class ContextMenuLayer extends OsmandMapLayer { } public boolean disableLongPressOnMap() { - if (mInChangeMarkerPositionMode || mInGpxDetailsMode || mInAddGpxWaypointMode) { + if (mInChangeMarkerPositionMode || mInGpxDetailsMode || mInAddGpxPointMode) { return true; } boolean res = false; From 6af21749fb4c2385f7af32c32b6301945d7fb4fa Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Thu, 3 Aug 2017 12:51:06 +0300 Subject: [PATCH 04/22] Change layout for "Save as GPX" dialog; add some logic --- OsmAnd/res/layout/save_gpx_dialog.xml | 5 +-- .../MeasurementToolFragment.java | 42 +++++++++++++++++++ 2 files changed, 44 insertions(+), 3 deletions(-) diff --git a/OsmAnd/res/layout/save_gpx_dialog.xml b/OsmAnd/res/layout/save_gpx_dialog.xml index 38ab5265d7..7ae9fc7579 100644 --- a/OsmAnd/res/layout/save_gpx_dialog.xml +++ b/OsmAnd/res/layout/save_gpx_dialog.xml @@ -3,7 +3,6 @@ xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" - android:animateLayoutChanges="true" android:orientation="vertical"> + android:visibility="invisible"/> Date: Thu, 3 Aug 2017 13:30:27 +0300 Subject: [PATCH 05/22] Add some code --- .../MeasurementToolFragment.java | 50 ++++++++++++++++--- 1 file changed, 44 insertions(+), 6 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java index 036539879c..4ba046e1d7 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java @@ -1,6 +1,8 @@ package net.osmand.plus.measurementtool; +import android.app.ProgressDialog; import android.content.DialogInterface; +import android.os.AsyncTask; import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; @@ -37,6 +39,7 @@ import java.util.Locale; public class MeasurementToolFragment extends Fragment { public static final String TAG = "MeasurementToolFragment"; + private static final String EXT = ".gpx"; private MeasurementToolBarController toolBarController; private TextView distanceTv; @@ -167,22 +170,23 @@ public class MeasurementToolFragment extends Fragment { private void saveAsGpxOnClick(MapActivity mapActivity) { final File dir = mapActivity.getMyApplication().getAppPath(IndexConstants.GPX_INDEX_DIR); - LayoutInflater inflater = getLayoutInflater(); + final LayoutInflater inflater = getLayoutInflater(); final View view = inflater.inflate(R.layout.save_gpx_dialog, null); - EditText nameEt = view.findViewById(R.id.gpx_name_et); + final EditText nameEt = view.findViewById(R.id.gpx_name_et); final TextView fileExistsTv = view.findViewById(R.id.file_exists_text_view); final String suggestedName = new SimpleDateFormat("dd-M-yyyy hh:mm", Locale.US).format(new Date()); String displayedName = String.copyValueOf(suggestedName.toCharArray()); - File fout = new File(dir, suggestedName + ".gpx"); + File fout = new File(dir, suggestedName + EXT); int ind = 1; while (fout.exists()) { displayedName = suggestedName + " " + (++ind); - fout = new File(dir, displayedName + ".gpx"); + fout = new File(dir, displayedName + EXT); } nameEt.setText(displayedName); nameEt.setSelection(displayedName.length()); + final boolean[] textChanged = new boolean[1]; nameEt.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) { @@ -196,11 +200,12 @@ public class MeasurementToolFragment extends Fragment { @Override public void afterTextChanged(Editable editable) { - if (new File(dir, editable.toString() + ".gpx").exists()) { + if (new File(dir, editable.toString() + EXT).exists()) { fileExistsTv.setVisibility(View.VISIBLE); } else { fileExistsTv.setVisibility(View.INVISIBLE); } + textChanged[0] = true; } }); @@ -210,13 +215,46 @@ public class MeasurementToolFragment extends Fragment { .setPositiveButton(R.string.shared_string_save, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { - + final String name = nameEt.getText().toString(); + String fileName = String.copyValueOf(name.toCharArray()) + EXT; + if (textChanged[0]) { + File fout = new File(dir, fileName); + int ind = 1; + while (fout.exists()) { + fileName = name + " " + (++ind) + EXT; + fout = new File(dir, fileName); + } + } + saveGpx(fileName); } }) .setNegativeButton(R.string.shared_string_cancel, null) .show(); } + private void saveGpx(final String fileName) { + new AsyncTask() { + + private ProgressDialog progressDialog; + private File toSave; + + @Override + protected void onPreExecute() { + super.onPreExecute(); + } + + @Override + protected String doInBackground(Void... voids) { + return null; + } + + @Override + protected void onPostExecute(String s) { + super.onPostExecute(s); + } + }.execute(); + } + @Override public void onDestroyView() { super.onDestroyView(); From f88ba653c4b75d15266b118471eb42cd8a293ddd Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Thu, 3 Aug 2017 14:55:28 +0300 Subject: [PATCH 06/22] Add ability to save GPX --- .../MeasurementToolFragment.java | 69 ++++++++++++++++--- .../measurementtool/MeasurementToolLayer.java | 4 ++ 2 files changed, 64 insertions(+), 9 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java index 4ba046e1d7..cb2e08c8fd 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java @@ -7,6 +7,7 @@ import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; import android.support.v7.app.AlertDialog; +import android.support.v7.widget.SwitchCompat; import android.text.Editable; import android.text.TextWatcher; import android.view.ContextThemeWrapper; @@ -23,6 +24,9 @@ import android.widget.Toast; import net.osmand.AndroidUtils; import net.osmand.IndexConstants; +import net.osmand.plus.GPXUtilities; +import net.osmand.plus.GPXUtilities.Route; +import net.osmand.plus.GPXUtilities.WptPt; import net.osmand.plus.IconsCache; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; @@ -32,10 +36,14 @@ import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarControll import net.osmand.plus.widgets.IconPopupMenu; import java.io.File; +import java.text.MessageFormat; import java.text.SimpleDateFormat; import java.util.Date; +import java.util.LinkedList; import java.util.Locale; +import static net.osmand.plus.GPXUtilities.GPXFile; + public class MeasurementToolFragment extends Fragment { public static final String TAG = "MeasurementToolFragment"; @@ -148,7 +156,12 @@ public class MeasurementToolFragment extends Fragment { public boolean onMenuItemClick(MenuItem menuItem) { switch (menuItem.getItemId()) { case R.id.action_save_as_gpx: - saveAsGpxOnClick(mapActivity); + if (measurementLayer.getPointsCount() > 0) { + saveAsGpxOnClick(mapActivity); + } else { + //todo + Toast.makeText(mapActivity, "There must be at least one point", Toast.LENGTH_SHORT).show(); + } return true; case R.id.action_clear_all: measurementLayer.clearPoints(); @@ -172,10 +185,11 @@ public class MeasurementToolFragment extends Fragment { final File dir = mapActivity.getMyApplication().getAppPath(IndexConstants.GPX_INDEX_DIR); final LayoutInflater inflater = getLayoutInflater(); final View view = inflater.inflate(R.layout.save_gpx_dialog, null); - final EditText nameEt = view.findViewById(R.id.gpx_name_et); - final TextView fileExistsTv = view.findViewById(R.id.file_exists_text_view); + final EditText nameEt = (EditText) view.findViewById(R.id.gpx_name_et); + final TextView fileExistsTv = (TextView) view.findViewById(R.id.file_exists_text_view); + final SwitchCompat showOnMapToggle = (SwitchCompat) view.findViewById(R.id.toggle_show_on_map); - final String suggestedName = new SimpleDateFormat("dd-M-yyyy hh:mm", Locale.US).format(new Date()); + final String suggestedName = new SimpleDateFormat("yyyy-M-dd hh-mm E", Locale.US).format(new Date()); String displayedName = String.copyValueOf(suggestedName.toCharArray()); File fout = new File(dir, suggestedName + EXT); int ind = 1; @@ -225,14 +239,14 @@ public class MeasurementToolFragment extends Fragment { fout = new File(dir, fileName); } } - saveGpx(fileName); + saveGpx(dir, fileName, showOnMapToggle.isChecked()); } }) .setNegativeButton(R.string.shared_string_cancel, null) .show(); } - private void saveGpx(final String fileName) { + private void saveGpx(final File dir, final String fileName, final boolean showOnMap) { new AsyncTask() { private ProgressDialog progressDialog; @@ -240,17 +254,54 @@ public class MeasurementToolFragment extends Fragment { @Override protected void onPreExecute() { - super.onPreExecute(); + MapActivity activity = getMapActivity(); + if (activity != null) { + progressDialog = new ProgressDialog(activity); + progressDialog.setMessage(activity.getString(R.string.saving_gpx_tracks)); + progressDialog.show(); + } } @Override protected String doInBackground(Void... voids) { + toSave = new File(dir, fileName); + GPXFile gpx = new GPXFile(); + MeasurementToolLayer measurementLayer = getMeasurementLayer(); + if (measurementLayer != null) { + LinkedList points = measurementLayer.getMeasurementPoints(); + if (points.size() == 1) { + gpx.points.add(points.getFirst()); + } else if (points.size() > 1) { + Route rt = new Route(); + gpx.routes.add(rt); + rt.points.addAll(points); + } + } + MapActivity activity = getMapActivity(); + if (activity != null) { + // todo + String res = GPXUtilities.writeGpxFile(toSave, gpx, activity.getMyApplication()); + activity.getMyApplication().getSelectedGpxHelper().selectGpxFile(gpx, showOnMap, false); + return res; + } return null; } @Override - protected void onPostExecute(String s) { - super.onPostExecute(s); + protected void onPostExecute(String warning) { + MapActivity activity = getMapActivity(); + if (activity != null) { + if (warning == null) { + Toast.makeText(activity, + MessageFormat.format(activity.getString(R.string.gpx_saved_sucessfully), toSave.getAbsolutePath()), + Toast.LENGTH_LONG).show(); + } else { + Toast.makeText(activity, warning, Toast.LENGTH_LONG).show(); + } + } + if (progressDialog != null && progressDialog.isShowing()) { + progressDialog.dismiss(); + } } }.execute(); } diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolLayer.java b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolLayer.java index 451fa60093..b3c831ad82 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolLayer.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolLayer.java @@ -66,6 +66,10 @@ public class MeasurementToolLayer extends OsmandMapLayer { return measurementPoints.size(); } + public LinkedList getMeasurementPoints() { + return measurementPoints; + } + String getDistanceSt() { float dist = 0; if (measurementPoints.size() > 0) { From 3cdb63a669753708b4d7bbf20f2a4d3cc8f51b35 Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Thu, 3 Aug 2017 15:54:00 +0300 Subject: [PATCH 07/22] Add string --- OsmAnd/res/values/strings.xml | 1 + .../osmand/plus/measurementtool/MeasurementToolFragment.java | 3 +-- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 32fe5e257c..884d826ffc 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -9,6 +9,7 @@ 3. All your modified/created strings are in the top of the file (to make easier find what\'s translated). PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy --> + You need to add at least one point. Enter name for GPX Show on map after saving Select a location on the map and click "Add" to add a point to the ruler. diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java index cb2e08c8fd..55900ff2d5 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java @@ -159,8 +159,7 @@ public class MeasurementToolFragment extends Fragment { if (measurementLayer.getPointsCount() > 0) { saveAsGpxOnClick(mapActivity); } else { - //todo - Toast.makeText(mapActivity, "There must be at least one point", Toast.LENGTH_SHORT).show(); + Toast.makeText(mapActivity, mapActivity.getString(R.string.none_point_error), Toast.LENGTH_SHORT).show(); } return true; case R.id.action_clear_all: From 307c77e5a2dca08b3cf06c00bd95660bf4231f1f Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Thu, 3 Aug 2017 17:31:38 +0300 Subject: [PATCH 08/22] Draw points over lines --- .../plus/measurementtool/MeasurementToolLayer.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolLayer.java b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolLayer.java index b3c831ad82..8cc17bcd27 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolLayer.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolLayer.java @@ -108,16 +108,19 @@ public class MeasurementToolLayer extends OsmandMapLayer { } tx.add(locX); ty.add(locY); - - if (tb.containsLatLon(pt.lat, pt.lon)) { - canvas.drawBitmap(pointIcon, locX - marginX, locY - marginY, bitmapPaint); - } } path.lineTo(tb.getCenterPixelX(), tb.getCenterPixelY()); tx.add(tb.getCenterPixelX()); ty.add(tb.getCenterPixelY()); calculatePath(tb, tx, ty, path); canvas.drawPath(path, lineAttrs.paint); + for (WptPt pt : measurementPoints) { + if (tb.containsLatLon(pt.lat, pt.lon)) { + int locX = tb.getPixXFromLonNoRot(pt.lon); + int locY = tb.getPixYFromLatNoRot(pt.lat); + canvas.drawBitmap(pointIcon, locX - marginX, locY - marginY, bitmapPaint); + } + } } } } From ddba6ba410e7a821ee362d9870f2871d55e8a3b1 Mon Sep 17 00:00:00 2001 From: Alexander Sytnyk Date: Thu, 3 Aug 2017 18:59:55 +0300 Subject: [PATCH 09/22] Add some code --- .../res/layout/fragment_measurement_tool.xml | 38 ++++++++++++++----- .../MeasurementToolFragment.java | 32 +++++++++++++--- 2 files changed, 55 insertions(+), 15 deletions(-) diff --git a/OsmAnd/res/layout/fragment_measurement_tool.xml b/OsmAnd/res/layout/fragment_measurement_tool.xml index 7ad35e3364..9b2d999161 100644 --- a/OsmAnd/res/layout/fragment_measurement_tool.xml +++ b/OsmAnd/res/layout/fragment_measurement_tool.xml @@ -43,11 +43,9 @@ android:layout_alignParentEnd="true" android:layout_alignParentRight="true" android:layout_centerVertical="true" - android:layout_marginEnd="16dp" - android:layout_marginLeft="16dp" - android:layout_marginRight="16dp" - android:layout_marginStart="16dp" android:background="@null" + android:paddingEnd="16dp" + android:paddingStart="16dp" tools:src="@drawable/ic_action_arrow_down"/> + + + + + + + + + @@ -94,11 +114,9 @@ android:layout_alignParentLeft="true" android:layout_alignParentStart="true" android:layout_centerVertical="true" - android:layout_marginEnd="16dp" - android:layout_marginLeft="16dp" - android:layout_marginRight="16dp" - android:layout_marginStart="16dp" android:background="@null" + android:paddingEnd="16dp" + android:paddingStart="16dp" tools:src="@drawable/ic_action_undo_dark"/>