Skip to content

Commit

Permalink
README updated, android sources updated
Browse files Browse the repository at this point in the history
  • Loading branch information
Erkki Silvola committed Apr 16, 2020
1 parent fdbba87 commit 9485c13
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 32 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ public void onDestroy() {
Detailed documentation [Full Documentation](polar-sdk-ios/docs/). Minimum iOS version is 10.
## Installation
Compiled Sdk and dependencys can be found from [polar-sdk-ios](polar-sdk-ios/)
Precompiled 4.4.0 RxSwift and RxAtomic is added to sdk package. All iOS demos and examples contains Cartfile if you desire to compile
Precompiled 5.1.1 RxSwift is added to sdk package. All iOS demos and examples contains Cartfile if you desire to compile
dependencies yourself.

1. In the project properties __General__ tab, add `PolarBleSdk.framework` , `RxSwift.framework` to __Embedded binaries__ and __Linked Frameworks and Libraries__.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import android.content.Context;
import android.support.annotation.Nullable;
import android.util.Pair;
import android.os.Handler;

import com.androidcommunications.polar.api.ble.BleDeviceListener;
import com.androidcommunications.polar.api.ble.model.BleDeviceSession;
Expand All @@ -30,41 +29,24 @@ public abstract class BleDeviceListener2 extends BleDeviceListener implements Sc
protected Context context;
private BleDeviceSessionStateChangedCallback changedCallback = null;
protected BlePowerStateChangedCallback powerStateChangedCallback = null;
private Handler stateHandler;

public BleDeviceListener2(final Context context, Set<Class<? extends BleGattBase> > clients) {
super(clients);
this.context = context;
this.stateHandler = new Handler(context.getMainLooper());
this.connectionHandler = new ConnectionHandler(this,this);
this.connectionHandler = new ConnectionHandler(context,this,this);
this.connectionHandler.addObserver(new ConnectionHandlerObserver() {
@Override
public void deviceSessionStateChanged(final BleDeviceSession2 session) {
if (changedCallback != null) {
if (session.getSessionState() == BleDeviceSession.DeviceSessionState.SESSION_OPEN_PARK &&
session.getPreviousState() == BleDeviceSession.DeviceSessionState.SESSION_OPEN) {
//NOTE special case, we were connected so propagate closed event( informal )
stateHandler.post(new Runnable() {
@Override
public void run() {
changedCallback.stateChanged(session, BleDeviceSession.DeviceSessionState.SESSION_CLOSED);
}
});
changedCallback.stateChanged(session, BleDeviceSession.DeviceSessionState.SESSION_CLOSED);
if (session.getSessionState() == BleDeviceSession.DeviceSessionState.SESSION_OPEN_PARK) {
stateHandler.post(new Runnable() {
@Override
public void run() {
changedCallback.stateChanged(session, BleDeviceSession.DeviceSessionState.SESSION_OPEN_PARK);
}
});
changedCallback.stateChanged(session, BleDeviceSession.DeviceSessionState.SESSION_OPEN_PARK);
}
} else {
stateHandler.post(new Runnable() {
@Override
public void run() {
changedCallback.stateChanged(session, session.getSessionState());
}
});
changedCallback.stateChanged(session, session.getSessionState());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.androidcommunications.polar.enpoints.ble.common.connection;

import android.content.Context;
import android.os.Handler;

import com.androidcommunications.polar.api.ble.BleLogger;
import com.androidcommunications.polar.api.ble.model.BleDeviceSession;
import com.androidcommunications.polar.common.ble.AtomicSet;
Expand Down Expand Up @@ -41,9 +44,11 @@ private enum ConnectionHandlerAction{
private BleDeviceSession2 current;
private AtomicSet<ConnectionHandlerObserver> observers = new AtomicSet<>();
private boolean automaticReconnection = true;
private Handler stateHandler;

public ConnectionHandler(ConnectionInterface connectionInterface,
public ConnectionHandler(Context context, ConnectionInterface connectionInterface,
ScannerInterface scannerInterface){
this.stateHandler = new Handler(context.getMainLooper());
this.scannerInterface = scannerInterface;
this.connectionInterface = connectionInterface;
this.state = ConnectionHandlerState.FREE;
Expand Down Expand Up @@ -76,21 +81,31 @@ public void disconnectDevice(BleDeviceSession2 bleDeviceSession){
}

public void deviceConnected(final BleDeviceSession2 bleDeviceSession){
commandState(bleDeviceSession, ConnectionHandlerAction.DEVICE_CONNECTED);
observers.accessAll(new AtomicSet.ObjectAccess<ConnectionHandlerObserver>() {
stateHandler.post(new Runnable() {
@Override
public void access(ConnectionHandlerObserver object) {
object.deviceConnected(bleDeviceSession);
public void run() {
commandState(bleDeviceSession, ConnectionHandlerAction.DEVICE_CONNECTED);
observers.accessAll(new AtomicSet.ObjectAccess<ConnectionHandlerObserver>() {
@Override
public void access(ConnectionHandlerObserver object) {
object.deviceConnected(bleDeviceSession);
}
});
}
});
}

public void deviceDisconnected(final BleDeviceSession2 bleDeviceSession){
commandState(bleDeviceSession, ConnectionHandlerAction.DEVICE_DISCONNECTED);
observers.accessAll(new AtomicSet.ObjectAccess<ConnectionHandlerObserver>() {
stateHandler.post(new Runnable() {
@Override
public void access(ConnectionHandlerObserver object) {
object.deviceDisconnected(bleDeviceSession);
public void run() {
commandState(bleDeviceSession, ConnectionHandlerAction.DEVICE_DISCONNECTED);
observers.accessAll(new AtomicSet.ObjectAccess<ConnectionHandlerObserver>() {
@Override
public void access(ConnectionHandlerObserver object) {
object.deviceDisconnected(bleDeviceSession);
}
});
}
});
}
Expand Down

0 comments on commit 9485c13

Please sign in to comment.