Save points as route points for distance measurement (if there is only 1 path)

This commit is contained in:
Victor Shcherb 2015-04-02 01:39:23 +02:00
parent 654bf79dbe
commit a233194807
2 changed files with 24 additions and 12 deletions

View file

@ -782,7 +782,6 @@
<string name="distance_measurement_finish_editing">Finish editing</string> <string name="distance_measurement_finish_editing">Finish editing</string>
<string name="distance_measurement_finish_subtrack">Begin a new subtrack</string> <string name="distance_measurement_finish_subtrack">Begin a new subtrack</string>
<string name="distance_measurement_clear_route">Clear all points</string> <string name="distance_measurement_clear_route">Clear all points</string>
<string name="distance_measurement_save_gpx">Save as GPX</string>
<string name="distance_measurement_load_gpx">Open existing GPX</string> <string name="distance_measurement_load_gpx">Open existing GPX</string>
<string name="wait_current_task_finished">Please wait until current task is finished</string> <string name="wait_current_task_finished">Please wait until current task is finished</string>
<string name="use_kalman_filter_compass_descr">Reduces noise in compass readings but adds inertia</string> <string name="use_kalman_filter_compass_descr">Reduces noise in compass readings but adds inertia</string>

View file

@ -154,7 +154,7 @@ public class DistanceCalculatorPlugin extends OsmandPlugin {
if(measurementPoints.size() > 0) { if(measurementPoints.size() > 0) {
list.add(R.string.distance_measurement_finish_subtrack); list.add(R.string.distance_measurement_finish_subtrack);
list.add(R.string.distance_measurement_clear_route); list.add(R.string.distance_measurement_clear_route);
list.add(R.string.distance_measurement_save_gpx); list.add(R.string.shared_string_save_as_gpx);
} }
list.add(R.string.distance_measurement_load_gpx); list.add(R.string.distance_measurement_load_gpx);
String[] items = new String[list.size()]; String[] items = new String[list.size()];
@ -177,7 +177,7 @@ public class DistanceCalculatorPlugin extends OsmandPlugin {
distanceMeasurementMode = 0; distanceMeasurementMode = 0;
measurementPoints.clear(); measurementPoints.clear();
calculateDistance(); calculateDistance();
} else if (id == R.string.distance_measurement_save_gpx) { } else if (id == R.string.shared_string_save_as_gpx) {
saveGpx(activity); saveGpx(activity);
} else if (id == R.string.distance_measurement_load_gpx) { } else if (id == R.string.distance_measurement_load_gpx) {
loadGpx(activity); loadGpx(activity);
@ -234,13 +234,26 @@ public class DistanceCalculatorPlugin extends OsmandPlugin {
final File dir = app.getAppPath(IndexConstants.GPX_INDEX_DIR); final File dir = app.getAppPath(IndexConstants.GPX_INDEX_DIR);
LinearLayout ll = new LinearLayout(activity); LinearLayout ll = new LinearLayout(activity);
ll.setOrientation(LinearLayout.VERTICAL); ll.setOrientation(LinearLayout.VERTICAL);
ll.setPadding(5, 5, 5, 5); ll.setPadding(7, 7, 7, 7);
final TextView tv = new TextView(activity); final TextView tv = new TextView(activity);
tv.setText(""); tv.setText("");
tv.setTextColor(Color.RED); tv.setTextColor(Color.RED);
ll.addView(tv); ll.addView(tv);
final EditText editText = new EditText(activity); final EditText editText = new EditText(activity);
editText.setHint(R.string.gpx_file_name); editText.setHint(R.string.gpx_file_name);
if(originalGPX != null && originalGPX.path != null){
String p = originalGPX.path;
int li = p.lastIndexOf('/');
if(li >= 0) {
p = p.substring(li + 1);
}
int pi = p.lastIndexOf('.');
if(pi >= 0) {
p = p.substring(0, pi);
}
editText.setText(p);
}
editText.addTextChangedListener(new TextWatcher() { editText.addTextChangedListener(new TextWatcher() {
@Override @Override
@ -291,27 +304,27 @@ public class DistanceCalculatorPlugin extends OsmandPlugin {
protected String doInBackground(Void... params) { protected String doInBackground(Void... params) {
toSave = new File(app.getAppPath(IndexConstants.GPX_INDEX_DIR), fileNameSave); toSave = new File(app.getAppPath(IndexConstants.GPX_INDEX_DIR), fileNameSave);
GPXFile gpx; GPXFile gpx;
boolean saveTrackToRte = false; boolean saveTrackToRte = measurementPoints.size() <= 1;
if(originalGPX != null) { if (originalGPX != null) {
gpx = originalGPX; gpx = originalGPX;
saveTrackToRte = originalGPX.routes.size() > 0 && originalGPX.tracks.size() == 0; saveTrackToRte = originalGPX.routes.size() > 0 && originalGPX.tracks.size() == 0;
gpx.tracks.clear(); gpx.tracks.clear();
gpx.routes.clear(); gpx.routes.clear();
gpx.points.clear(); gpx.points.clear();
} else { } else {
gpx = new GPXFile(); gpx = new GPXFile();
} }
for(int i = 0; i<measurementPoints.size(); i++) { for (int i = 0; i < measurementPoints.size(); i++) {
LinkedList<WptPt> lt = measurementPoints.get(i); LinkedList<WptPt> lt = measurementPoints.get(i);
if(lt.size() == 1) { if (lt.size() == 1) {
gpx.points.add(lt.getFirst()); gpx.points.add(lt.getFirst());
} else if(lt.size() > 1) { } else if (lt.size() > 1) {
if(saveTrackToRte) { if (saveTrackToRte) {
Route rt = new Route(); Route rt = new Route();
gpx.routes.add(rt); gpx.routes.add(rt);
rt.points.addAll(lt); rt.points.addAll(lt);
} else { } else {
if(gpx.tracks.size() == 0) { if (gpx.tracks.size() == 0) {
gpx.tracks.add(new Track()); gpx.tracks.add(new Track());
} }
Track ts = gpx.tracks.get(gpx.tracks.size() - 1); Track ts = gpx.tracks.get(gpx.tracks.size() - 1);