forked from upstream-mirrors/OpenTracks
Compare commits
24 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 8932578b90 | |||
| 631ac9881d | |||
| 78334ed797 | |||
| b06da89654 | |||
| d6c2e78993 | |||
| 67d1ac551d | |||
| dcb6be717d | |||
| f2c04eec1a | |||
| a08311cf43 | |||
| 1e28f3aa86 | |||
| 426af41f2c | |||
| fd08a219f9 | |||
| 25b6aec0e9 | |||
| 3e40209d15 | |||
| 54ff94f905 | |||
| 7a4faf6b0d | |||
| 8922b00a5f | |||
| 702efa8693 | |||
| e7a8c897a3 | |||
| c59d1d87bd | |||
| a706efb8b3 | |||
| e391e83a00 | |||
| 2940bf20d8 | |||
| 081db5a58b |
Generated
+6
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="RenderSettings">
|
||||
<option name="showDecorations" value="true" />
|
||||
</component>
|
||||
</project>
|
||||
@@ -30,6 +30,14 @@ To show your tracks on a map, a 3rd party application (e.g., [OsmAnd](https://pl
|
||||
<img alt="Donate using Liberapay" src="https://liberapay.com/assets/widgets/donate.svg" height="45">
|
||||
</a>
|
||||
|
||||
## Screenshots
|
||||
<div>
|
||||
<img width="20%" src="fastlane/metadata/android/en-US/phoneScreenshots/screenshot_1.png">
|
||||
<img width="20%" src="fastlane/metadata/android/en-US/phoneScreenshots/screenshot_2.png">
|
||||
<img width="20%" src="fastlane/metadata/android/en-US/phoneScreenshots/screenshot_3.png">
|
||||
<img width="20%" src="fastlane/metadata/android/en-US/phoneScreenshots/screenshot_4.png">
|
||||
</div>
|
||||
|
||||
## Project history
|
||||
|
||||
_OpenTracks_ is based upon Google _My Tracks app_ ([code](https://code.google.com/archive/p/mytracks/)).
|
||||
|
||||
+7
-7
@@ -6,7 +6,7 @@ buildscript {
|
||||
jcenter()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:3.5.0'
|
||||
classpath 'com.android.tools.build:gradle:3.5.2'
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,10 +35,14 @@ def getVersionName = { ->
|
||||
try {
|
||||
def stdout = new ByteArrayOutputStream()
|
||||
exec {
|
||||
commandLine 'git', 'describe', '--tags', '--dirty'
|
||||
commandLine 'git', 'describe', '--tags'
|
||||
standardOutput = stdout
|
||||
}
|
||||
return stdout.toString().trim()
|
||||
exec {
|
||||
commandLine 'git', 'log', '--format="%h"', '-n 1'
|
||||
standardOutput = stdout
|
||||
}
|
||||
return stdout.toString().replace('\n', '-').replace('"', '').trim()
|
||||
}
|
||||
catch (ignored) {
|
||||
return null
|
||||
@@ -75,10 +79,6 @@ android {
|
||||
applicationVariants.all { variant ->
|
||||
variant.resValue "string", "applicationId", variant.applicationId
|
||||
}
|
||||
|
||||
lintOptions {
|
||||
disable "AppCompatResource" // TODO Disable complaint to use androidx's SearchView as it is null.
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
Open Tracks – ein GPS-Tracker, der deine Daten für sich behält.
|
||||
OpenTracks – ein GPS-Tracker, der deine Daten für sich behält.
|
||||
Erfasst deine Kilometer, ohne dass es jemand anderes tut.
|
||||
|
||||
Funktionen & Features:
|
||||
|
||||
@@ -1 +1 @@
|
||||
Open Tracks – ein GPS-Tracker, der deine Daten für sich behält.
|
||||
OpenTracks – ein GPS-Tracker, der deine Daten für sich behält.
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
v3.2.6: OpenTracks
|
||||
|
||||
Changes:
|
||||
- Heart rate monitor: scan for available devices
|
||||
- Remove shortcut to Bluetooth settings
|
||||
|
||||
Developer:
|
||||
- Preferences: moved default of preferences from code to xml
|
||||
@@ -0,0 +1,10 @@
|
||||
v3.2.7: OpenTracks
|
||||
|
||||
Changes:
|
||||
- Notification show GPS accuracy
|
||||
- Show heads-up notification if GPS accuracy drops beyond threshold
|
||||
- Always show chart by time as well as by distance
|
||||
- Added help (in Settings)
|
||||
|
||||
Bugfix:
|
||||
- TrackDetailActivity: disabled non-working landscape mode (temporary)
|
||||
@@ -0,0 +1,8 @@
|
||||
OpenTracks es un tracker deportivo que respeta tu privacidad.
|
||||
|
||||
Funciones:
|
||||
* Tracker deportivo: haz un seguimiento de tus actividades al aire libre
|
||||
* Marca lugares de interés, incluso agrega fotos a los marcadores
|
||||
* Pulsómetro (compatible con dispositivos Bluetooth LE)
|
||||
* Exporta tus rutas como KML o GPX
|
||||
* Completamente offline, no necesitas internet
|
||||
@@ -0,0 +1 @@
|
||||
OpenTracks es un tracker deportivo que respeta tu privacidad.
|
||||
@@ -0,0 +1 @@
|
||||
OpenTracks
|
||||
@@ -46,8 +46,10 @@ public class ChartFragmentTest {
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
chartFragment = new ChartFragment();
|
||||
chartFragment.setChartView(new ChartView(ApplicationProvider.getApplicationContext()));
|
||||
boolean chartByDistance = false;
|
||||
chartFragment = new ChartFragment(chartByDistance) {
|
||||
};
|
||||
chartFragment.setChartView(new ChartView(ApplicationProvider.getApplicationContext(), chartByDistance));
|
||||
chartFragment.setTripStatisticsUpdater(TrackStubUtils.INITIAL_TIME);
|
||||
}
|
||||
|
||||
|
||||
+54
@@ -0,0 +1,54 @@
|
||||
package de.dennisguse.opentracks.services;
|
||||
|
||||
import android.app.NotificationManager;
|
||||
import android.content.Context;
|
||||
import android.location.Location;
|
||||
|
||||
import androidx.core.app.NotificationCompat;
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.anyBoolean;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class TrackRecordingServiceNotificationManagerTest {
|
||||
|
||||
private Context context = ApplicationProvider.getApplicationContext();
|
||||
|
||||
@Mock
|
||||
private Location locationMock;
|
||||
|
||||
@Mock
|
||||
private NotificationCompat.Builder notificationCompatBuilder;
|
||||
|
||||
@Mock
|
||||
private NotificationManager notificationManager;
|
||||
|
||||
@Test
|
||||
public void updateLocation_triggersAlertOnlyOnFirstInaccurateLocation() {
|
||||
when(locationMock.hasAccuracy()).thenReturn(true);
|
||||
when(locationMock.getAccuracy()).thenReturn(999f);
|
||||
when(notificationCompatBuilder.setContentText(anyString())).thenReturn(notificationCompatBuilder);
|
||||
when(notificationCompatBuilder.setOnlyAlertOnce(anyBoolean())).thenReturn(notificationCompatBuilder);
|
||||
|
||||
TrackRecordingServiceNotificationManager subject = new TrackRecordingServiceNotificationManager(notificationManager, notificationCompatBuilder);
|
||||
|
||||
// when
|
||||
subject.updateLocation(context, locationMock, 100);
|
||||
subject.updateLocation(context, locationMock, 100);
|
||||
subject.updateLocation(context, locationMock, 1000);
|
||||
subject.updateLocation(context, locationMock, 100);
|
||||
|
||||
// then
|
||||
verify(notificationCompatBuilder, times(6)).setOnlyAlertOnce(true);
|
||||
verify(notificationCompatBuilder, times(2)).setOnlyAlertOnce(false);
|
||||
}
|
||||
}
|
||||
+4
-2
@@ -139,7 +139,8 @@ public class TrackRecordingServiceTestLooper {
|
||||
@MediumTest
|
||||
@Test
|
||||
public void testWithProperties_minRecordingDistanceDefault() throws TimeoutException {
|
||||
PreferencesUtils.setInt(context, R.string.recording_distance_interval_key, PreferencesUtils.RECORDING_DISTANCE_INTERVAL_DEFAULT);
|
||||
int minRecordingIntervalDefault = Integer.parseInt(context.getResources().getString(R.string.min_recording_interval_default));
|
||||
PreferencesUtils.setInt(context, R.string.recording_distance_interval_key, minRecordingIntervalDefault);
|
||||
fullRecordingSession();
|
||||
}
|
||||
|
||||
@@ -202,7 +203,8 @@ public class TrackRecordingServiceTestLooper {
|
||||
@MediumTest
|
||||
@Test
|
||||
public void testWithProperties_minRequiredAccuracyDefault() throws TimeoutException {
|
||||
PreferencesUtils.setInt(context, R.string.recording_gps_accuracy_key, PreferencesUtils.RECORDING_GPS_ACCURACY_DEFAULT);
|
||||
int recordingGPSAccuracyDefault = Integer.parseInt(context.getResources().getString(R.string.recording_gps_accuracy_default));
|
||||
PreferencesUtils.setInt(context, R.string.recording_gps_accuracy_key, recordingGPSAccuracyDefault);
|
||||
fullRecordingSession();
|
||||
}
|
||||
|
||||
|
||||
@@ -16,8 +16,8 @@ limitations under the License.
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="de.dennisguse.opentracks"
|
||||
android:installLocation="auto"
|
||||
android:versionCode="3123"
|
||||
android:versionName="v3.2.5"> <!-- For FDroid. -->
|
||||
android:versionCode="3149"
|
||||
android:versionName="v3.2.7"> <!-- For FDroid. -->
|
||||
<!-- Permission to initialize services -->
|
||||
<application
|
||||
android:name=".Startup"
|
||||
@@ -32,6 +32,10 @@ limitations under the License.
|
||||
|
||||
<activity android:name=".DeleteActivity" />
|
||||
|
||||
<activity
|
||||
android:name=".HelpActivity"
|
||||
android:label="@string/menu_help" />
|
||||
|
||||
<activity
|
||||
android:name=".io.file.importer.ImportActivity"
|
||||
android:theme="@style/ThemeCustomTransparent">
|
||||
@@ -50,10 +54,10 @@ limitations under the License.
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<activity android:name=".MarkerEditActivity" />
|
||||
|
||||
<activity android:name=".MarkerDetailActivity" />
|
||||
|
||||
<activity android:name=".MarkerEditActivity" />
|
||||
|
||||
<activity
|
||||
android:name=".MarkerListActivity"
|
||||
android:label="@string/menu_markers">
|
||||
@@ -79,7 +83,9 @@ limitations under the License.
|
||||
|
||||
<activity android:name=".TrackEditActivity" />
|
||||
|
||||
<activity android:name=".TrackListActivity">
|
||||
<activity
|
||||
android:name=".TrackListActivity"
|
||||
android:screenOrientation="userPortrait">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
|
||||
@@ -17,11 +17,12 @@
|
||||
package de.dennisguse.opentracks;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.speech.tts.TextToSpeech;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
|
||||
import de.dennisguse.opentracks.util.TTSUtils;
|
||||
|
||||
/**
|
||||
* @author Jimmy Shih
|
||||
*/
|
||||
@@ -32,7 +33,7 @@ public abstract class AbstractActivity extends AppCompatActivity {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
// Set volume control stream for text to speech
|
||||
setVolumeControlStream(TextToSpeech.Engine.DEFAULT_STREAM);
|
||||
setVolumeControlStream(TTSUtils.getTTSStream());
|
||||
|
||||
setContentView(getLayoutResId());
|
||||
|
||||
|
||||
@@ -107,7 +107,7 @@ public class ChartView extends View {
|
||||
private int effectiveWidth = 0;
|
||||
private int effectiveHeight = 0;
|
||||
|
||||
private boolean chartByDistance = true;
|
||||
private boolean chartByDistance;
|
||||
private boolean metricUnits = true;
|
||||
private boolean reportSpeed = true;
|
||||
private boolean showPointer = false;
|
||||
@@ -117,8 +117,9 @@ public class ChartView extends View {
|
||||
*
|
||||
* @param context the context
|
||||
*/
|
||||
public ChartView(Context context) {
|
||||
public ChartView(Context context, boolean chartByDistance) {
|
||||
super(context);
|
||||
this.chartByDistance = chartByDistance;
|
||||
|
||||
series[ELEVATION_SERIES] = new ChartValueSeries(context,
|
||||
Integer.MIN_VALUE,
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
package de.dennisguse.opentracks;
|
||||
|
||||
public class HelpActivity extends AbstractActivity {
|
||||
|
||||
@Override
|
||||
protected int getLayoutResId() {
|
||||
return R.layout.help;
|
||||
}
|
||||
}
|
||||
@@ -69,7 +69,7 @@ public class MarkerListActivity extends AbstractActivity implements DeleteMarker
|
||||
private SharedPreferences sharedPreferences;
|
||||
|
||||
private long recordingTrackId = PreferencesUtils.RECORDING_TRACK_ID_DEFAULT;
|
||||
private boolean recordingTrackPaused = PreferencesUtils.RECORDING_TRACK_PAUSED_DEFAULT;
|
||||
private boolean recordingTrackPaused;
|
||||
/*
|
||||
* Note that sharedPreferenceChangeListener cannot be an anonymous inner
|
||||
* class. Anonymous inner class will get garbage collected.
|
||||
@@ -128,6 +128,8 @@ public class MarkerListActivity extends AbstractActivity implements DeleteMarker
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
recordingTrackPaused = PreferencesUtils.isRecordingTrackPausedDefault(this);
|
||||
|
||||
contentProviderUtils = ContentProviderUtils.Factory.get(this);
|
||||
sharedPreferences = PreferencesUtils.getSharedPreferences(this);
|
||||
|
||||
|
||||
@@ -101,7 +101,7 @@ public class SearchListActivity extends AbstractListActivity implements DeleteMa
|
||||
|
||||
private long recordingTrackId = PreferencesUtils.RECORDING_TRACK_ID_DEFAULT;
|
||||
|
||||
private boolean recordingTrackPaused = PreferencesUtils.RECORDING_TRACK_PAUSED_DEFAULT;
|
||||
private boolean recordingTrackPaused;
|
||||
|
||||
// Callback when an item is selected in the contextual action mode
|
||||
private ContextualActionModeCallback contextualActionModeCallback = new ContextualActionModeCallback() {
|
||||
@@ -168,6 +168,8 @@ public class SearchListActivity extends AbstractListActivity implements DeleteMa
|
||||
super.onCreate(savedInstanceState);
|
||||
setDefaultKeyMode(DEFAULT_KEYS_SEARCH_LOCAL);
|
||||
|
||||
recordingTrackPaused = PreferencesUtils.isRecordingTrackPausedDefault(this);
|
||||
|
||||
contentProviderUtils = ContentProviderUtils.Factory.get(this);
|
||||
sharedPreferences = PreferencesUtils.getSharedPreferences(this);
|
||||
trackRecordingServiceConnection = new TrackRecordingServiceConnection(this, null);
|
||||
|
||||
@@ -45,7 +45,8 @@ import de.dennisguse.opentracks.content.TrackDataHub;
|
||||
import de.dennisguse.opentracks.content.Waypoint;
|
||||
import de.dennisguse.opentracks.content.Waypoint.WaypointType;
|
||||
import de.dennisguse.opentracks.content.WaypointCreationRequest;
|
||||
import de.dennisguse.opentracks.fragments.ChartFragment;
|
||||
import de.dennisguse.opentracks.fragments.ChartDistanceFragment;
|
||||
import de.dennisguse.opentracks.fragments.ChartTimeFragment;
|
||||
import de.dennisguse.opentracks.fragments.ChooseActivityTypeDialogFragment;
|
||||
import de.dennisguse.opentracks.fragments.ConfirmDeleteDialogFragment;
|
||||
import de.dennisguse.opentracks.fragments.StatsFragment;
|
||||
@@ -54,6 +55,7 @@ import de.dennisguse.opentracks.settings.SettingsActivity;
|
||||
import de.dennisguse.opentracks.util.FileUtils;
|
||||
import de.dennisguse.opentracks.util.IntentUtils;
|
||||
import de.dennisguse.opentracks.util.PreferencesUtils;
|
||||
import de.dennisguse.opentracks.util.StatsUtils;
|
||||
import de.dennisguse.opentracks.util.TrackIconUtils;
|
||||
import de.dennisguse.opentracks.util.TrackUtils;
|
||||
|
||||
@@ -93,7 +95,7 @@ public class TrackDetailActivity extends AbstractListActivity implements ChooseA
|
||||
|
||||
// Preferences
|
||||
private long recordingTrackId = PreferencesUtils.RECORDING_TRACK_ID_DEFAULT;
|
||||
private boolean recordingTrackPaused = PreferencesUtils.RECORDING_TRACK_PAUSED_DEFAULT;
|
||||
private boolean recordingTrackPaused;
|
||||
|
||||
private final Runnable bindChangedCallback = new Runnable() {
|
||||
@Override
|
||||
@@ -120,8 +122,7 @@ public class TrackDetailActivity extends AbstractListActivity implements ChooseA
|
||||
* Note that sharedPreferenceChangeListener cannot be an anonymous inner
|
||||
* class. Anonymous inner class will get garbage collected.
|
||||
*/
|
||||
private final OnSharedPreferenceChangeListener
|
||||
sharedPreferenceChangeListener = new OnSharedPreferenceChangeListener() {
|
||||
private final OnSharedPreferenceChangeListener sharedPreferenceChangeListener = new OnSharedPreferenceChangeListener() {
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences preferences, String key) {
|
||||
if (PreferencesUtils.isKey(TrackDetailActivity.this, R.string.recording_track_id_key, key)) {
|
||||
@@ -182,6 +183,8 @@ public class TrackDetailActivity extends AbstractListActivity implements ChooseA
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
recordingTrackPaused = PreferencesUtils.isRecordingTrackPausedDefault(this);
|
||||
|
||||
hasCamera = getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA);
|
||||
photoUri = savedInstanceState != null ? (Uri) savedInstanceState.getParcelable(PHOTO_URI_KEY) : null;
|
||||
hasPhoto = savedInstanceState != null && savedInstanceState.getBoolean(HAS_PHOTO_KEY, false);
|
||||
@@ -203,8 +206,11 @@ public class TrackDetailActivity extends AbstractListActivity implements ChooseA
|
||||
TabSpec statsTabSpec = tabHost.newTabSpec(StatsFragment.STATS_FRAGMENT_TAG).setIndicator(getString(R.string.track_detail_stats_tab));
|
||||
tabsAdapter.addTab(statsTabSpec, StatsFragment.class, null);
|
||||
|
||||
TabSpec chartTabSpec = tabHost.newTabSpec(ChartFragment.CHART_FRAGMENT_TAG).setIndicator(getString(R.string.track_detail_chart_tab));
|
||||
tabsAdapter.addTab(chartTabSpec, ChartFragment.class, null);
|
||||
TabSpec chartTimeTabSpec = tabHost.newTabSpec(ChartTimeFragment.CHART_FRAGMENT_TAG).setIndicator(getString(R.string.settings_chart_by_time));
|
||||
tabsAdapter.addTab(chartTimeTabSpec, ChartTimeFragment.class, null);
|
||||
|
||||
TabSpec chartDistanceTabSpec = tabHost.newTabSpec(ChartDistanceFragment.CHART_FRAGMENT_TAG).setIndicator(getString(R.string.settings_chart_by_distance));
|
||||
tabsAdapter.addTab(chartDistanceTabSpec, ChartDistanceFragment.class, null);
|
||||
|
||||
if (savedInstanceState != null) {
|
||||
tabHost.setCurrentTabByTag(savedInstanceState.getString(CURRENT_TAB_TAG_KEY));
|
||||
@@ -410,10 +416,16 @@ public class TrackDetailActivity extends AbstractListActivity implements ChooseA
|
||||
/**
|
||||
* Gets the track id.
|
||||
*/
|
||||
// TODO Seems to be no used.
|
||||
@Deprecated
|
||||
public long getTrackId() {
|
||||
return trackId;
|
||||
}
|
||||
|
||||
private void setBluetoothHeartRateSensorName(String sensorName) {
|
||||
StatsUtils.setBluetoothHeartRateSensorName(this, sensorName, isRecording());
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles the data in the intent.
|
||||
*/
|
||||
|
||||
@@ -125,7 +125,7 @@ public class TrackListActivity extends AbstractListActivity implements ConfirmDe
|
||||
}
|
||||
};
|
||||
|
||||
private boolean recordingTrackPaused = PreferencesUtils.RECORDING_TRACK_PAUSED_DEFAULT;
|
||||
private boolean recordingTrackPaused;
|
||||
|
||||
/*
|
||||
* Note that sharedPreferenceChangeListener cannot be an anonymous inner class.
|
||||
@@ -225,8 +225,7 @@ public class TrackListActivity extends AbstractListActivity implements ConfirmDe
|
||||
// Not recording -> Recording
|
||||
updateMenuItems(false, true);
|
||||
startRecording();
|
||||
} else {
|
||||
if (recordingTrackPaused) {
|
||||
} else if (recordingTrackPaused) {
|
||||
// Paused -> Resume
|
||||
updateMenuItems(false, true);
|
||||
trackRecordingServiceConnection.resumeTrack();
|
||||
@@ -237,7 +236,6 @@ public class TrackListActivity extends AbstractListActivity implements ConfirmDe
|
||||
trackRecordingServiceConnection.pauseTrack();
|
||||
trackController.update(true, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -245,6 +243,8 @@ public class TrackListActivity extends AbstractListActivity implements ConfirmDe
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
recordingTrackPaused = PreferencesUtils.isRecordingTrackPausedDefault(this);
|
||||
|
||||
contentProviderUtils = ContentProviderUtils.Factory.get(this);
|
||||
sharedPreferences = PreferencesUtils.getSharedPreferences(this);
|
||||
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
package de.dennisguse.opentracks.fragments;
|
||||
|
||||
public class ChartDistanceFragment extends ChartFragment {
|
||||
|
||||
public static final String CHART_FRAGMENT_TAG = ChartDistanceFragment.class.getSimpleName();
|
||||
|
||||
public ChartDistanceFragment() {
|
||||
super(true);
|
||||
}
|
||||
}
|
||||
@@ -25,6 +25,7 @@ import android.view.ViewGroup.LayoutParams;
|
||||
import android.widget.ZoomControls;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
@@ -54,9 +55,9 @@ import de.dennisguse.opentracks.util.UnitConversions;
|
||||
* @author Sandor Dornbush
|
||||
* @author Rodrigo Damazio
|
||||
*/
|
||||
public class ChartFragment extends Fragment implements TrackDataListener {
|
||||
public abstract class ChartFragment extends Fragment implements TrackDataListener {
|
||||
|
||||
public static final String CHART_FRAGMENT_TAG = "chartFragment";
|
||||
private static final String STATE_CHART_VIEW_BY_DISTANCE_KEY = "chartViewByDistance";
|
||||
|
||||
private final ArrayList<double[]> pendingPoints = new ArrayList<>();
|
||||
|
||||
@@ -68,10 +69,10 @@ public class ChartFragment extends Fragment implements TrackDataListener {
|
||||
|
||||
private boolean metricUnits = true;
|
||||
private boolean reportSpeed = true;
|
||||
private int recordingDistanceInterval = PreferencesUtils.RECORDING_DISTANCE_INTERVAL_DEFAULT;
|
||||
private int recordingDistanceInterval;
|
||||
|
||||
// Modes of operation
|
||||
private boolean chartByDistance = true;
|
||||
private boolean chartByDistance;
|
||||
private boolean[] chartShow = new boolean[]{true, true, true, true, true, true};
|
||||
|
||||
// UI elements
|
||||
@@ -95,14 +96,18 @@ public class ChartFragment extends Fragment implements TrackDataListener {
|
||||
}
|
||||
};
|
||||
|
||||
public ChartFragment(boolean chartByDistance) {
|
||||
this.chartByDistance = chartByDistance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
/*
|
||||
* Create a chartView here to store data thus won't need to reload all the data on every onStart or onResume.
|
||||
*/
|
||||
chartView = new ChartView(getActivity());
|
||||
recordingDistanceInterval = PreferencesUtils.getRecordingDistanceIntervalDefault(getContext());
|
||||
|
||||
// Create a chartView here to store data thus won't need to reload all the data on every onStart or onResume.
|
||||
chartView = new ChartView(getActivity(), chartByDistance);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -127,7 +132,7 @@ public class ChartFragment extends Fragment implements TrackDataListener {
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
ViewGroup layout = getActivity().findViewById(R.id.chart_view_layout);
|
||||
ViewGroup layout = getView().findViewById(R.id.chart_view_layout);
|
||||
LayoutParams layoutParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
|
||||
layout.addView(chartView, layoutParams);
|
||||
}
|
||||
@@ -149,10 +154,24 @@ public class ChartFragment extends Fragment implements TrackDataListener {
|
||||
@Override
|
||||
public void onStop() {
|
||||
super.onStop();
|
||||
ViewGroup layout = getActivity().findViewById(R.id.chart_view_layout);
|
||||
ViewGroup layout = getView().findViewById(R.id.chart_view_layout);
|
||||
layout.removeView(chartView);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(@NonNull Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putBoolean(STATE_CHART_VIEW_BY_DISTANCE_KEY, chartByDistance);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewStateRestored(@Nullable Bundle savedInstanceState) {
|
||||
super.onViewStateRestored(savedInstanceState);
|
||||
if (savedInstanceState != null) {
|
||||
chartByDistance = savedInstanceState.getBoolean(STATE_CHART_VIEW_BY_DISTANCE_KEY);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTrackUpdated(Track track) {
|
||||
if (isResumed()) {
|
||||
@@ -302,12 +321,6 @@ public class ChartFragment extends Fragment implements TrackDataListener {
|
||||
*/
|
||||
private void checkChartSettings() {
|
||||
boolean needUpdate = false;
|
||||
if (chartByDistance != PreferencesUtils.isChartByDistance(getActivity())) {
|
||||
chartByDistance = !chartByDistance;
|
||||
chartView.setChartByDistance(chartByDistance);
|
||||
reloadTrackDataHub();
|
||||
needUpdate = true;
|
||||
}
|
||||
if (setSeriesEnabled(ChartView.ELEVATION_SERIES, PreferencesUtils.shouldChartShowElevation(getActivity()))) {
|
||||
needUpdate = true;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
package de.dennisguse.opentracks.fragments;
|
||||
|
||||
public class ChartTimeFragment extends ChartFragment {
|
||||
|
||||
public static final String CHART_FRAGMENT_TAG = ChartTimeFragment.class.getSimpleName();
|
||||
|
||||
public ChartTimeFragment() {
|
||||
super(false);
|
||||
}
|
||||
}
|
||||
@@ -45,7 +45,6 @@ import de.dennisguse.opentracks.services.ITrackRecordingService;
|
||||
import de.dennisguse.opentracks.services.TrackRecordingServiceConnection;
|
||||
import de.dennisguse.opentracks.stats.TripStatistics;
|
||||
import de.dennisguse.opentracks.util.LocationUtils;
|
||||
import de.dennisguse.opentracks.util.PreferencesUtils;
|
||||
import de.dennisguse.opentracks.util.StatsUtils;
|
||||
import de.dennisguse.opentracks.util.TrackIconUtils;
|
||||
import de.dennisguse.opentracks.util.UnitConversions;
|
||||
@@ -81,7 +80,7 @@ public class StatsFragment extends Fragment implements TrackDataListener {
|
||||
}
|
||||
};
|
||||
private String category = "";
|
||||
private int recordingGpsAccuracy = PreferencesUtils.RECORDING_GPS_ACCURACY_DEFAULT;
|
||||
private int recordingGpsAccuracy;
|
||||
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
@@ -91,6 +90,9 @@ public class StatsFragment extends Fragment implements TrackDataListener {
|
||||
@Override
|
||||
public void onActivityCreated(Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
|
||||
recordingGpsAccuracy = Integer.parseInt(getContext().getResources().getString(R.string.recording_gps_accuracy_default));
|
||||
|
||||
handlerUpdateUI = new Handler();
|
||||
|
||||
Spinner activityTypeIcon = getView().findViewById(R.id.stats_activity_type_icon);
|
||||
|
||||
@@ -33,10 +33,6 @@ public class LocationManagerConnector {
|
||||
private final Handler handler;
|
||||
private final LocationManager locationManager;
|
||||
|
||||
private LocationListener requestLocationUpdates;
|
||||
private float requestLocationUpdatesDistance;
|
||||
private long requestLocationUpdatesTime;
|
||||
|
||||
public LocationManagerConnector(Context context, Looper looper) {
|
||||
this.handler = new Handler(looper);
|
||||
|
||||
@@ -55,10 +51,7 @@ public class LocationManagerConnector {
|
||||
@Override
|
||||
@SuppressLint("MissingPermission")
|
||||
public void run() {
|
||||
requestLocationUpdatesTime = minTime;
|
||||
requestLocationUpdatesDistance = minDistance;
|
||||
requestLocationUpdates = locationListener;
|
||||
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, requestLocationUpdatesTime, requestLocationUpdatesDistance, locationListener);
|
||||
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, minTime, minDistance, locationListener);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -70,6 +63,5 @@ public class LocationManagerConnector {
|
||||
*/
|
||||
public void removeLocationUpdates(final LocationListener locationListener) {
|
||||
locationManager.removeUpdates(locationListener);
|
||||
requestLocationUpdates = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,9 +16,6 @@
|
||||
|
||||
package de.dennisguse.opentracks.services;
|
||||
|
||||
import android.app.Notification;
|
||||
import android.app.NotificationChannel;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.app.Service;
|
||||
import android.content.Context;
|
||||
@@ -30,7 +27,6 @@ import android.location.Location;
|
||||
import android.location.LocationListener;
|
||||
import android.location.LocationManager;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.IBinder;
|
||||
@@ -38,7 +34,6 @@ import android.os.PowerManager.WakeLock;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.core.app.NotificationCompat;
|
||||
import androidx.core.app.TaskStackBuilder;
|
||||
|
||||
import java.util.concurrent.ExecutorService;
|
||||
@@ -80,13 +75,13 @@ import de.dennisguse.opentracks.util.UnitConversions;
|
||||
public class TrackRecordingService extends Service {
|
||||
|
||||
// The name of extra intent property to indicate whether we want to resume a previously recorded track.
|
||||
public static final String RESUME_TRACK_EXTRA_NAME = "de.dennisguse.opentracks.RESUME_TRACK";
|
||||
public static final String RESUME_TRACK_EXTRA_NAME = "RESUME_TRACK";
|
||||
private static final int NOTIFICATION_ID = 123;
|
||||
|
||||
public static final double PAUSE_LATITUDE = 100.0;
|
||||
public static final double RESUME_LATITUDE = 200.0;
|
||||
|
||||
// Anything faster than that (in meters per second) will be considered moving.
|
||||
|
||||
public static final double MAX_NO_MOVEMENT_SPEED = 0.224;
|
||||
@VisibleForTesting
|
||||
static final int MAX_AUTO_RESUME_TRACK_RETRY_ATTEMPTS = 3;
|
||||
@@ -95,13 +90,13 @@ public class TrackRecordingService extends Service {
|
||||
private static final long ONE_MINUTE = (long) (UnitConversions.MIN_TO_S * UnitConversions.S_TO_MS);
|
||||
// The following variables are set in onCreate:
|
||||
private ExecutorService executorService;
|
||||
private Context context;
|
||||
private ContentProviderUtils contentProviderUtils;
|
||||
private Handler handler;
|
||||
private LocationManagerConnector locationManagerConnector;
|
||||
private PeriodicTaskExecutor voiceExecutor;
|
||||
private PeriodicTaskExecutor splitExecutor;
|
||||
private SharedPreferences sharedPreferences;
|
||||
private TrackRecordingServiceNotificationManager notificationManager;
|
||||
private long recordingTrackId;
|
||||
private boolean recordingTrackPaused;
|
||||
private LocationListenerPolicy locationListenerPolicy;
|
||||
@@ -117,10 +112,11 @@ public class TrackRecordingService extends Service {
|
||||
private final OnSharedPreferenceChangeListener sharedPreferenceChangeListener = new OnSharedPreferenceChangeListener() {
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences preferences, String key) {
|
||||
if (PreferencesUtils.isKey(context, R.string.recording_track_id_key, key)) {
|
||||
Context context = TrackRecordingService.this;
|
||||
if (PreferencesUtils.isKey(TrackRecordingService.this, R.string.recording_track_id_key, key)) {
|
||||
// Only through the TrackRecordingService can one stop a recording and set the recordingTrackId to -1L.
|
||||
if (PreferencesUtils.isRecording(context)) {
|
||||
recordingTrackId = PreferencesUtils.getRecordingTrackId(context);
|
||||
if (PreferencesUtils.isRecording(TrackRecordingService.this)) {
|
||||
recordingTrackId = PreferencesUtils.getRecordingTrackId(TrackRecordingService.this);
|
||||
}
|
||||
}
|
||||
if (PreferencesUtils.isKey(context, R.string.recording_track_paused_key, key)) {
|
||||
@@ -139,17 +135,14 @@ public class TrackRecordingService extends Service {
|
||||
}
|
||||
if (PreferencesUtils.isKey(context, R.string.min_recording_interval_key, key)) {
|
||||
int minRecordingInterval = PreferencesUtils.getMinRecordingInterval(context);
|
||||
switch (minRecordingInterval) {
|
||||
case PreferencesUtils.MIN_RECORDING_INTERVAL_ADAPT_BATTERY_LIFE:
|
||||
// Choose battery life over moving time accuracy.
|
||||
locationListenerPolicy = new AdaptiveLocationListenerPolicy(30 * UnitConversions.ONE_SECOND, 5 * ONE_MINUTE, 5);
|
||||
break;
|
||||
case PreferencesUtils.MIN_RECORDING_INTERVAL_ADAPT_ACCURACY:
|
||||
// Get all the updates.
|
||||
locationListenerPolicy = new AdaptiveLocationListenerPolicy(UnitConversions.ONE_SECOND, 30 * UnitConversions.ONE_SECOND, 0);
|
||||
break;
|
||||
default:
|
||||
locationListenerPolicy = new AbsoluteLocationListenerPolicy(minRecordingInterval * UnitConversions.ONE_SECOND);
|
||||
if (minRecordingInterval == PreferencesUtils.getMinRecordingIntervalAdaptBatteryLife(context)) {
|
||||
// Choose battery life over moving time accuracy.
|
||||
locationListenerPolicy = new AdaptiveLocationListenerPolicy(30 * UnitConversions.ONE_SECOND, 5 * ONE_MINUTE, 5);
|
||||
} else if (minRecordingInterval == PreferencesUtils.getMinRecordingIntervalAdaptAccuracy(context)) {
|
||||
// Get all the updates.
|
||||
locationListenerPolicy = new AdaptiveLocationListenerPolicy(UnitConversions.ONE_SECOND, 30 * UnitConversions.ONE_SECOND, 0);
|
||||
} else {
|
||||
locationListenerPolicy = new AbsoluteLocationListenerPolicy(minRecordingInterval * UnitConversions.ONE_SECOND);
|
||||
}
|
||||
}
|
||||
if (PreferencesUtils.isKey(context, R.string.recording_distance_interval_key, key)) {
|
||||
@@ -221,7 +214,6 @@ public class TrackRecordingService extends Service {
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
executorService = Executors.newSingleThreadExecutor();
|
||||
context = this;
|
||||
contentProviderUtils = ContentProviderUtils.Factory.get(this);
|
||||
handler = new Handler();
|
||||
locationManagerConnector = new LocationManagerConnector(this, handler.getLooper());
|
||||
@@ -229,6 +221,7 @@ public class TrackRecordingService extends Service {
|
||||
splitExecutor = new PeriodicTaskExecutor(this, new SplitPeriodicTaskFactory());
|
||||
sharedPreferences = PreferencesUtils.getSharedPreferences(this);
|
||||
sharedPreferences.registerOnSharedPreferenceChangeListener(sharedPreferenceChangeListener);
|
||||
notificationManager = new TrackRecordingServiceNotificationManager(this);
|
||||
|
||||
// onSharedPreferenceChanged might not set recordingTrackId.
|
||||
recordingTrackId = PreferencesUtils.RECORDING_TRACK_ID_DEFAULT;
|
||||
@@ -270,7 +263,7 @@ public class TrackRecordingService extends Service {
|
||||
}
|
||||
|
||||
// Reverse order from onCreate
|
||||
showNotification(false);
|
||||
showNotification(false); //TODO Why?
|
||||
|
||||
handler.removeCallbacks(registerLocationRunnable);
|
||||
unregisterLocationListener();
|
||||
@@ -403,40 +396,6 @@ public class TrackRecordingService extends Service {
|
||||
return Long.parseLong(uri.getLastPathSegment());
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts the service as a foreground service.
|
||||
*
|
||||
* @param pendingIntent the notification pending intent
|
||||
* @param messageId the notification message id
|
||||
*/
|
||||
@VisibleForTesting
|
||||
protected void startForegroundService(PendingIntent pendingIntent, int messageId) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
NotificationChannel notificationChannel = new NotificationChannel(getString(R.string.app_name), getString(R.string.app_name), NotificationManager.IMPORTANCE_DEFAULT);
|
||||
NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
if (manager != null) {
|
||||
manager.createNotificationChannel(notificationChannel);
|
||||
}
|
||||
}
|
||||
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, getString(R.string.app_name))
|
||||
.setContentIntent(pendingIntent)
|
||||
.setContentText(getString(messageId))
|
||||
.setContentTitle(getString(R.string.app_name))
|
||||
.setOngoing(true)
|
||||
.setSmallIcon(R.drawable.ic_logo_color_24dp)
|
||||
.setCategory(Notification.CATEGORY_SERVICE)
|
||||
.setWhen(System.currentTimeMillis());
|
||||
startForeground(1, builder.build());
|
||||
}
|
||||
|
||||
/**
|
||||
* Stops the service as a foreground service.
|
||||
*/
|
||||
@VisibleForTesting
|
||||
protected void stopForegroundService() {
|
||||
stopForeground(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles start command.
|
||||
*
|
||||
@@ -471,12 +430,12 @@ public class TrackRecordingService extends Service {
|
||||
}
|
||||
PreferencesUtils.incrementAutoResumeTrackCurrentRetryDefault(this);
|
||||
|
||||
if (autoResumeTrackTimeout == Integer.parseInt(context.getResources().getString(R.string.auto_resume_track_timeout_never))) {
|
||||
if (autoResumeTrackTimeout == Integer.parseInt(getResources().getString(R.string.auto_resume_track_timeout_never))) {
|
||||
Log.d(TAG, "Not resuming. Auto-resume track timeout set to never.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (autoResumeTrackTimeout == Integer.parseInt(context.getResources().getString(R.string.auto_resume_track_timeout_always))) {
|
||||
if (autoResumeTrackTimeout == Integer.parseInt(getResources().getString(R.string.auto_resume_track_timeout_always))) {
|
||||
Log.d(TAG, "Resuming. Auto-resume track timeout set to always.");
|
||||
return true;
|
||||
}
|
||||
@@ -680,6 +639,8 @@ public class TrackRecordingService extends Service {
|
||||
}
|
||||
|
||||
endRecording(false, recordingTrackId);
|
||||
|
||||
notificationManager.updateContent(getString(R.string.generic_paused));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -766,6 +727,8 @@ public class TrackRecordingService extends Service {
|
||||
return;
|
||||
}
|
||||
|
||||
notificationManager.updateLocation(this, location, recordingGpsAccuracy);
|
||||
|
||||
if (!location.hasAccuracy() || location.getAccuracy() >= recordingGpsAccuracy) {
|
||||
Log.d(TAG, "Ignore onLocationChangedAsync. Poor accuracy.");
|
||||
return;
|
||||
@@ -801,10 +764,7 @@ public class TrackRecordingService extends Service {
|
||||
}
|
||||
|
||||
if (!LocationUtils.isValidLocation(lastValidTrackPoint)) {
|
||||
/*
|
||||
* Should not happen. The current segment should have a location. Just
|
||||
* insert the current location.
|
||||
*/
|
||||
// Should not happen. The current segment should have a location. Just insert the current location.
|
||||
insertLocation(track, location, null);
|
||||
lastLocation = location;
|
||||
return;
|
||||
@@ -951,33 +911,33 @@ public class TrackRecordingService extends Service {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the notification.
|
||||
*
|
||||
* @param isGpsStarted true if GPS is started
|
||||
*/
|
||||
private void showNotification(boolean isGpsStarted) {
|
||||
if (isRecording()) {
|
||||
if (isPaused()) {
|
||||
stopForegroundService();
|
||||
} else {
|
||||
Intent intent = IntentUtils.newIntent(this, TrackDetailActivity.class)
|
||||
.putExtra(TrackDetailActivity.EXTRA_TRACK_ID, recordingTrackId);
|
||||
PendingIntent pendingIntent = TaskStackBuilder.create(this)
|
||||
.addParentStack(TrackDetailActivity.class).addNextIntent(intent)
|
||||
.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
startForegroundService(pendingIntent, R.string.track_record_notification);
|
||||
}
|
||||
} else {
|
||||
// Not recording
|
||||
if (isGpsStarted) {
|
||||
Intent intent = IntentUtils.newIntent(this, TrackListActivity.class);
|
||||
PendingIntent pendingIntent = TaskStackBuilder.create(this)
|
||||
.addNextIntent(intent).getPendingIntent(0, 0);
|
||||
startForegroundService(pendingIntent, R.string.gps_starting);
|
||||
} else {
|
||||
stopForegroundService();
|
||||
}
|
||||
if ((isRecording() && isPaused()) || (!isRecording() && !isGpsStarted)) {
|
||||
stopForeground(true);
|
||||
}
|
||||
|
||||
if (isRecording() && !isPaused()) {
|
||||
Intent intent = IntentUtils.newIntent(this, TrackDetailActivity.class)
|
||||
.putExtra(TrackDetailActivity.EXTRA_TRACK_ID, recordingTrackId);
|
||||
PendingIntent pendingIntent = TaskStackBuilder.create(this)
|
||||
.addParentStack(TrackDetailActivity.class)
|
||||
.addNextIntent(intent)
|
||||
.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
|
||||
notificationManager.updatePendingIntent(pendingIntent);
|
||||
notificationManager.updateContent(getString(R.string.gps_starting));
|
||||
startForeground(NOTIFICATION_ID, notificationManager.getNotification());
|
||||
}
|
||||
if (!isRecording() && isGpsStarted) {
|
||||
Intent intent = IntentUtils.newIntent(this, TrackListActivity.class);
|
||||
PendingIntent pendingIntent = TaskStackBuilder.create(this)
|
||||
.addNextIntent(intent)
|
||||
.getPendingIntent(0, 0);
|
||||
|
||||
notificationManager.updatePendingIntent(pendingIntent);
|
||||
notificationManager.updateContent(getString(R.string.gps_starting));
|
||||
|
||||
startForeground(NOTIFICATION_ID, notificationManager.getNotification());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+94
@@ -0,0 +1,94 @@
|
||||
package de.dennisguse.opentracks.services;
|
||||
|
||||
import android.app.Notification;
|
||||
import android.app.NotificationChannel;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
import android.location.Location;
|
||||
import android.os.Build;
|
||||
|
||||
import androidx.annotation.VisibleForTesting;
|
||||
import androidx.core.app.NotificationCompat;
|
||||
|
||||
import de.dennisguse.opentracks.R;
|
||||
import de.dennisguse.opentracks.util.PreferencesUtils;
|
||||
import de.dennisguse.opentracks.util.StringUtils;
|
||||
|
||||
/**
|
||||
* Manages the content of the notification shown by {@link TrackRecordingService}.
|
||||
*/
|
||||
class TrackRecordingServiceNotificationManager {
|
||||
|
||||
private final static int NOTIFICATION_ID = 123;
|
||||
|
||||
private final static String CHANNEL_ID = TrackRecordingServiceNotificationManager.class.getSimpleName();
|
||||
|
||||
private NotificationCompat.Builder notificationBuilder;
|
||||
|
||||
private NotificationManager notificationManager;
|
||||
|
||||
private boolean previousLocationWasAccurate = true;
|
||||
|
||||
TrackRecordingServiceNotificationManager(Context context) {
|
||||
notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
NotificationChannel notificationChannel = new NotificationChannel(CHANNEL_ID, context.getString(R.string.app_name), NotificationManager.IMPORTANCE_HIGH);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
||||
notificationChannel.setAllowBubbles(true);
|
||||
}
|
||||
|
||||
notificationManager.createNotificationChannel(notificationChannel);
|
||||
}
|
||||
|
||||
notificationBuilder = new NotificationCompat.Builder(context, CHANNEL_ID);
|
||||
notificationBuilder
|
||||
.setDefaults(NotificationCompat.DEFAULT_ALL)
|
||||
.setPriority(NotificationCompat.PRIORITY_MAX)
|
||||
.setOnlyAlertOnce(true)
|
||||
.setOngoing(true)
|
||||
.setCategory(NotificationCompat.CATEGORY_SERVICE)
|
||||
.setContentTitle(context.getString(R.string.app_name))
|
||||
.setSmallIcon(R.drawable.ic_logo_color_24dp);
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
TrackRecordingServiceNotificationManager(NotificationManager notificationManager, NotificationCompat.Builder notificationBuilder) {
|
||||
this.notificationManager = notificationManager;
|
||||
this.notificationBuilder = notificationBuilder;
|
||||
}
|
||||
|
||||
void updateContent(String content) {
|
||||
notificationBuilder.setContentText(content);
|
||||
updateNotification();
|
||||
}
|
||||
|
||||
void updateLocation(Context context, Location location, int recordingGpsAccuracy) {
|
||||
String formattedAccuracy = context.getString(R.string.value_none);
|
||||
if (location.hasAccuracy()) {
|
||||
formattedAccuracy = StringUtils.formatDistance(context, location.getAccuracy(), PreferencesUtils.isMetricUnits(context));
|
||||
|
||||
boolean currentLocationWasAccurate = location.getAccuracy() < recordingGpsAccuracy;
|
||||
boolean shouldAlert = !currentLocationWasAccurate && previousLocationWasAccurate;
|
||||
notificationBuilder.setOnlyAlertOnce(!shouldAlert);
|
||||
previousLocationWasAccurate = currentLocationWasAccurate;
|
||||
}
|
||||
|
||||
notificationBuilder.setContentText(context.getString(R.string.track_recording_notification_accuracy, formattedAccuracy));
|
||||
updateNotification();
|
||||
notificationBuilder.setOnlyAlertOnce(true);
|
||||
}
|
||||
|
||||
void updatePendingIntent(PendingIntent pendingIntent) {
|
||||
notificationBuilder.setContentIntent(pendingIntent);
|
||||
updateNotification();
|
||||
}
|
||||
|
||||
Notification getNotification() {
|
||||
return notificationBuilder.build();
|
||||
}
|
||||
|
||||
private void updateNotification() {
|
||||
notificationManager.notify(NOTIFICATION_ID, getNotification());
|
||||
}
|
||||
}
|
||||
+14
-5
@@ -21,6 +21,7 @@ import android.bluetooth.BluetoothGatt;
|
||||
import android.bluetooth.BluetoothGattCallback;
|
||||
import android.bluetooth.BluetoothGattCharacteristic;
|
||||
import android.bluetooth.BluetoothGattDescriptor;
|
||||
import android.bluetooth.BluetoothGattService;
|
||||
import android.bluetooth.BluetoothProfile;
|
||||
import android.content.Context;
|
||||
import android.os.Handler;
|
||||
@@ -45,7 +46,6 @@ public class BluetoothConnectionManager {
|
||||
static final int MESSAGE_READ = 3;
|
||||
static final int MESSAGE_DISCONNECTED = 4;
|
||||
|
||||
private static final UUID HEART_RATE_SERVICE_UUID = new UUID(0x180D00001000L, 0x800000805f9b34fbL);
|
||||
private static final UUID HEART_RATE_MEASUREMENT_CHAR_UUID = new UUID(0x2A3700001000L, 0x800000805f9b34fbL);
|
||||
private static final UUID CLIENT_CHARACTERISTIC_CONFIG_UUID = new UUID(0x290200001000L, 0x800000805f9b34fbL);
|
||||
|
||||
@@ -90,10 +90,18 @@ public class BluetoothConnectionManager {
|
||||
|
||||
@Override
|
||||
public void onServicesDiscovered(@NonNull BluetoothGatt gatt, int status) {
|
||||
BluetoothGattCharacteristic characteristic = gatt
|
||||
.getService(HEART_RATE_SERVICE_UUID)
|
||||
.getCharacteristic(HEART_RATE_MEASUREMENT_CHAR_UUID);
|
||||
BluetoothGattService service = gatt.getService(BluetoothUtils.HEART_RATE_SERVICE_UUID);
|
||||
if (service == null) {
|
||||
Log.e(TAG, "Could not get heart rate service for " + gatt.getDevice().getAddress());
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
BluetoothGattCharacteristic characteristic = service.getCharacteristic(HEART_RATE_MEASUREMENT_CHAR_UUID);
|
||||
if (characteristic == null) {
|
||||
Log.e(TAG, "Could not get BluetoothCharacteristic for " + gatt.getDevice().getAddress());
|
||||
return;
|
||||
}
|
||||
gatt.setCharacteristicNotification(characteristic, true);
|
||||
|
||||
BluetoothGattDescriptor descriptor = characteristic.getDescriptor(CLIENT_CHARACTERISTIC_CONFIG_UUID);
|
||||
@@ -131,8 +139,9 @@ public class BluetoothConnectionManager {
|
||||
|
||||
Log.d(TAG, "Connecting to: " + bluetoothDevice);
|
||||
|
||||
setState(SensorState.CONNECTING);
|
||||
bluetoothGatt = bluetoothDevice.connectGatt(this.context, true, this.connectCallback);
|
||||
|
||||
setState(SensorState.CONNECTING);
|
||||
}
|
||||
|
||||
public synchronized void disconnect() {
|
||||
|
||||
+6
-44
@@ -26,12 +26,10 @@ import android.os.Message;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import de.dennisguse.opentracks.R;
|
||||
import de.dennisguse.opentracks.content.sensor.SensorDataSet;
|
||||
import de.dennisguse.opentracks.util.BluetoothUtils;
|
||||
import de.dennisguse.opentracks.util.PreferencesUtils;
|
||||
import de.dennisguse.opentracks.util.UnitConversions;
|
||||
|
||||
/**
|
||||
* Bluetooth LE sensor manager.
|
||||
@@ -45,7 +43,7 @@ public class BluetoothRemoteSensorManager {
|
||||
|
||||
private static final String TAG = BluetoothConnectionManager.class.getSimpleName();
|
||||
|
||||
private static final BluetoothAdapter bluetoothAdapter = getDefaultBluetoothAdapter();
|
||||
private static final BluetoothAdapter bluetoothAdapter = BluetoothUtils.getDefaultBluetoothAdapter(TAG);
|
||||
|
||||
private final Context context;
|
||||
|
||||
@@ -87,8 +85,8 @@ public class BluetoothRemoteSensorManager {
|
||||
private final SharedPreferences.OnSharedPreferenceChangeListener sharedPreferenceChangeListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences preferences, String key) {
|
||||
if (bluetoothConnectionManager != null && PreferencesUtils.isKey(context, R.string.settings_sensor_bluetooth_sensor_key, key)) {
|
||||
String address = PreferencesUtils.getString(context, R.string.settings_sensor_bluetooth_sensor_key, PreferencesUtils.BLUETOOTH_SENSOR_DEFAULT);
|
||||
if (bluetoothConnectionManager != null && PreferencesUtils.isKey(context, R.string.settings_sensor_bluetooth_heart_rate_key, key)) {
|
||||
String address = PreferencesUtils.getBluetoothHeartRateSensorAddress(context);
|
||||
if (address.equals(PreferencesUtils.BLUETOOTH_SENSOR_DEFAULT)) {
|
||||
stop();
|
||||
return;
|
||||
@@ -114,43 +112,6 @@ public class BluetoothRemoteSensorManager {
|
||||
sharedPreferences = PreferencesUtils.getSharedPreferences(context);
|
||||
}
|
||||
|
||||
private static BluetoothAdapter getDefaultBluetoothAdapter() {
|
||||
// If from the main application thread, return directly
|
||||
if (Thread.currentThread().equals(Looper.getMainLooper().getThread())) {
|
||||
return BluetoothAdapter.getDefaultAdapter();
|
||||
}
|
||||
|
||||
// Get the default adapter from the main application thread
|
||||
final ArrayList<BluetoothAdapter> adapters = new ArrayList<>(1);
|
||||
final Object mutex = new Object();
|
||||
|
||||
Handler handler = new Handler(Looper.getMainLooper());
|
||||
handler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
adapters.add(BluetoothAdapter.getDefaultAdapter());
|
||||
synchronized (mutex) {
|
||||
mutex.notify();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
while (adapters.isEmpty()) {
|
||||
synchronized (mutex) {
|
||||
try {
|
||||
mutex.wait(UnitConversions.ONE_SECOND);
|
||||
} catch (InterruptedException e) {
|
||||
Log.e(TAG, "Interrupted while waiting for default bluetooth adapter", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (adapters.get(0) == null) {
|
||||
Log.w(TAG, "No bluetooth adapter found.");
|
||||
}
|
||||
return adapters.get(0);
|
||||
}
|
||||
|
||||
public void start() {
|
||||
sharedPreferences.registerOnSharedPreferenceChangeListener(sharedPreferenceChangeListener);
|
||||
startCurrentSensor();
|
||||
@@ -184,7 +145,8 @@ public class BluetoothRemoteSensorManager {
|
||||
return;
|
||||
}
|
||||
|
||||
String address = PreferencesUtils.getString(context, R.string.settings_sensor_bluetooth_sensor_key, PreferencesUtils.BLUETOOTH_SENSOR_DEFAULT);
|
||||
// String address = PreferencesUtils.getString(context, R.string.settings_sensor_bluetooth_heart_rate_key, PreferencesUtils.BLUETOOTH_SENSOR_DEFAULT);
|
||||
String address = PreferencesUtils.getBluetoothHeartRateSensorAddress(context);
|
||||
if (PreferencesUtils.BLUETOOTH_SENSOR_DEFAULT.equals(address)) {
|
||||
Log.w(TAG, "No bluetooth address.");
|
||||
return;
|
||||
|
||||
@@ -34,6 +34,7 @@ import de.dennisguse.opentracks.services.TrackRecordingService;
|
||||
import de.dennisguse.opentracks.stats.TripStatistics;
|
||||
import de.dennisguse.opentracks.util.PreferencesUtils;
|
||||
import de.dennisguse.opentracks.util.StringUtils;
|
||||
import de.dennisguse.opentracks.util.TTSUtils;
|
||||
import de.dennisguse.opentracks.util.UnitConversions;
|
||||
|
||||
/**
|
||||
@@ -193,7 +194,7 @@ public class AnnouncementPeriodicTask implements PeriodicTask {
|
||||
* @param announcement the announcement
|
||||
*/
|
||||
private void speakAnnouncement(String announcement) {
|
||||
int result = audioManager.requestAudioFocus(null, TextToSpeech.Engine.DEFAULT_STREAM, AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK);
|
||||
int result = audioManager.requestAudioFocus(null, TTSUtils.getTTSStream(), AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_MAY_DUCK);
|
||||
if (result == AudioManager.AUDIOFOCUS_REQUEST_FAILED) {
|
||||
Log.w(TAG, "Failed to request audio focus.");
|
||||
}
|
||||
|
||||
@@ -17,9 +17,9 @@ package de.dennisguse.opentracks.services.tasks;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import de.dennisguse.opentracks.R;
|
||||
import de.dennisguse.opentracks.services.TrackRecordingService;
|
||||
import de.dennisguse.opentracks.stats.TripStatistics;
|
||||
import de.dennisguse.opentracks.util.PreferencesUtils;
|
||||
import de.dennisguse.opentracks.util.UnitConversions;
|
||||
|
||||
/**
|
||||
@@ -35,13 +35,14 @@ public class PeriodicTaskExecutor {
|
||||
private final TrackRecordingService trackRecordingService;
|
||||
private final PeriodicTaskFactory periodicTaskFactory;
|
||||
|
||||
private final int TASK_FREQUENCY_OFF;
|
||||
/**
|
||||
* The task frequency.
|
||||
* A positive value is a time frequency (minutes).
|
||||
* A negative value is a distance frequency (km or mi).
|
||||
* A zero value is to turn off periodic task.
|
||||
*/
|
||||
private int taskFrequency = PreferencesUtils.FREQUENCY_OFF;
|
||||
private int taskFrequency;
|
||||
|
||||
private PeriodicTask periodicTask;
|
||||
|
||||
@@ -56,6 +57,9 @@ public class PeriodicTaskExecutor {
|
||||
public PeriodicTaskExecutor(TrackRecordingService trackRecordingService, PeriodicTaskFactory periodicTaskFactory) {
|
||||
this.trackRecordingService = trackRecordingService;
|
||||
this.periodicTaskFactory = periodicTaskFactory;
|
||||
|
||||
TASK_FREQUENCY_OFF = Integer.parseInt(trackRecordingService.getBaseContext().getResources().getString(R.string.frequency_off));
|
||||
taskFrequency = TASK_FREQUENCY_OFF;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -71,7 +75,7 @@ public class PeriodicTaskExecutor {
|
||||
timerTaskExecutor.shutdown();
|
||||
timerTaskExecutor = null;
|
||||
}
|
||||
if (taskFrequency == PreferencesUtils.FREQUENCY_OFF) {
|
||||
if (taskFrequency == TASK_FREQUENCY_OFF) {
|
||||
Log.d(TAG, "Task frequency is off.");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -43,14 +43,6 @@ import de.dennisguse.opentracks.util.TrackIconUtils;
|
||||
*/
|
||||
public class ActivityTypePreference extends DialogPreference {
|
||||
|
||||
private SummaryProvider<DialogPreference> summaryProvider = new SummaryProvider<DialogPreference>() {
|
||||
@Override
|
||||
public CharSequence provideSummary(DialogPreference preference) {
|
||||
String defaultActivity = PreferencesUtils.getDefaultActivity(ActivityTypePreference.this.getContext());
|
||||
return defaultActivity != null && !defaultActivity.equals(PreferencesUtils.DEFAULT_ACTIVITY_DEFAULT) ? defaultActivity : getContext().getString(R.string.value_unknown);
|
||||
}
|
||||
};
|
||||
|
||||
public ActivityTypePreference(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
setDialogLayoutResource(R.layout.preference_activity_type);
|
||||
@@ -58,6 +50,13 @@ public class ActivityTypePreference extends DialogPreference {
|
||||
setNegativeButtonText(android.R.string.cancel);
|
||||
setDialogIcon(null);
|
||||
setPersistent(true);
|
||||
|
||||
SummaryProvider<DialogPreference> summaryProvider = new SummaryProvider<DialogPreference>() {
|
||||
@Override
|
||||
public CharSequence provideSummary(DialogPreference preference) {
|
||||
return PreferencesUtils.getDefaultActivity(ActivityTypePreference.this.getContext());
|
||||
}
|
||||
};
|
||||
setSummaryProvider(summaryProvider);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,112 @@
|
||||
package de.dennisguse.opentracks.settings;
|
||||
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.BaseAdapter;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class BluetoothLeAdapter extends BaseAdapter {
|
||||
|
||||
/**
|
||||
* Contains a unique list (by address) of devices.
|
||||
*/
|
||||
private final List<Device> devices = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return devices.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getItem(int position) {
|
||||
return devices.get(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return devices.get(position).hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
View currentView = convertView;
|
||||
if (convertView == null) {
|
||||
LayoutInflater inflater = LayoutInflater.from(parent.getContext());
|
||||
//TODO Check if there is a better way to achieve identical look and feel to ListPreference.
|
||||
//Use material design single choice; for old style use: android.R.layout.select_dialog_singlechoice
|
||||
currentView = inflater.inflate(androidx.appcompat.R.layout.select_dialog_singlechoice_material, null);
|
||||
}
|
||||
|
||||
Device device = devices.get(position);
|
||||
TextView textView = currentView.findViewById(android.R.id.text1);
|
||||
textView.setText(device.getName());
|
||||
|
||||
return currentView;
|
||||
}
|
||||
|
||||
public void add(String name, String address) {
|
||||
Device device = new Device(name, address);
|
||||
if (!devices.contains(device)) {
|
||||
devices.add(new Device(name, address));
|
||||
} else {
|
||||
for (Device currentDevice : devices) {
|
||||
if (currentDevice.getAddress().equals(address)) {
|
||||
currentDevice.setName(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public void add(BluetoothDevice bluetoothDevice) {
|
||||
add(bluetoothDevice.getName(), bluetoothDevice.getAddress());
|
||||
}
|
||||
|
||||
public Device get(int index) {
|
||||
return devices.get(index);
|
||||
}
|
||||
|
||||
public class Device {
|
||||
private String name;
|
||||
private String address;
|
||||
|
||||
public Device(String name, String address) {
|
||||
this.name = name;
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getAddress() {
|
||||
return address;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the address is identical.
|
||||
*/
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof Device)) return false;
|
||||
Device device = (Device) o;
|
||||
return address.equals(device.address);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(name, address);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,199 @@
|
||||
package de.dennisguse.opentracks.settings;
|
||||
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.bluetooth.le.BluetoothLeScanner;
|
||||
import android.bluetooth.le.ScanCallback;
|
||||
import android.bluetooth.le.ScanFilter;
|
||||
import android.bluetooth.le.ScanResult;
|
||||
import android.bluetooth.le.ScanSettings;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.Bundle;
|
||||
import android.os.ParcelUuid;
|
||||
import android.text.TextUtils;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.preference.DialogPreference;
|
||||
import androidx.preference.PreferenceDialogFragmentCompat;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import de.dennisguse.opentracks.R;
|
||||
import de.dennisguse.opentracks.util.BluetoothUtils;
|
||||
|
||||
/**
|
||||
* Preference to select a discoverable Bluetooth LE device.
|
||||
* Based upon ListPreference.
|
||||
*/
|
||||
public class BluetoothLePreference extends DialogPreference {
|
||||
|
||||
private final static String TAG = BluetoothLePreference.class.getSimpleName();
|
||||
|
||||
public BluetoothLePreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||
super(context, attrs, defStyleAttr, defStyleRes);
|
||||
}
|
||||
|
||||
public BluetoothLePreference(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
}
|
||||
|
||||
public BluetoothLePreference(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
public BluetoothLePreference(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
private String value;
|
||||
private boolean valueSet = false;
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
final boolean changed = !TextUtils.equals(this.value, value);
|
||||
if (changed || !valueSet) {
|
||||
this.value = value;
|
||||
valueSet = true;
|
||||
persistString(value);
|
||||
if (changed) {
|
||||
notifyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSetInitialValue(Object defaultValue) {
|
||||
setValue(getPersistedString((String) defaultValue));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CharSequence getSummary() {
|
||||
return getValue();
|
||||
}
|
||||
|
||||
public static class BluetoothLePreferenceDialog extends PreferenceDialogFragmentCompat {
|
||||
|
||||
private int selectedEntryIndex;
|
||||
private BluetoothLeAdapter listAdapter = new BluetoothLeAdapter();
|
||||
|
||||
private BluetoothLeScanner scanner = null;
|
||||
private ScanCallback scanCallback = new ScanCallback() {
|
||||
@Override
|
||||
public void onScanResult(int callbackType, ScanResult result) {
|
||||
super.onScanResult(callbackType, result);
|
||||
Log.d(TAG, "Found device " + result.getDevice().getName() + " " + result);
|
||||
|
||||
listAdapter.add(result.getDevice());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBatchScanResults(List<ScanResult> results) {
|
||||
for (ScanResult scanResult : results) {
|
||||
listAdapter.add(scanResult.getDevice());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onScanFailed(int errorCode) {
|
||||
super.onScanFailed(errorCode);
|
||||
Log.e(TAG, "Bluetooth scan failed with errorCode " + errorCode);
|
||||
Toast.makeText(getContext(), R.string.sensor_could_not_scan, Toast.LENGTH_LONG).show();
|
||||
dismiss();
|
||||
}
|
||||
};
|
||||
|
||||
static BluetoothLePreferenceDialog newInstance(String key) {
|
||||
final BluetoothLePreferenceDialog fragment = new BluetoothLePreferenceDialog();
|
||||
final Bundle b = new Bundle(1);
|
||||
b.putString(ARG_KEY, key);
|
||||
fragment.setArguments(b);
|
||||
return fragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
BluetoothAdapter bluetoothAdapter = BluetoothUtils.getDefaultBluetoothAdapter(TAG);
|
||||
if (bluetoothAdapter == null || !bluetoothAdapter.isEnabled()) {
|
||||
Log.w(TAG, "Bluetooth adapter is present or not enabled.");
|
||||
Toast.makeText(getContext(), R.string.bluetooth_disabled, Toast.LENGTH_SHORT).show();
|
||||
dismiss();
|
||||
return;
|
||||
}
|
||||
|
||||
if (bluetoothAdapter.isDiscovering()) {
|
||||
Log.i(TAG, "Cancelling ongoing bluetooth discovery.");
|
||||
bluetoothAdapter.cancelDiscovery();
|
||||
}
|
||||
|
||||
scanner = bluetoothAdapter.getBluetoothLeScanner();
|
||||
if (scanner == null) {
|
||||
Log.e(TAG, "BluetoothLeScanner is null.");
|
||||
dismiss();
|
||||
return;
|
||||
}
|
||||
|
||||
String deviceNone = getContext().getString(R.string.sensor_type_value_none);
|
||||
listAdapter.add(getContext().getString(R.string.value_none), deviceNone);
|
||||
selectedEntryIndex = 0;
|
||||
|
||||
BluetoothLePreference preference = (BluetoothLePreference) getPreference();
|
||||
String deviceSelected = preference.getValue();
|
||||
if (!deviceNone.equals(deviceSelected)) {
|
||||
listAdapter.add(preference.getValue(), preference.getValue());
|
||||
selectedEntryIndex = 1;
|
||||
}
|
||||
|
||||
ScanFilter.Builder scanFilterBuilder = new ScanFilter.Builder().setServiceUuid(new ParcelUuid(BluetoothUtils.HEART_RATE_SERVICE_UUID));
|
||||
List<ScanFilter> scanFilter = new ArrayList<>();
|
||||
scanFilter.add(scanFilterBuilder.build());
|
||||
|
||||
ScanSettings.Builder scanSettingsBuilder = new ScanSettings.Builder();
|
||||
scanSettingsBuilder.setScanMode(ScanSettings.SCAN_MODE_LOW_LATENCY);
|
||||
|
||||
scanner.startScan(scanFilter, scanSettingsBuilder.build(), scanCallback);
|
||||
}
|
||||
|
||||
//Behave like ListPreferenceDialogFragmentCompat, but uses a custom listAdapter.
|
||||
@Override
|
||||
protected void onPrepareDialogBuilder(AlertDialog.Builder builder) {
|
||||
super.onPrepareDialogBuilder(builder);
|
||||
|
||||
builder.setSingleChoiceItems(listAdapter, selectedEntryIndex,
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
selectedEntryIndex = which;
|
||||
|
||||
BluetoothLePreferenceDialog.this.onClick(dialog, DialogInterface.BUTTON_POSITIVE);
|
||||
dialog.dismiss();
|
||||
}
|
||||
});
|
||||
builder.setIcon(android.R.drawable.stat_sys_data_bluetooth);
|
||||
builder.setPositiveButton(null, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDialogClosed(boolean positiveResult) {
|
||||
if (scanner != null) {
|
||||
scanner.stopScan(scanCallback);
|
||||
}
|
||||
|
||||
if (positiveResult && selectedEntryIndex >= 0) {
|
||||
String value = listAdapter.get(selectedEntryIndex).getAddress();
|
||||
BluetoothLePreference preference = (BluetoothLePreference) getPreference();
|
||||
if (preference.callChangeListener(value)) {
|
||||
preference.setValue(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,210 +1,163 @@
|
||||
package de.dennisguse.opentracks.settings;
|
||||
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.preference.ListPreference;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import de.dennisguse.opentracks.R;
|
||||
import de.dennisguse.opentracks.util.BluetoothUtils;
|
||||
import de.dennisguse.opentracks.util.PreferencesUtils;
|
||||
import de.dennisguse.opentracks.util.UnitConversions;
|
||||
|
||||
final class PreferenceHelper {
|
||||
|
||||
/**
|
||||
* Sets the min recording interval options.
|
||||
*
|
||||
* @param options the options
|
||||
* @param values the values
|
||||
*/
|
||||
static void setMinRecordingIntervalOptions(Context context, String[] options, String[] values) {
|
||||
for (int i = 0; i < values.length; i++) {
|
||||
int value = Integer.parseInt(values[i]);
|
||||
switch (value) {
|
||||
case PreferencesUtils.MIN_RECORDING_INTERVAL_ADAPT_BATTERY_LIFE:
|
||||
options[i] = context.getString(R.string.value_adapt_battery_life);
|
||||
break;
|
||||
case PreferencesUtils.MIN_RECORDING_INTERVAL_ADAPT_ACCURACY:
|
||||
options[i] = context.getString(R.string.value_adapt_accuracy);
|
||||
break;
|
||||
case PreferencesUtils.MIN_RECORDING_INTERVAL_DEFAULT:
|
||||
options[i] = context.getString(R.string.value_smallest_recommended);
|
||||
break;
|
||||
default:
|
||||
options[i] = value < 60 ? context.getString(R.string.value_integer_second, value) : context.getString(R.string.value_integer_minute, value / 60);
|
||||
static String[] getMinRecordingIntervalEntries(Context context) {
|
||||
String[] entryValues = context.getResources().getStringArray(R.array.min_recording_interval_values);
|
||||
String[] entries = new String[entryValues.length];
|
||||
for (int i = 0; i < entryValues.length; i++) {
|
||||
int value = Integer.parseInt(entryValues[i]);
|
||||
|
||||
if (value == PreferencesUtils.getMinRecordingIntervalAdaptAccuracy(context)) {
|
||||
entries[i] = context.getString(R.string.value_adapt_accuracy);
|
||||
} else if (value == PreferencesUtils.getMinRecordingIntervalAdaptBatteryLife(context)) {
|
||||
entries[i] = context.getString(R.string.value_adapt_battery_life);
|
||||
} else if (value == PreferencesUtils.getMinRecordingIntervalDefault(context)) {
|
||||
entries[i] = context.getString(R.string.value_smallest_recommended);
|
||||
} else {
|
||||
entries[i] = value < 60 ? context.getString(R.string.value_integer_second, value) : context.getString(R.string.value_integer_minute, value / 60);
|
||||
}
|
||||
}
|
||||
|
||||
return entries;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the recording distance interval options.
|
||||
*
|
||||
* @param options the options
|
||||
* @param values the values
|
||||
* @param metricUnits true for metric units
|
||||
*/
|
||||
static void setRecordingDistanceIntervalOptions(Context context, String[] options, String[] values, boolean metricUnits) {
|
||||
for (int i = 0; i < values.length; i++) {
|
||||
int value = Integer.parseInt(values[i]);
|
||||
static String[] getRecordingDistanceIntervalEntries(Context context, boolean metricUnits) {
|
||||
String[] entryValues = context.getResources().getStringArray(R.array.recording_distance_interval_values);
|
||||
String[] entries = new String[entryValues.length];
|
||||
|
||||
final int recordingDistanceIntervalDefault = PreferencesUtils.getRecordingDistanceIntervalDefault(context);
|
||||
|
||||
for (int i = 0; i < entryValues.length; i++) {
|
||||
int value = Integer.parseInt(entryValues[i]);
|
||||
String displayValue;
|
||||
if (metricUnits) {
|
||||
displayValue = context.getString(R.string.value_integer_meter, value);
|
||||
if (value == PreferencesUtils.RECORDING_DISTANCE_INTERVAL_DEFAULT) {
|
||||
options[i] = context.getString(R.string.value_integer_meter_recommended, value);
|
||||
if (value == recordingDistanceIntervalDefault) {
|
||||
entries[i] = context.getString(R.string.value_integer_meter_recommended, value);
|
||||
} else {
|
||||
options[i] = displayValue;
|
||||
entries[i] = displayValue;
|
||||
}
|
||||
} else {
|
||||
int feet = (int) (value * UnitConversions.M_TO_FT);
|
||||
displayValue = context.getString(R.string.value_integer_feet, feet);
|
||||
if (value == PreferencesUtils.RECORDING_DISTANCE_INTERVAL_DEFAULT) {
|
||||
options[i] = context.getString(R.string.value_integer_feet_recommended, feet);
|
||||
if (value == recordingDistanceIntervalDefault) {
|
||||
entries[i] = context.getString(R.string.value_integer_feet_recommended, feet);
|
||||
} else {
|
||||
options[i] = displayValue;
|
||||
entries[i] = displayValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return entries;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the max recording distance options.
|
||||
*
|
||||
* @param options the options
|
||||
* @param values the values
|
||||
* @param metricUnits true for metric units
|
||||
*/
|
||||
static void setMaxRecordingDistanceOptions(Context context, String[] options, String[] values, boolean metricUnits) {
|
||||
for (int i = 0; i < values.length; i++) {
|
||||
int value = Integer.parseInt(values[i]);
|
||||
static String[] getMaxRecordingDistanceEntries(Context context, boolean metricUnits) {
|
||||
String[] entryValues = context.getResources().getStringArray(R.array.max_recording_distance_values);
|
||||
String[] entries = new String[entryValues.length];
|
||||
|
||||
final int maxRecordingDistanceDefault = Integer.parseInt(context.getResources().getString(R.string.max_recording_distance_default));
|
||||
|
||||
for (int i = 0; i < entryValues.length; i++) {
|
||||
int value = Integer.parseInt(entryValues[i]);
|
||||
String displayValue;
|
||||
if (metricUnits) {
|
||||
displayValue = context.getString(R.string.value_integer_meter, value);
|
||||
if (value == PreferencesUtils.MAX_RECORDING_DISTANCE_DEFAULT) {
|
||||
options[i] = context.getString(R.string.value_integer_meter_recommended, value);
|
||||
if (value == maxRecordingDistanceDefault) {
|
||||
entries[i] = context.getString(R.string.value_integer_meter_recommended, value);
|
||||
} else {
|
||||
options[i] = displayValue;
|
||||
entries[i] = displayValue;
|
||||
}
|
||||
} else {
|
||||
int feet = (int) (value * UnitConversions.M_TO_FT);
|
||||
if (feet < 2000) {
|
||||
displayValue = context.getString(R.string.value_integer_feet, feet);
|
||||
if (value == PreferencesUtils.MAX_RECORDING_DISTANCE_DEFAULT) {
|
||||
options[i] = context.getString(R.string.value_integer_feet_recommended, feet);
|
||||
if (value == maxRecordingDistanceDefault) {
|
||||
entries[i] = context.getString(R.string.value_integer_feet_recommended, feet);
|
||||
} else {
|
||||
options[i] = displayValue;
|
||||
entries[i] = displayValue;
|
||||
}
|
||||
} else {
|
||||
double mile = feet * UnitConversions.FT_TO_MI;
|
||||
displayValue = context.getString(R.string.value_float_mile, mile);
|
||||
options[i] = displayValue;
|
||||
entries[i] = displayValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return entries;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the recording gps accuracy options.
|
||||
*
|
||||
* @param options the options
|
||||
* @param values the values
|
||||
* @param metricUnits true for metric units
|
||||
*/
|
||||
static void setRecordingGpsAccuracyOptions(Context context, String[] options, String[] values, boolean metricUnits) {
|
||||
for (int i = 0; i < values.length; i++) {
|
||||
int value = Integer.parseInt(values[i]);
|
||||
static String[] getRecordingGpsAccuracyEntries(Context context, boolean metricUnits) {
|
||||
String[] entryValues = context.getResources().getStringArray(R.array.recording_gps_accuracy_values);
|
||||
String[] entries = new String[entryValues.length];
|
||||
|
||||
final int recordingGPSAccuracyDefault = Integer.parseInt(context.getResources().getString(R.string.recording_gps_accuracy_default));
|
||||
final int recordingGPSAccuracyExcellent = Integer.parseInt(context.getResources().getString(R.string.recording_gps_accuracy_excellent));
|
||||
final int recordingGPSAccuracyPoor = Integer.parseInt(context.getResources().getString(R.string.recording_gps_accuracy_poor));
|
||||
|
||||
for (int i = 0; i < entryValues.length; i++) {
|
||||
int value = Integer.parseInt(entryValues[i]);
|
||||
String displayValue;
|
||||
if (metricUnits) {
|
||||
displayValue = context.getString(R.string.value_integer_meter, value);
|
||||
switch (value) {
|
||||
case PreferencesUtils.RECORDING_GPS_ACCURACY_DEFAULT:
|
||||
options[i] = context.getString(R.string.value_integer_meter_recommended, value);
|
||||
break;
|
||||
case PreferencesUtils.RECORDING_GPS_ACCURACY_EXCELLENT:
|
||||
options[i] = context.getString(R.string.value_integer_meter_excellent_gps, value);
|
||||
break;
|
||||
case PreferencesUtils.RECORDING_GPS_ACCURACY_POOR:
|
||||
options[i] = context.getString(R.string.value_integer_meter_poor_gps, value);
|
||||
break;
|
||||
default:
|
||||
options[i] = displayValue;
|
||||
if (value == recordingGPSAccuracyDefault) {
|
||||
entries[i] = context.getString(R.string.value_integer_meter_recommended, value);
|
||||
} else if (value == recordingGPSAccuracyExcellent) {
|
||||
entries[i] = context.getString(R.string.value_integer_meter_excellent_gps, value);
|
||||
} else if (value == recordingGPSAccuracyPoor) {
|
||||
entries[i] = context.getString(R.string.value_integer_meter_poor_gps, value);
|
||||
} else {
|
||||
entries[i] = displayValue;
|
||||
}
|
||||
} else {
|
||||
int feet = (int) (value * UnitConversions.M_TO_FT);
|
||||
if (feet < 2000) {
|
||||
displayValue = context.getString(R.string.value_integer_feet, feet);
|
||||
switch (value) {
|
||||
case PreferencesUtils.RECORDING_GPS_ACCURACY_DEFAULT:
|
||||
options[i] = context.getString(R.string.value_integer_feet_recommended, feet);
|
||||
break;
|
||||
case PreferencesUtils.RECORDING_GPS_ACCURACY_EXCELLENT:
|
||||
options[i] = context.getString(R.string.value_integer_feet_excellent_gps, feet);
|
||||
break;
|
||||
default:
|
||||
options[i] = displayValue;
|
||||
|
||||
if (value == recordingGPSAccuracyDefault) {
|
||||
entries[i] = context.getString(R.string.value_integer_feet_recommended, feet);
|
||||
} else if (value == recordingGPSAccuracyExcellent) {
|
||||
entries[i] = context.getString(R.string.value_integer_feet_excellent_gps, feet);
|
||||
} else {
|
||||
entries[i] = displayValue;
|
||||
}
|
||||
} else {
|
||||
double mile = feet * UnitConversions.FT_TO_MI;
|
||||
displayValue = context.getString(R.string.value_float_mile, mile);
|
||||
if (value == PreferencesUtils.RECORDING_GPS_ACCURACY_POOR) {
|
||||
options[i] = context.getString(R.string.value_float_mile_poor_gps, mile);
|
||||
if (value == recordingGPSAccuracyPoor) {
|
||||
entries[i] = context.getString(R.string.value_float_mile_poor_gps, mile);
|
||||
} else {
|
||||
options[i] = displayValue;
|
||||
entries[i] = displayValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return entries;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the auto resume track timeout options.
|
||||
*
|
||||
* @param options the options
|
||||
* @param values the values
|
||||
*/
|
||||
static void setAutoResumeTrackTimeoutOptions(Context context, String[] options, String[] values) {
|
||||
for (int i = 0; i < values.length; i++) {
|
||||
int value = Integer.parseInt(values[i]);
|
||||
static String[] getAutoResumeTrackTimeoutEntries(Context context) {
|
||||
String[] entryValues = context.getResources().getStringArray(R.array.auto_resume_track_timeout_values);
|
||||
String[] entries = new String[entryValues.length];
|
||||
|
||||
for (int i = 0; i < entryValues.length; i++) {
|
||||
int value = Integer.parseInt(entryValues[i]);
|
||||
if (value == Integer.parseInt(context.getResources().getString(R.string.auto_resume_track_timeout_never))) {
|
||||
options[i] = context.getString(R.string.value_never);
|
||||
entries[i] = context.getString(R.string.value_never);
|
||||
} else if (value == Integer.parseInt(context.getResources().getString(R.string.auto_resume_track_timeout_always))) {
|
||||
options[i] = context.getString(R.string.value_always);
|
||||
entries[i] = context.getString(R.string.value_always);
|
||||
} else {
|
||||
options[i] = context.getString(R.string.value_integer_minute, value);
|
||||
entries[i] = context.getString(R.string.value_integer_minute, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Configures the bluetooth sensor.
|
||||
*/
|
||||
static void configureBluetoothSensorList(ListPreference preference) {
|
||||
Context context = preference.getContext();
|
||||
|
||||
String value = PreferencesUtils.getString(context, R.string.settings_sensor_bluetooth_sensor_key, PreferencesUtils.BLUETOOTH_SENSOR_DEFAULT);
|
||||
List<String> devicesNameList = new ArrayList<>();
|
||||
List<String> devicesAddressList = new ArrayList<>();
|
||||
BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
|
||||
if (bluetoothAdapter != null) {
|
||||
BluetoothUtils.populateDeviceLists(bluetoothAdapter, devicesNameList, devicesAddressList);
|
||||
}
|
||||
|
||||
// Was the previously configured device unpaired? Then forget it.
|
||||
if (!devicesAddressList.contains(value)) {
|
||||
value = PreferencesUtils.BLUETOOTH_SENSOR_DEFAULT;
|
||||
PreferencesUtils.setString(context, R.string.settings_sensor_bluetooth_sensor_key, value);
|
||||
}
|
||||
|
||||
devicesNameList.add(0, context.getString(R.string.value_none));
|
||||
devicesAddressList.add(0, PreferencesUtils.BLUETOOTH_SENSOR_DEFAULT);
|
||||
|
||||
String[] values = devicesAddressList.toArray(new String[0]);
|
||||
preference.setEntryValues(values);
|
||||
|
||||
String[] options = devicesNameList.toArray(new String[0]);
|
||||
preference.setEntries(options);
|
||||
return entries;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,12 +13,15 @@ import androidx.preference.PreferenceFragmentCompat;
|
||||
|
||||
import de.dennisguse.opentracks.R;
|
||||
import de.dennisguse.opentracks.fragments.ChooseActivityTypeDialogFragment;
|
||||
import de.dennisguse.opentracks.util.BluetoothUtils;
|
||||
import de.dennisguse.opentracks.util.HackUtils;
|
||||
import de.dennisguse.opentracks.util.PreferencesUtils;
|
||||
import de.dennisguse.opentracks.util.StringUtils;
|
||||
|
||||
public class SettingsActivity extends AppCompatActivity implements ChooseActivityTypeDialogFragment.ChooseActivityTypeCaller, ResetDialogPreference.ResetCallback {
|
||||
|
||||
private static final String TAG = SettingsActivity.class.getSimpleName();
|
||||
|
||||
private PrefsFragment prefsFragment;
|
||||
|
||||
@Override
|
||||
@@ -54,13 +57,14 @@ public class SettingsActivity extends AppCompatActivity implements ChooseActivit
|
||||
private final SharedPreferences.OnSharedPreferenceChangeListener sharedPreferenceChangeListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences preferences, String key) {
|
||||
getActivity().runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
updateUI();
|
||||
}
|
||||
});
|
||||
|
||||
if (PreferencesUtils.isKey(getActivity(), R.string.recording_track_id_key, key)) {
|
||||
getActivity().runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
updateReset();
|
||||
}
|
||||
});
|
||||
}
|
||||
if (PreferencesUtils.isKey(getActivity(), R.string.stats_units_key, key)) {
|
||||
getActivity().runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
@@ -69,6 +73,14 @@ public class SettingsActivity extends AppCompatActivity implements ChooseActivit
|
||||
}
|
||||
});
|
||||
}
|
||||
if (PreferencesUtils.isKey(getActivity(), R.string.stats_rate_key, key)) {
|
||||
getActivity().runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
updateSpeed();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -86,14 +98,16 @@ public class SettingsActivity extends AppCompatActivity implements ChooseActivit
|
||||
|
||||
setPreferencesFromResource(R.xml.settings, rootKey);
|
||||
}
|
||||
updateUnits();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
PreferencesUtils.getSharedPreferences(getActivity()).registerOnSharedPreferenceChangeListener(sharedPreferenceChangeListener);
|
||||
updateUI();
|
||||
updateSpeed();
|
||||
updateUnits();
|
||||
updateReset();
|
||||
updateBluetooth();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -102,40 +116,6 @@ public class SettingsActivity extends AppCompatActivity implements ChooseActivit
|
||||
PreferencesUtils.getSharedPreferences(getActivity()).unregisterOnSharedPreferenceChangeListener(sharedPreferenceChangeListener);
|
||||
}
|
||||
|
||||
private void configFrequencyPreference(int key, boolean metricUnits) {
|
||||
ListPreference preference = findPreference(getString(key));
|
||||
|
||||
String[] options = StringUtils.getFrequencyOptions(getActivity(), metricUnits);
|
||||
preference.setEntries(options);
|
||||
}
|
||||
|
||||
private void configListPreference(int key, int valueArray, boolean metricUnits) {
|
||||
String[] values = getResources().getStringArray(valueArray);
|
||||
final String[] options = new String[values.length];
|
||||
switch (key) {
|
||||
case R.string.min_recording_interval_key:
|
||||
PreferenceHelper.setMinRecordingIntervalOptions(getActivity(), options, values);
|
||||
break;
|
||||
case R.string.recording_distance_interval_key:
|
||||
PreferenceHelper.setRecordingDistanceIntervalOptions(getActivity(), options, values, metricUnits);
|
||||
break;
|
||||
case R.string.max_recording_distance_key:
|
||||
PreferenceHelper.setMaxRecordingDistanceOptions(getActivity(), options, values, metricUnits);
|
||||
break;
|
||||
case R.string.recording_gps_accuracy_key:
|
||||
PreferenceHelper.setRecordingGpsAccuracyOptions(getActivity(), options, values, metricUnits);
|
||||
break;
|
||||
case R.string.auto_resume_track_timeout_key:
|
||||
PreferenceHelper.setAutoResumeTrackTimeoutOptions(getActivity(), options, values);
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
final ListPreference listPreference = findPreference(getString(key));
|
||||
listPreference.setEntries(options);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisplayPreferenceDialog(Preference preference) {
|
||||
DialogFragment dialogFragment = null;
|
||||
@@ -144,6 +124,8 @@ public class SettingsActivity extends AppCompatActivity implements ChooseActivit
|
||||
} else if (preference instanceof ActivityTypePreference) {
|
||||
activityPreferenceDialog = ActivityTypePreference.ActivityPreferenceDialog.newInstance(preference.getKey());
|
||||
dialogFragment = activityPreferenceDialog;
|
||||
} else if (preference instanceof BluetoothLePreference) {
|
||||
dialogFragment = BluetoothLePreference.BluetoothLePreferenceDialog.newInstance(preference.getKey());
|
||||
}
|
||||
|
||||
if (dialogFragment != null) {
|
||||
@@ -161,35 +143,51 @@ public class SettingsActivity extends AppCompatActivity implements ChooseActivit
|
||||
}
|
||||
}
|
||||
|
||||
private void updateUI() {
|
||||
private void updateReset() {
|
||||
final boolean isRecording = PreferencesUtils.isRecording(getActivity());
|
||||
Preference resetPreference = findPreference(getString(R.string.settings_reset_key));
|
||||
resetPreference.setSummary(isRecording ? getString(R.string.settings_not_while_recording) : "");
|
||||
resetPreference.setEnabled(!isRecording);
|
||||
}
|
||||
|
||||
private void updateSpeed() {
|
||||
Preference speedCheckBoxPreference = findPreference(getString(R.string.chart_show_speed_key));
|
||||
speedCheckBoxPreference.setTitle(PreferencesUtils.isReportSpeed(getActivity()) ? R.string.stats_speed : R.string.stats_pace);
|
||||
}
|
||||
|
||||
ListPreference bluetoothPreference = findPreference(getString(R.string.settings_sensor_bluetooth_sensor_key));
|
||||
PreferenceHelper.configureBluetoothSensorList(bluetoothPreference);
|
||||
private void updateBluetooth() {
|
||||
// Disable Bluetooth preference if device does not have Bluetooth
|
||||
BluetoothLePreference bluetoothPreference = findPreference(getString(R.string.settings_sensor_bluetooth_heart_rate_key));
|
||||
bluetoothPreference.setVisible(BluetoothUtils.hasBluetooth(TAG));
|
||||
}
|
||||
|
||||
private void updateUnits() {
|
||||
boolean metricUnits = PreferencesUtils.isMetricUnits(getActivity());
|
||||
|
||||
//TODO Refactor this!
|
||||
configFrequencyPreference(R.string.voice_frequency_key, metricUnits);
|
||||
configFrequencyPreference(R.string.split_frequency_key, metricUnits);
|
||||
configListPreference(R.string.min_recording_interval_key, R.array.min_recording_interval_values, metricUnits);
|
||||
configListPreference(R.string.recording_distance_interval_key, R.array.recording_distance_interval_values, metricUnits);
|
||||
configListPreference(R.string.max_recording_distance_key, R.array.max_recording_distance_values, metricUnits);
|
||||
configListPreference(R.string.recording_gps_accuracy_key, R.array.recording_gps_accuracy_values, metricUnits);
|
||||
configListPreference(R.string.auto_resume_track_timeout_key, R.array.auto_resume_track_timeout_values, metricUnits);
|
||||
configListPreference(R.string.auto_resume_track_timeout_key, R.array.auto_resume_track_timeout_values, metricUnits);
|
||||
ListPreference voiceFrequency = findPreference(getString(R.string.voice_frequency_key));
|
||||
voiceFrequency.setEntries(StringUtils.getFrequencyOptions(getActivity(), metricUnits));
|
||||
|
||||
final ListPreference statsRatePreferences = findPreference(getString(R.string.stats_rate_key));
|
||||
String[] options = getResources().getStringArray(metricUnits ? R.array.stats_rate_metric_options : R.array.stats_rate_imperial_options);
|
||||
statsRatePreferences.setEntries(options);
|
||||
ListPreference splitFrequency = findPreference(getString(R.string.split_frequency_key));
|
||||
splitFrequency.setEntries(StringUtils.getFrequencyOptions(getActivity(), metricUnits));
|
||||
|
||||
ListPreference minRecordingInterval = findPreference(getString(R.string.min_recording_interval_key));
|
||||
minRecordingInterval.setEntries(PreferenceHelper.getMinRecordingIntervalEntries(getActivity()));
|
||||
|
||||
ListPreference recordingDistanceInterval = findPreference(getString(R.string.recording_distance_interval_key));
|
||||
recordingDistanceInterval.setEntries(PreferenceHelper.getRecordingDistanceIntervalEntries(getActivity(), metricUnits));
|
||||
|
||||
ListPreference maxRecordingDistance = findPreference(getString(R.string.max_recording_distance_key));
|
||||
maxRecordingDistance.setEntries(PreferenceHelper.getMaxRecordingDistanceEntries(getActivity(), metricUnits));
|
||||
|
||||
ListPreference recordingGpsAccuracy = findPreference(getString(R.string.recording_gps_accuracy_key));
|
||||
recordingGpsAccuracy.setEntries(PreferenceHelper.getRecordingGpsAccuracyEntries(getActivity(), metricUnits));
|
||||
|
||||
ListPreference autoresumeTrack = findPreference(getString(R.string.auto_resume_track_timeout_key));
|
||||
autoresumeTrack.setEntries(PreferenceHelper.getAutoResumeTrackTimeoutEntries(getActivity()));
|
||||
|
||||
ListPreference statsRatePreferences = findPreference(getString(R.string.stats_rate_key));
|
||||
String[] entries = getResources().getStringArray(metricUnits ? R.array.stats_rate_metric_options : R.array.stats_rate_imperial_options);
|
||||
statsRatePreferences.setEntries(entries);
|
||||
|
||||
HackUtils.invalidatePreference(statsRatePreferences);
|
||||
}
|
||||
|
||||
@@ -16,12 +16,13 @@
|
||||
package de.dennisguse.opentracks.util;
|
||||
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.bluetooth.BluetoothClass;
|
||||
import android.bluetooth.BluetoothDevice;
|
||||
import android.bluetooth.BluetoothGattCharacteristic;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
import android.util.Log;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.ArrayList;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Utilities for dealing with bluetooth devices.
|
||||
@@ -30,29 +31,50 @@ import java.util.Set;
|
||||
*/
|
||||
public class BluetoothUtils {
|
||||
|
||||
public static final UUID HEART_RATE_SERVICE_UUID = new UUID(0x180D00001000L, 0x800000805f9b34fbL);
|
||||
|
||||
private BluetoothUtils() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Populates the device names and the device addresses with all the suitable
|
||||
* bluetooth devices.
|
||||
*
|
||||
* @param bluetoothAdapter the bluetooth adapter
|
||||
* @param deviceNames list of device names
|
||||
* @param deviceAddresses list of device addresses
|
||||
*/
|
||||
public static void populateDeviceLists(BluetoothAdapter bluetoothAdapter, List<String> deviceNames, List<String> deviceAddresses) {
|
||||
// Ensure the bluetooth adapter is not in discovery mode.
|
||||
bluetoothAdapter.cancelDiscovery();
|
||||
public static BluetoothAdapter getDefaultBluetoothAdapter(final String TAG) {
|
||||
// If from the main application thread, return directly
|
||||
if (Thread.currentThread().equals(Looper.getMainLooper().getThread())) {
|
||||
return BluetoothAdapter.getDefaultAdapter();
|
||||
}
|
||||
|
||||
Set<BluetoothDevice> pairedDevices = bluetoothAdapter.getBondedDevices();
|
||||
for (BluetoothDevice device : pairedDevices) {
|
||||
BluetoothClass bluetoothClass = device.getBluetoothClass();
|
||||
if (bluetoothClass != null && (bluetoothClass.getDeviceClass() & BluetoothClass.Device.HEALTH_PULSE_RATE) != 0) {
|
||||
deviceAddresses.add(device.getAddress());
|
||||
deviceNames.add(device.getName());
|
||||
// Get the default adapter from the main application thread
|
||||
final ArrayList<BluetoothAdapter> adapters = new ArrayList<>(1);
|
||||
final Object mutex = new Object();
|
||||
|
||||
Handler handler = new Handler(Looper.getMainLooper());
|
||||
handler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
adapters.add(BluetoothAdapter.getDefaultAdapter());
|
||||
synchronized (mutex) {
|
||||
mutex.notify();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
while (adapters.isEmpty()) {
|
||||
synchronized (mutex) {
|
||||
try {
|
||||
mutex.wait(UnitConversions.ONE_SECOND);
|
||||
} catch (InterruptedException e) {
|
||||
Log.e(TAG, "Interrupted while waiting for default bluetooth adapter", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (adapters.get(0) == null) {
|
||||
Log.w(TAG, "No bluetooth adapter found.");
|
||||
}
|
||||
return adapters.get(0);
|
||||
}
|
||||
|
||||
public static boolean hasBluetooth(final String TAG) {
|
||||
return BluetoothUtils.getDefaultBluetoothAdapter(TAG) != null;
|
||||
}
|
||||
|
||||
public static int parseHeartRate(BluetoothGattCharacteristic characteristic) {
|
||||
|
||||
@@ -157,7 +157,7 @@ public class LocationUtils {
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a given location is a valid (i.e. physically possible) locationon Earth.
|
||||
* Checks if a given location is a valid (i.e. physically possible) location on Earth.
|
||||
* Note: The special separator locations (which have latitude = 100) will not qualify as valid.
|
||||
* Neither will locations with lat=0 and lng=0 as these are most likely "bad" measurements which often cause trouble.
|
||||
*
|
||||
|
||||
@@ -32,41 +32,8 @@ import de.dennisguse.opentracks.R;
|
||||
*/
|
||||
public class PreferencesUtils {
|
||||
|
||||
/*
|
||||
* Preferences values.
|
||||
* The defaults need to match the defaults in the xml files.
|
||||
*/
|
||||
@Deprecated
|
||||
public static final boolean RECORDING_TRACK_PAUSED_DEFAULT = true;
|
||||
|
||||
public static final String BLUETOOTH_SENSOR_DEFAULT = "";
|
||||
|
||||
// Value for split_frequency_key and voice_frequency_key
|
||||
@Deprecated
|
||||
public static final int FREQUENCY_OFF = 0;
|
||||
|
||||
@Deprecated
|
||||
public static final int MAX_RECORDING_DISTANCE_DEFAULT = 200;
|
||||
|
||||
// Values for min_recording_interval_key
|
||||
@Deprecated
|
||||
public static final int MIN_RECORDING_INTERVAL_ADAPT_ACCURACY = -1;
|
||||
@Deprecated
|
||||
public static final int MIN_RECORDING_INTERVAL_ADAPT_BATTERY_LIFE = -2;
|
||||
@Deprecated
|
||||
public static final int MIN_RECORDING_INTERVAL_DEFAULT = 0;
|
||||
|
||||
@Deprecated
|
||||
public static final int RECORDING_DISTANCE_INTERVAL_DEFAULT = 10;
|
||||
|
||||
// Values for recording_gps_accuracy
|
||||
@Deprecated
|
||||
public static final int RECORDING_GPS_ACCURACY_DEFAULT = 50;
|
||||
@Deprecated
|
||||
public static final int RECORDING_GPS_ACCURACY_EXCELLENT = 10;
|
||||
@Deprecated
|
||||
public static final int RECORDING_GPS_ACCURACY_POOR = 2000;
|
||||
|
||||
private PreferencesUtils() {
|
||||
}
|
||||
|
||||
@@ -99,11 +66,8 @@ public class PreferencesUtils {
|
||||
PreferencesUtils.setInt(context, R.string.auto_resume_track_current_retry_key, getAutoResumeTrackCurrentRetryDefault(context) + 1);
|
||||
}
|
||||
|
||||
|
||||
public static final String DEFAULT_ACTIVITY_DEFAULT = "";
|
||||
|
||||
public static String getDefaultActivity(Context context) {
|
||||
return PreferencesUtils.getString(context, R.string.default_activity_key, PreferencesUtils.DEFAULT_ACTIVITY_DEFAULT);
|
||||
return PreferencesUtils.getString(context, R.string.default_activity_key, context.getString(R.string.default_activity_default));
|
||||
}
|
||||
|
||||
public static void setDefaultActivity(Context context, String newDefaultActivity) {
|
||||
@@ -273,9 +237,13 @@ public class PreferencesUtils {
|
||||
return PreferencesUtils.getInt(context, R.string.auto_resume_track_timeout_key, AUTO_RESUME_TRACK_TIMEOUT);
|
||||
}
|
||||
|
||||
|
||||
public static boolean isRecordingTrackPaused(Context context) {
|
||||
final boolean RECORDING_TRACK_PAUSED = context.getResources().getBoolean(R.bool.recording_track_paused_default);
|
||||
return PreferencesUtils.getBoolean(context, R.string.recording_track_paused_key, RECORDING_TRACK_PAUSED);
|
||||
return PreferencesUtils.getBoolean(context, R.string.recording_track_paused_key, isRecordingTrackPausedDefault(context));
|
||||
}
|
||||
|
||||
public static boolean isRecordingTrackPausedDefault(Context context) {
|
||||
return context.getResources().getBoolean(R.bool.recording_track_paused_default);
|
||||
}
|
||||
|
||||
public static void defaultRecordingTrackPaused(Context context) {
|
||||
@@ -283,9 +251,12 @@ public class PreferencesUtils {
|
||||
PreferencesUtils.setBoolean(context, R.string.recording_track_paused_key, RECORDING_TRACK_PAUSED);
|
||||
}
|
||||
|
||||
public static boolean isChartByDistance(Context context) {
|
||||
final String CHART_X_AXIS_DEFAULT = context.getString(R.string.chart_x_axis_default);
|
||||
return CHART_X_AXIS_DEFAULT.equals(getString(context, R.string.chart_x_axis_key, CHART_X_AXIS_DEFAULT));
|
||||
public static boolean isBluetoothHeartRateSensorAddressDefault(Context context) {
|
||||
return PreferencesUtils.BLUETOOTH_SENSOR_DEFAULT.equals(getBluetoothHeartRateSensorAddress(context));
|
||||
}
|
||||
|
||||
public static String getBluetoothHeartRateSensorAddress(Context context) {
|
||||
return PreferencesUtils.getString(context, R.string.settings_sensor_bluetooth_heart_rate_key, PreferencesUtils.BLUETOOTH_SENSOR_DEFAULT);
|
||||
}
|
||||
|
||||
public static boolean shouldChartShowCadence(Context context) {
|
||||
@@ -340,7 +311,11 @@ public class PreferencesUtils {
|
||||
|
||||
public static int getRecordingDistanceInterval(Context context) {
|
||||
final int RECORDING_DISTANCE_INTERVAL = Integer.parseInt(context.getResources().getString(R.string.recording_distance_interval_default));
|
||||
return PreferencesUtils.getInt(context, R.string.recording_distance_interval_key, RECORDING_DISTANCE_INTERVAL);
|
||||
return PreferencesUtils.getInt(context, R.string.recording_distance_interval_key, getRecordingDistanceIntervalDefault(context));
|
||||
}
|
||||
|
||||
public static int getRecordingDistanceIntervalDefault(Context context) {
|
||||
return Integer.parseInt(context.getResources().getString(R.string.recording_distance_interval_default));
|
||||
}
|
||||
|
||||
public static int getMaxRecordingDistance(Context context) {
|
||||
@@ -353,6 +328,22 @@ public class PreferencesUtils {
|
||||
return PreferencesUtils.getInt(context, R.string.min_recording_interval_key, MIN_RECORDING_INTERVAL);
|
||||
}
|
||||
|
||||
public static int getMinRecordingIntervalAdaptAccuracy(Context context) {
|
||||
return Integer.parseInt(context.getResources().getString(R.string.min_recording_interval_adapt_accuracy));
|
||||
}
|
||||
|
||||
public static int getMinRecordingIntervalAdaptBatteryLife(Context context) {
|
||||
return Integer.parseInt(context.getResources().getString(R.string.min_recording_interval_adapt_battery_life));
|
||||
}
|
||||
|
||||
public static int getMinRecordingIntervalDefault(Context context) {
|
||||
return Integer.parseInt(context.getResources().getString(R.string.min_recording_interval_default));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public static int getRecordingGPSAccuracy(Context context) {
|
||||
final int RECORDING_GPS_ACCURACY = Integer.parseInt(context.getResources().getString(R.string.recording_gps_accuracy_default));
|
||||
return PreferencesUtils.getInt(context, R.string.recording_gps_accuracy_key, RECORDING_GPS_ACCURACY);
|
||||
|
||||
@@ -108,7 +108,7 @@ public class StatsUtils {
|
||||
public static void setSensorData(Activity activity, SensorDataSet sensorDataSet, boolean isRecording) {
|
||||
// heart rate
|
||||
int isVisible = View.VISIBLE;
|
||||
if (!isRecording || PreferencesUtils.BLUETOOTH_SENSOR_DEFAULT.equals(PreferencesUtils.getString(activity, R.string.settings_sensor_bluetooth_sensor_key, PreferencesUtils.BLUETOOTH_SENSOR_DEFAULT))) {
|
||||
if (!isRecording || PreferencesUtils.isBluetoothHeartRateSensorAddressDefault(activity)) {
|
||||
isVisible = View.INVISIBLE;
|
||||
}
|
||||
activity.findViewById(R.id.stats_sensor_container).setVisibility(isVisible);
|
||||
@@ -125,11 +125,18 @@ public class StatsUtils {
|
||||
}
|
||||
}
|
||||
|
||||
heartRateValue.setText(heartRate);
|
||||
setBluetoothHeartRateSensorName(activity, sensor, isRecording);
|
||||
heartRateSensor.setText(sensor);
|
||||
}
|
||||
}
|
||||
|
||||
public static void setBluetoothHeartRateSensorName(Activity activity, String sensorName, boolean isRecording) {
|
||||
if (isRecording) {
|
||||
TextView heartRateSensor = activity.findViewById(R.id.stats_sensor_heart_rate_sensor_value);
|
||||
heartRateSensor.setText(sensorName);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the total time value.
|
||||
*
|
||||
|
||||
@@ -359,7 +359,7 @@ public class StringUtils {
|
||||
String[] options = new String[values.length];
|
||||
for (int i = 0; i < values.length; i++) {
|
||||
int value = Integer.parseInt(values[i]);
|
||||
if (value == PreferencesUtils.FREQUENCY_OFF) {
|
||||
if (context.getString(R.string.frequency_off).equals(values[i])) {
|
||||
options[i] = context.getString(R.string.value_off);
|
||||
} else if (value < 0) {
|
||||
options[i] = context.getString(metricUnits ? R.string.value_integer_kilometer : R.string.value_integer_mile, Math.abs(value));
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package de.dennisguse.opentracks.util;
|
||||
|
||||
import android.speech.tts.TextToSpeech;
|
||||
|
||||
public class TTSUtils {
|
||||
|
||||
private TTSUtils() {
|
||||
}
|
||||
|
||||
public static int getTTSStream() {
|
||||
return TextToSpeech.Engine.DEFAULT_STREAM;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,188 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<include layout="@layout/toolbar" />
|
||||
|
||||
<ScrollView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:padding="20dp">
|
||||
|
||||
<TextView
|
||||
style="@style/TextMedium"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/help_feature_title"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<TextView
|
||||
style="@style/TextMedium"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/help_feature_content" />
|
||||
|
||||
<TextView
|
||||
style="@style/TextMedium"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="20dp"
|
||||
android:text="@string/help_track_map_title"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<TextView
|
||||
style="@style/TextMedium"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:linksClickable="true"
|
||||
android:text="@string/help_track_map_content" />
|
||||
|
||||
<TextView
|
||||
style="@style/TextMedium"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="20dp"
|
||||
android:text="@string/help_data_statistics_customized_title"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<TextView
|
||||
style="@style/TextMedium"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/help_data_statistics_customized_content" />
|
||||
|
||||
<TextView
|
||||
style="@style/TextMedium"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="20dp"
|
||||
android:text="@string/help_recording_title"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<TextView
|
||||
style="@style/TextMedium"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/help_recording_content" />
|
||||
|
||||
<TextView
|
||||
style="@style/TextMedium"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="20dp"
|
||||
android:text="@string/help_gps_imprecise_title"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<TextView
|
||||
style="@style/TextMedium"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/help_gps_imprecise_content" />
|
||||
|
||||
<TextView
|
||||
style="@style/TextMedium"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="20dp"
|
||||
android:text="@string/help_heart_rate_sensors_title"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<TextView
|
||||
style="@style/TextMedium"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/help_heart_rate_sensors_content" />
|
||||
|
||||
<TextView
|
||||
style="@style/TextMedium"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="20dp"
|
||||
android:text="@string/help_storage_pictures_title"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<TextView
|
||||
style="@style/TextMedium"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/help_storage_pictures_content" />
|
||||
|
||||
<TextView
|
||||
style="@style/TextMedium"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="20dp"
|
||||
android:text="@string/help_track_export_title"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<TextView
|
||||
style="@style/TextMedium"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/help_track_export_content" />
|
||||
|
||||
<TextView
|
||||
style="@style/TextMedium"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="20dp"
|
||||
android:text="@string/help_data_upload_title"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<TextView
|
||||
style="@style/TextMedium"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/generic_no" />
|
||||
|
||||
<TextView
|
||||
style="@style/TextMedium"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/help_data_google_play_services_title"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<TextView
|
||||
style="@style/TextMedium"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/generic_no" />
|
||||
|
||||
<TextView
|
||||
style="@style/TextMedium"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="20dp"
|
||||
android:text="@string/help_data_online_title"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<TextView
|
||||
style="@style/TextMedium"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/generic_no" />
|
||||
|
||||
<TextView
|
||||
style="@style/TextMedium"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="20dp"
|
||||
android:text="@string/help_data_storage_title"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<TextView
|
||||
style="@style/TextMedium"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/help_data_storage_content" />
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
||||
|
||||
</LinearLayout>
|
||||
@@ -42,7 +42,7 @@ limitations under the License.
|
||||
android:id="@+id/track_detail_markers"
|
||||
android:icon="@drawable/ic_marker_show_24dp"
|
||||
android:orderInCategory="5"
|
||||
android:showAsAction="ifRoom"
|
||||
app:showAsAction="ifRoom"
|
||||
android:title="@string/menu_markers" />
|
||||
<item
|
||||
android:id="@+id/track_detail_edit"
|
||||
|
||||
@@ -27,12 +27,14 @@
|
||||
|
||||
<string name="settings_reset_key" translatable="false">settingsReset</string>
|
||||
|
||||
<string name="settings_sensor_bluetooth_sensor_key" translatable="false">bluetoothSensor</string>
|
||||
<string name="settings_sensor_bluetooth_pairing_key" translatable="false">settingsSensorBluetoothPairing</string>
|
||||
<string name="settings_sensor_bluetooth_heart_rate_key" translatable="false">bluetoothSensor</string>
|
||||
<string name="sensor_type_value_none" translatable="false">NONE</string>
|
||||
|
||||
<string name="default_activity_key" translatable="false">defaultActivity</string>
|
||||
<string name="default_activity_default" translatable="false">@string/activity_type_unknown</string>
|
||||
<string-array name="activity_types">
|
||||
<item>@string/default_activity_default</item>
|
||||
|
||||
<item>@string/activity_type_airplane</item>
|
||||
<item>@string/activity_type_atv</item>
|
||||
<item>@string/activity_type_biking</item>
|
||||
@@ -94,7 +96,6 @@
|
||||
<item>@string/activity_type_trail_running</item>
|
||||
<item>@string/activity_type_train</item>
|
||||
<item>@string/activity_type_ultimate_frisbee</item>
|
||||
<item>@string/activity_type_unknown</item>
|
||||
<item>@string/activity_type_wakeboarding</item>
|
||||
<item>@string/activity_type_walking</item>
|
||||
<item>@string/activity_type_water_skiing</item>
|
||||
@@ -113,26 +114,13 @@
|
||||
<item>@string/auto_resume_track_timeout_always</item>
|
||||
</string-array>
|
||||
|
||||
<string name="chart_x_axis_key" translatable="false">chartXAxis</string>
|
||||
<string name="chart_x_axis_default" translatable="false">@string/chart_x_axis_distance</string>
|
||||
<string-array name="chart_x_axis_values">
|
||||
<item>@string/chart_x_axis_distance</item>
|
||||
<item>@string/chart_x_axis_time</item>
|
||||
</string-array>
|
||||
<string name="chart_x_axis_time" translatable="false">TIME</string>
|
||||
<string name="chart_x_axis_distance" translatable="false">DISTANCE</string>
|
||||
<string-array name="chart_x_axis_options">
|
||||
<item>@string/settings_chart_by_distance</item>
|
||||
<item>@string/settings_chart_by_time</item>
|
||||
</string-array>
|
||||
|
||||
<string name="split_frequency_key" translatable="false">splitFrequency</string>
|
||||
<string name="split_frequency_default" translatable="false">@string/frequency_default</string>
|
||||
<string name="split_frequency_default" translatable="false">@string/frequency_off</string>
|
||||
<string name="voice_frequency_key" translatable="false">voiceFrequency</string>
|
||||
<string name="voice_frequency_default" translatable="false">@string/frequency_default</string>
|
||||
<string name="frequency_default" translatable="false">0</string>
|
||||
<string name="voice_frequency_default" translatable="false">@string/frequency_off</string>
|
||||
<string name="frequency_off" translatable="false">0</string>
|
||||
<string-array name="frequency_values">
|
||||
<item>@string/frequency_default</item>
|
||||
<item>@string/frequency_off</item>
|
||||
<item>1</item>
|
||||
<item>2</item>
|
||||
<item>5</item>
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<!-- This file contains old and now unused settings. -->
|
||||
<!-- It is recommended not to reuse the keys. -->
|
||||
|
||||
<string name="chart_x_axis_key" translatable="false">chartXAxis</string>
|
||||
<string name="chart_x_axis_default" translatable="false">@string/chart_x_axis_distance</string>
|
||||
<string-array name="chart_x_axis_values">
|
||||
<item>@string/chart_x_axis_distance</item>
|
||||
<item>@string/chart_x_axis_time</item>
|
||||
</string-array>
|
||||
<string name="chart_x_axis_time" translatable="false">TIME</string>
|
||||
<string name="chart_x_axis_distance" translatable="false">DISTANCE</string>
|
||||
<string-array name="chart_x_axis_options">
|
||||
<item>@string/settings_chart_by_distance</item>
|
||||
<item>@string/settings_chart_by_time</item>
|
||||
</string-array>
|
||||
</resources>
|
||||
@@ -38,6 +38,95 @@ limitations under the License.
|
||||
Libraries
|
||||
</string>
|
||||
|
||||
<!-- Help -->
|
||||
<string name="help_feature_title">
|
||||
OpenTracks has the following features:
|
||||
</string>
|
||||
<string name="help_feature_content">
|
||||
* Create markers (incl. pictures)\n
|
||||
* Heart rate sensor (Bluetooth LE)\n
|
||||
* Voice announcements by time or distance\n
|
||||
* While recording, show on lock screen\n
|
||||
* Share tracks
|
||||
</string>
|
||||
|
||||
<string name="help_data_statistics_customized_title">
|
||||
Can the statistics view be customized?
|
||||
</string>
|
||||
<string name="help_data_statistics_customized_content">
|
||||
Yes, it can be customized in the Settings.
|
||||
</string>
|
||||
|
||||
<string name="help_recording_title">
|
||||
How does OpenTracks record data?
|
||||
</string>
|
||||
<string name="help_recording_content">
|
||||
OpenTracks uses the GPS sensor of the device to record the location continuously.
|
||||
</string>
|
||||
|
||||
<string name="help_gps_imprecise_title">
|
||||
Statistics (e.g., speed) reported by OpenTracks are imprecise?
|
||||
</string>
|
||||
<string name="help_gps_imprecise_content">
|
||||
OpenTracks directly uses the data provided by the GPS of the mobile device.
|
||||
If the GPS device reports inaccurate locations, OpenTracks cannot do anything about it.
|
||||
</string>
|
||||
|
||||
<string name="help_heart_rate_sensors_title">
|
||||
Which heart rate sensors does OpenTracks support?
|
||||
</string>
|
||||
<string name="help_heart_rate_sensors_content">
|
||||
OpenTracks should work with any Bluetooth LE heart sensor that support streaming the data in real-time.
|
||||
Smartwatches that store the heart rate data are not supported.
|
||||
</string>
|
||||
|
||||
<string name="help_track_map_title">
|
||||
How to show a track on a map?
|
||||
</string>
|
||||
<string name="help_track_map_content">
|
||||
This requires a 3rd party application to be installed that can consume KMZ-encoded geo data.
|
||||
This works well with <a href="http://osmand.net/">OsmAnd~</a> and <a href="https://maps.me/">Maps.ME</a>.
|
||||
In fact, an App needs to support <i>ACTION_VIEW</i> with MIME <i>application/vnd.google-earth.kmz</i>.
|
||||
At the moment, the recorded locations as well as the timestamps are send to an App while pictures and sensor data are not shared.
|
||||
</string>
|
||||
|
||||
<string name="help_storage_pictures_title">
|
||||
How does OpenTracks store pictures that were taken as markers?
|
||||
</string>
|
||||
<string name="help_storage_pictures_content">
|
||||
These are stored directly on the file system.
|
||||
</string>
|
||||
|
||||
<string name="help_track_export_title">
|
||||
How can I export/share recorded tracks?
|
||||
</string>
|
||||
<string name="help_track_export_content">
|
||||
Tracks can be exported from the Settings as KMZ, KML, or GPX.
|
||||
KMZ contains all data incl. images, while KML contains only the sensor data, and GPX only the location.
|
||||
Tracks shared via the <i>share icon</i> are shared as KMZ and any App can be used to send the data.
|
||||
</string>
|
||||
|
||||
<string name="help_data_upload_title">
|
||||
Can OpenTracks upload the data automatically?
|
||||
</string>
|
||||
|
||||
<string name="help_data_google_play_services_title">
|
||||
Does OpenTracks require/use Google Play Service?
|
||||
</string>
|
||||
|
||||
<string name="help_data_online_title">
|
||||
Does OpenTracks use online services?
|
||||
</string>
|
||||
|
||||
<string name="help_data_storage_title">
|
||||
How does OpenTracks store sensor data?
|
||||
</string>
|
||||
<string name="help_data_storage_content">
|
||||
OpenTracks stores sensor data per recorded location.
|
||||
In terms of a heart rate sensor this means that only <i>one</i> heart rate measurement is stored per location.
|
||||
If you are standing still or are indoors, no sensor data will be recorded (but it will be shown).
|
||||
</string>
|
||||
|
||||
<!-- Activity Type -->
|
||||
<string name="activity_type_airplane" translation_description="When entering an 'Activity type', in the auto-complete text box, the
|
||||
completion suggestion for airplane.">
|
||||
@@ -1055,7 +1144,13 @@ limitations under the License.
|
||||
Sending
|
||||
</string>
|
||||
<string name="sensor_not_known" translation_description="Error message if sensor is not available in Android (e.g., pairing was removed in Bluetooth Settings).">
|
||||
Sensor %1$s is not known. Please check the settings.
|
||||
Sensor %1$s is unknown. Please check the settings.
|
||||
</string>
|
||||
<string name="sensor_could_not_scan">
|
||||
Could not scan for Bluetooth devices (error %1$i).
|
||||
</string>
|
||||
<string name="bluetooth_disabled">
|
||||
Please enable Bluetooth.
|
||||
</string>
|
||||
<!-- Settings -->
|
||||
<string name="settings_not_while_recording" translation_description="In settings, the summary for an option that is not available during a
|
||||
@@ -1220,7 +1315,7 @@ limitations under the License.
|
||||
</string>
|
||||
|
||||
<string name="settings_error_initial_values_restored" translation_description="If the ">
|
||||
Sorry, but an error occurred: and the all settings were reset to there default values.
|
||||
Sorry, but an error occurred. All settings have been reverted to the default values.
|
||||
</string>
|
||||
|
||||
<!-- Settings Sensor -->
|
||||
@@ -1419,6 +1514,9 @@ limitations under the License.
|
||||
<string name="track_record_notification" translation_description="When recording a track, the message on the OpenTracks notification
|
||||
informing the user that OpenTracks is actively recording his track.">
|
||||
Recording your track…
|
||||
</string>
|
||||
<string name="track_recording_notification_accuracy">
|
||||
Location accuracy: %1$s
|
||||
</string>
|
||||
<string name="track_markers" translation_description="Title indicating a particular track's markers.
|
||||
|
||||
|
||||
@@ -17,6 +17,14 @@ limitations under the License.
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:title="@string/menu_settings">
|
||||
|
||||
<PreferenceCategory android:title="@string/menu_help">
|
||||
<Preference android:title="@string/menu_help">
|
||||
<intent
|
||||
android:targetClass="de.dennisguse.opentracks.HelpActivity"
|
||||
android:targetPackage="@string/applicationId" />
|
||||
</Preference>
|
||||
</PreferenceCategory>
|
||||
|
||||
<PreferenceCategory android:title="@string/track_detail_stats_tab">
|
||||
<ListPreference
|
||||
android:defaultValue="@string/stats_units_default"
|
||||
@@ -46,13 +54,6 @@ limitations under the License.
|
||||
</PreferenceCategory>
|
||||
|
||||
<PreferenceCategory android:title="@string/track_detail_chart_tab">
|
||||
<ListPreference
|
||||
android:defaultValue="@string/chart_x_axis_default"
|
||||
android:entries="@array/chart_x_axis_options"
|
||||
android:entryValues="@array/chart_x_axis_values"
|
||||
android:key="@string/chart_x_axis_key"
|
||||
android:title="@string/settings_chart_x_axis"
|
||||
app:useSimpleSummaryProvider="true" />
|
||||
<CheckBoxPreference
|
||||
android:defaultValue="true"
|
||||
android:key="@string/chart_show_elevation_key"
|
||||
@@ -93,7 +94,7 @@ limitations under the License.
|
||||
android:title="@string/settings_recording_track_name_title"
|
||||
app:useSimpleSummaryProvider="true" />
|
||||
<ListPreference
|
||||
android:defaultValue="0"
|
||||
android:defaultValue="@string/min_recording_interval_default"
|
||||
android:entryValues="@array/min_recording_interval_values"
|
||||
android:key="@string/min_recording_interval_key"
|
||||
android:title="@string/settings_recording_min_recording_interval_title"
|
||||
@@ -111,37 +112,29 @@ limitations under the License.
|
||||
android:title="@string/settings_recording_max_recording_distance_title"
|
||||
app:useSimpleSummaryProvider="true" />
|
||||
<ListPreference
|
||||
android:defaultValue="50"
|
||||
android:defaultValue="@string/recording_gps_accuracy_default"
|
||||
android:entryValues="@array/recording_gps_accuracy_values"
|
||||
android:key="@string/recording_gps_accuracy_key"
|
||||
android:title="@string/settings_recording_min_required_accuracy_title"
|
||||
app:useSimpleSummaryProvider="true" />
|
||||
<ListPreference
|
||||
android:defaultValue="10"
|
||||
android:defaultValue="@string/auto_resume_track_timeout_default"
|
||||
android:entries="@array/auto_resume_track_timeout_values"
|
||||
android:entryValues="@array/auto_resume_track_timeout_values"
|
||||
android:key="@string/auto_resume_track_timeout_key"
|
||||
android:title="@string/settings_recording_auto_resume_track_timeout_title"
|
||||
app:useSimpleSummaryProvider="true" />
|
||||
<de.dennisguse.opentracks.settings.ActivityTypePreference
|
||||
android:defaultValue="@string/activity_type_running"
|
||||
android:defaultValue="@string/default_activity_default"
|
||||
android:key="@string/default_activity_key"
|
||||
android:title="@string/settings_recording_default_activity_title" />
|
||||
</PreferenceCategory>
|
||||
|
||||
<PreferenceCategory android:title="@string/settings_sensor">
|
||||
<ListPreference
|
||||
<PreferenceCategory android:title="@string/settings_sensor_bluetooth">
|
||||
<de.dennisguse.opentracks.settings.BluetoothLePreference
|
||||
android:defaultValue="@string/sensor_type_value_none"
|
||||
android:key="@string/settings_sensor_bluetooth_sensor_key"
|
||||
android:title="@string/settings_sensor_bluetooth_sensor"
|
||||
app:useSimpleSummaryProvider="true" />
|
||||
<Preference
|
||||
android:key="@string/settings_sensor_bluetooth_pairing_key"
|
||||
android:persistent="false"
|
||||
android:summary="@string/settings_sensor_bluetooth_pairing_summary"
|
||||
android:title="@string/settings_sensor_bluetooth_pairing">
|
||||
<intent android:action="android.settings.BLUETOOTH_SETTINGS" />
|
||||
</Preference>
|
||||
android:key="@string/settings_sensor_bluetooth_heart_rate_key"
|
||||
android:title="@string/sensor_state_heart_rate" />
|
||||
</PreferenceCategory>
|
||||
|
||||
<PreferenceCategory android:title="@string/generic_tracks">
|
||||
|
||||
Reference in New Issue
Block a user