diff --git a/.gitignore b/.gitignore index 49c42a75..4a239692 100644 --- a/.gitignore +++ b/.gitignore @@ -2,11 +2,5 @@ *.iml build demos/**/libs/ -.gradle -gradle -gradlew -gradlew.bat -.idea -local.properties project.xcworkspace xcuserdata diff --git a/demos/Android-Demos/PolarSDK-ECG-HR-Demo/app/build.gradle b/demos/Android-Demos/PolarSDK-ECG-HR-Demo/app/build.gradle index d78027e3..d873a8bb 100644 --- a/demos/Android-Demos/PolarSDK-ECG-HR-Demo/app/build.gradle +++ b/demos/Android-Demos/PolarSDK-ECG-HR-Demo/app/build.gradle @@ -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 { @@ -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' } diff --git a/demos/Android-Demos/PolarSDK-ECG-HR-Demo/app/src/androidTest/java/com/polar/polarsdkecghrdemo/ExampleInstrumentedTest.java b/demos/Android-Demos/PolarSDK-ECG-HR-Demo/app/src/androidTest/java/com/polar/polarsdkecghrdemo/ExampleInstrumentedTest.java index 95dfe313..aa32ca33 100644 --- a/demos/Android-Demos/PolarSDK-ECG-HR-Demo/app/src/androidTest/java/com/polar/polarsdkecghrdemo/ExampleInstrumentedTest.java +++ b/demos/Android-Demos/PolarSDK-ECG-HR-Demo/app/src/androidTest/java/com/polar/polarsdkecghrdemo/ExampleInstrumentedTest.java @@ -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; diff --git a/demos/Android-Demos/PolarSDK-ECG-HR-Demo/app/src/main/AndroidManifest.xml b/demos/Android-Demos/PolarSDK-ECG-HR-Demo/app/src/main/AndroidManifest.xml index 1439498e..aac1f0ca 100755 --- a/demos/Android-Demos/PolarSDK-ECG-HR-Demo/app/src/main/AndroidManifest.xml +++ b/demos/Android-Demos/PolarSDK-ECG-HR-Demo/app/src/main/AndroidManifest.xml @@ -2,9 +2,9 @@ - - - + + + + android:label="@string/app_name" + android:screenOrientation="portrait"> @@ -24,12 +25,12 @@ - + android:label="@string/ecg_name" + android:screenOrientation="portrait"/> - + android:label="@string/hr_name" + android:screenOrientation="portrait"/> diff --git a/demos/Android-Demos/PolarSDK-ECG-HR-Demo/app/src/main/java/com/polar/polarsdkecghrdemo/ECGActivity.java b/demos/Android-Demos/PolarSDK-ECG-HR-Demo/app/src/main/java/com/polar/polarsdkecghrdemo/ECGActivity.java index 06480db2..39953d55 100755 --- a/demos/Android-Demos/PolarSDK-ECG-HR-Demo/app/src/main/java/com/polar/polarsdkecghrdemo/ECGActivity.java +++ b/demos/Android-Demos/PolarSDK-ECG-HR-Demo/app/src/main/java/com/polar/polarsdkecghrdemo/ECGActivity.java @@ -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); @@ -65,57 +65,55 @@ 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"); @@ -123,7 +121,7 @@ public void disInformationReceived(String s, UUID u, String s1) { } @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(); @@ -131,24 +129,23 @@ public void batteryLevelReceived(String s, int i) { } @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()); @@ -167,37 +164,24 @@ public void onDestroy() { public void streamECG() { if (ecgDisposable == null) { ecgDisposable = - api.requestEcgSettings(DEVICE_ID).toFlowable().flatMap(new Function>() { - @Override - public Publisher apply(PolarSensorSetting sensorSetting) throws Exception { - return api.startEcgStreaming(DEVICE_ID, - sensorSetting.maxSettings()); - } - }).observeOn(AndroidSchedulers.mainThread()).subscribe( - new Consumer() { - @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() { - @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>) 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(); @@ -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()); } } diff --git a/demos/Android-Demos/PolarSDK-ECG-HR-Demo/app/src/main/java/com/polar/polarsdkecghrdemo/HRActivity.java b/demos/Android-Demos/PolarSDK-ECG-HR-Demo/app/src/main/java/com/polar/polarsdkecghrdemo/HRActivity.java index cf32d5a8..3f2268a5 100755 --- a/demos/Android-Demos/PolarSDK-ECG-HR-Demo/app/src/main/java/com/polar/polarsdkecghrdemo/HRActivity.java +++ b/demos/Android-Demos/PolarSDK-ECG-HR-Demo/app/src/main/java/com/polar/polarsdkecghrdemo/HRActivity.java @@ -2,12 +2,14 @@ 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.XYGraphWidget; @@ -17,31 +19,27 @@ import java.util.List; import java.util.UUID; -import io.reactivex.rxjava3.disposables.Disposable; 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.PolarHrData; -import polar.com.sdk.api.errors.PolarInvalidArgument; public class HRActivity extends AppCompatActivity implements PlotterListener { - + private static final String TAG = "HRActivity"; private XYPlot plot; private TimePlotter plotter; - - TextView textViewHR, textViewFW; - private String TAG = "Polar_HRActivity"; - public PolarBleApi api; - private Disposable ecgDisposable = null; - private Context classContext = this; - private String DEVICE_ID; + private TextView textViewHR; + private TextView textViewFW; + private PolarBleApi api; + private final Context classContext = this; @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_hr); - DEVICE_ID = getIntent().getStringExtra("id"); + String deviceId = getIntent().getStringExtra("id"); textViewHR = findViewById(R.id.info2); textViewFW = findViewById(R.id.fw2); @@ -58,56 +56,56 @@ 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(); } @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); } @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"); @@ -115,7 +113,7 @@ public void disInformationReceived(String s, UUID u, String s1) { } @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(); @@ -123,11 +121,11 @@ public void batteryLevelReceived(String s, int i) { } @Override - public void hrNotificationReceived(String s, - PolarHrData polarHrData) { + public void hrNotificationReceived(@NonNull String s, + @NonNull PolarHrData polarHrData) { Log.d(TAG, "HR " + polarHrData.hr); List rrsMs = polarHrData.rrsMs; - String msg = String.valueOf(polarHrData.hr) + "\n"; + String msg = polarHrData.hr + "\n"; for (int i : rrsMs) { msg += i + ","; } @@ -139,25 +137,23 @@ public void hrNotificationReceived(String s, } @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 TimePlotter(this, "HR/RR"); + plotter = new TimePlotter(); plotter.setListener(this); plot.addSeries(plotter.getHrSeries(), plotter.getHrFormatter()); plot.addSeries(plotter.getRrSeries(), plotter.getRrFormatter()); - plot.setRangeBoundaries(50, 100, - BoundaryMode.AUTO); - plot.setDomainBoundaries(0, 360000, - BoundaryMode.AUTO); + plot.setRangeBoundaries(50, 100, BoundaryMode.AUTO); + plot.setDomainBoundaries(0, 360000, BoundaryMode.AUTO); // Left labels will increment by 10 plot.setRangeStep(StepMode.INCREMENT_BY_VAL, 10); plot.setDomainStep(StepMode.INCREMENT_BY_VAL, 60000); @@ -175,11 +171,6 @@ public void onDestroy() { } public void update() { - runOnUiThread(new Runnable() { - @Override - public void run() { - plot.redraw(); - } - }); + runOnUiThread(() -> plot.redraw()); } } diff --git a/demos/Android-Demos/PolarSDK-ECG-HR-Demo/app/src/main/java/com/polar/polarsdkecghrdemo/MainActivity.java b/demos/Android-Demos/PolarSDK-ECG-HR-Demo/app/src/main/java/com/polar/polarsdkecghrdemo/MainActivity.java index ecce2ed1..5ae0d293 100755 --- a/demos/Android-Demos/PolarSDK-ECG-HR-Demo/app/src/main/java/com/polar/polarsdkecghrdemo/MainActivity.java +++ b/demos/Android-Demos/PolarSDK-ECG-HR-Demo/app/src/main/java/com/polar/polarsdkecghrdemo/MainActivity.java @@ -1,15 +1,11 @@ package com.polar.polarsdkecghrdemo; import android.Manifest; -import android.app.Activity; import android.bluetooth.BluetoothAdapter; import android.content.Context; -import android.content.DialogInterface; import android.content.Intent; import android.content.SharedPreferences; import android.os.Build; -import android.support.v7.app.AlertDialog; -import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.text.InputType; import android.util.Log; @@ -19,12 +15,13 @@ import android.widget.EditText; import android.widget.Toast; +import androidx.appcompat.app.AlertDialog; +import androidx.appcompat.app.AppCompatActivity; public class MainActivity extends AppCompatActivity { - - private String TAG = "Polar_MainActivity"; - private String sharedPrefsKey = "polar_device_id"; - private String DEVICE_ID; + private static final String TAG = "Polar_MainActivity"; + private static final String SHARED_PREFS_KEY = "polar_device_id"; + private String deviceId; SharedPreferences sharedPreferences; @Override @@ -37,28 +34,28 @@ protected void onCreate(Bundle savedInstanceState) { public void onClickConnect(View view) { checkBT(); - DEVICE_ID = sharedPreferences.getString(sharedPrefsKey,""); - Log.d(TAG,DEVICE_ID); - if(DEVICE_ID.equals("")){ + deviceId = sharedPreferences.getString(SHARED_PREFS_KEY, ""); + Log.d(TAG, deviceId); + if (deviceId.equals("")) { showDialog(view); } else { - Toast.makeText(this,getString(R.string.connecting) + " " + DEVICE_ID,Toast.LENGTH_SHORT).show(); + Toast.makeText(this, getString(R.string.connecting) + " " + deviceId, Toast.LENGTH_SHORT).show(); Intent intent = new Intent(this, ECGActivity.class); - intent.putExtra("id", DEVICE_ID); + intent.putExtra("id", deviceId); startActivity(intent); } } public void onClickConnect2(View view) { checkBT(); - DEVICE_ID = sharedPreferences.getString(sharedPrefsKey,""); - Log.d(TAG,DEVICE_ID); - if(DEVICE_ID.equals("")){ + deviceId = sharedPreferences.getString(SHARED_PREFS_KEY, ""); + Log.d(TAG, deviceId); + if (deviceId.equals("")) { showDialog(view); } else { - Toast.makeText(this,getString(R.string.connecting) + " " + DEVICE_ID,Toast.LENGTH_SHORT).show(); + Toast.makeText(this, getString(R.string.connecting) + " " + deviceId, Toast.LENGTH_SHORT).show(); Intent intent = new Intent(this, HRActivity.class); - intent.putExtra("id", DEVICE_ID); + intent.putExtra("id", deviceId); startActivity(intent); } } @@ -67,35 +64,27 @@ public void onClickChangeID(View view) { showDialog(view); } - public void showDialog(View view){ + public void showDialog(View view) { AlertDialog.Builder dialog = new AlertDialog.Builder(this, R.style.PolarTheme); dialog.setTitle("Enter your Polar device's ID"); - View viewInflated = LayoutInflater.from(getApplicationContext()).inflate(R.layout.device_id_dialog_layout,(ViewGroup) view.getRootView() , false); + View viewInflated = LayoutInflater.from(getApplicationContext()).inflate(R.layout.device_id_dialog_layout, (ViewGroup) view.getRootView(), false); final EditText input = viewInflated.findViewById(R.id.input); input.setInputType(InputType.TYPE_CLASS_TEXT); dialog.setView(viewInflated); - dialog.setPositiveButton("OK", new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - DEVICE_ID = input.getText().toString(); - SharedPreferences.Editor editor = sharedPreferences.edit(); - editor.putString(sharedPrefsKey, DEVICE_ID); - editor.apply(); - } - }); - dialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - dialog.cancel(); - } + dialog.setPositiveButton("OK", (dialog1, which) -> { + deviceId = input.getText().toString(); + SharedPreferences.Editor editor = sharedPreferences.edit(); + editor.putString(SHARED_PREFS_KEY, deviceId); + editor.apply(); }); + dialog.setNegativeButton("Cancel", (dialog12, which) -> dialog12.cancel()); dialog.show(); } - public void checkBT(){ + public void checkBT() { BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); if (mBluetoothAdapter != null && !mBluetoothAdapter.isEnabled()) { Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); @@ -103,8 +92,8 @@ public void checkBT(){ } //requestPermissions() method needs to be called when the build SDK version is 23 or above - if(Build.VERSION.SDK_INT >= 23){ - this.requestPermissions(new String[]{Manifest.permission.ACCESS_COARSE_LOCATION,Manifest.permission.ACCESS_FINE_LOCATION},1); + if (Build.VERSION.SDK_INT >= 23) { + this.requestPermissions(new String[]{Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION}, 1); } } } diff --git a/demos/Android-Demos/PolarSDK-ECG-HR-Demo/app/src/main/java/com/polar/polarsdkecghrdemo/Plotter.java b/demos/Android-Demos/PolarSDK-ECG-HR-Demo/app/src/main/java/com/polar/polarsdkecghrdemo/Plotter.java index af5a300c..a1c4728e 100755 --- a/demos/Android-Demos/PolarSDK-ECG-HR-Demo/app/src/main/java/com/polar/polarsdkecghrdemo/Plotter.java +++ b/demos/Android-Demos/PolarSDK-ECG-HR-Demo/app/src/main/java/com/polar/polarsdkecghrdemo/Plotter.java @@ -1,53 +1,45 @@ package com.polar.polarsdkecghrdemo; -import android.content.Context; import android.graphics.Paint; import com.androidplot.xy.AdvancedLineAndPointRenderer; import com.androidplot.xy.SimpleXYSeries; import com.androidplot.xy.XYSeries; + import java.util.Arrays; public class Plotter { - - String title; - private String TAG = "Polar_Plotter"; + private static final String TAG = "Plotter"; private PlotterListener listener; - private Context context; - private Number[] plotNumbers = new Number[500]; - private FadeFormatter formatter; - private XYSeries series; + private final Number[] plotNumbers = new Number[500]; + private final FadeFormatter formatter; + private final XYSeries series; private int dataIndex; - - public Plotter(Context context, String title){ - this.context = context; - this.title = title; - - for(int i = 0; i < plotNumbers.length - 1; i++){ + public Plotter(String title) { + for (int i = 0; i < plotNumbers.length - 1; i++) { plotNumbers[i] = 60; } formatter = new FadeFormatter(800); formatter.setLegendIconEnabled(false); - series = new SimpleXYSeries(Arrays.asList(plotNumbers), SimpleXYSeries.ArrayFormat.Y_VALS_ONLY, title); } - public SimpleXYSeries getSeries(){ + public SimpleXYSeries getSeries() { return (SimpleXYSeries) series; } - public FadeFormatter getFormatter(){ + public FadeFormatter getFormatter() { return formatter; } - public void sendSingleSample(float mV){ + public void sendSingleSample(float mV) { plotNumbers[dataIndex] = mV; - if(dataIndex >= plotNumbers.length - 1){ + if (dataIndex >= plotNumbers.length - 1) { dataIndex = 0; } - if(dataIndex < plotNumbers.length - 1){ + if (dataIndex < plotNumbers.length - 1) { plotNumbers[dataIndex + 1] = null; } @@ -56,13 +48,13 @@ public void sendSingleSample(float mV){ listener.update(); } - public void setListener(PlotterListener listener){ + public void setListener(PlotterListener listener) { this.listener = listener; } //Custom paint stroke to generate a "fade" effect public static class FadeFormatter extends AdvancedLineAndPointRenderer.Formatter { - private int trailSize; + private final int trailSize; public FadeFormatter(int trailSize) { this.trailSize = trailSize; @@ -72,14 +64,14 @@ public FadeFormatter(int trailSize) { public Paint getLinePaint(int thisIndex, int latestIndex, int seriesSize) { // offset from the latest index: int offset; - if(thisIndex > latestIndex) { + if (thisIndex > latestIndex) { offset = latestIndex + (seriesSize - thisIndex); } else { - offset = latestIndex - thisIndex; + offset = latestIndex - thisIndex; } float scale = 255f / trailSize; int alpha = (int) (255 - (offset * scale)); - getLinePaint().setAlpha(alpha > 0 ? alpha : 0); + getLinePaint().setAlpha(Math.max(alpha, 0)); return getLinePaint(); } } diff --git a/demos/Android-Demos/PolarSDK-ECG-HR-Demo/app/src/main/java/com/polar/polarsdkecghrdemo/PlotterListener.java b/demos/Android-Demos/PolarSDK-ECG-HR-Demo/app/src/main/java/com/polar/polarsdkecghrdemo/PlotterListener.java index a7be0d2d..dc090556 100755 --- a/demos/Android-Demos/PolarSDK-ECG-HR-Demo/app/src/main/java/com/polar/polarsdkecghrdemo/PlotterListener.java +++ b/demos/Android-Demos/PolarSDK-ECG-HR-Demo/app/src/main/java/com/polar/polarsdkecghrdemo/PlotterListener.java @@ -1,5 +1,5 @@ package com.polar.polarsdkecghrdemo; -public interface PlotterListener{ +public interface PlotterListener { void update(); } diff --git a/demos/Android-Demos/PolarSDK-ECG-HR-Demo/app/src/main/java/com/polar/polarsdkecghrdemo/TimePlotter.java b/demos/Android-Demos/PolarSDK-ECG-HR-Demo/app/src/main/java/com/polar/polarsdkecghrdemo/TimePlotter.java index f4c48011..e684ef1b 100755 --- a/demos/Android-Demos/PolarSDK-ECG-HR-Demo/app/src/main/java/com/polar/polarsdkecghrdemo/TimePlotter.java +++ b/demos/Android-Demos/PolarSDK-ECG-HR-Demo/app/src/main/java/com/polar/polarsdkecghrdemo/TimePlotter.java @@ -1,6 +1,5 @@ package com.polar.polarsdkecghrdemo; -import android.content.Context; import android.graphics.Color; import com.androidplot.xy.LineAndPointFormatter; @@ -17,13 +16,11 @@ * Implements two series for HR and RR using time for the x values. */ public class TimePlotter { + private static final String TAG = "TimePlotter"; private static final int NVALS = 300; // 5 min - - String title; - private String TAG = "Polar_Plotter"; - private double RR_SCALE = .1; + private static final double RR_SCALE = .1; private PlotterListener listener; - private Context context; + private XYSeriesFormatter hrFormatter; private XYSeriesFormatter rrFormatter; private SimpleXYSeries hrSeries; @@ -33,9 +30,7 @@ public class TimePlotter { private Double[] xRrVals = new Double[NVALS]; private Double[] yRrVals = new Double[NVALS]; - public TimePlotter(Context context, String title) { - this.context = context; - this.title = title; // Not used + public TimePlotter() { Date now = new Date(); double endTime = now.getTime(); double startTime = endTime - NVALS * 1000; @@ -43,33 +38,26 @@ public TimePlotter(Context context, String title) { // Specify initial values to keep it from auto sizing for (int i = 0; i < NVALS; i++) { - xHrVals[i] = new Double(startTime + i * delta); - yHrVals[i] = new Double(60); - xRrVals[i] = new Double(startTime + i * delta); - yRrVals[i] = new Double(100); + xHrVals[i] = startTime + i * delta; + yHrVals[i] = 60d; + xRrVals[i] = startTime + i * delta; + yRrVals[i] = 100d; } - hrFormatter = new LineAndPointFormatter(Color.RED, - null, null, null); + hrFormatter = new LineAndPointFormatter(Color.RED, null, null, null); hrFormatter.setLegendIconEnabled(false); - hrSeries = new SimpleXYSeries(Arrays.asList(xHrVals), - Arrays.asList(yHrVals), - "HR"); - - rrFormatter = new LineAndPointFormatter(Color.BLUE, - null, null, null); + hrSeries = new SimpleXYSeries(Arrays.asList(xHrVals), Arrays.asList(yHrVals), "HR"); + rrFormatter = new LineAndPointFormatter(Color.BLUE, null, null, null); rrFormatter.setLegendIconEnabled(false); - rrSeries = new SimpleXYSeries(Arrays.asList(xRrVals), - Arrays.asList(yRrVals), - "HR"); + rrSeries = new SimpleXYSeries(Arrays.asList(xRrVals), Arrays.asList(yRrVals), "HR"); } public SimpleXYSeries getHrSeries() { - return (SimpleXYSeries) hrSeries; + return hrSeries; } public SimpleXYSeries getRrSeries() { - return (SimpleXYSeries) rrSeries; + return rrSeries; } public XYSeriesFormatter getHrFormatter() { @@ -94,8 +82,8 @@ public void addValues(PolarHrData polarHrData) { yHrVals[i] = yHrVals[i + 1]; hrSeries.setXY(xHrVals[i], yHrVals[i], i); } - xHrVals[NVALS - 1] = new Double(time); - yHrVals[NVALS - 1] = new Double(polarHrData.hr); + xHrVals[NVALS - 1] = (double) time; + yHrVals[NVALS - 1] = (double) polarHrData.hr; hrSeries.setXY(xHrVals[NVALS - 1], yHrVals[NVALS - 1], NVALS - 1); // Do RR @@ -123,8 +111,8 @@ public void addValues(PolarHrData polarHrData) { double rr; for (int i = NVALS - nRrVals; i < NVALS; i++) { rr = RR_SCALE * rrsMs.get(index++); - xRrVals[i] = new Double(time - totalRR); - yRrVals[i] = new Double(rr); + xRrVals[i] = time - totalRR; + yRrVals[i] = rr; totalRR -= rr; rrSeries.setXY(xRrVals[i], yRrVals[i], i); } diff --git a/demos/Android-Demos/PolarSDK-ECG-HR-Demo/app/src/main/res/layout/activity_ecg.xml b/demos/Android-Demos/PolarSDK-ECG-HR-Demo/app/src/main/res/layout/activity_ecg.xml index 60a35f63..e2b87d01 100755 --- a/demos/Android-Demos/PolarSDK-ECG-HR-Demo/app/src/main/res/layout/activity_ecg.xml +++ b/demos/Android-Demos/PolarSDK-ECG-HR-Demo/app/src/main/res/layout/activity_ecg.xml @@ -1,8 +1,6 @@ - @@ -13,9 +11,9 @@ android:layout_marginStart="8dp" android:layout_marginEnd="8dp" android:layout_marginBottom="8dp" - android:textSize="20sp" android:textColor="#000000" - app:layout_constraintBottom_toBottomOf="@+id/info" + android:textSize="20sp" + app:layout_constraintBottom_toBottomOf="@+id/info" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" @@ -29,8 +27,8 @@ android:layout_marginEnd="8dp" android:layout_marginBottom="8dp" android:textAlignment="center" - android:textSize="30sp" android:textColor="#C00000" + android:textSize="30sp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" @@ -43,10 +41,10 @@ android:layout_width="fill_parent" android:layout_height="304dp" android:layout_marginTop="345dp" - app:graphMarginTop="12dp" + app:graphBackgroundColor="@color/colorAccent" app:graphMarginBottom="12dp" + app:graphMarginTop="12dp" app:gridBackgroundColor="@color/colorAccent" - app:graphBackgroundColor="@color/colorAccent" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.0" @@ -58,4 +56,4 @@ app:renderMode="use_background_thread" app:title="" /> - \ No newline at end of file + \ No newline at end of file diff --git a/demos/Android-Demos/PolarSDK-ECG-HR-Demo/app/src/main/res/layout/activity_hr.xml b/demos/Android-Demos/PolarSDK-ECG-HR-Demo/app/src/main/res/layout/activity_hr.xml index 93a4d682..c16958ea 100755 --- a/demos/Android-Demos/PolarSDK-ECG-HR-Demo/app/src/main/res/layout/activity_hr.xml +++ b/demos/Android-Demos/PolarSDK-ECG-HR-Demo/app/src/main/res/layout/activity_hr.xml @@ -1,8 +1,6 @@ - @@ -13,8 +11,8 @@ android:layout_marginStart="8dp" android:layout_marginEnd="8dp" android:layout_marginBottom="8dp" - android:textSize="20sp" android:textColor="#000000" + android:textSize="20sp" app:layout_constraintBottom_toBottomOf="@+id/info2" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" @@ -29,8 +27,8 @@ android:layout_marginEnd="8dp" android:layout_marginBottom="8dp" android:textAlignment="center" - android:textSize="30sp" android:textColor="#C00000" + android:textSize="30sp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" @@ -43,35 +41,31 @@ android:layout_width="fill_parent" android:layout_height="304dp" android:layout_marginTop="345dp" + app:backgroundColor="@color/colorAccent" + app:graphBackgroundColor="@color/colorAccent" + app:graphMarginBottom="12dp" + app:graphMarginLeft="30dp" + app:graphMarginRight="5dp" + app:graphMarginTop="20dp" + app:gridBackgroundColor="@color/colorAccent" + app:gridInsetLeft="25dp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintHorizontal_bias="0.0" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" app:layout_constraintVertical_bias="1.0" - - app:paddingTop="5dp" + app:lineLabels="left" app:paddingBottom="5dp" app:paddingLeft="5dp" app:paddingRight="5dp" - app:backgroundColor="@color/colorAccent" - - app:gridBackgroundColor="@color/colorAccent" - app:graphBackgroundColor="@color/colorAccent" - app:graphMarginTop="20dp" - app:graphMarginBottom="12dp" - app:graphMarginLeft="30dp" - app:graphMarginRight="5dp" - app:gridInsetLeft="25dp" - app:title="@string/hr_title" - app:titleTextColor="#000000" - app:titleTextSize="15dp" + app:paddingTop="5dp" app:rangeTitle="@string/hr_range_title" app:rangeTitleTextColor="#000000" app:rangeTitleTextSize="14dp" - - app:lineLabels="left" app:renderMode="use_background_thread" - /> + app:title="@string/hr_title" + app:titleTextColor="#000000" + app:titleTextSize="15dp" /> - \ No newline at end of file + \ No newline at end of file diff --git a/demos/Android-Demos/PolarSDK-ECG-HR-Demo/app/src/main/res/layout/activity_main.xml b/demos/Android-Demos/PolarSDK-ECG-HR-Demo/app/src/main/res/layout/activity_main.xml index c0b5e648..e6aa002a 100755 --- a/demos/Android-Demos/PolarSDK-ECG-HR-Demo/app/src/main/res/layout/activity_main.xml +++ b/demos/Android-Demos/PolarSDK-ECG-HR-Demo/app/src/main/res/layout/activity_main.xml @@ -1,5 +1,5 @@ - + app:layout_constraintTop_toTopOf="parent" />