Skip to content

Commit

Permalink
#109 Fixed several sonarqube issues
Browse files Browse the repository at this point in the history
  • Loading branch information
thomcz committed Feb 2, 2017
1 parent 8d9ec0e commit 3ea080a
Show file tree
Hide file tree
Showing 126 changed files with 2,241 additions and 2,347 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ android {
applicationId "hrv.band.aurora"
minSdkVersion 19
targetSdkVersion 25
versionCode 4
versionName "1.1"
versionCode 5
versionName "1.11"

testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/androidTest/java/hrv/band/app/ApplicationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import java.util.Date;

import hrv.band.app.control.HRVParameters;
import hrv.band.app.storage.SQLite.SQLController;
import hrv.band.app.storage.sqlite.SQLController;

/**
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
Expand Down
38 changes: 24 additions & 14 deletions app/src/main/java/hrv/band/app/Control/HRVParameters.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,24 @@ public class HRVParameters implements Parcelable {
private double baevsky;
private double[] rrIntervals;
private double rating;
private MeasurementCategoryAdapter.MeasureCategory category = MeasurementCategoryAdapter.MeasureCategory.GENERAL;
private MeasurementCategoryAdapter.MeasureCategory category;
private String note;

public HRVParameters() {}
// this is used to regenerate your object. All Parcelables must have a CREATOR that implements these two methods
public static final Parcelable.Creator<HRVParameters> CREATOR = new Parcelable.Creator<HRVParameters>() {
@Override
public HRVParameters createFromParcel(Parcel in) {
return new HRVParameters(in);
}
@Override
public HRVParameters[] newArray(int size) {
return new HRVParameters[size];
}
};

public HRVParameters() {
//the standard constructor
}

// example constructor that takes a Parcel and gives you an object populated with it's values
private HRVParameters(Parcel in) {
Expand Down Expand Up @@ -67,6 +81,8 @@ public HRVParameters(Date time, double sdsd, double sd1, double sd2, double lf,
this.sdnn = sdnn;
this.baevsky = baevsky;
this.rrIntervals = rrIntervals;
this.category = MeasurementCategoryAdapter.MeasureCategory.GENERAL;
this.note = "";
}

@Override
Expand All @@ -93,18 +109,6 @@ public void writeToParcel(Parcel out, int flags) {
out.writeString(note);
}

// this is used to regenerate your object. All Parcelables must have a CREATOR that implements these two methods
public static final Parcelable.Creator<HRVParameters> CREATOR = new Parcelable.Creator<HRVParameters>() {
@Override
public HRVParameters createFromParcel(Parcel in) {
return new HRVParameters(in);
}
@Override
public HRVParameters[] newArray(int size) {
return new HRVParameters[size];
}
};

public Date getTime() {
return time;
}
Expand Down Expand Up @@ -202,6 +206,9 @@ public void setRating(double rating) {
}

public MeasurementCategoryAdapter.MeasureCategory getCategory() {
if (category == null) {
return MeasurementCategoryAdapter.MeasureCategory.GENERAL;
}
return category;
}

Expand All @@ -210,6 +217,9 @@ public void setCategory(MeasurementCategoryAdapter.MeasureCategory category) {
}

public String getNote() {
if (note == null) {
return "";
}
return note;
}

Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/hrv/band/app/devices/HRVDeviceStatus.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package hrv.band.app.devices;

/**
* Created by Julian on 03.01.2017.
* Copyright (c) 2017
* Created by Julian Martin on 03.01.2016.
*/

public enum HRVDeviceStatus {
CONNECTED,
DISCONNECTED,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package hrv.band.app.devices;

/**
* Created by Julian on 03.01.2017.
* Copyright (c) 2017
* Created by Julian Martin on 03.01.2016.
*/

public interface HRVRRDeviceListener {

void deviceStartedMeasurement();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
import java.util.List;

/**
* Created by Thomas on 13.06.2016.
* Copyright (c) 2017
* Created by Julian Martin on 03.01.2016.
*
* Collaborator Thomas Czogalik
*/
public abstract class HRVRRIntervalDevice implements HRVRRIntervalEventInitiator {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package hrv.band.app.devices;

/**
* Created by Julian on 02.01.2017.
* Copyright (c) 2017
* Created by Julian Martin on 03.01.2016.
*/

public class HRVRRIntervalEvent {

private double rr;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package hrv.band.app.devices;

/**
* Created by Julian on 02.01.2017.
* Observer class, that notifies listeners, when a new heart beat arises
* Copyright (c) 2017
* Created by Julian Martin on 03.01.2016.
*
* Observer class, that notifies listeners, when a new heart beat arises.
*/

interface HRVRRIntervalEventInitiator {

void notifyRRIntervalListeners(double rrValue);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package hrv.band.app.devices;

/**
* Created by Julian on 02.01.2017.
* Copyright (c) 2017
* Created by Julian Martin on 03.01.2016.
*/

public interface HRVRRIntervalListener {

void newRRInterval(HRVRRIntervalEvent event);
Expand Down
5 changes: 3 additions & 2 deletions app/src/main/java/hrv/band/app/devices/Interval.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import java.util.Date;

/**
* Created by Julian on 11.06.2016.
* Copyright (c) 2017
* Created by Julian Martin on 03.01.2016.
*/
public class Interval {

Expand All @@ -28,7 +29,7 @@ public double[] getRRInterval()
public void setRRInterval(Double[] rrInterval)
{
this.rrInterval = new double[rrInterval.length];
for (int i= 0; i < rrInterval.length;i++ ) {
for (int i = 0; i < rrInterval.length; i++ ) {
this.rrInterval[i] = rrInterval[i];
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@

import hrv.band.app.devices.HRVDeviceStatus;
import hrv.band.app.devices.HRVRRIntervalDevice;

/**
* Created by Julian on 29.12.2016.
* Copyright (c) 2017
* Created by Julian Martin on 29.12.2016.
*/
public class AntPlusRRDataDevice
extends HRVRRIntervalDevice
Expand Down Expand Up @@ -84,7 +84,7 @@ public List<Double> getRRIntervals() {

@Override
public void pauseMeasuring() {

stopMeasuring();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package hrv.band.app.devices.msband;
/**
* Created by Thomas on 13.06.2016.
*/

import android.app.Activity;
import android.os.AsyncTask;
import android.util.Log;

import com.microsoft.band.BandClient;
import com.microsoft.band.BandException;
Expand All @@ -15,7 +14,12 @@
import hrv.band.app.devices.HRVDeviceStatus;

/**
* Class that gets user-permission for measuring the heartrate (and rrIntervals)
* Copyright (c) 2017
* Created by Thomas Czogalik 13.06.2016.
*
* Collaborator Julian Martin
*
* Class that gets user-permission for measuring the heart rate (and rr intervals)
*/
class MSBandHeartRateConsentTask extends AsyncTask<Void, Void, Void> {

Expand Down Expand Up @@ -47,6 +51,7 @@ public void userAccepted(boolean consentGiven) {
msBandRRIntervalDevice.notifyDeviceError(msg);
}
} catch (BandException e) {
Log.e(e.getClass().getName(), "BandException", e);
String exceptionMessage;
switch (e.getErrorType()) {
case UNSUPPORTED_SDK_VERSION_ERROR:
Expand All @@ -62,6 +67,7 @@ public void userAccepted(boolean consentGiven) {
msBandRRIntervalDevice.notifyDeviceError(exceptionMessage);

} catch (Exception e) {
Log.e(e.getClass().getName(), "BandException", e);
msBandRRIntervalDevice.notifyDeviceError(e.getMessage());
}
return null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package hrv.band.app.devices.msband;

import android.app.Activity;
import android.util.Log;

import com.microsoft.band.BandClient;
import com.microsoft.band.BandClientManager;
Expand All @@ -19,7 +20,10 @@
import hrv.band.app.devices.HRVRRIntervalDevice;

/**
* Created by Thomas on 13.06.2016.
* Copyright (c) 2017
* Created by Thomas Czogalik 13.06.2016.
*
* Collaborator Julian Martin
*/
public class MSBandRRIntervalDevice extends HRVRRIntervalDevice {
private BandClient client;
Expand Down Expand Up @@ -58,7 +62,7 @@ public void stopMeasuring() {
client.getSensorManager().unregisterRRIntervalEventListener(mRRIntervalEventListener);
}
} catch (BandIOException e) {
e.printStackTrace();
Log.e(e.getClass().getName(), "BandIOException", e);
}
}

Expand All @@ -75,13 +79,11 @@ public void destroy() {
try {
client.disconnect().await();
} catch (InterruptedException | BandException e) {
// Do nothing as this is happening during destroy
Log.e(e.getClass().getName(), "InterruptedException | BandException", e);
}
}
}



@Override
public void connect(){
new MSBandHeartRateConsentTask(reference, this).execute();
Expand All @@ -93,7 +95,7 @@ public void connect(){
* @throws InterruptedException connection has dropped e.g.
* @throws BandException ohter stuff that should not happen
*/
public boolean getConnectedBandClient() throws InterruptedException, BandException {
boolean getConnectedBandClient() throws InterruptedException, BandException {
if (client == null) {
BandInfo[] devices = BandClientManager.getInstance().getPairedBands();
if (devices.length == 0) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,54 +1,51 @@
package hrv.band.app.devices.msband;

/**
* Created by Thomas on 13.06.2016.
*/

import android.os.AsyncTask;
import android.util.Log;

import com.microsoft.band.BandClient;
import com.microsoft.band.BandException;
import com.microsoft.band.UserConsent;
import com.microsoft.band.sensors.BandSensorManager;

//import hrv.band.app.view.UiHandlingUtil;

/**
* Class that meassures the RRInterval (get results via Eventhandler...)
* Copyright (c) 2017
* Created by Thomas Czogalik 13.06.2016.
*
* Collaborator Julian Martin
*
* Class that measures the RRInterval (get results via Eventhandler).
*/
class MSBandRRIntervalSubscriptionTask extends AsyncTask<Void, Void, Void> {

private final MSBandRRIntervalDevice msBandRRIntervalDevice;
public MSBandRRIntervalSubscriptionTask(MSBandRRIntervalDevice msBandRRIntervalDevice) {
MSBandRRIntervalSubscriptionTask(MSBandRRIntervalDevice msBandRRIntervalDevice) {
this.msBandRRIntervalDevice = msBandRRIntervalDevice;
}

//register eventhandler, so we can recieve the rrIntervals
@Override
protected Void doInBackground(Void... params) {
try {
if (msBandRRIntervalDevice.getConnectedBandClient()) {
BandClient client = msBandRRIntervalDevice.getClient();
int hardwareVersion = Integer.parseInt(client.getHardwareVersion().await());
if (hardwareVersion >= 20) {
BandSensorManager sensorManager = client.getSensorManager();
if (sensorManager.getCurrentHeartRateConsent() == UserConsent.GRANTED) {
sensorManager.registerRRIntervalEventListener(msBandRRIntervalDevice.getRRIntervalEventListener());
//msBandRRIntervalDevice.setupAnimation();
msBandRRIntervalDevice.notifyDeviceStartedMeasurement();
} else {
//msBandRRIntervalDevice.showConsentSnackbar("Please give consent to access heart rate data");
msBandRRIntervalDevice.connect();
}
} else {
msBandRRIntervalDevice.notifyDeviceError("The RR Interval sensor is only supported with MS Band 2.\n");
//UiHandlingUtil.showSnackbar("The RR Interval sensor is only supported with MS Band 2.\n");
}
} else {
msBandRRIntervalDevice.notifyDeviceError("Device isn't connected. Is bluetooth on and the device in range?\n");
//UiHandlingUtil.showSnackbar("Device isn't connected. Is bluetooth on and the device in range?\n");
}
if (!msBandRRIntervalDevice.getConnectedBandClient()) {
msBandRRIntervalDevice.notifyDeviceError("Device isn't connected. Is bluetooth on and the device in range?\n");
return null;
}
BandClient client = msBandRRIntervalDevice.getClient();
int hardwareVersion = Integer.parseInt(client.getHardwareVersion().await());
if (hardwareVersion < 20) {
msBandRRIntervalDevice.notifyDeviceError("The RR Interval sensor is only supported with MS Band 2.\n");
return null;
}
BandSensorManager sensorManager = client.getSensorManager();
if (sensorManager.getCurrentHeartRateConsent() != UserConsent.GRANTED) {
msBandRRIntervalDevice.connect();
return null;
}
sensorManager.registerRRIntervalEventListener(msBandRRIntervalDevice.getRRIntervalEventListener());
msBandRRIntervalDevice.notifyDeviceStartedMeasurement();
} catch (BandException e) {
Log.e(e.getClass().getName(), "BandException", e);
String exceptionMessage;
switch (e.getErrorType()) {
case UNSUPPORTED_SDK_VERSION_ERROR:
Expand All @@ -62,11 +59,10 @@ protected Void doInBackground(Void... params) {
break;
}
msBandRRIntervalDevice.notifyDeviceError(exceptionMessage);
//UiHandlingUtil.showSnackbar(exceptionMessage);

} catch (Exception e) {
Log.e(e.getClass().getName(), "Exception", e);
msBandRRIntervalDevice.notifyDeviceError(e.getMessage());
//UiHandlingUtil.showSnackbar(e.getMessage());
}
return null;
}
Expand Down
Loading

0 comments on commit 3ea080a

Please sign in to comment.