mirror of
https://github.com/russok/FitoTrack.git
synced 2025-10-28 16:22:12 -07:00
allow to set the distance for speech updates
This commit is contained in:
parent
b9e16bda25
commit
ac3dfe4a7f
19
.gitignore
vendored
Normal file
19
.gitignore
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
||||
|
||||
# dependencies
|
||||
/node_modules
|
||||
|
||||
# testing
|
||||
/coverage
|
||||
|
||||
# production
|
||||
/build
|
||||
/app/build
|
||||
/app/release
|
||||
|
||||
# misc
|
||||
.*
|
||||
*.properties
|
||||
*.iml
|
||||
!.gitignore
|
||||
|
||||
@ -55,6 +55,7 @@ import java.util.List;
|
||||
|
||||
import de.tadris.fitness.Instance;
|
||||
import de.tadris.fitness.R;
|
||||
import de.tadris.fitness.data.UserPreferences;
|
||||
import de.tadris.fitness.data.Workout;
|
||||
import de.tadris.fitness.map.MapManager;
|
||||
import de.tadris.fitness.map.tilesource.TileSources;
|
||||
@ -170,10 +171,7 @@ public class RecordWorkoutActivity extends FitoTrackActivity implements Location
|
||||
try{
|
||||
while (recorder.isActive()){
|
||||
Thread.sleep(1000);
|
||||
if(isResumed){
|
||||
mHandler.post(this::updateDescription);
|
||||
}
|
||||
mHandler.post(this::spokenUpdate);
|
||||
mHandler.post(this::updateDescription);
|
||||
}
|
||||
}catch (InterruptedException e){
|
||||
e.printStackTrace();
|
||||
@ -181,19 +179,32 @@ public class RecordWorkoutActivity extends FitoTrackActivity implements Location
|
||||
}).start();
|
||||
}
|
||||
|
||||
private void spokenUpdate() {
|
||||
final long interval = 60 * 1000 * Instance.getInstance(this).userPreferences.getSpokenUpdatePeriod();
|
||||
if (interval == 0)
|
||||
return;
|
||||
long duration = recorder.getDuration();
|
||||
if (duration / interval == lastSpokenUpdate / interval)
|
||||
return;
|
||||
TextToSpeech tts;
|
||||
long lastSpokenUpdateTime = 0;
|
||||
int lastSpokenUpdateDistance = 0;
|
||||
|
||||
timeView.setText(UnitUtils.getHourMinuteSecondTime(duration));
|
||||
private void updateDescription() {
|
||||
long duration = recorder.getDuration();
|
||||
int distanceInMeters = recorder.getDistance();
|
||||
final String distanceCaption = getString(R.string.workoutDistance);
|
||||
final String distance = UnitUtils.getDistance(recorder.getDistance());
|
||||
final String distance = UnitUtils.getDistance(distanceInMeters);
|
||||
final String avgSpeedCaption = getString(R.string.workoutAvgSpeed);
|
||||
final String avgSpeed = UnitUtils.getSpeed(Math.min(100d, recorder.getAvgSpeed()));
|
||||
if (isResumed) {
|
||||
timeView.setText(UnitUtils.getHourMinuteSecondTime(duration));
|
||||
infoViews[0].setText(distanceCaption, distance);
|
||||
infoViews[1].setText(getString(R.string.workoutBurnedEnergy), recorder.getCalories() + " kcal");
|
||||
infoViews[2].setText(avgSpeedCaption, avgSpeed);
|
||||
infoViews[3].setText(getString(R.string.workoutPauseDuration), UnitUtils.getHourMinuteSecondTime(recorder.getPauseDuration()));
|
||||
}
|
||||
|
||||
final UserPreferences prefs=Instance.getInstance(this).userPreferences;
|
||||
final long intervalT = 60 * 1000 * prefs.getSpokenUpdateTimePeriod();
|
||||
final int intervalInMeters = (int)(1000.0/UnitUtils.CHOSEN_SYSTEM.getDistanceFromKilometers(1) * prefs.getSpokenUpdateDistancePeriod());
|
||||
if (
|
||||
(intervalT == 0 || duration / intervalT == lastSpokenUpdateTime / intervalT)
|
||||
&& (intervalInMeters == 0 || distanceInMeters / intervalInMeters == lastSpokenUpdateDistance / intervalInMeters)
|
||||
) return;
|
||||
|
||||
tts = new TextToSpeech(this, (int status) -> {
|
||||
if (status != TextToSpeech.SUCCESS) return;
|
||||
@ -202,23 +213,8 @@ public class RecordWorkoutActivity extends FitoTrackActivity implements Location
|
||||
tts.speak(text, TextToSpeech.QUEUE_FLUSH, null, "updateDescription" + duration);
|
||||
});
|
||||
|
||||
lastSpokenUpdate = duration;
|
||||
}
|
||||
|
||||
TextToSpeech tts;
|
||||
long lastSpokenUpdate = 0;
|
||||
|
||||
private void updateDescription() {
|
||||
long duration = recorder.getDuration();
|
||||
timeView.setText(UnitUtils.getHourMinuteSecondTime(duration));
|
||||
final String distanceCaption = getString(R.string.workoutDistance);
|
||||
final String distance = UnitUtils.getDistance(recorder.getDistance());
|
||||
final String avgSpeedCaption = getString(R.string.workoutAvgSpeed);
|
||||
final String avgSpeed = UnitUtils.getSpeed(Math.min(100d, recorder.getAvgSpeed()));
|
||||
infoViews[0].setText(distanceCaption, distance);
|
||||
infoViews[1].setText(getString(R.string.workoutBurnedEnergy), recorder.getCalories() + " kcal");
|
||||
infoViews[2].setText(avgSpeedCaption, avgSpeed);
|
||||
infoViews[3].setText(getString(R.string.workoutPauseDuration), UnitUtils.getHourMinuteSecondTime(recorder.getPauseDuration()));
|
||||
lastSpokenUpdateTime = duration;
|
||||
lastSpokenUpdateDistance = distanceInMeters;
|
||||
}
|
||||
|
||||
private void stop(){
|
||||
|
||||
@ -160,7 +160,7 @@ public class SettingsActivity extends PreferenceActivity {
|
||||
bindPreferenceSummaryToValue(findPreference("mapStyle"));
|
||||
|
||||
findPreference("weight").setOnPreferenceClickListener(preference -> showWeightPicker());
|
||||
findPreference("spokenUpdatePeriod").setOnPreferenceClickListener(preference -> showSpokenUdatePeriodPicker());
|
||||
findPreference("speech").setOnPreferenceClickListener(preference -> showSpeechConfig());
|
||||
findPreference("import").setOnPreferenceClickListener(preference -> showImportDialog());
|
||||
findPreference("export").setOnPreferenceClickListener(preference -> showExportDialog());
|
||||
|
||||
@ -281,8 +281,8 @@ public class SettingsActivity extends PreferenceActivity {
|
||||
np.setMaxValue((int) UnitUtils.CHOSEN_SYSTEM.getWeightFromKilogram(150));
|
||||
np.setMinValue((int) UnitUtils.CHOSEN_SYSTEM.getWeightFromKilogram(20));
|
||||
np.setFormatter(value -> value + " " + UnitUtils.CHOSEN_SYSTEM.getWeightUnit());
|
||||
final String preferenceKey = "weight";
|
||||
np.setValue((int)Math.round(UnitUtils.CHOSEN_SYSTEM.getWeightFromKilogram(preferences.getInt(preferenceKey, 80))));
|
||||
final String preferenceVariable = "weight";
|
||||
np.setValue((int)Math.round(UnitUtils.CHOSEN_SYSTEM.getWeightFromKilogram(preferences.getInt(preferenceVariable, 80))));
|
||||
np.setWrapSelectorWheel(false);
|
||||
|
||||
d.setView(v);
|
||||
@ -291,7 +291,7 @@ public class SettingsActivity extends PreferenceActivity {
|
||||
d.setPositiveButton(R.string.okay, (dialog, which) -> {
|
||||
int unitValue= np.getValue();
|
||||
int kilograms= (int)Math.round(UnitUtils.CHOSEN_SYSTEM.getKilogramFromUnit(unitValue));
|
||||
preferences.edit().putInt(preferenceKey, kilograms).apply();
|
||||
preferences.edit().putInt(preferenceVariable, kilograms).apply();
|
||||
});
|
||||
|
||||
d.create().show();
|
||||
@ -299,25 +299,39 @@ public class SettingsActivity extends PreferenceActivity {
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean showSpokenUdatePeriodPicker() {
|
||||
final String preferenceKey = "spokenUpdatePeriod";
|
||||
private boolean showSpeechConfig() {
|
||||
UnitUtils.setUnit(this); // Maybe the user changed unit system
|
||||
|
||||
final AlertDialog.Builder d = new AlertDialog.Builder(this);
|
||||
final SharedPreferences preferences= PreferenceManager.getDefaultSharedPreferences(this);
|
||||
//d.setTitle(getString(R.string.pref_weight));
|
||||
d.setTitle("Select period between spoken updates, in minutes");
|
||||
d.setTitle(getString(R.string.pref_spoken_updates_summary));
|
||||
View v= getLayoutInflater().inflate(R.layout.dialog_spoken_updates_picker, null);
|
||||
NumberPicker np = v.findViewById(R.id.spokenUpdatesPicker);
|
||||
np.setMaxValue(60);
|
||||
np.setMinValue(0);
|
||||
np.setFormatter(value -> value==0 ? "No speech" : value + " min" );
|
||||
np.setValue((preferences.getInt(preferenceKey, 0)));
|
||||
np.setWrapSelectorWheel(false);
|
||||
|
||||
NumberPicker npT = v.findViewById(R.id.spokenUpdatesTimePicker);
|
||||
npT.setMaxValue(60);
|
||||
npT.setMinValue(0);
|
||||
npT.setFormatter(value -> value == 0 ? "No speech" : value + " min");
|
||||
final String updateTimeVariable = "spokenUpdateTimePeriod";
|
||||
npT.setValue(preferences.getInt(updateTimeVariable, 0));
|
||||
npT.setWrapSelectorWheel(false);
|
||||
|
||||
final String distanceUnit = " " + UnitUtils.CHOSEN_SYSTEM.getLongDistanceUnit();
|
||||
NumberPicker npD = v.findViewById(R.id.spokenUpdatesDistancePicker);
|
||||
npD.setMaxValue(10);
|
||||
npD.setMinValue(0);
|
||||
npD.setFormatter(value -> value == 0 ? "No speech" : value + distanceUnit);
|
||||
final String updateDistanceVariable = "spokenUpdateDistancePeriod";
|
||||
npD.setValue(preferences.getInt(updateDistanceVariable, 0));
|
||||
npD.setWrapSelectorWheel(false);
|
||||
|
||||
d.setView(v);
|
||||
|
||||
d.setNegativeButton(R.string.cancel, null);
|
||||
d.setPositiveButton(R.string.okay, (dialog, which) -> {
|
||||
preferences.edit().putInt(preferenceKey, np.getValue()).apply();
|
||||
preferences.edit()
|
||||
.putInt(updateTimeVariable, npT.getValue())
|
||||
.putInt(updateDistanceVariable, npD.getValue())
|
||||
.apply();
|
||||
});
|
||||
|
||||
d.create().show();
|
||||
|
||||
@ -35,8 +35,12 @@ public class UserPreferences {
|
||||
return preferences.getInt("weight", 80);
|
||||
}
|
||||
|
||||
public int getSpokenUpdatePeriod(){
|
||||
return preferences.getInt("spokenUpdatePeriod", 5);
|
||||
public int getSpokenUpdateTimePeriod(){
|
||||
return preferences.getInt("spokenUpdateTimePeriod", 5);
|
||||
}
|
||||
|
||||
public int getSpokenUpdateDistancePeriod(){
|
||||
return preferences.getInt("spokenUpdateDistancePeriod", 1);
|
||||
}
|
||||
|
||||
public String getMapStyle(){
|
||||
|
||||
@ -3,12 +3,20 @@
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent" >
|
||||
|
||||
<NumberPicker
|
||||
android:id="@+id/spokenUpdatesPicker"
|
||||
<NumberPicker
|
||||
android:id="@+id/spokenUpdatesTimePicker"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentTop="true"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_margin="30dp" />
|
||||
android:layout_margin="50dp"
|
||||
android:layout_alignParentLeft="true"/>
|
||||
|
||||
<NumberPicker
|
||||
android:id="@+id/spokenUpdatesDistancePicker"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentTop="true"
|
||||
android:layout_margin="50dp"
|
||||
android:layout_alignParentRight="true"/>
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
@ -51,6 +51,11 @@
|
||||
<string name="pref_unit_system">Bevorzugtes Einheitensystem</string>
|
||||
<string name="pref_weight">Dein Gewicht</string>
|
||||
<string name="pref_weight_summary">Dein Gewicht ist zur Kalorienberechnung wichtig</string>
|
||||
|
||||
<!-- please translate -->
|
||||
<string name="pref_spoken_updates">Spoken Updates</string>
|
||||
<string name="pref_spoken_updates_summary">Choose the time and distance between spoken updates</string>
|
||||
|
||||
<string name="preferences">Einstellungen</string>
|
||||
<string name="recordWorkout">Workout aufzeichnen</string>
|
||||
<string name="restore">Wiederherstellen</string>
|
||||
@ -107,4 +112,4 @@
|
||||
<string name="waiting_gps">Warte auf GPS</string>
|
||||
<string name="uploadFailed">Upload fehlgeschlagen</string>
|
||||
<string name="uploadSuccessful">Upload erfolgreich</string>
|
||||
</resources>
|
||||
</resources>
|
||||
|
||||
@ -111,6 +111,8 @@
|
||||
<string name="exportAsGpxFile">Export as GPX-File</string>
|
||||
<string name="pref_weight">Your Weight</string>
|
||||
<string name="pref_weight_summary">Your weight is needed to calculate the burned calories</string>
|
||||
<string name="pref_spoken_updates">Spoken Updates</string>
|
||||
<string name="pref_spoken_updates_summary">Choose the time and distance between spoken updates</string>
|
||||
<string name="pref_unit_system">Preferred system of units</string>
|
||||
<string name="settings">Settings</string>
|
||||
<string name="exportData">Export Data</string>
|
||||
|
||||
@ -42,11 +42,11 @@
|
||||
android:title="@string/mapStyle" />
|
||||
|
||||
<Preference
|
||||
android:key="spokenUpdatePeriod"
|
||||
android:key="speech"
|
||||
android:selectAllOnFocus="true"
|
||||
android:singleLine="true"
|
||||
android:summary="Choose the frequency of spoken updates"
|
||||
android:title="Spoken updates" />
|
||||
android:summary="@string/pref_spoken_updates_summary"
|
||||
android:title="@string/pref_spoken_updates" />
|
||||
|
||||
|
||||
<PreferenceCategory android:title="@string/data">
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user