Merge remote-tracking branch 'mylocal/develop' into develop

This commit is contained in:
Ruslan Sokolovski 2020-01-04 19:20:01 -08:00
commit 4e354a8078
13 changed files with 183 additions and 22 deletions

19
.gitignore vendored Normal file
View 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

View File

@ -49,6 +49,12 @@ android {
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
}
lintOptions {
checkReleaseBuilds false
// Or, if you prefer, you can continue to check for errors in release builds,
// but continue the build even when errors are found:
// abortOnError false
}
}
dependencies {

View File

@ -38,6 +38,8 @@ import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.TextView;
import android.speech.tts.TextToSpeech;
import androidx.core.app.ActivityCompat;
import org.mapsforge.core.graphics.Paint;
@ -50,9 +52,11 @@ import org.mapsforge.map.layer.overlay.Polyline;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
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;
@ -82,6 +86,8 @@ public class RecordWorkoutActivity extends FitoTrackActivity implements Location
private Intent locationListener;
private Intent pressureService;
private boolean saved= false;
TextToSpeech tts;
boolean ttsReady = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -102,6 +108,9 @@ public class RecordWorkoutActivity extends FitoTrackActivity implements Location
recorder= new WorkoutRecorder(this, ACTIVITY, this);
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[1]= new InfoViewHolder(findViewById(R.id.recordInfo2Title), findViewById(R.id.recordInfo2Value));
infoViews[2]= new InfoViewHolder(findViewById(R.id.recordInfo3Title), findViewById(R.id.recordInfo3Value));
@ -169,27 +178,48 @@ public class RecordWorkoutActivity extends FitoTrackActivity implements Location
try{
while (recorder.isActive()){
Thread.sleep(1000);
if(isResumed){
mHandler.post(this::updateDescription);
}
}
}catch (InterruptedException e){
e.printStackTrace();
}
}).start();
}
private int i = 0;
long lastSpokenUpdateTime = 0;
int lastSpokenUpdateDistance = 0;
private void updateDescription() {
i++;
timeView.setText(UnitUtils.getHourMinuteSecondTime(recorder.getDuration()));
infoViews[0].setText(getString(R.string.workoutDistance), UnitUtils.getDistance(recorder.getDistance()));
long duration = recorder.getDuration();
int distanceInMeters = recorder.getDistance();
final String distanceCaption = getString(R.string.workoutDistance);
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(getString(R.string.workoutAvgSpeed), UnitUtils.getSpeed(Math.min(100d, recorder.getAvgSpeed())));
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 (!ttsReady ||
(intervalT == 0 || duration / intervalT == lastSpokenUpdateTime / intervalT)
&& (intervalInMeters == 0 || distanceInMeters / intervalInMeters == lastSpokenUpdateDistance / intervalInMeters)
) return;
final String text = distanceCaption + ": " + distance + ". "
+ avgSpeedCaption + ": " + avgSpeed;
tts.speak(text, TextToSpeech.QUEUE_FLUSH, null, "updateDescription" + duration);
lastSpokenUpdateTime = duration;
lastSpokenUpdateDistance = distanceInMeters;
}
private void stop(){
recorder.stop();
if(recorder.getSampleCount() > 3){

View File

@ -165,6 +165,10 @@ public class SettingsActivity extends PreferenceActivity {
showWeightPicker();
return true;
});
findPreference("speech").setOnPreferenceClickListener(preference -> {
showSpeechConfig();
return true;
});
findPreference("import").setOnPreferenceClickListener(preference -> {
showImportDialog();
return true;
@ -285,7 +289,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 preferenceVariable = "weight";
np.setValue((int)Math.round(UnitUtils.CHOSEN_SYSTEM.getWeightFromKilogram(preferences.getInt(preferenceVariable, 80))));
np.setWrapSelectorWheel(false);
d.setView(v);
@ -294,7 +299,47 @@ 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(preferenceVariable, kilograms).apply();
});
d.create().show();
return true;
}
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_spoken_updates_summary));
View v= getLayoutInflater().inflate(R.layout.dialog_spoken_updates_picker, null);
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(updateTimeVariable, npT.getValue())
.putInt(updateDistanceVariable, npD.getValue())
.apply();
});
d.create().show();

View File

@ -35,6 +35,14 @@ public class UserPreferences {
return preferences.getInt("weight", 80);
}
public int getSpokenUpdateTimePeriod(){
return preferences.getInt("spokenUpdateTimePeriod", 5);
}
public int getSpokenUpdateDistancePeriod(){
return preferences.getInt("spokenUpdateDistancePeriod", 1);
}
public String getMapStyle(){
return preferences.getString("mapStyle", "osm.mapnik");
}

View File

@ -62,7 +62,6 @@ public class MapManager {
mapView.getLayerManager().redrawLayers();
mapView.setZoomLevel((byte) 18);
mapView.setCenter(new LatLong(52, 13));
return downloadLayer;
}

View File

@ -30,7 +30,7 @@ public class MapnikTileSource extends FitoTrackTileSource {
"a.tile.openstreetmap.org", "b.tile.openstreetmap.org", "c.tile.openstreetmap.org"}, 443);
private static final int PARALLEL_REQUESTS_LIMIT = 8;
private static final String PROTOCOL = "https";
private static final int ZOOM_LEVEL_MAX = 18;
private static final int ZOOM_LEVEL_MAX = 19;
private static final int ZOOM_LEVEL_MIN = 0;
private static final String NAME = "OSM Mapnik";

View File

@ -47,7 +47,7 @@ public class WorkoutRecorder implements LocationListener.LocationChangeListener
}
}
private static final int PAUSE_TIME= 10000;
private static final int PAUSE_TIME= 1000*1000;
/**
* Time after which the workout is stopped and saved automatically because there is no activity anymore

View File

@ -0,0 +1,40 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (c) 2020 Ruslan Sokolovski <russok@gmail.com>
~
~ This file is part of FitoTrack
~
~ FitoTrack is free software: you can redistribute it and/or modify
~ it under the terms of the GNU General Public License as published by
~ the Free Software Foundation, either version 3 of the License, or
~ (at your option) any later version.
~
~ FitoTrack is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU General Public License for more details.
~
~ You should have received a copy of the GNU General Public License
~ along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<NumberPicker
android:id="@+id/spokenUpdatesTimePicker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
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>

View File

@ -50,6 +50,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>

View File

@ -57,7 +57,7 @@
<string name="workoutPace">Pace</string>
<string name="workoutRoute">Route</string>
<string name="workoutSpeed">Speed</string>
<string name="workoutAvgSpeed">Avg. Speed</string>
<string name="workoutAvgSpeed">Average Speed</string>
<string name="workoutTopSpeed">Top Speed</string>
<string name="workoutBurnedEnergy">Burned Energy</string>
<string name="workoutTotalEnergy">Total Energy</string>
@ -112,6 +112,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>

View File

@ -40,6 +40,13 @@
android:key="mapStyle"
android:title="@string/mapStyle" />
<Preference
android:key="speech"
android:selectAllOnFocus="true"
android:singleLine="true"
android:summary="@string/pref_spoken_updates_summary"
android:title="@string/pref_spoken_updates" />
<PreferenceCategory android:title="@string/data">