diff --git a/Demos/src/main/java/com/estimote/examples/demos/activities/ConfigureDeviceActivity.java b/Demos/src/main/java/com/estimote/examples/demos/activities/ConfigureDeviceActivity.java index a416609..7b8daf9 100644 --- a/Demos/src/main/java/com/estimote/examples/demos/activities/ConfigureDeviceActivity.java +++ b/Demos/src/main/java/com/estimote/examples/demos/activities/ConfigureDeviceActivity.java @@ -74,24 +74,7 @@ public class ConfigureDeviceActivity extends BaseActivity { connection.checkForFirmwareUpdate(new DeviceConnection.CheckFirmwareCallback() { @Override public void onDeviceUpToDate(DeviceFirmware firmware) { - setStatus("Firmware is up to date"); - connection.updateDevice(new DeviceConnection.FirmwareUpdateCallback() { - @Override - public void onSuccess() { - setStatus("Device firmware updated"); - connection.reconnect(); - } - - @Override - public void onProgress(float progress, String message) { - setStatus("" + (int) (progress * 100.0f) + "%: " + message); - } - - @Override - public void onFailure(DeviceConnectionException e) { - handleError(e); - } - }); + setStatus("Device is up to date. Current firmware version is " + firmware.software); } @Override public void onDeviceNeedsUpdate(DeviceFirmware firmware) { @@ -249,11 +232,7 @@ private void handleError(DeviceConnectionException exception) { } private void setStatus(final String status) { - runOnUiThread(new Runnable() { - @Override public void run() { - statusView.setText("Status: " + status); - } - }); + statusView.setText("Status: " + status); } public void readSensors() { diff --git a/Demos/src/main/java/com/estimote/examples/demos/activities/DistanceBeaconActivity.java b/Demos/src/main/java/com/estimote/examples/demos/activities/DistanceBeaconActivity.java index 89031c1..e4848ba 100644 --- a/Demos/src/main/java/com/estimote/examples/demos/activities/DistanceBeaconActivity.java +++ b/Demos/src/main/java/com/estimote/examples/demos/activities/DistanceBeaconActivity.java @@ -9,6 +9,7 @@ import com.estimote.sdk.BeaconManager; import com.estimote.sdk.Region; import com.estimote.sdk.Utils; + import java.util.List; /** @@ -50,27 +51,6 @@ protected void onCreate(Bundle savedInstanceState) { } beaconManager = new BeaconManager(this); - beaconManager.setRangingListener(new BeaconManager.RangingListener() { - @Override - public void onBeaconsDiscovered(Region region, final List rangedBeacons) { - // Note that results are not delivered on UI thread. - runOnUiThread(new Runnable() { - @Override - public void run() { - // Just in case if there are multiple beacons with the same uuid, major, minor. - Beacon foundBeacon = null; - for (Beacon rangedBeacon : rangedBeacons) { - if (rangedBeacon.getMacAddress().equals(beacon.getMacAddress())) { - foundBeacon = rangedBeacon; - } - } - if (foundBeacon != null) { - updateDistanceView(foundBeacon); - } - } - }); - } - }); final View view = findViewById(R.id.sonar); view.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @@ -105,16 +85,41 @@ private int computeDotPosY(Beacon beacon) { protected void onStart() { super.onStart(); + beaconManager.setRangingListener(new BeaconManager.RangingListener() { + @Override + public void onBeaconsDiscovered(Region region, final List rangedBeacons) { + // Note that results are not delivered on UI thread. + runOnUiThread(new Runnable() { + @Override + public void run() { + // Just in case if there are multiple beacons with the same uuid, major, minor. + Beacon foundBeacon = null; + for (Beacon rangedBeacon : rangedBeacons) { + if (rangedBeacon.getMacAddress().equals(beacon.getMacAddress())) { + foundBeacon = rangedBeacon; + } + } + if (foundBeacon != null) { + updateDistanceView(foundBeacon); + } + } + }); + } + }); + beaconManager.connect(new BeaconManager.ServiceReadyCallback() { @Override public void onServiceReady() { beaconManager.startRanging(region); } }); + + } @Override protected void onStop() { + beaconManager.stopRanging(region); beaconManager.disconnect(); super.onStop(); diff --git a/Demos/src/main/java/com/estimote/examples/demos/activities/NotifyDemoActivity.java b/Demos/src/main/java/com/estimote/examples/demos/activities/NotifyDemoActivity.java index 49bae54..96c6eef 100644 --- a/Demos/src/main/java/com/estimote/examples/demos/activities/NotifyDemoActivity.java +++ b/Demos/src/main/java/com/estimote/examples/demos/activities/NotifyDemoActivity.java @@ -7,10 +7,12 @@ import android.content.Intent; import android.os.Bundle; import android.widget.TextView; + import com.estimote.examples.demos.R; import com.estimote.sdk.Beacon; import com.estimote.sdk.BeaconManager; import com.estimote.sdk.Region; + import java.util.List; import java.util.concurrent.TimeUnit; @@ -48,8 +50,16 @@ protected void onCreate(Bundle savedInstanceState) { // Default values are 5s of scanning and 25s of waiting time to save CPU cycles. // In order for this demo to be more responsive and immediate we lower down those values. - beaconManager.setBackgroundScanPeriod(TimeUnit.SECONDS.toMillis(1), 0); + beaconManager.setBackgroundScanPeriod(TimeUnit.SECONDS.toMillis(1), TimeUnit.SECONDS.toMillis(0)); + + // Changes expiration time for beacons. The longer this period is, the less responsive onExit events are. + // On the other hand, there is less possible to throw short onExit/onEnter events during monitoring. + // Please bear in mind, that this is strictly connected to beacon advertising interval - the lower the value is, + // the more possible for device is to find an advertised packet. The clue is to find a sweet spot between advertising interval + // and expiration time. + beaconManager.setRegionExitExpiration(TimeUnit.SECONDS.toMillis(20)); + // Set monitoring listener to handle incoming beacon events beaconManager.setMonitoringListener(new MonitoringListener() { @Override public void onEnteredRegion(Region region, List beacons) {