Search in sources :

Example 1 with MonitoringData

use of org.altbeacon.beacon.service.MonitoringData in project android-beacon-library by AltBeacon.

the class BeaconIntentProcessor method onHandleIntent.

@Override
protected void onHandleIntent(Intent intent) {
    LogManager.d(TAG, "got an intent to process");
    MonitoringData monitoringData = null;
    RangingData rangingData = null;
    if (intent != null && intent.getExtras() != null) {
        monitoringData = (MonitoringData) intent.getExtras().get("monitoringData");
        rangingData = (RangingData) intent.getExtras().get("rangingData");
    }
    if (rangingData != null) {
        LogManager.d(TAG, "got ranging data");
        if (rangingData.getBeacons() == null) {
            LogManager.w(TAG, "Ranging data has a null beacons collection");
        }
        Set<RangeNotifier> notifiers = BeaconManager.getInstanceForApplication(this).getRangingNotifiers();
        java.util.Collection<Beacon> beacons = rangingData.getBeacons();
        if (notifiers != null) {
            for (RangeNotifier notifier : notifiers) {
                notifier.didRangeBeaconsInRegion(beacons, rangingData.getRegion());
            }
        } else {
            LogManager.d(TAG, "but ranging notifier is null, so we're dropping it.");
        }
        RangeNotifier dataNotifier = BeaconManager.getInstanceForApplication(this).getDataRequestNotifier();
        if (dataNotifier != null) {
            dataNotifier.didRangeBeaconsInRegion(beacons, rangingData.getRegion());
        }
    }
    if (monitoringData != null) {
        LogManager.d(TAG, "got monitoring data");
        Set<MonitorNotifier> notifiers = BeaconManager.getInstanceForApplication(this).getMonitoringNotifiers();
        if (notifiers != null) {
            for (MonitorNotifier notifier : notifiers) {
                LogManager.d(TAG, "Calling monitoring notifier: %s", notifier);
                notifier.didDetermineStateForRegion(monitoringData.isInside() ? MonitorNotifier.INSIDE : MonitorNotifier.OUTSIDE, monitoringData.getRegion());
                if (monitoringData.isInside()) {
                    notifier.didEnterRegion(monitoringData.getRegion());
                } else {
                    notifier.didExitRegion(monitoringData.getRegion());
                }
            }
        }
    }
}
Also used : RangingData(org.altbeacon.beacon.service.RangingData) MonitoringData(org.altbeacon.beacon.service.MonitoringData)

Aggregations

MonitoringData (org.altbeacon.beacon.service.MonitoringData)1 RangingData (org.altbeacon.beacon.service.RangingData)1