diff --git a/app/src/main/java/de/tadris/fitness/activity/RecordWorkoutActivity.java b/app/src/main/java/de/tadris/fitness/activity/RecordWorkoutActivity.java
index d05d804..1a8f617 100644
--- a/app/src/main/java/de/tadris/fitness/activity/RecordWorkoutActivity.java
+++ b/app/src/main/java/de/tadris/fitness/activity/RecordWorkoutActivity.java
@@ -57,7 +57,7 @@ import de.tadris.fitness.map.tilesource.TileSources;
import de.tadris.fitness.util.ThemeManager;
import de.tadris.fitness.util.unit.UnitUtils;
-public class RecordWorkoutActivity extends FitoTrackActivity implements LocationListener.LocationChangeListener {
+public class RecordWorkoutActivity extends FitoTrackActivity implements LocationListener.LocationChangeListener, WorkoutRecorder.GpsStateChangedListener {
public static String ACTIVITY= Workout.WORKOUT_TYPE_RUNNING;
@@ -88,7 +88,7 @@ public class RecordWorkoutActivity extends FitoTrackActivity implements Location
checkPermissions();
- recorder= new WorkoutRecorder(this, ACTIVITY);
+ recorder= new WorkoutRecorder(this, ACTIVITY, this);
recorder.start();
infoViews[0]= new InfoViewHolder(findViewById(R.id.recordInfo1Title), findViewById(R.id.recordInfo1Value));
@@ -96,6 +96,7 @@ public class RecordWorkoutActivity extends FitoTrackActivity implements Location
infoViews[2]= new InfoViewHolder(findViewById(R.id.recordInfo3Title), findViewById(R.id.recordInfo3Value));
infoViews[3]= new InfoViewHolder(findViewById(R.id.recordInfo4Title), findViewById(R.id.recordInfo4Value));
timeView= findViewById(R.id.recordTime);
+ gpsStatusView= findViewById(R.id.recordGpsStatus);
updateDescription();
@@ -303,6 +304,11 @@ public class RecordWorkoutActivity extends FitoTrackActivity implements Location
}
}
+ @Override
+ public void onGPSStateChanged(WorkoutRecorder.GpsState oldState, WorkoutRecorder.GpsState state) {
+ gpsStatusView.setTextColor(state.color);
+ }
+
public static class InfoViewHolder{
TextView titleView, valueView;
diff --git a/app/src/main/java/de/tadris/fitness/location/WorkoutRecorder.java b/app/src/main/java/de/tadris/fitness/location/WorkoutRecorder.java
index fa95550..5665484 100644
--- a/app/src/main/java/de/tadris/fitness/location/WorkoutRecorder.java
+++ b/app/src/main/java/de/tadris/fitness/location/WorkoutRecorder.java
@@ -20,6 +20,7 @@
package de.tadris.fitness.location;
import android.content.Context;
+import android.graphics.Color;
import android.location.Location;
import android.util.Log;
@@ -61,9 +62,16 @@ public class WorkoutRecorder implements LocationListener.LocationChangeListener
private double distance= 0;
private boolean hasBegan = false;
- public WorkoutRecorder(Context context, String workoutType) {
+ private static final double SIGNAL_BAD_THRESHOLD= 20; // In meters
+ private static final int SIGNAL_LOST_THRESHOLD= 10000; // In milliseconds
+ private Location lastFix;
+ private GpsStateChangedListener gpsStateChangedListener;
+ private GpsState gpsState= GpsState.SIGNAL_LOST;
+
+ public WorkoutRecorder(Context context, String workoutType, GpsStateChangedListener gpsStateChangedListener) {
this.context= context;
this.state= RecordingState.IDLE;
+ this.gpsStateChangedListener= gpsStateChangedListener;
this.workout= new Workout();
@@ -92,34 +100,47 @@ public class WorkoutRecorder implements LocationListener.LocationChangeListener
}
private void startWatchdog(){
- new Thread(new Runnable() {
- @Override
- public void run() {
- try {
- while (isActive()){
- synchronized (samples){
- if(samples.size() > 2){
- WorkoutSample lastSample= samples.get(samples.size()-1);
- if(System.currentTimeMillis() - lastSampleTime > PAUSE_TIME){
- if(state == RecordingState.RUNNING){
- pause();
- }
- }else{
- if(state == RecordingState.PAUSED){
- resume();
- }
+ new Thread(() -> {
+ try {
+ while (isActive()){
+ checkSignalState();
+ synchronized (samples){
+ if(samples.size() > 2){
+ WorkoutSample lastSample= samples.get(samples.size()-1);
+ if(System.currentTimeMillis() - lastSampleTime > PAUSE_TIME){
+ if(state == RecordingState.RUNNING){
+ pause();
+ }
+ }else{
+ if(state == RecordingState.PAUSED){
+ resume();
}
}
}
- Thread.sleep(5000);
}
- } catch (InterruptedException e) {
- e.printStackTrace();
+ Thread.sleep(5000);
}
+ } catch (InterruptedException e) {
+ e.printStackTrace();
}
}).start();
}
+ private void checkSignalState(){
+ GpsState state;
+ if(System.currentTimeMillis() - lastFix.getTime() > SIGNAL_LOST_THRESHOLD){
+ state= GpsState.SIGNAL_LOST;
+ }else if(lastFix.getAccuracy() > SIGNAL_BAD_THRESHOLD){
+ state= GpsState.SIGNAL_BAD;
+ }else{
+ state= GpsState.SIGNAL_OKAY;
+ }
+ if(state != gpsState){
+ gpsStateChangedListener.onGPSStateChanged(gpsState, state);
+ gpsState= state;
+ }
+ }
+
private void resume(){
Log.i("Recorder", "Resume");
state= RecordingState.RUNNING;
@@ -169,6 +190,7 @@ public class WorkoutRecorder implements LocationListener.LocationChangeListener
@Override
public void onLocationChange(Location location) {
+ lastFix= location;
if(isActive()){
double distance= 0;
if(getSampleCount() > 0){
@@ -262,4 +284,20 @@ public class WorkoutRecorder implements LocationListener.LocationChangeListener
IDLE, RUNNING, PAUSED, STOPPED
}
+ public enum GpsState{
+ SIGNAL_LOST(Color.RED),
+ SIGNAL_OKAY(Color.GREEN),
+ SIGNAL_BAD(Color.YELLOW);
+
+ public int color;
+
+ GpsState(int color) {
+ this.color = color;
+ }
+ }
+
+ public interface GpsStateChangedListener{
+ void onGPSStateChanged(GpsState oldState, GpsState state);
+ }
+
}
diff --git a/app/src/main/res/layout/activity_record_workout.xml b/app/src/main/res/layout/activity_record_workout.xml
index f0afe2e..25196e2 100644
--- a/app/src/main/res/layout/activity_record_workout.xml
+++ b/app/src/main/res/layout/activity_record_workout.xml
@@ -47,6 +47,15 @@
android:layout_gravity="center"
android:src="@drawable/location_marker" />
+
+
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 07b4de3..50159cb 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -98,4 +98,5 @@
This takes a backup of all your preferences and workout data
Import Data Backup
Restore a taken backup
+ GPS