2015-08-03 23:09:49 +02:00
|
|
|
package nodomain.freeyourgadget.gadgetbridge.impl;
|
2015-05-30 17:28:03 +02:00
|
|
|
|
2015-08-03 23:09:49 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.devices.SampleProvider;
|
2015-07-27 23:49:53 +02:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.model.ActivitySample;
|
2016-02-26 00:30:57 +01:00
|
|
|
import nodomain.freeyourgadget.gadgetbridge.util.DateTimeUtils;
|
2015-05-30 21:52:29 +02:00
|
|
|
|
2015-07-27 23:49:53 +02:00
|
|
|
public class GBActivitySample implements ActivitySample {
|
2015-05-30 17:28:03 +02:00
|
|
|
private final int timestamp;
|
2015-07-27 23:49:53 +02:00
|
|
|
private final SampleProvider provider;
|
2015-05-30 17:28:03 +02:00
|
|
|
private final short intensity;
|
2015-07-27 23:49:53 +02:00
|
|
|
private final short steps;
|
2015-05-30 17:28:03 +02:00
|
|
|
private final byte type;
|
2016-02-26 23:45:17 +01:00
|
|
|
private final short customShortValue;
|
2015-05-30 17:28:03 +02:00
|
|
|
|
2015-07-27 23:49:53 +02:00
|
|
|
public GBActivitySample(SampleProvider provider, int timestamp, short intensity, short steps, byte type) {
|
2016-02-26 23:45:17 +01:00
|
|
|
this(provider, timestamp, intensity, steps, type, (short) 0);
|
2016-02-26 00:30:57 +01:00
|
|
|
}
|
|
|
|
|
2016-02-26 23:45:17 +01:00
|
|
|
public GBActivitySample(SampleProvider provider, int timestamp, short intensity, short steps, byte type, short customShortValue) {
|
2015-05-30 17:28:03 +02:00
|
|
|
this.timestamp = timestamp;
|
|
|
|
this.provider = provider;
|
|
|
|
this.intensity = intensity;
|
|
|
|
this.steps = steps;
|
2016-02-26 23:45:17 +01:00
|
|
|
this.customShortValue = customShortValue;
|
2015-05-30 17:28:03 +02:00
|
|
|
this.type = type;
|
2015-09-09 20:46:50 +02:00
|
|
|
validate();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void validate() {
|
|
|
|
if (steps < 0) {
|
2016-02-26 00:30:57 +01:00
|
|
|
throw new IllegalArgumentException("steps must be >= 0");
|
2015-09-09 20:46:50 +02:00
|
|
|
}
|
|
|
|
if (intensity < 0) {
|
2016-02-26 00:30:57 +01:00
|
|
|
throw new IllegalArgumentException("intensity must be >= 0");
|
2015-09-09 20:46:50 +02:00
|
|
|
}
|
|
|
|
if (timestamp < 0) {
|
2016-02-26 00:30:57 +01:00
|
|
|
throw new IllegalArgumentException("timestamp must be >= 0");
|
|
|
|
}
|
2016-02-26 23:45:17 +01:00
|
|
|
if (customShortValue < 0) {
|
|
|
|
throw new IllegalArgumentException("customShortValue must be >= 0");
|
2015-09-09 20:46:50 +02:00
|
|
|
}
|
2015-05-30 17:28:03 +02:00
|
|
|
}
|
|
|
|
|
2015-07-27 23:49:53 +02:00
|
|
|
@Override
|
2015-05-30 17:28:03 +02:00
|
|
|
public int getTimestamp() {
|
|
|
|
return timestamp;
|
|
|
|
}
|
|
|
|
|
2015-07-27 23:49:53 +02:00
|
|
|
@Override
|
|
|
|
public SampleProvider getProvider() {
|
2015-05-30 17:28:03 +02:00
|
|
|
return provider;
|
|
|
|
}
|
|
|
|
|
2015-07-27 23:49:53 +02:00
|
|
|
@Override
|
|
|
|
public short getRawIntensity() {
|
2015-05-30 17:28:03 +02:00
|
|
|
return intensity;
|
|
|
|
}
|
|
|
|
|
2015-07-27 23:49:53 +02:00
|
|
|
@Override
|
|
|
|
public float getIntensity() {
|
|
|
|
return getProvider().normalizeIntensity(getRawIntensity());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public short getSteps() {
|
2015-05-30 17:28:03 +02:00
|
|
|
return steps;
|
|
|
|
}
|
|
|
|
|
2015-07-27 23:49:53 +02:00
|
|
|
@Override
|
|
|
|
public byte getRawKind() {
|
2015-05-30 17:28:03 +02:00
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
2015-07-27 23:49:53 +02:00
|
|
|
@Override
|
|
|
|
public int getKind() {
|
|
|
|
return getProvider().normalizeType(getRawKind());
|
|
|
|
}
|
2016-02-26 00:30:57 +01:00
|
|
|
|
|
|
|
@Override
|
2016-02-26 23:45:17 +01:00
|
|
|
public short getCustomShortValue() {
|
|
|
|
return customShortValue;
|
2016-02-26 00:30:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String toString() {
|
|
|
|
return "GBActivitySample{" +
|
|
|
|
"timestamp=" + DateTimeUtils.formatDateTime(DateTimeUtils.parseTimeStamp(timestamp)) +
|
|
|
|
", intensity=" + getIntensity() +
|
|
|
|
", steps=" + getSteps() +
|
2016-02-26 23:45:17 +01:00
|
|
|
", customShortValue=" + getCustomShortValue() +
|
2016-02-26 00:30:57 +01:00
|
|
|
", type=" + getKind() +
|
|
|
|
'}';
|
|
|
|
}
|
2015-05-30 17:28:03 +02:00
|
|
|
}
|