added empty implementations for the geofence classes

new file:   2015/android/Geofence/app/src/main/java/com/esrlabs/geofence/CircleGeofence.java
new file:   2015/android/Geofence/app/src/main/java/com/esrlabs/geofence/Geofence.java
modified:   2015/android/Geofence/app/src/main/java/com/esrlabs/geofence/GeofenceApp.java
new file:   2015/android/Geofence/app/src/main/java/com/esrlabs/geofence/PolygonGeofence.java
renamed:    2015/android/Geofence/app/src/test/java/com/esrlabs/geofence/Utils.java -> 2015/android/Geofence/app/src/main/java/com/esrlabs/geofence/Utils.java
This commit is contained in:
Andrei Bechet 2015-07-01 08:31:29 +02:00
parent 4c9a0b9be6
commit db654fdb0b
5 changed files with 112 additions and 0 deletions

View file

@ -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;
}
}

View file

@ -0,0 +1,8 @@
package com.esrlabs.geofence;
import android.location.Location;
public interface Geofence {
public boolean containsLocation(Location location);
}

View file

@ -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) {
}
}

View file

@ -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<Location> polygonPoints;
public PolygonGeofence(Location... locations) {
polygonPoints = new ArrayList<Location>(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<Location> corners = new ArrayList<Location>(polygonPoints);
corners.add(polygonPoints.get(0));
return false;
}
}