Add dialog for saving and exiting
This commit is contained in:
parent
93b615c201
commit
fb86e28940
3 changed files with 86 additions and 20 deletions
22
OsmAnd/res/layout/close_measurement_tool_dialog.xml
Normal file
22
OsmAnd/res/layout/close_measurement_tool_dialog.xml
Normal file
|
@ -0,0 +1,22 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="horizontal"
|
||||
android:padding="@dimen/measurement_tool_content_padding">
|
||||
|
||||
<TextView
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/keep_showing_on_map"/>
|
||||
|
||||
<android.support.v7.widget.SwitchCompat
|
||||
android:id="@+id/toggle_show_on_map"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="@dimen/measurement_tool_content_margin"
|
||||
android:layout_marginStart="@dimen/measurement_tool_content_margin"/>
|
||||
|
||||
</LinearLayout>
|
|
@ -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
|
||||
-->
|
||||
<string name="keep_showing_on_map">Keep showing on map</string>
|
||||
<string name="exit_without_saving">Exit without saving?</string>
|
||||
<string name="line">Line</string>
|
||||
<string name="save_as_route_point">Save as route points</string>
|
||||
<string name="save_as_line">Save as line</string>
|
||||
|
|
|
@ -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<Void, Void, String>() {
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue