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.Instance;
|
||||||
import de.tadris.fitness.R;
|
import de.tadris.fitness.R;
|
||||||
|
import de.tadris.fitness.data.UserPreferences;
|
||||||
import de.tadris.fitness.data.Workout;
|
import de.tadris.fitness.data.Workout;
|
||||||
import de.tadris.fitness.map.MapManager;
|
import de.tadris.fitness.map.MapManager;
|
||||||
import de.tadris.fitness.map.tilesource.TileSources;
|
import de.tadris.fitness.map.tilesource.TileSources;
|
||||||
@ -170,30 +171,40 @@ public class RecordWorkoutActivity extends FitoTrackActivity implements Location
|
|||||||
try{
|
try{
|
||||||
while (recorder.isActive()){
|
while (recorder.isActive()){
|
||||||
Thread.sleep(1000);
|
Thread.sleep(1000);
|
||||||
if(isResumed){
|
|
||||||
mHandler.post(this::updateDescription);
|
mHandler.post(this::updateDescription);
|
||||||
}
|
}
|
||||||
mHandler.post(this::spokenUpdate);
|
|
||||||
}
|
|
||||||
}catch (InterruptedException e){
|
}catch (InterruptedException e){
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}).start();
|
}).start();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void spokenUpdate() {
|
TextToSpeech tts;
|
||||||
final long interval = 60 * 1000 * Instance.getInstance(this).userPreferences.getSpokenUpdatePeriod();
|
long lastSpokenUpdateTime = 0;
|
||||||
if (interval == 0)
|
int lastSpokenUpdateDistance = 0;
|
||||||
return;
|
|
||||||
long duration = recorder.getDuration();
|
|
||||||
if (duration / interval == lastSpokenUpdate / interval)
|
|
||||||
return;
|
|
||||||
|
|
||||||
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 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 avgSpeedCaption = getString(R.string.workoutAvgSpeed);
|
||||||
final String avgSpeed = UnitUtils.getSpeed(Math.min(100d, recorder.getAvgSpeed()));
|
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) -> {
|
tts = new TextToSpeech(this, (int status) -> {
|
||||||
if (status != TextToSpeech.SUCCESS) return;
|
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);
|
tts.speak(text, TextToSpeech.QUEUE_FLUSH, null, "updateDescription" + duration);
|
||||||
});
|
});
|
||||||
|
|
||||||
lastSpokenUpdate = duration;
|
lastSpokenUpdateTime = duration;
|
||||||
}
|
lastSpokenUpdateDistance = distanceInMeters;
|
||||||
|
|
||||||
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()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void stop(){
|
private void stop(){
|
||||||
|
|||||||
@ -160,7 +160,7 @@ public class SettingsActivity extends PreferenceActivity {
|
|||||||
bindPreferenceSummaryToValue(findPreference("mapStyle"));
|
bindPreferenceSummaryToValue(findPreference("mapStyle"));
|
||||||
|
|
||||||
findPreference("weight").setOnPreferenceClickListener(preference -> showWeightPicker());
|
findPreference("weight").setOnPreferenceClickListener(preference -> showWeightPicker());
|
||||||
findPreference("spokenUpdatePeriod").setOnPreferenceClickListener(preference -> showSpokenUdatePeriodPicker());
|
findPreference("speech").setOnPreferenceClickListener(preference -> showSpeechConfig());
|
||||||
findPreference("import").setOnPreferenceClickListener(preference -> showImportDialog());
|
findPreference("import").setOnPreferenceClickListener(preference -> showImportDialog());
|
||||||
findPreference("export").setOnPreferenceClickListener(preference -> showExportDialog());
|
findPreference("export").setOnPreferenceClickListener(preference -> showExportDialog());
|
||||||
|
|
||||||
@ -281,8 +281,8 @@ public class SettingsActivity extends PreferenceActivity {
|
|||||||
np.setMaxValue((int) UnitUtils.CHOSEN_SYSTEM.getWeightFromKilogram(150));
|
np.setMaxValue((int) UnitUtils.CHOSEN_SYSTEM.getWeightFromKilogram(150));
|
||||||
np.setMinValue((int) UnitUtils.CHOSEN_SYSTEM.getWeightFromKilogram(20));
|
np.setMinValue((int) UnitUtils.CHOSEN_SYSTEM.getWeightFromKilogram(20));
|
||||||
np.setFormatter(value -> value + " " + UnitUtils.CHOSEN_SYSTEM.getWeightUnit());
|
np.setFormatter(value -> value + " " + UnitUtils.CHOSEN_SYSTEM.getWeightUnit());
|
||||||
final String preferenceKey = "weight";
|
final String preferenceVariable = "weight";
|
||||||
np.setValue((int)Math.round(UnitUtils.CHOSEN_SYSTEM.getWeightFromKilogram(preferences.getInt(preferenceKey, 80))));
|
np.setValue((int)Math.round(UnitUtils.CHOSEN_SYSTEM.getWeightFromKilogram(preferences.getInt(preferenceVariable, 80))));
|
||||||
np.setWrapSelectorWheel(false);
|
np.setWrapSelectorWheel(false);
|
||||||
|
|
||||||
d.setView(v);
|
d.setView(v);
|
||||||
@ -291,7 +291,7 @@ public class SettingsActivity extends PreferenceActivity {
|
|||||||
d.setPositiveButton(R.string.okay, (dialog, which) -> {
|
d.setPositiveButton(R.string.okay, (dialog, which) -> {
|
||||||
int unitValue= np.getValue();
|
int unitValue= np.getValue();
|
||||||
int kilograms= (int)Math.round(UnitUtils.CHOSEN_SYSTEM.getKilogramFromUnit(unitValue));
|
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();
|
d.create().show();
|
||||||
@ -299,25 +299,39 @@ public class SettingsActivity extends PreferenceActivity {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean showSpokenUdatePeriodPicker() {
|
private boolean showSpeechConfig() {
|
||||||
final String preferenceKey = "spokenUpdatePeriod";
|
UnitUtils.setUnit(this); // Maybe the user changed unit system
|
||||||
|
|
||||||
final AlertDialog.Builder d = new AlertDialog.Builder(this);
|
final AlertDialog.Builder d = new AlertDialog.Builder(this);
|
||||||
final SharedPreferences preferences= PreferenceManager.getDefaultSharedPreferences(this);
|
final SharedPreferences preferences= PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
//d.setTitle(getString(R.string.pref_weight));
|
d.setTitle(getString(R.string.pref_spoken_updates_summary));
|
||||||
d.setTitle("Select period between spoken updates, in minutes");
|
|
||||||
View v= getLayoutInflater().inflate(R.layout.dialog_spoken_updates_picker, null);
|
View v= getLayoutInflater().inflate(R.layout.dialog_spoken_updates_picker, null);
|
||||||
NumberPicker np = v.findViewById(R.id.spokenUpdatesPicker);
|
|
||||||
np.setMaxValue(60);
|
NumberPicker npT = v.findViewById(R.id.spokenUpdatesTimePicker);
|
||||||
np.setMinValue(0);
|
npT.setMaxValue(60);
|
||||||
np.setFormatter(value -> value==0 ? "No speech" : value + " min" );
|
npT.setMinValue(0);
|
||||||
np.setValue((preferences.getInt(preferenceKey, 0)));
|
npT.setFormatter(value -> value == 0 ? "No speech" : value + " min");
|
||||||
np.setWrapSelectorWheel(false);
|
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.setView(v);
|
||||||
|
|
||||||
d.setNegativeButton(R.string.cancel, null);
|
d.setNegativeButton(R.string.cancel, null);
|
||||||
d.setPositiveButton(R.string.okay, (dialog, which) -> {
|
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();
|
d.create().show();
|
||||||
|
|||||||
@ -35,8 +35,12 @@ public class UserPreferences {
|
|||||||
return preferences.getInt("weight", 80);
|
return preferences.getInt("weight", 80);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getSpokenUpdatePeriod(){
|
public int getSpokenUpdateTimePeriod(){
|
||||||
return preferences.getInt("spokenUpdatePeriod", 5);
|
return preferences.getInt("spokenUpdateTimePeriod", 5);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getSpokenUpdateDistancePeriod(){
|
||||||
|
return preferences.getInt("spokenUpdateDistancePeriod", 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getMapStyle(){
|
public String getMapStyle(){
|
||||||
|
|||||||
@ -4,11 +4,19 @@
|
|||||||
android:layout_height="fill_parent" >
|
android:layout_height="fill_parent" >
|
||||||
|
|
||||||
<NumberPicker
|
<NumberPicker
|
||||||
android:id="@+id/spokenUpdatesPicker"
|
android:id="@+id/spokenUpdatesTimePicker"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_alignParentTop="true"
|
android:layout_alignParentTop="true"
|
||||||
android:layout_centerHorizontal="true"
|
android:layout_margin="50dp"
|
||||||
android:layout_margin="30dp" />
|
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>
|
</RelativeLayout>
|
||||||
|
|||||||
@ -51,6 +51,11 @@
|
|||||||
<string name="pref_unit_system">Bevorzugtes Einheitensystem</string>
|
<string name="pref_unit_system">Bevorzugtes Einheitensystem</string>
|
||||||
<string name="pref_weight">Dein Gewicht</string>
|
<string name="pref_weight">Dein Gewicht</string>
|
||||||
<string name="pref_weight_summary">Dein Gewicht ist zur Kalorienberechnung wichtig</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="preferences">Einstellungen</string>
|
||||||
<string name="recordWorkout">Workout aufzeichnen</string>
|
<string name="recordWorkout">Workout aufzeichnen</string>
|
||||||
<string name="restore">Wiederherstellen</string>
|
<string name="restore">Wiederherstellen</string>
|
||||||
|
|||||||
@ -111,6 +111,8 @@
|
|||||||
<string name="exportAsGpxFile">Export as GPX-File</string>
|
<string name="exportAsGpxFile">Export as GPX-File</string>
|
||||||
<string name="pref_weight">Your Weight</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_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="pref_unit_system">Preferred system of units</string>
|
||||||
<string name="settings">Settings</string>
|
<string name="settings">Settings</string>
|
||||||
<string name="exportData">Export Data</string>
|
<string name="exportData">Export Data</string>
|
||||||
|
|||||||
@ -42,11 +42,11 @@
|
|||||||
android:title="@string/mapStyle" />
|
android:title="@string/mapStyle" />
|
||||||
|
|
||||||
<Preference
|
<Preference
|
||||||
android:key="spokenUpdatePeriod"
|
android:key="speech"
|
||||||
android:selectAllOnFocus="true"
|
android:selectAllOnFocus="true"
|
||||||
android:singleLine="true"
|
android:singleLine="true"
|
||||||
android:summary="Choose the frequency of spoken updates"
|
android:summary="@string/pref_spoken_updates_summary"
|
||||||
android:title="Spoken updates" />
|
android:title="@string/pref_spoken_updates" />
|
||||||
|
|
||||||
|
|
||||||
<PreferenceCategory android:title="@string/data">
|
<PreferenceCategory android:title="@string/data">
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user