Skip to content

Commit

Permalink
Merge pull request #112 from polarofficial/update-android-sdk-to-late…
Browse files Browse the repository at this point in the history
…st-gradle-version

Update android sdk to latest gradle version
  • Loading branch information
JOikarinen authored Dec 7, 2020
2 parents 1f21397 + c1f0e2d commit b2d662c
Show file tree
Hide file tree
Showing 62 changed files with 1,471 additions and 612 deletions.
6 changes: 0 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,5 @@
*.iml
build
demos/**/libs/
.gradle
gradle
gradlew
gradlew.bat
.idea
local.properties
project.xcworkspace
xcuserdata
21 changes: 10 additions & 11 deletions demos/Android-Demos/PolarSDK-ECG-HR-Demo/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 28
compileSdkVersion 29
defaultConfig {
applicationId "com.polar.polarsdkdemo"
minSdkVersion 21
targetSdkVersion 28
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
}
buildTypes {
release {
Expand All @@ -31,16 +31,15 @@ task copySdk {
}

preBuild.dependsOn copySdk

dependencies {
implementation "com.androidplot:androidplot-core:1.5.6"
implementation files('libs/polar-ble-sdk.aar')
implementation 'com.androidplot:androidplot-core:1.5.6'
implementation 'io.reactivex.rxjava3:rxjava:3.0.0'
implementation group: 'commons-io', name: 'commons-io', version: '2.4'
implementation 'io.reactivex.rxjava3:rxandroid:3.0.0'
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
testImplementation 'junit:junit:4.13.1'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.polar.polarsdkecghrdemo;

import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;
import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.ext.junit.runners.AndroidJUnit4;

import org.junit.Test;
import org.junit.runner.RunWith;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.polar.polarsdkecghrdemo">

<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

<application
android:allowBackup="true"
Expand All @@ -15,7 +15,8 @@
android:theme="@style/AppTheme">
<activity
android:name="com.polar.polarsdkecghrdemo.MainActivity"
android:label="@string/app_name" android:screenOrientation="portrait">
android:label="@string/app_name"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand All @@ -24,12 +25,12 @@
</activity>
<activity
android:name="com.polar.polarsdkecghrdemo.ECGActivity"
android:label="@string/ecg_name" android:screenOrientation="portrait">
</activity>
android:label="@string/ecg_name"
android:screenOrientation="portrait"/>
<activity
android:name="com.polar.polarsdkecghrdemo.HRActivity"
android:label="@string/hr_name" android:screenOrientation="portrait">
</activity>
android:label="@string/hr_name"
android:screenOrientation="portrait"/>
</application>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -2,52 +2,52 @@

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.androidplot.xy.BoundaryMode;
import com.androidplot.xy.StepMode;
import com.androidplot.xy.XYPlot;

import org.reactivestreams.Publisher;

import java.util.List;
import java.util.UUID;

import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers;
import io.reactivex.rxjava3.disposables.Disposable;
import io.reactivex.rxjava3.functions.Action;
import io.reactivex.rxjava3.functions.Consumer;
import io.reactivex.rxjava3.functions.Function;
import polar.com.sdk.api.PolarBleApi;
import polar.com.sdk.api.PolarBleApiCallback;
import polar.com.sdk.api.PolarBleApiDefaultImpl;
import polar.com.sdk.api.errors.PolarInvalidArgument;
import polar.com.sdk.api.model.PolarDeviceInfo;
import polar.com.sdk.api.model.PolarEcgData;
import polar.com.sdk.api.model.PolarHrData;
import polar.com.sdk.api.model.PolarSensorSetting;
import polar.com.sdk.api.errors.PolarInvalidArgument;

public class ECGActivity extends AppCompatActivity implements PlotterListener {
private static final String TAG = "ECGActivity";

private PolarBleApi api;
private TextView textViewHR;
private TextView textViewFW;
private XYPlot plot;
private Plotter plotter;

TextView textViewHR, textViewFW;
private String TAG = "Polar_ECGActivity";
public PolarBleApi api;
private Disposable ecgDisposable = null;
private Context classContext = this;
private String DEVICE_ID;
private final Context classContext = this;
private String deviceId;

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_ecg);
DEVICE_ID = getIntent().getStringExtra("id");
deviceId = getIntent().getStringExtra("id");
textViewHR = findViewById(R.id.info);
textViewFW = findViewById(R.id.fw);

Expand All @@ -65,90 +65,87 @@ public void blePowerStateChanged(boolean b) {
}

@Override
public void deviceConnected(PolarDeviceInfo s) {
public void deviceConnected(@NonNull PolarDeviceInfo s) {
Log.d(TAG, "Device connected " + s.deviceId);
Toast.makeText(classContext, R.string.connected,
Toast.LENGTH_SHORT).show();
Toast.makeText(classContext, R.string.connected, Toast.LENGTH_SHORT).show();
}

@Override
public void deviceConnecting(PolarDeviceInfo polarDeviceInfo) {
public void deviceConnecting(@NonNull PolarDeviceInfo polarDeviceInfo) {

}

@Override
public void deviceDisconnected(PolarDeviceInfo s) {
public void deviceDisconnected(@NonNull PolarDeviceInfo s) {
Log.d(TAG, "Device disconnected " + s);

}

@Override
public void ecgFeatureReady(String s) {
public void ecgFeatureReady(@NonNull String s) {
Log.d(TAG, "ECG Feature ready " + s);
streamECG();
}

@Override
public void accelerometerFeatureReady(String s) {
public void accelerometerFeatureReady(@NonNull String s) {
Log.d(TAG, "ACC Feature ready " + s);
}

@Override
public void ppgFeatureReady(String s) {
public void ppgFeatureReady(@NonNull String s) {
Log.d(TAG, "PPG Feature ready " + s);
}

@Override
public void ppiFeatureReady(String s) {
public void ppiFeatureReady(@NonNull String s) {
Log.d(TAG, "PPI Feature ready " + s);
}

@Override
public void biozFeatureReady(String s) {
public void biozFeatureReady(@NonNull String s) {

}

@Override
public void hrFeatureReady(String s) {
public void hrFeatureReady(@NonNull String s) {
Log.d(TAG, "HR Feature ready " + s);
}

@Override
public void disInformationReceived(String s, UUID u, String s1) {
if( u.equals(UUID.fromString("00002a28-0000-1000-8000-00805f9b34fb"))) {
public void disInformationReceived(@NonNull String s, @NonNull UUID u, @NonNull String s1) {
if (u.equals(UUID.fromString("00002a28-0000-1000-8000-00805f9b34fb"))) {
String msg = "Firmware: " + s1.trim();
Log.d(TAG, "Firmware: " + s + " " + s1.trim());
textViewFW.append(msg + "\n");
}
}

@Override
public void batteryLevelReceived(String s, int i) {
public void batteryLevelReceived(@NonNull String s, int i) {
String msg = "ID: " + s + "\nBattery level: " + i;
Log.d(TAG, "Battery level " + s + " " + i);
// Toast.makeText(classContext, msg, Toast.LENGTH_LONG).show();
textViewFW.append(msg + "\n");
}

@Override
public void hrNotificationReceived(String s,
PolarHrData polarHrData) {
public void hrNotificationReceived(@NonNull String s, @NonNull PolarHrData polarHrData) {
Log.d(TAG, "HR " + polarHrData.hr);
textViewHR.setText(String.valueOf(polarHrData.hr));
}

@Override
public void polarFtpFeatureReady(String s) {
public void polarFtpFeatureReady(@NonNull String s) {
Log.d(TAG, "Polar FTP ready " + s);
}
});
try {
api.connectToDevice(DEVICE_ID);
} catch (PolarInvalidArgument a){
api.connectToDevice(deviceId);
} catch (PolarInvalidArgument a) {
a.printStackTrace();
}

plotter = new Plotter(this, "ECG");
plotter = new Plotter("ECG");
plotter.setListener(this);

plot.addSeries(plotter.getSeries(), plotter.getFormatter());
Expand All @@ -167,37 +164,24 @@ public void onDestroy() {
public void streamECG() {
if (ecgDisposable == null) {
ecgDisposable =
api.requestEcgSettings(DEVICE_ID).toFlowable().flatMap(new Function<PolarSensorSetting, Publisher<PolarEcgData>>() {
@Override
public Publisher<PolarEcgData> apply(PolarSensorSetting sensorSetting) throws Exception {
return api.startEcgStreaming(DEVICE_ID,
sensorSetting.maxSettings());
}
}).observeOn(AndroidSchedulers.mainThread()).subscribe(
new Consumer<PolarEcgData>() {
@Override
public void accept(PolarEcgData polarEcgData) throws Exception {
Log.d(TAG, "ecg update");
for (Integer data : polarEcgData.samples) {
plotter.sendSingleSample((float) ((float) data / 1000.0));
}
}
},
new Consumer<Throwable>() {
@Override
public void accept(Throwable throwable) throws Exception {
Log.e(TAG,
"" + throwable.getLocalizedMessage());
ecgDisposable = null;
}
},
new Action() {
@Override
public void run() throws Exception {
Log.d(TAG, "complete");
}
}
);
api.requestEcgSettings(deviceId)
.toFlowable()
.flatMap((Function<PolarSensorSetting, Publisher<PolarEcgData>>) sensorSetting -> api.startEcgStreaming(deviceId, sensorSetting.maxSettings()))
.observeOn(AndroidSchedulers.mainThread())
.subscribe(
polarEcgData -> {
Log.d(TAG, "ecg update");
for (Integer data : polarEcgData.samples) {
plotter.sendSingleSample((float) ((float) data / 1000.0));
}
},
throwable -> {
Log.e(TAG,
"" + throwable.getLocalizedMessage());
ecgDisposable = null;
},
() -> Log.d(TAG, "complete")
);
} else {
// NOTE stops streaming if it is "running"
ecgDisposable.dispose();
Expand All @@ -207,11 +191,6 @@ public void run() throws Exception {

@Override
public void update() {
runOnUiThread(new Runnable() {
@Override
public void run() {
plot.redraw();
}
});
runOnUiThread(() -> plot.redraw());
}
}
Loading

0 comments on commit b2d662c

Please sign in to comment.