diff --git a/OsmAnd/res/layout/close_measurement_tool_dialog.xml b/OsmAnd/res/layout/close_measurement_tool_dialog.xml new file mode 100644 index 0000000000..6485e8582f --- /dev/null +++ b/OsmAnd/res/layout/close_measurement_tool_dialog.xml @@ -0,0 +1,22 @@ + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 29df34dfbd..352d6b9ce4 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -9,6 +9,8 @@ 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 --> + Keep showing on map + Exit without saving? Line Save as route points Save as line diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java index c824b3bec1..523522c9b3 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java @@ -463,16 +463,9 @@ public class MeasurementToolFragment extends Fragment { if (pointsListOpened) { hidePointsList(); } - if (editingCtx.getOriginalPointToMove() != null) { - switchMovePointMode(false); - } else if (editingCtx.getSelectedPointPosition() != -1) { - switchAddPointBeforeAfterMode(false); - } + closeModes(); MeasurementToolLayer layer = getMeasurementLayer(); if (layer != null) { - if (editingCtx.getOriginalPointToMove() != null) { - layer.exitMovePointMode(true); - } layer.setOnSingleTapListener(null); layer.setOnEnterMovePointModeListener(null); } @@ -858,6 +851,18 @@ public class MeasurementToolFragment extends Fragment { } } + private void closeModes() { + if (editingCtx.getOriginalPointToMove() != null) { + switchMovePointMode(false); + } else if (editingCtx.getSelectedPointPosition() != -1) { + switchAddPointBeforeAfterMode(false); + } + MeasurementToolLayer layer = getMeasurementLayer(); + if (layer != null && editingCtx.getOriginalPointToMove() != null) { + layer.exitMovePointMode(true); + } + } + private void addPointBeforeAfter() { MeasurementToolLayer measurementLayer = getMeasurementLayer(); if (measurementLayer != null) { @@ -1118,7 +1123,7 @@ public class MeasurementToolFragment extends Fragment { fout = new File(dir, fileName); } } - saveNewGpx(dir, fileName, showOnMapToggle.isChecked(), saveType); + saveNewGpx(dir, fileName, showOnMapToggle.isChecked(), saveType, false); } }) .setNegativeButton(R.string.shared_string_cancel, null) @@ -1126,12 +1131,12 @@ public class MeasurementToolFragment extends Fragment { } } - private void saveNewGpx(File dir, String fileName, boolean checked, SaveType saveType) { - saveGpx(dir, fileName, checked, null, false, null, saveType); + private void saveNewGpx(File dir, String fileName, boolean checked, SaveType saveType, boolean close) { + saveGpx(dir, fileName, checked, null, false, null, saveType, close); } private void saveExistingGpx(GPXFile gpx, boolean showOnMap, NewGpxData.ActionType actionType, boolean openTrackActivity) { - saveGpx(null, null, showOnMap, gpx, openTrackActivity, actionType, null); + saveGpx(null, null, showOnMap, gpx, openTrackActivity, actionType, null, false); } private void saveGpx(final File dir, @@ -1140,7 +1145,8 @@ public class MeasurementToolFragment extends Fragment { final GPXFile gpx, final boolean openTrackActivity, final NewGpxData.ActionType actionType, - final SaveType saveType) { + final SaveType saveType, + final boolean close) { new AsyncTask() { @@ -1149,6 +1155,7 @@ public class MeasurementToolFragment extends Fragment { @Override protected void onPreExecute() { + closeModes(); MapActivity activity = getMapActivity(); if (activity != null) { progressDialog = new ProgressDialog(activity); @@ -1240,6 +1247,9 @@ public class MeasurementToolFragment extends Fragment { Toast.makeText(activity, MessageFormat.format(getString(R.string.gpx_saved_sucessfully), toSave.getAbsolutePath()), Toast.LENGTH_LONG).show(); + if (close) { + dismiss(activity); + } } } else { Toast.makeText(activity, warning, Toast.LENGTH_LONG).show(); @@ -1368,17 +1378,49 @@ public class MeasurementToolFragment extends Fragment { dismiss(mapActivity); return; } - new AlertDialog.Builder(mapActivity) - .setTitle(getString(R.string.are_you_sure)) + AlertDialog.Builder builder = new AlertDialog.Builder(mapActivity); + if (editingCtx.getNewGpxData() == null) { + final File dir = mapActivity.getMyApplication().getAppPath(IndexConstants.GPX_INDEX_DIR); + final LayoutInflater inflater = mapActivity.getLayoutInflater(); + final View view = inflater.inflate(R.layout.close_measurement_tool_dialog, null); + final SwitchCompat showOnMapToggle = (SwitchCompat) view.findViewById(R.id.toggle_show_on_map); + + builder.setView(view); + builder.setPositiveButton(R.string.shared_string_save, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + final String name = new SimpleDateFormat("yyyy-M-dd_HH-mm_EEE", Locale.US).format(new Date()); + String fileName = name + GPX_SUFFIX; + File fout = new File(dir, fileName); + int ind = 1; + while (fout.exists()) { + fileName = name + "_" + (++ind) + GPX_SUFFIX; + fout = new File(dir, fileName); + } + saveNewGpx(dir, fileName, showOnMapToggle.isChecked(), SaveType.LINE, true); + } + }); + } else { + builder.setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialogInterface, int i) { + GPXFile gpx = editingCtx.getNewGpxData().getGpxFile(); + SelectedGpxFile selectedGpxFile = mapActivity.getMyApplication().getSelectedGpxHelper().getSelectedFileByPath(gpx.path); + boolean showOnMap = selectedGpxFile != null; + ActionType actionType = editingCtx.getNewGpxData().getActionType(); + saveExistingGpx(gpx, showOnMap, actionType, true); + } + }); + } + builder.setTitle(getString(R.string.exit_without_saving)) .setMessage(getString(R.string.unsaved_changes_will_be_lost)) - .setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() { + .setNegativeButton(R.string.shared_string_cancel, new DialogInterface.OnClickListener() { @Override - public void onClick(DialogInterface dialog, int which) { + public void onClick(DialogInterface dialogInterface, int i) { dismiss(mapActivity); } - }) - .setNegativeButton(R.string.shared_string_cancel, null) - .show(); + }); + builder.show(); } }