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

View File

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

View File

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