Skip to content

Commit

Permalink
Version 0.10.5
Browse files Browse the repository at this point in the history
  • Loading branch information
pawelDylag committed May 25, 2016
1 parent 197d9aa commit 0cee6da
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.estimote.sdk.BeaconManager;
import com.estimote.sdk.Region;
import com.estimote.sdk.Utils;

import java.util.List;

/**
Expand Down Expand Up @@ -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<Beacon> 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() {
Expand Down Expand Up @@ -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<Beacon> 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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<Beacon> beacons) {
Expand Down

0 comments on commit 0cee6da

Please sign in to comment.