Add found object marker.
This commit is contained in:
parent
e5709a7112
commit
91efe32482
|
|
@ -47,6 +47,7 @@ import java.util.Observer;
|
|||
|
||||
import fr.chteufleur.mytrackingdog.models.beans.MyLocation;
|
||||
import fr.chteufleur.mytrackingdog.models.beans.MyLocationArray;
|
||||
import fr.chteufleur.mytrackingdog.models.beans.WayPointLocation;
|
||||
import fr.chteufleur.mytrackingdog.services.ServiceGps;
|
||||
|
||||
public class MainActivity extends AppCompatActivity implements IOrientationConsumer, Observer {
|
||||
|
|
@ -191,17 +192,33 @@ public class MainActivity extends AppCompatActivity implements IOrientationConsu
|
|||
|
||||
|
||||
private void addMarker() {
|
||||
MyLocation loc = serviceGps.addPointObject();
|
||||
WayPointLocation loc = serviceGps.addPointObject();
|
||||
GeoPoint gp = new GeoPoint(loc.getLatitude(), loc.getLongitude(), loc.getAltitude());
|
||||
addMarker(gp);
|
||||
addMarker(gp, loc.isFound());
|
||||
}
|
||||
|
||||
private void addMarker(GeoPoint gp) {
|
||||
private void addMarker(GeoPoint gp, boolean isFound) {
|
||||
Marker marker = new Marker(map);
|
||||
marker.setIcon(getResources().getDrawable(isFound ? R.drawable.ic_marker_blue : R.drawable.ic_marker_red));
|
||||
marker.setPosition(gp);
|
||||
marker.setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_BOTTOM);
|
||||
marker.setTitle("Object");
|
||||
marker.setDraggable(false);
|
||||
marker.setOnMarkerClickListener(new Marker.OnMarkerClickListener() {
|
||||
@Override
|
||||
public boolean onMarkerClick(Marker marker, MapView mapView) {
|
||||
if (serviceGps.isDogActivated()) {
|
||||
GeoPoint gp = marker.getPosition();
|
||||
WayPointLocation wpl = serviceGps.getPoint(gp.getLatitude(), gp.getLongitude());
|
||||
if (wpl != null) {
|
||||
wpl.setFound();
|
||||
marker.setIcon(getResources().getDrawable(R.drawable.ic_marker_blue));
|
||||
marker.setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_BOTTOM);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
});
|
||||
map.getOverlays().add(marker);
|
||||
}
|
||||
|
||||
|
|
@ -326,7 +343,11 @@ public class MainActivity extends AppCompatActivity implements IOrientationConsu
|
|||
updateTrailTrace();
|
||||
calculTrailDistance();
|
||||
for (MyLocation loc: serviceGps.getListGeoPointObjects()) {
|
||||
addMarker(new GeoPoint(loc.getLatitude(), loc.getLongitude(), loc.getAltitude()));
|
||||
boolean isFound = false;
|
||||
if (loc instanceof WayPointLocation) {
|
||||
isFound = ((WayPointLocation) loc).isFound();
|
||||
}
|
||||
addMarker(new GeoPoint(loc.getLatitude(), loc.getLongitude(), loc.getAltitude()), isFound);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -143,6 +143,7 @@ public class ImportGpx extends Gpx {
|
|||
double lat = Double.parseDouble(latStr);
|
||||
double lon = Double.parseDouble(lonStr);
|
||||
long time = -1;
|
||||
boolean isFound = false;
|
||||
|
||||
while (parser.next() != XmlPullParser.END_TAG) {
|
||||
if (parser.getEventType() != XmlPullParser.START_TAG) {
|
||||
|
|
@ -151,11 +152,13 @@ public class ImportGpx extends Gpx {
|
|||
String name = parser.getName();
|
||||
if (name.equals("time")) {
|
||||
time = readTime(parser);
|
||||
} else if (name.equals("extensions")) {
|
||||
isFound = readExtensions(parser);
|
||||
} else {
|
||||
skip(parser);
|
||||
}
|
||||
}
|
||||
return new WayPointLocation(lat, lon, time);
|
||||
return new WayPointLocation(lat, lon, time, isFound);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -182,6 +185,33 @@ public class ImportGpx extends Gpx {
|
|||
return ret;
|
||||
}
|
||||
|
||||
private boolean readExtensions(XmlPullParser parser) throws XmlPullParserException, IOException {
|
||||
boolean ret = false;
|
||||
parser.require(XmlPullParser.START_TAG, null, "extensions");
|
||||
|
||||
while (parser.next() != XmlPullParser.END_TAG) {
|
||||
if (parser.getEventType() != XmlPullParser.START_TAG) {
|
||||
continue;
|
||||
}
|
||||
String name = parser.getName();
|
||||
if (name.equals("found")) {
|
||||
ret = readFound(parser);
|
||||
} else {
|
||||
skip(parser);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
private boolean readFound(XmlPullParser parser) throws XmlPullParserException, IOException {
|
||||
boolean ret = false;
|
||||
parser.require(XmlPullParser.START_TAG, null, "found");
|
||||
ret = Boolean.parseBoolean(readText(parser));
|
||||
parser.require(XmlPullParser.END_TAG, null, "found");
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
private String readName(XmlPullParser parser) throws XmlPullParserException, IOException {
|
||||
String ret;
|
||||
|
|
|
|||
|
|
@ -2,11 +2,9 @@ package fr.chteufleur.mytrackingdog.models;
|
|||
|
||||
import android.util.Log;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import fr.chteufleur.mytrackingdog.models.beans.MyLocation;
|
||||
import fr.chteufleur.mytrackingdog.models.beans.MyLocationArray;
|
||||
import fr.chteufleur.mytrackingdog.models.beans.WayPointLocation;
|
||||
|
||||
public class Traces {
|
||||
|
||||
|
|
@ -21,17 +19,23 @@ public class Traces {
|
|||
|
||||
|
||||
public void addPointTraceur(MyLocation point) {
|
||||
Log.i(TAG, "add point traceur");
|
||||
listPointTraceur.add(point);
|
||||
}
|
||||
public void addPointDog(MyLocation point) {
|
||||
Log.i(TAG, "add point dog");
|
||||
listPointDog.add(point);
|
||||
}
|
||||
public void addPointObject(MyLocation point) {
|
||||
Log.i(TAG, "add point object ("+point.toString()+")");
|
||||
public void addPointObject(WayPointLocation point) {
|
||||
listPointObjects.add(point);
|
||||
}
|
||||
public WayPointLocation getPoint(double lat, double lon) {
|
||||
WayPointLocation ret = null;
|
||||
for (MyLocation ml: listPointObjects) {
|
||||
if (ml.isEquals(lat, lon) && ml instanceof WayPointLocation) {
|
||||
ret = (WayPointLocation) ml;
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
public void addCurrentPoint(MyLocation point) {
|
||||
if (traceurActivated) {
|
||||
addPointTraceur(point);
|
||||
|
|
|
|||
|
|
@ -102,6 +102,11 @@ public class MyLocation {
|
|||
ret += "</trkpt>";
|
||||
return ret;
|
||||
}
|
||||
|
||||
public boolean isEquals(double lat, double lon) {
|
||||
return this.latitude == lat && this.longitude == lon;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("lat=%,4f ; lon=%,4f ; time=%s", getLatitude(), getLongitude(), getDate());
|
||||
|
|
|
|||
|
|
@ -1,14 +1,32 @@
|
|||
package fr.chteufleur.mytrackingdog.models.beans;
|
||||
|
||||
import android.location.Location;
|
||||
|
||||
|
||||
public class WayPointLocation extends MyLocation {
|
||||
public WayPointLocation(Location l) {
|
||||
super(l);
|
||||
|
||||
private boolean isFound = false;
|
||||
|
||||
public WayPointLocation(MyLocation l) {
|
||||
this(l.getLatitude(), l.getLongitude(), l.getTime(), false);
|
||||
}
|
||||
public WayPointLocation(double lat, double lon, long time, boolean isFound) {
|
||||
super(lat, lon, time);
|
||||
this.isFound = isFound;
|
||||
}
|
||||
|
||||
public WayPointLocation(double lat, double lon, long time) {
|
||||
super(lat, lon, time);
|
||||
public boolean isFound() {
|
||||
return isFound;
|
||||
}
|
||||
public void setFound() {
|
||||
isFound = true;
|
||||
}
|
||||
public void setNotFound() {
|
||||
isFound = false;
|
||||
}
|
||||
|
||||
public String toWayPoint() {
|
||||
String ret = "<wpt lat=\""+getLatitude()+"\" lon=\""+getLongitude()+"\">";
|
||||
ret += "<time>"+getDate()+"</time>";
|
||||
ret += "<extensions><found>"+isFound+"</found></extensions>";
|
||||
ret += "</wpt>";
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -146,11 +146,13 @@ public class ServiceGps extends Observable implements IServiceGps, LocationListe
|
|||
return traces.isDogActivated();
|
||||
}
|
||||
|
||||
public MyLocation addPointObject() {
|
||||
public WayPointLocation addPointObject() {
|
||||
WayPointLocation wpl = null;
|
||||
if (currentLocation != null) {
|
||||
traces.addPointObject(currentLocation);
|
||||
wpl = new WayPointLocation(currentLocation);
|
||||
traces.addPointObject(wpl);
|
||||
}
|
||||
return currentLocation;
|
||||
return wpl;
|
||||
}
|
||||
|
||||
public MyLocationArray getListGeoPointTraceur() {
|
||||
|
|
@ -162,6 +164,9 @@ public class ServiceGps extends Observable implements IServiceGps, LocationListe
|
|||
public MyLocationArray getListGeoPointObjects() {
|
||||
return traces.getListPointObjects();
|
||||
}
|
||||
public WayPointLocation getPoint(double lat, double lon) {
|
||||
return traces.getPoint(lat, lon);
|
||||
}
|
||||
|
||||
public String getFileName(String prefix) {
|
||||
SimpleDateFormat formater = new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss");
|
||||
|
|
@ -174,6 +179,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.setTrace(traces.getListPointDog());
|
||||
return exportGpx.export();
|
||||
}
|
||||
|
|
|
|||
Binary file not shown.
|
After Width: | Height: | Size: 9.2 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 760 B |
Binary file not shown.
|
After Width: | Height: | Size: 765 B |
Loading…
Reference in New Issue