diff --git a/2015/android/Geofence/app/src/main/java/com/esrlabs/geofence/CircleGeofence.java b/2015/android/Geofence/app/src/main/java/com/esrlabs/geofence/CircleGeofence.java new file mode 100644 index 0000000..7df55e5 --- /dev/null +++ b/2015/android/Geofence/app/src/main/java/com/esrlabs/geofence/CircleGeofence.java @@ -0,0 +1,19 @@ +package com.esrlabs.geofence; + +import android.location.Location; + +public class CircleGeofence implements Geofence { + + final Location center; + final float radiusInMeters; + + public CircleGeofence(Location center, float radiusInMeters) { + this.center = center; + this.radiusInMeters = radiusInMeters; + } + + @Override + public boolean containsLocation(Location location) { + return false; + } +} diff --git a/2015/android/Geofence/app/src/main/java/com/esrlabs/geofence/Geofence.java b/2015/android/Geofence/app/src/main/java/com/esrlabs/geofence/Geofence.java new file mode 100644 index 0000000..edb778b --- /dev/null +++ b/2015/android/Geofence/app/src/main/java/com/esrlabs/geofence/Geofence.java @@ -0,0 +1,8 @@ +package com.esrlabs.geofence; + +import android.location.Location; + +public interface Geofence { + + public boolean containsLocation(Location location); +} diff --git a/2015/android/Geofence/app/src/main/java/com/esrlabs/geofence/GeofenceApp.java b/2015/android/Geofence/app/src/main/java/com/esrlabs/geofence/GeofenceApp.java index 2ade4cc..2869661 100644 --- a/2015/android/Geofence/app/src/main/java/com/esrlabs/geofence/GeofenceApp.java +++ b/2015/android/Geofence/app/src/main/java/com/esrlabs/geofence/GeofenceApp.java @@ -17,6 +17,9 @@ import com.esrlabs.headunitinterface.HeadUnit; import java.util.List; +import static android.location.LocationManager.NETWORK_PROVIDER; +import static com.esrlabs.geofence.Utils.location; + /** * Steps: * - register to the location provider @@ -33,5 +36,53 @@ public class GeofenceApp extends Service implements LocationListener { public static final String TAG = "GeofenceApp"; public static final String CAN_PROVIDER = "CanLocationProvider"; + private LocationManager locationManager; + private Geofence geofence; + + @Override + public void onCreate() { + super.onCreate(); + + Log.d(TAG, "onCreate"); + + if (locationManager == null) { + locationManager = (LocationManager) + this.getSystemService(Context.LOCATION_SERVICE); + } + + initLocationListener(); + initHeadUnitService(); + + if (geofence == null) { + final int someRadiusInMeters = 25; + final Location someCenterForTheGeofence = location(NETWORK_PROVIDER, 48.118920, 11.601057); + geofence = new CircleGeofence(someCenterForTheGeofence, someRadiusInMeters); + } + } + + @Override + public IBinder onBind(Intent intent) { + return null; + } + + @Override + public void onLocationChanged(Location location) { + + } + + @Override + public void onStatusChanged(String provider, int status, Bundle extras) { + + } + + @Override + public void onProviderEnabled(String provider) { + + } + + @Override + public void onProviderDisabled(String provider) { + + } } \ No newline at end of file diff --git a/2015/android/Geofence/app/src/main/java/com/esrlabs/geofence/PolygonGeofence.java b/2015/android/Geofence/app/src/main/java/com/esrlabs/geofence/PolygonGeofence.java new file mode 100644 index 0000000..4e14397 --- /dev/null +++ b/2015/android/Geofence/app/src/main/java/com/esrlabs/geofence/PolygonGeofence.java @@ -0,0 +1,34 @@ +package com.esrlabs.geofence; + +import android.location.Location; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class PolygonGeofence implements Geofence { + + final List polygonPoints; + + public PolygonGeofence(Location... locations) { + polygonPoints = new ArrayList(Arrays.asList(locations)); + } + + /** + * It implements the Ray casting algorithm, with the convention that the line is horizontal and + * goes from left to right. + * @param location The point to be checked if is inside the defined polygon shaped geofence + * @return True if the location is inside the defined polygon. + */ + @Override + public boolean containsLocation(Location location) { + int numberOfCorners = polygonPoints.size(); + + //adding the first corner at the end so that we can count the edge between last and first corners too + List corners = new ArrayList(polygonPoints); + corners.add(polygonPoints.get(0)); + + return false; + } + +} diff --git a/2015/android/Geofence/app/src/test/java/com/esrlabs/geofence/Utils.java b/2015/android/Geofence/app/src/main/java/com/esrlabs/geofence/Utils.java similarity index 100% rename from 2015/android/Geofence/app/src/test/java/com/esrlabs/geofence/Utils.java rename to 2015/android/Geofence/app/src/main/java/com/esrlabs/geofence/Utils.java