diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerLocation.java b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerLocation.java
index 8622cd8b68..5b31f09b86 100644
--- a/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerLocation.java
+++ b/app/src/main/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerLocation.java
@@ -68,7 +68,6 @@ public class TriggerLocation extends Trigger {
@Override
public synchronized boolean shouldRun() {
Location location = LocationService.getLastLocation();
- log.debug("Entered shouldRun()");
if (location == null)
return false;
@@ -203,4 +202,21 @@ public class TriggerLocation extends Trigger {
else
return OUTSIDE;
}
+
+ double calculateDistance() {
+ Location location = LocationService.getLastLocation();
+ if (location == null)
+ return -1d;
+ Location a = new Location("Trigger");
+ a.setLatitude(latitude.getValue());
+ a.setLongitude(longitude.getValue());
+ return location.distanceTo(a);
+ }
+
+ String getLocation(){
+ Location location = LocationService.getLastLocation();
+ if (location == null)
+ return "No service!";
+ return location.toString();
+ }
}
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 3c48994172..72c45ab649 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -1410,12 +1410,12 @@
Lon:
Dist [m]:
Name:
- Location is %1$s %2$s
- In/Out of defined area
- inside
- outside
- when you enter the area named
- when you leave the area named
+ %1$s %2$s
+ When
+ When you are inside the area
+ When you are inside the area
+ When you enter the area named
+ When you leave the area named
Last bolus ago
Last bolus time %1$s %2$s min ago
COB
diff --git a/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerLocationTest.java b/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerLocationTest.java
index 53589b4128..a02754c622 100644
--- a/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerLocationTest.java
+++ b/app/src/test/java/info/nightscout/androidaps/plugins/general/automation/triggers/TriggerLocationTest.java
@@ -91,6 +91,33 @@ public class TriggerLocationTest {
t = new TriggerLocation();
t.distance.setValue(-500);
Assert.assertFalse(t.shouldRun());
+
+ //Test of GOING_IN - last mode should be OUTSIDE, and current mode should be INSIDE
+ t = new TriggerLocation();
+ t.distance.setValue(50);
+ t.lastMode = t.currentMode(55d);
+ PowerMockito.when(LocationService.getLastLocation()).thenReturn(null);
+ PowerMockito.when(LocationService.getLastLocation()).thenReturn(mockedLocationOut());
+ t.modeSelected.setValue(InputLocationMode.Mode.GOING_IN);
+ Assert.assertEquals(t.lastMode, InputLocationMode.Mode.OUTSIDE);
+ Assert.assertEquals(t.currentMode(5d), InputLocationMode.Mode.INSIDE);
+ Assert.assertTrue(t.shouldRun());
+
+ //Test of GOING_OUT - last mode should be INSIDE, and current mode should be OUTSIDE
+ t = new TriggerLocation();
+ t.latitude.setValue(213);
+ t.longitude.setValue(212);
+ t.distance.setValue(2d);
+ t.lastMode = t.currentMode(1d);
+
+ PowerMockito.when(LocationService.getLastLocation()).thenReturn(mockedLocation());
+ t.modeSelected.setValue(InputLocationMode.Mode.GOING_OUT);
+ Assert.assertEquals(t.lastMode, InputLocationMode.Mode.INSIDE);
+ Assert.assertEquals(t.currentMode(55d), InputLocationMode.Mode.OUTSIDE);
+ PowerMockito.when(LocationService.getLastLocation()).thenReturn(null);
+ PowerMockito.when(LocationService.getLastLocation()).thenReturn(mockedLocationOut());
+ Assert.assertEquals(-1d, t.calculateDistance(), 0d);
+ Assert.assertTrue(t.shouldRun());
}
String locationJson = "{\"data\":{\"mode\":\"OUTSIDE\",\"distance\":2,\"lastRun\":0,\"latitude\":213,\"name\":\"\",\"longitude\":212},\"type\":\"info.nightscout.androidaps.plugins.general.automation.triggers.TriggerLocation\"}";
@@ -111,7 +138,6 @@ public class TriggerLocationTest {
t.latitude.setValue(213);
t.longitude.setValue(212);
t.distance.setValue(2);
-// t.setMode(t.stringToMode(new InputSelect(modes).getValue()));
t.modeSelected.setValue(InputLocationMode.Mode.INSIDE);
TriggerLocation t2 = (TriggerLocation) Trigger.instantiate(new JSONObject(t.toJSON()));
@@ -172,6 +198,13 @@ public class TriggerLocationTest {
Assert.assertEquals(t.lastRun, 1514766900000L, 0d);
}
+ @Test
+ public void getLocationTest() {
+ PowerMockito.when(LocationService.getLastLocation()).thenReturn(mockedLocationOut());
+ TriggerLocation t = new TriggerLocation();
+ Assert.assertEquals("", t.getLocation());
+ }
+
public Location mockedLocation() {
Location newLocation = new Location("test");
newLocation.setLatitude(10);
@@ -179,4 +212,12 @@ public class TriggerLocationTest {
newLocation.setAccuracy(1f);
return newLocation;
}
+
+ public Location mockedLocationOut() {
+ Location newLocation = new Location("test");
+ newLocation.setLatitude(12f);
+ newLocation.setLongitude(13f);
+ newLocation.setAccuracy(1f);
+ return newLocation;
+ }
}
\ No newline at end of file