use of org.altbeacon.beacon.Region in project android-beacon-library by AltBeacon.
the class MonitoringStatus method restoreMonitoringStatus.
protected void restoreMonitoringStatus() {
FileInputStream inputStream = null;
ObjectInputStream objectInputStream = null;
try {
inputStream = mContext.openFileInput(STATUS_PRESERVATION_FILE_NAME);
objectInputStream = new ObjectInputStream(inputStream);
Map<Region, RegionMonitoringState> obj = (Map<Region, RegionMonitoringState>) objectInputStream.readObject();
LogManager.d(TAG, "Restored region monitoring state for " + obj.size() + " regions.");
for (Region region : obj.keySet()) {
LogManager.d(TAG, "Region " + region + " uniqueId: " + region.getUniqueId() + " state: " + obj.get(region));
}
// Mark all beacons that were inside again so they don't trigger as a new exit - enter.
for (RegionMonitoringState regionMonitoringState : obj.values()) {
if (regionMonitoringState.getInside()) {
regionMonitoringState.markInside();
}
}
mRegionsStatesMap.putAll(obj);
} catch (IOException | ClassNotFoundException | ClassCastException e) {
if (e instanceof InvalidClassException) {
LogManager.d(TAG, "Serialized Monitoring State has wrong class. Just ignoring saved state...");
} else
LogManager.e(TAG, "Deserialization exception, message: %s", e.getMessage());
} finally {
if (null != inputStream) {
try {
inputStream.close();
} catch (IOException ignored) {
}
}
if (objectInputStream != null) {
try {
objectInputStream.close();
} catch (IOException ignored) {
}
}
}
}
use of org.altbeacon.beacon.Region in project android-beacon-library by AltBeacon.
the class RegionBootstrap method disable.
/**
* Used to disable additional bootstrap callbacks after the first is received. Unless this is called,
* your application will be get additional calls as the supplied regions are entered or exited.
*/
public void disable() {
if (disabled) {
return;
}
disabled = true;
try {
for (Region region : regions) {
beaconManager.stopMonitoringBeaconsInRegion(region);
}
} catch (RemoteException e) {
LogManager.e(e, TAG, "Can't stop bootstrap regions");
}
beaconManager.unbind(beaconConsumer);
}
use of org.altbeacon.beacon.Region in project android-beacon-library by AltBeacon.
the class BeaconService method processBeaconFromScan.
private void processBeaconFromScan(Beacon beacon) {
if (Stats.getInstance().isEnabled()) {
Stats.getInstance().log(beacon);
}
if (LogManager.isVerboseLoggingEnabled()) {
LogManager.d(TAG, "beacon detected : %s", beacon.toString());
}
beacon = mExtraDataBeaconTracker.track(beacon);
// the above
if (beacon == null) {
if (LogManager.isVerboseLoggingEnabled()) {
LogManager.d(TAG, "not processing detections for GATT extra data beacon");
}
} else {
monitoringStatus.updateNewlyInsideInRegionsContaining(beacon);
List<Region> matchedRegions = null;
Iterator<Region> matchedRegionIterator;
LogManager.d(TAG, "looking for ranging region matches for this beacon");
synchronized (rangedRegionState) {
matchedRegions = matchingRegions(beacon, rangedRegionState.keySet());
matchedRegionIterator = matchedRegions.iterator();
while (matchedRegionIterator.hasNext()) {
Region region = matchedRegionIterator.next();
LogManager.d(TAG, "matches ranging region: %s", region);
RangeState rangeState = rangedRegionState.get(region);
if (rangeState != null) {
rangeState.addBeacon(beacon);
}
}
}
}
}
use of org.altbeacon.beacon.Region in project android-beacon-library by AltBeacon.
the class MonitoringStatus method updateNewlyOutside.
public synchronized void updateNewlyOutside() {
Iterator<Region> monitoredRegionIterator = regions().iterator();
boolean needsMonitoringStateSaving = false;
while (monitoredRegionIterator.hasNext()) {
Region region = monitoredRegionIterator.next();
RegionMonitoringState state = stateOf(region);
if (state.markOutsideIfExpired()) {
needsMonitoringStateSaving = true;
LogManager.d(TAG, "found a monitor that expired: %s", region);
state.getCallback().call(mContext, "monitoringData", new MonitoringData(state.getInside(), region));
}
}
if (needsMonitoringStateSaving) {
saveMonitoringStatusIfOn();
} else {
updateMonitoringStatusTime(System.currentTimeMillis());
}
}
use of org.altbeacon.beacon.Region in project android-beacon-library by AltBeacon.
the class MonitoringStatus method addRegion.
public synchronized void addRegion(Region region, Callback callback) {
if (getRegionsStateMap().containsKey(region)) {
// otherwise a region with the same uniqueId can never be changed
for (Region existingRegion : getRegionsStateMap().keySet()) {
if (existingRegion.equals(region)) {
if (existingRegion.hasSameIdentifiers(region)) {
return;
} else {
LogManager.d(TAG, "Replacing region with unique identifier " + region.getUniqueId());
LogManager.d(TAG, "Old definition: " + existingRegion);
LogManager.d(TAG, "New definition: " + region);
LogManager.d(TAG, "clearing state");
getRegionsStateMap().remove(region);
break;
}
}
}
}
getRegionsStateMap().put(region, new RegionMonitoringState(callback));
saveMonitoringStatusIfOn();
}
Aggregations