forked from upstream-mirrors/OpenTracks
Refactoring: move TrackPointDataSet directly into TrackPoint.
This commit is contained in:
@@ -29,6 +29,10 @@ public class TrackPoint {
|
||||
|
||||
private final Location location;
|
||||
|
||||
private Float heartRate_bpm = null;
|
||||
private Float cyclingCadence_rpm = null;
|
||||
private Float power = null;
|
||||
|
||||
public TrackPoint() {
|
||||
this.location = new Location("");
|
||||
}
|
||||
@@ -37,17 +41,13 @@ public class TrackPoint {
|
||||
this.location = location;
|
||||
}
|
||||
|
||||
public TrackPoint(@NonNull Location location, TrackPointSensorDataSet sensorDataSet) {
|
||||
this.location = location;
|
||||
this.sensorDataSet = sensorDataSet;
|
||||
}
|
||||
|
||||
public TrackPoint(@NonNull TrackPoint trackPoint, TrackPointSensorDataSet sensorDataSet) {
|
||||
public TrackPoint(@NonNull TrackPoint trackPoint) {
|
||||
this.location = trackPoint.getLocation();
|
||||
this.sensorDataSet = sensorDataSet;
|
||||
}
|
||||
|
||||
private TrackPointSensorDataSet sensorDataSet = null;
|
||||
this.heartRate_bpm = trackPoint.getHeartRate_bpm();
|
||||
this.cyclingCadence_rpm = trackPoint.getCyclingCadence_rpm();
|
||||
this.power = trackPoint.getPower();
|
||||
}
|
||||
|
||||
public TrackPoint(double latitude, double longitude, Double altitude, long time) {
|
||||
location = new Location(LocationManager.GPS_PROVIDER);
|
||||
@@ -88,14 +88,6 @@ public class TrackPoint {
|
||||
return location;
|
||||
}
|
||||
|
||||
public TrackPointSensorDataSet getSensorDataSet() {
|
||||
return sensorDataSet;
|
||||
}
|
||||
|
||||
public void setSensorDataSet(TrackPointSensorDataSet sensorDataSet) {
|
||||
this.sensorDataSet = sensorDataSet;
|
||||
}
|
||||
|
||||
public double getLatitude() {
|
||||
return location.getLatitude();
|
||||
}
|
||||
@@ -180,6 +172,47 @@ public class TrackPoint {
|
||||
return location.bearingTo(dest);
|
||||
}
|
||||
|
||||
// Sensor data
|
||||
public boolean hasSensorData() {
|
||||
return hasHeartRate() || hasCyclingCadence() || hasPower();
|
||||
}
|
||||
|
||||
public boolean hasHeartRate() {
|
||||
return heartRate_bpm != null && heartRate_bpm > 0;
|
||||
}
|
||||
|
||||
public float getHeartRate_bpm() {
|
||||
return heartRate_bpm;
|
||||
}
|
||||
|
||||
public void setHeartRate_bpm(Float heartRate_bpm) {
|
||||
this.heartRate_bpm = heartRate_bpm;
|
||||
}
|
||||
|
||||
public boolean hasCyclingCadence() {
|
||||
return cyclingCadence_rpm != null;
|
||||
}
|
||||
|
||||
public Float getCyclingCadence_rpm() {
|
||||
return cyclingCadence_rpm;
|
||||
}
|
||||
|
||||
public void setCyclingCadence_rpm(Float cyclingCadence_rpm) {
|
||||
this.cyclingCadence_rpm = cyclingCadence_rpm;
|
||||
}
|
||||
|
||||
public boolean hasPower() {
|
||||
return power != null;
|
||||
}
|
||||
|
||||
public Float getPower() {
|
||||
return power;
|
||||
}
|
||||
|
||||
public void setPower(Float power) {
|
||||
this.power = power;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String toString() {
|
||||
|
||||
@@ -1,99 +0,0 @@
|
||||
package de.dennisguse.opentracks.content.data;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
//TODO Rename.
|
||||
public final class TrackPointSensorDataSet {
|
||||
private long time_ms;
|
||||
|
||||
private Float heartRate_bpm = null;
|
||||
private Float cyclingCadence = null;
|
||||
private Float cyclingSpeed = null;
|
||||
private Float power = null;
|
||||
|
||||
public TrackPointSensorDataSet() {
|
||||
this(System.currentTimeMillis());
|
||||
}
|
||||
|
||||
public TrackPointSensorDataSet(long time_ms) {
|
||||
this.time_ms = time_ms;
|
||||
}
|
||||
|
||||
public boolean hasHeartRate() {
|
||||
return heartRate_bpm != null && heartRate_bpm > 0;
|
||||
}
|
||||
|
||||
public float getHeartRate_bpm() {
|
||||
return heartRate_bpm;
|
||||
}
|
||||
|
||||
public void setHeartRate_bpm(Float heartRate_bpm) {
|
||||
this.heartRate_bpm = heartRate_bpm;
|
||||
}
|
||||
|
||||
public boolean hasCyclingCadence() {
|
||||
return cyclingCadence != null;
|
||||
}
|
||||
|
||||
public Float getCyclingCadence_rpm() {
|
||||
return cyclingCadence;
|
||||
}
|
||||
|
||||
public void setCyclingCadence(Float cyclingCadence) {
|
||||
this.cyclingCadence = cyclingCadence;
|
||||
}
|
||||
|
||||
public void setCyclingCadence(Integer cyclingCadence) {
|
||||
this.cyclingCadence = cyclingCadence != null ? cyclingCadence.floatValue() : null;
|
||||
}
|
||||
|
||||
public boolean hasCyclingSpeed() {
|
||||
return cyclingSpeed != null;
|
||||
}
|
||||
|
||||
public Float getCyclingSpeed() {
|
||||
return cyclingSpeed;
|
||||
}
|
||||
|
||||
public void setCyclingSpeed(Float cyclingSpeed) {
|
||||
this.cyclingSpeed = cyclingSpeed;
|
||||
}
|
||||
|
||||
public boolean hasPower() {
|
||||
return power != null;
|
||||
}
|
||||
|
||||
public Float getPower() {
|
||||
return power;
|
||||
}
|
||||
|
||||
public void setPower(Float power) {
|
||||
this.power = power;
|
||||
}
|
||||
|
||||
public long getTime() {
|
||||
return time_ms;
|
||||
}
|
||||
|
||||
public void setTime(long time_ms) {
|
||||
this.time_ms = time_ms;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the data recent considering the current time.
|
||||
*
|
||||
* @param maxAge the maximal age in milliseconds.
|
||||
*/
|
||||
public boolean isRecent(long maxAge) {
|
||||
return time_ms + maxAge > System.currentTimeMillis();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String toString() {
|
||||
return "time=" + getTime()
|
||||
+ (hasHeartRate() ? " heart=" + getHeartRate_bpm() : "")
|
||||
+ (hasCyclingCadence() ? " cyclingCad=" + getCyclingCadence_rpm() : "")
|
||||
+ (hasCyclingSpeed() ? " cyclingSpeed=" + getCyclingSpeed() : "");
|
||||
}
|
||||
}
|
||||
@@ -36,7 +36,6 @@ import de.dennisguse.opentracks.android.ContentResolverWrapper;
|
||||
import de.dennisguse.opentracks.android.IContentResolver;
|
||||
import de.dennisguse.opentracks.content.data.Track;
|
||||
import de.dennisguse.opentracks.content.data.TrackPoint;
|
||||
import de.dennisguse.opentracks.content.data.TrackPointSensorDataSet;
|
||||
import de.dennisguse.opentracks.content.data.TrackPointsColumns;
|
||||
import de.dennisguse.opentracks.content.data.TracksColumns;
|
||||
import de.dennisguse.opentracks.content.data.Waypoint;
|
||||
@@ -621,19 +620,16 @@ public class ContentProviderUtils {
|
||||
trackPoint.setBearing(cursor.getFloat(indexes.bearingIndex));
|
||||
}
|
||||
|
||||
TrackPointSensorDataSet sensorDataSet = new TrackPointSensorDataSet();
|
||||
|
||||
if (cursor.isNull(indexes.sensorHeartRateIndex)) {
|
||||
sensorDataSet.setHeartRate_bpm(cursor.getFloat(indexes.sensorHeartRateIndex));
|
||||
if (!cursor.isNull(indexes.sensorHeartRateIndex)) {
|
||||
trackPoint.setHeartRate_bpm(cursor.getFloat(indexes.sensorHeartRateIndex));
|
||||
}
|
||||
if (cursor.isNull(indexes.sensorCadenceIndex)) {
|
||||
sensorDataSet.setCyclingCadence(cursor.getFloat(indexes.sensorCadenceIndex));
|
||||
if (!cursor.isNull(indexes.sensorCadenceIndex)) {
|
||||
trackPoint.setCyclingCadence_rpm(cursor.getFloat(indexes.sensorCadenceIndex));
|
||||
}
|
||||
if (cursor.isNull(indexes.sensorPowerIndex)) {
|
||||
sensorDataSet.setCyclingSpeed(cursor.getFloat(indexes.sensorPowerIndex));
|
||||
if (!cursor.isNull(indexes.sensorPowerIndex)) {
|
||||
trackPoint.setPower(cursor.getFloat(indexes.sensorPowerIndex));
|
||||
}
|
||||
|
||||
trackPoint.setSensorDataSet(sensorDataSet);
|
||||
return trackPoint;
|
||||
}
|
||||
|
||||
@@ -812,16 +808,14 @@ public class ContentProviderUtils {
|
||||
values.put(TrackPointsColumns.BEARING, trackPoint.getBearing());
|
||||
}
|
||||
|
||||
//SensorData
|
||||
TrackPointSensorDataSet sensorDataSet = trackPoint.getSensorDataSet();
|
||||
if (sensorDataSet != null && sensorDataSet.hasHeartRate()) {
|
||||
values.put(TrackPointsColumns.SENSOR_HEARTRATE, sensorDataSet.getHeartRate_bpm());
|
||||
if (trackPoint.hasHeartRate()) {
|
||||
values.put(TrackPointsColumns.SENSOR_HEARTRATE, trackPoint.getHeartRate_bpm());
|
||||
}
|
||||
if (sensorDataSet != null && sensorDataSet.hasCyclingCadence()) {
|
||||
values.put(TrackPointsColumns.SENSOR_CADENCE, sensorDataSet.getCyclingCadence_rpm());
|
||||
if (trackPoint.hasCyclingCadence()) {
|
||||
values.put(TrackPointsColumns.SENSOR_CADENCE, trackPoint.getCyclingCadence_rpm());
|
||||
}
|
||||
if (sensorDataSet != null && sensorDataSet.hasPower()) {
|
||||
values.put(TrackPointsColumns.SENSOR_POWER, sensorDataSet.getPower());
|
||||
if (trackPoint.hasPower()) {
|
||||
values.put(TrackPointsColumns.SENSOR_POWER, trackPoint.getPower());
|
||||
}
|
||||
return values;
|
||||
}
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
package de.dennisguse.opentracks.content.sensor;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
|
||||
import de.dennisguse.opentracks.content.data.TrackPointSensorDataSet;
|
||||
import de.dennisguse.opentracks.content.data.TrackPoint;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -19,13 +18,6 @@ public final class SensorDataSet {
|
||||
public SensorDataSet() {
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
public SensorDataSet(SensorDataHeartRate heartRate, SensorDataCycling.Cadence cyclingCadence, SensorDataCycling.Speed cyclingSpeed) {
|
||||
this.heartRate = heartRate;
|
||||
this.cyclingCadence = cyclingCadence;
|
||||
this.cyclingSpeed = cyclingSpeed;
|
||||
}
|
||||
|
||||
public SensorDataHeartRate getHeartRate() {
|
||||
return heartRate;
|
||||
}
|
||||
@@ -70,21 +62,18 @@ public final class SensorDataSet {
|
||||
this.cyclingSpeed = null;
|
||||
}
|
||||
|
||||
public TrackPointSensorDataSet createTrackPointSensorDataSet() {
|
||||
TrackPointSensorDataSet sensorDataSet = new TrackPointSensorDataSet();
|
||||
public void fillTrackPoint(TrackPoint trackPoint) {
|
||||
if (heartRate != null) {
|
||||
sensorDataSet.setHeartRate_bpm(heartRate.getHeartRate_bpm());
|
||||
trackPoint.setHeartRate_bpm(heartRate.getHeartRate_bpm());
|
||||
}
|
||||
|
||||
if (cyclingCadence != null && cyclingCadence.hasCadence_rpm()) {
|
||||
sensorDataSet.setCyclingCadence(cyclingCadence.getCadence_rpm());
|
||||
trackPoint.setCyclingCadence_rpm(cyclingCadence.getCadence_rpm());
|
||||
}
|
||||
|
||||
if (cyclingSpeed != null && cyclingSpeed.hasSpeed()) {
|
||||
sensorDataSet.setCyclingCadence(cyclingSpeed.getSpeed_ms());
|
||||
trackPoint.setSpeed(cyclingSpeed.getSpeed_ms());
|
||||
}
|
||||
|
||||
return sensorDataSet;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
|
||||
Reference in New Issue
Block a user