Save actual position when mark object as found.

This commit is contained in:
chteufleur 2018-09-26 17:35:44 +02:00
parent 542d07ec56
commit fb110c4f09
3 changed files with 64 additions and 28 deletions

View File

@ -16,8 +16,6 @@ import android.support.annotation.NonNull;
import android.support.annotation.RequiresApi;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.DragEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
@ -44,9 +42,7 @@ import org.osmdroid.views.overlay.mylocation.GpsMyLocationProvider;
import org.osmdroid.views.overlay.mylocation.MyLocationNewOverlay;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Observable;
import java.util.Observer;
@ -222,7 +218,7 @@ public class MainActivity extends AppCompatActivity implements IOrientationConsu
private void addMarker() {
WayPointLocation loc = serviceGps.addPointObject();
WayPointLocation loc = serviceGps.addPointObjectTrail();
GeoPoint gp = new GeoPoint(loc.getLatitude(), loc.getLongitude(), loc.getAltitude());
addMarker(gp, loc.isFound());
}
@ -239,7 +235,7 @@ public class MainActivity extends AppCompatActivity implements IOrientationConsu
public boolean onMarkerClick(Marker marker, MapView mapView) {
if (serviceGps.isDogActivated()) {
GeoPoint gp = marker.getPosition();
WayPointLocation wpl = serviceGps.getPoint(gp.getLatitude(), gp.getLongitude());
WayPointLocation wpl = serviceGps.getPointTrail(gp.getLatitude(), gp.getLongitude());
if (wpl != null) {
wpl.setFound();
marker.setIcon(getResources().getDrawable(R.drawable.ic_marker_blue));
@ -268,6 +264,7 @@ public class MainActivity extends AppCompatActivity implements IOrientationConsu
}
}
}
serviceGps.addPointObjectDog();
break;
}
}
@ -394,7 +391,10 @@ public class MainActivity extends AppCompatActivity implements IOrientationConsu
updateDogTrace();
updateTrailTrace();
calculTrailDistance();
for (MyLocation loc: serviceGps.getListGeoPointObjects()) {
for (MyLocation loc: serviceGps.getListGeoPointObjectsTrail()) {
addMarker(new GeoPoint(loc.getLatitude(), loc.getLongitude(), loc.getAltitude()), false);
}
for (MyLocation loc: serviceGps.getListGeoPointObjectsDog()) {
boolean isFound = false;
if (loc instanceof WayPointLocation) {
isFound = ((WayPointLocation) loc).isFound();
@ -580,7 +580,7 @@ public class MainActivity extends AppCompatActivity implements IOrientationConsu
}
private String getTextTraceur() {
return String.format("Distance: %,dm\t\t\t\t\t\t\t\tObjets: %d", ((int) distance), serviceGps.getListGeoPointObjects().size());
return String.format("Distance: %,dm\t\t\t\t\t\t\t\tObjets: %d", ((int) distance), serviceGps.getListGeoPointObjectsTrail().size());
}
private String getTextDog() {
@ -598,12 +598,12 @@ public class MainActivity extends AppCompatActivity implements IOrientationConsu
text = String.format("Time: %02d:%02d:%02d", h, m, s);
int nbFoundObject = 0;
for (MyLocation loc: serviceGps.getListGeoPointObjects()) {
for (MyLocation loc: serviceGps.getListGeoPointObjectsDog()) {
if (loc instanceof WayPointLocation && ((WayPointLocation) loc).isFound()) {
nbFoundObject++;
}
}
text += "\t\t\t\t\t\t\t\tObjets: "+nbFoundObject+"/"+serviceGps.getListGeoPointObjects().size();
text += "\t\t\t\t\t\t\t\tObjets: "+nbFoundObject+"/"+serviceGps.getListGeoPointObjectsTrail().size();
}
return text;
}

View File

@ -12,7 +12,8 @@ public class Traces {
private MyLocationArray listPointTraceur = new MyLocationArray();
private MyLocationArray listPointDog = new MyLocationArray();
private MyLocationArray listPointObjects = new MyLocationArray();
private MyLocationArray listPointObjectsTrail = new MyLocationArray();
private MyLocationArray listPointObjectsDog = new MyLocationArray();
private boolean traceurActivated = false;
private boolean dogActivated = false;
@ -24,12 +25,24 @@ public class Traces {
public void addPointDog(MyLocation point) {
listPointDog.add(point);
}
public void addPointObject(WayPointLocation point) {
listPointObjects.add(point);
public void addPointObjectTrail(WayPointLocation point) {
listPointObjectsTrail.add(point);
}
public WayPointLocation getPoint(double lat, double lon) {
public void addPointObjectDog(WayPointLocation point) {
listPointObjectsDog.add(point);
}
public WayPointLocation getPointObjectTrail(double lat, double lon) {
WayPointLocation ret = null;
for (MyLocation ml: listPointObjects) {
for (MyLocation ml: listPointObjectsTrail) {
if (ml.isEquals(lat, lon) && ml instanceof WayPointLocation) {
ret = (WayPointLocation) ml;
}
}
return ret;
}
public WayPointLocation getPointObjectDog(double lat, double lon) {
WayPointLocation ret = null;
for (MyLocation ml: listPointObjectsDog) {
if (ml.isEquals(lat, lon) && ml instanceof WayPointLocation) {
ret = (WayPointLocation) ml;
}
@ -49,8 +62,11 @@ public class Traces {
public MyLocationArray getListPointDog() {
return listPointDog;
}
public MyLocationArray getListPointObjects() {
return listPointObjects;
public MyLocationArray getListPointObjectsTrail() {
return listPointObjectsTrail;
}
public MyLocationArray getListPointObjectsDog() {
return listPointObjectsDog;
}
public void toggleTraceurActivation() {

View File

@ -147,11 +147,21 @@ public class ServiceGps extends Observable implements IServiceGps, LocationListe
return traces.isDogActivated();
}
public WayPointLocation addPointObject() {
public WayPointLocation addPointObjectTrail() {
WayPointLocation wpl = null;
if (currentLocation != null) {
wpl = new WayPointLocation(currentLocation);
traces.addPointObject(wpl);
traces.addPointObjectTrail(wpl);
}
return wpl;
}
public WayPointLocation addPointObjectDog() {
WayPointLocation wpl = null;
if (currentLocation != null) {
wpl = new WayPointLocation(currentLocation);
wpl.setFound();
traces.addPointObjectDog(wpl);
}
return wpl;
}
@ -162,17 +172,23 @@ public class ServiceGps extends Observable implements IServiceGps, LocationListe
public MyLocationArray getListGeoPointDog() {
return traces.getListPointDog();
}
public MyLocationArray getListGeoPointObjects() {
return traces.getListPointObjects();
public MyLocationArray getListGeoPointObjectsTrail() {
return traces.getListPointObjectsTrail();
}
public WayPointLocation getPoint(double lat, double lon) {
return traces.getPoint(lat, lon);
public MyLocationArray getListGeoPointObjectsDog() {
return traces.getListPointObjectsDog();
}
public WayPointLocation getPointTrail(double lat, double lon) {
return traces.getPointObjectTrail(lat, lon);
}
public WayPointLocation getPointDog(double lat, double lon) {
return traces.getPointObjectDog(lat, lon);
}
public List<WayPointLocation> foundNearObjects() {
List<WayPointLocation> ret = new ArrayList<>();
MyLocation curLoc = currentLocation;
for (MyLocation ml: getListGeoPointObjects()) {
for (MyLocation ml: getListGeoPointObjectsTrail()) {
if (curLoc.distanceTo(ml) < 10 && ml instanceof WayPointLocation) {
ret.add((WayPointLocation) ml);
}
@ -191,7 +207,7 @@ public class ServiceGps extends Observable implements IServiceGps, LocationListe
public boolean exportDogTraceToGpx() {
File file = new File(getFileName(Gpx.DOG_TRACE_NAME));
ExportGpx exportGpx = new ExportGpx(file, Gpx.DOG_TRACE_NAME);
exportGpx.setObjects(traces.getListPointObjects());
exportGpx.setObjects(traces.getListPointObjectsDog());
exportGpx.setTrace(traces.getListPointDog());
return exportGpx.export();
}
@ -199,7 +215,7 @@ public class ServiceGps extends Observable implements IServiceGps, LocationListe
public boolean exportTrailTraceToGpx() {
File file = new File(getFileName(Gpx.TRAIL_TRACE_NAME));
ExportGpx exportGpx = new ExportGpx(file, Gpx.TRAIL_TRACE_NAME);
exportGpx.setObjects(traces.getListPointObjects());
exportGpx.setObjects(traces.getListPointObjectsTrail());
exportGpx.setTrace(traces.getListPointTraceur());
return exportGpx.export();
}
@ -212,7 +228,11 @@ public class ServiceGps extends Observable implements IServiceGps, LocationListe
for (int i=0; i<list.size(); i++) {
Object o = list.get(i);
if (o instanceof WayPointLocation) {
traces.addPointObject((WayPointLocation) o);
if (traceName.equals(Gpx.DOG_TRACE_NAME)) {
traces.addPointObjectDog((WayPointLocation) o);
} else if (traceName.equals(Gpx.TRAIL_TRACE_NAME)) {
traces.addPointObjectTrail((WayPointLocation) o);
}
} else if (o instanceof TraceLocation) {
if (traceName.equals(Gpx.DOG_TRACE_NAME)) {
traces.addPointDog((TraceLocation) o);