From 40abc3b3f80e2c1b6c9f98eeb77aae7e9cee4e38 Mon Sep 17 00:00:00 2001 From: AustinHaigh Date: Wed, 8 May 2019 10:00:13 -1000 Subject: [PATCH] feat: add ARMA filter support for distance calcs --- src/android/LocationManager.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/android/LocationManager.java b/src/android/LocationManager.java index d27794a..d0556a0 100644 --- a/src/android/LocationManager.java +++ b/src/android/LocationManager.java @@ -53,6 +53,7 @@ Licensed to the Apache Software Foundation (ASF) under one import org.altbeacon.beacon.RangeNotifier; import org.altbeacon.beacon.Region; import org.altbeacon.beacon.service.RunningAverageRssiFilter; +import org.altbeacon.beacon.service.ArmaRssiFilter; import org.altbeacon.beacon.service.RangedBeacon; import org.apache.cordova.CallbackContext; import org.apache.cordova.CordovaInterface; @@ -81,6 +82,8 @@ public class LocationManager extends CordovaPlugin implements BeaconConsumer { private static final int DEFAULT_FOREGROUND_BETWEEN_SCAN_PERIOD = 0; private static final String SAMPLE_EXPIRATION_MILLISECOND = "com.unarin.cordova.beacon.android.altbeacon.SampleExpirationMilliseconds"; private static final int DEFAULT_SAMPLE_EXPIRATION_MILLISECOND = 20000; + private static final String ENABLE_ARMA_FILTER_NAME = "com.unarin.cordova.beacon.android.altbeacon.EnableArmaFilter"; + private static final boolean DEFAULT_ENABLE_ARMA_FILTER = false; private static final int DEFAULT_FOREGROUND_SCAN_PERIOD = 1100; private static int CDV_LOCATION_MANAGER_DOM_DELEGATE_TIMEOUT = 30; private static final int BUILD_VERSION_CODES_M = 23; @@ -135,8 +138,16 @@ public void initialize(CordovaInterface cordova, CordovaWebView webView) { Log.i(TAG, "Determined config value SAMPLE_EXPIRATION_MILLISECOND: " + String.valueOf(sampleExpirationMilliseconds)); - iBeaconManager.setRssiFilterImplClass(RunningAverageRssiFilter.class); - RunningAverageRssiFilter.setSampleExpirationMilliseconds(sampleExpirationMilliseconds); + final boolean enableArmaFilter = this.preferences.getBoolean( + ENABLE_ARMA_FILTER_NAME, DEFAULT_ENABLE_ARMA_FILTER); + + if(enableArmaFilter){ + iBeaconManager.setRssiFilterImplClass(ArmaRssiFilter.class); + } + else{ + iBeaconManager.setRssiFilterImplClass(RunningAverageRssiFilter.class); + RunningAverageRssiFilter.setSampleExpirationMilliseconds(sampleExpirationMilliseconds); + } RangedBeacon.setSampleExpirationMilliseconds(sampleExpirationMilliseconds); initBluetoothListener();