allow to select the frequency of spoken updates

This commit is contained in:
Ruslan Sokolovski 2020-01-02 00:59:23 -08:00
parent a0a1f44ef9
commit b9e16bda25
5 changed files with 64 additions and 9 deletions

View File

@ -173,7 +173,7 @@ public class RecordWorkoutActivity extends FitoTrackActivity implements Location
if(isResumed){
mHandler.post(this::updateDescription);
}
mHandler.post(this::speechUpdate);
mHandler.post(this::spokenUpdate);
}
}catch (InterruptedException e){
e.printStackTrace();
@ -181,9 +181,12 @@ public class RecordWorkoutActivity extends FitoTrackActivity implements Location
}).start();
}
private void speechUpdate() {
private void spokenUpdate() {
final long interval = 60 * 1000 * Instance.getInstance(this).userPreferences.getSpokenUpdatePeriod();
if (interval == 0)
return;
long duration = recorder.getDuration();
if (duration / interval == lastSpeechUpdate / interval)
if (duration / interval == lastSpokenUpdate / interval)
return;
timeView.setText(UnitUtils.getHourMinuteSecondTime(duration));
@ -199,12 +202,11 @@ public class RecordWorkoutActivity extends FitoTrackActivity implements Location
tts.speak(text, TextToSpeech.QUEUE_FLUSH, null, "updateDescription" + duration);
});
lastSpeechUpdate = duration;
lastSpokenUpdate = duration;
}
TextToSpeech tts;
long lastSpeechUpdate = 0;
final long interval = 60 * 1000;
long lastSpokenUpdate = 0;
private void updateDescription() {
long duration = recorder.getDuration();

View File

@ -160,6 +160,7 @@ public class SettingsActivity extends PreferenceActivity {
bindPreferenceSummaryToValue(findPreference("mapStyle"));
findPreference("weight").setOnPreferenceClickListener(preference -> showWeightPicker());
findPreference("spokenUpdatePeriod").setOnPreferenceClickListener(preference -> showSpokenUdatePeriodPicker());
findPreference("import").setOnPreferenceClickListener(preference -> showImportDialog());
findPreference("export").setOnPreferenceClickListener(preference -> showExportDialog());
@ -280,7 +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());
np.setValue((int)Math.round(UnitUtils.CHOSEN_SYSTEM.getWeightFromKilogram(preferences.getInt("weight", 80))));
final String preferenceKey = "weight";
np.setValue((int)Math.round(UnitUtils.CHOSEN_SYSTEM.getWeightFromKilogram(preferences.getInt(preferenceKey, 80))));
np.setWrapSelectorWheel(false);
d.setView(v);
@ -289,7 +291,33 @@ 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("weight", kilograms).apply();
preferences.edit().putInt(preferenceKey, kilograms).apply();
});
d.create().show();
return true;
}
private boolean showSpokenUdatePeriodPicker() {
final String preferenceKey = "spokenUpdatePeriod";
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");
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);
d.setView(v);
d.setNegativeButton(R.string.cancel, null);
d.setPositiveButton(R.string.okay, (dialog, which) -> {
preferences.edit().putInt(preferenceKey, np.getValue()).apply();
});
d.create().show();

View File

@ -35,6 +35,10 @@ public class UserPreferences {
return preferences.getInt("weight", 80);
}
public int getSpokenUpdatePeriod(){
return preferences.getInt("spokenUpdatePeriod", 5);
}
public String getMapStyle(){
return preferences.getString("mapStyle", "osm.mapnik");
}

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<NumberPicker
android:id="@+id/spokenUpdatesPicker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_margin="30dp" />
</RelativeLayout>

View File

@ -41,6 +41,13 @@
android:key="mapStyle"
android:title="@string/mapStyle" />
<Preference
android:key="spokenUpdatePeriod"
android:selectAllOnFocus="true"
android:singleLine="true"
android:summary="Choose the frequency of spoken updates"
android:title="Spoken updates" />
<PreferenceCategory android:title="@string/data">