Move trace management into ServiceTrackingDog.
This commit is contained in:
parent
25504418d3
commit
0176f37d01
|
|
@ -7,6 +7,7 @@ import android.content.pm.ActivityInfo;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.hardware.GeomagneticField;
|
import android.hardware.GeomagneticField;
|
||||||
|
import android.location.Location;
|
||||||
import android.location.LocationManager;
|
import android.location.LocationManager;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
|
|
@ -54,6 +55,7 @@ import java.util.List;
|
||||||
import java.util.Observable;
|
import java.util.Observable;
|
||||||
import java.util.Observer;
|
import java.util.Observer;
|
||||||
|
|
||||||
|
import fr.chteufleur.mytrackingdog.models.Notification;
|
||||||
import fr.chteufleur.mytrackingdog.models.beans.MyLocation;
|
import fr.chteufleur.mytrackingdog.models.beans.MyLocation;
|
||||||
import fr.chteufleur.mytrackingdog.models.beans.MyLocationArray;
|
import fr.chteufleur.mytrackingdog.models.beans.MyLocationArray;
|
||||||
import fr.chteufleur.mytrackingdog.models.beans.WayPointLocation;
|
import fr.chteufleur.mytrackingdog.models.beans.WayPointLocation;
|
||||||
|
|
@ -174,6 +176,7 @@ public class MainActivity extends AppCompatActivity implements IOrientationConsu
|
||||||
serviceTrackingDog.sendCommandStopTrail();
|
serviceTrackingDog.sendCommandStopTrail();
|
||||||
}
|
}
|
||||||
} catch (XmppStringprepException | InterruptedException | SmackException.NoResponseException | SmackException.NotConnectedException | XMPPException.XMPPErrorException ex) {
|
} catch (XmppStringprepException | InterruptedException | SmackException.NoResponseException | SmackException.NotConnectedException | XMPPException.XMPPErrorException ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -197,6 +200,7 @@ public class MainActivity extends AppCompatActivity implements IOrientationConsu
|
||||||
try {
|
try {
|
||||||
serviceTrackingDog.sendCommandObjectTrail(loc.getLatitude(), loc.getLongitude(), loc.getTime());
|
serviceTrackingDog.sendCommandObjectTrail(loc.getLatitude(), loc.getLongitude(), loc.getTime());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (serviceTrackingDog.isDogActivated()) {
|
} else if (serviceTrackingDog.isDogActivated()) {
|
||||||
|
|
@ -421,7 +425,7 @@ public class MainActivity extends AppCompatActivity implements IOrientationConsu
|
||||||
Log.i(TAG, "TEXT: "+text);
|
Log.i(TAG, "TEXT: "+text);
|
||||||
} catch (SmackException.NotConnectedException | InterruptedException | XmppStringprepException e) {
|
} catch (SmackException.NotConnectedException | InterruptedException | XmppStringprepException e) {
|
||||||
Log.e(TAG, "Fail send presence", e);
|
Log.e(TAG, "Fail send presence", e);
|
||||||
Toast.makeText(ctx, "Echec connexion avec le matériel", Toast.LENGTH_LONG).show();;
|
Toast.makeText(ctx, "Echec connexion avec le matériel", Toast.LENGTH_LONG).show();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
@ -461,7 +465,6 @@ public class MainActivity extends AppCompatActivity implements IOrientationConsu
|
||||||
if (gpsspeed < 0.01) {
|
if (gpsspeed < 0.01) {
|
||||||
GeomagneticField gf = new GeomagneticField(lat, lon, alt, timeOfFix);
|
GeomagneticField gf = new GeomagneticField(lat, lon, alt, timeOfFix);
|
||||||
float trueNorth = orientationToMagneticNorth + gf.getDeclination();
|
float trueNorth = orientationToMagneticNorth + gf.getDeclination();
|
||||||
gf = null;
|
|
||||||
if (trueNorth > 360.0f) {
|
if (trueNorth > 360.0f) {
|
||||||
trueNorth = trueNorth - 360.0f;
|
trueNorth = trueNorth - 360.0f;
|
||||||
}
|
}
|
||||||
|
|
@ -637,93 +640,90 @@ public class MainActivity extends AppCompatActivity implements IOrientationConsu
|
||||||
@Override
|
@Override
|
||||||
public void update(Observable observable, Object o) {
|
public void update(Observable observable, Object o) {
|
||||||
if (observable.getClass().getName().equals(ServiceGps.class.getName())) {
|
if (observable.getClass().getName().equals(ServiceGps.class.getName())) {
|
||||||
updateServiceGps(o);
|
updateServiceGps((Notification) o);
|
||||||
} else if (observable.getClass().getName().equals(ServiceXmpp.class.getName())) {
|
} else if (observable.getClass().getName().equals(ServiceXmpp.class.getName())) {
|
||||||
updateServiceXmpp(o);
|
updateServiceXmpp((Notification) o);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateServiceGps(Object o) {
|
public void updateServiceGps(Notification notification) {
|
||||||
if (o instanceof String && o.equals(ServiceGps.NOTIF_NEW_LOCATION)) {
|
if (notification.isAction(ServiceGps.NOTIF_NEW_LOCATION)) {
|
||||||
MyLocation loc = serviceTrackingDog.getCurrentLocation();
|
Location loc = (Location) notification.getExtra(ServiceGps.NOTIF_NEW_LOCATION_VALUE_LOCATION);
|
||||||
onNewLocation(loc);
|
if (loc != null) {
|
||||||
}
|
onNewLocation(new MyLocation(loc));
|
||||||
}
|
|
||||||
|
|
||||||
public void updateServiceXmpp(Object o) {
|
|
||||||
if (o instanceof String) {
|
|
||||||
if (o.equals(ServiceXmpp.NOTIF_NEW_LOCATION)) {
|
|
||||||
runOnUiThread(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
if (serviceTrackingDog.isTraceurActivated()) {
|
|
||||||
MyLocation loc = serviceTrackingDog.getXmppCurrentLocation();
|
|
||||||
onNewLocation(loc);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else if (o.equals(ServiceXmpp.NOTIF_NEW_OBJECT)){
|
|
||||||
runOnUiThread(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
if (serviceTrackingDog.isTraceurActivated()) {
|
|
||||||
MyLocation locObj = serviceTrackingDog.getXmppLastObjectLocation();
|
|
||||||
WayPointLocation loc = serviceTrackingDog.addPointObjectTrail(locObj);
|
|
||||||
GeoPoint gp = new GeoPoint(loc.getLatitude(), loc.getLongitude(), loc.getAltitude());
|
|
||||||
addMarker(gp, loc.isFound());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else if (o.equals(ServiceXmpp.NOTIF_START_TRAIL)){
|
|
||||||
runOnUiThread(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
changeStatusTrace();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else if (o.equals(ServiceXmpp.NOTIF_STOP_TRAIL)){
|
|
||||||
runOnUiThread(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
changeStatusTrace();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void updateServiceXmpp(Notification notification) {
|
||||||
|
if (notification.isAction(ServiceXmpp.NOTIF_NEW_LOCATION)) {
|
||||||
|
if (serviceTrackingDog.isTraceurActivated()) {
|
||||||
|
MyLocation loc = (MyLocation) notification.getExtra(ServiceXmpp.NOTIF_NEW_LOCATION_VALUE_LOCATION);
|
||||||
|
onNewLocation(loc);
|
||||||
|
}
|
||||||
|
} else if (notification.isAction(ServiceXmpp.NOTIF_NEW_OBJECT)){
|
||||||
|
if (serviceTrackingDog.isTraceurActivated()) {
|
||||||
|
MyLocation locObj = (MyLocation) notification.getExtra(ServiceXmpp.NOTIF_NEW_OBJECT_VALUE_LOCATION);
|
||||||
|
WayPointLocation loc = serviceTrackingDog.addPointObjectTrail(locObj);
|
||||||
|
GeoPoint gp = new GeoPoint(loc.getLatitude(), loc.getLongitude(), loc.getAltitude());
|
||||||
|
addMarker(gp, loc.isFound());
|
||||||
|
}
|
||||||
|
} else if (notification.isAction(ServiceXmpp.NOTIF_START_TRAIL)){
|
||||||
|
runOnUiThread(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
changeStatusTrace();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else if (notification.isAction(ServiceXmpp.NOTIF_STOP_TRAIL)){
|
||||||
|
runOnUiThread(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
changeStatusTrace();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private MyLocation onNewLocation = null;
|
||||||
private void onNewLocation(MyLocation loc) {
|
private void onNewLocation(MyLocation loc) {
|
||||||
if (loc != null) {
|
if (loc != null) {
|
||||||
GeoPoint currentPoint = new GeoPoint(loc.getLatitude(), loc.getLongitude(), loc.getAltitude());
|
onNewLocation = loc;
|
||||||
if (mLocationOverlay.isFollowLocationEnabled()) {
|
runOnUiThread(new Runnable() {
|
||||||
map.getController().setCenter(currentPoint);
|
@Override
|
||||||
}
|
public void run() {
|
||||||
if (serviceTrackingDog.isTraceurActivated()) {
|
GeoPoint currentPoint = new GeoPoint(onNewLocation.getLatitude(), onNewLocation.getLongitude(), onNewLocation.getAltitude());
|
||||||
updateTrailTrace();
|
if (mLocationOverlay.isFollowLocationEnabled()) {
|
||||||
if (lastLocation != null) {
|
map.getController().setCenter(currentPoint);
|
||||||
distance += loc.distanceTo(lastLocation);
|
}
|
||||||
updateDistance();
|
if (serviceTrackingDog.isTraceurActivated()) {
|
||||||
}
|
updateTrailTrace();
|
||||||
lastLocation = loc;
|
if (lastLocation != null) {
|
||||||
} else if (serviceTrackingDog.isDogActivated()) {
|
distance += onNewLocation.distanceTo(lastLocation);
|
||||||
updateDogTrace();
|
updateDistance();
|
||||||
if (lastLocation != null) {
|
}
|
||||||
distance += loc.distanceTo(lastLocation);
|
lastLocation = onNewLocation;
|
||||||
updateDistance();
|
} else if (serviceTrackingDog.isDogActivated()) {
|
||||||
}
|
updateDogTrace();
|
||||||
lastLocation = loc;
|
if (lastLocation != null) {
|
||||||
}
|
distance += onNewLocation.distanceTo(lastLocation);
|
||||||
|
updateDistance();
|
||||||
|
}
|
||||||
|
lastLocation = onNewLocation;
|
||||||
|
}
|
||||||
|
|
||||||
float orientation = serviceTrackingDog.getOrientation(deviceOrientation);
|
float orientation = serviceTrackingDog.getOrientation(deviceOrientation);
|
||||||
if (orientation >= 0) {
|
if (orientation >= 0) {
|
||||||
map.setMapOrientation(orientation);
|
map.setMapOrientation(orientation);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!zoomed) {
|
if (!zoomed) {
|
||||||
IMapController mapController = map.getController();
|
IMapController mapController = map.getController();
|
||||||
mapController.setZoom(20.0);
|
mapController.setZoom(20.0);
|
||||||
zoomed = true;
|
zoomed = true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//</editor-fold>
|
//</editor-fold>
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,42 @@
|
||||||
|
package fr.chteufleur.mytrackingdog.models;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class Notification {
|
||||||
|
|
||||||
|
private final String action;
|
||||||
|
private final Map<String, Object> extras;
|
||||||
|
|
||||||
|
public Notification(String action) {
|
||||||
|
this(action, new HashMap<String, Object>());
|
||||||
|
}
|
||||||
|
|
||||||
|
public Notification(String action, Map<String, Object> extras) {
|
||||||
|
this.action = action;
|
||||||
|
this.extras = extras;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isAction(String action) {
|
||||||
|
boolean ret = false;
|
||||||
|
if (action != null) {
|
||||||
|
ret = this.action.equals(action);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Notification addExtra(String param, Object value) {
|
||||||
|
if (extras != null) {
|
||||||
|
extras.put(param, value);
|
||||||
|
}
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object getExtra(String param) {
|
||||||
|
Object ret = null;
|
||||||
|
if (extras != null && extras.containsKey(param)) {
|
||||||
|
ret = extras.get(param);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,62 +1,29 @@
|
||||||
package fr.chteufleur.mytrackingdog.services;
|
package fr.chteufleur.mytrackingdog.services;
|
||||||
|
|
||||||
import android.content.SharedPreferences;
|
|
||||||
import android.location.Location;
|
import android.location.Location;
|
||||||
import android.location.LocationListener;
|
import android.location.LocationListener;
|
||||||
import android.location.LocationManager;
|
import android.location.LocationManager;
|
||||||
import android.location.LocationProvider;
|
import android.location.LocationProvider;
|
||||||
import android.os.Build;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Environment;
|
|
||||||
import android.os.VibrationEffect;
|
|
||||||
import android.os.Vibrator;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import org.xmlpull.v1.XmlPullParserException;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.text.SimpleDateFormat;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Observable;
|
import java.util.Observable;
|
||||||
|
|
||||||
import fr.chteufleur.mytrackingdog.models.ExportGpx;
|
import fr.chteufleur.mytrackingdog.models.Notification;
|
||||||
import fr.chteufleur.mytrackingdog.models.Gpx;
|
|
||||||
import fr.chteufleur.mytrackingdog.models.ImportGpx;
|
|
||||||
import fr.chteufleur.mytrackingdog.models.Traces;
|
|
||||||
import fr.chteufleur.mytrackingdog.models.beans.MyLocation;
|
|
||||||
import fr.chteufleur.mytrackingdog.models.beans.MyLocationArray;
|
|
||||||
import fr.chteufleur.mytrackingdog.models.beans.TraceLocation;
|
|
||||||
import fr.chteufleur.mytrackingdog.models.beans.WayPointLocation;
|
|
||||||
|
|
||||||
public class ServiceGps extends Observable implements LocationListener {
|
public class ServiceGps extends Observable implements LocationListener {
|
||||||
|
|
||||||
private static final String TAG = ServiceGps.class.getName();
|
private static final String TAG = ServiceGps.class.getName();
|
||||||
public static final String NOTIF_NEW_LOCATION = ServiceGps.class.getName()+".newlocation";
|
public static final String NOTIF_NEW_LOCATION = ServiceGps.class.getName()+".newlocation";
|
||||||
|
public static final String NOTIF_NEW_LOCATION_VALUE_LOCATION = NOTIF_NEW_LOCATION+".value.location";
|
||||||
private File lastExportedTrailFile = null;
|
|
||||||
|
|
||||||
private LocationManager locationManager;
|
private LocationManager locationManager;
|
||||||
private MyLocation currentLocation = null;
|
|
||||||
private String appName = "";
|
|
||||||
|
|
||||||
private final Traces traces = new Traces();
|
|
||||||
|
|
||||||
public ServiceGps() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLocationManager(LocationManager locationManager) {
|
public void setLocationManager(LocationManager locationManager) {
|
||||||
this.locationManager = locationManager;
|
this.locationManager = locationManager;
|
||||||
}
|
}
|
||||||
public void setAppName(String appName) {
|
|
||||||
this.appName = appName;
|
|
||||||
}
|
|
||||||
|
|
||||||
public MyLocation getCurrentLocation() {
|
|
||||||
return currentLocation;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void start() {
|
public void start() {
|
||||||
try {
|
try {
|
||||||
|
|
@ -76,32 +43,12 @@ public class ServiceGps extends Observable implements LocationListener {
|
||||||
Log.i(TAG, "Stop location");
|
Log.i(TAG, "Stop location");
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getOrientation(int deviceOrientation) {
|
|
||||||
float ret = -1;
|
|
||||||
if (currentLocation != null && currentLocation.getSpeed() >= 0.01) {
|
|
||||||
ret = (360 - currentLocation.getBearing() - deviceOrientation);
|
|
||||||
if (ret < 0) {
|
|
||||||
ret += 360;
|
|
||||||
}
|
|
||||||
if (ret > 360) {
|
|
||||||
ret -= 360;
|
|
||||||
}
|
|
||||||
//help smooth everything out
|
|
||||||
ret = (int) ret;
|
|
||||||
ret = ret / 5;
|
|
||||||
ret = (int) ret;
|
|
||||||
ret = ret * 5;
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
//<editor-fold defaultstate="collapsed" desc="GPS Callback">
|
//<editor-fold defaultstate="collapsed" desc="GPS Callback">
|
||||||
@Override
|
@Override
|
||||||
public void onLocationChanged(Location location) {
|
public void onLocationChanged(Location location) {
|
||||||
Log.i(TAG, "onLocationChanged");
|
Log.i(TAG, "onLocationChanged");
|
||||||
currentLocation = new MyLocation(location);
|
|
||||||
setChanged();
|
setChanged();
|
||||||
notifyObservers(NOTIF_NEW_LOCATION);
|
notifyObservers(new Notification(NOTIF_NEW_LOCATION).addExtra(NOTIF_NEW_LOCATION_VALUE_LOCATION, location));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -133,155 +80,4 @@ public class ServiceGps extends Observable implements LocationListener {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//</editor-fold>
|
//</editor-fold>
|
||||||
|
|
||||||
//<editor-fold defaultstate="collapsed" desc="Trace management">
|
|
||||||
//<editor-fold defaultstate="collapsed" desc="Trace activation">
|
|
||||||
public void toggleTraceurActivation() {
|
|
||||||
traces.toggleTraceurActivation();
|
|
||||||
if (!isTraceurActivated()) {
|
|
||||||
exportTrailTraceToGpx();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public boolean isTraceurActivated() {
|
|
||||||
return traces.isTraceurActivated();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void toggleDogActivation() {
|
|
||||||
traces.toggleDogActivation();
|
|
||||||
if (!isDogActivated()) {
|
|
||||||
exportDogTraceToGpx();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public boolean isDogActivated() {
|
|
||||||
return traces.isDogActivated();
|
|
||||||
}
|
|
||||||
//</editor-fold>
|
|
||||||
//<editor-fold defaultstate="collapsed" desc="Objects">
|
|
||||||
public WayPointLocation addPointObjectTrail() {
|
|
||||||
return addPointObjectTrail(currentLocation);
|
|
||||||
}
|
|
||||||
|
|
||||||
public WayPointLocation addPointObjectTrail(MyLocation location) {
|
|
||||||
WayPointLocation wpl = null;
|
|
||||||
if (location != null) {
|
|
||||||
wpl = new WayPointLocation(location);
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
public MyLocationArray getListGeoPointObjectsTrail() {
|
|
||||||
return traces.getListPointObjectsTrail();
|
|
||||||
}
|
|
||||||
public MyLocationArray getListGeoPointObjectsDog() {
|
|
||||||
return traces.getListPointObjectsDog();
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<WayPointLocation> foundNearObjects(int distance) {
|
|
||||||
List<WayPointLocation> ret = new ArrayList<>();
|
|
||||||
MyLocation curLoc = currentLocation;
|
|
||||||
for (MyLocation ml: getListGeoPointObjectsTrail()) {
|
|
||||||
if (curLoc.distanceTo(ml) < distance && ml instanceof WayPointLocation) {
|
|
||||||
ret.add((WayPointLocation) ml);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
public boolean isNearObjects() {
|
|
||||||
return !foundNearObjects(20).isEmpty();
|
|
||||||
}
|
|
||||||
public List<WayPointLocation> foundNearObjects() {
|
|
||||||
return foundNearObjects(10);
|
|
||||||
}
|
|
||||||
//</editor-fold>
|
|
||||||
//<editor-fold defaultstate="collapsed" desc="Traces">
|
|
||||||
public void addPoint(MyLocation location) {
|
|
||||||
traces.addCurrentPoint(location);
|
|
||||||
}
|
|
||||||
public MyLocationArray getListGeoPointTraceur() {
|
|
||||||
return traces.getListPointTraceur();
|
|
||||||
}
|
|
||||||
public MyLocationArray getListGeoPointDog() {
|
|
||||||
return traces.getListPointDog();
|
|
||||||
}
|
|
||||||
public WayPointLocation getPointTrail(double lat, double lon) {
|
|
||||||
return traces.getPointObjectTrail(lat, lon);
|
|
||||||
}
|
|
||||||
public WayPointLocation getPointDog(double lat, double lon) {
|
|
||||||
return traces.getPointObjectDog(lat, lon);
|
|
||||||
}
|
|
||||||
//</editor-fold>
|
|
||||||
//</editor-fold>
|
|
||||||
|
|
||||||
//<editor-fold defaultstate="collapsed" desc="Export file management">
|
|
||||||
private String getFileName(String prefix) {
|
|
||||||
SimpleDateFormat formater = new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss");
|
|
||||||
String date = formater.format(new Date());
|
|
||||||
return Environment.getExternalStorageDirectory().getAbsolutePath() + "/"
|
|
||||||
+ appName + "/" + date + "_" + prefix
|
|
||||||
+ ".gpx";
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean exportDogTraceToGpx() {
|
|
||||||
File file = new File(getFileName(Gpx.DOG_TRACE_NAME));
|
|
||||||
ExportGpx exportGpx = new ExportGpx(file, Gpx.DOG_TRACE_NAME);
|
|
||||||
exportGpx.setObjects(traces.getListPointObjectsDog());
|
|
||||||
exportGpx.setTrace(traces.getListPointDog());
|
|
||||||
return exportGpx.export();
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean exportTrailTraceToGpx() {
|
|
||||||
File file = new File(getFileName(Gpx.TRAIL_TRACE_NAME));
|
|
||||||
ExportGpx exportGpx = new ExportGpx(file, Gpx.TRAIL_TRACE_NAME);
|
|
||||||
exportGpx.setObjects(traces.getListPointObjectsTrail());
|
|
||||||
exportGpx.setTrace(traces.getListPointTraceur());
|
|
||||||
lastExportedTrailFile = file;
|
|
||||||
return exportGpx.export();
|
|
||||||
}
|
|
||||||
|
|
||||||
public File getLastExportedTrailFile() {
|
|
||||||
return lastExportedTrailFile;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void importGpxTrace(File file) {
|
|
||||||
ImportGpx importGpx = new ImportGpx(file);
|
|
||||||
try {
|
|
||||||
List<MyLocation> list = importGpx.parse();
|
|
||||||
String traceName = importGpx.getTraceName();
|
|
||||||
if (traceName.equals(Gpx.TRAIL_TRACE_NAME)) {
|
|
||||||
lastExportedTrailFile = file;
|
|
||||||
}
|
|
||||||
for (int i=0; i<list.size(); i++) {
|
|
||||||
MyLocation o = list.get(i);
|
|
||||||
if (o instanceof WayPointLocation) {
|
|
||||||
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);
|
|
||||||
} else if (traceName.equals(Gpx.TRAIL_TRACE_NAME)) {
|
|
||||||
traces.addPointTraceur((TraceLocation) o);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (XmlPullParserException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//</editor-fold>
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,28 +2,45 @@ package fr.chteufleur.mytrackingdog.services;
|
||||||
|
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
|
import android.location.Location;
|
||||||
import android.location.LocationManager;
|
import android.location.LocationManager;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
|
import android.os.Environment;
|
||||||
import android.os.VibrationEffect;
|
import android.os.VibrationEffect;
|
||||||
import android.os.Vibrator;
|
import android.os.Vibrator;
|
||||||
|
|
||||||
import org.jivesoftware.smack.SmackException;
|
import org.jivesoftware.smack.SmackException;
|
||||||
import org.jivesoftware.smack.XMPPException;
|
import org.jivesoftware.smack.XMPPException;
|
||||||
import org.jxmpp.stringprep.XmppStringprepException;
|
import org.jxmpp.stringprep.XmppStringprepException;
|
||||||
|
import org.xmlpull.v1.XmlPullParserException;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
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;
|
||||||
|
|
||||||
|
import fr.chteufleur.mytrackingdog.models.ExportGpx;
|
||||||
|
import fr.chteufleur.mytrackingdog.models.Gpx;
|
||||||
|
import fr.chteufleur.mytrackingdog.models.ImportGpx;
|
||||||
|
import fr.chteufleur.mytrackingdog.models.Notification;
|
||||||
|
import fr.chteufleur.mytrackingdog.models.Traces;
|
||||||
import fr.chteufleur.mytrackingdog.models.beans.MyLocation;
|
import fr.chteufleur.mytrackingdog.models.beans.MyLocation;
|
||||||
import fr.chteufleur.mytrackingdog.models.beans.MyLocationArray;
|
import fr.chteufleur.mytrackingdog.models.beans.MyLocationArray;
|
||||||
|
import fr.chteufleur.mytrackingdog.models.beans.TraceLocation;
|
||||||
import fr.chteufleur.mytrackingdog.models.beans.WayPointLocation;
|
import fr.chteufleur.mytrackingdog.models.beans.WayPointLocation;
|
||||||
|
|
||||||
public class ServiceTrackingDog implements Observer {
|
public class ServiceTrackingDog implements Observer {
|
||||||
|
|
||||||
|
private enum LocationProvider {
|
||||||
|
GPS,
|
||||||
|
XMPP
|
||||||
|
}
|
||||||
|
|
||||||
//<editor-fold defaultstate="collapsed" desc="Preferences">
|
//<editor-fold defaultstate="collapsed" desc="Preferences">
|
||||||
private final SharedPreferences preferences;
|
private final SharedPreferences preferences;
|
||||||
private static final String PREF_VIBRATION_NEAR_OBJECT_ENABLED = "PREF_VIBRATION_NEAR_OBJECT_ENABLED";
|
private static final String PREF_VIBRATION_NEAR_OBJECT_ENABLED = "PREF_VIBRATION_NEAR_OBJECT_ENABLED";
|
||||||
|
|
@ -31,8 +48,13 @@ public class ServiceTrackingDog implements Observer {
|
||||||
|
|
||||||
private final ServiceGps serviceGps;
|
private final ServiceGps serviceGps;
|
||||||
private final ServiceXmpp serviceXmpp;
|
private final ServiceXmpp serviceXmpp;
|
||||||
|
private final Traces traces = new Traces();
|
||||||
|
|
||||||
private String appName = "";
|
private String appName = "";
|
||||||
|
|
||||||
|
private LocationProvider currentLocationProvider = LocationProvider.GPS;
|
||||||
|
private MyLocation currentLocation = null;
|
||||||
|
|
||||||
|
|
||||||
public ServiceTrackingDog(Vibrator vibrator, SharedPreferences preferences, Resources resources) {
|
public ServiceTrackingDog(Vibrator vibrator, SharedPreferences preferences, Resources resources) {
|
||||||
this.vibrator = vibrator;
|
this.vibrator = vibrator;
|
||||||
|
|
@ -56,7 +78,6 @@ public class ServiceTrackingDog implements Observer {
|
||||||
|
|
||||||
public void setAppName(String appName) {
|
public void setAppName(String appName) {
|
||||||
this.appName = appName;
|
this.appName = appName;
|
||||||
serviceGps.setAppName(appName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addObserver(Observer observer, String name) {
|
public void addObserver(Observer observer, String name) {
|
||||||
|
|
@ -74,25 +95,137 @@ public class ServiceTrackingDog implements Observer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//<editor-fold defaultstate="collapsed" desc="Location management">
|
||||||
|
public MyLocation getCurrentLocation() {
|
||||||
|
return currentLocation;
|
||||||
|
}
|
||||||
|
public float getOrientation(int deviceOrientation) {
|
||||||
|
float ret = -1;
|
||||||
|
if (currentLocation != null && currentLocation.getSpeed() >= 0.01) {
|
||||||
|
ret = (360 - currentLocation.getBearing() - deviceOrientation);
|
||||||
|
if (ret < 0) {
|
||||||
|
ret += 360;
|
||||||
|
}
|
||||||
|
if (ret > 360) {
|
||||||
|
ret -= 360;
|
||||||
|
}
|
||||||
|
//help smooth everything out
|
||||||
|
ret = (int) ret;
|
||||||
|
ret = ret / 5;
|
||||||
|
ret = (int) ret;
|
||||||
|
ret = ret * 5;
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
//</editor-fold>
|
||||||
|
|
||||||
|
//<editor-fold defaultstate="collapsed" desc="Trace management">
|
||||||
|
//<editor-fold defaultstate="collapsed" desc="Trace activation">
|
||||||
|
public void toggleTraceurActivation() {
|
||||||
|
traces.toggleTraceurActivation();
|
||||||
|
if (!isTraceurActivated()) {
|
||||||
|
exportTrailTraceToGpx();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public boolean isTraceurActivated() {
|
||||||
|
return traces.isTraceurActivated();
|
||||||
|
}
|
||||||
|
public void toggleDogActivation() {
|
||||||
|
traces.toggleDogActivation();
|
||||||
|
if (!isDogActivated()) {
|
||||||
|
exportDogTraceToGpx();
|
||||||
|
} else {
|
||||||
|
currentLocationProvider = LocationProvider.GPS;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public boolean isDogActivated() {
|
||||||
|
return traces.isDogActivated();
|
||||||
|
}
|
||||||
|
//</editor-fold>
|
||||||
|
//<editor-fold defaultstate="collapsed" desc="Objects">
|
||||||
|
public WayPointLocation addPointObjectTrail() {
|
||||||
|
return addPointObjectTrail(currentLocation);
|
||||||
|
}
|
||||||
|
public WayPointLocation addPointObjectTrail(MyLocation location) {
|
||||||
|
WayPointLocation wpl = null;
|
||||||
|
if (location != null) {
|
||||||
|
wpl = new WayPointLocation(location);
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MyLocationArray getListGeoPointObjectsTrail() {
|
||||||
|
return traces.getListPointObjectsTrail();
|
||||||
|
}
|
||||||
|
public MyLocationArray getListGeoPointObjectsDog() {
|
||||||
|
return traces.getListPointObjectsDog();
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<WayPointLocation> foundNearObjects(int distance) {
|
||||||
|
List<WayPointLocation> ret = new ArrayList<>();
|
||||||
|
MyLocation curLoc = currentLocation;
|
||||||
|
for (MyLocation ml: getListGeoPointObjectsTrail()) {
|
||||||
|
if (curLoc.distanceTo(ml) < distance && ml instanceof WayPointLocation) {
|
||||||
|
ret.add((WayPointLocation) ml);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
public boolean isNearObjects() {
|
||||||
|
return !foundNearObjects(20).isEmpty();
|
||||||
|
}
|
||||||
|
public List<WayPointLocation> foundNearObjects() {
|
||||||
|
return foundNearObjects(10);
|
||||||
|
}
|
||||||
|
//</editor-fold>
|
||||||
|
//<editor-fold defaultstate="collapsed" desc="Traces">
|
||||||
|
public void addPoint(MyLocation location) {
|
||||||
|
traces.addCurrentPoint(location);
|
||||||
|
}
|
||||||
|
public MyLocationArray getListGeoPointTraceur() {
|
||||||
|
return traces.getListPointTraceur();
|
||||||
|
}
|
||||||
|
public MyLocationArray getListGeoPointDog() {
|
||||||
|
return traces.getListPointDog();
|
||||||
|
}
|
||||||
|
public WayPointLocation getPointTrail(double lat, double lon) {
|
||||||
|
return traces.getPointObjectTrail(lat, lon);
|
||||||
|
}
|
||||||
|
public WayPointLocation getPointDog(double lat, double lon) {
|
||||||
|
return traces.getPointObjectDog(lat, lon);
|
||||||
|
}
|
||||||
|
//</editor-fold>
|
||||||
|
//</editor-fold>
|
||||||
|
|
||||||
//<editor-fold defaultstate="collapsed" desc="Observer Callback">
|
//<editor-fold defaultstate="collapsed" desc="Observer Callback">
|
||||||
@Override
|
@Override
|
||||||
public void update(Observable observable, Object o) {
|
public void update(Observable observable, Object o) {
|
||||||
if (observable == serviceGps) {
|
if (observable == serviceGps) {
|
||||||
updateGps(o);
|
updateGps((Notification) o);
|
||||||
} else if (observable == serviceXmpp) {
|
} else if (observable == serviceXmpp) {
|
||||||
updateXmpp(o);
|
updateXmpp((Notification) o);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateGps(Object o) {
|
public void updateGps(Notification notification) {
|
||||||
if (o != null && o instanceof String) {
|
if (notification.isAction(ServiceGps.NOTIF_NEW_LOCATION)) {
|
||||||
String action = (String) o;
|
if (currentLocationProvider == LocationProvider.GPS) {
|
||||||
if (action.equals(ServiceGps.NOTIF_NEW_LOCATION)) {
|
MyLocation location = new MyLocation((Location) notification.getExtra(ServiceGps.NOTIF_NEW_LOCATION_VALUE_LOCATION));
|
||||||
MyLocation loc = onNewLocation();
|
onNewLocation(location);
|
||||||
shouldVibrate();
|
shouldVibrate();
|
||||||
if (serviceXmpp != null && loc != null) {
|
if (serviceXmpp != null && location != null) {
|
||||||
try {
|
try {
|
||||||
serviceXmpp.sendCommandLocationTrail(loc.getLatitude(), loc.getLongitude(), loc.getTime());
|
serviceXmpp.sendCommandLocationTrail(location.getLatitude(), location.getLongitude(), location.getTime());
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -100,22 +233,25 @@ public class ServiceTrackingDog implements Observer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateXmpp(Object o) {
|
public void updateXmpp(Notification notification) {
|
||||||
if (o != null && o instanceof String) {
|
if (notification.isAction(ServiceXmpp.NOTIF_NEW_LOCATION)) {
|
||||||
String action = (String) o;
|
if (currentLocationProvider == LocationProvider.XMPP) {
|
||||||
if (o.equals(ServiceXmpp.NOTIF_NEW_LOCATION)) {
|
MyLocation location = (MyLocation) notification.getExtra(ServiceXmpp.NOTIF_NEW_LOCATION_VALUE_LOCATION);
|
||||||
onNewLocation();
|
onNewLocation(location);
|
||||||
// } else if (o.equals(ServiceXmpp.NOTIF_NEW_OBJECT)) {
|
|
||||||
// } else if (o.equals(ServiceXmpp.NOTIF_START_TRAIL)) {
|
|
||||||
// } else if (o.equals(ServiceXmpp.NOTIF_STOP_TRAIL)) {
|
|
||||||
}
|
}
|
||||||
|
// } else if (notification.isAction(ServiceXmpp.NOTIF_NEW_OBJECT)) {
|
||||||
|
} else if (notification.isAction(ServiceXmpp.NOTIF_START_TRAIL)) {
|
||||||
|
currentLocationProvider = LocationProvider.XMPP;
|
||||||
|
} else if (notification.isAction(ServiceXmpp.NOTIF_STOP_TRAIL)) {
|
||||||
|
currentLocationProvider = LocationProvider.GPS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public MyLocation onNewLocation() {
|
public void onNewLocation(MyLocation location) {
|
||||||
MyLocation loc = serviceGps.getCurrentLocation();
|
if (location != null) {
|
||||||
serviceGps.addPoint(loc);
|
currentLocation = location;
|
||||||
return loc;
|
addPoint(currentLocation);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
//</editor-fold>
|
//</editor-fold>
|
||||||
|
|
||||||
|
|
@ -151,8 +287,8 @@ public class ServiceTrackingDog implements Observer {
|
||||||
|
|
||||||
private void shouldVibrate() {
|
private void shouldVibrate() {
|
||||||
// Near object vibration check
|
// Near object vibration check
|
||||||
if (serviceGps.isDogActivated()) {
|
if (isDogActivated()) {
|
||||||
if (vibrationNearObjectEnabled && serviceGps.isNearObjects()) {
|
if (vibrationNearObjectEnabled && isNearObjects()) {
|
||||||
if (!nearObjectVibration) {
|
if (!nearObjectVibration) {
|
||||||
nearObjectVibration = true;
|
nearObjectVibration = true;
|
||||||
vibrate(TIME_VIBRATION_NEAR_OBJECT_MS);
|
vibrate(TIME_VIBRATION_NEAR_OBJECT_MS);
|
||||||
|
|
@ -171,78 +307,6 @@ public class ServiceTrackingDog implements Observer {
|
||||||
public void startLocation() {
|
public void startLocation() {
|
||||||
serviceGps.start();
|
serviceGps.start();
|
||||||
}
|
}
|
||||||
public File getLastExportedTrailFile() {
|
|
||||||
return serviceGps.getLastExportedTrailFile();
|
|
||||||
}
|
|
||||||
public MyLocation getCurrentLocation() {
|
|
||||||
return serviceGps.getCurrentLocation();
|
|
||||||
}
|
|
||||||
public void importGpxTrace(File file) {
|
|
||||||
serviceGps.importGpxTrace(file);
|
|
||||||
}
|
|
||||||
public float getOrientation(int deviceOrientation) {
|
|
||||||
return serviceGps.getOrientation(deviceOrientation);
|
|
||||||
}
|
|
||||||
//<editor-fold defaultstate="collapsed" desc="Trace activation">
|
|
||||||
public void toggleTraceurActivation() {
|
|
||||||
serviceGps.toggleTraceurActivation();
|
|
||||||
}
|
|
||||||
public boolean isTraceurActivated() {
|
|
||||||
return serviceGps.isTraceurActivated();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void toggleDogActivation() {
|
|
||||||
serviceGps.toggleDogActivation();
|
|
||||||
}
|
|
||||||
public boolean isDogActivated() {
|
|
||||||
return serviceGps.isDogActivated();
|
|
||||||
}
|
|
||||||
//</editor-fold>
|
|
||||||
//<editor-fold defaultstate="collapsed" desc="Objects">
|
|
||||||
public WayPointLocation addPointObjectTrail() {
|
|
||||||
return serviceGps.addPointObjectTrail();
|
|
||||||
}
|
|
||||||
public WayPointLocation addPointObjectTrail(MyLocation location) {
|
|
||||||
return serviceGps.addPointObjectTrail(location);
|
|
||||||
}
|
|
||||||
public WayPointLocation addPointObjectDog() {
|
|
||||||
return serviceGps.addPointObjectDog();
|
|
||||||
}
|
|
||||||
|
|
||||||
public MyLocationArray getListGeoPointObjectsTrail() {
|
|
||||||
return serviceGps.getListGeoPointObjectsTrail();
|
|
||||||
}
|
|
||||||
public MyLocationArray getListGeoPointObjectsDog() {
|
|
||||||
return serviceGps.getListGeoPointObjectsDog();
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<WayPointLocation> foundNearObjects(int distance) {
|
|
||||||
return serviceGps.foundNearObjects(distance);
|
|
||||||
}
|
|
||||||
public boolean isNearObjects() {
|
|
||||||
return serviceGps.isNearObjects();
|
|
||||||
}
|
|
||||||
public List<WayPointLocation> foundNearObjects() {
|
|
||||||
return serviceGps.foundNearObjects();
|
|
||||||
}
|
|
||||||
//</editor-fold>
|
|
||||||
//<editor-fold defaultstate="collapsed" desc="Traces">
|
|
||||||
public void addPoint(MyLocation location) {
|
|
||||||
serviceGps.addPoint(location);
|
|
||||||
}
|
|
||||||
public MyLocationArray getListGeoPointTraceur() {
|
|
||||||
return serviceGps.getListGeoPointTraceur();
|
|
||||||
}
|
|
||||||
public MyLocationArray getListGeoPointDog() {
|
|
||||||
return serviceGps.getListGeoPointDog();
|
|
||||||
}
|
|
||||||
public WayPointLocation getPointTrail(double lat, double lon) {
|
|
||||||
return serviceGps.getPointTrail(lat, lon);
|
|
||||||
}
|
|
||||||
public WayPointLocation getPointDog(double lat, double lon) {
|
|
||||||
return serviceGps.getPointDog(lat, lon);
|
|
||||||
}
|
|
||||||
//</editor-fold>
|
|
||||||
//</editor-fold>
|
//</editor-fold>
|
||||||
|
|
||||||
//<editor-fold defaultstate="collapsed" desc="Service XMPP delegation">
|
//<editor-fold defaultstate="collapsed" desc="Service XMPP delegation">
|
||||||
|
|
@ -269,20 +333,6 @@ public class ServiceTrackingDog implements Observer {
|
||||||
serviceXmpp.sendPresenceAvailable();
|
serviceXmpp.sendPresenceAvailable();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public MyLocation getXmppCurrentLocation() {
|
|
||||||
MyLocation ret = null;
|
|
||||||
if (serviceXmpp != null) {
|
|
||||||
ret = serviceXmpp.getCurrentLocation();
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
public MyLocation getXmppLastObjectLocation() {
|
|
||||||
MyLocation ret = null;
|
|
||||||
if (serviceXmpp != null) {
|
|
||||||
ret = serviceXmpp.getLastObjectXmppLocation();
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
//<editor-fold defaultstate="collapsed" desc="Commands">
|
//<editor-fold defaultstate="collapsed" desc="Commands">
|
||||||
public void sendCommandStartTrail() throws XmppStringprepException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException, SmackException.NoResponseException {
|
public void sendCommandStartTrail() throws XmppStringprepException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException, SmackException.NoResponseException {
|
||||||
if (serviceXmpp != null) {
|
if (serviceXmpp != null) {
|
||||||
|
|
@ -306,4 +356,65 @@ public class ServiceTrackingDog implements Observer {
|
||||||
}
|
}
|
||||||
//</editor-fold>
|
//</editor-fold>
|
||||||
//</editor-fold>
|
//</editor-fold>
|
||||||
|
|
||||||
|
//<editor-fold defaultstate="collapsed" desc="Import/Export">
|
||||||
|
private File lastExportedTrailFile = null;
|
||||||
|
private String getFileName(String prefix) {
|
||||||
|
SimpleDateFormat formater = new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss");
|
||||||
|
String date = formater.format(new Date());
|
||||||
|
return Environment.getExternalStorageDirectory().getAbsolutePath() + "/"
|
||||||
|
+ appName + "/" + date + "_" + prefix
|
||||||
|
+ ".gpx";
|
||||||
|
}
|
||||||
|
|
||||||
|
public File getLastExportedTrailFile() {
|
||||||
|
return lastExportedTrailFile;
|
||||||
|
}
|
||||||
|
private boolean exportDogTraceToGpx() {
|
||||||
|
File file = new File(getFileName(Gpx.DOG_TRACE_NAME));
|
||||||
|
ExportGpx exportGpx = new ExportGpx(file, Gpx.DOG_TRACE_NAME);
|
||||||
|
exportGpx.setObjects(traces.getListPointObjectsDog());
|
||||||
|
exportGpx.setTrace(traces.getListPointDog());
|
||||||
|
return exportGpx.export();
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean exportTrailTraceToGpx() {
|
||||||
|
File file = new File(getFileName(Gpx.TRAIL_TRACE_NAME));
|
||||||
|
ExportGpx exportGpx = new ExportGpx(file, Gpx.TRAIL_TRACE_NAME);
|
||||||
|
exportGpx.setObjects(traces.getListPointObjectsTrail());
|
||||||
|
exportGpx.setTrace(traces.getListPointTraceur());
|
||||||
|
lastExportedTrailFile = file;
|
||||||
|
return exportGpx.export();
|
||||||
|
}
|
||||||
|
public void importGpxTrace(File file) {
|
||||||
|
ImportGpx importGpx = new ImportGpx(file);
|
||||||
|
try {
|
||||||
|
List<MyLocation> list = importGpx.parse();
|
||||||
|
String traceName = importGpx.getTraceName();
|
||||||
|
if (traceName.equals(Gpx.TRAIL_TRACE_NAME)) {
|
||||||
|
lastExportedTrailFile = file;
|
||||||
|
}
|
||||||
|
for (int i=0; i<list.size(); i++) {
|
||||||
|
MyLocation o = list.get(i);
|
||||||
|
if (o instanceof WayPointLocation) {
|
||||||
|
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);
|
||||||
|
} else if (traceName.equals(Gpx.TRAIL_TRACE_NAME)) {
|
||||||
|
traces.addPointTraceur((TraceLocation) o);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (XmlPullParserException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//</editor-fold>
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,7 @@ import java.net.UnknownHostException;
|
||||||
import java.util.Observable;
|
import java.util.Observable;
|
||||||
|
|
||||||
import fr.chteufleur.mytrackingdog.QRCodeGeneratorActivity;
|
import fr.chteufleur.mytrackingdog.QRCodeGeneratorActivity;
|
||||||
|
import fr.chteufleur.mytrackingdog.models.Notification;
|
||||||
import fr.chteufleur.mytrackingdog.models.beans.MyLocation;
|
import fr.chteufleur.mytrackingdog.models.beans.MyLocation;
|
||||||
import fr.chteufleur.mytrackingdog.models.xmpp.commands.ObjectGeolocCommand;
|
import fr.chteufleur.mytrackingdog.models.xmpp.commands.ObjectGeolocCommand;
|
||||||
import fr.chteufleur.mytrackingdog.models.xmpp.commands.StartTrailGeolocCommand;
|
import fr.chteufleur.mytrackingdog.models.xmpp.commands.StartTrailGeolocCommand;
|
||||||
|
|
@ -46,6 +47,8 @@ public class ServiceXmpp extends Observable implements PresenceEventListener {
|
||||||
public static final String NOTIF_NEW_OBJECT = ServiceXmpp.class.getName()+".newobject";
|
public static final String NOTIF_NEW_OBJECT = ServiceXmpp.class.getName()+".newobject";
|
||||||
public static final String NOTIF_START_TRAIL = ServiceXmpp.class.getName()+".starttrail";
|
public static final String NOTIF_START_TRAIL = ServiceXmpp.class.getName()+".starttrail";
|
||||||
public static final String NOTIF_STOP_TRAIL = ServiceXmpp.class.getName()+".stoptrail";
|
public static final String NOTIF_STOP_TRAIL = ServiceXmpp.class.getName()+".stoptrail";
|
||||||
|
public static final String NOTIF_NEW_OBJECT_VALUE_LOCATION = NOTIF_NEW_OBJECT+".value.location";
|
||||||
|
public static final String NOTIF_NEW_LOCATION_VALUE_LOCATION = NOTIF_NEW_LOCATION+".value.location";
|
||||||
|
|
||||||
private static final String XMPP_NODE_TRAIL_GEOLOC = "trail_geoloc";
|
private static final String XMPP_NODE_TRAIL_GEOLOC = "trail_geoloc";
|
||||||
private static final String XMPP_NODE_OBJECT_GEOLOC = "object_geoloc";
|
private static final String XMPP_NODE_OBJECT_GEOLOC = "object_geoloc";
|
||||||
|
|
@ -202,8 +205,6 @@ public class ServiceXmpp extends Observable implements PresenceEventListener {
|
||||||
//</editor-fold>
|
//</editor-fold>
|
||||||
|
|
||||||
//<editor-fold defaultstate="collapsed" desc="Commands">
|
//<editor-fold defaultstate="collapsed" desc="Commands">
|
||||||
private MyLocation currentXmppLocation = null;
|
|
||||||
private MyLocation lastObjectXmppLocation = null;
|
|
||||||
private void registerCommands() {
|
private void registerCommands() {
|
||||||
commandManager.registerCommand(XMPP_NODE_TRAIL_GEOLOC, XMPP_NODE_TRAIL_GEOLOC, new LocalCommandFactory() {
|
commandManager.registerCommand(XMPP_NODE_TRAIL_GEOLOC, XMPP_NODE_TRAIL_GEOLOC, new LocalCommandFactory() {
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -234,35 +235,27 @@ public class ServiceXmpp extends Observable implements PresenceEventListener {
|
||||||
public void startTrailGeoloc() {
|
public void startTrailGeoloc() {
|
||||||
Log.i(TAG, "Start trail");
|
Log.i(TAG, "Start trail");
|
||||||
setChanged();
|
setChanged();
|
||||||
notifyObservers(NOTIF_START_TRAIL);
|
notifyObservers(new Notification(NOTIF_START_TRAIL));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stopTrailGeoloc() {
|
public void stopTrailGeoloc() {
|
||||||
Log.i(TAG, "Stop trail");
|
Log.i(TAG, "Stop trail");
|
||||||
setChanged();
|
setChanged();
|
||||||
notifyObservers(NOTIF_STOP_TRAIL);
|
notifyObservers(new Notification(NOTIF_STOP_TRAIL));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addTrailGeoloc(double lat, double lon, long time) {
|
public void addTrailGeoloc(double lat, double lon, long time) {
|
||||||
Log.i(TAG, "Add location");
|
Log.i(TAG, "Add location");
|
||||||
currentXmppLocation = new MyLocation(lat, lon, time);
|
MyLocation location = new MyLocation(lat, lon, time);
|
||||||
setChanged();
|
setChanged();
|
||||||
notifyObservers(NOTIF_NEW_LOCATION);
|
notifyObservers(new Notification(NOTIF_NEW_LOCATION).addExtra(NOTIF_NEW_LOCATION_VALUE_LOCATION, location));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addObjectGeoloc(double lat, double lon, long time) {
|
public void addObjectGeoloc(double lat, double lon, long time) {
|
||||||
Log.i(TAG, "Add object");
|
Log.i(TAG, "Add object");
|
||||||
lastObjectXmppLocation = new MyLocation(lat, lon, time);
|
MyLocation objectLocation = new MyLocation(lat, lon, time);
|
||||||
setChanged();
|
setChanged();
|
||||||
notifyObservers(NOTIF_NEW_OBJECT);
|
notifyObservers(new Notification(NOTIF_NEW_OBJECT).addExtra(NOTIF_NEW_OBJECT_VALUE_LOCATION, objectLocation));
|
||||||
}
|
|
||||||
|
|
||||||
public MyLocation getCurrentLocation() {
|
|
||||||
return currentXmppLocation;
|
|
||||||
}
|
|
||||||
|
|
||||||
public MyLocation getLastObjectXmppLocation() {
|
|
||||||
return lastObjectXmppLocation;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendCommandStartTrail() throws XmppStringprepException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException, SmackException.NoResponseException {
|
public void sendCommandStartTrail() throws XmppStringprepException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException, SmackException.NoResponseException {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue