GeofenceStatepublic class GeofenceState extends Object Represents state associated with a geofence |
Fields Summary |
---|
public static final int | FLAG_ENTER | public static final int | FLAG_EXIT | private static final int | STATE_UNKNOWN | private static final int | STATE_INSIDE | private static final int | STATE_OUTSIDE | public final android.location.Geofence | mFence | private final android.location.Location | mLocation | public final long | mExpireAt | public final int | mAllowedResolutionLevel | public final int | mUid | public final String | mPackageName | public final android.app.PendingIntent | mIntent | int | mState | double | mDistanceToCenter |
Constructors Summary |
---|
public GeofenceState(android.location.Geofence fence, long expireAt, int allowedResolutionLevel, int uid, String packageName, android.app.PendingIntent intent) // current distance to center of fence
mState = STATE_UNKNOWN;
mDistanceToCenter = Double.MAX_VALUE;
mFence = fence;
mExpireAt = expireAt;
mAllowedResolutionLevel = allowedResolutionLevel;
mUid = uid;
mPackageName = packageName;
mIntent = intent;
mLocation = new Location("");
mLocation.setLatitude(fence.getLatitude());
mLocation.setLongitude(fence.getLongitude());
|
Methods Summary |
---|
public double | getDistanceToBoundary()Gets the distance from the current location to the fence's boundary.
if (Double.compare(mDistanceToCenter, Double.MAX_VALUE) == 0) {
return Double.MAX_VALUE;
} else {
return Math.abs(mFence.getRadius() - mDistanceToCenter);
}
| public int | processLocation(android.location.Location location)Process a new location.
mDistanceToCenter = mLocation.distanceTo(location);
int prevState = mState;
//TODO: inside/outside detection could be made more rigorous
boolean inside = mDistanceToCenter <= Math.max(mFence.getRadius(), location.getAccuracy());
if (inside) {
mState = STATE_INSIDE;
if (prevState != STATE_INSIDE) {
return FLAG_ENTER; // return enter if previously exited or unknown
}
} else {
mState = STATE_OUTSIDE;
if (prevState == STATE_INSIDE) {
return FLAG_EXIT; // return exit only if previously entered
}
}
return 0;
| public java.lang.String | toString()
String state;
switch (mState) {
case STATE_INSIDE:
state = "IN";
break;
case STATE_OUTSIDE:
state = "OUT";
break;
default:
state = "?";
}
return String.format("%s d=%.0f %s", mFence.toString(), mDistanceToCenter, state);
|
|