Some initial heartrate support #205

(not visible to user yet)
This commit is contained in:
cpfeiffer 2016-02-26 00:30:57 +01:00
parent 0b568df8de
commit a10c6f3b9f
3 changed files with 37 additions and 3 deletions

View File

@ -2,32 +2,42 @@ package nodomain.freeyourgadget.gadgetbridge.impl;
import nodomain.freeyourgadget.gadgetbridge.devices.SampleProvider;
import nodomain.freeyourgadget.gadgetbridge.model.ActivitySample;
import nodomain.freeyourgadget.gadgetbridge.util.DateTimeUtils;
public class GBActivitySample implements ActivitySample {
private final int timestamp;
private final SampleProvider provider;
private final short intensity;
private final short steps;
private final short heartrate;
private final byte type;
public GBActivitySample(SampleProvider provider, int timestamp, short intensity, short steps, byte type) {
this(provider, timestamp, intensity, steps, (short) 0, type);
}
public GBActivitySample(SampleProvider provider, int timestamp, short intensity, short steps, short heartrate, byte type) {
this.timestamp = timestamp;
this.provider = provider;
this.intensity = intensity;
this.steps = steps;
this.heartrate = heartrate;
this.type = type;
validate();
}
private void validate() {
if (steps < 0) {
throw new IllegalArgumentException("steps must be > 0");
throw new IllegalArgumentException("steps must be >= 0");
}
if (intensity < 0) {
throw new IllegalArgumentException("intensity must be > 0");
throw new IllegalArgumentException("intensity must be >= 0");
}
if (timestamp < 0) {
throw new IllegalArgumentException("timestamp must be > 0");
throw new IllegalArgumentException("timestamp must be >= 0");
}
if (heartrate < 0) {
throw new IllegalArgumentException("heartrate must be >= 0");
}
}
@ -65,4 +75,20 @@ public class GBActivitySample implements ActivitySample {
public int getKind() {
return getProvider().normalizeType(getRawKind());
}
@Override
public short getHeartRate() {
return heartrate;
}
@Override
public String toString() {
return "GBActivitySample{" +
"timestamp=" + DateTimeUtils.formatDateTime(DateTimeUtils.parseTimeStamp(timestamp)) +
", intensity=" + getIntensity() +
", steps=" + getSteps() +
", heartrate=" + getHeartRate() +
", type=" + getKind() +
'}';
}
}

View File

@ -41,4 +41,6 @@ public interface ActivitySample {
* Returns the number of steps performed during the period of this sample
*/
short getSteps();
short getHeartRate();
}

View File

@ -49,4 +49,10 @@ public class DateTimeUtils {
Date newDate = cal.getTime();
return newDate;
}
public static Date parseTimeStamp(int timestamp) {
GregorianCalendar cal = (GregorianCalendar) GregorianCalendar.getInstance();
cal.setTimeInMillis(timestamp * 1000L); // make sure it's converted to long
return cal.getTime();
}
}