mirror of
https://github.com/russok/FitoTrack.git
synced 2025-10-29 08:42:12 -07:00
create the engine only once
This commit is contained in:
parent
ac3dfe4a7f
commit
7da68b6fc7
@ -52,6 +52,7 @@ import org.mapsforge.map.layer.overlay.Polyline;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
import de.tadris.fitness.Instance;
|
import de.tadris.fitness.Instance;
|
||||||
import de.tadris.fitness.R;
|
import de.tadris.fitness.R;
|
||||||
@ -84,6 +85,8 @@ public class RecordWorkoutActivity extends FitoTrackActivity implements Location
|
|||||||
Intent locationListener;
|
Intent locationListener;
|
||||||
Intent pressureService;
|
Intent pressureService;
|
||||||
private boolean saved= false;
|
private boolean saved= false;
|
||||||
|
TextToSpeech tts;
|
||||||
|
boolean ttsReady = false;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
@ -104,6 +107,9 @@ public class RecordWorkoutActivity extends FitoTrackActivity implements Location
|
|||||||
recorder= new WorkoutRecorder(this, ACTIVITY, this);
|
recorder= new WorkoutRecorder(this, ACTIVITY, this);
|
||||||
recorder.start();
|
recorder.start();
|
||||||
|
|
||||||
|
tts = new TextToSpeech(this, (int status) -> {
|
||||||
|
ttsReady = status == TextToSpeech.SUCCESS && tts.setLanguage(Locale.getDefault())>=0;
|
||||||
|
});
|
||||||
infoViews[0]= new InfoViewHolder(findViewById(R.id.recordInfo1Title), findViewById(R.id.recordInfo1Value));
|
infoViews[0]= new InfoViewHolder(findViewById(R.id.recordInfo1Title), findViewById(R.id.recordInfo1Value));
|
||||||
infoViews[1]= new InfoViewHolder(findViewById(R.id.recordInfo2Title), findViewById(R.id.recordInfo2Value));
|
infoViews[1]= new InfoViewHolder(findViewById(R.id.recordInfo2Title), findViewById(R.id.recordInfo2Value));
|
||||||
infoViews[2]= new InfoViewHolder(findViewById(R.id.recordInfo3Title), findViewById(R.id.recordInfo3Value));
|
infoViews[2]= new InfoViewHolder(findViewById(R.id.recordInfo3Title), findViewById(R.id.recordInfo3Value));
|
||||||
@ -179,7 +185,6 @@ public class RecordWorkoutActivity extends FitoTrackActivity implements Location
|
|||||||
}).start();
|
}).start();
|
||||||
}
|
}
|
||||||
|
|
||||||
TextToSpeech tts;
|
|
||||||
long lastSpokenUpdateTime = 0;
|
long lastSpokenUpdateTime = 0;
|
||||||
int lastSpokenUpdateDistance = 0;
|
int lastSpokenUpdateDistance = 0;
|
||||||
|
|
||||||
@ -198,20 +203,17 @@ public class RecordWorkoutActivity extends FitoTrackActivity implements Location
|
|||||||
infoViews[3].setText(getString(R.string.workoutPauseDuration), UnitUtils.getHourMinuteSecondTime(recorder.getPauseDuration()));
|
infoViews[3].setText(getString(R.string.workoutPauseDuration), UnitUtils.getHourMinuteSecondTime(recorder.getPauseDuration()));
|
||||||
}
|
}
|
||||||
|
|
||||||
final UserPreferences prefs=Instance.getInstance(this).userPreferences;
|
final UserPreferences prefs = Instance.getInstance(this).userPreferences;
|
||||||
final long intervalT = 60 * 1000 * prefs.getSpokenUpdateTimePeriod();
|
final long intervalT = 60 * 1000 * prefs.getSpokenUpdateTimePeriod();
|
||||||
final int intervalInMeters = (int)(1000.0/UnitUtils.CHOSEN_SYSTEM.getDistanceFromKilometers(1) * prefs.getSpokenUpdateDistancePeriod());
|
final int intervalInMeters = (int) (1000.0 / UnitUtils.CHOSEN_SYSTEM.getDistanceFromKilometers(1) * prefs.getSpokenUpdateDistancePeriod());
|
||||||
if (
|
if (!ttsReady ||
|
||||||
(intervalT == 0 || duration / intervalT == lastSpokenUpdateTime / intervalT)
|
(intervalT == 0 || duration / intervalT == lastSpokenUpdateTime / intervalT)
|
||||||
&& (intervalInMeters == 0 || distanceInMeters / intervalInMeters == lastSpokenUpdateDistance / intervalInMeters)
|
&& (intervalInMeters == 0 || distanceInMeters / intervalInMeters == lastSpokenUpdateDistance / intervalInMeters)
|
||||||
) return;
|
) return;
|
||||||
|
|
||||||
tts = new TextToSpeech(this, (int status) -> {
|
|
||||||
if (status != TextToSpeech.SUCCESS) return;
|
|
||||||
final String text = distanceCaption + ": " + distance + ". "
|
final String text = distanceCaption + ": " + distance + ". "
|
||||||
+ avgSpeedCaption + ": " + avgSpeed;
|
+ avgSpeedCaption + ": " + avgSpeed;
|
||||||
tts.speak(text, TextToSpeech.QUEUE_FLUSH, null, "updateDescription" + duration);
|
tts.speak(text, TextToSpeech.QUEUE_FLUSH, null, "updateDescription" + duration);
|
||||||
});
|
|
||||||
|
|
||||||
lastSpokenUpdateTime = duration;
|
lastSpokenUpdateTime = duration;
|
||||||
lastSpokenUpdateDistance = distanceInMeters;
|
lastSpokenUpdateDistance = distanceInMeters;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user