Fix XMPP start/stop infinite loop.
This commit is contained in:
parent
d253dbd765
commit
192838b585
|
|
@ -171,6 +171,15 @@ public class MainActivity extends AppCompatActivity implements IOrientationConsu
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
changeStatusTrace();
|
changeStatusTrace();
|
||||||
|
try {
|
||||||
|
if (serviceTrackingDog.isTraceurActivated()) {
|
||||||
|
serviceTrackingDog.sendXmppCommandStartTrail();
|
||||||
|
} else {
|
||||||
|
serviceTrackingDog.sendXmppCommandStopTrail();
|
||||||
|
}
|
||||||
|
} catch (XmppStringprepException | XMPPException.XMPPErrorException | SmackException.NotConnectedException | InterruptedException | SmackException.NoResponseException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
start_stop_dog_trace = findViewById(R.id.start_stop_dog_trace);
|
start_stop_dog_trace = findViewById(R.id.start_stop_dog_trace);
|
||||||
|
|
@ -390,7 +399,7 @@ public class MainActivity extends AppCompatActivity implements IOrientationConsu
|
||||||
// Update distance
|
// Update distance
|
||||||
distance = serviceTrackingDog.calculTrailDistance();
|
distance = serviceTrackingDog.calculTrailDistance();
|
||||||
if (distance != 0) {
|
if (distance != 0) {
|
||||||
updateDistance();
|
updatePlaceholder();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (MyLocation loc: serviceTrackingDog.getListGeoPointObjectsTrail()) {
|
for (MyLocation loc: serviceTrackingDog.getListGeoPointObjectsTrail()) {
|
||||||
|
|
@ -489,7 +498,7 @@ public class MainActivity extends AppCompatActivity implements IOrientationConsu
|
||||||
this.add_object.setVisibility(View.VISIBLE);
|
this.add_object.setVisibility(View.VISIBLE);
|
||||||
this.add_object.setText(R.string.trail_object);
|
this.add_object.setText(R.string.trail_object);
|
||||||
this.start_stop_dog_trace.setVisibility(View.GONE);
|
this.start_stop_dog_trace.setVisibility(View.GONE);
|
||||||
updateDistance();
|
updatePlaceholder();
|
||||||
} else {
|
} else {
|
||||||
this.start_stop_trace.setText(R.string.trail_start);
|
this.start_stop_trace.setText(R.string.trail_start);
|
||||||
this.add_object.setVisibility(View.GONE);
|
this.add_object.setVisibility(View.GONE);
|
||||||
|
|
@ -505,7 +514,7 @@ public class MainActivity extends AppCompatActivity implements IOrientationConsu
|
||||||
this.add_object.setText(R.string.dog_object);
|
this.add_object.setText(R.string.dog_object);
|
||||||
this.start_stop_trace.setVisibility(View.GONE);
|
this.start_stop_trace.setVisibility(View.GONE);
|
||||||
this.textViewCurrentLocation.setVisibility(View.GONE);
|
this.textViewCurrentLocation.setVisibility(View.GONE);
|
||||||
updateDistance();
|
updatePlaceholder();
|
||||||
} else {
|
} else {
|
||||||
this.start_stop_dog_trace.setText(R.string.dog_start);
|
this.start_stop_dog_trace.setText(R.string.dog_start);
|
||||||
this.add_object.setVisibility(View.GONE);
|
this.add_object.setVisibility(View.GONE);
|
||||||
|
|
@ -676,17 +685,12 @@ public class MainActivity extends AppCompatActivity implements IOrientationConsu
|
||||||
}
|
}
|
||||||
if (serviceTrackingDog.isTraceurActivated()) {
|
if (serviceTrackingDog.isTraceurActivated()) {
|
||||||
updateTrailTrace();
|
updateTrailTrace();
|
||||||
if (lastLocation != null) {
|
distance = serviceTrackingDog.calculTrailDistance();
|
||||||
distance += onNewLocation.distanceTo(lastLocation);
|
updatePlaceholder();
|
||||||
updateDistance();
|
|
||||||
}
|
|
||||||
lastLocation = onNewLocation;
|
lastLocation = onNewLocation;
|
||||||
} else if (serviceTrackingDog.isDogActivated()) {
|
} else if (serviceTrackingDog.isDogActivated()) {
|
||||||
updateDogTrace();
|
updateDogTrace();
|
||||||
if (lastLocation != null) {
|
updatePlaceholder();
|
||||||
distance += onNewLocation.distanceTo(lastLocation);
|
|
||||||
updateDistance();
|
|
||||||
}
|
|
||||||
lastLocation = onNewLocation;
|
lastLocation = onNewLocation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -707,7 +711,7 @@ public class MainActivity extends AppCompatActivity implements IOrientationConsu
|
||||||
//</editor-fold>
|
//</editor-fold>
|
||||||
|
|
||||||
//<editor-fold defaultstate="collapsed" desc="Placeholder management">
|
//<editor-fold defaultstate="collapsed" desc="Placeholder management">
|
||||||
private void updateDistance() {
|
private void updatePlaceholder() {
|
||||||
String text = null;
|
String text = null;
|
||||||
if (serviceTrackingDog.isTraceurActivated()) {
|
if (serviceTrackingDog.isTraceurActivated()) {
|
||||||
text = getTextTraceur();
|
text = getTextTraceur();
|
||||||
|
|
|
||||||
|
|
@ -84,6 +84,8 @@ public class ServiceTrackingDog implements Observer {
|
||||||
if (name != null) {
|
if (name != null) {
|
||||||
if (name.equals(ServiceGps.class.getName())) {
|
if (name.equals(ServiceGps.class.getName())) {
|
||||||
serviceGps.addObserver(observer);
|
serviceGps.addObserver(observer);
|
||||||
|
} else if (name.equals(ServiceXmpp.class.getName())) {
|
||||||
|
serviceXmpp.addObserver(observer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -128,17 +130,6 @@ public class ServiceTrackingDog implements Observer {
|
||||||
traces.toggleTraceurActivation();
|
traces.toggleTraceurActivation();
|
||||||
if (!isTraceurActivated()) {
|
if (!isTraceurActivated()) {
|
||||||
exportTrailTraceToGpx();
|
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() {
|
public boolean isTraceurActivated() {
|
||||||
|
|
@ -254,9 +245,9 @@ public class ServiceTrackingDog implements Observer {
|
||||||
MyLocation location = new MyLocation((Location) notification.getExtra(ServiceGps.NOTIF_NEW_LOCATION_VALUE_LOCATION));
|
MyLocation location = new MyLocation((Location) notification.getExtra(ServiceGps.NOTIF_NEW_LOCATION_VALUE_LOCATION));
|
||||||
onNewLocation(location);
|
onNewLocation(location);
|
||||||
shouldVibrate();
|
shouldVibrate();
|
||||||
if (serviceXmpp != null && location != null) {
|
if (serviceXmpp != null && location != null && isTraceurActivated()) {
|
||||||
try {
|
try {
|
||||||
serviceXmpp.sendCommandLocationTrail(location.getLatitude(), location.getLongitude(), location.getTime());
|
sendXmppCommandLocationTrail(location.getLatitude(), location.getLongitude(), location.getTime());
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -367,12 +358,12 @@ public class ServiceTrackingDog implements Observer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//<editor-fold defaultstate="collapsed" desc="Commands">
|
//<editor-fold defaultstate="collapsed" desc="Commands">
|
||||||
private void sendXmppCommandStartTrail() throws XmppStringprepException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException, SmackException.NoResponseException {
|
public void sendXmppCommandStartTrail() throws XmppStringprepException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException, SmackException.NoResponseException {
|
||||||
if (serviceXmpp != null) {
|
if (serviceXmpp != null) {
|
||||||
serviceXmpp.sendCommandStartTrail();
|
serviceXmpp.sendCommandStartTrail();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private void sendXmppCommandStopTrail() throws XmppStringprepException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException, SmackException.NoResponseException {
|
public void sendXmppCommandStopTrail() throws XmppStringprepException, XMPPException.XMPPErrorException, SmackException.NotConnectedException, InterruptedException, SmackException.NoResponseException {
|
||||||
if (serviceXmpp != null) {
|
if (serviceXmpp != null) {
|
||||||
serviceXmpp.sendCommandStopTrail();
|
serviceXmpp.sendCommandStopTrail();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue