Merge remote-tracking branch 'origin/sasha_pasha_branch' into sasha_pasha_branch
This commit is contained in:
commit
f1465dc490
4 changed files with 113 additions and 32 deletions
|
@ -9,6 +9,10 @@
|
||||||
android:id="@+id/action_save_as_gpx"
|
android:id="@+id/action_save_as_gpx"
|
||||||
android:icon="@drawable/ic_action_polygom_dark"
|
android:icon="@drawable/ic_action_polygom_dark"
|
||||||
android:title="@string/shared_string_save_as_gpx"/>
|
android:title="@string/shared_string_save_as_gpx"/>
|
||||||
|
<item
|
||||||
|
android:id="@+id/action_add_segment_to_track"
|
||||||
|
android:icon="@drawable/ic_action_polygom_dark"
|
||||||
|
android:title="@string/add_segment_to_the_track"/>
|
||||||
<item
|
<item
|
||||||
android:id="@+id/action_clear_all"
|
android:id="@+id/action_clear_all"
|
||||||
android:icon="@drawable/ic_action_reset_to_default_dark"
|
android:icon="@drawable/ic_action_reset_to_default_dark"
|
||||||
|
|
|
@ -2678,4 +2678,5 @@
|
||||||
<string name="import_track_desc">File %1$s does not contain waypoints, import it as a track?</string>
|
<string name="import_track_desc">File %1$s does not contain waypoints, import it as a track?</string>
|
||||||
<string name="save_as_new_segment">Save as new segment</string>
|
<string name="save_as_new_segment">Save as new segment</string>
|
||||||
<string name="move_point">Move Point</string>
|
<string name="move_point">Move Point</string>
|
||||||
|
<string name="add_segment_to_the_track">Add segment to the track</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
|
@ -31,6 +31,7 @@ import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import net.osmand.AndroidUtils;
|
import net.osmand.AndroidUtils;
|
||||||
|
import net.osmand.CallbackWithObject;
|
||||||
import net.osmand.IndexConstants;
|
import net.osmand.IndexConstants;
|
||||||
import net.osmand.plus.GPXUtilities;
|
import net.osmand.plus.GPXUtilities;
|
||||||
import net.osmand.plus.GPXUtilities.Route;
|
import net.osmand.plus.GPXUtilities.Route;
|
||||||
|
@ -42,6 +43,7 @@ import net.osmand.plus.activities.MapActivity;
|
||||||
import net.osmand.plus.activities.TrackActivity;
|
import net.osmand.plus.activities.TrackActivity;
|
||||||
import net.osmand.plus.activities.TrackActivity.NewGpxLine;
|
import net.osmand.plus.activities.TrackActivity.NewGpxLine;
|
||||||
import net.osmand.plus.helpers.AndroidUiHelper;
|
import net.osmand.plus.helpers.AndroidUiHelper;
|
||||||
|
import net.osmand.plus.helpers.GpxUiHelper;
|
||||||
import net.osmand.plus.measurementtool.adapter.MeasurementToolAdapter;
|
import net.osmand.plus.measurementtool.adapter.MeasurementToolAdapter;
|
||||||
import net.osmand.plus.measurementtool.adapter.MeasurementToolItemTouchHelperCallback;
|
import net.osmand.plus.measurementtool.adapter.MeasurementToolItemTouchHelperCallback;
|
||||||
import net.osmand.plus.measurementtool.command.AddPointCommand;
|
import net.osmand.plus.measurementtool.command.AddPointCommand;
|
||||||
|
@ -59,6 +61,7 @@ import net.osmand.plus.widgets.TextViewEx;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.text.MessageFormat;
|
import java.text.MessageFormat;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -249,11 +252,14 @@ public class MeasurementToolFragment extends Fragment {
|
||||||
IconsCache ic = mapActivity.getMyApplication().getIconsCache();
|
IconsCache ic = mapActivity.getMyApplication().getIconsCache();
|
||||||
MenuItem saveAsNewSegmentMenuItem = menu.findItem(R.id.action_save_as_new_segment);
|
MenuItem saveAsNewSegmentMenuItem = menu.findItem(R.id.action_save_as_new_segment);
|
||||||
MenuItem saveAsGpxTrack = menu.findItem(R.id.action_save_as_gpx);
|
MenuItem saveAsGpxTrack = menu.findItem(R.id.action_save_as_gpx);
|
||||||
|
MenuItem addSegmentToTrack = menu.findItem(R.id.action_add_segment_to_track);
|
||||||
|
addSegmentToTrack.setIcon(ic.getThemedIcon(R.drawable.ic_action_polygom_dark));
|
||||||
saveAsNewSegmentMenuItem.setIcon(ic.getThemedIcon(R.drawable.ic_action_polygom_dark));
|
saveAsNewSegmentMenuItem.setIcon(ic.getThemedIcon(R.drawable.ic_action_polygom_dark));
|
||||||
saveAsGpxTrack.setIcon(ic.getThemedIcon(R.drawable.ic_action_polygom_dark));
|
saveAsGpxTrack.setIcon(ic.getThemedIcon(R.drawable.ic_action_polygom_dark));
|
||||||
if (newGpxLine != null) {
|
if (newGpxLine != null) {
|
||||||
saveAsNewSegmentMenuItem.setVisible(true);
|
saveAsNewSegmentMenuItem.setVisible(true);
|
||||||
saveAsGpxTrack.setVisible(false);
|
saveAsGpxTrack.setVisible(false);
|
||||||
|
addSegmentToTrack.setVisible(false);
|
||||||
}
|
}
|
||||||
menu.findItem(R.id.action_clear_all).setIcon(ic.getThemedIcon(R.drawable.ic_action_reset_to_default_dark));
|
menu.findItem(R.id.action_clear_all).setIcon(ic.getThemedIcon(R.drawable.ic_action_reset_to_default_dark));
|
||||||
popup.setOnMenuItemClickListener(new IconPopupMenu.OnMenuItemClickListener() {
|
popup.setOnMenuItemClickListener(new IconPopupMenu.OnMenuItemClickListener() {
|
||||||
|
@ -267,6 +273,13 @@ public class MeasurementToolFragment extends Fragment {
|
||||||
Toast.makeText(mapActivity, getString(R.string.none_point_error), Toast.LENGTH_SHORT).show();
|
Toast.makeText(mapActivity, getString(R.string.none_point_error), Toast.LENGTH_SHORT).show();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
case R.id.action_add_segment_to_track:
|
||||||
|
if (measurementLayer.getPointsCount() > 0) {
|
||||||
|
// showAddSegmentDialog(mapActivity);
|
||||||
|
} else {
|
||||||
|
Toast.makeText(mapActivity, getString(R.string.none_point_error), Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
return true;
|
||||||
case R.id.action_save_as_gpx:
|
case R.id.action_save_as_gpx:
|
||||||
if (measurementLayer.getPointsCount() > 0) {
|
if (measurementLayer.getPointsCount() > 0) {
|
||||||
saveAsGpxOnClick(mapActivity);
|
saveAsGpxOnClick(mapActivity);
|
||||||
|
@ -342,6 +355,21 @@ public class MeasurementToolFragment extends Fragment {
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private AlertDialog showAddSegmentDialog(final MapActivity mapActivity) {
|
||||||
|
CallbackWithObject<GPXFile[]> callbackWithObject = new CallbackWithObject<GPXFile[]>() {
|
||||||
|
@Override
|
||||||
|
public boolean processResult(GPXFile[] result) {
|
||||||
|
GPXFile gpxFile;
|
||||||
|
if (result != null && result.length > 0) {
|
||||||
|
gpxFile = result[0];
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return GpxUiHelper.selectSingleGPXFile(mapActivity, false, callbackWithObject);
|
||||||
|
}
|
||||||
|
|
||||||
private void cancelMovePointMode() {
|
private void cancelMovePointMode() {
|
||||||
if (inMovePointMode) {
|
if (inMovePointMode) {
|
||||||
exitMovePointMode();
|
exitMovePointMode();
|
||||||
|
@ -464,7 +492,7 @@ public class MeasurementToolFragment extends Fragment {
|
||||||
GPXFile gpx = newGpxLine.getGpxFile();
|
GPXFile gpx = newGpxLine.getGpxFile();
|
||||||
SelectedGpxFile selectedGpxFile = mapActivity.getMyApplication().getSelectedGpxHelper().getSelectedFileByPath(gpx.path);
|
SelectedGpxFile selectedGpxFile = mapActivity.getMyApplication().getSelectedGpxHelper().getSelectedFileByPath(gpx.path);
|
||||||
boolean showOnMap = selectedGpxFile != null;
|
boolean showOnMap = selectedGpxFile != null;
|
||||||
saveGpx(null, null, showOnMap);
|
saveGpx(gpx, showOnMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void saveAsGpxOnClick(MapActivity mapActivity) {
|
private void saveAsGpxOnClick(MapActivity mapActivity) {
|
||||||
|
@ -526,14 +554,14 @@ public class MeasurementToolFragment extends Fragment {
|
||||||
fout = new File(dir, fileName);
|
fout = new File(dir, fileName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
saveGpx(dir, fileName, showOnMapToggle.isChecked());
|
createAndSaveGpx(dir, fileName, showOnMapToggle.isChecked());
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.setNegativeButton(R.string.shared_string_cancel, null)
|
.setNegativeButton(R.string.shared_string_cancel, null)
|
||||||
.show();
|
.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void saveGpx(final File dir, final String fileName, final boolean showOnMap) {
|
private void saveGpx(final GPXFile gpx, final boolean showOnMap) {
|
||||||
new AsyncTask<Void, Void, String>() {
|
new AsyncTask<Void, Void, String>() {
|
||||||
|
|
||||||
private ProgressDialog progressDialog;
|
private ProgressDialog progressDialog;
|
||||||
|
@ -552,17 +580,67 @@ public class MeasurementToolFragment extends Fragment {
|
||||||
@Override
|
@Override
|
||||||
protected String doInBackground(Void... voids) {
|
protected String doInBackground(Void... voids) {
|
||||||
MeasurementToolLayer measurementLayer = getMeasurementLayer();
|
MeasurementToolLayer measurementLayer = getMeasurementLayer();
|
||||||
GPXFile gpx;
|
|
||||||
if (newGpxLine != null) {
|
|
||||||
gpx = newGpxLine.getGpxFile();
|
|
||||||
toSave = new File(gpx.path);
|
toSave = new File(gpx.path);
|
||||||
if (measurementLayer != null) {
|
if (measurementLayer != null) {
|
||||||
List<WptPt> points = measurementLayer.getMeasurementPoints();
|
List<WptPt> points = measurementLayer.getMeasurementPoints();
|
||||||
gpx.addTrkSegment(points);
|
gpx.addTrkSegment(points);
|
||||||
}
|
}
|
||||||
|
MapActivity activity = getMapActivity();
|
||||||
|
if (activity != null) {
|
||||||
|
String res = GPXUtilities.writeGpxFile(toSave, gpx, activity.getMyApplication());
|
||||||
|
if (showOnMap) {
|
||||||
|
SelectedGpxFile sf = activity.getMyApplication().getSelectedGpxHelper().selectGpxFile(gpx, true, false);
|
||||||
|
if (sf != null) {
|
||||||
|
sf.processPoints();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPostExecute(String warning) {
|
||||||
|
MapActivity activity = getMapActivity();
|
||||||
|
if (activity != null) {
|
||||||
|
if (warning == null) {
|
||||||
|
Toast.makeText(activity,
|
||||||
|
MessageFormat.format(getString(R.string.gpx_saved_sucessfully), toSave.getAbsolutePath()),
|
||||||
|
Toast.LENGTH_LONG).show();
|
||||||
|
saved = true;
|
||||||
} else {
|
} else {
|
||||||
gpx = new GPXFile();
|
Toast.makeText(activity, warning, Toast.LENGTH_LONG).show();
|
||||||
|
}
|
||||||
|
activity.refreshMap();
|
||||||
|
}
|
||||||
|
if (progressDialog != null && progressDialog.isShowing()) {
|
||||||
|
progressDialog.dismiss();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}.execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createAndSaveGpx(final File dir, final String fileName, final boolean showOnMap) {
|
||||||
|
new AsyncTask<Void, Void, String>() {
|
||||||
|
|
||||||
|
private ProgressDialog progressDialog;
|
||||||
|
private File toSave;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPreExecute() {
|
||||||
|
MapActivity activity = getMapActivity();
|
||||||
|
if (activity != null) {
|
||||||
|
progressDialog = new ProgressDialog(activity);
|
||||||
|
progressDialog.setMessage(getString(R.string.saving_gpx_tracks));
|
||||||
|
progressDialog.show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String doInBackground(Void... voids) {
|
||||||
toSave = new File(dir, fileName);
|
toSave = new File(dir, fileName);
|
||||||
|
GPXFile gpx = new GPXFile();
|
||||||
|
MeasurementToolLayer measurementLayer = getMeasurementLayer();
|
||||||
if (measurementLayer != null) {
|
if (measurementLayer != null) {
|
||||||
LinkedList<WptPt> points = measurementLayer.getMeasurementPoints();
|
LinkedList<WptPt> points = measurementLayer.getMeasurementPoints();
|
||||||
if (points.size() == 1) {
|
if (points.size() == 1) {
|
||||||
|
@ -573,18 +651,12 @@ public class MeasurementToolFragment extends Fragment {
|
||||||
rt.points.addAll(points);
|
rt.points.addAll(points);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
MapActivity activity = getMapActivity();
|
MapActivity activity = getMapActivity();
|
||||||
if (activity != null) {
|
if (activity != null) {
|
||||||
String res = GPXUtilities.writeGpxFile(toSave, gpx, activity.getMyApplication());
|
String res = GPXUtilities.writeGpxFile(toSave, gpx, activity.getMyApplication());
|
||||||
if (newGpxLine == null) {
|
|
||||||
gpx.path = toSave.getAbsolutePath();
|
gpx.path = toSave.getAbsolutePath();
|
||||||
}
|
|
||||||
if (showOnMap) {
|
if (showOnMap) {
|
||||||
SelectedGpxFile sf = activity.getMyApplication().getSelectedGpxHelper().selectGpxFile(gpx, true, false);
|
activity.getMyApplication().getSelectedGpxHelper().selectGpxFile(gpx, true, false);
|
||||||
if (newGpxLine != null && sf != null) {
|
|
||||||
sf.processPoints();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
|
@ -203,12 +203,11 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
|
||||||
}
|
}
|
||||||
calculatePath(tb, tx, ty, path);
|
calculatePath(tb, tx, ty, path);
|
||||||
canvas.drawPath(path, lineAttrs.paint);
|
canvas.drawPath(path, lineAttrs.paint);
|
||||||
|
WptPt pointToDrawOnTop = null;
|
||||||
for (int i = 0; i < measurementPoints.size(); i++) {
|
for (int i = 0; i < measurementPoints.size(); i++) {
|
||||||
WptPt pt = measurementPoints.get(i);
|
WptPt pt = measurementPoints.get(i);
|
||||||
if (inMovePointMode && i == movePointPos) {
|
if (inMovePointMode && i == movePointPos) {
|
||||||
int locX = tb.getCenterPixelX();
|
pointToDrawOnTop = pt;
|
||||||
int locY = tb.getCenterPixelY();
|
|
||||||
canvas.drawBitmap(movePointIcon, locX - marginX, locY - marginY, bitmapPaint);
|
|
||||||
} else {
|
} else {
|
||||||
if (tb.containsLatLon(pt.lat, pt.lon)) {
|
if (tb.containsLatLon(pt.lat, pt.lon)) {
|
||||||
int locX = tb.getPixXFromLonNoRot(pt.lon);
|
int locX = tb.getPixXFromLonNoRot(pt.lon);
|
||||||
|
@ -217,6 +216,11 @@ public class MeasurementToolLayer extends OsmandMapLayer implements ContextMenuL
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (pointToDrawOnTop != null) {
|
||||||
|
int locX = tb.getCenterPixelX();
|
||||||
|
int locY = tb.getCenterPixelY();
|
||||||
|
canvas.drawBitmap(movePointIcon, locX - marginX, locY - marginY, bitmapPaint);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue