Cleanning code.
This commit is contained in:
parent
0176f37d01
commit
d253dbd765
|
|
@ -1,6 +1,7 @@
|
|||
package fr.chteufleur.mytrackingdog;
|
||||
|
||||
import android.Manifest;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ActivityInfo;
|
||||
|
|
@ -132,6 +133,7 @@ public class MainActivity extends AppCompatActivity implements IOrientationConsu
|
|||
map.setBuiltInZoomControls(false);
|
||||
map.setMultiTouchControls(true);
|
||||
map.setOnTouchListener(new View.OnTouchListener() {
|
||||
@SuppressLint("ClickableViewAccessibility")
|
||||
@Override
|
||||
public boolean onTouch(View view, MotionEvent motionEvent) {
|
||||
map.onTouchEvent(motionEvent);
|
||||
|
|
@ -169,15 +171,6 @@ public class MainActivity extends AppCompatActivity implements IOrientationConsu
|
|||
@Override
|
||||
public void onClick(View view) {
|
||||
changeStatusTrace();
|
||||
try {
|
||||
if (serviceTrackingDog.isTraceurActivated()) {
|
||||
serviceTrackingDog.sendCommandStartTrail();
|
||||
} else {
|
||||
serviceTrackingDog.sendCommandStopTrail();
|
||||
}
|
||||
} catch (XmppStringprepException | InterruptedException | SmackException.NoResponseException | SmackException.NotConnectedException | XMPPException.XMPPErrorException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
start_stop_dog_trace = findViewById(R.id.start_stop_dog_trace);
|
||||
|
|
@ -197,11 +190,6 @@ public class MainActivity extends AppCompatActivity implements IOrientationConsu
|
|||
if (loc != null) {
|
||||
GeoPoint gp = new GeoPoint(loc.getLatitude(), loc.getLongitude(), loc.getAltitude());
|
||||
addMarker(gp, loc.isFound());
|
||||
try {
|
||||
serviceTrackingDog.sendCommandObjectTrail(loc.getLatitude(), loc.getLongitude(), loc.getTime());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
} else if (serviceTrackingDog.isDogActivated()) {
|
||||
markAsFound();
|
||||
|
|
@ -398,7 +386,13 @@ public class MainActivity extends AppCompatActivity implements IOrientationConsu
|
|||
serviceTrackingDog.importGpxTrace(new File(data.getStringExtra(FilePicker.EXTRA_FILE_PATH)));
|
||||
updateDogTrace();
|
||||
updateTrailTrace();
|
||||
calculTrailDistance();
|
||||
|
||||
// Update distance
|
||||
distance = serviceTrackingDog.calculTrailDistance();
|
||||
if (distance != 0) {
|
||||
updateDistance();
|
||||
}
|
||||
|
||||
for (MyLocation loc: serviceTrackingDog.getListGeoPointObjectsTrail()) {
|
||||
addMarker(new GeoPoint(loc.getLatitude(), loc.getLongitude(), loc.getAltitude()), false);
|
||||
}
|
||||
|
|
@ -410,9 +404,9 @@ public class MainActivity extends AppCompatActivity implements IOrientationConsu
|
|||
addMarker(new GeoPoint(loc.getLatitude(), loc.getLongitude(), loc.getAltitude()), isFound);
|
||||
}
|
||||
if (!serviceTrackingDog.getListGeoPointTraceur().isEmpty()) {
|
||||
updateDistance(getTextTraceur());
|
||||
updatePlaceholder(getTextTraceur());
|
||||
} else if (!serviceTrackingDog.getListGeoPointDog().isEmpty()) {
|
||||
updateDistance(getTextDog());
|
||||
updatePlaceholder(getTextDog());
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
|
@ -567,28 +561,13 @@ public class MainActivity extends AppCompatActivity implements IOrientationConsu
|
|||
}
|
||||
}
|
||||
if (wpls.isEmpty() || !findMarker) {
|
||||
// if no object is near
|
||||
// if no object is near -> add new found object
|
||||
WayPointLocation wpl = serviceTrackingDog.addPointObjectDog();
|
||||
GeoPoint gp = new GeoPoint(wpl.getLatitude(), wpl.getLongitude(), wpl.getAltitude());
|
||||
addMarker(gp, true);
|
||||
}
|
||||
}
|
||||
|
||||
private void calculTrailDistance() {
|
||||
List<MyLocation> listLoc = serviceTrackingDog.getListGeoPointTraceur();
|
||||
MyLocation last = null;
|
||||
distance = 0;
|
||||
for (MyLocation loc: listLoc) {
|
||||
if (last != null) {
|
||||
distance += loc.distanceTo(last);
|
||||
}
|
||||
last = loc;
|
||||
}
|
||||
if (distance != 0) {
|
||||
updateDistance();
|
||||
}
|
||||
}
|
||||
|
||||
private void updateDogTrace() {
|
||||
MyLocationArray listLoc = serviceTrackingDog.getListGeoPointDog();
|
||||
if (listLoc.isEmpty()) {
|
||||
|
|
@ -661,21 +640,20 @@ public class MainActivity extends AppCompatActivity implements IOrientationConsu
|
|||
MyLocation loc = (MyLocation) notification.getExtra(ServiceXmpp.NOTIF_NEW_LOCATION_VALUE_LOCATION);
|
||||
onNewLocation(loc);
|
||||
}
|
||||
} else if (notification.isAction(ServiceXmpp.NOTIF_NEW_OBJECT)){
|
||||
} 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());
|
||||
GeoPoint gp = new GeoPoint(locObj.getLatitude(), locObj.getLongitude(), locObj.getAltitude());
|
||||
addMarker(gp, false);
|
||||
}
|
||||
} else if (notification.isAction(ServiceXmpp.NOTIF_START_TRAIL)){
|
||||
} else if (notification.isAction(ServiceXmpp.NOTIF_START_TRAIL)) {
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
changeStatusTrace();
|
||||
}
|
||||
});
|
||||
} else if (notification.isAction(ServiceXmpp.NOTIF_STOP_TRAIL)){
|
||||
} else if (notification.isAction(ServiceXmpp.NOTIF_STOP_TRAIL)) {
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
|
@ -719,7 +697,7 @@ public class MainActivity extends AppCompatActivity implements IOrientationConsu
|
|||
|
||||
if (!zoomed) {
|
||||
IMapController mapController = map.getController();
|
||||
mapController.setZoom(20.0);
|
||||
mapController.setZoom(19.0);
|
||||
zoomed = true;
|
||||
}
|
||||
}
|
||||
|
|
@ -736,7 +714,7 @@ public class MainActivity extends AppCompatActivity implements IOrientationConsu
|
|||
} else if (serviceTrackingDog.isDogActivated()) {
|
||||
text = getTextDog();
|
||||
}
|
||||
updateDistance(text);
|
||||
updatePlaceholder(text);
|
||||
}
|
||||
|
||||
private String getTextTraceur() {
|
||||
|
|
@ -768,7 +746,7 @@ public class MainActivity extends AppCompatActivity implements IOrientationConsu
|
|||
return text;
|
||||
}
|
||||
|
||||
private void updateDistance(String text) {
|
||||
private void updatePlaceholder(String text) {
|
||||
if (text != null) {
|
||||
this.textViewCurrentLocation.setText(text);
|
||||
this.textViewCurrentLocation.setVisibility(View.VISIBLE);
|
||||
|
|
|
|||
|
|
@ -10,10 +10,10 @@ public class Traces {
|
|||
|
||||
private static final String TAG = Traces.class.getName();
|
||||
|
||||
private MyLocationArray listPointTraceur = new MyLocationArray();
|
||||
private MyLocationArray listPointDog = new MyLocationArray();
|
||||
private MyLocationArray listPointObjectsTrail = new MyLocationArray();
|
||||
private MyLocationArray listPointObjectsDog = new MyLocationArray();
|
||||
private final MyLocationArray listPointTraceur = new MyLocationArray();
|
||||
private final MyLocationArray listPointDog = new MyLocationArray();
|
||||
private final MyLocationArray listPointObjectsTrail = new MyLocationArray();
|
||||
private final MyLocationArray listPointObjectsDog = new MyLocationArray();
|
||||
|
||||
private boolean traceurActivated = false;
|
||||
private boolean dogActivated = false;
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ public class ServiceTrackingDog implements Observer {
|
|||
|
||||
this.serviceGps = new ServiceGps();
|
||||
this.serviceGps.addObserver(this);
|
||||
ServiceXmpp sx = null;
|
||||
ServiceXmpp sx;
|
||||
try {
|
||||
sx = new ServiceXmpp(resources);
|
||||
sx.addObserver(this);
|
||||
|
|
@ -117,6 +117,9 @@ public class ServiceTrackingDog implements Observer {
|
|||
}
|
||||
return ret;
|
||||
}
|
||||
public LocationProvider getCurrentLocationProvider() {
|
||||
return currentLocationProvider;
|
||||
}
|
||||
//</editor-fold>
|
||||
|
||||
//<editor-fold defaultstate="collapsed" desc="Trace management">
|
||||
|
|
@ -125,6 +128,17 @@ public class ServiceTrackingDog implements Observer {
|
|||
traces.toggleTraceurActivation();
|
||||
if (!isTraceurActivated()) {
|
||||
exportTrailTraceToGpx();
|
||||
try {
|
||||
sendXmppCommandStopTrail();
|
||||
} catch (XmppStringprepException | XMPPException.XMPPErrorException | SmackException.NotConnectedException | InterruptedException | SmackException.NoResponseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
try {
|
||||
sendXmppCommandStartTrail();
|
||||
} catch (XmppStringprepException | XMPPException.XMPPErrorException | SmackException.NotConnectedException | InterruptedException | SmackException.NoResponseException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
public boolean isTraceurActivated() {
|
||||
|
|
@ -144,9 +158,14 @@ public class ServiceTrackingDog implements Observer {
|
|||
//</editor-fold>
|
||||
//<editor-fold defaultstate="collapsed" desc="Objects">
|
||||
public WayPointLocation addPointObjectTrail() {
|
||||
try {
|
||||
sendXmppCommandObjectTrail(currentLocation.getLatitude(), currentLocation.getLongitude(), currentLocation.getTime());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return addPointObjectTrail(currentLocation);
|
||||
}
|
||||
public WayPointLocation addPointObjectTrail(MyLocation location) {
|
||||
private WayPointLocation addPointObjectTrail(MyLocation location) {
|
||||
WayPointLocation wpl = null;
|
||||
if (location != null) {
|
||||
wpl = new WayPointLocation(location);
|
||||
|
|
@ -204,6 +223,18 @@ public class ServiceTrackingDog implements Observer {
|
|||
public WayPointLocation getPointDog(double lat, double lon) {
|
||||
return traces.getPointObjectDog(lat, lon);
|
||||
}
|
||||
public float calculTrailDistance() {
|
||||
List<MyLocation> listLoc = getListGeoPointTraceur();
|
||||
MyLocation last = null;
|
||||
float distance = 0;
|
||||
for (MyLocation loc: getListGeoPointTraceur()) {
|
||||
if (last != null) {
|
||||
distance += loc.distanceTo(last);
|
||||
}
|
||||
last = loc;
|
||||
}
|
||||
return distance;
|
||||
}
|
||||
//</editor-fold>
|
||||
//</editor-fold>
|
||||
|
||||
|
|
@ -239,7 +270,9 @@ public class ServiceTrackingDog implements Observer {
|
|||
MyLocation location = (MyLocation) notification.getExtra(ServiceXmpp.NOTIF_NEW_LOCATION_VALUE_LOCATION);
|
||||
onNewLocation(location);
|
||||
}
|
||||
// } else if (notification.isAction(ServiceXmpp.NOTIF_NEW_OBJECT)) {
|
||||
} else if (notification.isAction(ServiceXmpp.NOTIF_NEW_OBJECT)) {
|
||||
MyLocation location = (MyLocation) notification.getExtra(ServiceXmpp.NOTIF_NEW_OBJECT_VALUE_LOCATION);
|
||||
addPointObjectTrail(location);
|
||||
} else if (notification.isAction(ServiceXmpp.NOTIF_START_TRAIL)) {
|
||||
currentLocationProvider = LocationProvider.XMPP;
|
||||
} else if (notification.isAction(ServiceXmpp.NOTIF_STOP_TRAIL)) {
|
||||
|
|
@ -334,22 +367,22 @@ public class ServiceTrackingDog implements Observer {
|
|||
}
|
||||
}
|
||||
//<editor-fold defaultstate="collapsed" desc="Commands">
|
||||
public void sendCommandStartTrail() throws XmppStringprepException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException, SmackException.NoResponseException {
|
||||
private void sendXmppCommandStartTrail() throws XmppStringprepException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException, SmackException.NoResponseException {
|
||||
if (serviceXmpp != null) {
|
||||
serviceXmpp.sendCommandStartTrail();
|
||||
}
|
||||
}
|
||||
public void sendCommandStopTrail() throws XmppStringprepException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException, SmackException.NoResponseException {
|
||||
private void sendXmppCommandStopTrail() throws XmppStringprepException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException, SmackException.NoResponseException {
|
||||
if (serviceXmpp != null) {
|
||||
serviceXmpp.sendCommandStopTrail();
|
||||
}
|
||||
}
|
||||
public void sendCommandObjectTrail(double lat, double lon, long time) throws Exception {
|
||||
private void sendXmppCommandObjectTrail(double lat, double lon, long time) throws Exception {
|
||||
if (serviceXmpp != null) {
|
||||
serviceXmpp.sendCommandObjectTrail(lat, lon, time);
|
||||
}
|
||||
}
|
||||
public void sendCommandLocationTrail(double lat, double lon, long time) throws Exception {
|
||||
private void sendXmppCommandLocationTrail(double lat, double lon, long time) throws Exception {
|
||||
if (serviceXmpp != null) {
|
||||
serviceXmpp.sendCommandLocationTrail(lat, lon, time);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue