Change location beans class.
This commit is contained in:
parent
95ad89a181
commit
e883f7eeba
|
|
@ -6,7 +6,6 @@ import android.content.pm.ActivityInfo;
|
|||
import android.content.pm.PackageManager;
|
||||
import android.graphics.Color;
|
||||
import android.hardware.GeomagneticField;
|
||||
import android.location.Location;
|
||||
import android.location.LocationManager;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
|
|
@ -39,9 +38,12 @@ import org.osmdroid.views.overlay.infowindow.BasicInfoWindow;
|
|||
import org.osmdroid.views.overlay.mylocation.GpsMyLocationProvider;
|
||||
import org.osmdroid.views.overlay.mylocation.MyLocationNewOverlay;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Observable;
|
||||
import java.util.Observer;
|
||||
|
||||
import fr.chteufleur.mytrackingdog.models.beans.MyLocation;
|
||||
import fr.chteufleur.mytrackingdog.services.ServiceGps;
|
||||
|
||||
public class MainActivity extends AppCompatActivity implements IOrientationConsumer, Observer {
|
||||
|
|
@ -180,7 +182,8 @@ public class MainActivity extends AppCompatActivity implements IOrientationConsu
|
|||
|
||||
|
||||
private void addMarker() {
|
||||
GeoPoint gp = serviceGps.addPointObject();
|
||||
MyLocation loc = serviceGps.addPointObject();
|
||||
GeoPoint gp = new GeoPoint(loc.getLatitude(), loc.getLongitude(), loc.getAltitude());
|
||||
Marker marker = new Marker(map);
|
||||
marker.setPosition(gp);
|
||||
marker.setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_BOTTOM);
|
||||
|
|
@ -311,7 +314,7 @@ public class MainActivity extends AppCompatActivity implements IOrientationConsu
|
|||
@Override
|
||||
public void onOrientationChanged(float orientationToMagneticNorth, IOrientationProvider source) {
|
||||
//note, on devices without a compass this never fires...
|
||||
Location location = serviceGps.getCurrentLocation();
|
||||
MyLocation location = serviceGps.getCurrentLocation();
|
||||
if (location == null) {
|
||||
return ;
|
||||
}
|
||||
|
|
@ -370,7 +373,7 @@ public class MainActivity extends AppCompatActivity implements IOrientationConsu
|
|||
line = new Polyline(map);
|
||||
line.setTitle("Traceur");
|
||||
line.setColor(Color.RED);
|
||||
line.setPoints(serviceGps.getListGeoPointTraceur());
|
||||
line.setPoints(convertListLocation(serviceGps.getListGeoPointTraceur()));
|
||||
|
||||
} else if (serviceGps.isDogActivated()) {
|
||||
Log.i(TAG, "polyline dog");
|
||||
|
|
@ -379,7 +382,7 @@ public class MainActivity extends AppCompatActivity implements IOrientationConsu
|
|||
line = new Polyline(map);
|
||||
line.setTitle("Dog");
|
||||
line.setColor(Color.BLUE);
|
||||
line.setPoints(serviceGps.getListGeoPointDog());
|
||||
line.setPoints(convertListLocation(serviceGps.getListGeoPointDog()));
|
||||
}
|
||||
|
||||
if (line != null) {
|
||||
|
|
@ -397,4 +400,14 @@ public class MainActivity extends AppCompatActivity implements IOrientationConsu
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
private List<GeoPoint> convertListLocation(List<MyLocation> list) {
|
||||
List<GeoPoint> ret = new ArrayList<>();
|
||||
if (list != null) {
|
||||
for (MyLocation loc : list) {
|
||||
ret.add(new GeoPoint(loc.getLatitude(), loc.getLongitude(), loc.getAltitude()));
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,50 +2,50 @@ package fr.chteufleur.mytrackingdog.models;
|
|||
|
||||
import android.util.Log;
|
||||
|
||||
import org.osmdroid.util.GeoPoint;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import fr.chteufleur.mytrackingdog.models.beans.MyLocation;
|
||||
|
||||
public class Traces {
|
||||
|
||||
private static final String TAG = Traces.class.getName();
|
||||
|
||||
private List<GeoPoint> lGeoPointTraceur = new ArrayList<>();
|
||||
private List<GeoPoint> lGeoPointDog = new ArrayList<>();
|
||||
private List<GeoPoint> lGeoPointObjects = new ArrayList<>();
|
||||
private List<MyLocation> listPointTraceur = new ArrayList<>();
|
||||
private List<MyLocation> listPointDog = new ArrayList<>();
|
||||
private List<MyLocation> listPointObjects = new ArrayList<>();
|
||||
|
||||
private boolean traceurActivated = false;
|
||||
private boolean dogActivated = false;
|
||||
|
||||
|
||||
public void addPointTraceur(GeoPoint point) {
|
||||
public void addPointTraceur(MyLocation point) {
|
||||
Log.i(TAG, "add point traceur");
|
||||
lGeoPointTraceur.add(point);
|
||||
listPointTraceur.add(point);
|
||||
}
|
||||
public void addPointDog(GeoPoint point) {
|
||||
public void addPointDog(MyLocation point) {
|
||||
Log.i(TAG, "add point dog");
|
||||
lGeoPointDog.add(point);
|
||||
listPointDog.add(point);
|
||||
}
|
||||
public void addPointObject(GeoPoint point) {
|
||||
public void addPointObject(MyLocation point) {
|
||||
Log.i(TAG, "add point object");
|
||||
lGeoPointObjects.add(point);
|
||||
listPointObjects.add(point);
|
||||
}
|
||||
public void addCurrentPoint(GeoPoint point) {
|
||||
public void addCurrentPoint(MyLocation point) {
|
||||
if (traceurActivated) {
|
||||
addPointTraceur(point);
|
||||
} else if (dogActivated) {
|
||||
addPointDog(point);
|
||||
}
|
||||
}
|
||||
public List<GeoPoint> getListGeoPointTraceur() {
|
||||
return lGeoPointTraceur;
|
||||
public List<MyLocation> getListPointTraceur() {
|
||||
return listPointTraceur;
|
||||
}
|
||||
public List<GeoPoint> getListGeoPointDog() {
|
||||
return lGeoPointDog;
|
||||
public List<MyLocation> getListPointDog() {
|
||||
return listPointDog;
|
||||
}
|
||||
public List<GeoPoint> getListGeoPointObjects() {
|
||||
return lGeoPointObjects;
|
||||
public List<MyLocation> getListPointObjects() {
|
||||
return listPointObjects;
|
||||
}
|
||||
|
||||
public void toggleTraceurActivation() {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,10 @@
|
|||
package fr.chteufleur.mytrackingdog.models.beans;
|
||||
|
||||
import android.location.Location;
|
||||
|
||||
public class MyLocation extends Location {
|
||||
|
||||
public MyLocation(Location l) {
|
||||
super(l);
|
||||
}
|
||||
}
|
||||
|
|
@ -12,6 +12,7 @@ import java.util.List;
|
|||
import java.util.Observable;
|
||||
|
||||
import fr.chteufleur.mytrackingdog.models.Traces;
|
||||
import fr.chteufleur.mytrackingdog.models.beans.MyLocation;
|
||||
|
||||
public class ServiceGps extends Observable implements IServiceGps, LocationListener {
|
||||
|
||||
|
|
@ -19,7 +20,7 @@ public class ServiceGps extends Observable implements IServiceGps, LocationListe
|
|||
public static final String NOTIF_NEW_LOCATION = "fr.chteufleur.mytrackingdog.services.servicegps.newlocation";
|
||||
|
||||
private LocationManager locationManager;
|
||||
private Location currentLocation = null;
|
||||
private MyLocation currentLocation = null;
|
||||
|
||||
private final Traces traces = new Traces();
|
||||
|
||||
|
|
@ -27,7 +28,7 @@ public class ServiceGps extends Observable implements IServiceGps, LocationListe
|
|||
this.locationManager = locationManager;
|
||||
}
|
||||
|
||||
public Location getCurrentLocation() {
|
||||
public MyLocation getCurrentLocation() {
|
||||
return currentLocation;
|
||||
}
|
||||
|
||||
|
|
@ -67,8 +68,8 @@ public class ServiceGps extends Observable implements IServiceGps, LocationListe
|
|||
|
||||
@Override
|
||||
public void onLocationChanged(Location location) {
|
||||
currentLocation = location;
|
||||
traces.addCurrentPoint(getCurrentGeoPoint());
|
||||
currentLocation = new MyLocation(location);
|
||||
traces.addCurrentPoint(currentLocation);
|
||||
setChanged();
|
||||
notifyObservers(NOTIF_NEW_LOCATION);
|
||||
}
|
||||
|
|
@ -109,19 +110,20 @@ public class ServiceGps extends Observable implements IServiceGps, LocationListe
|
|||
return traces.isDogActivated();
|
||||
}
|
||||
|
||||
public GeoPoint addPointObject() {
|
||||
GeoPoint point = getCurrentGeoPoint();
|
||||
traces.addPointObject(point);
|
||||
return point;
|
||||
public MyLocation addPointObject() {
|
||||
if (currentLocation != null) {
|
||||
traces.addPointObject(currentLocation);
|
||||
}
|
||||
return currentLocation;
|
||||
}
|
||||
|
||||
public List<GeoPoint> getListGeoPointTraceur() {
|
||||
return traces.getListGeoPointTraceur();
|
||||
public List<MyLocation> getListGeoPointTraceur() {
|
||||
return traces.getListPointTraceur();
|
||||
}
|
||||
public List<GeoPoint> getListGeoPointDog() {
|
||||
return traces.getListGeoPointDog();
|
||||
public List<MyLocation> getListGeoPointDog() {
|
||||
return traces.getListPointDog();
|
||||
}
|
||||
public List<GeoPoint> getListGeoPointObjects() {
|
||||
return traces.getListGeoPointObjects();
|
||||
public List<MyLocation> getListGeoPointObjects() {
|
||||
return traces.getListPointObjects();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue