mirror of
https://github.com/russok/FitoTrack.git
synced 2025-10-28 16:22:12 -07:00
#14 Show GPS Status icon in Recorder
This commit is contained in:
parent
50e8976424
commit
9e893c5fad
@ -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;
|
||||
|
||||
|
||||
@ -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,11 +100,10 @@ public class WorkoutRecorder implements LocationListener.LocationChangeListener
|
||||
}
|
||||
|
||||
private void startWatchdog(){
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
new Thread(() -> {
|
||||
try {
|
||||
while (isActive()){
|
||||
checkSignalState();
|
||||
synchronized (samples){
|
||||
if(samples.size() > 2){
|
||||
WorkoutSample lastSample= samples.get(samples.size()-1);
|
||||
@ -116,10 +123,24 @@ public class WorkoutRecorder implements LocationListener.LocationChangeListener
|
||||
} 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -47,6 +47,15 @@
|
||||
android:layout_gravity="center"
|
||||
android:src="@drawable/location_marker" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/recordGpsStatus"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom|right"
|
||||
android:layout_margin="5dp"
|
||||
android:text="@string/gps"
|
||||
android:textColor="@android:color/transparent" />
|
||||
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
|
||||
@ -98,4 +98,5 @@
|
||||
<string name="exportDataSummary">This takes a backup of all your preferences and workout data</string>
|
||||
<string name="importBackup">Import Data Backup</string>
|
||||
<string name="importBackupSummary">Restore a taken backup</string>
|
||||
<string name="gps">GPS</string>
|
||||
</resources>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user