Compare commits
164 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 6133ef121a | |||
| c6d24e9534 | |||
| 441d3f721f | |||
| 3c212e4bcc | |||
| 50eb71bc1f | |||
| 0806821b5f | |||
| 36d0f17953 | |||
| 700adb7972 | |||
| a156369f8b | |||
| c0f6dc511b | |||
| 63e1461eba | |||
| 804e5f10c8 | |||
| 6cc7271a41 | |||
| f66194189b | |||
| 5d97d6d492 | |||
| f3a308e669 | |||
| a230504925 | |||
| 90e19e282c | |||
| b585bfe44c | |||
| 475e04eeb4 | |||
| f89b2b0efb | |||
| b94f3c176b | |||
| d1d729d287 | |||
| e23bbcc405 | |||
| 4129985b0f | |||
| 5cb7b623d9 | |||
| 3c52efadd6 | |||
| 73b4977051 | |||
| 422c2c02ce | |||
| d692329975 | |||
| 931574bc11 | |||
| caddbd8501 | |||
| 8ece2c8612 | |||
| 3a219321d1 | |||
| 35cb924a17 | |||
| b67e5bbd20 | |||
| 1db275230e | |||
| 5ac72092fb | |||
| bdd9ded1e8 | |||
| 759aeb6ed6 | |||
| 12023d51ae | |||
| c426785b90 | |||
| 09d960c7a1 | |||
| f37fe4a503 | |||
| 013e56bef0 | |||
| d6835ba766 | |||
| d7890cbc81 | |||
| 2b6886c534 | |||
| e77590a125 | |||
| ca330b2d80 | |||
| 20f1524701 | |||
| 96b2a15643 | |||
| ad59392e02 | |||
| 29f92b887c | |||
| 46328211c2 | |||
| 3760130d1f | |||
| 1094827fac | |||
| 36fcb44af5 | |||
| a683fbac4b | |||
| 64ad9019d1 | |||
| 1e80d5c8a8 | |||
| ac765b1ee8 | |||
| 850c4f0a9a | |||
| 4c32999752 | |||
| 76823b167a | |||
| 9994cfd260 | |||
| 1750236474 | |||
| fed6e31f9e | |||
| 9bafc7d4a1 | |||
| be58b48d20 | |||
| 303abac980 | |||
| d1a459efc2 | |||
| 96069e6f09 | |||
| 301a721329 | |||
| e8c6801a32 | |||
| 355f3ef614 | |||
| eaa6083586 | |||
| a0c5d02c51 | |||
| 76f9f5fc82 | |||
| 8e2598e93b | |||
| c0672c41df | |||
| 4c6601fbc5 | |||
| b99c87d1bd | |||
| 66ffbfe951 | |||
| 8cb01a1027 | |||
| 193e5eccbb | |||
| bf7fc28bb0 | |||
| e35cbc343a | |||
| 1c7b053c8c | |||
| 88cdcd4b47 | |||
| 1432fed8f9 | |||
| a14307b9a4 | |||
| 3bdce5aa08 | |||
| d7526f93b8 | |||
| 8932578b90 | |||
| 631ac9881d | |||
| 78334ed797 | |||
| b06da89654 | |||
| d6c2e78993 | |||
| 67d1ac551d | |||
| dcb6be717d | |||
| f2c04eec1a | |||
| a08311cf43 | |||
| 1e28f3aa86 | |||
| 426af41f2c | |||
| fd08a219f9 | |||
| 25b6aec0e9 | |||
| 3e40209d15 | |||
| 54ff94f905 | |||
| 7a4faf6b0d | |||
| 8922b00a5f | |||
| 702efa8693 | |||
| e7a8c897a3 | |||
| c59d1d87bd | |||
| a706efb8b3 | |||
| e391e83a00 | |||
| 2940bf20d8 | |||
| 081db5a58b | |||
| b34805272f | |||
| 98443dba99 | |||
| dd6e733d8c | |||
| 92d3439c3b | |||
| bd155cd600 | |||
| e14e53c0ae | |||
| 77a6a63174 | |||
| 40f2463f09 | |||
| e5d1048c8d | |||
| bf3b529fb2 | |||
| d0fde46027 | |||
| 0f348dff10 | |||
| d3f5080e73 | |||
| a453c8ec1e | |||
| 2a60aa8f59 | |||
| 41e7870509 | |||
| 57f66b77ab | |||
| 53572406e9 | |||
| a288255ab1 | |||
| 353c958ae0 | |||
| bc5ab0d7e5 | |||
| 9d915b5640 | |||
| 3aaee270eb | |||
| d53a7156e2 | |||
| 3af24ea3d0 | |||
| 5483212b06 | |||
| 419279fe5e | |||
| 501e899b27 | |||
| 3bb9edb009 | |||
| e52b1188a3 | |||
| 9e877e4762 | |||
| 5711757110 | |||
| e1c33dad43 | |||
| 4b2400774c | |||
| afd4a59622 | |||
| bdce437470 | |||
| 33479cda11 | |||
| 385cee3dc7 | |||
| d0bbd7655b | |||
| a83b8f62fe | |||
| 0cd9176703 | |||
| d8e526923d | |||
| 3a6f417662 | |||
| 7d807a7f11 | |||
| e9d5718495 | |||
| 0dd7f74a11 |
@@ -0,0 +1,4 @@
|
|||||||
|
# These are supported funding model platforms
|
||||||
|
|
||||||
|
liberapay: dennis.guse
|
||||||
|
custom: https://play.google.com/store/apps/details?id=de.dennisguse.opentracks.playstore
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
---
|
||||||
|
name: Bug report
|
||||||
|
about: Report issues of OpenTracks features
|
||||||
|
title: ''
|
||||||
|
labels: potential bug
|
||||||
|
assignees: ''
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**Describe the bug**
|
||||||
|
A clear and concise description of what the bug is.
|
||||||
|
|
||||||
|
**To Reproduce**
|
||||||
|
1. Go to '...'
|
||||||
|
2. Click on '....'
|
||||||
|
3. Scroll down to '....'
|
||||||
|
4. See error
|
||||||
|
|
||||||
|
If applicable:
|
||||||
|
* add screenshots
|
||||||
|
* add logcat output
|
||||||
|
|
||||||
|
**Technical information**
|
||||||
|
- Device: [e.g. Nexus 7 (2013)]
|
||||||
|
- OS: [e.g. LineageOS 15.1]
|
||||||
|
- Version [e.g. v3.2.4]
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
---
|
||||||
|
name: Feature request
|
||||||
|
about: Suggest an idea for OpenTracks
|
||||||
|
title: ''
|
||||||
|
labels: enhancement
|
||||||
|
assignees: ''
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
**Is your feature request related to a problem? Please describe.**
|
||||||
|
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
||||||
|
|
||||||
|
**Describe the solution you'd like**
|
||||||
|
A clear and concise description of what you want to happen.
|
||||||
|
|
||||||
|
**Describe alternatives you've considered**
|
||||||
|
A clear and concise description of any alternative solutions or features you've considered.
|
||||||
|
|
||||||
|
**Additional context**
|
||||||
|
Add any other context or screenshots about the feature request here.
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
# Thanks for your contribution.
|
||||||
|
|
||||||
|
**Describe the pull request**
|
||||||
|
A clear and concise description of what the pull request changes/adds.
|
||||||
|
|
||||||
|
**Link to the the issue**
|
||||||
|
(If available): The link to the issue that this pull request solves.
|
||||||
|
|
||||||
|
**License agreement**
|
||||||
|
By opening this pull request, you are providing your contribution under the _Apache License 2.0_ (see [LICENSE.md](LICENSE.md)).
|
||||||
@@ -73,8 +73,12 @@ captures/
|
|||||||
.idea/workspace.xml
|
.idea/workspace.xml
|
||||||
|
|
||||||
# Keystore files
|
# Keystore files
|
||||||
# Uncomment the following line if you do not want to check your keystore files in.
|
*.jks
|
||||||
#*.jks
|
|
||||||
|
|
||||||
# External native build folder generated in Android Studio 2.2 and later
|
# External native build folder generated in Android Studio 2.2 and later
|
||||||
.externalNativeBuild
|
.externalNativeBuild
|
||||||
|
|
||||||
|
# Fastlane
|
||||||
|
Appfile
|
||||||
|
releasePlayStore/*
|
||||||
|
Gemfile.lock
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="RenderSettings">
|
||||||
|
<option name="showDecorations" value="true" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
@@ -1,12 +1,46 @@
|
|||||||
|
#See https://docs.travis-ci.com/user/languages/android/
|
||||||
|
#See https://github.com/ankidroid/Anki-Android/blob/master/.travis.yml
|
||||||
language: android
|
language: android
|
||||||
dist: trusty
|
|
||||||
|
env:
|
||||||
|
global:
|
||||||
|
- ADB_INSTALL_TIMEOUT=8
|
||||||
|
- ABI=armeabi-v7a
|
||||||
|
- EMU_FLAVOR=default
|
||||||
|
# PATH order is incredibly important. e.g. the 'emulator' script exists in more than one place!
|
||||||
|
- ANDROID_HOME=/usr/local/android-sdk
|
||||||
|
- TOOLS=${ANDROID_HOME}/tools
|
||||||
|
- PATH=${ANDROID_HOME}:${ANDROID_HOME}/emulator:${TOOLS}:${TOOLS}/bin:${ANDROID_HOME}/platform-tools:${PATH}
|
||||||
|
matrix:
|
||||||
|
- API=27 ABI=x86_64
|
||||||
|
|
||||||
android:
|
android:
|
||||||
components:
|
components:
|
||||||
|
# installing tools to start, then use `sdkmanager` below to get the rest
|
||||||
|
- tools
|
||||||
- build-tools-28.0.3
|
- build-tools-28.0.3
|
||||||
- android-29
|
- android-29
|
||||||
|
|
||||||
|
# Emulator Management: Create, Start and Wait
|
||||||
|
#install:
|
||||||
|
# - echo y | sdkmanager "platform-tools"
|
||||||
|
# - echo y | sdkmanager --channel=4 "emulator"
|
||||||
|
# - echo y | sdkmanager "system-images;android-$API;$EMU_FLAVOR;$ABI"
|
||||||
|
# - echo no | avdmanager create avd --force -n test -k "system-images;android-$API;$EMU_FLAVOR;$ABI" -c 10M
|
||||||
|
# - emulator -verbose -avd test -no-accel -no-snapshot -no-window -camera-back none -camera-front none -selinux permissive -qemu -m 2048 &
|
||||||
|
# - android-wait-for-emulator
|
||||||
|
# - adb shell input keyevent 82 &
|
||||||
|
|
||||||
script:
|
script:
|
||||||
- ./gradlew build
|
- ./gradlew clean build
|
||||||
#TODO: When all tests are passing, CI should also execute them.
|
# - ./gradlew connectedCheck
|
||||||
#- ./gradlew connectedCheck
|
|
||||||
|
sbefore_cache:
|
||||||
|
- rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
|
||||||
|
- rm -fr $HOME/.gradle/caches/*/plugin-resolution/
|
||||||
|
|
||||||
|
cache:
|
||||||
|
directories:
|
||||||
|
- $HOME/.gradle/caches/
|
||||||
|
- $HOME/.gradle/wrapper/
|
||||||
|
- $HOME/.android/build-cache
|
||||||
@@ -1,12 +0,0 @@
|
|||||||
# OpenTrack: Developer information
|
|
||||||
|
|
||||||
## Create releases for FDroid
|
|
||||||
|
|
||||||
1. Get next _version code_ (master branch): `git rev-list HEAD --count master`
|
|
||||||
2. Decide on _version name_ (semantic versioning)
|
|
||||||
3. Manually update _version code_ and _version name_ in `AndroidManifest.xml` (used by FDroid)
|
|
||||||
4. Create changelog (`_version code_.txt`)
|
|
||||||
5. Create commit with all changes
|
|
||||||
6. Push commits
|
|
||||||
7. Tag newly create commit with _version name_ (e.g., v3.2.1)
|
|
||||||
8. Push the tagged commit to public repository
|
|
||||||
@@ -2,9 +2,30 @@
|
|||||||
|
|
||||||
_OpenTracks_ is a sport tracking application that completely respects your privacy.
|
_OpenTracks_ is a sport tracking application that completely respects your privacy.
|
||||||
|
|
||||||
<a href="https://f-droid.org/packages/de.dennisguse.opentracks">
|
<table>
|
||||||
<img src="https://fdroid.gitlab.io/artwork/badge/get-it-on.png" alt="Get it on F-Droid" height="60">
|
<tr>
|
||||||
</a>
|
<th>Free</th>
|
||||||
|
<th>Paid</th>
|
||||||
|
<th>Donations</th>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
<a href="https://f-droid.org/packages/de.dennisguse.opentracks">
|
||||||
|
<img alt="Get it on F-Droid" src="https://fdroid.gitlab.io/artwork/badge/get-it-on.png" height="60" align="middle">
|
||||||
|
</a>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<a href="https://play.google.com/store/apps/details?id=de.dennisguse.opentracks.playstore">
|
||||||
|
<img alt="Get it on Google Play" src="https://play.google.com/intl/en_us/badges/static/images/badges/en_badge_web_generic.png" height="60" align="middle">
|
||||||
|
</a>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<a href="https://liberapay.com/dennis.guse/donate">
|
||||||
|
<img alt="Donate using Liberapay" src="https://liberapay.com/assets/widgets/donate.svg" height="45" align="middle">
|
||||||
|
</a>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
|
||||||
## Features:
|
## Features:
|
||||||
* __Tracking:__ track your sport and outdoor activities
|
* __Tracking:__ track your sport and outdoor activities
|
||||||
@@ -26,9 +47,14 @@ _Please note:_
|
|||||||
_Tracks_ does not contain a _map_ (as this would required Internet access).
|
_Tracks_ does not contain a _map_ (as this would required Internet access).
|
||||||
To show your tracks on a map, a 3rd party application (e.g., [OsmAnd](https://play.google.com/store/apps/details?id=net.osmand) or [MAPS.ME](https://play.google.com/store/apps/details?id=com.mapswithme.maps.pro)) needs to be installed.
|
To show your tracks on a map, a 3rd party application (e.g., [OsmAnd](https://play.google.com/store/apps/details?id=net.osmand) or [MAPS.ME](https://play.google.com/store/apps/details?id=com.mapswithme.maps.pro)) needs to be installed.
|
||||||
|
|
||||||
<a href="https://liberapay.com/dennis.guse/donate">
|
|
||||||
<img alt="Donate using Liberapay" src="https://liberapay.com/assets/widgets/donate.svg" height="45">
|
## Screenshots
|
||||||
</a>
|
<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
|
## Project history
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,37 @@
|
|||||||
|
# OpenTracks: Developer information
|
||||||
|
|
||||||
|
## Craft new releases
|
||||||
|
|
||||||
|
1. Get next _version code_ (master branch): `git rev-list HEAD --count master`
|
||||||
|
2. Decide on _version name_ (semantic versioning)
|
||||||
|
3. Manually update _version code_ and _version name_ in `AndroidManifest.xml` (used by FDroid)
|
||||||
|
4. Create changelog (`_version code_.txt`)
|
||||||
|
5. Create commit with all changes
|
||||||
|
6. Tag newly create commit with _version name_ (e.g., v3.2.1)
|
||||||
|
7. Push commits and tags to public repository
|
||||||
|
8. Add changelog to tag (Github releases)
|
||||||
|
|
||||||
|
## F-Droid
|
||||||
|
Application id: de.dennisguse.opentracks
|
||||||
|
|
||||||
|
It if it properly tagged F-Droid takes care of building the app and publishing.
|
||||||
|
Usually, it takes two days before the update is published (build, signed, and published).
|
||||||
|
|
||||||
|
The recent build activity can be found [here](https://f-droid.org/wiki/index.php?title=Special:RecentChanges&days=7&from=&hidebots=0&hideanons=1&hideliu=1&limit=500)
|
||||||
|
|
||||||
|
## Google Play Store
|
||||||
|
Application id: de.dennisguse.opentracks.playstore
|
||||||
|
|
||||||
|
Requirement: `gem install fastlane`
|
||||||
|
|
||||||
|
1. Build signed apk
|
||||||
|
(requires keystore)
|
||||||
|
2. Upload signed apk to [Google Play Console](https://play.google.com/apps/publish)
|
||||||
|
3. Update store meta data (e.g., description and screenshots)
|
||||||
|
`fastlane supply --version_code VERSION_CODE --skip_upload_apk`
|
||||||
|
(use the version code from the manifest)
|
||||||
|
(requires API key)
|
||||||
|
|
||||||
|
## Translations (localization)
|
||||||
|
|
||||||
|
Translations of the OpenTracks are handled in Transifex: [https://www.transifex.com/opentracks](https://www.transifex.com/opentracks/).
|
||||||
@@ -6,7 +6,7 @@ buildscript {
|
|||||||
jcenter()
|
jcenter()
|
||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
classpath 'com.android.tools.build:gradle:3.5.0'
|
classpath 'com.android.tools.build:gradle:3.5.3'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -35,10 +35,14 @@ def getVersionName = { ->
|
|||||||
try {
|
try {
|
||||||
def stdout = new ByteArrayOutputStream()
|
def stdout = new ByteArrayOutputStream()
|
||||||
exec {
|
exec {
|
||||||
commandLine 'git', 'describe', '--tags', '--dirty'
|
commandLine 'git', 'describe', '--tags'
|
||||||
standardOutput = stdout
|
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) {
|
catch (ignored) {
|
||||||
return null
|
return null
|
||||||
@@ -50,6 +54,11 @@ android {
|
|||||||
|
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
applicationId "de.dennisguse.opentracks"
|
applicationId "de.dennisguse.opentracks"
|
||||||
|
manifestPlaceholders = [
|
||||||
|
applicationLogo: "@drawable/ic_logo_color_24dp",
|
||||||
|
applicationName: "@strings/app_name"
|
||||||
|
]
|
||||||
|
|
||||||
//Useful for debugging.
|
//Useful for debugging.
|
||||||
//versionCode getVersionCode()
|
//versionCode getVersionCode()
|
||||||
|
|
||||||
@@ -65,20 +74,25 @@ android {
|
|||||||
debug {
|
debug {
|
||||||
applicationIdSuffix ".debug"
|
applicationIdSuffix ".debug"
|
||||||
versionNameSuffix "-debug"
|
versionNameSuffix "-debug"
|
||||||
|
manifestPlaceholders = [
|
||||||
|
applicationLogo: "@drawable/ic_logo_black_24dp",
|
||||||
|
applicationName: "OpenTracks (Debug)"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
release {
|
release {
|
||||||
minifyEnabled false
|
minifyEnabled false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
releasePlayStore {
|
||||||
|
applicationIdSuffix ".playstore"
|
||||||
|
versionNameSuffix "-PlayStore"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
applicationVariants.all { variant ->
|
applicationVariants.all { variant ->
|
||||||
variant.resValue "string", "applicationId", variant.applicationId
|
variant.resValue "string", "applicationId", variant.applicationId
|
||||||
}
|
}
|
||||||
|
|
||||||
lintOptions {
|
|
||||||
disable "AppCompatResource" // TODO Disable complaint to use androidx's SearchView as it is null.
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
@@ -95,4 +109,5 @@ dependencies {
|
|||||||
|
|
||||||
testImplementation 'androidx.test:core:1.2.0'
|
testImplementation 'androidx.test:core:1.2.0'
|
||||||
testImplementation 'org.mockito:mockito-core:3.0.0'
|
testImplementation 'org.mockito:mockito-core:3.0.0'
|
||||||
|
implementation 'com.google.android.material:material:1.0.0'
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,52 @@
|
|||||||
|
@startuml
|
||||||
|
class Track {
|
||||||
|
-id
|
||||||
|
-name
|
||||||
|
-description
|
||||||
|
-category
|
||||||
|
-numberOfPoints
|
||||||
|
-icon
|
||||||
|
}
|
||||||
|
Track o-- TrackPoint
|
||||||
|
Track o-- Waypoint
|
||||||
|
Track "1" - "1" TripStatistics
|
||||||
|
|
||||||
|
class TripStatistics {
|
||||||
|
- startTime
|
||||||
|
- stopTime
|
||||||
|
- totalDistance
|
||||||
|
- totalTime
|
||||||
|
- movingTime
|
||||||
|
- maxSpeed
|
||||||
|
- totalElevationGain
|
||||||
|
}
|
||||||
|
|
||||||
|
class TrackPoint extends android.location.Location {
|
||||||
|
- id
|
||||||
|
- trackId
|
||||||
|
- longitude
|
||||||
|
- latitude
|
||||||
|
- time
|
||||||
|
- altitude
|
||||||
|
- accuracy
|
||||||
|
- speed
|
||||||
|
- bearing
|
||||||
|
- sensor_heartrate
|
||||||
|
- sensor_cadence
|
||||||
|
- sensor_power
|
||||||
|
}
|
||||||
|
|
||||||
|
class Waypoint {
|
||||||
|
- id
|
||||||
|
- trackId
|
||||||
|
- name
|
||||||
|
- description
|
||||||
|
- category
|
||||||
|
- icon
|
||||||
|
- length
|
||||||
|
- duration
|
||||||
|
- location
|
||||||
|
- tripStatistics
|
||||||
|
- photoUrl
|
||||||
|
}
|
||||||
|
@enduml
|
||||||
@@ -17,7 +17,7 @@
|
|||||||
<rdf:RDF>
|
<rdf:RDF>
|
||||||
<cc:Work rdf:about="">
|
<cc:Work rdf:about="">
|
||||||
<dc:format>image/svg+xml</dc:format>
|
<dc:format>image/svg+xml</dc:format>
|
||||||
<dc:title></dc:title>
|
<dc:title />
|
||||||
<dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
<dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||||
</cc:Work>
|
</cc:Work>
|
||||||
</rdf:RDF>
|
</rdf:RDF>
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 1.6 KiB |
@@ -43,7 +43,7 @@
|
|||||||
<rdf:RDF>
|
<rdf:RDF>
|
||||||
<cc:Work rdf:about="">
|
<cc:Work rdf:about="">
|
||||||
<dc:format>image/svg+xml</dc:format>
|
<dc:format>image/svg+xml</dc:format>
|
||||||
<dc:title></dc:title>
|
<dc:title />
|
||||||
<dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
<dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||||
</cc:Work>
|
</cc:Work>
|
||||||
</rdf:RDF>
|
</rdf:RDF>
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 2.5 KiB After Width: | Height: | Size: 2.5 KiB |
@@ -41,7 +41,7 @@
|
|||||||
<rdf:RDF>
|
<rdf:RDF>
|
||||||
<cc:Work rdf:about="">
|
<cc:Work rdf:about="">
|
||||||
<dc:format>image/svg+xml</dc:format>
|
<dc:format>image/svg+xml</dc:format>
|
||||||
<dc:title></dc:title>
|
<dc:title />
|
||||||
<dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
<dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||||
</cc:Work>
|
</cc:Work>
|
||||||
</rdf:RDF>
|
</rdf:RDF>
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 1.8 KiB |
@@ -33,7 +33,7 @@
|
|||||||
<rdf:RDF>
|
<rdf:RDF>
|
||||||
<cc:Work rdf:about="">
|
<cc:Work rdf:about="">
|
||||||
<dc:format>image/svg+xml</dc:format>
|
<dc:format>image/svg+xml</dc:format>
|
||||||
<dc:title></dc:title>
|
<dc:title />
|
||||||
<dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
<dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||||
</cc:Work>
|
</cc:Work>
|
||||||
</rdf:RDF>
|
</rdf:RDF>
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 1.4 KiB |
@@ -39,7 +39,7 @@
|
|||||||
<rdf:RDF>
|
<rdf:RDF>
|
||||||
<cc:Work rdf:about="">
|
<cc:Work rdf:about="">
|
||||||
<dc:format>image/svg+xml</dc:format>
|
<dc:format>image/svg+xml</dc:format>
|
||||||
<dc:title></dc:title>
|
<dc:title />
|
||||||
<dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
<dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||||
</cc:Work>
|
</cc:Work>
|
||||||
</rdf:RDF>
|
</rdf:RDF>
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 1.9 KiB After Width: | Height: | Size: 1.9 KiB |
@@ -18,7 +18,7 @@
|
|||||||
<rdf:RDF>
|
<rdf:RDF>
|
||||||
<cc:Work rdf:about="">
|
<cc:Work rdf:about="">
|
||||||
<dc:format>image/svg+xml</dc:format>
|
<dc:format>image/svg+xml</dc:format>
|
||||||
<dc:title></dc:title>
|
<dc:title />
|
||||||
<dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
<dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||||
</cc:Work>
|
</cc:Work>
|
||||||
</rdf:RDF>
|
</rdf:RDF>
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 2.0 KiB After Width: | Height: | Size: 2.0 KiB |
@@ -21,7 +21,7 @@
|
|||||||
<rdf:RDF>
|
<rdf:RDF>
|
||||||
<cc:Work rdf:about="">
|
<cc:Work rdf:about="">
|
||||||
<dc:format>image/svg+xml</dc:format>
|
<dc:format>image/svg+xml</dc:format>
|
||||||
<dc:title></dc:title>
|
<dc:title />
|
||||||
<dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
<dc:type rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||||
</cc:Work>
|
</cc:Work>
|
||||||
</rdf:RDF>
|
</rdf:RDF>
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 1.8 KiB |
@@ -0,0 +1,38 @@
|
|||||||
|
# This file contains the fastlane.tools configuration
|
||||||
|
# You can find the documentation at https://docs.fastlane.tools
|
||||||
|
#
|
||||||
|
# For a list of all available actions, check out
|
||||||
|
#
|
||||||
|
# https://docs.fastlane.tools/actions
|
||||||
|
#
|
||||||
|
# For a list of all available plugins, check out
|
||||||
|
#
|
||||||
|
# https://docs.fastlane.tools/plugins/available-plugins
|
||||||
|
#
|
||||||
|
|
||||||
|
# Uncomment the line if you want fastlane to automatically update itself
|
||||||
|
# update_fastlane
|
||||||
|
|
||||||
|
default_platform(:android)
|
||||||
|
|
||||||
|
platform :android do
|
||||||
|
desc "Runs all the tests"
|
||||||
|
lane :test do
|
||||||
|
gradle(task: "test")
|
||||||
|
end
|
||||||
|
|
||||||
|
desc "Submit a new Beta Build to Crashlytics Beta"
|
||||||
|
lane :beta do
|
||||||
|
gradle(task: "clean assembleRelease")
|
||||||
|
crashlytics
|
||||||
|
|
||||||
|
# sh "your_script.sh"
|
||||||
|
# You can also use other beta testing services here
|
||||||
|
end
|
||||||
|
|
||||||
|
desc "Deploy a new version to the Google Play"
|
||||||
|
lane :deploy do
|
||||||
|
gradle(task: "clean assembleRelease")
|
||||||
|
upload_to_play_store
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -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.
|
Erfasst deine Kilometer, ohne dass es jemand anderes tut.
|
||||||
|
|
||||||
Funktionen & Features:
|
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,14 @@
|
|||||||
|
v3.2.3: OpenTracks
|
||||||
|
|
||||||
|
Changes:
|
||||||
|
- Sharing: use Android Sharesheet
|
||||||
|
- Sharing: share multiple tracks as individual files
|
||||||
|
- Use Android ShareSheet
|
||||||
|
- Heart rate sensor (Bluetooth LE): automatic reconnect
|
||||||
|
|
||||||
|
Bugfix:
|
||||||
|
- Heart rate sensor (Bluetooth LE): disconnect properly
|
||||||
|
- Heart rate wasn't always shown while recording
|
||||||
|
|
||||||
|
Developer:
|
||||||
|
- Enabled TravisCI instrumentation tests
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
v3.2.4: OpenTracks
|
||||||
|
|
||||||
|
Bugfix:
|
||||||
|
- Settings activity crashes
|
||||||
|
Removed possibility to change voice/split frequency from the context menu
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
v3.2.5: OpenTracks
|
||||||
|
|
||||||
|
Changes:
|
||||||
|
- Disable activity change
|
||||||
|
- Add permission for Android 10: recording location data
|
||||||
|
|
||||||
|
Bugfix:
|
||||||
|
- Fix reset settings
|
||||||
|
|
||||||
|
Developer:
|
||||||
|
- Preferences
|
||||||
|
- if Settings cannot be loaded reset all preferences
|
||||||
|
- moved access to preferences to PreferencesUtil
|
||||||
|
- moved default of preferences from code to xml
|
||||||
|
- use SummaryProvider
|
||||||
@@ -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,10 @@
|
|||||||
|
v3.2.8: OpenTracks
|
||||||
|
|
||||||
|
Changes:
|
||||||
|
- Chart: zoom via gestures
|
||||||
|
|
||||||
|
Bugfixes:
|
||||||
|
- Export via KMZ did not export picture filenames correctly
|
||||||
|
- Sharing multiple tracks did not include KMZ files
|
||||||
|
- MarkerDetailActivity's UI was not shown
|
||||||
|
- Settings crashed if preference of heart rate was not initialized
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
v3.2.9: OpenTracks
|
||||||
|
|
||||||
|
Changes:
|
||||||
|
- Option to keep screen on while recording
|
||||||
|
- Markers: removed split markers completely
|
||||||
|
- Voice announcement now work without READ_PHONE_STATE permission
|
||||||
|
|
||||||
|
Bugfixes:
|
||||||
|
- Statistics: heart rate was not shown
|
||||||
|
- Statistics: time was briefly reset to 0s
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
v3.2.10: OpenTracks
|
||||||
|
|
||||||
|
Changes:
|
||||||
|
- ChartView is not configurable anymore
|
||||||
|
- After reboot: removed automatic restart of an unfinished recording
|
||||||
|
|
||||||
|
Bugfix:
|
||||||
|
- Speech announcements use MAY_DUCK (again)
|
||||||
|
- ChartView shows markers (again)
|
||||||
|
- Fixed landscape layout of TrackListActivity
|
||||||
|
- Request legacy file API behavior (necessary for Android 10)
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
v3.2.11: OpenTracks
|
||||||
|
|
||||||
|
Bug:
|
||||||
|
- Max speed is identical to avg speed
|
||||||
|
|
||||||
|
Bugfix:
|
||||||
|
- Crash on heart rate sensor selection
|
||||||
|
|
||||||
|
Developer:
|
||||||
|
- Replaced TabHost by TabsLayout
|
||||||
|
- Removed special first waypoint
|
||||||
|
- Removed duplicate translations
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
v3.3.0: OpenTracks
|
||||||
|
|
||||||
|
Breaking changes:
|
||||||
|
- Pictures are now stored in app-private storage (do not show up other picture apps)
|
||||||
|
NOTE: Pictures taking with previous version cannot be shown
|
||||||
|
- Localization for Spanish (Latin America) only works on Android 7.0 or later
|
||||||
|
|
||||||
|
Changes:
|
||||||
|
- Import/Export via Storage Access Framework (avoids READ/WRITE_EXTERNAL_STORAGE permission)
|
||||||
|
|
||||||
|
Developer:
|
||||||
|
- Cleaned internal data structures
|
||||||
|
- Use separate icons/app names for debug version
|
||||||
|
After Width: | Height: | Size: 16 KiB |
|
After Width: | Height: | Size: 52 KiB |
@@ -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
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
OpenTracks est une application de suivi d'activités sportives qui respecte totalement votre vie privée.
|
||||||
|
|
||||||
|
Fonctionnalités :
|
||||||
|
|
||||||
|
* Suivi d'activité : enregistre vos activités sportives et de plein air
|
||||||
|
* Photos et repères : ajout de photos et de repères pendant l'enregistrement de l'activité
|
||||||
|
* Rythme cardiaque : support des capteurs Bluetooth LE
|
||||||
|
* Export : export des traces au format KML ou GPX
|
||||||
|
* Pas d'accès internet requis : Internet n'est pas nécessaire pour le fonctionnement de l'application
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
OpenTracks - Suivi d'activités sportives respectueux de votre vie privée.
|
||||||
|
After Width: | Height: | Size: 125 KiB |
@@ -1,103 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2012 Google Inc.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
|
||||||
* use this file except in compliance with the License. You may obtain a copy of
|
|
||||||
* the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
||||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
||||||
* License for the specific language governing permissions and limitations under
|
|
||||||
* the License.
|
|
||||||
*/
|
|
||||||
package de.dennisguse.opentracks;
|
|
||||||
|
|
||||||
import android.app.ActivityManager;
|
|
||||||
import android.app.ActivityManager.RunningServiceInfo;
|
|
||||||
import android.content.ComponentName;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
|
||||||
|
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
|
||||||
import androidx.test.platform.app.InstrumentationRegistry;
|
|
||||||
|
|
||||||
import org.junit.Assert;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import de.dennisguse.opentracks.services.TrackRecordingService;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests for the BootReceiver.
|
|
||||||
*
|
|
||||||
* @author Youtao Liu
|
|
||||||
*/
|
|
||||||
@RunWith(AndroidJUnit4.class)
|
|
||||||
public class BootReceiverTest {
|
|
||||||
private static final String SERVICE_NAME = "de.dennisguse.opentracks.services.TrackRecordingService";
|
|
||||||
|
|
||||||
private Context context = InstrumentationRegistry.getInstrumentation().getContext();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests the behavior when receive notification which is the phone boot.
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void testOnReceive_startService() {
|
|
||||||
// Make sure no TrackRecordingService
|
|
||||||
Intent stopIntent = new Intent(context, TrackRecordingService.class);
|
|
||||||
context.stopService(stopIntent);
|
|
||||||
Assert.assertFalse(isServiceExisted(context));
|
|
||||||
|
|
||||||
BootReceiver bootReceiver = new BootReceiver();
|
|
||||||
Intent intent = new Intent();
|
|
||||||
intent.setAction(Intent.ACTION_BOOT_COMPLETED);
|
|
||||||
bootReceiver.onReceive(context, intent);
|
|
||||||
// Check if the service is started
|
|
||||||
Assert.assertFalse(isServiceExisted(context));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests the behavior when receive notification which is not the phone boot.
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void testOnReceive_noStartService() {
|
|
||||||
// Make sure no TrackRecordingService
|
|
||||||
Intent stopIntent = new Intent(context, TrackRecordingService.class);
|
|
||||||
context.stopService(stopIntent);
|
|
||||||
Assert.assertFalse(isServiceExisted(context));
|
|
||||||
|
|
||||||
BootReceiver bootReceiver = new BootReceiver();
|
|
||||||
Intent intent = new Intent();
|
|
||||||
intent.setAction(Intent.ACTION_BUG_REPORT);
|
|
||||||
bootReceiver.onReceive(context, intent);
|
|
||||||
|
|
||||||
// Check if the service is not started
|
|
||||||
Assert.assertFalse(isServiceExisted(context));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if a service is started in a context.
|
|
||||||
*
|
|
||||||
* @param context the context for checking a service
|
|
||||||
*/
|
|
||||||
private boolean isServiceExisted(Context context) {
|
|
||||||
ActivityManager activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE);
|
|
||||||
Assert.assertNotNull(activityManager);
|
|
||||||
|
|
||||||
List<ActivityManager.RunningServiceInfo> serviceList = activityManager.getRunningServices(Integer.MAX_VALUE);
|
|
||||||
|
|
||||||
for (int i = 0; i < serviceList.size(); i++) {
|
|
||||||
RunningServiceInfo serviceInfo = serviceList.get(i);
|
|
||||||
ComponentName componentName = serviceInfo.service;
|
|
||||||
if (componentName.getClassName().equals(SERVICE_NAME)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -18,8 +18,8 @@ package de.dennisguse.opentracks;
|
|||||||
|
|
||||||
import android.location.Location;
|
import android.location.Location;
|
||||||
|
|
||||||
import de.dennisguse.opentracks.content.SensorDataSetLocation;
|
import de.dennisguse.opentracks.content.data.Track;
|
||||||
import de.dennisguse.opentracks.content.Track;
|
import de.dennisguse.opentracks.content.data.TrackPoint;
|
||||||
import de.dennisguse.opentracks.content.sensor.SensorDataSet;
|
import de.dennisguse.opentracks.content.sensor.SensorDataSet;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -60,16 +60,16 @@ public class TrackStubUtils {
|
|||||||
*
|
*
|
||||||
* @return a track stub.
|
* @return a track stub.
|
||||||
*/
|
*/
|
||||||
public static SensorDataSetLocation createSensorDataSetLocation() {
|
public static TrackPoint createSensorDataSetLocation() {
|
||||||
return createSensorDataSetLocation(INITIAL_LATITUDE, INITIAL_LONGITUDE, INITIAL_ALTITUDE);
|
return createSensorDataSetLocation(INITIAL_LATITUDE, INITIAL_LONGITUDE, INITIAL_ALTITUDE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a {@link SensorDataSetLocation} stub with specified values.
|
* Creates a {@link TrackPoint} stub with specified values.
|
||||||
*
|
*
|
||||||
* @return a SensorDataSetLocation stub.
|
* @return a SensorDataSetLocation stub.
|
||||||
*/
|
*/
|
||||||
private static SensorDataSetLocation createSensorDataSetLocation(double latitude, double longitude, double altitude) {
|
private static TrackPoint createSensorDataSetLocation(double latitude, double longitude, double altitude) {
|
||||||
// Initial Location
|
// Initial Location
|
||||||
Location loc = new Location(LOCATION_PROVIDER);
|
Location loc = new Location(LOCATION_PROVIDER);
|
||||||
loc.setLatitude(latitude);
|
loc.setLatitude(latitude);
|
||||||
@@ -81,6 +81,6 @@ public class TrackStubUtils {
|
|||||||
loc.setBearing(INITIAL_BEARING);
|
loc.setBearing(INITIAL_BEARING);
|
||||||
SensorDataSet sd = new SensorDataSet(Float.NaN, Float.NaN);
|
SensorDataSet sd = new SensorDataSet(Float.NaN, Float.NaN);
|
||||||
|
|
||||||
return new SensorDataSetLocation(loc, sd);
|
return new TrackPoint(loc, sd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,7 @@
|
|||||||
* License for the specific language governing permissions and limitations under
|
* License for the specific language governing permissions and limitations under
|
||||||
* the License.
|
* the License.
|
||||||
*/
|
*/
|
||||||
package de.dennisguse.opentracks;
|
package de.dennisguse.opentracks.chart;
|
||||||
|
|
||||||
import androidx.test.core.app.ApplicationProvider;
|
import androidx.test.core.app.ApplicationProvider;
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||||
@@ -23,6 +23,8 @@ import org.junit.Before;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
|
import de.dennisguse.opentracks.R;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests {@link ChartValueSeries}.
|
* Tests {@link ChartValueSeries}.
|
||||||
*
|
*
|
||||||
@@ -27,6 +27,9 @@ import org.junit.Before;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import de.dennisguse.opentracks.content.CustomContentProvider.DatabaseHelper;
|
import de.dennisguse.opentracks.content.CustomContentProvider.DatabaseHelper;
|
||||||
|
import de.dennisguse.opentracks.content.data.TrackPointsColumns;
|
||||||
|
import de.dennisguse.opentracks.content.data.TracksColumns;
|
||||||
|
import de.dennisguse.opentracks.content.data.WaypointsColumns;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests {@link CustomContentProvider}.
|
* Tests {@link CustomContentProvider}.
|
||||||
|
|||||||
@@ -35,32 +35,31 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
import de.dennisguse.opentracks.content.ContentProviderUtils.LocationFactory;
|
import de.dennisguse.opentracks.content.data.TestDataUtil;
|
||||||
import de.dennisguse.opentracks.content.ContentProviderUtils.LocationIterator;
|
import de.dennisguse.opentracks.content.data.Track;
|
||||||
import de.dennisguse.opentracks.content.Waypoint.WaypointType;
|
import de.dennisguse.opentracks.content.data.TrackPointsColumns;
|
||||||
|
import de.dennisguse.opentracks.content.data.TracksColumns;
|
||||||
|
import de.dennisguse.opentracks.content.data.Waypoint;
|
||||||
|
import de.dennisguse.opentracks.content.data.WaypointsColumns;
|
||||||
import de.dennisguse.opentracks.stats.TripStatistics;
|
import de.dennisguse.opentracks.stats.TripStatistics;
|
||||||
|
|
||||||
import static org.mockito.Mockito.verify;
|
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A unit test for {@link ContentProviderUtilsImpl}.
|
* A unit test for {@link ContentProviderUtils}.
|
||||||
*
|
*
|
||||||
* @author Bartlomiej Niechwiej
|
* @author Bartlomiej Niechwiej
|
||||||
* @author Youtao Liu
|
* @author Youtao Liu
|
||||||
*/
|
*/
|
||||||
@RunWith(MockitoJUnitRunner.class)
|
@RunWith(MockitoJUnitRunner.class)
|
||||||
public class CustomContentProviderUtilsImplTest {
|
public class CustomContentProviderUtilsTest {
|
||||||
private static final String NAME_PREFIX = "test name";
|
private static final String NAME_PREFIX = "test name";
|
||||||
private static final String MOCK_DESC = "Mock Next Waypoint Desc!";
|
private static final String MOCK_DESC = "Mock Next Waypoint Desc!";
|
||||||
private static final String TEST_DESC = "Test Desc!";
|
private static final String TEST_DESC = "Test Desc!";
|
||||||
private static final String TEST_DESC_NEW = "Test Desc new!";
|
private static final String TEST_DESC_NEW = "Test Desc new!";
|
||||||
private static final double INITIAL_LATITUDE = 37.0;
|
|
||||||
private static final double INITIAL_LONGITUDE = -57.0;
|
|
||||||
private static final double ALTITUDE_INTERVAL = 2.5;
|
|
||||||
|
|
||||||
private Context context = ApplicationProvider.getApplicationContext();
|
private Context context = ApplicationProvider.getApplicationContext();
|
||||||
private ContentProviderUtils providerUtils;
|
private ContentProviderUtils contentProviderUtils;
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
private Cursor cursorMock;
|
private Cursor cursorMock;
|
||||||
@@ -70,13 +69,13 @@ public class CustomContentProviderUtilsImplTest {
|
|||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
providerUtils = ContentProviderUtils.Factory.get(context);
|
contentProviderUtils = new ContentProviderUtils(context);
|
||||||
providerUtils.deleteAllTracks(context);
|
contentProviderUtils.deleteAllTracks(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLocationIterator_noPoints() {
|
public void testLocationIterator_noPoints() {
|
||||||
testIterator(1, 0, 1, false, ContentProviderUtils.DEFAULT_LOCATION_FACTORY);
|
testIterator(1, 0, 1, false, LocationFactory.DEFAULT_LOCATION_FACTORY);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -106,38 +105,38 @@ public class CustomContentProviderUtilsImplTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLocationIterator_noBatchAscending() {
|
public void testLocationIterator_noBatchAscending() {
|
||||||
testIterator(1, 50, 100, false, ContentProviderUtils.DEFAULT_LOCATION_FACTORY);
|
testIterator(1, 50, 100, false, LocationFactory.DEFAULT_LOCATION_FACTORY);
|
||||||
testIterator(2, 50, 50, false, ContentProviderUtils.DEFAULT_LOCATION_FACTORY);
|
testIterator(2, 50, 50, false, LocationFactory.DEFAULT_LOCATION_FACTORY);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLocationIterator_noBatchDescending() {
|
public void testLocationIterator_noBatchDescending() {
|
||||||
testIterator(1, 50, 100, true, ContentProviderUtils.DEFAULT_LOCATION_FACTORY);
|
testIterator(1, 50, 100, true, LocationFactory.DEFAULT_LOCATION_FACTORY);
|
||||||
testIterator(2, 50, 50, true, ContentProviderUtils.DEFAULT_LOCATION_FACTORY);
|
testIterator(2, 50, 50, true, LocationFactory.DEFAULT_LOCATION_FACTORY);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLocationIterator_batchAscending() {
|
public void testLocationIterator_batchAscending() {
|
||||||
testIterator(1, 50, 11, false, ContentProviderUtils.DEFAULT_LOCATION_FACTORY);
|
testIterator(1, 50, 11, false, LocationFactory.DEFAULT_LOCATION_FACTORY);
|
||||||
testIterator(2, 50, 25, false, ContentProviderUtils.DEFAULT_LOCATION_FACTORY);
|
testIterator(2, 50, 25, false, LocationFactory.DEFAULT_LOCATION_FACTORY);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLocationIterator_batchDescending() {
|
public void testLocationIterator_batchDescending() {
|
||||||
testIterator(1, 50, 11, true, ContentProviderUtils.DEFAULT_LOCATION_FACTORY);
|
testIterator(1, 50, 11, true, LocationFactory.DEFAULT_LOCATION_FACTORY);
|
||||||
testIterator(2, 50, 25, true, ContentProviderUtils.DEFAULT_LOCATION_FACTORY);
|
testIterator(2, 50, 25, true, LocationFactory.DEFAULT_LOCATION_FACTORY);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLocationIterator_largeTrack() {
|
public void testLocationIterator_largeTrack() {
|
||||||
testIterator(1, 20000, 2000, false, ContentProviderUtils.DEFAULT_LOCATION_FACTORY);
|
testIterator(1, 20000, 2000, false, LocationFactory.DEFAULT_LOCATION_FACTORY);
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Location> testIterator(long trackId, int numPoints, int batchSize, boolean descending, LocationFactory locationFactory) {
|
private List<Location> testIterator(long trackId, int numPoints, int batchSize, boolean descending, LocationFactory locationFactory) {
|
||||||
long lastPointId = initializeTrack(trackId, numPoints);
|
long lastPointId = initializeTrack(trackId, numPoints);
|
||||||
((ContentProviderUtilsImpl) providerUtils).setDefaultCursorBatchSize(batchSize);
|
((ContentProviderUtils) contentProviderUtils).setDefaultCursorBatchSize(batchSize);
|
||||||
List<Location> locations = new ArrayList<Location>(numPoints);
|
List<Location> locations = new ArrayList<Location>(numPoints);
|
||||||
try (LocationIterator it = providerUtils.getTrackPointLocationIterator(trackId, -1L, descending, locationFactory)) {
|
try (LocationIterator it = contentProviderUtils.getTrackPointLocationIterator(trackId, -1L, descending, locationFactory)) {
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
Location loc = it.next();
|
Location loc = it.next();
|
||||||
Assert.assertNotNull(loc);
|
Assert.assertNotNull(loc);
|
||||||
@@ -156,8 +155,8 @@ public class CustomContentProviderUtilsImplTest {
|
|||||||
track.setId(id);
|
track.setId(id);
|
||||||
track.setName("Test: " + id);
|
track.setName("Test: " + id);
|
||||||
track.setNumberOfPoints(numPoints);
|
track.setNumberOfPoints(numPoints);
|
||||||
providerUtils.insertTrack(track);
|
contentProviderUtils.insertTrack(track);
|
||||||
track = providerUtils.getTrack(id);
|
track = contentProviderUtils.getTrack(id);
|
||||||
Assert.assertNotNull(track);
|
Assert.assertNotNull(track);
|
||||||
|
|
||||||
Location[] locations = new Location[numPoints];
|
Location[] locations = new Location[numPoints];
|
||||||
@@ -169,12 +168,12 @@ public class CustomContentProviderUtilsImplTest {
|
|||||||
loc.setAltitude(i * 2.5);
|
loc.setAltitude(i * 2.5);
|
||||||
locations[i] = loc;
|
locations[i] = loc;
|
||||||
}
|
}
|
||||||
providerUtils.bulkInsertTrackPoint(locations, numPoints, id);
|
contentProviderUtils.bulkInsertTrackPoint(locations, numPoints, id);
|
||||||
|
|
||||||
// Load all inserted locations.
|
// Load all inserted locations.
|
||||||
long lastPointId = -1;
|
long lastPointId = -1;
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
try (LocationIterator it = providerUtils.getTrackPointLocationIterator(id, -1L, false, ContentProviderUtils.DEFAULT_LOCATION_FACTORY)) {
|
try (LocationIterator it = contentProviderUtils.getTrackPointLocationIterator(id, -1L, false, LocationFactory.DEFAULT_LOCATION_FACTORY)) {
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
it.next();
|
it.next();
|
||||||
lastPointId = it.getLocationId();
|
lastPointId = it.getLocationId();
|
||||||
@@ -190,7 +189,7 @@ public class CustomContentProviderUtilsImplTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests the method {@link ContentProviderUtilsImpl#createTrack(Cursor)}.
|
* Tests the method {@link ContentProviderUtils#createTrack(Cursor)}.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testCreateTrack() {
|
public void testCreateTrack() {
|
||||||
@@ -211,23 +210,22 @@ public class CustomContentProviderUtilsImplTest {
|
|||||||
String name = NAME_PREFIX + trackId;
|
String name = NAME_PREFIX + trackId;
|
||||||
when(cursorMock.getString(columnIndex++)).thenReturn(name);
|
when(cursorMock.getString(columnIndex++)).thenReturn(name);
|
||||||
|
|
||||||
Track track = providerUtils.createTrack(cursorMock);
|
Track track = contentProviderUtils.createTrack(cursorMock);
|
||||||
Assert.assertEquals(trackId, track.getId());
|
Assert.assertEquals(trackId, track.getId());
|
||||||
Assert.assertEquals(name, track.getName());
|
Assert.assertEquals(name, track.getName());
|
||||||
verify(cursorMock);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests the method {@link ContentProviderUtilsImpl#deleteAllTracks(Context)}
|
* Tests the method {@link ContentProviderUtils#deleteAllTracks(Context)}
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testDeleteAllTracks() {
|
public void testDeleteAllTracks() {
|
||||||
// Insert track, points and waypoint at first.
|
// Insert track, points and waypoint at first.
|
||||||
long trackId = System.currentTimeMillis();
|
long trackId = System.currentTimeMillis();
|
||||||
Track track = getTrack(trackId, 10);
|
Track track = TestDataUtil.getTrack(trackId, 10);
|
||||||
insertTrackWithLocations(track);
|
insertTrackWithLocations(track);
|
||||||
Waypoint waypoint = new Waypoint();
|
Waypoint waypoint = new Waypoint();
|
||||||
providerUtils.insertWaypoint(waypoint);
|
contentProviderUtils.insertWaypoint(waypoint);
|
||||||
ContentResolver contentResolver = context.getContentResolver();
|
ContentResolver contentResolver = context.getContentResolver();
|
||||||
Cursor tracksCursor = contentResolver.query(TracksColumns.CONTENT_URI, null, null, null, TracksColumns._ID);
|
Cursor tracksCursor = contentResolver.query(TracksColumns.CONTENT_URI, null, null, null, TracksColumns._ID);
|
||||||
Assert.assertEquals(1, tracksCursor.getCount());
|
Assert.assertEquals(1, tracksCursor.getCount());
|
||||||
@@ -236,7 +234,7 @@ public class CustomContentProviderUtilsImplTest {
|
|||||||
Cursor waypointCursor = contentResolver.query(WaypointsColumns.CONTENT_URI, null, null, null, WaypointsColumns._ID);
|
Cursor waypointCursor = contentResolver.query(WaypointsColumns.CONTENT_URI, null, null, null, WaypointsColumns._ID);
|
||||||
Assert.assertEquals(1, waypointCursor.getCount());
|
Assert.assertEquals(1, waypointCursor.getCount());
|
||||||
// Delete all.
|
// Delete all.
|
||||||
providerUtils.deleteAllTracks(context);
|
contentProviderUtils.deleteAllTracks(context);
|
||||||
// Check whether all have been deleted.
|
// Check whether all have been deleted.
|
||||||
tracksCursor = contentResolver.query(TracksColumns.CONTENT_URI, null, null, null, TracksColumns._ID);
|
tracksCursor = contentResolver.query(TracksColumns.CONTENT_URI, null, null, null, TracksColumns._ID);
|
||||||
Assert.assertEquals(0, tracksCursor.getCount());
|
Assert.assertEquals(0, tracksCursor.getCount());
|
||||||
@@ -247,21 +245,21 @@ public class CustomContentProviderUtilsImplTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests the method {@link ContentProviderUtilsImpl#deleteTrack(Context, long)}.
|
* Tests the method {@link ContentProviderUtils#deleteTrack(Context, long)}.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testDeleteTrack() {
|
public void testDeleteTrack() {
|
||||||
// Insert three tracks, points of two tracks and way point of one track.
|
// Insert three tracks, points of two tracks and way point of one track.
|
||||||
long trackId = System.currentTimeMillis();
|
long trackId = System.currentTimeMillis();
|
||||||
Track track = getTrack(trackId, 10);
|
Track track = TestDataUtil.getTrack(trackId, 10);
|
||||||
|
|
||||||
providerUtils.insertTrack(track);
|
contentProviderUtils.insertTrack(track);
|
||||||
insertTrackWithLocations(getTrack(trackId + 1, 10));
|
insertTrackWithLocations(TestDataUtil.getTrack(trackId + 1, 10));
|
||||||
insertTrackWithLocations(getTrack(trackId + 2, 10));
|
insertTrackWithLocations(TestDataUtil.getTrack(trackId + 2, 10));
|
||||||
|
|
||||||
Waypoint waypoint = new Waypoint();
|
Waypoint waypoint = new Waypoint();
|
||||||
waypoint.setTrackId(trackId);
|
waypoint.setTrackId(trackId);
|
||||||
providerUtils.insertWaypoint(waypoint);
|
contentProviderUtils.insertWaypoint(waypoint);
|
||||||
|
|
||||||
ContentResolver contentResolver = context.getContentResolver();
|
ContentResolver contentResolver = context.getContentResolver();
|
||||||
Cursor tracksCursor = contentResolver.query(TracksColumns.CONTENT_URI, null, null, null, TracksColumns._ID);
|
Cursor tracksCursor = contentResolver.query(TracksColumns.CONTENT_URI, null, null, null, TracksColumns._ID);
|
||||||
@@ -271,7 +269,7 @@ public class CustomContentProviderUtilsImplTest {
|
|||||||
Cursor waypointCursor = contentResolver.query(WaypointsColumns.CONTENT_URI, null, null, null, WaypointsColumns._ID);
|
Cursor waypointCursor = contentResolver.query(WaypointsColumns.CONTENT_URI, null, null, null, WaypointsColumns._ID);
|
||||||
Assert.assertEquals(1, waypointCursor.getCount());
|
Assert.assertEquals(1, waypointCursor.getCount());
|
||||||
// Delete one track.
|
// Delete one track.
|
||||||
providerUtils.deleteTrack(context, trackId);
|
contentProviderUtils.deleteTrack(context, trackId);
|
||||||
// Check whether all data of a track has been deleted.
|
// Check whether all data of a track has been deleted.
|
||||||
tracksCursor = contentResolver.query(TracksColumns.CONTENT_URI, null, null, null, TracksColumns._ID);
|
tracksCursor = contentResolver.query(TracksColumns.CONTENT_URI, null, null, null, TracksColumns._ID);
|
||||||
Assert.assertEquals(2, tracksCursor.getCount());
|
Assert.assertEquals(2, tracksCursor.getCount());
|
||||||
@@ -282,63 +280,62 @@ public class CustomContentProviderUtilsImplTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests the method {@link ContentProviderUtilsImpl#getAllTracks()}
|
* Tests the method {@link ContentProviderUtils#getAllTracks()}
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testGetAllTracks() {
|
public void testGetAllTracks() {
|
||||||
int initialTrackNumber = providerUtils.getAllTracks().size();
|
int initialTrackNumber = contentProviderUtils.getAllTracks().size();
|
||||||
long trackId = System.currentTimeMillis();
|
long trackId = System.currentTimeMillis();
|
||||||
providerUtils.insertTrack(getTrack(trackId, 0));
|
contentProviderUtils.insertTrack(TestDataUtil.getTrack(trackId, 0));
|
||||||
List<Track> allTracks = providerUtils.getAllTracks();
|
List<Track> allTracks = contentProviderUtils.getAllTracks();
|
||||||
Assert.assertEquals(initialTrackNumber + 1, allTracks.size());
|
Assert.assertEquals(initialTrackNumber + 1, allTracks.size());
|
||||||
Assert.assertEquals(trackId, allTracks.get(allTracks.size() - 1).getId());
|
Assert.assertEquals(trackId, allTracks.get(allTracks.size() - 1).getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests the method {@link ContentProviderUtilsImpl#getLastTrack()}
|
* Tests the method {@link ContentProviderUtils#getLastTrack()}
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testGetLastTrack() {
|
public void testGetLastTrack() {
|
||||||
long trackId = System.currentTimeMillis();
|
long trackId = System.currentTimeMillis();
|
||||||
providerUtils.insertTrack(getTrack(trackId, 0));
|
contentProviderUtils.insertTrack(TestDataUtil.getTrack(trackId, 0));
|
||||||
Assert.assertEquals(trackId, providerUtils.getLastTrack().getId());
|
Assert.assertEquals(trackId, contentProviderUtils.getLastTrack().getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests the method {@link ContentProviderUtilsImpl#getTrack(long)}
|
* Tests the method {@link ContentProviderUtils#getTrack(long)}
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testGetTrack() {
|
public void testGetTrack() {
|
||||||
long trackId = System.currentTimeMillis();
|
long trackId = System.currentTimeMillis();
|
||||||
providerUtils.insertTrack(getTrack(trackId, 0));
|
contentProviderUtils.insertTrack(TestDataUtil.getTrack(trackId, 0));
|
||||||
Assert.assertNotNull(providerUtils.getTrack(trackId));
|
Assert.assertNotNull(contentProviderUtils.getTrack(trackId));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests the method {@link ContentProviderUtilsImpl#updateTrack(Track)}
|
* Tests the method {@link ContentProviderUtils#updateTrack(Track)}
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testUpdateTrack() {
|
public void testUpdateTrack() {
|
||||||
long trackId = System.currentTimeMillis();
|
long trackId = System.currentTimeMillis();
|
||||||
Track track = getTrack(trackId, 0);
|
Track track = TestDataUtil.getTrack(trackId, 0);
|
||||||
String nameOld = "name1";
|
String nameOld = "name1";
|
||||||
String nameNew = "name2";
|
String nameNew = "name2";
|
||||||
track.setName(nameOld);
|
track.setName(nameOld);
|
||||||
providerUtils.insertTrack(track);
|
contentProviderUtils.insertTrack(track);
|
||||||
Assert.assertEquals(nameOld, providerUtils.getTrack(trackId).getName());
|
Assert.assertEquals(nameOld, contentProviderUtils.getTrack(trackId).getName());
|
||||||
track.setName(nameNew);
|
track.setName(nameNew);
|
||||||
providerUtils.updateTrack(track);
|
contentProviderUtils.updateTrack(track);
|
||||||
Assert.assertEquals(nameNew, providerUtils.getTrack(trackId).getName());
|
Assert.assertEquals(nameNew, contentProviderUtils.getTrack(trackId).getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests the method {@link ContentProviderUtilsImpl#createContentValues(Waypoint)}.
|
* Tests the method {@link ContentProviderUtils#createContentValues(Waypoint)}.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testCreateContentValues_waypoint() {
|
public void testCreateContentValues_waypoint() {
|
||||||
long trackId = System.currentTimeMillis();
|
long trackId = System.currentTimeMillis();
|
||||||
Track track = getTrack(trackId, 10);
|
Track track = TestDataUtil.getTrack(trackId, 10);
|
||||||
providerUtils.insertTrack(track);
|
|
||||||
// Bottom
|
// Bottom
|
||||||
long startTime = 1000L;
|
long startTime = 1000L;
|
||||||
// AverageSpeed
|
// AverageSpeed
|
||||||
@@ -355,12 +352,13 @@ public class CustomContentProviderUtilsImplTest {
|
|||||||
statistics.setMinElevation(1200.0);
|
statistics.setMinElevation(1200.0);
|
||||||
statistics.setMaxGrade(15.0);
|
statistics.setMaxGrade(15.0);
|
||||||
statistics.setMinGrade(minGrade);
|
statistics.setMinGrade(minGrade);
|
||||||
statistics.setBounds(-10000, 20000, 30000, -40000);
|
|
||||||
|
track.setTripStatistics(statistics);
|
||||||
|
contentProviderUtils.insertTrack(track);
|
||||||
|
|
||||||
// Insert at first.
|
// Insert at first.
|
||||||
Waypoint waypoint = new Waypoint();
|
Waypoint waypoint = new Waypoint();
|
||||||
waypoint.setDescription(TEST_DESC);
|
waypoint.setDescription(TEST_DESC);
|
||||||
waypoint.setType(WaypointType.STATISTICS);
|
|
||||||
waypoint.setTripStatistics(statistics);
|
|
||||||
|
|
||||||
Location location = new Location("test");
|
Location location = new Location("test");
|
||||||
location.setLatitude(22);
|
location.setLatitude(22);
|
||||||
@@ -368,9 +366,9 @@ public class CustomContentProviderUtilsImplTest {
|
|||||||
location.setAccuracy((float) 1 / 100.0f);
|
location.setAccuracy((float) 1 / 100.0f);
|
||||||
location.setAltitude(2.5);
|
location.setAltitude(2.5);
|
||||||
waypoint.setLocation(location);
|
waypoint.setLocation(location);
|
||||||
providerUtils.insertWaypoint(waypoint);
|
contentProviderUtils.insertWaypoint(waypoint);
|
||||||
|
|
||||||
ContentProviderUtilsImpl contentProviderUtils = new ContentProviderUtilsImpl(contentResolverMock);
|
ContentProviderUtils contentProviderUtils = new ContentProviderUtils(contentResolverMock);
|
||||||
|
|
||||||
long waypointId = System.currentTimeMillis();
|
long waypointId = System.currentTimeMillis();
|
||||||
waypoint.setId(waypointId);
|
waypoint.setId(waypointId);
|
||||||
@@ -378,12 +376,10 @@ public class CustomContentProviderUtilsImplTest {
|
|||||||
Assert.assertEquals(waypointId, contentValues.get(WaypointsColumns._ID));
|
Assert.assertEquals(waypointId, contentValues.get(WaypointsColumns._ID));
|
||||||
Assert.assertEquals(22 * 1000000, contentValues.get(WaypointsColumns.LONGITUDE));
|
Assert.assertEquals(22 * 1000000, contentValues.get(WaypointsColumns.LONGITUDE));
|
||||||
Assert.assertEquals(TEST_DESC, contentValues.get(WaypointsColumns.DESCRIPTION));
|
Assert.assertEquals(TEST_DESC, contentValues.get(WaypointsColumns.DESCRIPTION));
|
||||||
Assert.assertEquals(startTime, contentValues.get(WaypointsColumns.STARTTIME));
|
|
||||||
Assert.assertEquals(minGrade, contentValues.get(WaypointsColumns.MINGRADE));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests the method {@link ContentProviderUtilsImpl#createWaypoint(Cursor)}.
|
* Tests the method {@link ContentProviderUtils#createWaypoint(Cursor)}.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testCreateWaypoint() {
|
public void testCreateWaypoint() {
|
||||||
@@ -410,59 +406,44 @@ public class CustomContentProviderUtilsImplTest {
|
|||||||
long trackId = 11L;
|
long trackId = 11L;
|
||||||
when(cursorMock.getLong(columnIndex++)).thenReturn(trackId);
|
when(cursorMock.getLong(columnIndex++)).thenReturn(trackId);
|
||||||
|
|
||||||
Waypoint waypoint = providerUtils.createWaypoint(cursorMock);
|
Waypoint waypoint = contentProviderUtils.createWaypoint(cursorMock);
|
||||||
Assert.assertEquals(id, waypoint.getId());
|
Assert.assertEquals(id, waypoint.getId());
|
||||||
Assert.assertEquals(name, waypoint.getName());
|
Assert.assertEquals(name, waypoint.getName());
|
||||||
Assert.assertEquals(trackId, waypoint.getTrackId());
|
Assert.assertEquals(trackId, waypoint.getTrackId());
|
||||||
verify(cursorMock);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests the method
|
* Tests the method
|
||||||
* {@link ContentProviderUtilsImpl#deleteWaypoint(Context, long, DescriptionGenerator)}
|
* {@link ContentProviderUtils#deleteWaypoint(Context, long)}
|
||||||
* when there is only one waypoint in the track.
|
* when there is only one waypoint in the track.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testDeleteWaypoint_onlyOneWayPoint() {
|
public void testDeleteWaypoint_onlyOneWayPoint() {
|
||||||
long trackId = System.currentTimeMillis();
|
long trackId = System.currentTimeMillis();
|
||||||
Track track = getTrack(trackId, 10);
|
Track track = TestDataUtil.getTrack(trackId, 10);
|
||||||
providerUtils.insertTrack(track);
|
contentProviderUtils.insertTrack(track);
|
||||||
|
|
||||||
// Insert at first.
|
// Insert at first.
|
||||||
Waypoint waypoint1 = new Waypoint();
|
Waypoint waypoint1 = new Waypoint();
|
||||||
waypoint1.setDescription(TEST_DESC);
|
waypoint1.setDescription(TEST_DESC);
|
||||||
waypoint1.setTrackId(trackId);
|
waypoint1.setTrackId(trackId);
|
||||||
waypoint1.setType(WaypointType.STATISTICS);
|
contentProviderUtils.insertWaypoint(waypoint1);
|
||||||
providerUtils.insertWaypoint(waypoint1);
|
|
||||||
|
|
||||||
// Delete
|
// Delete
|
||||||
DescriptionGenerator descriptionGenerator = new DescriptionGenerator() {
|
contentProviderUtils.deleteWaypoint(context, 1);
|
||||||
|
|
||||||
@Override
|
Assert.assertNull(contentProviderUtils.getWaypoint(1));
|
||||||
public String generateWaypointDescription(TripStatistics tripStatistics) {
|
|
||||||
return CustomContentProviderUtilsImplTest.MOCK_DESC;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String generateTrackDescription(Track aTrack, boolean html) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
providerUtils.deleteWaypoint(context, 1, descriptionGenerator);
|
|
||||||
|
|
||||||
Assert.assertNull(providerUtils.getWaypoint(1));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests the method
|
* Tests the method
|
||||||
* {@link ContentProviderUtilsImpl#deleteWaypoint(Context, long, DescriptionGenerator)}
|
* {@link ContentProviderUtils#deleteWaypoint(Context, long)}
|
||||||
* when there is more than one waypoint in the track.
|
* when there is more than one waypoint in the track.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testDeleteWaypoint_hasNextWayPoint() {
|
public void testDeleteWaypoint_hasNextWayPoint() {
|
||||||
long trackId = System.currentTimeMillis();
|
long trackId = System.currentTimeMillis();
|
||||||
Track track = getTrack(trackId, 10);
|
Track track = TestDataUtil.getTrack(trackId, 10);
|
||||||
providerUtils.insertTrack(track);
|
|
||||||
|
|
||||||
TripStatistics statistics = new TripStatistics();
|
TripStatistics statistics = new TripStatistics();
|
||||||
statistics.setStartTime(1000L);
|
statistics.setStartTime(1000L);
|
||||||
@@ -476,184 +457,139 @@ public class CustomContentProviderUtilsImplTest {
|
|||||||
statistics.setMinElevation(1200.0);
|
statistics.setMinElevation(1200.0);
|
||||||
statistics.setMaxGrade(15.0);
|
statistics.setMaxGrade(15.0);
|
||||||
statistics.setMinGrade(-25.0);
|
statistics.setMinGrade(-25.0);
|
||||||
statistics.setBounds(-10000, 20000, 30000, -40000);
|
|
||||||
|
track.setTripStatistics(statistics);
|
||||||
|
contentProviderUtils.insertTrack(track);
|
||||||
|
|
||||||
|
|
||||||
// Insert at first.
|
// Insert at first.
|
||||||
Waypoint waypoint1 = new Waypoint();
|
Waypoint waypoint1 = new Waypoint();
|
||||||
waypoint1.setDescription(Long.toString(trackId));
|
waypoint1.setDescription(MOCK_DESC);
|
||||||
waypoint1.setTrackId(trackId);
|
waypoint1.setTrackId(trackId);
|
||||||
waypoint1.setType(WaypointType.STATISTICS);
|
long waypoint1Id = ContentUris.parseId(contentProviderUtils.insertWaypoint(waypoint1));
|
||||||
waypoint1.setTripStatistics(statistics);
|
|
||||||
long waypoint1Id = ContentUris.parseId(providerUtils.insertWaypoint(waypoint1));
|
|
||||||
|
|
||||||
Waypoint waypoint2 = new Waypoint();
|
Waypoint waypoint2 = new Waypoint();
|
||||||
waypoint2.setDescription(Long.toString(trackId));
|
waypoint2.setDescription(MOCK_DESC);
|
||||||
waypoint2.setTrackId(trackId);
|
waypoint2.setTrackId(trackId);
|
||||||
waypoint2.setType(WaypointType.STATISTICS);
|
long waypoint2Id = ContentUris.parseId(contentProviderUtils.insertWaypoint(waypoint2));
|
||||||
waypoint2.setTripStatistics(statistics);
|
|
||||||
long waypoint2Id = ContentUris.parseId(providerUtils.insertWaypoint(waypoint2));
|
|
||||||
|
|
||||||
|
|
||||||
// Delete
|
// Delete
|
||||||
DescriptionGenerator descriptionGenerator = new DescriptionGenerator() {
|
Assert.assertNotNull(contentProviderUtils.getWaypoint(waypoint1Id));
|
||||||
@Override
|
contentProviderUtils.deleteWaypoint(context, waypoint1Id);
|
||||||
public String generateWaypointDescription(TripStatistics tripStatistics) {
|
Assert.assertNull(contentProviderUtils.getWaypoint(waypoint1Id));
|
||||||
return CustomContentProviderUtilsImplTest.MOCK_DESC;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
Assert.assertEquals(MOCK_DESC, contentProviderUtils.getWaypoint(waypoint2Id).getDescription());
|
||||||
public String generateTrackDescription(Track aTrack, boolean html) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
Assert.assertNotNull(providerUtils.getWaypoint(waypoint1Id));
|
|
||||||
providerUtils.deleteWaypoint(context, waypoint1Id, descriptionGenerator);
|
|
||||||
Assert.assertNull(providerUtils.getWaypoint(waypoint1Id));
|
|
||||||
|
|
||||||
Assert.assertEquals(CustomContentProviderUtilsImplTest.MOCK_DESC, providerUtils.getWaypoint(waypoint2Id)
|
|
||||||
.getDescription());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests the method {@link ContentProviderUtilsImpl#getFirstWaypointId(long)}.
|
* Tests the method {@link ContentProviderUtils#getNextWaypointNumber(long)}.
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void testGetFirstWaypointId() {
|
|
||||||
long trackId = System.currentTimeMillis();
|
|
||||||
Track track = getTrack(trackId, 10);
|
|
||||||
providerUtils.insertTrack(track);
|
|
||||||
|
|
||||||
Waypoint waypoint1 = new Waypoint();
|
|
||||||
waypoint1.setTrackId(trackId);
|
|
||||||
long waypoint1id = ContentUris.parseId(providerUtils.insertWaypoint(waypoint1));
|
|
||||||
|
|
||||||
Waypoint waypoint2 = new Waypoint();
|
|
||||||
waypoint2.setTrackId(trackId);
|
|
||||||
long waypoint2id = ContentUris.parseId(providerUtils.insertWaypoint(waypoint2));
|
|
||||||
|
|
||||||
Assert.assertEquals(-1L, providerUtils.getFirstWaypointId(-1));
|
|
||||||
Assert.assertEquals(waypoint1id, providerUtils.getFirstWaypointId(trackId));
|
|
||||||
Assert.assertEquals(waypoint2id, providerUtils.getLastWaypoint(trackId, WaypointType.WAYPOINT).getId());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests the method {@link ContentProviderUtilsImpl#getNextWaypointNumber(long, WaypointType)}.
|
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testGetNextWaypointNumber() {
|
public void testGetNextWaypointNumber() {
|
||||||
long trackId = System.currentTimeMillis();
|
long trackId = System.currentTimeMillis();
|
||||||
Track track = getTrack(trackId, 10);
|
Track track = TestDataUtil.getTrack(trackId, 10);
|
||||||
providerUtils.insertTrack(track);
|
contentProviderUtils.insertTrack(track);
|
||||||
|
|
||||||
Waypoint waypoint1 = new Waypoint();
|
Waypoint waypoint1 = new Waypoint();
|
||||||
waypoint1.setType(WaypointType.STATISTICS);
|
|
||||||
waypoint1.setTrackId(trackId);
|
waypoint1.setTrackId(trackId);
|
||||||
Waypoint waypoint2 = new Waypoint();
|
Waypoint waypoint2 = new Waypoint();
|
||||||
waypoint2.setType(WaypointType.WAYPOINT);
|
|
||||||
waypoint2.setTrackId(trackId);
|
waypoint2.setTrackId(trackId);
|
||||||
Waypoint waypoint3 = new Waypoint();
|
Waypoint waypoint3 = new Waypoint();
|
||||||
waypoint3.setType(WaypointType.STATISTICS);
|
|
||||||
waypoint3.setTrackId(trackId);
|
waypoint3.setTrackId(trackId);
|
||||||
Waypoint waypoint4 = new Waypoint();
|
Waypoint waypoint4 = new Waypoint();
|
||||||
waypoint4.setType(WaypointType.WAYPOINT);
|
|
||||||
waypoint4.setTrackId(trackId);
|
waypoint4.setTrackId(trackId);
|
||||||
providerUtils.insertWaypoint(waypoint1);
|
contentProviderUtils.insertWaypoint(waypoint1);
|
||||||
providerUtils.insertWaypoint(waypoint2);
|
contentProviderUtils.insertWaypoint(waypoint2);
|
||||||
providerUtils.insertWaypoint(waypoint3);
|
contentProviderUtils.insertWaypoint(waypoint3);
|
||||||
providerUtils.insertWaypoint(waypoint4);
|
contentProviderUtils.insertWaypoint(waypoint4);
|
||||||
|
|
||||||
Assert.assertEquals(2, providerUtils.getNextWaypointNumber(trackId, WaypointType.STATISTICS));
|
Assert.assertEquals(4, contentProviderUtils.getNextWaypointNumber(trackId));
|
||||||
Assert.assertEquals(3, providerUtils.getNextWaypointNumber(trackId, WaypointType.WAYPOINT));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests the method
|
* Tests the method
|
||||||
* {@link ContentProviderUtils#getLastWaypoint(long, WaypointType)}.
|
* {@link ContentProviderUtils#getLastWaypoint(long)}.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testGetLastStatisticsWaypoint() {
|
public void testGetLastWaypoint() {
|
||||||
long trackId = System.currentTimeMillis();
|
long trackId = System.currentTimeMillis();
|
||||||
Track track = getTrack(trackId, 10);
|
Track track = TestDataUtil.getTrack(trackId, 10);
|
||||||
providerUtils.insertTrack(track);
|
contentProviderUtils.insertTrack(track);
|
||||||
|
|
||||||
Waypoint waypoint1 = new Waypoint();
|
Waypoint waypoint1 = new Waypoint();
|
||||||
waypoint1.setTrackId(trackId);
|
waypoint1.setTrackId(trackId);
|
||||||
waypoint1.setType(WaypointType.STATISTICS);
|
|
||||||
waypoint1.setDescription("Desc1");
|
waypoint1.setDescription("Desc1");
|
||||||
Waypoint waypoint2 = new Waypoint();
|
Waypoint waypoint2 = new Waypoint();
|
||||||
waypoint2.setTrackId(trackId);
|
waypoint2.setTrackId(trackId);
|
||||||
waypoint2.setType(WaypointType.STATISTICS);
|
|
||||||
waypoint2.setDescription("Desc2");
|
waypoint2.setDescription("Desc2");
|
||||||
Waypoint waypoint3 = new Waypoint();
|
Waypoint waypoint3 = new Waypoint();
|
||||||
waypoint3.setTrackId(trackId);
|
waypoint3.setTrackId(trackId);
|
||||||
waypoint3.setType(WaypointType.WAYPOINT);
|
|
||||||
waypoint3.setDescription("Desc3");
|
waypoint3.setDescription("Desc3");
|
||||||
providerUtils.insertWaypoint(waypoint1);
|
contentProviderUtils.insertWaypoint(waypoint1);
|
||||||
providerUtils.insertWaypoint(waypoint2);
|
contentProviderUtils.insertWaypoint(waypoint2);
|
||||||
providerUtils.insertWaypoint(waypoint3);
|
contentProviderUtils.insertWaypoint(waypoint3);
|
||||||
|
|
||||||
Assert.assertEquals("Desc2", providerUtils.getLastWaypoint(trackId, WaypointType.STATISTICS).getDescription());
|
Assert.assertEquals("Desc3", contentProviderUtils.getLastWaypoint(trackId).getDescription());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests the method {@link ContentProviderUtilsImpl#insertWaypoint(Waypoint)} and
|
* Tests the method {@link ContentProviderUtils#insertWaypoint(Waypoint)} and
|
||||||
* {@link ContentProviderUtilsImpl#getWaypoint(long)}.
|
* {@link ContentProviderUtils#getWaypoint(long)}.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testInsertAndGetWaypoint() {
|
public void testInsertAndGetWaypoint() {
|
||||||
long trackId = System.currentTimeMillis();
|
long trackId = System.currentTimeMillis();
|
||||||
Track track = getTrack(trackId, 10);
|
Track track = TestDataUtil.getTrack(trackId, 10);
|
||||||
providerUtils.insertTrack(track);
|
contentProviderUtils.insertTrack(track);
|
||||||
|
|
||||||
Waypoint waypoint = new Waypoint();
|
Waypoint waypoint = new Waypoint();
|
||||||
waypoint.setDescription(TEST_DESC);
|
waypoint.setDescription(TEST_DESC);
|
||||||
waypoint.setTrackId(trackId);
|
waypoint.setTrackId(trackId);
|
||||||
long waypointId = ContentUris.parseId(providerUtils.insertWaypoint(waypoint));
|
long waypointId = ContentUris.parseId(contentProviderUtils.insertWaypoint(waypoint));
|
||||||
|
|
||||||
Assert.assertEquals(TEST_DESC, providerUtils.getWaypoint(waypointId).getDescription());
|
Assert.assertEquals(TEST_DESC, contentProviderUtils.getWaypoint(waypointId).getDescription());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests the method {@link ContentProviderUtilsImpl#updateWaypoint(Waypoint)}.
|
* Tests the method {@link ContentProviderUtils#updateWaypoint(Waypoint)}.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testUpdateWaypoint() {
|
public void testUpdateWaypoint() {
|
||||||
long trackId = System.currentTimeMillis();
|
long trackId = System.currentTimeMillis();
|
||||||
Track track = getTrack(trackId, 10);
|
Track track = TestDataUtil.getTrack(trackId, 10);
|
||||||
providerUtils.insertTrack(track);
|
contentProviderUtils.insertTrack(track);
|
||||||
// Insert at first.
|
// Insert at first.
|
||||||
Waypoint waypoint = new Waypoint();
|
Waypoint waypoint = new Waypoint();
|
||||||
waypoint.setDescription(TEST_DESC);
|
waypoint.setDescription(TEST_DESC);
|
||||||
waypoint.setTrackId(trackId);
|
waypoint.setTrackId(trackId);
|
||||||
long waypointId = ContentUris.parseId(providerUtils.insertWaypoint(waypoint));
|
long waypointId = ContentUris.parseId(contentProviderUtils.insertWaypoint(waypoint));
|
||||||
|
|
||||||
// Update
|
// Update
|
||||||
waypoint = providerUtils.getWaypoint(waypointId);
|
waypoint = contentProviderUtils.getWaypoint(waypointId);
|
||||||
waypoint.setDescription(TEST_DESC_NEW);
|
waypoint.setDescription(TEST_DESC_NEW);
|
||||||
providerUtils.updateWaypoint(waypoint);
|
contentProviderUtils.updateWaypoint(waypoint);
|
||||||
|
|
||||||
Assert.assertEquals(TEST_DESC_NEW, providerUtils.getWaypoint(waypointId).getDescription());
|
Assert.assertEquals(TEST_DESC_NEW, contentProviderUtils.getWaypoint(waypointId).getDescription());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests the method {@link ContentProviderUtilsImpl#bulkInsertTrackPoint(Location[], int, long)}.
|
* Tests the method {@link ContentProviderUtils#bulkInsertTrackPoint(Location[], int, long)}.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testBulkInsertTrackPoint() {
|
public void testBulkInsertTrackPoint() {
|
||||||
// Insert track, point at first.
|
// Insert track, point at first.
|
||||||
long trackId = System.currentTimeMillis();
|
long trackId = System.currentTimeMillis();
|
||||||
Track track = getTrack(trackId, 10);
|
Track track = TestDataUtil.getTrack(trackId, 10);
|
||||||
insertTrackWithLocations(track);
|
insertTrackWithLocations(track);
|
||||||
|
|
||||||
providerUtils.bulkInsertTrackPoint(track.getLocations().toArray(new Location[0]), -1, trackId);
|
contentProviderUtils.bulkInsertTrackPoint(track.getLocations().toArray(new Location[0]), -1, trackId);
|
||||||
Assert.assertEquals(20, providerUtils.getTrackPointCursor(trackId, -1L, 1000, false).getCount());
|
Assert.assertEquals(20, contentProviderUtils.getTrackPointCursor(trackId, -1L, 1000, false).getCount());
|
||||||
providerUtils.bulkInsertTrackPoint(track.getLocations().toArray(new Location[0]), 8, trackId);
|
contentProviderUtils.bulkInsertTrackPoint(track.getLocations().toArray(new Location[0]), 8, trackId);
|
||||||
Assert.assertEquals(28, providerUtils.getTrackPointCursor(trackId, -1L, 1000, false).getCount());
|
Assert.assertEquals(28, contentProviderUtils.getTrackPointCursor(trackId, -1L, 1000, false).getCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests the method {@link ContentProviderUtilsImpl#createTrackPoint(Cursor)}.
|
* Tests the method {@link ContentProviderUtils#createTrackPoint(Cursor)}.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testCreateTrackPoint() {
|
public void testCreateTrackPoint() {
|
||||||
@@ -704,125 +640,98 @@ public class CustomContentProviderUtilsImplTest {
|
|||||||
byte[] sensor = "Sensor state".getBytes();
|
byte[] sensor = "Sensor state".getBytes();
|
||||||
when(cursorMock.getBlob(index++)).thenReturn(sensor);
|
when(cursorMock.getBlob(index++)).thenReturn(sensor);
|
||||||
|
|
||||||
Location location = providerUtils.createTrackPoint(cursorMock);
|
Location location = contentProviderUtils.createTrackPoint(cursorMock);
|
||||||
Assert.assertEquals((double) longitude, location.getLongitude(), 0.01);
|
Assert.assertEquals((double) longitude, location.getLongitude(), 0.01);
|
||||||
Assert.assertEquals((double) latitude, location.getLatitude(), 0.01);
|
Assert.assertEquals((double) latitude, location.getLatitude(), 0.01);
|
||||||
Assert.assertEquals(time, location.getTime(), 0.01);
|
Assert.assertEquals(time, location.getTime(), 0.01);
|
||||||
Assert.assertEquals(speed, location.getSpeed(), 0.01);
|
Assert.assertEquals(speed, location.getSpeed(), 0.01);
|
||||||
verify(cursorMock);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests the method
|
* Tests the method
|
||||||
* {@link ContentProviderUtilsImpl#insertTrackPoint(Location, long)}.
|
* {@link ContentProviderUtils#insertTrackPoint(Location, long)}.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testInsertTrackPoint() {
|
public void testInsertTrackPoint() {
|
||||||
// Insert track, point at first.
|
// Insert track, point at first.
|
||||||
long trackId = System.currentTimeMillis();
|
long trackId = System.currentTimeMillis();
|
||||||
Track track = getTrack(trackId, 10);
|
Track track = TestDataUtil.getTrack(trackId, 10);
|
||||||
insertTrackWithLocations(track);
|
insertTrackWithLocations(track);
|
||||||
|
|
||||||
providerUtils.insertTrackPoint(createLocation(22), trackId);
|
contentProviderUtils.insertTrackPoint(TestDataUtil.createLocation(22), trackId);
|
||||||
Assert.assertEquals(11, providerUtils.getTrackPointCursor(trackId, -1L, 1000, false).getCount());
|
Assert.assertEquals(11, contentProviderUtils.getTrackPointCursor(trackId, -1L, 1000, false).getCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests the method {@link ContentProviderUtilsImpl#getFirstTrackPointId(long)}.
|
* Tests the method {@link ContentProviderUtils#getLastValidTrackPoint(long)}.
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void testGetFirstTrackPointId() {
|
|
||||||
// Insert track, point at first.
|
|
||||||
long trackId = System.currentTimeMillis();
|
|
||||||
Track track = getTrack(trackId, 10);
|
|
||||||
insertTrackWithLocations(track);
|
|
||||||
|
|
||||||
Assert.assertNotEquals(-1L, providerUtils.getFirstTrackPointId(trackId));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests the method {@link ContentProviderUtilsImpl#getLastTrackPointId(long)}.
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void testGetLastTrackPointId() {
|
|
||||||
// Insert track, point at first.
|
|
||||||
long trackId = System.currentTimeMillis();
|
|
||||||
Track track = getTrack(trackId, 10);
|
|
||||||
insertTrackWithLocations(track);
|
|
||||||
|
|
||||||
Assert.assertTrue(providerUtils.getFirstTrackPointId(trackId) < providerUtils.getLastTrackPointId(trackId));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests the method {@link ContentProviderUtilsImpl#getLastValidTrackPoint(long)}.
|
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testGetLastValidTrackPoint() {
|
public void testGetLastValidTrackPoint() {
|
||||||
// Insert track, points at first.
|
// Insert track, points at first.
|
||||||
long trackId = System.currentTimeMillis();
|
long trackId = System.currentTimeMillis();
|
||||||
Track track = getTrack(trackId, 10);
|
Track track = TestDataUtil.getTrack(trackId, 10);
|
||||||
insertTrackWithLocations(track);
|
insertTrackWithLocations(track);
|
||||||
|
|
||||||
Location lastLocation = providerUtils.getLastValidTrackPoint(trackId);
|
Location lastLocation = contentProviderUtils.getLastValidTrackPoint(trackId);
|
||||||
checkLocation(9, lastLocation);
|
checkLocation(9, lastLocation);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests the method {@link ContentProviderUtilsImpl#getTrackPointCursor(long, long, int, boolean)} in descending.
|
* Tests the method {@link ContentProviderUtils#getTrackPointCursor(long, long, int, boolean)} in descending.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testGetTrackPointCursor_desc() {
|
public void testGetTrackPointCursor_desc() {
|
||||||
// Insert track, points at first.
|
// Insert track, points at first.
|
||||||
long trackId = System.currentTimeMillis();
|
long trackId = System.currentTimeMillis();
|
||||||
Track track = getTrack(trackId, 10);
|
Track track = TestDataUtil.getTrack(trackId, 10);
|
||||||
providerUtils.insertTrack(track);
|
contentProviderUtils.insertTrack(track);
|
||||||
|
|
||||||
long[] trackpointIds = new long[track.getNumberOfPoints()];
|
long[] trackpointIds = new long[track.getNumberOfPoints()];
|
||||||
for (int i = 0; i < trackpointIds.length; i++) {
|
for (int i = 0; i < trackpointIds.length; i++) {
|
||||||
trackpointIds[i] = ContentUris.parseId(providerUtils.insertTrackPoint(track.getLocations().get(i), track.getId()));
|
trackpointIds[i] = ContentUris.parseId(contentProviderUtils.insertTrackPoint(track.getLocations().get(i), track.getId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
Cursor cursor = providerUtils.getTrackPointCursor(trackId, trackpointIds[1], 5, true);
|
Cursor cursor = contentProviderUtils.getTrackPointCursor(trackId, trackpointIds[1], 5, true);
|
||||||
Assert.assertEquals(2, cursor.getCount());
|
Assert.assertEquals(2, cursor.getCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests the method {@link ContentProviderUtilsImpl#getTrackPointCursor(long, long, int, boolean)} in ascending.
|
* Tests the method {@link ContentProviderUtils#getTrackPointCursor(long, long, int, boolean)} in ascending.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testGetTrackPointCursor_asc() {
|
public void testGetTrackPointCursor_asc() {
|
||||||
// Insert track, points at first.
|
// Insert track, points at first.
|
||||||
long trackId = System.currentTimeMillis();
|
long trackId = System.currentTimeMillis();
|
||||||
Track track = getTrack(trackId, 10);
|
Track track = TestDataUtil.getTrack(trackId, 10);
|
||||||
providerUtils.insertTrack(track);
|
contentProviderUtils.insertTrack(track);
|
||||||
|
|
||||||
long[] trackpointIds = new long[track.getNumberOfPoints()];
|
long[] trackpointIds = new long[track.getNumberOfPoints()];
|
||||||
for (int i = 0; i < trackpointIds.length; i++) {
|
for (int i = 0; i < trackpointIds.length; i++) {
|
||||||
trackpointIds[i] = ContentUris.parseId(providerUtils.insertTrackPoint(track.getLocations().get(i), track.getId()));
|
trackpointIds[i] = ContentUris.parseId(contentProviderUtils.insertTrackPoint(track.getLocations().get(i), track.getId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
Cursor cursor = providerUtils.getTrackPointCursor(trackId, trackpointIds[8], 5, false);
|
Cursor cursor = contentProviderUtils.getTrackPointCursor(trackId, trackpointIds[8], 5, false);
|
||||||
Assert.assertEquals(2, cursor.getCount());
|
Assert.assertEquals(2, cursor.getCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests the method {@link ContentProviderUtilsImpl#getTrackPointLocationIterator(long, long, boolean, LocationFactory)} in descending.
|
* Tests the method {@link ContentProviderUtils#getTrackPointLocationIterator(long, long, boolean, LocationFactory)} in descending.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testGetTrackPointLocationIterator_desc() {
|
public void testGetTrackPointLocationIterator_desc() {
|
||||||
// Insert track, points at first.
|
// Insert track, points at first.
|
||||||
long trackId = System.currentTimeMillis();
|
long trackId = System.currentTimeMillis();
|
||||||
Track track = getTrack(trackId, 10);
|
Track track = TestDataUtil.getTrack(trackId, 10);
|
||||||
providerUtils.insertTrack(track);
|
contentProviderUtils.insertTrack(track);
|
||||||
|
|
||||||
long[] trackpointIds = new long[track.getNumberOfPoints()];
|
long[] trackpointIds = new long[track.getNumberOfPoints()];
|
||||||
for (int i = 0; i < trackpointIds.length; i++) {
|
for (int i = 0; i < trackpointIds.length; i++) {
|
||||||
trackpointIds[i] = ContentUris.parseId(providerUtils.insertTrackPoint(track.getLocations().get(i), track.getId()));
|
trackpointIds[i] = ContentUris.parseId(contentProviderUtils.insertTrackPoint(track.getLocations().get(i), track.getId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
long startTrackPointId = trackpointIds[9];
|
long startTrackPointId = trackpointIds[9];
|
||||||
|
|
||||||
LocationIterator locationIterator = providerUtils.getTrackPointLocationIterator(trackId, startTrackPointId, true, ContentProviderUtils.DEFAULT_LOCATION_FACTORY);
|
LocationIterator locationIterator = contentProviderUtils.getTrackPointLocationIterator(trackId, startTrackPointId, true, LocationFactory.DEFAULT_LOCATION_FACTORY);
|
||||||
for (int i = 0; i < trackpointIds.length; i++) {
|
for (int i = 0; i < trackpointIds.length; i++) {
|
||||||
Assert.assertTrue(locationIterator.hasNext());
|
Assert.assertTrue(locationIterator.hasNext());
|
||||||
Location location = locationIterator.next();
|
Location location = locationIterator.next();
|
||||||
@@ -833,23 +742,23 @@ public class CustomContentProviderUtilsImplTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests the method {@link ContentProviderUtilsImpl#getTrackPointLocationIterator(long, long, boolean, LocationFactory)} in ascending.
|
* Tests the method {@link ContentProviderUtils#getTrackPointLocationIterator(long, long, boolean, LocationFactory)} in ascending.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testGetTrackPointLocationIterator_asc() {
|
public void testGetTrackPointLocationIterator_asc() {
|
||||||
// Insert track, point at first.
|
// Insert track, point at first.
|
||||||
long trackId = System.currentTimeMillis();
|
long trackId = System.currentTimeMillis();
|
||||||
Track track = getTrack(trackId, 10);
|
Track track = TestDataUtil.getTrack(trackId, 10);
|
||||||
providerUtils.insertTrack(track);
|
contentProviderUtils.insertTrack(track);
|
||||||
|
|
||||||
long[] trackpointIds = new long[track.getNumberOfPoints()];
|
long[] trackpointIds = new long[track.getNumberOfPoints()];
|
||||||
for (int i = 0; i < trackpointIds.length; i++) {
|
for (int i = 0; i < trackpointIds.length; i++) {
|
||||||
trackpointIds[i] = ContentUris.parseId(providerUtils.insertTrackPoint(track.getLocations().get(i), track.getId()));
|
trackpointIds[i] = ContentUris.parseId(contentProviderUtils.insertTrackPoint(track.getLocations().get(i), track.getId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
long startTrackPointId = trackpointIds[0];
|
long startTrackPointId = trackpointIds[0];
|
||||||
|
|
||||||
LocationIterator locationIterator = providerUtils.getTrackPointLocationIterator(trackId, startTrackPointId, false, ContentProviderUtils.DEFAULT_LOCATION_FACTORY);
|
LocationIterator locationIterator = contentProviderUtils.getTrackPointLocationIterator(trackId, startTrackPointId, false, LocationFactory.DEFAULT_LOCATION_FACTORY);
|
||||||
for (int i = 0; i < trackpointIds.length; i++) {
|
for (int i = 0; i < trackpointIds.length; i++) {
|
||||||
Assert.assertTrue(locationIterator.hasNext());
|
Assert.assertTrue(locationIterator.hasNext());
|
||||||
Location location = locationIterator.next();
|
Location location = locationIterator.next();
|
||||||
@@ -860,50 +769,17 @@ public class CustomContentProviderUtilsImplTest {
|
|||||||
Assert.assertFalse(locationIterator.hasNext());
|
Assert.assertFalse(locationIterator.hasNext());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Simulates a track which is used for testing.
|
|
||||||
*
|
|
||||||
* @param id the id of the track
|
|
||||||
* @param numPoints the location number in the track
|
|
||||||
* @return the simulated track
|
|
||||||
*/
|
|
||||||
private Track getTrack(long id, int numPoints) {
|
|
||||||
Track track = new Track();
|
|
||||||
track.setId(id);
|
|
||||||
track.setName("Test: " + id);
|
|
||||||
track.setNumberOfPoints(numPoints);
|
|
||||||
for (int i = 0; i < numPoints; i++) {
|
|
||||||
track.addLocation(createLocation(i));
|
|
||||||
}
|
|
||||||
return track;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a location.
|
|
||||||
*
|
|
||||||
* @param i the index to set the value of location.
|
|
||||||
* @return created location
|
|
||||||
*/
|
|
||||||
private Location createLocation(int i) {
|
|
||||||
Location loc = new Location("test");
|
|
||||||
loc.setLatitude(INITIAL_LATITUDE + (double) i / 10000.0);
|
|
||||||
loc.setLongitude(INITIAL_LONGITUDE - (double) i / 10000.0);
|
|
||||||
loc.setAccuracy((float) i / 100.0f);
|
|
||||||
loc.setAltitude(i * ALTITUDE_INTERVAL);
|
|
||||||
return loc;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks the value of a location.
|
* Checks the value of a location.
|
||||||
*
|
*
|
||||||
* @param i the index of this location which created in the method {@link CustomContentProviderUtilsImplTest#getTrack(long, int)}
|
* @param i the index of this location which created in the method {@link TestDataUtil#getTrack(long, int)}
|
||||||
* @param location the location to be checked
|
* @param location the location to be checked
|
||||||
*/
|
*/
|
||||||
private void checkLocation(int i, Location location) {
|
private void checkLocation(int i, Location location) {
|
||||||
Assert.assertEquals(INITIAL_LATITUDE + (double) i / 10000.0, location.getLatitude(), 0.01);
|
Assert.assertEquals(TestDataUtil.INITIAL_LATITUDE + (double) i / 10000.0, location.getLatitude(), 0.01);
|
||||||
Assert.assertEquals(INITIAL_LONGITUDE - (double) i / 10000.0, location.getLongitude(), 0.01);
|
Assert.assertEquals(TestDataUtil.INITIAL_LONGITUDE - (double) i / 10000.0, location.getLongitude(), 0.01);
|
||||||
Assert.assertEquals((float) i / 100.0f, location.getAccuracy(), 0.01);
|
Assert.assertEquals((float) i / 100.0f, location.getAccuracy(), 0.01);
|
||||||
Assert.assertEquals(i * ALTITUDE_INTERVAL, location.getAltitude(), 0.01);
|
Assert.assertEquals(i * TestDataUtil.ALTITUDE_INTERVAL, location.getAltitude(), 0.01);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -912,7 +788,7 @@ public class CustomContentProviderUtilsImplTest {
|
|||||||
* @param track track to be inserted
|
* @param track track to be inserted
|
||||||
*/
|
*/
|
||||||
private void insertTrackWithLocations(Track track) {
|
private void insertTrackWithLocations(Track track) {
|
||||||
providerUtils.insertTrack(track);
|
contentProviderUtils.insertTrack(track);
|
||||||
providerUtils.bulkInsertTrackPoint(track.getLocations().toArray(new Location[0]), track.getLocations().size(), track.getId());
|
contentProviderUtils.bulkInsertTrackPoint(track.getLocations().toArray(new Location[0]), track.getLocations().size(), track.getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -27,29 +27,30 @@ import org.junit.Test;
|
|||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
import de.dennisguse.opentracks.R;
|
import de.dennisguse.opentracks.R;
|
||||||
|
import de.dennisguse.opentracks.content.data.Track;
|
||||||
import de.dennisguse.opentracks.stats.TripStatistics;
|
import de.dennisguse.opentracks.stats.TripStatistics;
|
||||||
import de.dennisguse.opentracks.util.StringUtils;
|
import de.dennisguse.opentracks.util.StringUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for {@link DescriptionGeneratorImpl}.
|
* Tests for {@link DescriptionGenerator}.
|
||||||
*
|
*
|
||||||
* @author Jimmy Shih
|
* @author Jimmy Shih
|
||||||
*/
|
*/
|
||||||
@RunWith(AndroidJUnit4.class)
|
@RunWith(AndroidJUnit4.class)
|
||||||
public class DescriptionGeneratorImplTest {
|
public class DescriptionGeneratorTest {
|
||||||
|
|
||||||
private static final long START_TIME = 1288721514000L;
|
private static final long START_TIME = 1288721514000L;
|
||||||
private DescriptionGeneratorImpl descriptionGenerator;
|
private DescriptionGenerator descriptionGenerator;
|
||||||
|
|
||||||
private Context context = ApplicationProvider.getApplicationContext();
|
private Context context = ApplicationProvider.getApplicationContext();
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
descriptionGenerator = new DescriptionGeneratorImpl(ApplicationProvider.getApplicationContext());
|
descriptionGenerator = new DescriptionGenerator(ApplicationProvider.getApplicationContext());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests {@link DescriptionGeneratorImpl#generateTrackDescription(Track, boolean)}.
|
* Tests {@link DescriptionGenerator#generateTrackDescription(Track, boolean)}.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testGenerateTrackDescription() {
|
public void testGenerateTrackDescription() {
|
||||||
@@ -68,7 +69,7 @@ public class DescriptionGeneratorImplTest {
|
|||||||
track.setTripStatistics(stats);
|
track.setTripStatistics(stats);
|
||||||
track.setCategory("hiking");
|
track.setCategory("hiking");
|
||||||
String expected = //"Created by"
|
String expected = //"Created by"
|
||||||
"<a href='https://github.com/dennisguse/opentracks'>OpenTracks</a><p>"
|
"<a href='https://github.com/OpenTracksApp/OpenTracks'>OpenTracks</a><p>"
|
||||||
+ "Name: -<br>"
|
+ "Name: -<br>"
|
||||||
+ "Activity type: hiking<br>"
|
+ "Activity type: hiking<br>"
|
||||||
+ "Description: -<br>"
|
+ "Description: -<br>"
|
||||||
@@ -91,44 +92,9 @@ public class DescriptionGeneratorImplTest {
|
|||||||
Assert.assertEquals(expected, descriptionGenerator.generateTrackDescription(track, true));
|
Assert.assertEquals(expected, descriptionGenerator.generateTrackDescription(track, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests {@link DescriptionGeneratorImpl#generateWaypointDescription(TripStatistics)}.
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void testGenerateWaypointDescription() {
|
|
||||||
Waypoint waypoint = new Waypoint();
|
|
||||||
TripStatistics stats = new TripStatistics();
|
|
||||||
stats.setTotalDistance(20000);
|
|
||||||
stats.setTotalTime(600000);
|
|
||||||
stats.setMovingTime(300000);
|
|
||||||
stats.setMaxSpeed(100);
|
|
||||||
stats.setMaxElevation(550);
|
|
||||||
stats.setMinElevation(-500);
|
|
||||||
stats.setTotalElevationGain(6000);
|
|
||||||
stats.setMaxGrade(0.42);
|
|
||||||
stats.setMinGrade(0.11);
|
|
||||||
stats.setStartTime(START_TIME);
|
|
||||||
waypoint.setTripStatistics(stats);
|
|
||||||
String expected = "Total distance: 20.00 km (12.4 mi)\n"
|
|
||||||
+ "Total time: 10:00\n"
|
|
||||||
+ "Moving time: 05:00\n"
|
|
||||||
+ "Average speed: 120.00 km/h (74.6 mi/h)\n"
|
|
||||||
+ "Average moving speed: 240.00 km/h (149.1 mi/h)\n"
|
|
||||||
+ "Max speed: 360.00 km/h (223.7 mi/h)\n"
|
|
||||||
+ "Average pace: 0:30 min/km (0:48 min/mi)\n"
|
|
||||||
+ "Average moving pace: 0:15 min/km (0:24 min/mi)\n"
|
|
||||||
+ "Fastest pace: 0:10 min/km (0:16 min/mi)\n"
|
|
||||||
+ "Max elevation: 550 m (1804 ft)\n"
|
|
||||||
+ "Min elevation: -500 m (-1640 ft)\n"
|
|
||||||
+ "Elevation gain: 6000 m (19685 ft)\n"
|
|
||||||
+ "Max grade: 42 %\n"
|
|
||||||
+ "Min grade: 11 %\n"
|
|
||||||
+ "Recorded: " + StringUtils.formatDateTime(context, START_TIME) + "\n";
|
|
||||||
Assert.assertEquals(expected, descriptionGenerator.generateWaypointDescription(waypoint.getTripStatistics()));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests {@link DescriptionGeneratorImpl#writeDistance(double, StringBuilder, int, String)}.
|
* Tests {@link DescriptionGenerator#writeDistance(double, StringBuilder, int, String)}.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testWriteDistance() {
|
public void testWriteDistance() {
|
||||||
@@ -138,7 +104,7 @@ public class DescriptionGeneratorImplTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests {@link DescriptionGeneratorImpl#writeTime(long, StringBuilder, int, String)}.
|
* Tests {@link DescriptionGenerator#writeTime(long, StringBuilder, int, String)}.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testWriteTime() {
|
public void testWriteTime() {
|
||||||
@@ -148,7 +114,7 @@ public class DescriptionGeneratorImplTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests {@link DescriptionGeneratorImpl#writeSpeed(double, StringBuilder, int, String)}.
|
* Tests {@link DescriptionGenerator#writeSpeed(double, StringBuilder, int, String)}.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testWriteSpeed() {
|
public void testWriteSpeed() {
|
||||||
@@ -158,7 +124,7 @@ public class DescriptionGeneratorImplTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests {@link DescriptionGeneratorImpl#writeElevation(double, StringBuilder, int, String)}.
|
* Tests {@link DescriptionGenerator#writeElevation(double, StringBuilder, int, String)}.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testWriteElevation() {
|
public void testWriteElevation() {
|
||||||
@@ -168,7 +134,7 @@ public class DescriptionGeneratorImplTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests {@link DescriptionGeneratorImpl#writePace(double, StringBuilder, int, String)}.
|
* Tests {@link DescriptionGenerator#writePace(double, StringBuilder, int, String)}.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testWritePace() {
|
public void testWritePace() {
|
||||||
@@ -178,7 +144,7 @@ public class DescriptionGeneratorImplTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests {@link DescriptionGeneratorImpl#writeGrade(double, StringBuilder, int, String)}.
|
* Tests {@link DescriptionGenerator#writeGrade(double, StringBuilder, int, String)}.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testWriteGrade() {
|
public void testWriteGrade() {
|
||||||
@@ -188,7 +154,7 @@ public class DescriptionGeneratorImplTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests {@link DescriptionGeneratorImpl#writeGrade(double, StringBuilder, int, String)} with a NaN.
|
* Tests {@link DescriptionGenerator#writeGrade(double, StringBuilder, int, String)} with a NaN.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testWriteGrade_nan() {
|
public void testWriteGrade_nan() {
|
||||||
@@ -198,7 +164,7 @@ public class DescriptionGeneratorImplTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests {@link DescriptionGeneratorImpl#writeGrade(double, StringBuilder, int, String)} with an infinite number.
|
* Tests {@link DescriptionGenerator#writeGrade(double, StringBuilder, int, String)} with an infinite number.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testWriteGrade_infinite() {
|
public void testWriteGrade_infinite() {
|
||||||
@@ -36,6 +36,8 @@ import java.util.List;
|
|||||||
|
|
||||||
import de.dennisguse.opentracks.content.SearchEngine.ScoredResult;
|
import de.dennisguse.opentracks.content.SearchEngine.ScoredResult;
|
||||||
import de.dennisguse.opentracks.content.SearchEngine.SearchQuery;
|
import de.dennisguse.opentracks.content.SearchEngine.SearchQuery;
|
||||||
|
import de.dennisguse.opentracks.content.data.Track;
|
||||||
|
import de.dennisguse.opentracks.content.data.Waypoint;
|
||||||
import de.dennisguse.opentracks.stats.TripStatistics;
|
import de.dennisguse.opentracks.stats.TripStatistics;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -58,7 +60,7 @@ public class SearchEngineTest {
|
|||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
providerUtils = ContentProviderUtils.Factory.get(context);
|
providerUtils = new ContentProviderUtils(context);
|
||||||
engine = new SearchEngine(providerUtils);
|
engine = new SearchEngine(providerUtils);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,10 +82,6 @@ public class SearchEngineTest {
|
|||||||
stats.setStopTime(NOW);
|
stats.setStopTime(NOW);
|
||||||
}
|
}
|
||||||
|
|
||||||
int latitude = (int) ((HERE.getLatitude() + distance) * 1E6);
|
|
||||||
int longitude = (int) ((HERE.getLongitude() + distance) * 1E6);
|
|
||||||
stats.setBounds(latitude, longitude, latitude, longitude);
|
|
||||||
|
|
||||||
Uri uri = providerUtils.insertTrack(track);
|
Uri uri = providerUtils.insertTrack(track);
|
||||||
return ContentUris.parseId(uri);
|
return ContentUris.parseId(uri);
|
||||||
}
|
}
|
||||||
@@ -209,20 +207,6 @@ public class SearchEngineTest {
|
|||||||
assertWaypointResult(descriptionWaypointId, results.get(2));
|
assertWaypointResult(descriptionWaypointId, results.get(2));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testSearchTrackDistance() {
|
|
||||||
// All results match text, but they're at difference distances from the user.
|
|
||||||
long farFarAwayId = insertTrack("aa", 0.3);
|
|
||||||
long nearId = insertTrack("ab", 0.1);
|
|
||||||
long farId = insertTrack("ac", 0.2);
|
|
||||||
|
|
||||||
SearchQuery query = new SearchQuery("a", HERE, -1, NOW);
|
|
||||||
ArrayList<ScoredResult> results = new ArrayList<ScoredResult>(engine.search(query));
|
|
||||||
|
|
||||||
// Distance order.
|
|
||||||
assertTrackResults(results, nearId, farId, farFarAwayId);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSearchWaypointDistance() {
|
public void testSearchWaypointDistance() {
|
||||||
// All results match text, but they're at difference distances from the user.
|
// All results match text, but they're at difference distances from the user.
|
||||||
|
|||||||
@@ -0,0 +1,44 @@
|
|||||||
|
package de.dennisguse.opentracks.content.data;
|
||||||
|
|
||||||
|
import android.location.Location;
|
||||||
|
|
||||||
|
public class TestDataUtil {
|
||||||
|
|
||||||
|
public static final double INITIAL_LATITUDE = 37.0;
|
||||||
|
public static final double INITIAL_LONGITUDE = -57.0;
|
||||||
|
public static final double ALTITUDE_INTERVAL = 2.5;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Simulates a track which is used for testing.
|
||||||
|
*
|
||||||
|
* @param id the id of the track
|
||||||
|
* @param numPoints the location number in the track
|
||||||
|
* @return the simulated track
|
||||||
|
*/
|
||||||
|
public static Track getTrack(long id, int numPoints) {
|
||||||
|
Track track = new Track();
|
||||||
|
track.setId(id);
|
||||||
|
track.setName("Test: " + id);
|
||||||
|
track.setNumberOfPoints(numPoints);
|
||||||
|
for (int i = 0; i < numPoints; i++) {
|
||||||
|
track.addLocation(createLocation(i));
|
||||||
|
}
|
||||||
|
return track;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a location.
|
||||||
|
*
|
||||||
|
* @param i the index to set the value of location.
|
||||||
|
* @return created location
|
||||||
|
*/
|
||||||
|
public static Location createLocation(int i) {
|
||||||
|
Location loc = new Location("test");
|
||||||
|
loc.setLatitude(INITIAL_LATITUDE + (double) i / 10000.0);
|
||||||
|
loc.setLongitude(INITIAL_LONGITUDE - (double) i / 10000.0);
|
||||||
|
loc.setAccuracy((float) i / 100.0f);
|
||||||
|
loc.setAltitude(i * ALTITUDE_INTERVAL);
|
||||||
|
loc.setTime(i + 1);
|
||||||
|
return loc;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -17,18 +17,21 @@
|
|||||||
package de.dennisguse.opentracks.fragments;
|
package de.dennisguse.opentracks.fragments;
|
||||||
|
|
||||||
import android.location.Location;
|
import android.location.Location;
|
||||||
|
import android.os.Looper;
|
||||||
|
|
||||||
import androidx.test.core.app.ApplicationProvider;
|
import androidx.test.core.app.ApplicationProvider;
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||||
|
|
||||||
|
import org.junit.AfterClass;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
import de.dennisguse.opentracks.ChartView;
|
|
||||||
import de.dennisguse.opentracks.TrackStubUtils;
|
import de.dennisguse.opentracks.TrackStubUtils;
|
||||||
import de.dennisguse.opentracks.content.SensorDataSetLocation;
|
import de.dennisguse.opentracks.chart.ChartView;
|
||||||
|
import de.dennisguse.opentracks.content.data.TrackPoint;
|
||||||
import de.dennisguse.opentracks.content.sensor.SensorDataSet;
|
import de.dennisguse.opentracks.content.sensor.SensorDataSet;
|
||||||
import de.dennisguse.opentracks.util.UnitConversions;
|
import de.dennisguse.opentracks.util.UnitConversions;
|
||||||
|
|
||||||
@@ -44,10 +47,23 @@ public class ChartFragmentTest {
|
|||||||
|
|
||||||
private ChartFragment chartFragment;
|
private ChartFragment chartFragment;
|
||||||
|
|
||||||
|
@BeforeClass
|
||||||
|
public static void preSetUp() {
|
||||||
|
// Prepare looper for Android's message queue
|
||||||
|
if (Looper.myLooper() == null) Looper.prepare();
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterClass
|
||||||
|
public static void finalTearDown() {
|
||||||
|
if (Looper.myLooper() != null) Looper.myLooper().quit();
|
||||||
|
}
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
chartFragment = new ChartFragment();
|
boolean chartByDistance = false;
|
||||||
chartFragment.setChartView(new ChartView(ApplicationProvider.getApplicationContext()));
|
chartFragment = new ChartFragment(chartByDistance) {
|
||||||
|
};
|
||||||
|
chartFragment.setChartView(new ChartView(ApplicationProvider.getApplicationContext(), chartByDistance));
|
||||||
chartFragment.setTripStatisticsUpdater(TrackStubUtils.INITIAL_TIME);
|
chartFragment.setTripStatisticsUpdater(TrackStubUtils.INITIAL_TIME);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,7 +72,7 @@ public class ChartFragmentTest {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testFillDataPoint_sensorIncorrect() {
|
public void testFillDataPoint_sensorIncorrect() {
|
||||||
SensorDataSetLocation sensorDataSetLocation = TrackStubUtils.createSensorDataSetLocation();
|
TrackPoint sensorDataSetLocation = TrackStubUtils.createSensorDataSetLocation();
|
||||||
|
|
||||||
// No input.
|
// No input.
|
||||||
double[] point = fillDataPointTestHelper(sensorDataSetLocation);
|
double[] point = fillDataPointTestHelper(sensorDataSetLocation);
|
||||||
@@ -80,7 +96,7 @@ public class ChartFragmentTest {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testFillDataPoint_sensorCorrect() {
|
public void testFillDataPoint_sensorCorrect() {
|
||||||
SensorDataSetLocation sensorDataSetLocation = TrackStubUtils.createSensorDataSetLocation();
|
TrackPoint sensorDataSetLocation = TrackStubUtils.createSensorDataSetLocation();
|
||||||
// No input.
|
// No input.
|
||||||
double[] point = fillDataPointTestHelper(sensorDataSetLocation);
|
double[] point = fillDataPointTestHelper(sensorDataSetLocation);
|
||||||
Assert.assertEquals(Float.NaN, point[ChartView.HEART_RATE_SERIES + 1], 0.01);
|
Assert.assertEquals(Float.NaN, point[ChartView.HEART_RATE_SERIES + 1], 0.01);
|
||||||
@@ -107,17 +123,17 @@ public class ChartFragmentTest {
|
|||||||
// By distance.
|
// By distance.
|
||||||
chartFragment.setChartByDistance(true);
|
chartFragment.setChartByDistance(true);
|
||||||
// Resets last location and writes first location.
|
// Resets last location and writes first location.
|
||||||
SensorDataSetLocation sensorDataSetLocation1 = TrackStubUtils.createSensorDataSetLocation();
|
TrackPoint sensorDataSetLocation1 = TrackStubUtils.createSensorDataSetLocation();
|
||||||
double[] point = fillDataPointTestHelper(sensorDataSetLocation1);
|
double[] point = fillDataPointTestHelper(sensorDataSetLocation1);
|
||||||
Assert.assertEquals(0.0, point[0], 0.01);
|
Assert.assertEquals(0.0, point[0], 0.01);
|
||||||
|
|
||||||
// The second is a same location, just different time.
|
// The second is a same location, just different time.
|
||||||
SensorDataSetLocation sensorDataSetLocation2 = TrackStubUtils.createSensorDataSetLocation();
|
TrackPoint sensorDataSetLocation2 = TrackStubUtils.createSensorDataSetLocation();
|
||||||
point = fillDataPointTestHelper(sensorDataSetLocation2);
|
point = fillDataPointTestHelper(sensorDataSetLocation2);
|
||||||
Assert.assertEquals(0.0, point[0], 0.01);
|
Assert.assertEquals(0.0, point[0], 0.01);
|
||||||
|
|
||||||
// The third location is a new location, and use metric.
|
// The third location is a new location, and use metric.
|
||||||
SensorDataSetLocation sensorDataSetLocation3 = TrackStubUtils.createSensorDataSetLocation();
|
TrackPoint sensorDataSetLocation3 = TrackStubUtils.createSensorDataSetLocation();
|
||||||
sensorDataSetLocation3.setLatitude(23);
|
sensorDataSetLocation3.setLatitude(23);
|
||||||
point = fillDataPointTestHelper(sensorDataSetLocation3);
|
point = fillDataPointTestHelper(sensorDataSetLocation3);
|
||||||
|
|
||||||
@@ -129,7 +145,7 @@ public class ChartFragmentTest {
|
|||||||
Assert.assertEquals(distance1, point[0], 0.01);
|
Assert.assertEquals(distance1, point[0], 0.01);
|
||||||
|
|
||||||
// The fourth location is a new location, and use metric.
|
// The fourth location is a new location, and use metric.
|
||||||
SensorDataSetLocation sensorDataSetLocation4 = TrackStubUtils.createSensorDataSetLocation();
|
TrackPoint sensorDataSetLocation4 = TrackStubUtils.createSensorDataSetLocation();
|
||||||
sensorDataSetLocation4.setLatitude(24);
|
sensorDataSetLocation4.setLatitude(24);
|
||||||
point = fillDataPointTestHelper(sensorDataSetLocation4);
|
point = fillDataPointTestHelper(sensorDataSetLocation4);
|
||||||
|
|
||||||
@@ -151,12 +167,12 @@ public class ChartFragmentTest {
|
|||||||
chartFragment.setMetricUnits(false);
|
chartFragment.setMetricUnits(false);
|
||||||
|
|
||||||
// The first is a same location, just different time.
|
// The first is a same location, just different time.
|
||||||
SensorDataSetLocation sensorDataSetLocation1 = TrackStubUtils.createSensorDataSetLocation();
|
TrackPoint sensorDataSetLocation1 = TrackStubUtils.createSensorDataSetLocation();
|
||||||
double[] point = fillDataPointTestHelper(sensorDataSetLocation1);
|
double[] point = fillDataPointTestHelper(sensorDataSetLocation1);
|
||||||
Assert.assertEquals(0.0, point[0], 0.01);
|
Assert.assertEquals(0.0, point[0], 0.01);
|
||||||
|
|
||||||
// The second location is a new location, and use imperial.
|
// The second location is a new location, and use imperial.
|
||||||
SensorDataSetLocation sensorDataSetLocation2 = TrackStubUtils.createSensorDataSetLocation();
|
TrackPoint sensorDataSetLocation2 = TrackStubUtils.createSensorDataSetLocation();
|
||||||
sensorDataSetLocation2.setLatitude(23);
|
sensorDataSetLocation2.setLatitude(23);
|
||||||
point = fillDataPointTestHelper(sensorDataSetLocation2);
|
point = fillDataPointTestHelper(sensorDataSetLocation2);
|
||||||
|
|
||||||
@@ -170,7 +186,7 @@ public class ChartFragmentTest {
|
|||||||
Assert.assertEquals(distance1, point[0], 0.01);
|
Assert.assertEquals(distance1, point[0], 0.01);
|
||||||
|
|
||||||
// The third location is a new location, and use imperial.
|
// The third location is a new location, and use imperial.
|
||||||
SensorDataSetLocation sensorDataSetLocation3 = TrackStubUtils.createSensorDataSetLocation();
|
TrackPoint sensorDataSetLocation3 = TrackStubUtils.createSensorDataSetLocation();
|
||||||
sensorDataSetLocation3.setLatitude(24);
|
sensorDataSetLocation3.setLatitude(24);
|
||||||
point = fillDataPointTestHelper(sensorDataSetLocation3);
|
point = fillDataPointTestHelper(sensorDataSetLocation3);
|
||||||
|
|
||||||
@@ -190,11 +206,11 @@ public class ChartFragmentTest {
|
|||||||
public void testFillDataPoint_time() {
|
public void testFillDataPoint_time() {
|
||||||
// By time
|
// By time
|
||||||
chartFragment.setChartByDistance(false);
|
chartFragment.setChartByDistance(false);
|
||||||
SensorDataSetLocation sensorDataSetLocation1 = TrackStubUtils.createSensorDataSetLocation();
|
TrackPoint sensorDataSetLocation1 = TrackStubUtils.createSensorDataSetLocation();
|
||||||
double[] point = fillDataPointTestHelper(sensorDataSetLocation1);
|
double[] point = fillDataPointTestHelper(sensorDataSetLocation1);
|
||||||
Assert.assertEquals(0.0, point[0], 0.01);
|
Assert.assertEquals(0.0, point[0], 0.01);
|
||||||
long timeSpan = 222;
|
long timeSpan = 222;
|
||||||
SensorDataSetLocation sensorDataSetLocation2 = TrackStubUtils.createSensorDataSetLocation();
|
TrackPoint sensorDataSetLocation2 = TrackStubUtils.createSensorDataSetLocation();
|
||||||
sensorDataSetLocation2.setTime(sensorDataSetLocation1.getTime() + timeSpan);
|
sensorDataSetLocation2.setTime(sensorDataSetLocation1.getTime() + timeSpan);
|
||||||
point = fillDataPointTestHelper(sensorDataSetLocation2);
|
point = fillDataPointTestHelper(sensorDataSetLocation2);
|
||||||
Assert.assertEquals((double) timeSpan, point[0], 0.01);
|
Assert.assertEquals((double) timeSpan, point[0], 0.01);
|
||||||
@@ -205,7 +221,7 @@ public class ChartFragmentTest {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testFillDataPoint_elevation() {
|
public void testFillDataPoint_elevation() {
|
||||||
SensorDataSetLocation sensorDataSetLocation1 = TrackStubUtils.createSensorDataSetLocation();
|
TrackPoint sensorDataSetLocation1 = TrackStubUtils.createSensorDataSetLocation();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* At first, clear old points of elevation, so give true to the second parameter.
|
* At first, clear old points of elevation, so give true to the second parameter.
|
||||||
@@ -217,7 +233,7 @@ public class ChartFragmentTest {
|
|||||||
/*
|
/*
|
||||||
* Send another value to buffer, now there are two values, INITIAL_ALTITUDE and INITIAL_ALTITUDE * 2.
|
* Send another value to buffer, now there are two values, INITIAL_ALTITUDE and INITIAL_ALTITUDE * 2.
|
||||||
*/
|
*/
|
||||||
SensorDataSetLocation sensorDataSetLocation2 = TrackStubUtils.createSensorDataSetLocation();
|
TrackPoint sensorDataSetLocation2 = TrackStubUtils.createSensorDataSetLocation();
|
||||||
sensorDataSetLocation2.setAltitude(TrackStubUtils.INITIAL_ALTITUDE * 2);
|
sensorDataSetLocation2.setAltitude(TrackStubUtils.INITIAL_ALTITUDE * 2);
|
||||||
point = fillDataPointTestHelper(sensorDataSetLocation2);
|
point = fillDataPointTestHelper(sensorDataSetLocation2);
|
||||||
Assert.assertEquals((TrackStubUtils.INITIAL_ALTITUDE + TrackStubUtils.INITIAL_ALTITUDE * 2) / 2.0,
|
Assert.assertEquals((TrackStubUtils.INITIAL_ALTITUDE + TrackStubUtils.INITIAL_ALTITUDE * 2) / 2.0,
|
||||||
@@ -235,7 +251,7 @@ public class ChartFragmentTest {
|
|||||||
* At first, clear old points of speed, so give true to the second parameter.
|
* At first, clear old points of speed, so give true to the second parameter.
|
||||||
* It will not be filled in to the speed buffer.
|
* It will not be filled in to the speed buffer.
|
||||||
*/
|
*/
|
||||||
SensorDataSetLocation sensorDataSetLocation1 = TrackStubUtils.createSensorDataSetLocation();
|
TrackPoint sensorDataSetLocation1 = TrackStubUtils.createSensorDataSetLocation();
|
||||||
sensorDataSetLocation1.setSpeed(128.5f);
|
sensorDataSetLocation1.setSpeed(128.5f);
|
||||||
double[] point = fillDataPointTestHelper(sensorDataSetLocation1);
|
double[] point = fillDataPointTestHelper(sensorDataSetLocation1);
|
||||||
Assert.assertEquals(0.0, point[ChartView.SPEED_SERIES + 1], 0.01);
|
Assert.assertEquals(0.0, point[ChartView.SPEED_SERIES + 1], 0.01);
|
||||||
@@ -244,7 +260,7 @@ public class ChartFragmentTest {
|
|||||||
* Tests the logic when both metricUnits and reportSpeed are true.
|
* Tests the logic when both metricUnits and reportSpeed are true.
|
||||||
* This location will be filled into speed buffer.
|
* This location will be filled into speed buffer.
|
||||||
*/
|
*/
|
||||||
SensorDataSetLocation sensorDataSetLocation2 = TrackStubUtils.createSensorDataSetLocation();
|
TrackPoint sensorDataSetLocation2 = TrackStubUtils.createSensorDataSetLocation();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Add a time span here to make sure the second point is valid, the value 222 here is doesn't matter.
|
* Add a time span here to make sure the second point is valid, the value 222 here is doesn't matter.
|
||||||
@@ -264,12 +280,12 @@ public class ChartFragmentTest {
|
|||||||
chartFragment.setMetricUnits(false);
|
chartFragment.setMetricUnits(false);
|
||||||
|
|
||||||
// First data point is not added to the speed buffer
|
// First data point is not added to the speed buffer
|
||||||
SensorDataSetLocation sensorDataSetLocation1 = TrackStubUtils.createSensorDataSetLocation();
|
TrackPoint sensorDataSetLocation1 = TrackStubUtils.createSensorDataSetLocation();
|
||||||
sensorDataSetLocation1.setSpeed(100.0f);
|
sensorDataSetLocation1.setSpeed(100.0f);
|
||||||
double[] point = fillDataPointTestHelper(sensorDataSetLocation1);
|
double[] point = fillDataPointTestHelper(sensorDataSetLocation1);
|
||||||
Assert.assertEquals(0.0, point[ChartView.SPEED_SERIES + 1], 0.01);
|
Assert.assertEquals(0.0, point[ChartView.SPEED_SERIES + 1], 0.01);
|
||||||
|
|
||||||
SensorDataSetLocation sensorDataSetLocation2 = TrackStubUtils.createSensorDataSetLocation();
|
TrackPoint sensorDataSetLocation2 = TrackStubUtils.createSensorDataSetLocation();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Add a time span here to make sure the second point and the speed is valid.
|
* Add a time span here to make sure the second point and the speed is valid.
|
||||||
@@ -290,12 +306,12 @@ public class ChartFragmentTest {
|
|||||||
chartFragment.setReportSpeed(false);
|
chartFragment.setReportSpeed(false);
|
||||||
|
|
||||||
// First data point is not added to the speed buffer
|
// First data point is not added to the speed buffer
|
||||||
SensorDataSetLocation sensorDataSetLocation1 = TrackStubUtils.createSensorDataSetLocation();
|
TrackPoint sensorDataSetLocation1 = TrackStubUtils.createSensorDataSetLocation();
|
||||||
sensorDataSetLocation1.setSpeed(100.0f);
|
sensorDataSetLocation1.setSpeed(100.0f);
|
||||||
double[] point = fillDataPointTestHelper(sensorDataSetLocation1);
|
double[] point = fillDataPointTestHelper(sensorDataSetLocation1);
|
||||||
Assert.assertEquals(0.0, point[ChartView.SPEED_SERIES + 1], 0.01);
|
Assert.assertEquals(0.0, point[ChartView.SPEED_SERIES + 1], 0.01);
|
||||||
|
|
||||||
SensorDataSetLocation sensorDataSetLocation2 = TrackStubUtils.createSensorDataSetLocation();
|
TrackPoint sensorDataSetLocation2 = TrackStubUtils.createSensorDataSetLocation();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Add a time span here to make sure the second point and the speed is valid.
|
* Add a time span here to make sure the second point and the speed is valid.
|
||||||
@@ -314,7 +330,7 @@ public class ChartFragmentTest {
|
|||||||
public void testFillDataPoint_pace_zeroSpeed() {
|
public void testFillDataPoint_pace_zeroSpeed() {
|
||||||
// Setups reportSpeed to false.
|
// Setups reportSpeed to false.
|
||||||
chartFragment.setReportSpeed(false);
|
chartFragment.setReportSpeed(false);
|
||||||
SensorDataSetLocation sensorDataSetLocation = TrackStubUtils.createSensorDataSetLocation();
|
TrackPoint sensorDataSetLocation = TrackStubUtils.createSensorDataSetLocation();
|
||||||
sensorDataSetLocation.setSpeed(0);
|
sensorDataSetLocation.setSpeed(0);
|
||||||
double[] point = fillDataPointTestHelper(sensorDataSetLocation);
|
double[] point = fillDataPointTestHelper(sensorDataSetLocation);
|
||||||
Assert.assertEquals(0.0, point[ChartView.PACE_SERIES + 1], 0.01);
|
Assert.assertEquals(0.0, point[ChartView.PACE_SERIES + 1], 0.01);
|
||||||
|
|||||||
@@ -33,10 +33,10 @@ import java.util.Locale;
|
|||||||
import java.util.SimpleTimeZone;
|
import java.util.SimpleTimeZone;
|
||||||
|
|
||||||
import de.dennisguse.opentracks.content.ContentProviderUtils;
|
import de.dennisguse.opentracks.content.ContentProviderUtils;
|
||||||
import de.dennisguse.opentracks.content.Track;
|
import de.dennisguse.opentracks.content.data.Track;
|
||||||
import de.dennisguse.opentracks.content.TracksColumns;
|
import de.dennisguse.opentracks.content.data.TracksColumns;
|
||||||
import de.dennisguse.opentracks.content.Waypoint;
|
import de.dennisguse.opentracks.content.data.Waypoint;
|
||||||
import de.dennisguse.opentracks.content.WaypointsColumns;
|
import de.dennisguse.opentracks.content.data.WaypointsColumns;
|
||||||
|
|
||||||
import static org.mockito.Mockito.any;
|
import static org.mockito.Mockito.any;
|
||||||
import static org.mockito.Mockito.eq;
|
import static org.mockito.Mockito.eq;
|
||||||
@@ -101,8 +101,6 @@ public abstract class AbstractTestFileTrackImporter {
|
|||||||
*/
|
*/
|
||||||
protected void expectFirstTrackPoint(Location location, long trackId, long trackPointId) {
|
protected void expectFirstTrackPoint(Location location, long trackId, long trackPointId) {
|
||||||
when(contentProviderUtils.bulkInsertTrackPoint(location != null ? (Location[]) any() : (Location[]) any(), eq(1), eq(trackId))).thenReturn(1);
|
when(contentProviderUtils.bulkInsertTrackPoint(location != null ? (Location[]) any() : (Location[]) any(), eq(1), eq(trackId))).thenReturn(1);
|
||||||
when(contentProviderUtils.getFirstTrackPointId(trackId)).thenReturn(trackPointId);
|
|
||||||
when(contentProviderUtils.getLastTrackPointId(trackId)).thenReturn(trackPointId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -112,7 +110,7 @@ public abstract class AbstractTestFileTrackImporter {
|
|||||||
* @param lastTrack true if it is the last track in the gpx
|
* @param lastTrack true if it is the last track in the gpx
|
||||||
* @param trackId the track id
|
* @param trackId the track id
|
||||||
*/
|
*/
|
||||||
protected void expectUpdateTrack(ArgumentCaptor<Track> trackCaptor, boolean lastTrack, long trackId) {
|
protected void expectTrackUpdate(ArgumentCaptor<Track> trackCaptor, boolean lastTrack, long trackId) {
|
||||||
contentProviderUtils.updateTrack(trackCaptor.capture());
|
contentProviderUtils.updateTrack(trackCaptor.capture());
|
||||||
|
|
||||||
when(contentProviderUtils.insertWaypoint((Waypoint) any())).thenReturn(WAYPOINT_ID_O_URI);
|
when(contentProviderUtils.insertWaypoint((Waypoint) any())).thenReturn(WAYPOINT_ID_O_URI);
|
||||||
@@ -128,7 +126,5 @@ public abstract class AbstractTestFileTrackImporter {
|
|||||||
if (time != -1L) {
|
if (time != -1L) {
|
||||||
Assert.assertEquals(time, track.getTripStatistics().getStartTime());
|
Assert.assertEquals(time, track.getTripStatistics().getStartTime());
|
||||||
}
|
}
|
||||||
Assert.assertNotSame(-1, track.getStartId());
|
|
||||||
Assert.assertNotSame(-1, track.getStopId());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,219 @@
|
|||||||
|
package de.dennisguse.opentracks.io.file.importer;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.location.Location;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import androidx.test.core.app.ApplicationProvider;
|
||||||
|
import androidx.test.filters.LargeTest;
|
||||||
|
|
||||||
|
import org.junit.After;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.junit.runners.JUnit4;
|
||||||
|
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import de.dennisguse.opentracks.content.ContentProviderUtils;
|
||||||
|
import de.dennisguse.opentracks.content.data.TestDataUtil;
|
||||||
|
import de.dennisguse.opentracks.content.data.Track;
|
||||||
|
import de.dennisguse.opentracks.content.data.Waypoint;
|
||||||
|
import de.dennisguse.opentracks.io.file.TrackFileFormat;
|
||||||
|
import de.dennisguse.opentracks.io.file.exporter.TrackExporter;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Export a track to {@link TrackFileFormat} and verify that the import is identical.
|
||||||
|
* <p>
|
||||||
|
* TODO: test ignores {@link de.dennisguse.opentracks.stats.TripStatistics} for now.
|
||||||
|
*/
|
||||||
|
@RunWith(JUnit4.class)
|
||||||
|
public class ExportImportTest {
|
||||||
|
|
||||||
|
private static final String TAG = ExportImportTest.class.getSimpleName();
|
||||||
|
|
||||||
|
private Context context = ApplicationProvider.getApplicationContext();
|
||||||
|
|
||||||
|
private ContentProviderUtils contentProviderUtils = new ContentProviderUtils(context);
|
||||||
|
|
||||||
|
private static final String TRACK_ICON = "the track icon";
|
||||||
|
private static final String TRACK_CATEGORY = "the category";
|
||||||
|
private static final String TRACK_DESCRIPTION = "the description";
|
||||||
|
private final List<Waypoint> waypoints = new ArrayList<>();
|
||||||
|
private long importTrackId;
|
||||||
|
private long trackId = System.currentTimeMillis();
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
Track track = TestDataUtil.getTrack(trackId, 10);
|
||||||
|
track.setIcon(TRACK_ICON);
|
||||||
|
track.setCategory(TRACK_CATEGORY);
|
||||||
|
track.setDescription(TRACK_DESCRIPTION);
|
||||||
|
contentProviderUtils.insertTrack(track);
|
||||||
|
contentProviderUtils.bulkInsertTrackPoint(track.getLocations().toArray(new Location[0]), track.getLocations().size(), track.getId());
|
||||||
|
|
||||||
|
for (int i = 0; i < 3; i++) {
|
||||||
|
Waypoint waypoint = new Waypoint();
|
||||||
|
waypoint.setName("the waypoint " + i);
|
||||||
|
waypoint.setDescription("the waypoint description " + i);
|
||||||
|
waypoint.setCategory("the waypoint category" + i);
|
||||||
|
waypoint.setIcon("the waypoing icon" + i);
|
||||||
|
waypoint.setPhotoUrl("the photo url" + i);
|
||||||
|
waypoint.setTrackId(trackId);
|
||||||
|
waypoint.setLocation(track.getLocations().get(i));
|
||||||
|
contentProviderUtils.insertWaypoint(waypoint);
|
||||||
|
|
||||||
|
waypoints.add(waypoint);
|
||||||
|
}
|
||||||
|
|
||||||
|
assertEquals(waypoints.size(), contentProviderUtils.getWaypointCount(trackId));
|
||||||
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void tearDown() {
|
||||||
|
contentProviderUtils.deleteTrack(context, trackId);
|
||||||
|
contentProviderUtils.deleteTrack(context, importTrackId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@LargeTest
|
||||||
|
@Test
|
||||||
|
public void kml_only_track() {
|
||||||
|
// TODO
|
||||||
|
Log.e(TAG, "Test not implemented.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@LargeTest
|
||||||
|
@Test
|
||||||
|
public void kml_with_trackdetail() {
|
||||||
|
// given
|
||||||
|
Track track = contentProviderUtils.getTrack(trackId);
|
||||||
|
|
||||||
|
TrackFileFormat trackFileFormat = TrackFileFormat.KML_WITH_TRACKDETAIL;
|
||||||
|
TrackExporter trackExporter = trackFileFormat.newTrackExporter(context, new Track[]{track}, null);
|
||||||
|
|
||||||
|
// when
|
||||||
|
// 1. export
|
||||||
|
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||||
|
trackExporter.writeTrack(context, outputStream);
|
||||||
|
|
||||||
|
System.out.println(outputStream.toString());
|
||||||
|
|
||||||
|
// 2. import
|
||||||
|
InputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());
|
||||||
|
AbstractFileTrackImporter trackImporter = new KmlFileTrackImporter(context, -1L);
|
||||||
|
importTrackId = trackImporter.importFile(inputStream);
|
||||||
|
|
||||||
|
// then
|
||||||
|
// 1. track
|
||||||
|
Track importedTrack = contentProviderUtils.getTrack(importTrackId);
|
||||||
|
assertNotNull(importedTrack);
|
||||||
|
assertEquals(track.getLocations(), importedTrack.getLocations());
|
||||||
|
assertEquals(track.getCategory(), importedTrack.getCategory());
|
||||||
|
assertEquals(track.getDescription(), importedTrack.getDescription());
|
||||||
|
assertEquals(track.getName(), importedTrack.getName());
|
||||||
|
assertEquals(track.getIcon(), importedTrack.getIcon());
|
||||||
|
|
||||||
|
// 2. waypoints
|
||||||
|
assertWaypoints();
|
||||||
|
|
||||||
|
//TODO Check absolute time of trackpoints
|
||||||
|
}
|
||||||
|
|
||||||
|
@LargeTest
|
||||||
|
@Test
|
||||||
|
public void kml_with_trackdetail_and_sensordata() {
|
||||||
|
// TODO
|
||||||
|
Log.e(TAG, "Test not implemented.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@LargeTest
|
||||||
|
@Test
|
||||||
|
public void kmz_only_track() {
|
||||||
|
// TODO
|
||||||
|
Log.e(TAG, "Test not implemented.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@LargeTest
|
||||||
|
@Test
|
||||||
|
public void kmz_with_trackdetail() {
|
||||||
|
// TODO
|
||||||
|
Log.e(TAG, "Test not implemented.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@LargeTest
|
||||||
|
@Test
|
||||||
|
public void kmz_with_trackdetail_and_sensordata() {
|
||||||
|
// TODO
|
||||||
|
Log.e(TAG, "Test not implemented.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@LargeTest
|
||||||
|
@Test
|
||||||
|
public void kmz_with_trackdetail_and_sensordata_and_pictures() {
|
||||||
|
// TODO
|
||||||
|
Log.e(TAG, "Test not implemented.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@LargeTest
|
||||||
|
@Test
|
||||||
|
public void gpx() {
|
||||||
|
// given
|
||||||
|
Track track = contentProviderUtils.getTrack(trackId);
|
||||||
|
|
||||||
|
TrackFileFormat trackFileFormat = TrackFileFormat.GPX;
|
||||||
|
TrackExporter trackExporter = trackFileFormat.newTrackExporter(context, new Track[]{track}, null);
|
||||||
|
|
||||||
|
// when
|
||||||
|
// 1. export
|
||||||
|
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||||
|
trackExporter.writeTrack(context, outputStream);
|
||||||
|
|
||||||
|
// 2. import
|
||||||
|
InputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());
|
||||||
|
AbstractFileTrackImporter trackImporter = new GpxFileTrackImporter(context, contentProviderUtils);
|
||||||
|
importTrackId = trackImporter.importFile(inputStream);
|
||||||
|
|
||||||
|
// then
|
||||||
|
// 1. track
|
||||||
|
Track trackImported = contentProviderUtils.getTrack(importTrackId);
|
||||||
|
assertNotNull(trackImported);
|
||||||
|
assertEquals(track.getLocations(), trackImported.getLocations());
|
||||||
|
assertEquals(track.getCategory(), trackImported.getCategory());
|
||||||
|
assertEquals(track.getDescription(), trackImported.getDescription());
|
||||||
|
assertEquals(track.getName(), trackImported.getName());
|
||||||
|
|
||||||
|
//TODO exporting and importing a track icon is not yet supported by GpxTrackWriter.
|
||||||
|
//assertEquals(track.getIcon(), trackImported.getIcon());
|
||||||
|
|
||||||
|
// 2. waypoints
|
||||||
|
assertWaypoints();
|
||||||
|
|
||||||
|
//TODO Check absolute time of trackpoints
|
||||||
|
}
|
||||||
|
|
||||||
|
private void assertWaypoints() {
|
||||||
|
assertEquals(waypoints.size(), contentProviderUtils.getWaypointCount(importTrackId));
|
||||||
|
|
||||||
|
List<Waypoint> importedWaypoints = contentProviderUtils.getWaypoints(importTrackId);
|
||||||
|
for (int i = 0; i < waypoints.size(); i++) {
|
||||||
|
Waypoint waypoint = waypoints.get(i);
|
||||||
|
Waypoint importedWaypoint = importedWaypoints.get(i);
|
||||||
|
assertEquals(waypoint.getCategory(), importedWaypoint.getCategory());
|
||||||
|
assertEquals(waypoint.getDescription(), importedWaypoint.getDescription());
|
||||||
|
// assertEquals(waypoint.getIcon(), importedWaypoint.getIcon()); // TODO for KML
|
||||||
|
assertEquals(waypoint.getName(), importedWaypoint.getName());
|
||||||
|
assertEquals("", importedWaypoint.getPhotoUrl());
|
||||||
|
|
||||||
|
assertEquals(waypoint.getLocation().getLatitude(), importedWaypoint.getLocation().getLatitude(), 0.001);
|
||||||
|
assertEquals(waypoint.getLocation().getLongitude(), importedWaypoint.getLocation().getLongitude(), 0.001);
|
||||||
|
assertEquals(waypoint.getLocation().getAltitude(), importedWaypoint.getLocation().getAltitude(), 0.001);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -27,13 +27,13 @@ import org.mockito.junit.MockitoJUnitRunner;
|
|||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
||||||
import de.dennisguse.opentracks.R;
|
import de.dennisguse.opentracks.content.data.Track;
|
||||||
import de.dennisguse.opentracks.content.Track;
|
|
||||||
import de.dennisguse.opentracks.util.PreferencesUtils;
|
import de.dennisguse.opentracks.util.PreferencesUtils;
|
||||||
|
|
||||||
import static org.mockito.Mockito.any;
|
import static org.mockito.Mockito.any;
|
||||||
import static org.mockito.Mockito.anyInt;
|
import static org.mockito.Mockito.anyInt;
|
||||||
import static org.mockito.Mockito.anyLong;
|
import static org.mockito.Mockito.anyLong;
|
||||||
|
import static org.mockito.Mockito.atLeastOnce;
|
||||||
import static org.mockito.Mockito.eq;
|
import static org.mockito.Mockito.eq;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
@@ -84,8 +84,7 @@ public class GpxFileTrackImporterTest extends AbstractTestFileTrackImporter {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testOneTrackOneSegment() throws Exception {
|
public void testOneTrackOneSegment() throws Exception {
|
||||||
ArgumentCaptor<Track> trackCaptor = ArgumentCaptor.forClass(Track.class);
|
// given
|
||||||
|
|
||||||
Location location0 = createLocation(0, DATE_FORMAT_0.parse(TRACK_TIME_0).getTime());
|
Location location0 = createLocation(0, DATE_FORMAT_0.parse(TRACK_TIME_0).getTime());
|
||||||
Location location1 = createLocation(1, DATE_FORMAT_1.parse(TRACK_TIME_1).getTime());
|
Location location1 = createLocation(1, DATE_FORMAT_1.parse(TRACK_TIME_1).getTime());
|
||||||
|
|
||||||
@@ -95,25 +94,28 @@ public class GpxFileTrackImporterTest extends AbstractTestFileTrackImporter {
|
|||||||
// A flush happens at the end
|
// A flush happens at the end
|
||||||
when(contentProviderUtils.bulkInsertTrackPoint((Location[]) any(), eq(1), eq(TRACK_ID_0))).thenReturn(1);
|
when(contentProviderUtils.bulkInsertTrackPoint((Location[]) any(), eq(1), eq(TRACK_ID_0))).thenReturn(1);
|
||||||
when(contentProviderUtils.getLastTrackPointId(TRACK_ID_0)).thenReturn(TRACK_POINT_ID_1);
|
when(contentProviderUtils.getLastTrackPointId(TRACK_ID_0)).thenReturn(TRACK_POINT_ID_1);
|
||||||
when(contentProviderUtils.getTrack(PreferencesUtils.getLong(context, R.string.recording_track_id_key))).thenReturn(null);
|
when(contentProviderUtils.getTrack(PreferencesUtils.getRecordingTrackId(context))).thenReturn(null);
|
||||||
expectUpdateTrack(trackCaptor, true, TRACK_ID_0);
|
ArgumentCaptor<Track> trackCaptor = ArgumentCaptor.forClass(Track.class);
|
||||||
|
expectTrackUpdate(trackCaptor, true, TRACK_ID_0);
|
||||||
|
|
||||||
|
// when
|
||||||
InputStream inputStream = new ByteArrayInputStream(VALID_ONE_TRACK_ONE_SEGMENT_GPX.getBytes());
|
InputStream inputStream = new ByteArrayInputStream(VALID_ONE_TRACK_ONE_SEGMENT_GPX.getBytes());
|
||||||
GpxFileTrackImporter gpxFileTrackImporter = new GpxFileTrackImporter(context, contentProviderUtils);
|
GpxFileTrackImporter gpxFileTrackImporter = new GpxFileTrackImporter(context, contentProviderUtils);
|
||||||
long trackId = gpxFileTrackImporter.importFile(inputStream);
|
long trackId = gpxFileTrackImporter.importFile(inputStream);
|
||||||
|
|
||||||
|
// then
|
||||||
Assert.assertEquals(TRACK_ID_0, trackId);
|
Assert.assertEquals(TRACK_ID_0, trackId);
|
||||||
|
|
||||||
|
verify(contentProviderUtils, atLeastOnce()).updateTrack(trackCaptor.capture());
|
||||||
long time0 = DATE_FORMAT_0.parse(TRACK_TIME_0).getTime();
|
long time0 = DATE_FORMAT_0.parse(TRACK_TIME_0).getTime();
|
||||||
long time1 = DATE_FORMAT_1.parse(TRACK_TIME_1).getTime();
|
long time1 = DATE_FORMAT_1.parse(TRACK_TIME_1).getTime();
|
||||||
Assert.assertEquals(time1 - time0, trackCaptor.getValue().getTripStatistics().getTotalTime());
|
Assert.assertEquals(time1 - time0, trackCaptor.getValue().getTripStatistics().getTotalTime());
|
||||||
verify(contentProviderUtils);
|
|
||||||
verifyTrack(trackCaptor.getValue(), TRACK_NAME_0, TRACK_DESCRIPTION_0, time0);
|
verifyTrack(trackCaptor.getValue(), TRACK_NAME_0, TRACK_DESCRIPTION_0, time0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testOneTrackTwoSegments() throws Exception {
|
public void testOneTrackTwoSegments() throws Exception {
|
||||||
ArgumentCaptor<Track> trackCaptor = ArgumentCaptor.forClass(Track.class);
|
// given
|
||||||
|
|
||||||
Location location0 = createLocation(0, DATE_FORMAT_0.parse(TRACK_TIME_0).getTime());
|
Location location0 = createLocation(0, DATE_FORMAT_0.parse(TRACK_TIME_0).getTime());
|
||||||
|
|
||||||
when(contentProviderUtils.insertTrack((Track) any())).thenReturn(TRACK_ID_0_URI);
|
when(contentProviderUtils.insertTrack((Track) any())).thenReturn(TRACK_ID_0_URI);
|
||||||
@@ -121,12 +123,18 @@ public class GpxFileTrackImporterTest extends AbstractTestFileTrackImporter {
|
|||||||
// A flush happens at the end
|
// A flush happens at the end
|
||||||
when(contentProviderUtils.bulkInsertTrackPoint((Location[]) any(), eq(5), eq(TRACK_ID_0))).thenReturn(5);
|
when(contentProviderUtils.bulkInsertTrackPoint((Location[]) any(), eq(5), eq(TRACK_ID_0))).thenReturn(5);
|
||||||
when(contentProviderUtils.getLastTrackPointId(TRACK_ID_0)).thenReturn(TRACK_POINT_ID_3);
|
when(contentProviderUtils.getLastTrackPointId(TRACK_ID_0)).thenReturn(TRACK_POINT_ID_3);
|
||||||
when(contentProviderUtils.getTrack(PreferencesUtils.getLong(context, R.string.recording_track_id_key))).thenReturn(null);
|
when(contentProviderUtils.getTrack(PreferencesUtils.getRecordingTrackId(context))).thenReturn(null);
|
||||||
expectUpdateTrack(trackCaptor, true, TRACK_ID_0);
|
|
||||||
|
|
||||||
|
ArgumentCaptor<Track> trackCaptor = ArgumentCaptor.forClass(Track.class);
|
||||||
|
expectTrackUpdate(trackCaptor, true, TRACK_ID_0);
|
||||||
|
|
||||||
|
// when
|
||||||
InputStream inputStream = new ByteArrayInputStream(VALID_ONE_TRACK_TWO_SEGMENTS_GPX.getBytes());
|
InputStream inputStream = new ByteArrayInputStream(VALID_ONE_TRACK_TWO_SEGMENTS_GPX.getBytes());
|
||||||
GpxFileTrackImporter gpxFileTrackImporter = new GpxFileTrackImporter(context, contentProviderUtils);
|
GpxFileTrackImporter gpxFileTrackImporter = new GpxFileTrackImporter(context, contentProviderUtils);
|
||||||
long trackId = gpxFileTrackImporter.importFile(inputStream);
|
long trackId = gpxFileTrackImporter.importFile(inputStream);
|
||||||
|
|
||||||
|
// then
|
||||||
|
verify(contentProviderUtils, atLeastOnce()).updateTrack(trackCaptor.capture());
|
||||||
Assert.assertEquals(TRACK_ID_0, trackId);
|
Assert.assertEquals(TRACK_ID_0, trackId);
|
||||||
|
|
||||||
long time0 = DATE_FORMAT_0.parse(TRACK_TIME_0).getTime();
|
long time0 = DATE_FORMAT_0.parse(TRACK_TIME_0).getTime();
|
||||||
@@ -135,30 +143,33 @@ public class GpxFileTrackImporterTest extends AbstractTestFileTrackImporter {
|
|||||||
long time3 = DATE_FORMAT_1.parse(TRACK_TIME_3).getTime();
|
long time3 = DATE_FORMAT_1.parse(TRACK_TIME_3).getTime();
|
||||||
Assert.assertEquals(time1 - time0 + time3 - time2, trackCaptor.getValue().getTripStatistics().getTotalTime());
|
Assert.assertEquals(time1 - time0 + time3 - time2, trackCaptor.getValue().getTripStatistics().getTotalTime());
|
||||||
|
|
||||||
verify(contentProviderUtils);
|
|
||||||
verifyTrack(trackCaptor.getValue(), TRACK_NAME_0, TRACK_DESCRIPTION_0, DATE_FORMAT_0.parse(TRACK_TIME_0).getTime());
|
verifyTrack(trackCaptor.getValue(), TRACK_NAME_0, TRACK_DESCRIPTION_0, DATE_FORMAT_0.parse(TRACK_TIME_0).getTime());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testOneTrackTwoSegmentsNoTime() {
|
public void testOneTrackTwoSegmentsNoTime() {
|
||||||
ArgumentCaptor<Track> trackCaptor = ArgumentCaptor.forClass(Track.class);
|
// given
|
||||||
|
|
||||||
when(contentProviderUtils.insertTrack((Track) any())).thenReturn(TRACK_ID_0_URI);
|
when(contentProviderUtils.insertTrack((Track) any())).thenReturn(TRACK_ID_0_URI);
|
||||||
expectFirstTrackPoint(null, TRACK_ID_0, TRACK_POINT_ID_0);
|
expectFirstTrackPoint(null, TRACK_ID_0, TRACK_POINT_ID_0);
|
||||||
|
|
||||||
// A flush happens at the end
|
// A flush happens at the end
|
||||||
when(contentProviderUtils.bulkInsertTrackPoint((Location[]) any(), eq(5), eq(TRACK_ID_0))).thenReturn(5);
|
when(contentProviderUtils.bulkInsertTrackPoint((Location[]) any(), eq(5), eq(TRACK_ID_0))).thenReturn(5);
|
||||||
when(contentProviderUtils.getLastTrackPointId(TRACK_ID_0)).thenReturn(TRACK_POINT_ID_3);
|
when(contentProviderUtils.getLastTrackPointId(TRACK_ID_0)).thenReturn(TRACK_POINT_ID_3);
|
||||||
when(contentProviderUtils.getTrack(PreferencesUtils.getLong(context, R.string.recording_track_id_key))).thenReturn(null);
|
when(contentProviderUtils.getTrack(PreferencesUtils.getRecordingTrackId(context))).thenReturn(null);
|
||||||
expectUpdateTrack(trackCaptor, true, TRACK_ID_0);
|
|
||||||
|
|
||||||
|
ArgumentCaptor<Track> trackCaptor = ArgumentCaptor.forClass(Track.class);
|
||||||
|
expectTrackUpdate(trackCaptor, true, TRACK_ID_0);
|
||||||
|
|
||||||
|
// when
|
||||||
InputStream inputStream = new ByteArrayInputStream(VALID_ONE_TRACK_TWO_SEGMENTS_NO_TIME_GPX.getBytes());
|
InputStream inputStream = new ByteArrayInputStream(VALID_ONE_TRACK_TWO_SEGMENTS_NO_TIME_GPX.getBytes());
|
||||||
GpxFileTrackImporter gpxFileTrackImporter = new GpxFileTrackImporter(context, contentProviderUtils);
|
GpxFileTrackImporter gpxFileTrackImporter = new GpxFileTrackImporter(context, contentProviderUtils);
|
||||||
long trackId = gpxFileTrackImporter.importFile(inputStream);
|
long trackId = gpxFileTrackImporter.importFile(inputStream);
|
||||||
Assert.assertEquals(TRACK_ID_0, trackId);
|
|
||||||
Assert.assertEquals(0, trackCaptor.getValue().getTripStatistics().getTotalTime());
|
|
||||||
|
|
||||||
verify(contentProviderUtils);
|
// then
|
||||||
|
verify(contentProviderUtils, atLeastOnce()).updateTrack(trackCaptor.capture());
|
||||||
|
Assert.assertEquals(TRACK_ID_0, trackId);
|
||||||
|
|
||||||
|
Assert.assertEquals(0, trackCaptor.getValue().getTripStatistics().getTotalTime());
|
||||||
verifyTrack(trackCaptor.getValue(), TRACK_NAME_0, TRACK_DESCRIPTION_0, -1L);
|
verifyTrack(trackCaptor.getValue(), TRACK_NAME_0, TRACK_DESCRIPTION_0, -1L);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -197,9 +208,7 @@ public class GpxFileTrackImporterTest extends AbstractTestFileTrackImporter {
|
|||||||
|
|
||||||
// For the following, use StubReturn since we don't care whether they are invoked or not.
|
// For the following, use StubReturn since we don't care whether they are invoked or not.
|
||||||
when(contentProviderUtils.bulkInsertTrackPoint((Location[]) any(), anyInt(), anyLong())).thenReturn(1);
|
when(contentProviderUtils.bulkInsertTrackPoint((Location[]) any(), anyInt(), anyLong())).thenReturn(1);
|
||||||
when(contentProviderUtils.getFirstTrackPointId(TRACK_ID_0)).thenReturn(TRACK_POINT_ID_0);
|
when(contentProviderUtils.getTrack(PreferencesUtils.getRecordingTrackId(context))).thenReturn(null);
|
||||||
when(contentProviderUtils.getLastTrackPointId(TRACK_ID_0)).thenReturn(TRACK_POINT_ID_0);
|
|
||||||
when(contentProviderUtils.getTrack(PreferencesUtils.getLong(context, R.string.recording_track_id_key))).thenReturn(null);
|
|
||||||
contentProviderUtils.deleteTrack(context, TRACK_ID_0);
|
contentProviderUtils.deleteTrack(context, TRACK_ID_0);
|
||||||
|
|
||||||
InputStream inputStream = new ByteArrayInputStream(xml.getBytes());
|
InputStream inputStream = new ByteArrayInputStream(xml.getBytes());
|
||||||
|
|||||||
@@ -27,11 +27,11 @@ import org.mockito.junit.MockitoJUnitRunner;
|
|||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
||||||
import de.dennisguse.opentracks.R;
|
import de.dennisguse.opentracks.content.data.Track;
|
||||||
import de.dennisguse.opentracks.content.Track;
|
|
||||||
import de.dennisguse.opentracks.util.PreferencesUtils;
|
import de.dennisguse.opentracks.util.PreferencesUtils;
|
||||||
|
|
||||||
import static org.mockito.Mockito.any;
|
import static org.mockito.Mockito.any;
|
||||||
|
import static org.mockito.Mockito.atLeastOnce;
|
||||||
import static org.mockito.Mockito.eq;
|
import static org.mockito.Mockito.eq;
|
||||||
import static org.mockito.Mockito.verify;
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
@@ -68,8 +68,7 @@ public class KmlFileTrackImporterTest extends AbstractTestFileTrackImporter {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testOneTrackOneSegment() throws Exception {
|
public void testOneTrackOneSegment() throws Exception {
|
||||||
ArgumentCaptor<Track> trackCaptor = ArgumentCaptor.forClass(Track.class);
|
// given
|
||||||
|
|
||||||
Location location0 = createLocation(0, DATE_FORMAT_0.parse(TRACK_TIME_0).getTime());
|
Location location0 = createLocation(0, DATE_FORMAT_0.parse(TRACK_TIME_0).getTime());
|
||||||
Location location1 = createLocation(1, DATE_FORMAT_1.parse(TRACK_TIME_1).getTime());
|
Location location1 = createLocation(1, DATE_FORMAT_1.parse(TRACK_TIME_1).getTime());
|
||||||
|
|
||||||
@@ -77,27 +76,31 @@ public class KmlFileTrackImporterTest extends AbstractTestFileTrackImporter {
|
|||||||
expectFirstTrackPoint(location0, TRACK_ID_0, TRACK_POINT_ID_0);
|
expectFirstTrackPoint(location0, TRACK_ID_0, TRACK_POINT_ID_0);
|
||||||
|
|
||||||
// A flush happens at the end
|
// A flush happens at the end
|
||||||
when(contentProviderUtils.bulkInsertTrackPoint(new Location[]{location1}, eq(1), eq(TRACK_ID_0))).thenReturn(1);
|
when(contentProviderUtils.bulkInsertTrackPoint((Location[]) any(), eq(1), eq(TRACK_ID_0))).thenReturn(1);
|
||||||
when(contentProviderUtils.getLastTrackPointId(TRACK_ID_0)).thenReturn(TRACK_POINT_ID_1);
|
when(contentProviderUtils.getLastTrackPointId(TRACK_ID_0)).thenReturn(TRACK_POINT_ID_1);
|
||||||
when(contentProviderUtils.getTrack(PreferencesUtils.getLong(context, R.string.recording_track_id_key))).thenReturn(null);
|
when(contentProviderUtils.getTrack(PreferencesUtils.getRecordingTrackId(context))).thenReturn(null);
|
||||||
expectUpdateTrack(trackCaptor, true, TRACK_ID_0);
|
|
||||||
|
|
||||||
|
ArgumentCaptor<Track> trackCaptor = ArgumentCaptor.forClass(Track.class);
|
||||||
|
expectTrackUpdate(trackCaptor, true, TRACK_ID_0);
|
||||||
|
|
||||||
|
// when
|
||||||
InputStream inputStream = new ByteArrayInputStream(VALID_ONE_TRACK_ONE_SEGMENT_GPX.getBytes());
|
InputStream inputStream = new ByteArrayInputStream(VALID_ONE_TRACK_ONE_SEGMENT_GPX.getBytes());
|
||||||
KmlFileTrackImporter kmlFileTrackImporter = new KmlFileTrackImporter(context, TRACK_ID_0, contentProviderUtils);
|
KmlFileTrackImporter kmlFileTrackImporter = new KmlFileTrackImporter(context, TRACK_ID_0, contentProviderUtils);
|
||||||
long trackId = kmlFileTrackImporter.importFile(inputStream);
|
long trackId = kmlFileTrackImporter.importFile(inputStream);
|
||||||
|
|
||||||
|
// then
|
||||||
|
verify(contentProviderUtils, atLeastOnce()).updateTrack(trackCaptor.capture());
|
||||||
Assert.assertEquals(TRACK_ID_0, trackId);
|
Assert.assertEquals(TRACK_ID_0, trackId);
|
||||||
|
|
||||||
long time0 = DATE_FORMAT_0.parse(TRACK_TIME_0).getTime();
|
long time0 = DATE_FORMAT_0.parse(TRACK_TIME_0).getTime();
|
||||||
long time1 = DATE_FORMAT_1.parse(TRACK_TIME_1).getTime();
|
long time1 = DATE_FORMAT_1.parse(TRACK_TIME_1).getTime();
|
||||||
Assert.assertEquals(time1 - time0, trackCaptor.getValue().getTripStatistics().getTotalTime());
|
Assert.assertEquals(time1 - time0, trackCaptor.getValue().getTripStatistics().getTotalTime());
|
||||||
verify(contentProviderUtils);
|
|
||||||
verifyTrack(trackCaptor.getValue(), TRACK_NAME_0, TRACK_DESCRIPTION_0, time0);
|
verifyTrack(trackCaptor.getValue(), TRACK_NAME_0, TRACK_DESCRIPTION_0, time0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testOneTrackTwoSegments() throws Exception {
|
public void testOneTrackTwoSegments() throws Exception {
|
||||||
ArgumentCaptor<Track> trackCaptor = ArgumentCaptor.forClass(Track.class);
|
// given
|
||||||
|
|
||||||
Location location0 = createLocation(0, DATE_FORMAT_0.parse(TRACK_TIME_0).getTime());
|
Location location0 = createLocation(0, DATE_FORMAT_0.parse(TRACK_TIME_0).getTime());
|
||||||
|
|
||||||
contentProviderUtils.clearTrack(context, TRACK_ID_0);
|
contentProviderUtils.clearTrack(context, TRACK_ID_0);
|
||||||
@@ -106,12 +109,18 @@ public class KmlFileTrackImporterTest extends AbstractTestFileTrackImporter {
|
|||||||
// A flush happens at the end
|
// A flush happens at the end
|
||||||
when(contentProviderUtils.bulkInsertTrackPoint((Location[]) any(), eq(5), eq(TRACK_ID_0))).thenReturn(5);
|
when(contentProviderUtils.bulkInsertTrackPoint((Location[]) any(), eq(5), eq(TRACK_ID_0))).thenReturn(5);
|
||||||
when(contentProviderUtils.getLastTrackPointId(TRACK_ID_0)).thenReturn(TRACK_POINT_ID_3);
|
when(contentProviderUtils.getLastTrackPointId(TRACK_ID_0)).thenReturn(TRACK_POINT_ID_3);
|
||||||
when(contentProviderUtils.getTrack(PreferencesUtils.getLong(context, R.string.recording_track_id_key))).thenReturn(null);
|
when(contentProviderUtils.getTrack(PreferencesUtils.getRecordingTrackId(context))).thenReturn(null);
|
||||||
expectUpdateTrack(trackCaptor, true, TRACK_ID_0);
|
|
||||||
|
|
||||||
|
ArgumentCaptor<Track> trackCaptor = ArgumentCaptor.forClass(Track.class);
|
||||||
|
expectTrackUpdate(trackCaptor, true, TRACK_ID_0);
|
||||||
|
|
||||||
|
// when
|
||||||
InputStream inputStream = new ByteArrayInputStream(VALID_ONE_TRACK_TWO_SEGMENTS_GPX.getBytes());
|
InputStream inputStream = new ByteArrayInputStream(VALID_ONE_TRACK_TWO_SEGMENTS_GPX.getBytes());
|
||||||
KmlFileTrackImporter kmlFileTrackImporter = new KmlFileTrackImporter(context, TRACK_ID_0, contentProviderUtils);
|
KmlFileTrackImporter kmlFileTrackImporter = new KmlFileTrackImporter(context, TRACK_ID_0, contentProviderUtils);
|
||||||
long trackId = kmlFileTrackImporter.importFile(inputStream);
|
long trackId = kmlFileTrackImporter.importFile(inputStream);
|
||||||
|
|
||||||
|
// then
|
||||||
|
verify(contentProviderUtils, atLeastOnce()).updateTrack(trackCaptor.capture());
|
||||||
Assert.assertEquals(TRACK_ID_0, trackId);
|
Assert.assertEquals(TRACK_ID_0, trackId);
|
||||||
|
|
||||||
long time0 = DATE_FORMAT_0.parse(TRACK_TIME_0).getTime();
|
long time0 = DATE_FORMAT_0.parse(TRACK_TIME_0).getTime();
|
||||||
@@ -120,7 +129,6 @@ public class KmlFileTrackImporterTest extends AbstractTestFileTrackImporter {
|
|||||||
long time3 = DATE_FORMAT_1.parse(TRACK_TIME_3).getTime();
|
long time3 = DATE_FORMAT_1.parse(TRACK_TIME_3).getTime();
|
||||||
Assert.assertEquals(time1 - time0 + time3 - time2, trackCaptor.getValue().getTripStatistics().getTotalTime());
|
Assert.assertEquals(time1 - time0 + time3 - time2, trackCaptor.getValue().getTripStatistics().getTotalTime());
|
||||||
|
|
||||||
verify(contentProviderUtils);
|
|
||||||
verifyTrack(trackCaptor.getValue(), TRACK_NAME_0, TRACK_DESCRIPTION_0, DATE_FORMAT_0.parse(TRACK_TIME_0).getTime());
|
verifyTrack(trackCaptor.getValue(), TRACK_NAME_0, TRACK_DESCRIPTION_0, DATE_FORMAT_0.parse(TRACK_TIME_0).getTime());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,14 +15,19 @@
|
|||||||
*/
|
*/
|
||||||
package de.dennisguse.opentracks.services;
|
package de.dennisguse.opentracks.services;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import org.junit.Assert;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.junit.runners.JUnit4;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests the {@link AdaptiveLocationListenerPolicy}.
|
* Tests the {@link AdaptiveLocationListenerPolicy}.
|
||||||
*
|
*
|
||||||
* @author youtaol
|
* @author youtaol
|
||||||
*/
|
*/
|
||||||
public class AdaptiveLocationListenerPolicyTest extends TestCase {
|
@RunWith(JUnit4.class)
|
||||||
|
public class AdaptiveLocationListenerPolicyTest {
|
||||||
|
|
||||||
private static final long MIN = 1000;
|
private static final long MIN = 1000;
|
||||||
private static final long MAX = 3000;
|
private static final long MAX = 3000;
|
||||||
@@ -31,12 +36,11 @@ public class AdaptiveLocationListenerPolicyTest extends TestCase {
|
|||||||
private static final long NEW_IDLE_TIME_NORMAL = 5000;
|
private static final long NEW_IDLE_TIME_NORMAL = 5000;
|
||||||
private static final long NEW_IDLE_TIME_SMALL = 2000;
|
private static final long NEW_IDLE_TIME_SMALL = 2000;
|
||||||
private static final long NEW_IDLE_TIME_LESS_THAN_MIN = 500;
|
private static final long NEW_IDLE_TIME_LESS_THAN_MIN = 500;
|
||||||
private AdaptiveLocationListenerPolicy adocationListenerPolicy;
|
private AdaptiveLocationListenerPolicy adaptiveLocationListenerPolicy;
|
||||||
|
|
||||||
@Override
|
@Before
|
||||||
protected void setUp() throws Exception {
|
public void setUp() {
|
||||||
super.setUp();
|
adaptiveLocationListenerPolicy = new AdaptiveLocationListenerPolicy(MIN, MAX, MIN_DISTANCE);
|
||||||
adocationListenerPolicy = new AdaptiveLocationListenerPolicy(MIN, MAX, MIN_DISTANCE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -48,27 +52,27 @@ public class AdaptiveLocationListenerPolicyTest extends TestCase {
|
|||||||
* <li>The newIdleTime is smaller than the smallest interval unit.</li>
|
* <li>The newIdleTime is smaller than the smallest interval unit.</li>
|
||||||
* </ul>
|
* </ul>
|
||||||
*/
|
*/
|
||||||
|
@Test
|
||||||
public void testGetDesiredPollingInterval() {
|
public void testGetDesiredPollingInterval() {
|
||||||
adocationListenerPolicy.updateIdleTime(NEW_IDLE_TIME_BIG);
|
adaptiveLocationListenerPolicy.updateIdleTime(NEW_IDLE_TIME_BIG);
|
||||||
assertEquals(MAX, adocationListenerPolicy.getDesiredPollingInterval());
|
Assert.assertEquals(MAX, adaptiveLocationListenerPolicy.getDesiredPollingInterval());
|
||||||
|
|
||||||
adocationListenerPolicy.updateIdleTime(NEW_IDLE_TIME_NORMAL);
|
adaptiveLocationListenerPolicy.updateIdleTime(NEW_IDLE_TIME_NORMAL);
|
||||||
// First get the half of NEW_IDLE_TIME_NORMAL, and then round it to the
|
// First get the half of NEW_IDLE_TIME_NORMAL, and then round it to the nearest second.
|
||||||
// nearest second.
|
Assert.assertEquals((NEW_IDLE_TIME_NORMAL / 2 / 1000) * 1000, adaptiveLocationListenerPolicy.getDesiredPollingInterval());
|
||||||
assertEquals((NEW_IDLE_TIME_NORMAL / 2 / 1000) * 1000,
|
|
||||||
adocationListenerPolicy.getDesiredPollingInterval());
|
|
||||||
|
|
||||||
adocationListenerPolicy.updateIdleTime(NEW_IDLE_TIME_SMALL);
|
adaptiveLocationListenerPolicy.updateIdleTime(NEW_IDLE_TIME_SMALL);
|
||||||
assertEquals(MIN, adocationListenerPolicy.getDesiredPollingInterval());
|
Assert.assertEquals(MIN, adaptiveLocationListenerPolicy.getDesiredPollingInterval());
|
||||||
|
|
||||||
adocationListenerPolicy.updateIdleTime(NEW_IDLE_TIME_LESS_THAN_MIN);
|
adaptiveLocationListenerPolicy.updateIdleTime(NEW_IDLE_TIME_LESS_THAN_MIN);
|
||||||
assertEquals(MIN, adocationListenerPolicy.getDesiredPollingInterval());
|
Assert.assertEquals(MIN, adaptiveLocationListenerPolicy.getDesiredPollingInterval());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests the method {@link AdaptiveLocationListenerPolicy#getMinDistance_m()}.
|
* Tests the method {@link AdaptiveLocationListenerPolicy#getMinDistance_m()}.
|
||||||
*/
|
*/
|
||||||
|
@Test
|
||||||
public void testGetMinDistance() {
|
public void testGetMinDistance() {
|
||||||
assertEquals(MIN_DISTANCE, adocationListenerPolicy.getMinDistance_m());
|
Assert.assertEquals(MIN_DISTANCE, adaptiveLocationListenerPolicy.getMinDistance_m());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -15,14 +15,12 @@
|
|||||||
*/
|
*/
|
||||||
package de.dennisguse.opentracks.services;
|
package de.dennisguse.opentracks.services;
|
||||||
|
|
||||||
import android.content.BroadcastReceiver;
|
|
||||||
import android.content.ContentProvider;
|
import android.content.ContentProvider;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.location.Location;
|
import android.location.Location;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
import androidx.test.core.app.ApplicationProvider;
|
import androidx.test.core.app.ApplicationProvider;
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||||
@@ -38,7 +36,6 @@ import org.junit.Rule;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
@@ -47,10 +44,8 @@ import java.util.concurrent.TimeoutException;
|
|||||||
import de.dennisguse.opentracks.R;
|
import de.dennisguse.opentracks.R;
|
||||||
import de.dennisguse.opentracks.content.ContentProviderUtils;
|
import de.dennisguse.opentracks.content.ContentProviderUtils;
|
||||||
import de.dennisguse.opentracks.content.CustomContentProvider;
|
import de.dennisguse.opentracks.content.CustomContentProvider;
|
||||||
import de.dennisguse.opentracks.content.Track;
|
import de.dennisguse.opentracks.content.data.Track;
|
||||||
import de.dennisguse.opentracks.content.Waypoint;
|
import de.dennisguse.opentracks.content.data.Waypoint;
|
||||||
import de.dennisguse.opentracks.content.Waypoint.WaypointType;
|
|
||||||
import de.dennisguse.opentracks.content.WaypointCreationRequest;
|
|
||||||
import de.dennisguse.opentracks.stats.TripStatistics;
|
import de.dennisguse.opentracks.stats.TripStatistics;
|
||||||
import de.dennisguse.opentracks.util.PreferencesUtils;
|
import de.dennisguse.opentracks.util.PreferencesUtils;
|
||||||
|
|
||||||
@@ -59,7 +54,7 @@ import de.dennisguse.opentracks.util.PreferencesUtils;
|
|||||||
*
|
*
|
||||||
* @author Bartlomiej Niechwiej
|
* @author Bartlomiej Niechwiej
|
||||||
* <p>
|
* <p>
|
||||||
* ATTENTION: This tests deletes all stored tracks in the database.
|
* //TODO ATTENTION: This tests deletes all stored tracks in the database.
|
||||||
* So, if it is executed on a real device, data might be lost.
|
* So, if it is executed on a real device, data might be lost.
|
||||||
*/
|
*/
|
||||||
@RunWith(AndroidJUnit4.class)
|
@RunWith(AndroidJUnit4.class)
|
||||||
@@ -72,19 +67,12 @@ public class TrackRecordingServiceTest {
|
|||||||
public GrantPermissionRule mRuntimePermissionRule = GrantPermissionRule.grant(android.Manifest.permission.ACCESS_FINE_LOCATION);
|
public GrantPermissionRule mRuntimePermissionRule = GrantPermissionRule.grant(android.Manifest.permission.ACCESS_FINE_LOCATION);
|
||||||
|
|
||||||
private Context context = ApplicationProvider.getApplicationContext();
|
private Context context = ApplicationProvider.getApplicationContext();
|
||||||
private ContentProviderUtils providerUtils;
|
private ContentProviderUtils contentProviderUtils;
|
||||||
|
|
||||||
private long trackId = Math.abs(new Random().nextLong());
|
private final long trackId = Math.abs(new Random().nextLong());
|
||||||
|
|
||||||
static Intent createStartIntent(Context context) {
|
static Intent createStartIntent(Context context) {
|
||||||
Intent startIntent = new Intent();
|
return new Intent(context, TrackRecordingService.class);
|
||||||
startIntent.setClass(context, TrackRecordingService.class);
|
|
||||||
return startIntent;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void updateAutoResumePrefs(Context context, int attempts, int timeoutMins) {
|
|
||||||
PreferencesUtils.setInt(context, R.string.auto_resume_track_current_retry_key, attempts);
|
|
||||||
PreferencesUtils.setInt(context, R.string.auto_resume_track_timeout_key, timeoutMins);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
@@ -94,17 +82,14 @@ public class TrackRecordingServiceTest {
|
|||||||
};
|
};
|
||||||
customContentProvider.attachInfo(context, null);
|
customContentProvider.attachInfo(context, null);
|
||||||
|
|
||||||
providerUtils = ContentProviderUtils.Factory.get(context);
|
contentProviderUtils = new ContentProviderUtils(context);
|
||||||
|
|
||||||
// Let's use default values.
|
// Let's use default values.
|
||||||
SharedPreferences sharedPreferences = PreferencesUtils.getSharedPreferences(context);
|
SharedPreferences sharedPreferences = PreferencesUtils.getSharedPreferences(context);
|
||||||
sharedPreferences.edit().clear().apply();
|
sharedPreferences.edit().clear().apply();
|
||||||
|
|
||||||
// Disable auto resume by default.
|
|
||||||
updateAutoResumePrefs(context, PreferencesUtils.AUTO_RESUME_TRACK_CURRENT_RETRY_DEFAULT, 0);
|
|
||||||
|
|
||||||
// Ensure that the database is empty before every test
|
// Ensure that the database is empty before every test
|
||||||
providerUtils.deleteAllTracks(context);
|
contentProviderUtils.deleteAllTracks(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@After
|
||||||
@@ -116,7 +101,7 @@ public class TrackRecordingServiceTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Ensure that the database is empty after every test
|
// Ensure that the database is empty after every test
|
||||||
providerUtils.deleteAllTracks(context);
|
contentProviderUtils.deleteAllTracks(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SmallTest
|
@SmallTest
|
||||||
@@ -133,121 +118,16 @@ public class TrackRecordingServiceTest {
|
|||||||
Assert.assertNotNull(service);
|
Assert.assertNotNull(service);
|
||||||
}
|
}
|
||||||
|
|
||||||
@MediumTest
|
|
||||||
@Test
|
|
||||||
public void testResumeAfterReboot_shouldResume() throws Exception {
|
|
||||||
// Insert a dummy track and mark it as recording track.
|
|
||||||
createDummyTrack(trackId, System.currentTimeMillis(), true);
|
|
||||||
|
|
||||||
// Clear the number of attempts and set the timeout to 10 min.
|
|
||||||
updateAutoResumePrefs(context, PreferencesUtils.AUTO_RESUME_TRACK_CURRENT_RETRY_DEFAULT, PreferencesUtils.AUTO_RESUME_TRACK_TIMEOUT_DEFAULT);
|
|
||||||
|
|
||||||
// Start the service in "resume" mode (simulates the on-reboot action).
|
|
||||||
Intent startIntent = createStartIntent(context);
|
|
||||||
startIntent.putExtra(TrackRecordingService.RESUME_TRACK_EXTRA_NAME, true);
|
|
||||||
ITrackRecordingService service = ((ITrackRecordingService) mServiceRule.bindService(startIntent));
|
|
||||||
Assert.assertNotNull(service);
|
|
||||||
|
|
||||||
// We expect to resume the previous track.
|
|
||||||
Assert.assertTrue(service.isRecording());
|
|
||||||
Assert.assertEquals(trackId, service.getRecordingTrackId());
|
|
||||||
}
|
|
||||||
|
|
||||||
@MediumTest
|
|
||||||
@Test
|
|
||||||
public void testResumeAfterReboot_simulateReboot() throws Exception {
|
|
||||||
updateAutoResumePrefs(context, PreferencesUtils.AUTO_RESUME_TRACK_CURRENT_RETRY_DEFAULT, PreferencesUtils.AUTO_RESUME_TRACK_TIMEOUT_DEFAULT);
|
|
||||||
ITrackRecordingService service = ((ITrackRecordingService) mServiceRule.bindService(createStartIntent(context)));
|
|
||||||
Assert.assertFalse(service.isRecording());
|
|
||||||
|
|
||||||
// Simulate recording a track.
|
|
||||||
long id = service.startNewTrack();
|
|
||||||
Assert.assertTrue(service.isRecording());
|
|
||||||
Assert.assertEquals(id, service.getRecordingTrackId());
|
|
||||||
mServiceRule.unbindService();
|
|
||||||
Assert.assertEquals(id, PreferencesUtils.getLong(context, R.string.recording_track_id_key));
|
|
||||||
|
|
||||||
// Start the service in "resume" mode (simulates the on-reboot action).
|
|
||||||
Intent startIntent = createStartIntent(context);
|
|
||||||
startIntent.putExtra(TrackRecordingService.RESUME_TRACK_EXTRA_NAME, true);
|
|
||||||
mServiceRule.startService(startIntent);
|
|
||||||
service = ((ITrackRecordingService) mServiceRule.bindService(createStartIntent(context)));
|
|
||||||
Assert.assertNotNull(service);
|
|
||||||
|
|
||||||
Assert.assertTrue(service.isRecording());
|
|
||||||
}
|
|
||||||
|
|
||||||
@MediumTest
|
|
||||||
@Test
|
|
||||||
public void testResumeAfterReboot_noRecordingTrack() throws Exception {
|
|
||||||
// Insert a dummy track and mark it as recording track.
|
|
||||||
createDummyTrack(trackId, System.currentTimeMillis(), false);
|
|
||||||
|
|
||||||
// Clear the number of attempts and set the timeout to 10 min.
|
|
||||||
updateAutoResumePrefs(context, PreferencesUtils.AUTO_RESUME_TRACK_CURRENT_RETRY_DEFAULT, PreferencesUtils.AUTO_RESUME_TRACK_TIMEOUT_DEFAULT);
|
|
||||||
|
|
||||||
// Start the service in "resume" mode (simulates the on-reboot action).
|
|
||||||
Intent startIntent = createStartIntent(context);
|
|
||||||
startIntent.putExtra(TrackRecordingService.RESUME_TRACK_EXTRA_NAME, true);
|
|
||||||
ITrackRecordingService service = ((ITrackRecordingService) mServiceRule.bindService(startIntent));
|
|
||||||
Assert.assertNotNull(service);
|
|
||||||
|
|
||||||
// We don't expect to resume the previous track, because it was stopped.
|
|
||||||
Assert.assertFalse(service.isRecording());
|
|
||||||
Assert.assertEquals(-1L, service.getRecordingTrackId());
|
|
||||||
}
|
|
||||||
|
|
||||||
@MediumTest
|
|
||||||
@Test
|
|
||||||
public void testResumeAfterReboot_expiredTrack() throws Exception {
|
|
||||||
// Insert a dummy track last updated 20 min ago.
|
|
||||||
createDummyTrack(trackId, System.currentTimeMillis() - 20 * 60 * 1000, true);
|
|
||||||
|
|
||||||
// Clear the number of attempts and set the timeout to 10 min.
|
|
||||||
updateAutoResumePrefs(context, PreferencesUtils.AUTO_RESUME_TRACK_CURRENT_RETRY_DEFAULT, PreferencesUtils.AUTO_RESUME_TRACK_TIMEOUT_DEFAULT);
|
|
||||||
|
|
||||||
// Start the service in "resume" mode (simulates the on-reboot action).
|
|
||||||
Intent startIntent = createStartIntent(context);
|
|
||||||
startIntent.putExtra(TrackRecordingService.RESUME_TRACK_EXTRA_NAME, true);
|
|
||||||
ITrackRecordingService service = ((ITrackRecordingService) mServiceRule.bindService(startIntent));
|
|
||||||
Assert.assertNotNull(service);
|
|
||||||
|
|
||||||
// We don't expect to resume the previous track, because it has expired.
|
|
||||||
Assert.assertFalse(service.isRecording());
|
|
||||||
Assert.assertEquals(PreferencesUtils.RECORDING_TRACK_ID_DEFAULT, service.getRecordingTrackId());
|
|
||||||
}
|
|
||||||
|
|
||||||
@MediumTest
|
|
||||||
@Test
|
|
||||||
public void testResumeAfterReboot_tooManyAttempts() throws Exception {
|
|
||||||
// Insert a dummy track.
|
|
||||||
createDummyTrack(trackId, System.currentTimeMillis(), true);
|
|
||||||
|
|
||||||
// Set the number of attempts to max.
|
|
||||||
updateAutoResumePrefs(context, TrackRecordingService.MAX_AUTO_RESUME_TRACK_RETRY_ATTEMPTS, PreferencesUtils.AUTO_RESUME_TRACK_TIMEOUT_DEFAULT);
|
|
||||||
|
|
||||||
// Start the service in "resume" mode (simulates the on-reboot action).
|
|
||||||
Intent startIntent = createStartIntent(context);
|
|
||||||
startIntent.putExtra(TrackRecordingService.RESUME_TRACK_EXTRA_NAME, true);
|
|
||||||
|
|
||||||
//Explicit start service, so `startCommand()` is executed - which would be called by BootReceiver.
|
|
||||||
context.startService(startIntent);
|
|
||||||
|
|
||||||
ITrackRecordingService service = ((ITrackRecordingService) mServiceRule.bindService(startIntent));
|
|
||||||
Assert.assertNotNull(service);
|
|
||||||
|
|
||||||
// We don't expect to resume the previous track, because there were already too many attempts.
|
|
||||||
Assert.assertFalse(service.isRecording());
|
|
||||||
Assert.assertEquals(PreferencesUtils.RECORDING_TRACK_ID_DEFAULT, service.getRecordingTrackId());
|
|
||||||
}
|
|
||||||
|
|
||||||
@MediumTest
|
@MediumTest
|
||||||
@Test
|
@Test
|
||||||
public void testRecording_noTracks() throws Exception {
|
public void testRecording_noTracks() throws Exception {
|
||||||
List<Track> tracks = providerUtils.getAllTracks();
|
List<Track> tracks = contentProviderUtils.getAllTracks();
|
||||||
Assert.assertTrue(tracks.isEmpty());
|
Assert.assertTrue(tracks.isEmpty());
|
||||||
|
|
||||||
ITrackRecordingService service = ((ITrackRecordingService) mServiceRule.bindService(createStartIntent(context)));
|
Intent startIntent = createStartIntent(context);
|
||||||
|
mServiceRule.startService(startIntent);
|
||||||
|
ITrackRecordingService service = ((ITrackRecordingService) mServiceRule.bindService(startIntent));
|
||||||
|
|
||||||
// Test if we start in no-recording mode by default.
|
// Test if we start in no-recording mode by default.
|
||||||
Assert.assertFalse(service.isRecording());
|
Assert.assertFalse(service.isRecording());
|
||||||
Assert.assertEquals(-1L, service.getRecordingTrackId());
|
Assert.assertEquals(-1L, service.getRecordingTrackId());
|
||||||
@@ -266,11 +146,14 @@ public class TrackRecordingServiceTest {
|
|||||||
@MediumTest
|
@MediumTest
|
||||||
@Test
|
@Test
|
||||||
public void testRecording_orphanedRecordingTrack() throws Exception {
|
public void testRecording_orphanedRecordingTrack() throws Exception {
|
||||||
|
Intent startIntent = createStartIntent(context);
|
||||||
|
ITrackRecordingService service = ((ITrackRecordingService) mServiceRule.bindService(startIntent));
|
||||||
|
|
||||||
// Just set recording track to a bogus value.
|
// Just set recording track to a bogus value.
|
||||||
|
// Make sure that the service will not start recording and will clear the bogus track.
|
||||||
PreferencesUtils.setLong(context, R.string.recording_track_id_key, 123L);
|
PreferencesUtils.setLong(context, R.string.recording_track_id_key, 123L);
|
||||||
|
|
||||||
// Make sure that the service will not start recording and will clear the bogus track.
|
// then
|
||||||
ITrackRecordingService service = ((ITrackRecordingService) mServiceRule.bindService(createStartIntent(context)));
|
|
||||||
Assert.assertFalse(service.isRecording());
|
Assert.assertFalse(service.isRecording());
|
||||||
Assert.assertEquals(PreferencesUtils.RECORDING_TRACK_ID_DEFAULT, service.getRecordingTrackId());
|
Assert.assertEquals(PreferencesUtils.RECORDING_TRACK_ID_DEFAULT, service.getRecordingTrackId());
|
||||||
}
|
}
|
||||||
@@ -278,16 +161,18 @@ public class TrackRecordingServiceTest {
|
|||||||
@MediumTest
|
@MediumTest
|
||||||
@Test
|
@Test
|
||||||
public void testStartNewTrack_alreadyRecording() throws Exception {
|
public void testStartNewTrack_alreadyRecording() throws Exception {
|
||||||
createDummyTrack(trackId, -1L, true);
|
|
||||||
|
|
||||||
ITrackRecordingService service = ((ITrackRecordingService) mServiceRule.bindService(createStartIntent(context)));
|
ITrackRecordingService service = ((ITrackRecordingService) mServiceRule.bindService(createStartIntent(context)));
|
||||||
|
service.startNewTrack();
|
||||||
Assert.assertTrue(service.isRecording());
|
Assert.assertTrue(service.isRecording());
|
||||||
|
long trackId = service.getRecordingTrackId();
|
||||||
|
|
||||||
long newTrackId = service.startNewTrack();
|
long newTrackId = service.startNewTrack();
|
||||||
Assert.assertEquals(PreferencesUtils.RECORDING_TRACK_ID_DEFAULT, newTrackId);
|
Assert.assertEquals(PreferencesUtils.RECORDING_TRACK_ID_DEFAULT, newTrackId);
|
||||||
|
|
||||||
Assert.assertEquals(trackId, PreferencesUtils.getLong(context, R.string.recording_track_id_key));
|
Assert.assertEquals(trackId, PreferencesUtils.getRecordingTrackId(context));
|
||||||
Assert.assertEquals(trackId, service.getRecordingTrackId());
|
Assert.assertEquals(trackId, service.getRecordingTrackId());
|
||||||
|
|
||||||
|
service.endCurrentTrack();
|
||||||
}
|
}
|
||||||
|
|
||||||
@MediumTest
|
@MediumTest
|
||||||
@@ -299,48 +184,11 @@ public class TrackRecordingServiceTest {
|
|||||||
// Ending the current track when there is no recording should not result in any error.
|
// Ending the current track when there is no recording should not result in any error.
|
||||||
service.endCurrentTrack();
|
service.endCurrentTrack();
|
||||||
|
|
||||||
Assert.assertEquals(PreferencesUtils.RECORDING_TRACK_ID_DEFAULT, PreferencesUtils.getLong(context, R.string.recording_track_id_key));
|
Assert.assertFalse(PreferencesUtils.isRecording(context));
|
||||||
Assert.assertEquals(PreferencesUtils.RECORDING_TRACK_ID_DEFAULT, service.getRecordingTrackId());
|
Assert.assertEquals(PreferencesUtils.RECORDING_TRACK_ID_DEFAULT, service.getRecordingTrackId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@MediumTest
|
// NOTE: Do not use to create a track that is currently recording.
|
||||||
@Test
|
|
||||||
public void testInsertStatisticsMarker_noRecordingTrack() throws Exception {
|
|
||||||
ITrackRecordingService service = ((ITrackRecordingService) mServiceRule.bindService(createStartIntent(context)));
|
|
||||||
Assert.assertFalse(service.isRecording());
|
|
||||||
|
|
||||||
long waypointId = service.insertWaypoint(WaypointCreationRequest.DEFAULT_STATISTICS);
|
|
||||||
Assert.assertEquals(-1L, waypointId);
|
|
||||||
}
|
|
||||||
|
|
||||||
@MediumTest
|
|
||||||
@Test
|
|
||||||
public void testInsertStatisticsMarker_validLocation() throws Exception {
|
|
||||||
createDummyTrack(trackId, -1L, true);
|
|
||||||
|
|
||||||
ITrackRecordingService service = ((ITrackRecordingService) mServiceRule.bindService(createStartIntent(context)));
|
|
||||||
Assert.assertTrue(service.isRecording());
|
|
||||||
Assert.assertFalse(service.isPaused());
|
|
||||||
insertLocation(service);
|
|
||||||
|
|
||||||
long waypointId1 = service.insertWaypoint(WaypointCreationRequest.DEFAULT_STATISTICS);
|
|
||||||
Assert.assertNotEquals(-1L, waypointId1);
|
|
||||||
long waypointId2 = service.insertWaypoint(WaypointCreationRequest.DEFAULT_STATISTICS);
|
|
||||||
Assert.assertNotEquals(-1L, waypointId2);
|
|
||||||
|
|
||||||
Waypoint wpt = providerUtils.getWaypoint(waypointId1);
|
|
||||||
Assert.assertEquals(context.getString(R.string.marker_statistics_icon_url), wpt.getIcon());
|
|
||||||
Assert.assertEquals(context.getString(R.string.marker_split_name_format, 0), wpt.getName());
|
|
||||||
Assert.assertEquals(WaypointType.STATISTICS, wpt.getType());
|
|
||||||
Assert.assertEquals(trackId, wpt.getTrackId());
|
|
||||||
Assert.assertEquals(0.0, wpt.getLength(), 0.01);
|
|
||||||
Assert.assertNotNull(wpt.getLocation());
|
|
||||||
Assert.assertNotNull(wpt.getTripStatistics());
|
|
||||||
// TODO check the rest of the params.
|
|
||||||
|
|
||||||
// TODO: Check waypoint 2.
|
|
||||||
}
|
|
||||||
|
|
||||||
private void createDummyTrack(long id, long stopTime, boolean isRecording) {
|
private void createDummyTrack(long id, long stopTime, boolean isRecording) {
|
||||||
Track dummyTrack = new Track();
|
Track dummyTrack = new Track();
|
||||||
dummyTrack.setId(id);
|
dummyTrack.setId(id);
|
||||||
@@ -353,8 +201,8 @@ public class TrackRecordingServiceTest {
|
|||||||
|
|
||||||
private void addTrack(Track track, boolean isRecording) {
|
private void addTrack(Track track, boolean isRecording) {
|
||||||
Assert.assertTrue(track.getId() >= 0);
|
Assert.assertTrue(track.getId() >= 0);
|
||||||
providerUtils.insertTrack(track);
|
contentProviderUtils.insertTrack(track);
|
||||||
Assert.assertEquals(track.getId(), providerUtils.getTrack(track.getId()).getId());
|
Assert.assertEquals(track.getId(), contentProviderUtils.getTrack(track.getId()).getId());
|
||||||
PreferencesUtils.setLong(context, R.string.recording_track_id_key, isRecording ? track.getId() : PreferencesUtils.RECORDING_TRACK_ID_DEFAULT);
|
PreferencesUtils.setLong(context, R.string.recording_track_id_key, isRecording ? track.getId() : PreferencesUtils.RECORDING_TRACK_ID_DEFAULT);
|
||||||
PreferencesUtils.setBoolean(context, R.string.recording_track_paused_key, !isRecording);
|
PreferencesUtils.setBoolean(context, R.string.recording_track_paused_key, !isRecording);
|
||||||
}
|
}
|
||||||
@@ -381,69 +229,28 @@ public class TrackRecordingServiceTest {
|
|||||||
ITrackRecordingService service = ((ITrackRecordingService) mServiceRule.bindService(createStartIntent(context)));
|
ITrackRecordingService service = ((ITrackRecordingService) mServiceRule.bindService(createStartIntent(context)));
|
||||||
Assert.assertFalse(service.isRecording());
|
Assert.assertFalse(service.isRecording());
|
||||||
|
|
||||||
long waypointId = service.insertWaypoint(WaypointCreationRequest.DEFAULT_WAYPOINT);
|
long waypointId = service.insertWaypoint(null, null, null, null);
|
||||||
Assert.assertEquals(-1L, waypointId);
|
Assert.assertEquals(-1L, waypointId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@MediumTest
|
@MediumTest
|
||||||
@Test
|
@Test
|
||||||
public void testInsertWaypointMarker_validWaypoint() throws Exception {
|
public void testInsertWaypointMarker_validWaypoint() throws Exception {
|
||||||
createDummyTrack(trackId, -1L, true);
|
|
||||||
|
|
||||||
ITrackRecordingService service = ((ITrackRecordingService) mServiceRule.bindService(createStartIntent(context)));
|
ITrackRecordingService service = ((ITrackRecordingService) mServiceRule.bindService(createStartIntent(context)));
|
||||||
|
service.startNewTrack();
|
||||||
Assert.assertTrue(service.isRecording());
|
Assert.assertTrue(service.isRecording());
|
||||||
insertLocation(service);
|
insertLocation(service);
|
||||||
|
|
||||||
long waypointId = service.insertWaypoint(WaypointCreationRequest.DEFAULT_WAYPOINT);
|
long trackId = service.getRecordingTrackId();
|
||||||
|
long waypointId = service.insertWaypoint(null, null, null, null);
|
||||||
Assert.assertNotEquals(-1L, waypointId);
|
Assert.assertNotEquals(-1L, waypointId);
|
||||||
Waypoint wpt = providerUtils.getWaypoint(waypointId);
|
Waypoint wpt = contentProviderUtils.getWaypoint(waypointId);
|
||||||
Assert.assertEquals(context.getString(R.string.marker_waypoint_icon_url), wpt.getIcon());
|
Assert.assertEquals(context.getString(R.string.marker_waypoint_icon_url), wpt.getIcon());
|
||||||
Assert.assertEquals(context.getString(R.string.marker_name_format, 1), wpt.getName());
|
Assert.assertEquals(context.getString(R.string.marker_name_format, 1), wpt.getName());
|
||||||
Assert.assertEquals(WaypointType.WAYPOINT, wpt.getType());
|
|
||||||
Assert.assertEquals(trackId, wpt.getTrackId());
|
Assert.assertEquals(trackId, wpt.getTrackId());
|
||||||
Assert.assertEquals(0.0, wpt.getLength(), 0.01);
|
Assert.assertEquals(0.0, wpt.getLength(), 0.01);
|
||||||
Assert.assertNotNull(wpt.getLocation());
|
Assert.assertNotNull(wpt.getLocation());
|
||||||
Assert.assertNull(wpt.getTripStatistics());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
service.endCurrentTrack();
|
||||||
* Synchronous/waitable broadcast receiver to be used in testing.
|
|
||||||
*/
|
|
||||||
private class BlockingBroadcastReceiver extends BroadcastReceiver {
|
|
||||||
private static final long MAX_WAIT_TIME_MS = 3000;
|
|
||||||
private final List<Intent> receivedIntents = new ArrayList<>();
|
|
||||||
|
|
||||||
public List<Intent> getReceivedIntents() {
|
|
||||||
return receivedIntents;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onReceive(Context ctx, Intent intent) {
|
|
||||||
Log.d("Test", "Got broadcast: " + intent);
|
|
||||||
synchronized (receivedIntents) {
|
|
||||||
receivedIntents.add(intent);
|
|
||||||
receivedIntents.notifyAll();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean waitUntilReceived(int receiveCount) {
|
|
||||||
long deadline = System.currentTimeMillis() + MAX_WAIT_TIME_MS;
|
|
||||||
synchronized (receivedIntents) {
|
|
||||||
while (receivedIntents.size() < receiveCount) {
|
|
||||||
try {
|
|
||||||
// Wait releases synchronized lock until it returns
|
|
||||||
receivedIntents.wait(500);
|
|
||||||
} catch (InterruptedException e) {
|
|
||||||
// Do nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
if (System.currentTimeMillis() > deadline) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,8 +27,7 @@ import java.util.concurrent.TimeoutException;
|
|||||||
import de.dennisguse.opentracks.R;
|
import de.dennisguse.opentracks.R;
|
||||||
import de.dennisguse.opentracks.content.ContentProviderUtils;
|
import de.dennisguse.opentracks.content.ContentProviderUtils;
|
||||||
import de.dennisguse.opentracks.content.CustomContentProvider;
|
import de.dennisguse.opentracks.content.CustomContentProvider;
|
||||||
import de.dennisguse.opentracks.content.Track;
|
import de.dennisguse.opentracks.content.data.Track;
|
||||||
import de.dennisguse.opentracks.content.WaypointCreationRequest;
|
|
||||||
import de.dennisguse.opentracks.stats.TripStatistics;
|
import de.dennisguse.opentracks.stats.TripStatistics;
|
||||||
import de.dennisguse.opentracks.util.PreferencesUtils;
|
import de.dennisguse.opentracks.util.PreferencesUtils;
|
||||||
|
|
||||||
@@ -68,15 +67,12 @@ public class TrackRecordingServiceTestLooper {
|
|||||||
};
|
};
|
||||||
customContentProvider.attachInfo(context, null);
|
customContentProvider.attachInfo(context, null);
|
||||||
|
|
||||||
providerUtils = ContentProviderUtils.Factory.get(context);
|
providerUtils = new ContentProviderUtils(context);
|
||||||
|
|
||||||
// Let's use default values.
|
// Let's use default values.
|
||||||
SharedPreferences sharedPreferences = PreferencesUtils.getSharedPreferences(context);
|
SharedPreferences sharedPreferences = PreferencesUtils.getSharedPreferences(context);
|
||||||
sharedPreferences.edit().clear().apply();
|
sharedPreferences.edit().clear().apply();
|
||||||
|
|
||||||
// Disable auto resume by default.
|
|
||||||
TrackRecordingServiceTest.updateAutoResumePrefs(context, PreferencesUtils.AUTO_RESUME_TRACK_CURRENT_RETRY_DEFAULT, 0);
|
|
||||||
|
|
||||||
// Ensure that the database is empty before every test
|
// Ensure that the database is empty before every test
|
||||||
providerUtils.deleteAllTracks(context);
|
providerUtils.deleteAllTracks(context);
|
||||||
}
|
}
|
||||||
@@ -103,7 +99,7 @@ public class TrackRecordingServiceTestLooper {
|
|||||||
@MediumTest
|
@MediumTest
|
||||||
@Test
|
@Test
|
||||||
public void testWithProperties_voiceFrequencyDefault() throws TimeoutException {
|
public void testWithProperties_voiceFrequencyDefault() throws TimeoutException {
|
||||||
PreferencesUtils.setInt(context, R.string.voice_frequency_key, PreferencesUtils.VOICE_FREQUENCY_DEFAULT);
|
PreferencesUtils.setInt(context, R.string.voice_frequency_key, Integer.parseInt(context.getResources().getString(R.string.voice_frequency_default)));
|
||||||
fullRecordingSession();
|
fullRecordingSession();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -125,7 +121,7 @@ public class TrackRecordingServiceTestLooper {
|
|||||||
@MediumTest
|
@MediumTest
|
||||||
@Test
|
@Test
|
||||||
public void testWithProperties_maxRecordingDistanceDefault() throws TimeoutException {
|
public void testWithProperties_maxRecordingDistanceDefault() throws TimeoutException {
|
||||||
PreferencesUtils.setInt(context, R.string.max_recording_distance_key, PreferencesUtils.MAX_RECORDING_DISTANCE_DEFAULT);
|
PreferencesUtils.setInt(context, R.string.max_recording_distance_key, Integer.parseInt(context.getResources().getString(R.string.max_recording_distance_default)));
|
||||||
fullRecordingSession();
|
fullRecordingSession();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -139,7 +135,8 @@ public class TrackRecordingServiceTestLooper {
|
|||||||
@MediumTest
|
@MediumTest
|
||||||
@Test
|
@Test
|
||||||
public void testWithProperties_minRecordingDistanceDefault() throws TimeoutException {
|
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();
|
fullRecordingSession();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -150,31 +147,10 @@ public class TrackRecordingServiceTestLooper {
|
|||||||
fullRecordingSession();
|
fullRecordingSession();
|
||||||
}
|
}
|
||||||
|
|
||||||
@MediumTest
|
|
||||||
@Test
|
|
||||||
public void testWithProperties_splitFrequencyDefault() throws TimeoutException {
|
|
||||||
PreferencesUtils.setInt(context, R.string.split_frequency_key, PreferencesUtils.SPLIT_FREQUENCY_DEFAULT);
|
|
||||||
fullRecordingSession();
|
|
||||||
}
|
|
||||||
|
|
||||||
@MediumTest
|
|
||||||
@Test
|
|
||||||
public void testWithProperties_splitFrequencyByDistance() throws TimeoutException {
|
|
||||||
PreferencesUtils.setInt(context, R.string.split_frequency_key, -1);
|
|
||||||
fullRecordingSession();
|
|
||||||
}
|
|
||||||
|
|
||||||
@MediumTest
|
|
||||||
@Test
|
|
||||||
public void testWithProperties_splitFrequencyByTime() throws TimeoutException {
|
|
||||||
PreferencesUtils.setInt(context, R.string.split_frequency_key, 1);
|
|
||||||
fullRecordingSession();
|
|
||||||
}
|
|
||||||
|
|
||||||
@MediumTest
|
@MediumTest
|
||||||
@Test
|
@Test
|
||||||
public void testWithProperties_metricUnitsDefault() throws TimeoutException {
|
public void testWithProperties_metricUnitsDefault() throws TimeoutException {
|
||||||
PreferencesUtils.setString(context, R.string.stats_units_key, PreferencesUtils.STATS_UNITS_DEFAULT);
|
PreferencesUtils.setString(context, R.string.stats_units_key, context.getString(R.string.stats_units_default));
|
||||||
fullRecordingSession();
|
fullRecordingSession();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -188,7 +164,7 @@ public class TrackRecordingServiceTestLooper {
|
|||||||
@MediumTest
|
@MediumTest
|
||||||
@Test
|
@Test
|
||||||
public void testWithProperties_minRecordingIntervalDefault() throws TimeoutException {
|
public void testWithProperties_minRecordingIntervalDefault() throws TimeoutException {
|
||||||
PreferencesUtils.setInt(context, R.string.min_recording_interval_key, PreferencesUtils.MIN_RECORDING_INTERVAL_DEFAULT);
|
PreferencesUtils.setInt(context, R.string.min_recording_interval_key, Integer.parseInt(context.getResources().getString(R.string.min_recording_interval_default)));
|
||||||
fullRecordingSession();
|
fullRecordingSession();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -202,7 +178,8 @@ public class TrackRecordingServiceTestLooper {
|
|||||||
@MediumTest
|
@MediumTest
|
||||||
@Test
|
@Test
|
||||||
public void testWithProperties_minRequiredAccuracyDefault() throws TimeoutException {
|
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();
|
fullRecordingSession();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -225,7 +202,7 @@ public class TrackRecordingServiceTestLooper {
|
|||||||
Track track = providerUtils.getTrack(id);
|
Track track = providerUtils.getTrack(id);
|
||||||
Assert.assertNotNull(track);
|
Assert.assertNotNull(track);
|
||||||
Assert.assertEquals(id, track.getId());
|
Assert.assertEquals(id, track.getId());
|
||||||
Assert.assertEquals(id, PreferencesUtils.getLong(context, R.string.recording_track_id_key));
|
Assert.assertEquals(id, PreferencesUtils.getRecordingTrackId(context));
|
||||||
Assert.assertEquals(id, service.getRecordingTrackId());
|
Assert.assertEquals(id, service.getRecordingTrackId());
|
||||||
|
|
||||||
// Insert a few points, markers and statistics.
|
// Insert a few points, markers and statistics.
|
||||||
@@ -240,10 +217,8 @@ public class TrackRecordingServiceTestLooper {
|
|||||||
location.setBearing(3.0f);
|
location.setBearing(3.0f);
|
||||||
service.insertTrackPoint(location);
|
service.insertTrackPoint(location);
|
||||||
|
|
||||||
if (i % 10 == 0) {
|
if (i % 7 == 0) {
|
||||||
service.insertWaypoint(WaypointCreationRequest.DEFAULT_STATISTICS);
|
service.insertWaypoint(null, null, null, null);
|
||||||
} else if (i % 7 == 0) {
|
|
||||||
service.insertWaypoint(WaypointCreationRequest.DEFAULT_WAYPOINT);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,557 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010 Google Inc.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
|
||||||
* use this file except in compliance with the License. You may obtain a copy of
|
|
||||||
* the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
||||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
||||||
* License for the specific language governing permissions and limitations under
|
|
||||||
* the License.
|
|
||||||
*/
|
|
||||||
package de.dennisguse.opentracks.services.tasks;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.os.Looper;
|
|
||||||
import android.speech.tts.TextToSpeech;
|
|
||||||
import android.speech.tts.TextToSpeech.OnInitListener;
|
|
||||||
import android.speech.tts.TextToSpeech.OnUtteranceCompletedListener;
|
|
||||||
import android.telephony.PhoneStateListener;
|
|
||||||
import android.telephony.TelephonyManager;
|
|
||||||
|
|
||||||
import androidx.test.core.app.ApplicationProvider;
|
|
||||||
|
|
||||||
import org.junit.After;
|
|
||||||
import org.junit.AfterClass;
|
|
||||||
import org.junit.Assert;
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.BeforeClass;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.mockito.ArgumentCaptor;
|
|
||||||
import org.mockito.Mock;
|
|
||||||
import org.mockito.junit.MockitoJUnitRunner;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
|
||||||
|
|
||||||
import de.dennisguse.opentracks.stats.TripStatistics;
|
|
||||||
|
|
||||||
import static org.mockito.Mockito.any;
|
|
||||||
import static org.mockito.Mockito.eq;
|
|
||||||
import static org.mockito.Mockito.reset;
|
|
||||||
import static org.mockito.Mockito.same;
|
|
||||||
import static org.mockito.Mockito.verify;
|
|
||||||
import static org.mockito.Mockito.when;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests for {@link AnnouncementPeriodicTask}.
|
|
||||||
*
|
|
||||||
* WARNING: I'm not responsible if your eyes start bleeding while reading this code.
|
|
||||||
* You have been warned.
|
|
||||||
* It's still better than no test, though.
|
|
||||||
*
|
|
||||||
* @author Rodrigo Damazio
|
|
||||||
*/
|
|
||||||
@RunWith(MockitoJUnitRunner.class)
|
|
||||||
public class AnnouncementPeriodicTaskTest {
|
|
||||||
|
|
||||||
// Use something other than our hardcoded value
|
|
||||||
private static final Locale DEFAULT_LOCALE = Locale.KOREAN;
|
|
||||||
private static final String ANNOUNCEMENT = "I can haz cheeseburger?";
|
|
||||||
private Locale oldDefaultLocale;
|
|
||||||
|
|
||||||
private Context context = ApplicationProvider.getApplicationContext();
|
|
||||||
|
|
||||||
private AnnouncementPeriodicTask task;
|
|
||||||
@Mock
|
|
||||||
private AnnouncementPeriodicTask mockTask;
|
|
||||||
private ArgumentCaptor<OnInitListener> initListenerCapture = ArgumentCaptor.forClass(OnInitListener.class);
|
|
||||||
private ArgumentCaptor<PhoneStateListener> phoneListenerCapture = ArgumentCaptor.forClass(PhoneStateListener.class);
|
|
||||||
private TextToSpeechDelegate ttsDelegate;
|
|
||||||
@Mock
|
|
||||||
private TextToSpeechInterface tts;
|
|
||||||
|
|
||||||
@BeforeClass
|
|
||||||
public static void preSetUp() {
|
|
||||||
// Prepare looper for Android's message queue
|
|
||||||
if (Looper.myLooper() == null) Looper.prepare();
|
|
||||||
}
|
|
||||||
|
|
||||||
@AfterClass
|
|
||||||
public static void finalTearDown() {
|
|
||||||
if (Looper.myLooper() != null) Looper.myLooper().quit();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void setUp() throws Exception {
|
|
||||||
oldDefaultLocale = Locale.getDefault();
|
|
||||||
Locale.setDefault(DEFAULT_LOCALE);
|
|
||||||
|
|
||||||
// Eww, the effort required just to mock TextToSpeech is insane
|
|
||||||
final AtomicBoolean listenerCalled = new AtomicBoolean();
|
|
||||||
OnInitListener blockingListener = new OnInitListener() {
|
|
||||||
@Override
|
|
||||||
public void onInit(int status) {
|
|
||||||
synchronized (this) {
|
|
||||||
listenerCalled.set(true);
|
|
||||||
notify();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
ttsDelegate = new TextToSpeechDelegate(context, blockingListener);
|
|
||||||
|
|
||||||
// Wait for all async operations done in the constructor to finish.
|
|
||||||
synchronized (blockingListener) {
|
|
||||||
while (!listenerCalled.get()) {
|
|
||||||
// Releases the synchronized lock until we're woken up.
|
|
||||||
blockingListener.wait();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create a partial forwarding mock
|
|
||||||
task = new AnnouncementPeriodicTask(context) {
|
|
||||||
@Override
|
|
||||||
protected TextToSpeech newTextToSpeech(Context ctx, OnInitListener onInitListener) {
|
|
||||||
return mockTask.newTextToSpeech(ctx, onInitListener);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected String getAnnouncement(TripStatistics stats) {
|
|
||||||
return mockTask.getAnnouncement(stats);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void listenToPhoneState(PhoneStateListener listener, int events) {
|
|
||||||
mockTask.listenToPhoneState(listener, events);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
@After
|
|
||||||
public void tearDown() {
|
|
||||||
Locale.setDefault(oldDefaultLocale);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testStart() {
|
|
||||||
doStart();
|
|
||||||
OnInitListener ttsInitListener = initListenerCapture.getValue();
|
|
||||||
Assert.assertNotNull(ttsInitListener);
|
|
||||||
|
|
||||||
ttsInitListener.onInit(TextToSpeech.SUCCESS);
|
|
||||||
//TODO
|
|
||||||
//verify(mockTask, tts);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testStart_notReady() {
|
|
||||||
doStart();
|
|
||||||
OnInitListener ttsInitListener = initListenerCapture.getValue();
|
|
||||||
Assert.assertNotNull(ttsInitListener);
|
|
||||||
|
|
||||||
ttsInitListener.onInit(TextToSpeech.ERROR);
|
|
||||||
//TODO
|
|
||||||
//AndroidMock.verify(mockTask, tts);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testShutdown() {
|
|
||||||
// First, start
|
|
||||||
doStart();
|
|
||||||
verify(mockTask);
|
|
||||||
reset(mockTask);
|
|
||||||
|
|
||||||
// Then, shut down
|
|
||||||
PhoneStateListener phoneListener = phoneListenerCapture.getValue();
|
|
||||||
mockTask.listenToPhoneState(
|
|
||||||
same(phoneListener), eq(PhoneStateListener.LISTEN_NONE));
|
|
||||||
tts.shutdown();
|
|
||||||
task.shutdown();
|
|
||||||
//TODO
|
|
||||||
//AndroidMock.verify(mockTask, tts);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testRun() {
|
|
||||||
// when service data calls
|
|
||||||
TripStatistics stats = new TripStatistics();
|
|
||||||
|
|
||||||
// when announcement building call
|
|
||||||
when(mockTask.getAnnouncement(same(stats))).thenReturn(ANNOUNCEMENT);
|
|
||||||
|
|
||||||
// Put task in "ready" state
|
|
||||||
startTask(TextToSpeech.SUCCESS);
|
|
||||||
|
|
||||||
when(tts.isLanguageAvailable(DEFAULT_LOCALE)).thenReturn(TextToSpeech.LANG_AVAILABLE);
|
|
||||||
when(tts.setLanguage(DEFAULT_LOCALE)).thenReturn(TextToSpeech.LANG_AVAILABLE);
|
|
||||||
when(tts.setSpeechRate(AnnouncementPeriodicTask.TTS_SPEECH_RATE)).thenReturn(TextToSpeech.SUCCESS);
|
|
||||||
when(tts.setOnUtteranceCompletedListener((OnUtteranceCompletedListener) any())).thenReturn(0);
|
|
||||||
|
|
||||||
// Run the announcement
|
|
||||||
task.announce(stats);
|
|
||||||
//TODO
|
|
||||||
//AndroidMock.verify(mockTask, tts);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testRun_notReady() {
|
|
||||||
// Put task in "not ready" state
|
|
||||||
startTask(TextToSpeech.ERROR);
|
|
||||||
|
|
||||||
// Run the announcement
|
|
||||||
task.run(null);
|
|
||||||
//TODO
|
|
||||||
//verify(mockTask, tts);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testRun_duringCall() {
|
|
||||||
startTask(TextToSpeech.SUCCESS);
|
|
||||||
|
|
||||||
when(tts.isSpeaking()).thenReturn(false);
|
|
||||||
|
|
||||||
// Run the announcement
|
|
||||||
PhoneStateListener phoneListener = phoneListenerCapture.getValue();
|
|
||||||
phoneListener.onCallStateChanged(TelephonyManager.CALL_STATE_OFFHOOK, null);
|
|
||||||
task.run(null);
|
|
||||||
//TODO
|
|
||||||
//verify(mockTask, tts);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testRun_ringWhileSpeaking() {
|
|
||||||
startTask(TextToSpeech.SUCCESS);
|
|
||||||
|
|
||||||
when(tts.isSpeaking()).thenReturn(true);
|
|
||||||
when(tts.stop()).thenReturn(TextToSpeech.SUCCESS);
|
|
||||||
|
|
||||||
// Update the state to ringing - this should stop the current announcement.
|
|
||||||
PhoneStateListener phoneListener = phoneListenerCapture.getValue();
|
|
||||||
phoneListener.onCallStateChanged(TelephonyManager.CALL_STATE_RINGING, null);
|
|
||||||
|
|
||||||
// Run the announcement - this should do nothing.
|
|
||||||
task.run(null);
|
|
||||||
//TODO
|
|
||||||
//AndroidMock.verify(mockTask, tts);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testRun_whileRinging() {
|
|
||||||
startTask(TextToSpeech.SUCCESS);
|
|
||||||
|
|
||||||
when(tts.isSpeaking()).thenReturn(false);
|
|
||||||
|
|
||||||
// Run the announcement
|
|
||||||
PhoneStateListener phoneListener = phoneListenerCapture.getValue();
|
|
||||||
phoneListener.onCallStateChanged(TelephonyManager.CALL_STATE_RINGING, null);
|
|
||||||
task.run(null);
|
|
||||||
//TODO
|
|
||||||
//AndroidMock.verify(mockTask, tts);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testRun_noService() {
|
|
||||||
startTask(TextToSpeech.SUCCESS);
|
|
||||||
|
|
||||||
// Run the announcement
|
|
||||||
task.run(null);
|
|
||||||
//TODO
|
|
||||||
//AndroidMock.verify(mockTask, tts);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testRun_noStats() {
|
|
||||||
// when service data calls
|
|
||||||
|
|
||||||
startTask(TextToSpeech.SUCCESS);
|
|
||||||
|
|
||||||
// Run the announcement
|
|
||||||
task.run(null);
|
|
||||||
//TODO
|
|
||||||
//AndroidMock.verify(mockTask, tts);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests {@link AnnouncementPeriodicTask#getAnnounceTime(long)} with time zero.
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void testGetAnnounceTime_time_zero() {
|
|
||||||
long time = 0; // 0 seconds
|
|
||||||
Assert.assertEquals("0 minutes 0 seconds", task.getAnnounceTime(time));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests {@link AnnouncementPeriodicTask#getAnnounceTime(long)} with time one.
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void testGetAnnounceTime_time_one() {
|
|
||||||
long time = 1000; // 1 second
|
|
||||||
Assert.assertEquals("0 minutes 1 second", task.getAnnounceTime(time));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests {@link AnnouncementPeriodicTask#getAnnounceTime(long)} with singular
|
|
||||||
* numbers with the hour unit.
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void testGetAnnounceTime_singular_has_hour() {
|
|
||||||
long time = (60 * 60 * 1000) + (60 * 1000) + (1000); // 1 hour 1 minute 1 second
|
|
||||||
Assert.assertEquals("1 hour 1 minute 1 second", task.getAnnounceTime(time));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests {@link AnnouncementPeriodicTask#getAnnounceTime(long)} with plural numbers
|
|
||||||
* with the hour unit.
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void testGetAnnounceTime_plural_has_hour() {
|
|
||||||
long time = (2 * 60 * 60 * 1000) + (2 * 60 * 1000) + (2 * 1000); // 2 hours 2 minutes 2 seconds
|
|
||||||
Assert.assertEquals("2 hours 2 minutes 2 seconds", task.getAnnounceTime(time));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests {@link AnnouncementPeriodicTask#getAnnounceTime(long)} with singular
|
|
||||||
* numbers without the hour unit.
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void testGetAnnounceTime_singular_no_hour() {
|
|
||||||
long time = (1 * 60 * 1000) + (1 * 1000); // 1 minute 1 second
|
|
||||||
Assert.assertEquals("1 minute 1 second", task.getAnnounceTime(time));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests {@link AnnouncementPeriodicTask#getAnnounceTime(long)} with plural numbers
|
|
||||||
* without the hour unit.
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void testGetAnnounceTime_plural_no_hour() {
|
|
||||||
long time = (2 * 60 * 1000) + (2 * 1000); // 2 minutes 2 seconds
|
|
||||||
Assert.assertEquals("2 minutes 2 seconds", task.getAnnounceTime(time));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void startTask(int state) {
|
|
||||||
reset(tts);
|
|
||||||
doStart();
|
|
||||||
OnInitListener ttsInitListener = initListenerCapture.getValue();
|
|
||||||
ttsInitListener.onInit(state);
|
|
||||||
//TODO
|
|
||||||
reset(tts);
|
|
||||||
//AndroidMock.resetToDefault(tts);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void doStart() {
|
|
||||||
mockTask.listenToPhoneState(phoneListenerCapture.capture(), eq(PhoneStateListener.LISTEN_CALL_STATE));
|
|
||||||
when(mockTask.newTextToSpeech(same(context), initListenerCapture.capture())).thenReturn(ttsDelegate);
|
|
||||||
|
|
||||||
task.start();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Mockable interface that we delegate TTS calls to.
|
|
||||||
*/
|
|
||||||
interface TextToSpeechInterface {
|
|
||||||
int addEarcon(String earcon, String packagename, int resourceId);
|
|
||||||
|
|
||||||
int addEarcon(String earcon, String filename);
|
|
||||||
|
|
||||||
int addSpeech(String text, String packagename, int resourceId);
|
|
||||||
|
|
||||||
int addSpeech(String text, String filename);
|
|
||||||
|
|
||||||
boolean areDefaultsEnforced();
|
|
||||||
|
|
||||||
String getDefaultEngine();
|
|
||||||
|
|
||||||
Locale getLanguage();
|
|
||||||
|
|
||||||
int isLanguageAvailable(Locale loc);
|
|
||||||
|
|
||||||
boolean isSpeaking();
|
|
||||||
|
|
||||||
int playEarcon(String earcon, int queueMode,
|
|
||||||
HashMap<String, String> params);
|
|
||||||
|
|
||||||
int playSilence(long durationInMs, int queueMode, HashMap<String, String> params);
|
|
||||||
|
|
||||||
int setLanguage(Locale loc);
|
|
||||||
|
|
||||||
int setOnUtteranceCompletedListener(OnUtteranceCompletedListener listener);
|
|
||||||
|
|
||||||
int setPitch(float pitch);
|
|
||||||
|
|
||||||
int setSpeechRate(float speechRate);
|
|
||||||
|
|
||||||
void shutdown();
|
|
||||||
|
|
||||||
int speak(String text, int queueMode, HashMap<String, String> params);
|
|
||||||
|
|
||||||
int stop();
|
|
||||||
|
|
||||||
int synthesizeToFile(String text, HashMap<String, String> params, String filename);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Subclass of {@link TextToSpeech} which delegates calls to the interface
|
|
||||||
* above.
|
|
||||||
* The logic here is stupid and the author is ashamed of having to write it
|
|
||||||
* like this, but basically the issue is that TextToSpeech cannot be mocked
|
|
||||||
* without running its constructor, its constructor runs async operations
|
|
||||||
* which call other methods (and then if the methods are part of a mock we'd
|
|
||||||
* have to set a behavior, but we can't 'cause the object hasn't been fully
|
|
||||||
* built yet).
|
|
||||||
* The logic is that calls made during the constructor (when tts is not yet
|
|
||||||
* set) will go up to the original class, but after tts is set we'll forward
|
|
||||||
* them all to the mock.
|
|
||||||
*/
|
|
||||||
private class TextToSpeechDelegate extends TextToSpeech implements TextToSpeechInterface {
|
|
||||||
public TextToSpeechDelegate(Context context, OnInitListener listener) {
|
|
||||||
super(context, listener);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int addEarcon(String earcon, String packagename, int resourceId) {
|
|
||||||
if (tts == null) {
|
|
||||||
return super.addEarcon(earcon, packagename, resourceId);
|
|
||||||
}
|
|
||||||
return tts.addEarcon(earcon, packagename, resourceId);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int addEarcon(String earcon, String filename) {
|
|
||||||
if (tts == null) {
|
|
||||||
return super.addEarcon(earcon, filename);
|
|
||||||
}
|
|
||||||
return tts.addEarcon(earcon, filename);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int addSpeech(String text, String packagename, int resourceId) {
|
|
||||||
if (tts == null) {
|
|
||||||
return super.addSpeech(text, packagename, resourceId);
|
|
||||||
}
|
|
||||||
return tts.addSpeech(text, packagename, resourceId);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int addSpeech(String text, String filename) {
|
|
||||||
if (tts == null) {
|
|
||||||
return super.addSpeech(text, filename);
|
|
||||||
}
|
|
||||||
return tts.addSpeech(text, filename);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Locale getLanguage() {
|
|
||||||
if (tts == null) {
|
|
||||||
return super.getLanguage();
|
|
||||||
}
|
|
||||||
return tts.getLanguage();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int isLanguageAvailable(Locale loc) {
|
|
||||||
if (tts == null) {
|
|
||||||
return super.isLanguageAvailable(loc);
|
|
||||||
}
|
|
||||||
return tts.isLanguageAvailable(loc);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isSpeaking() {
|
|
||||||
if (tts == null) {
|
|
||||||
return super.isSpeaking();
|
|
||||||
}
|
|
||||||
return tts.isSpeaking();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int playEarcon(String earcon, int queueMode, HashMap<String, String> params) {
|
|
||||||
if (tts == null) {
|
|
||||||
return super.playEarcon(earcon, queueMode, params);
|
|
||||||
}
|
|
||||||
return tts.playEarcon(earcon, queueMode, params);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int playSilence(long durationInMs, int queueMode, HashMap<String, String> params) {
|
|
||||||
if (tts == null) {
|
|
||||||
return super.playSilence(durationInMs, queueMode, params);
|
|
||||||
}
|
|
||||||
return tts.playSilence(durationInMs, queueMode, params);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int setLanguage(Locale loc) {
|
|
||||||
if (tts == null) {
|
|
||||||
return super.setLanguage(loc);
|
|
||||||
}
|
|
||||||
return tts.setLanguage(loc);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int setOnUtteranceCompletedListener(OnUtteranceCompletedListener listener) {
|
|
||||||
if (tts == null) {
|
|
||||||
return super.setOnUtteranceCompletedListener(listener);
|
|
||||||
}
|
|
||||||
return tts.setOnUtteranceCompletedListener(listener);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int setPitch(float pitch) {
|
|
||||||
if (tts == null) {
|
|
||||||
return super.setPitch(pitch);
|
|
||||||
}
|
|
||||||
return tts.setPitch(pitch);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int setSpeechRate(float speechRate) {
|
|
||||||
if (tts == null) {
|
|
||||||
return super.setSpeechRate(speechRate);
|
|
||||||
}
|
|
||||||
return tts.setSpeechRate(speechRate);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void shutdown() {
|
|
||||||
if (tts == null) {
|
|
||||||
super.shutdown();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
tts.shutdown();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int speak(
|
|
||||||
String text, int queueMode, HashMap<String, String> params) {
|
|
||||||
if (tts == null) {
|
|
||||||
return super.speak(text, queueMode, params);
|
|
||||||
}
|
|
||||||
return tts.speak(text, queueMode, params);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int stop() {
|
|
||||||
if (tts == null) {
|
|
||||||
return super.stop();
|
|
||||||
}
|
|
||||||
return tts.stop();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int synthesizeToFile(String text, HashMap<String, String> params, String filename) {
|
|
||||||
if (tts == null) {
|
|
||||||
return super.synthesizeToFile(text, params, filename);
|
|
||||||
}
|
|
||||||
return tts.synthesizeToFile(text, params, filename);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -15,7 +15,11 @@
|
|||||||
*/
|
*/
|
||||||
package de.dennisguse.opentracks.stats;
|
package de.dennisguse.opentracks.stats;
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
import org.junit.Assert;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.junit.runners.JUnit4;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for {@link TripStatistics}.
|
* Tests for {@link TripStatistics}.
|
||||||
@@ -23,26 +27,17 @@ import junit.framework.TestCase;
|
|||||||
*
|
*
|
||||||
* @author Rodrigo Damazio
|
* @author Rodrigo Damazio
|
||||||
*/
|
*/
|
||||||
public class TripStatisticsTest extends TestCase {
|
@RunWith(JUnit4.class)
|
||||||
|
public class TripStatisticsTest {
|
||||||
|
|
||||||
private TripStatistics statistics;
|
private TripStatistics statistics;
|
||||||
|
|
||||||
@Override
|
@Before
|
||||||
protected void setUp() throws Exception {
|
public void setUp() {
|
||||||
super.setUp();
|
|
||||||
|
|
||||||
statistics = new TripStatistics();
|
statistics = new TripStatistics();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSetBounds() {
|
@Test
|
||||||
// This is not a trivial setter, conversion happens in it
|
|
||||||
statistics.setBounds(12345, -34567, 56789, -98765);
|
|
||||||
assertEquals(12345, statistics.getLeft());
|
|
||||||
assertEquals(-34567, statistics.getTop());
|
|
||||||
assertEquals(56789, statistics.getRight());
|
|
||||||
assertEquals(-98765, statistics.getBottom());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testMerge() {
|
public void testMerge() {
|
||||||
TripStatistics statistics2 = new TripStatistics();
|
TripStatistics statistics2 = new TripStatistics();
|
||||||
statistics.setStartTime(1000L); // Resulting start time
|
statistics.setStartTime(1000L); // Resulting start time
|
||||||
@@ -68,38 +63,32 @@ public class TripStatisticsTest extends TestCase {
|
|||||||
statistics2.setMaxGrade(35.0); // Resulting max grade
|
statistics2.setMaxGrade(35.0); // Resulting max grade
|
||||||
statistics2.setMinGrade(0.0);
|
statistics2.setMinGrade(0.0);
|
||||||
|
|
||||||
// Resulting bounds: -10000, 35000, 30000, -40000
|
|
||||||
statistics.setBounds(-10000, 20000, 30000, -40000);
|
|
||||||
statistics2.setBounds(-5000, 35000, 0, 20000);
|
|
||||||
|
|
||||||
statistics.merge(statistics2);
|
statistics.merge(statistics2);
|
||||||
|
|
||||||
assertEquals(1000L, statistics.getStartTime());
|
Assert.assertEquals(1000L, statistics.getStartTime());
|
||||||
assertEquals(4000L, statistics.getStopTime());
|
Assert.assertEquals(4000L, statistics.getStopTime());
|
||||||
assertEquals(2500L, statistics.getTotalTime());
|
Assert.assertEquals(2500L, statistics.getTotalTime());
|
||||||
assertEquals(1300L, statistics.getMovingTime());
|
Assert.assertEquals(1300L, statistics.getMovingTime());
|
||||||
assertEquals(1100.0, statistics.getTotalDistance());
|
Assert.assertEquals(1100.0, statistics.getTotalDistance(), 0.001);
|
||||||
assertEquals(900.0, statistics.getTotalElevationGain());
|
Assert.assertEquals(900.0, statistics.getTotalElevationGain(), 0.001);
|
||||||
assertEquals(statistics.getTotalDistance() / (statistics.getMovingTime() / 1000.0), statistics.getMaxSpeed());
|
Assert.assertEquals(statistics.getTotalDistance() / (statistics.getMovingTime() / 1000.0), statistics.getMaxSpeed(), 0.001);
|
||||||
assertEquals(-10000, statistics.getLeft());
|
Assert.assertEquals(1200.0, statistics.getMinElevation(), 0.001);
|
||||||
assertEquals(30000, statistics.getRight());
|
Assert.assertEquals(3575.0, statistics.getMaxElevation(), 0.001);
|
||||||
assertEquals(35000, statistics.getTop());
|
Assert.assertEquals(-25.0, statistics.getMinGrade(), 0.001);
|
||||||
assertEquals(-40000, statistics.getBottom());
|
Assert.assertEquals(35.0, statistics.getMaxGrade(), 0.001);
|
||||||
assertEquals(1200.0, statistics.getMinElevation());
|
|
||||||
assertEquals(3575.0, statistics.getMaxElevation());
|
|
||||||
assertEquals(-25.0, statistics.getMinGrade());
|
|
||||||
assertEquals(35.0, statistics.getMaxGrade());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testGetAverageSpeed() {
|
public void testGetAverageSpeed() {
|
||||||
statistics.setTotalDistance(1000.0);
|
statistics.setTotalDistance(1000.0);
|
||||||
statistics.setTotalTime(50000); // in milliseconds
|
statistics.setTotalTime(50000); // in milliseconds
|
||||||
assertEquals(20.0, statistics.getAverageSpeed());
|
Assert.assertEquals(20.0, statistics.getAverageSpeed(), 0.001);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testGetAverageMovingSpeed() {
|
public void testGetAverageMovingSpeed() {
|
||||||
statistics.setTotalDistance(1000.0);
|
statistics.setTotalDistance(1000.0);
|
||||||
statistics.setMovingTime(20000); // in milliseconds
|
statistics.setMovingTime(20000); // in milliseconds
|
||||||
assertEquals(50.0, statistics.getAverageMovingSpeed());
|
Assert.assertEquals(50.0, statistics.getAverageMovingSpeed(), 0.001);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,9 +15,10 @@
|
|||||||
*/
|
*/
|
||||||
package de.dennisguse.opentracks.util;
|
package de.dennisguse.opentracks.util;
|
||||||
|
|
||||||
import android.os.Environment;
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
import junit.framework.TestCase;
|
import org.junit.runner.RunWith;
|
||||||
|
import org.junit.runners.JUnit4;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
@@ -26,78 +27,83 @@ import java.io.File;
|
|||||||
*
|
*
|
||||||
* @author Rodrigo Damazio
|
* @author Rodrigo Damazio
|
||||||
*/
|
*/
|
||||||
public class FileUtilsTest extends TestCase {
|
@RunWith(JUnit4.class)
|
||||||
|
public class FileUtilsTest {
|
||||||
/**
|
|
||||||
* Tests {@link FileUtils#getPath(String...)}.
|
|
||||||
*/
|
|
||||||
public void testBuildExternalDirectoryPath() {
|
|
||||||
String expectedName = Environment.getExternalStorageDirectory() + File.separator + FileUtils.SDCARD_TOP_DIR + File.separator + "a" + File.separator + "b" + File.separator + "c";
|
|
||||||
String dirName = FileUtils.getPath("a", "b", "c");
|
|
||||||
assertEquals(expectedName, dirName);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests {@link FileUtils#buildUniqueFileName(File, String, String)} when the file is new.
|
* Tests {@link FileUtils#buildUniqueFileName(File, String, String)} when the file is new.
|
||||||
*/
|
*/
|
||||||
|
@Test
|
||||||
public void testBuildUniqueFileName_new() {
|
public void testBuildUniqueFileName_new() {
|
||||||
String filename = FileUtils.buildUniqueFileName(new File("/dir"), "Filename", "ext");
|
String filename = FileUtils.buildUniqueFileName(new File("/dir"), "Filename", "ext");
|
||||||
assertEquals("Filename.ext", filename);
|
Assert.assertEquals("Filename.ext", filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests {@link FileUtils#buildUniqueFileName(File, String, String)} when the file exists already.
|
* Tests {@link FileUtils#buildUniqueFileName(File, String, String)} when the file exists already.
|
||||||
*/
|
*/
|
||||||
|
@Test
|
||||||
public void testBuildUniqueFileName_exist() {
|
public void testBuildUniqueFileName_exist() {
|
||||||
// Expect "/default.prop" to exist on the phone/emulator
|
// Expect "/default.prop" to exist on the phone/emulator
|
||||||
String filename = FileUtils.buildUniqueFileName(new File("/"), "default", "prop");
|
String filename = FileUtils.buildUniqueFileName(new File("/"), "default", "prop");
|
||||||
assertEquals("default(1).prop", filename);
|
Assert.assertEquals("default(1).prop", filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests {@link FileUtils#sanitizeFileName(String)} with special characters.
|
* Tests {@link FileUtils#sanitizeFileName(String)} with special characters.
|
||||||
* Verifies that they are sanitized.
|
* Verifies that they are sanitized.
|
||||||
*/
|
*/
|
||||||
|
@Test
|
||||||
public void testSanitizeFileName() {
|
public void testSanitizeFileName() {
|
||||||
String name = "Swim\10ming-^across:/the/ pacific (ocean).";
|
String name = "Swim\10ming-^across:/the/ pacific (ocean).";
|
||||||
String expected = "Swim_ming-^across_the_ pacific (ocean)_";
|
String expected = "Swim_ming-^across_the_ pacific (ocean).";
|
||||||
assertEquals(expected, FileUtils.sanitizeFileName(name));
|
Assert.assertEquals(expected, FileUtils.sanitizeFileName(name));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSanitizeFileNameWithSuffix() {
|
||||||
|
String name = "FileName.jpeg";
|
||||||
|
Assert.assertEquals(name, FileUtils.sanitizeFileName(name));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests {@link FileUtils#sanitizeFileName(String)} with i18n characters (in Chinese and Russian).
|
* Tests {@link FileUtils#sanitizeFileName(String)} with i18n characters (in Chinese and Russian).
|
||||||
* Verifies that they are allowed.
|
* Verifies that they are allowed.
|
||||||
*/
|
*/
|
||||||
|
@Test
|
||||||
public void testSanitizeFileName_i18n() {
|
public void testSanitizeFileName_i18n() {
|
||||||
String name = "您好-привет";
|
String name = "您好-привет";
|
||||||
String expected = "您好-привет";
|
String expected = "您好-привет";
|
||||||
assertEquals(expected, FileUtils.sanitizeFileName(name));
|
Assert.assertEquals(expected, FileUtils.sanitizeFileName(name));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests {@link FileUtils#sanitizeFileName(String)} with special FAT32 characters.
|
* Tests {@link FileUtils#sanitizeFileName(String)} with special FAT32 characters.
|
||||||
* Verifies that they are allowed.
|
* Verifies that they are allowed.
|
||||||
*/
|
*/
|
||||||
|
@Test
|
||||||
public void testSanitizeFileName_special_characters() {
|
public void testSanitizeFileName_special_characters() {
|
||||||
String name = "$%'-_@~`!(){}^#&+,;=[] ";
|
String name = "$%'-_@~`!(){}^#&+,;=[] ";
|
||||||
String expected = "$%'-_@~`!(){}^#&+,;=[] ";
|
String expected = "$%'-_@~`!(){}^#&+,;=[] ";
|
||||||
assertEquals(expected, FileUtils.sanitizeFileName(name));
|
Assert.assertEquals(expected, FileUtils.sanitizeFileName(name));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests {@link FileUtils#sanitizeFileName(String)} with multiple escaped characters in a row.
|
* Tests {@link FileUtils#sanitizeFileName(String)} with multiple escaped characters in a row.
|
||||||
* Verifies that they are collapsed into one underscore.
|
* Verifies that they are collapsed into one underscore.
|
||||||
*/
|
*/
|
||||||
|
@Test
|
||||||
public void testSanitizeFileName_collapse() {
|
public void testSanitizeFileName_collapse() {
|
||||||
String name = "hello//there";
|
String name = "hello//there";
|
||||||
String expected = "hello_there";
|
String expected = "hello_there";
|
||||||
assertEquals(expected, FileUtils.sanitizeFileName(name));
|
Assert.assertEquals(expected, FileUtils.sanitizeFileName(name));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests {@link FileUtils#truncateFileName(File, String, String)}.
|
* Tests {@link FileUtils#truncateFileName(File, String, String)}.
|
||||||
* Verifies the a long file name is truncated.
|
* Verifies the a long file name is truncated.
|
||||||
*/
|
*/
|
||||||
|
@Test
|
||||||
public void testTruncateFileName() {
|
public void testTruncateFileName() {
|
||||||
File directory = new File("/dir1/dir2/");
|
File directory = new File("/dir1/dir2/");
|
||||||
String suffix = ".gpx";
|
String suffix = ".gpx";
|
||||||
@@ -109,8 +115,8 @@ public class FileUtilsTest extends TestCase {
|
|||||||
String truncated = FileUtils.truncateFileName(directory, nameString, suffix);
|
String truncated = FileUtils.truncateFileName(directory, nameString, suffix);
|
||||||
|
|
||||||
for (int i = 0; i < truncated.length(); i++) {
|
for (int i = 0; i < truncated.length(); i++) {
|
||||||
assertEquals('a', truncated.charAt(i));
|
Assert.assertEquals('a', truncated.charAt(i));
|
||||||
}
|
}
|
||||||
assertEquals(FileUtils.MAX_FAT32_PATH_LENGTH, new File(directory, truncated + suffix).getPath().length());
|
Assert.assertEquals(FileUtils.MAX_FAT32_PATH_LENGTH, new File(directory, truncated + suffix).getPath().length());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -131,7 +131,7 @@ public class StringUtilsTest {
|
|||||||
assertGetTime("2010-05-04T03:02:01.3", 2010, 5, 4, 3, 2, 1, 300);
|
assertGetTime("2010-05-04T03:02:01.3", 2010, 5, 4, 3, 2, 1, 300);
|
||||||
assertGetTime("2010-05-04T03:02:01.35", 2010, 5, 4, 3, 2, 1, 350);
|
assertGetTime("2010-05-04T03:02:01.35", 2010, 5, 4, 3, 2, 1, 350);
|
||||||
assertGetTime("2010-05-04T03:02:01.352Z", 2010, 5, 4, 3, 2, 1, 352);
|
assertGetTime("2010-05-04T03:02:01.352Z", 2010, 5, 4, 3, 2, 1, 352);
|
||||||
assertGetTime("2010-05-04T03:02:01.3525Z", 2010, 5, 4, 3, 2, 1, 352);
|
assertGetTime("2010-05-04T03:02:01.3529Z", 2010, 5, 4, 3, 2, 1, 353);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -199,4 +199,24 @@ public class StringUtilsTest {
|
|||||||
Assert.assertEquals(-1, parts[1]);
|
Assert.assertEquals(-1, parts[1]);
|
||||||
Assert.assertEquals(0, parts[2]);
|
Assert.assertEquals(0, parts[2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testFormatDecimal() {
|
||||||
|
Assert.assertEquals("0", StringUtils.formatDecimal(0.0, 0));
|
||||||
|
Assert.assertEquals("0", StringUtils.formatDecimal(0.1, 0));
|
||||||
|
Assert.assertEquals("1", StringUtils.formatDecimal(1.1, 0));
|
||||||
|
Assert.assertEquals("10", StringUtils.formatDecimal(10, 0));
|
||||||
|
Assert.assertEquals("10", StringUtils.formatDecimal(10.1, 0));
|
||||||
|
Assert.assertEquals("0", StringUtils.formatDecimal(-0.1, 0));
|
||||||
|
|
||||||
|
Assert.assertEquals("0", StringUtils.formatDecimal(0.0, 2));
|
||||||
|
Assert.assertEquals("0.1", StringUtils.formatDecimal(0.1, 2));
|
||||||
|
Assert.assertEquals("1.1", StringUtils.formatDecimal(1.1, 2));
|
||||||
|
Assert.assertEquals("10", StringUtils.formatDecimal(10, 2));
|
||||||
|
Assert.assertEquals("10.1", StringUtils.formatDecimal(10.1, 2));
|
||||||
|
Assert.assertEquals("10.11", StringUtils.formatDecimal(10.111, 2));
|
||||||
|
Assert.assertEquals("-0.1", StringUtils.formatDecimal(-0.1, 2));
|
||||||
|
|
||||||
|
Assert.assertEquals("1", StringUtils.formatDecimal(0.99, 1));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,15 +16,15 @@ limitations under the License.
|
|||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
package="de.dennisguse.opentracks"
|
package="de.dennisguse.opentracks"
|
||||||
android:installLocation="auto"
|
android:installLocation="auto"
|
||||||
android:versionCode="3079"
|
android:versionCode="3243"
|
||||||
android:versionName="v3.2.2"> <!-- For FDroid. -->
|
android:versionName="v3.3.0"> <!-- For FDroid. -->
|
||||||
<!-- Permission to initialize services -->
|
<!-- Permission to initialize services -->
|
||||||
<application
|
<application
|
||||||
android:name=".Startup"
|
android:name=".Startup"
|
||||||
android:allowBackup="false"
|
android:allowBackup="false"
|
||||||
android:hardwareAccelerated="true"
|
android:hardwareAccelerated="true"
|
||||||
android:icon="@drawable/ic_logo_color_24dp"
|
android:icon="${applicationLogo}"
|
||||||
android:label="@string/app_name"
|
android:label="${applicationName}"
|
||||||
android:theme="@style/ThemeCustom">
|
android:theme="@style/ThemeCustom">
|
||||||
|
|
||||||
<!-- Activities -->
|
<!-- Activities -->
|
||||||
@@ -32,6 +32,10 @@ limitations under the License.
|
|||||||
|
|
||||||
<activity android:name=".DeleteActivity" />
|
<activity android:name=".DeleteActivity" />
|
||||||
|
|
||||||
|
<activity
|
||||||
|
android:name=".HelpActivity"
|
||||||
|
android:label="@string/menu_help" />
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name=".io.file.importer.ImportActivity"
|
android:name=".io.file.importer.ImportActivity"
|
||||||
android:theme="@style/ThemeCustomTransparent">
|
android:theme="@style/ThemeCustomTransparent">
|
||||||
@@ -50,10 +54,10 @@ limitations under the License.
|
|||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
<activity android:name=".MarkerEditActivity" />
|
|
||||||
|
|
||||||
<activity android:name=".MarkerDetailActivity" />
|
<activity android:name=".MarkerDetailActivity" />
|
||||||
|
|
||||||
|
<activity android:name=".MarkerEditActivity" />
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name=".MarkerListActivity"
|
android:name=".MarkerListActivity"
|
||||||
android:label="@string/menu_markers">
|
android:label="@string/menu_markers">
|
||||||
@@ -95,7 +99,6 @@ limitations under the License.
|
|||||||
|
|
||||||
<activity android:name=".settings.SettingsActivity" />
|
<activity android:name=".settings.SettingsActivity" />
|
||||||
|
|
||||||
<!-- Services -->
|
|
||||||
<provider
|
<provider
|
||||||
android:name=".content.ShareContentProvider"
|
android:name=".content.ShareContentProvider"
|
||||||
android:authorities="${applicationId}.content"
|
android:authorities="${applicationId}.content"
|
||||||
@@ -112,18 +115,11 @@ limitations under the License.
|
|||||||
android:resource="@xml/file_paths" />
|
android:resource="@xml/file_paths" />
|
||||||
</provider>
|
</provider>
|
||||||
|
|
||||||
<!-- Receivers -->
|
|
||||||
<receiver android:name=".BootReceiver">
|
|
||||||
<intent-filter>
|
|
||||||
<action android:name="android.intent.action.BOOT_COMPLETED" />
|
|
||||||
</intent-filter>
|
|
||||||
</receiver>
|
|
||||||
|
|
||||||
<!-- Providers -->
|
|
||||||
<service
|
<service
|
||||||
android:name=".services.TrackRecordingService"
|
android:name=".services.TrackRecordingService"
|
||||||
android:enabled="true"
|
android:enabled="true"
|
||||||
android:exported="false"
|
android:exported="false"
|
||||||
|
android:foregroundServiceType="location|connectedDevice"
|
||||||
android:icon="@drawable/ic_logo_color_24dp"
|
android:icon="@drawable/ic_logo_color_24dp"
|
||||||
android:label="@string/recording_service" />
|
android:label="@string/recording_service" />
|
||||||
</application>
|
</application>
|
||||||
@@ -138,44 +134,21 @@ limitations under the License.
|
|||||||
android:name="android.hardware.location.gps"
|
android:name="android.hardware.location.gps"
|
||||||
android:required="true" />
|
android:required="true" />
|
||||||
<uses-feature
|
<uses-feature
|
||||||
android:name="android.hardware.bluetooth"
|
android:name="android.hardware.android.hardware.bluetooth_le"
|
||||||
android:required="false" />
|
android:required="false" />
|
||||||
<!-- Permissions to access sensors -->
|
|
||||||
<uses-feature
|
<uses-feature
|
||||||
android:name="android.hardware.camera"
|
android:name="android.hardware.camera"
|
||||||
android:required="false" />
|
android:required="false" />
|
||||||
<uses-feature
|
|
||||||
android:name="android.hardware.faketouch"
|
|
||||||
android:required="false" />
|
|
||||||
<!-- Permission to read phone state so voice announcement will not interrupt ongoing calls -->
|
|
||||||
<uses-feature
|
<uses-feature
|
||||||
android:name="android.hardware.sensor.compass"
|
android:name="android.hardware.sensor.compass"
|
||||||
android:required="false" />
|
android:required="false" />
|
||||||
<!-- Permission to read/write external storage -->
|
|
||||||
<uses-feature
|
|
||||||
android:name="android.hardware.telephony"
|
|
||||||
android:required="false" />
|
|
||||||
<uses-feature
|
|
||||||
android:name="android.hardware.telephony.gsm"
|
|
||||||
android:required="false" />
|
|
||||||
<!-- Required features -->
|
|
||||||
<uses-feature
|
<uses-feature
|
||||||
android:name="android.hardware.touchscreen"
|
android:name="android.hardware.touchscreen"
|
||||||
android:required="false" />
|
android:required="false" />
|
||||||
<!-- Optional features -->
|
|
||||||
<uses-feature
|
|
||||||
android:name="android.hardware.touchscreen.multitouch"
|
|
||||||
android:required="false" />
|
|
||||||
|
|
||||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
|
||||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
||||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
||||||
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
||||||
<uses-permission android:name="android.permission.BLUETOOTH" />
|
<uses-permission android:name="android.permission.BLUETOOTH" />
|
||||||
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
|
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
|
||||||
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
|
|
||||||
|
|
||||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
|
||||||
|
|
||||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
|
||||||
</manifest>
|
</manifest>
|
||||||
|
|||||||
@@ -17,11 +17,12 @@
|
|||||||
package de.dennisguse.opentracks;
|
package de.dennisguse.opentracks;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.speech.tts.TextToSpeech;
|
|
||||||
|
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
import androidx.appcompat.widget.Toolbar;
|
import androidx.appcompat.widget.Toolbar;
|
||||||
|
|
||||||
|
import de.dennisguse.opentracks.util.TTSUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Jimmy Shih
|
* @author Jimmy Shih
|
||||||
*/
|
*/
|
||||||
@@ -32,7 +33,7 @@ public abstract class AbstractActivity extends AppCompatActivity {
|
|||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
// Set volume control stream for text to speech
|
// Set volume control stream for text to speech
|
||||||
setVolumeControlStream(TextToSpeech.Engine.DEFAULT_STREAM);
|
setVolumeControlStream(TTSUtils.getTTSStream());
|
||||||
|
|
||||||
setContentView(getLayoutResId());
|
setContentView(getLayoutResId());
|
||||||
|
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ public abstract class AbstractListActivity extends AbstractActivity implements C
|
|||||||
if (trackIds.length == 1 && trackIds[0] == -1L) {
|
if (trackIds.length == 1 && trackIds[0] == -1L) {
|
||||||
stopRecording = true;
|
stopRecording = true;
|
||||||
} else {
|
} else {
|
||||||
long recordingTrackId = PreferencesUtils.getLong(this, R.string.recording_track_id_key);
|
long recordingTrackId = PreferencesUtils.getRecordingTrackId(this);
|
||||||
for (long trackId : trackIds) {
|
for (long trackId : trackIds) {
|
||||||
if (trackId == recordingTrackId) {
|
if (trackId == recordingTrackId) {
|
||||||
stopRecording = true;
|
stopRecording = true;
|
||||||
|
|||||||
@@ -1,57 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010 Google Inc.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
|
||||||
* use this file except in compliance with the License. You may obtain a copy of
|
|
||||||
* the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
||||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
||||||
* License for the specific language governing permissions and limitations under
|
|
||||||
* the License.
|
|
||||||
*/
|
|
||||||
package de.dennisguse.opentracks;
|
|
||||||
|
|
||||||
import android.content.BroadcastReceiver;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
import de.dennisguse.opentracks.services.TrackRecordingService;
|
|
||||||
|
|
||||||
import static android.content.Intent.ACTION_BOOT_COMPLETED;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This class react to the BOOT_COMPLETED broadcast.
|
|
||||||
* <p>
|
|
||||||
* One example of a broadcast message that this class is interested in,
|
|
||||||
* is notification about the phone boot. We may want to resume a previously
|
|
||||||
* started tracking session if the phone crashed (hopefully not), or the user
|
|
||||||
* decided to swap the battery or some external event occurred which forced
|
|
||||||
* a phone reboot.
|
|
||||||
* <p>
|
|
||||||
* This class simply delegates to {@link TrackRecordingService} to make a
|
|
||||||
* decision whether to continue with the previous track (if any), or just
|
|
||||||
* abandon it.
|
|
||||||
*
|
|
||||||
* @author Bartlomiej Niechwiej
|
|
||||||
*/
|
|
||||||
public class BootReceiver extends BroadcastReceiver {
|
|
||||||
|
|
||||||
private static final String TAG = BootReceiver.class.getSimpleName();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onReceive(Context context, Intent intent) {
|
|
||||||
Log.d(TAG, "BootReceiver.onReceive: " + intent.getAction());
|
|
||||||
if (ACTION_BOOT_COMPLETED.equals(intent.getAction())) {
|
|
||||||
Intent startIntent = new Intent(context, TrackRecordingService.class)
|
|
||||||
.putExtra(TrackRecordingService.RESUME_TRACK_EXTRA_NAME, true);
|
|
||||||
context.startService(startIntent);
|
|
||||||
} else {
|
|
||||||
Log.w(TAG, "BootReceiver: unsupported action");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -69,7 +69,7 @@ public class DeleteAsyncTask extends AsyncTask<Void, Integer, Boolean> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Boolean doInBackground(Void... params) {
|
protected Boolean doInBackground(Void... params) {
|
||||||
ContentProviderUtils contentProviderUtils = ContentProviderUtils.Factory.get(context);
|
ContentProviderUtils contentProviderUtils = new ContentProviderUtils(context);
|
||||||
|
|
||||||
if (trackIds.length == 1 && trackIds[0] == -1L) {
|
if (trackIds.length == 1 && trackIds[0] == -1L) {
|
||||||
contentProviderUtils.deleteAllTracks(context);
|
contentProviderUtils.deleteAllTracks(context);
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package de.dennisguse.opentracks;
|
||||||
|
|
||||||
|
public class HelpActivity extends AbstractActivity {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected int getLayoutResId() {
|
||||||
|
return R.layout.help;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -31,7 +31,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import de.dennisguse.opentracks.content.ContentProviderUtils;
|
import de.dennisguse.opentracks.content.ContentProviderUtils;
|
||||||
import de.dennisguse.opentracks.content.Waypoint;
|
import de.dennisguse.opentracks.content.data.Waypoint;
|
||||||
import de.dennisguse.opentracks.fragments.DeleteMarkerDialogFragment.DeleteMarkerCaller;
|
import de.dennisguse.opentracks.fragments.DeleteMarkerDialogFragment.DeleteMarkerCaller;
|
||||||
import de.dennisguse.opentracks.fragments.MarkerDetailFragment;
|
import de.dennisguse.opentracks.fragments.MarkerDetailFragment;
|
||||||
|
|
||||||
@@ -61,7 +61,7 @@ public class MarkerDetailActivity extends AbstractActivity implements DeleteMark
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ContentProviderUtils contentProviderUtils = ContentProviderUtils.Factory.get(this);
|
ContentProviderUtils contentProviderUtils = new ContentProviderUtils(this);
|
||||||
Waypoint waypoint = contentProviderUtils.getWaypoint(markerId);
|
Waypoint waypoint = contentProviderUtils.getWaypoint(markerId);
|
||||||
|
|
||||||
markerIds = new ArrayList<>();
|
markerIds = new ArrayList<>();
|
||||||
@@ -71,12 +71,9 @@ public class MarkerDetailActivity extends AbstractActivity implements DeleteMark
|
|||||||
if (cursor != null && cursor.moveToFirst()) {
|
if (cursor != null && cursor.moveToFirst()) {
|
||||||
for (int i = 0; i < cursor.getCount(); i++) {
|
for (int i = 0; i < cursor.getCount(); i++) {
|
||||||
Waypoint currentMarker = contentProviderUtils.createWaypoint(cursor);
|
Waypoint currentMarker = contentProviderUtils.createWaypoint(cursor);
|
||||||
|
markerIds.add(currentMarker.getId());
|
||||||
if (!currentMarker.isTripStatistics()) {
|
if (currentMarker.getId() == markerId) {
|
||||||
markerIds.add(currentMarker.getId());
|
markerIndex = markerIds.size() - 1;
|
||||||
if (currentMarker.getId() == markerId) {
|
|
||||||
markerIndex = markerIds.size() - 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cursor.moveToNext();
|
cursor.moveToNext();
|
||||||
|
|||||||
@@ -26,9 +26,7 @@ import android.widget.Button;
|
|||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
|
|
||||||
import de.dennisguse.opentracks.content.ContentProviderUtils;
|
import de.dennisguse.opentracks.content.ContentProviderUtils;
|
||||||
import de.dennisguse.opentracks.content.Waypoint;
|
import de.dennisguse.opentracks.content.data.Waypoint;
|
||||||
import de.dennisguse.opentracks.content.Waypoint.WaypointType;
|
|
||||||
import de.dennisguse.opentracks.content.WaypointCreationRequest;
|
|
||||||
import de.dennisguse.opentracks.services.TrackRecordingServiceConnection;
|
import de.dennisguse.opentracks.services.TrackRecordingServiceConnection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -48,9 +46,6 @@ public class MarkerEditActivity extends AbstractActivity {
|
|||||||
private Waypoint waypoint;
|
private Waypoint waypoint;
|
||||||
|
|
||||||
// UI elements
|
// UI elements
|
||||||
private View statisticsSection;
|
|
||||||
private EditText statisticsName;
|
|
||||||
private View waypointSection;
|
|
||||||
private EditText waypointName;
|
private EditText waypointName;
|
||||||
private AutoCompleteTextView waypointMarkerType;
|
private AutoCompleteTextView waypointMarkerType;
|
||||||
private EditText waypointDescription;
|
private EditText waypointDescription;
|
||||||
@@ -65,14 +60,9 @@ public class MarkerEditActivity extends AbstractActivity {
|
|||||||
trackRecordingServiceConnection = new TrackRecordingServiceConnection(this, null);
|
trackRecordingServiceConnection = new TrackRecordingServiceConnection(this, null);
|
||||||
|
|
||||||
// Setup UI elements
|
// Setup UI elements
|
||||||
statisticsSection = findViewById(R.id.marker_edit_statistics_section);
|
|
||||||
statisticsName = findViewById(R.id.marker_edit_statistics_name);
|
|
||||||
|
|
||||||
waypointSection = findViewById(R.id.marker_edit_waypoint_section);
|
|
||||||
waypointName = findViewById(R.id.marker_edit_waypoint_name);
|
waypointName = findViewById(R.id.marker_edit_waypoint_name);
|
||||||
waypointMarkerType = findViewById(R.id.marker_edit_waypoint_marker_type);
|
waypointMarkerType = findViewById(R.id.marker_edit_waypoint_marker_type);
|
||||||
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
|
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.waypoint_types, android.R.layout.simple_dropdown_item_1line);
|
||||||
this, R.array.waypoint_types, android.R.layout.simple_dropdown_item_1line);
|
|
||||||
waypointMarkerType.setAdapter(adapter);
|
waypointMarkerType.setAdapter(adapter);
|
||||||
waypointDescription = findViewById(R.id.marker_edit_waypoint_description);
|
waypointDescription = findViewById(R.id.marker_edit_waypoint_description);
|
||||||
|
|
||||||
@@ -96,7 +86,7 @@ public class MarkerEditActivity extends AbstractActivity {
|
|||||||
@Override
|
@Override
|
||||||
protected void onStop() {
|
protected void onStop() {
|
||||||
super.onStop();
|
super.onStop();
|
||||||
trackRecordingServiceConnection.unbind();
|
trackRecordingServiceConnection.unbind(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -125,9 +115,7 @@ public class MarkerEditActivity extends AbstractActivity {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (newMarker) {
|
if (newMarker) {
|
||||||
statisticsSection.setVisibility(View.GONE);
|
int nextWaypointNumber = trackId == -1L ? -1 : new ContentProviderUtils(this).getNextWaypointNumber(trackId);
|
||||||
waypointSection.setVisibility(View.VISIBLE);
|
|
||||||
int nextWaypointNumber = trackId == -1L ? -1 : ContentProviderUtils.Factory.get(this).getNextWaypointNumber(trackId, WaypointType.WAYPOINT);
|
|
||||||
if (nextWaypointNumber == -1) {
|
if (nextWaypointNumber == -1) {
|
||||||
nextWaypointNumber = 0;
|
nextWaypointNumber = 0;
|
||||||
}
|
}
|
||||||
@@ -136,22 +124,15 @@ public class MarkerEditActivity extends AbstractActivity {
|
|||||||
waypointMarkerType.setText("");
|
waypointMarkerType.setText("");
|
||||||
waypointDescription.setText("");
|
waypointDescription.setText("");
|
||||||
} else {
|
} else {
|
||||||
waypoint = ContentProviderUtils.Factory.get(this).getWaypoint(markerId);
|
waypoint = new ContentProviderUtils(this).getWaypoint(markerId);
|
||||||
if (waypoint == null) {
|
if (waypoint == null) {
|
||||||
Log.d(TAG, "waypoint is null");
|
Log.d(TAG, "waypoint is null");
|
||||||
finish();
|
finish();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
boolean statistics = waypoint.getType() == WaypointType.STATISTICS;
|
waypointName.setText(waypoint.getName());
|
||||||
statisticsSection.setVisibility(statistics ? View.VISIBLE : View.GONE);
|
waypointMarkerType.setText(waypoint.getCategory());
|
||||||
waypointSection.setVisibility(statistics ? View.GONE : View.VISIBLE);
|
waypointDescription.setText(waypoint.getDescription());
|
||||||
if (statistics) {
|
|
||||||
statisticsName.setText(waypoint.getName());
|
|
||||||
} else {
|
|
||||||
waypointName.setText(waypoint.getName());
|
|
||||||
waypointMarkerType.setText(waypoint.getCategory());
|
|
||||||
waypointDescription.setText(waypoint.getDescription());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -159,29 +140,21 @@ public class MarkerEditActivity extends AbstractActivity {
|
|||||||
* Adds a marker.
|
* Adds a marker.
|
||||||
*/
|
*/
|
||||||
private void addMarker() {
|
private void addMarker() {
|
||||||
WaypointCreationRequest waypointCreationRequest = new WaypointCreationRequest(
|
trackRecordingServiceConnection.addMarker(this,
|
||||||
WaypointType.WAYPOINT,
|
|
||||||
false,
|
|
||||||
waypointName.getText().toString(),
|
waypointName.getText().toString(),
|
||||||
waypointMarkerType.getText().toString(),
|
waypointMarkerType.getText().toString(),
|
||||||
waypointDescription.getText().toString(),
|
waypointDescription.getText().toString(),
|
||||||
null,
|
|
||||||
null);
|
null);
|
||||||
trackRecordingServiceConnection.addMarker(this, waypointCreationRequest);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Saves a marker.
|
* Saves a marker.
|
||||||
*/
|
*/
|
||||||
private void saveMarker() {
|
private void saveMarker() {
|
||||||
boolean statistics = waypoint.getType() == WaypointType.STATISTICS;
|
waypoint.setName(waypointName.getText().toString());
|
||||||
if (statistics) {
|
waypoint.setCategory(waypointMarkerType.getText().toString());
|
||||||
waypoint.setName(statisticsName.getText().toString());
|
waypoint.setDescription(waypointDescription.getText().toString());
|
||||||
} else {
|
|
||||||
waypoint.setName(waypointName.getText().toString());
|
new ContentProviderUtils(this).updateWaypoint(waypoint);
|
||||||
waypoint.setCategory(waypointMarkerType.getText().toString());
|
|
||||||
waypoint.setDescription(waypointDescription.getText().toString());
|
|
||||||
}
|
|
||||||
ContentProviderUtils.Factory.get(this).updateWaypoint(waypoint);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,14 +38,14 @@ import androidx.loader.content.CursorLoader;
|
|||||||
import androidx.loader.content.Loader;
|
import androidx.loader.content.Loader;
|
||||||
|
|
||||||
import de.dennisguse.opentracks.content.ContentProviderUtils;
|
import de.dennisguse.opentracks.content.ContentProviderUtils;
|
||||||
import de.dennisguse.opentracks.content.Track;
|
import de.dennisguse.opentracks.content.data.Track;
|
||||||
import de.dennisguse.opentracks.content.Waypoint.WaypointType;
|
import de.dennisguse.opentracks.content.data.WaypointsColumns;
|
||||||
import de.dennisguse.opentracks.content.WaypointsColumns;
|
|
||||||
import de.dennisguse.opentracks.fragments.DeleteMarkerDialogFragment;
|
import de.dennisguse.opentracks.fragments.DeleteMarkerDialogFragment;
|
||||||
import de.dennisguse.opentracks.fragments.DeleteMarkerDialogFragment.DeleteMarkerCaller;
|
import de.dennisguse.opentracks.fragments.DeleteMarkerDialogFragment.DeleteMarkerCaller;
|
||||||
import de.dennisguse.opentracks.util.ActivityUtils;
|
import de.dennisguse.opentracks.util.ActivityUtils;
|
||||||
import de.dennisguse.opentracks.util.IntentUtils;
|
import de.dennisguse.opentracks.util.IntentUtils;
|
||||||
import de.dennisguse.opentracks.util.ListItemUtils;
|
import de.dennisguse.opentracks.util.ListItemUtils;
|
||||||
|
import de.dennisguse.opentracks.util.MarkerUtils;
|
||||||
import de.dennisguse.opentracks.util.PreferencesUtils;
|
import de.dennisguse.opentracks.util.PreferencesUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -69,21 +69,20 @@ public class MarkerListActivity extends AbstractActivity implements DeleteMarker
|
|||||||
private SharedPreferences sharedPreferences;
|
private SharedPreferences sharedPreferences;
|
||||||
|
|
||||||
private long recordingTrackId = PreferencesUtils.RECORDING_TRACK_ID_DEFAULT;
|
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
|
* Note that sharedPreferenceChangeListener cannot be an anonymous inner
|
||||||
* class. Anonymous inner class will get garbage collected.
|
* class. Anonymous inner class will get garbage collected.
|
||||||
*/
|
*/
|
||||||
private final OnSharedPreferenceChangeListener
|
private final OnSharedPreferenceChangeListener sharedPreferenceChangeListener = new OnSharedPreferenceChangeListener() {
|
||||||
sharedPreferenceChangeListener = new OnSharedPreferenceChangeListener() {
|
|
||||||
@Override
|
@Override
|
||||||
public void onSharedPreferenceChanged(SharedPreferences preferences, String key) {
|
public void onSharedPreferenceChanged(SharedPreferences preferences, String key) {
|
||||||
// Note that the key can be null
|
// Note that the key can be null
|
||||||
if (key == null || key.equals(PreferencesUtils.getKey(MarkerListActivity.this, R.string.recording_track_id_key))) {
|
if (PreferencesUtils.isKey(MarkerListActivity.this, R.string.recording_track_id_key, key)) {
|
||||||
recordingTrackId = PreferencesUtils.getLong(MarkerListActivity.this, R.string.recording_track_id_key);
|
recordingTrackId = PreferencesUtils.getRecordingTrackId(MarkerListActivity.this);
|
||||||
}
|
}
|
||||||
if (key == null || key.equals(PreferencesUtils.getKey(MarkerListActivity.this, R.string.recording_track_paused_key))) {
|
if (PreferencesUtils.isKey(MarkerListActivity.this, R.string.recording_track_paused_key, key)) {
|
||||||
recordingTrackPaused = PreferencesUtils.getBoolean(MarkerListActivity.this, R.string.recording_track_paused_key, PreferencesUtils.RECORDING_TRACK_PAUSED_DEFAULT);
|
recordingTrackPaused = PreferencesUtils.isRecordingTrackPaused(MarkerListActivity.this);
|
||||||
}
|
}
|
||||||
if (key != null) {
|
if (key != null) {
|
||||||
runOnUiThread(new Runnable() {
|
runOnUiThread(new Runnable() {
|
||||||
@@ -127,15 +126,14 @@ public class MarkerListActivity extends AbstractActivity implements DeleteMarker
|
|||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
setDefaultKeyMode(DEFAULT_KEYS_SEARCH_LOCAL);
|
||||||
|
long trackId = getIntent().getLongExtra(EXTRA_TRACK_ID, -1L);
|
||||||
|
recordingTrackPaused = PreferencesUtils.isRecordingTrackPausedDefault(this);
|
||||||
|
|
||||||
contentProviderUtils = ContentProviderUtils.Factory.get(this);
|
contentProviderUtils = new ContentProviderUtils(this);
|
||||||
sharedPreferences = PreferencesUtils.getSharedPreferences(this);
|
sharedPreferences = PreferencesUtils.getSharedPreferences(this);
|
||||||
|
|
||||||
long trackId = getIntent().getLongExtra(EXTRA_TRACK_ID, -1L);
|
|
||||||
track = trackId != -1L ? contentProviderUtils.getTrack(trackId) : null;
|
track = trackId != -1L ? contentProviderUtils.getTrack(trackId) : null;
|
||||||
final long trackFirstWaypointId = trackId != -1 ? contentProviderUtils.getFirstWaypointId(trackId) : -1;
|
|
||||||
|
|
||||||
setDefaultKeyMode(DEFAULT_KEYS_SEARCH_LOCAL);
|
|
||||||
|
|
||||||
listView = findViewById(R.id.marker_list);
|
listView = findViewById(R.id.marker_list);
|
||||||
listView.setEmptyView(findViewById(R.id.marker_list_empty));
|
listView.setEmptyView(findViewById(R.id.marker_list_empty));
|
||||||
@@ -150,7 +148,6 @@ public class MarkerListActivity extends AbstractActivity implements DeleteMarker
|
|||||||
resourceCursorAdapter = new ResourceCursorAdapter(this, R.layout.list_item, null, 0) {
|
resourceCursorAdapter = new ResourceCursorAdapter(this, R.layout.list_item, null, 0) {
|
||||||
@Override
|
@Override
|
||||||
public void bindView(View view, Context context, Cursor cursor) {
|
public void bindView(View view, Context context, Cursor cursor) {
|
||||||
int typeIndex = cursor.getColumnIndex(WaypointsColumns.TYPE);
|
|
||||||
int nameIndex = cursor.getColumnIndex(WaypointsColumns.NAME);
|
int nameIndex = cursor.getColumnIndex(WaypointsColumns.NAME);
|
||||||
int timeIndex = cursor.getColumnIndexOrThrow(WaypointsColumns.TIME);
|
int timeIndex = cursor.getColumnIndexOrThrow(WaypointsColumns.TIME);
|
||||||
int categoryIndex = cursor.getColumnIndex(WaypointsColumns.CATEGORY);
|
int categoryIndex = cursor.getColumnIndex(WaypointsColumns.CATEGORY);
|
||||||
@@ -159,13 +156,13 @@ public class MarkerListActivity extends AbstractActivity implements DeleteMarker
|
|||||||
int latitudeIndex = cursor.getColumnIndex(WaypointsColumns.LATITUDE);
|
int latitudeIndex = cursor.getColumnIndex(WaypointsColumns.LATITUDE);
|
||||||
int longitudeIndex = cursor.getColumnIndex(WaypointsColumns.LONGITUDE);
|
int longitudeIndex = cursor.getColumnIndex(WaypointsColumns.LONGITUDE);
|
||||||
|
|
||||||
boolean statistics = WaypointType.values()[cursor.getInt(typeIndex)] == WaypointType.STATISTICS;
|
int iconId = MarkerUtils.ICON_ID;
|
||||||
int iconId = statistics ? R.drawable.ic_marker_yellow_pushpin : R.drawable.ic_marker_blue_pushpin;
|
|
||||||
String name = cursor.getString(nameIndex);
|
String name = cursor.getString(nameIndex);
|
||||||
long time = cursor.getLong(timeIndex);
|
long time = cursor.getLong(timeIndex);
|
||||||
String category = statistics ? null : cursor.getString(categoryIndex);
|
String category = cursor.getString(categoryIndex);
|
||||||
String description = statistics ? null : cursor.getString(descriptionIndex);
|
String description = cursor.getString(descriptionIndex);
|
||||||
String photoUrl = cursor.getString(photoUrlIndex);
|
String photoUrl = cursor.getString(photoUrlIndex);
|
||||||
|
//TODO also show latitude and longitude in list
|
||||||
double latitude = cursor.getDouble(latitudeIndex);
|
double latitude = cursor.getDouble(latitudeIndex);
|
||||||
double longitude = cursor.getDouble(longitudeIndex);
|
double longitude = cursor.getDouble(longitudeIndex);
|
||||||
|
|
||||||
@@ -181,8 +178,8 @@ public class MarkerListActivity extends AbstractActivity implements DeleteMarker
|
|||||||
public Loader<Cursor> onCreateLoader(int arg0, Bundle arg1) {
|
public Loader<Cursor> onCreateLoader(int arg0, Bundle arg1) {
|
||||||
if (track != null) {
|
if (track != null) {
|
||||||
return new CursorLoader(MarkerListActivity.this, WaypointsColumns.CONTENT_URI, PROJECTION,
|
return new CursorLoader(MarkerListActivity.this, WaypointsColumns.CONTENT_URI, PROJECTION,
|
||||||
WaypointsColumns.TRACKID + "=? AND " + WaypointsColumns._ID + "!=?",
|
WaypointsColumns.TRACKID + "=?",
|
||||||
new String[]{String.valueOf(track.getId()), String.valueOf(trackFirstWaypointId)}, null);
|
new String[]{String.valueOf(track.getId())}, null);
|
||||||
} else {
|
} else {
|
||||||
return new CursorLoader(MarkerListActivity.this, WaypointsColumns.CONTENT_URI, PROJECTION,
|
return new CursorLoader(MarkerListActivity.this, WaypointsColumns.CONTENT_URI, PROJECTION,
|
||||||
WaypointsColumns.STARTTIME + " IS NULL", null, null);
|
WaypointsColumns.STARTTIME + " IS NULL", null, null);
|
||||||
@@ -244,7 +241,7 @@ public class MarkerListActivity extends AbstractActivity implements DeleteMarker
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
|
||||||
if (track != null && item.getItemId() == R.id.marker_list_insert_marker) {
|
if (track != null && item.getItemId() == R.id.marker_list_insert_marker) {
|
||||||
Intent intent = IntentUtils.newIntent(this, MarkerEditActivity.class)
|
Intent intent = IntentUtils.newIntent(this, MarkerEditActivity.class)
|
||||||
.putExtra(MarkerEditActivity.EXTRA_TRACK_ID, track.getId());
|
.putExtra(MarkerEditActivity.EXTRA_TRACK_ID, track.getId());
|
||||||
|
|||||||
@@ -44,9 +44,8 @@ import de.dennisguse.opentracks.content.ContentProviderUtils;
|
|||||||
import de.dennisguse.opentracks.content.SearchEngine;
|
import de.dennisguse.opentracks.content.SearchEngine;
|
||||||
import de.dennisguse.opentracks.content.SearchEngine.ScoredResult;
|
import de.dennisguse.opentracks.content.SearchEngine.ScoredResult;
|
||||||
import de.dennisguse.opentracks.content.SearchEngine.SearchQuery;
|
import de.dennisguse.opentracks.content.SearchEngine.SearchQuery;
|
||||||
import de.dennisguse.opentracks.content.Track;
|
import de.dennisguse.opentracks.content.data.Track;
|
||||||
import de.dennisguse.opentracks.content.Waypoint;
|
import de.dennisguse.opentracks.content.data.Waypoint;
|
||||||
import de.dennisguse.opentracks.content.Waypoint.WaypointType;
|
|
||||||
import de.dennisguse.opentracks.fragments.ConfirmDeleteDialogFragment;
|
import de.dennisguse.opentracks.fragments.ConfirmDeleteDialogFragment;
|
||||||
import de.dennisguse.opentracks.fragments.DeleteMarkerDialogFragment;
|
import de.dennisguse.opentracks.fragments.DeleteMarkerDialogFragment;
|
||||||
import de.dennisguse.opentracks.fragments.DeleteMarkerDialogFragment.DeleteMarkerCaller;
|
import de.dennisguse.opentracks.fragments.DeleteMarkerDialogFragment.DeleteMarkerCaller;
|
||||||
@@ -55,9 +54,9 @@ import de.dennisguse.opentracks.stats.TripStatistics;
|
|||||||
import de.dennisguse.opentracks.util.ActivityUtils;
|
import de.dennisguse.opentracks.util.ActivityUtils;
|
||||||
import de.dennisguse.opentracks.util.IntentUtils;
|
import de.dennisguse.opentracks.util.IntentUtils;
|
||||||
import de.dennisguse.opentracks.util.ListItemUtils;
|
import de.dennisguse.opentracks.util.ListItemUtils;
|
||||||
|
import de.dennisguse.opentracks.util.MarkerUtils;
|
||||||
import de.dennisguse.opentracks.util.PreferencesUtils;
|
import de.dennisguse.opentracks.util.PreferencesUtils;
|
||||||
import de.dennisguse.opentracks.util.StringUtils;
|
import de.dennisguse.opentracks.util.StringUtils;
|
||||||
import de.dennisguse.opentracks.util.ToolbarUtils;
|
|
||||||
import de.dennisguse.opentracks.util.TrackIconUtils;
|
import de.dennisguse.opentracks.util.TrackIconUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -102,7 +101,7 @@ public class SearchListActivity extends AbstractListActivity implements DeleteMa
|
|||||||
|
|
||||||
private long recordingTrackId = PreferencesUtils.RECORDING_TRACK_ID_DEFAULT;
|
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
|
// Callback when an item is selected in the contextual action mode
|
||||||
private ContextualActionModeCallback contextualActionModeCallback = new ContextualActionModeCallback() {
|
private ContextualActionModeCallback contextualActionModeCallback = new ContextualActionModeCallback() {
|
||||||
@@ -123,10 +122,6 @@ public class SearchListActivity extends AbstractListActivity implements DeleteMa
|
|||||||
MenuItem shareMenuItem = menu.findItem(R.id.list_context_menu_share);
|
MenuItem shareMenuItem = menu.findItem(R.id.list_context_menu_share);
|
||||||
if (isSingleSelectionTrack) {
|
if (isSingleSelectionTrack) {
|
||||||
shareMenuItem.setVisible(!isRecording);
|
shareMenuItem.setVisible(!isRecording);
|
||||||
Map<String, Object> item = arrayAdapter.getItem(positions[0]);
|
|
||||||
Long trackId = (Long) item.get(TRACK_ID_FIELD);
|
|
||||||
|
|
||||||
ToolbarUtils.setupShareActionProvider(SearchListActivity.this, shareMenuItem, new long[]{trackId});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// One item, item is a marker
|
// One item, item is a marker
|
||||||
@@ -148,14 +143,14 @@ public class SearchListActivity extends AbstractListActivity implements DeleteMa
|
|||||||
private final OnSharedPreferenceChangeListener sharedPreferenceChangeListener = new OnSharedPreferenceChangeListener() {
|
private final OnSharedPreferenceChangeListener sharedPreferenceChangeListener = new OnSharedPreferenceChangeListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onSharedPreferenceChanged(SharedPreferences preferences, String key) {
|
public void onSharedPreferenceChanged(SharedPreferences preferences, String key) {
|
||||||
if (key == null || key.equals(PreferencesUtils.getKey(SearchListActivity.this, R.string.stats_units_key))) {
|
if (PreferencesUtils.isKey(SearchListActivity.this, R.string.stats_units_key, key)) {
|
||||||
metricUnits = PreferencesUtils.isMetricUnits(SearchListActivity.this);
|
metricUnits = PreferencesUtils.isMetricUnits(SearchListActivity.this);
|
||||||
}
|
}
|
||||||
if (key == null || key.equals(PreferencesUtils.getKey(SearchListActivity.this, R.string.recording_track_id_key))) {
|
if (PreferencesUtils.isKey(SearchListActivity.this, R.string.recording_track_id_key, key)) {
|
||||||
recordingTrackId = PreferencesUtils.getLong(SearchListActivity.this, R.string.recording_track_id_key);
|
recordingTrackId = PreferencesUtils.getRecordingTrackId(SearchListActivity.this);
|
||||||
}
|
}
|
||||||
if (key == null || key.equals(PreferencesUtils.getKey(SearchListActivity.this, R.string.recording_track_paused_key))) {
|
if (PreferencesUtils.isKey(SearchListActivity.this, R.string.recording_track_paused_key, key)) {
|
||||||
recordingTrackPaused = PreferencesUtils.getBoolean(SearchListActivity.this, R.string.recording_track_paused_key, PreferencesUtils.RECORDING_TRACK_PAUSED_DEFAULT);
|
recordingTrackPaused = PreferencesUtils.isRecordingTrackPaused(SearchListActivity.this);
|
||||||
}
|
}
|
||||||
if (key != null) {
|
if (key != null) {
|
||||||
runOnUiThread(new Runnable() {
|
runOnUiThread(new Runnable() {
|
||||||
@@ -173,7 +168,9 @@ public class SearchListActivity extends AbstractListActivity implements DeleteMa
|
|||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setDefaultKeyMode(DEFAULT_KEYS_SEARCH_LOCAL);
|
setDefaultKeyMode(DEFAULT_KEYS_SEARCH_LOCAL);
|
||||||
|
|
||||||
contentProviderUtils = ContentProviderUtils.Factory.get(this);
|
recordingTrackPaused = PreferencesUtils.isRecordingTrackPausedDefault(this);
|
||||||
|
|
||||||
|
contentProviderUtils = new ContentProviderUtils(this);
|
||||||
sharedPreferences = PreferencesUtils.getSharedPreferences(this);
|
sharedPreferences = PreferencesUtils.getSharedPreferences(this);
|
||||||
trackRecordingServiceConnection = new TrackRecordingServiceConnection(this, null);
|
trackRecordingServiceConnection = new TrackRecordingServiceConnection(this, null);
|
||||||
searchEngine = new SearchEngine(contentProviderUtils);
|
searchEngine = new SearchEngine(contentProviderUtils);
|
||||||
@@ -248,7 +245,7 @@ public class SearchListActivity extends AbstractListActivity implements DeleteMa
|
|||||||
protected void onStop() {
|
protected void onStop() {
|
||||||
super.onStop();
|
super.onStop();
|
||||||
sharedPreferences.unregisterOnSharedPreferenceChangeListener(sharedPreferenceChangeListener);
|
sharedPreferences.unregisterOnSharedPreferenceChangeListener(sharedPreferenceChangeListener);
|
||||||
trackRecordingServiceConnection.unbind();
|
trackRecordingServiceConnection.unbind(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -290,6 +287,11 @@ public class SearchListActivity extends AbstractListActivity implements DeleteMa
|
|||||||
case R.id.list_context_menu_show_on_map:
|
case R.id.list_context_menu_show_on_map:
|
||||||
IntentUtils.showCoordinateOnMap(this, (double) item.get(MARKER_LATITUDE_FIELD), (double) item.get(MARKER_LONGITUDE_FIELD), item.get(NAME_FIELD) + "");
|
IntentUtils.showCoordinateOnMap(this, (double) item.get(MARKER_LATITUDE_FIELD), (double) item.get(MARKER_LONGITUDE_FIELD), item.get(NAME_FIELD) + "");
|
||||||
return true;
|
return true;
|
||||||
|
case R.id.list_context_menu_share:
|
||||||
|
intent = IntentUtils.newShareFileIntent(this, new long[]{trackId});
|
||||||
|
intent = Intent.createChooser(intent, null);
|
||||||
|
startActivity(intent);
|
||||||
|
return true;
|
||||||
case R.id.list_context_menu_edit:
|
case R.id.list_context_menu_edit:
|
||||||
if (markerId != null) {
|
if (markerId != null) {
|
||||||
intent = IntentUtils.newIntent(this, MarkerEditActivity.class)
|
intent = IntentUtils.newIntent(this, MarkerEditActivity.class)
|
||||||
@@ -391,11 +393,9 @@ public class SearchListActivity extends AbstractListActivity implements DeleteMa
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean statistics = waypoint.getType() == WaypointType.STATISTICS;
|
|
||||||
|
|
||||||
resultMap.put(IS_RECORDING_FIELD, false);
|
resultMap.put(IS_RECORDING_FIELD, false);
|
||||||
resultMap.put(IS_PAUSED_FIELD, true);
|
resultMap.put(IS_PAUSED_FIELD, true);
|
||||||
resultMap.put(ICON_ID_FIELD, statistics ? R.drawable.ic_marker_yellow_pushpin : R.drawable.ic_marker_blue_pushpin);
|
resultMap.put(ICON_ID_FIELD, MarkerUtils.ICON_ID);
|
||||||
resultMap.put(ICON_CONTENT_DESCRIPTION_ID_FIELD, R.string.image_marker);
|
resultMap.put(ICON_CONTENT_DESCRIPTION_ID_FIELD, R.string.image_marker);
|
||||||
resultMap.put(NAME_FIELD, waypoint.getName());
|
resultMap.put(NAME_FIELD, waypoint.getName());
|
||||||
// Display the marker's track name in the total time field
|
// Display the marker's track name in the total time field
|
||||||
@@ -403,8 +403,8 @@ public class SearchListActivity extends AbstractListActivity implements DeleteMa
|
|||||||
resultMap.put(TOTAL_DISTANCE_FIELD, null);
|
resultMap.put(TOTAL_DISTANCE_FIELD, null);
|
||||||
resultMap.put(MARKER_COUNT_FIELD, 0);
|
resultMap.put(MARKER_COUNT_FIELD, 0);
|
||||||
resultMap.put(START_TIME_FIELD, waypoint.getLocation().getTime());
|
resultMap.put(START_TIME_FIELD, waypoint.getLocation().getTime());
|
||||||
resultMap.put(CATEGORY_FIELD, statistics ? null : waypoint.getCategory());
|
resultMap.put(CATEGORY_FIELD, waypoint.getCategory());
|
||||||
resultMap.put(DESCRIPTION_FIELD, statistics ? null : waypoint.getDescription());
|
resultMap.put(DESCRIPTION_FIELD, waypoint.getDescription());
|
||||||
resultMap.put(PHOTO_URL_FIELD, waypoint.getPhotoUrl());
|
resultMap.put(PHOTO_URL_FIELD, waypoint.getPhotoUrl());
|
||||||
resultMap.put(TRACK_ID_FIELD, waypoint.getTrackId());
|
resultMap.put(TRACK_ID_FIELD, waypoint.getTrackId());
|
||||||
resultMap.put(MARKER_ID_FIELD, waypoint.getId());
|
resultMap.put(MARKER_ID_FIELD, waypoint.getId());
|
||||||
|
|||||||
@@ -1,151 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2013q Google Inc.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
|
||||||
* use this file except in compliance with the License. You may obtain a copy of
|
|
||||||
* the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
||||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
||||||
* License for the specific language governing permissions and limitations under
|
|
||||||
* the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package de.dennisguse.opentracks;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.view.View;
|
|
||||||
import android.view.ViewGroup;
|
|
||||||
import android.widget.TabHost;
|
|
||||||
import android.widget.TabHost.TabContentFactory;
|
|
||||||
import android.widget.TabWidget;
|
|
||||||
|
|
||||||
import androidx.fragment.app.Fragment;
|
|
||||||
import androidx.fragment.app.FragmentActivity;
|
|
||||||
import androidx.fragment.app.FragmentPagerAdapter;
|
|
||||||
import androidx.viewpager.widget.ViewPager;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This is a helper class that implements the management of tabs and all details
|
|
||||||
* of connecting a ViewPager with associated TabHost. It relies on a trick.
|
|
||||||
* Normally a tab host has a simple API for supplying a View or Intent that each
|
|
||||||
* tab will show. This is not sufficient for switching between pages. So instead
|
|
||||||
* we make the content part of the tab host 0dp high (it is not shown) and the
|
|
||||||
* TabsAdapter supplies its own dummy view to show as the tab content. It
|
|
||||||
* listens to changes in tabs, and takes care of switch to the correct paged in
|
|
||||||
* the ViewPager whenever the selected tab changes.
|
|
||||||
* <p>
|
|
||||||
* Copied from the FragmentTabsPager sample in the support library.
|
|
||||||
*
|
|
||||||
* @author Jimmy Shih
|
|
||||||
*/
|
|
||||||
//TODO Rework or better remove.
|
|
||||||
public class TabsAdapter extends FragmentPagerAdapter implements TabHost.OnTabChangeListener, ViewPager.OnPageChangeListener {
|
|
||||||
|
|
||||||
private final Context context;
|
|
||||||
private final TabHost tabHost;
|
|
||||||
private final ViewPager viewPager;
|
|
||||||
private final ArrayList<TabInfo> tabInfos = new ArrayList<>();
|
|
||||||
|
|
||||||
public TabsAdapter(FragmentActivity activity, TabHost tabHost, ViewPager viewPager) {
|
|
||||||
super(activity.getSupportFragmentManager());
|
|
||||||
this.context = activity;
|
|
||||||
this.tabHost = tabHost;
|
|
||||||
this.viewPager = viewPager;
|
|
||||||
this.tabHost.setOnTabChangedListener(this);
|
|
||||||
this.viewPager.setAdapter(this);
|
|
||||||
this.viewPager.setOnPageChangeListener(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addTab(TabHost.TabSpec tabSpec, Class<?> clss, Bundle bundle) {
|
|
||||||
tabSpec.setContent(new DummyTabFactory(context));
|
|
||||||
|
|
||||||
TabInfo info = new TabInfo(clss, bundle);
|
|
||||||
|
|
||||||
tabInfos.add(info);
|
|
||||||
tabHost.addTab(tabSpec);
|
|
||||||
notifyDataSetChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getCount() {
|
|
||||||
return tabInfos.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Fragment getItem(int position) {
|
|
||||||
TabInfo info = tabInfos.get(position);
|
|
||||||
return Fragment.instantiate(context, info.clss.getName(), info.bundle);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onTabChanged(String tabId) {
|
|
||||||
int position = tabHost.getCurrentTab();
|
|
||||||
viewPager.setCurrentItem(position);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onPageSelected(int position) {
|
|
||||||
/*
|
|
||||||
* Unfortunately when TabHost changes the current tab, it kindly also takes care of putting focus on it when not in touch mode.
|
|
||||||
* The jerk. This hack tries to prevent this from pulling focus out of our ViewPager.
|
|
||||||
*/
|
|
||||||
TabWidget tabWidget = tabHost.getTabWidget();
|
|
||||||
int oldFocusability = tabWidget.getDescendantFocusability();
|
|
||||||
tabWidget.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);
|
|
||||||
tabHost.setCurrentTab(position);
|
|
||||||
tabWidget.setDescendantFocusability(oldFocusability);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onPageScrollStateChanged(int state) {
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* An object to hold a tab's info.
|
|
||||||
*
|
|
||||||
* @author Jimmy Shih
|
|
||||||
*/
|
|
||||||
private static final class TabInfo {
|
|
||||||
|
|
||||||
private final Class<?> clss;
|
|
||||||
private final Bundle bundle;
|
|
||||||
|
|
||||||
TabInfo(Class<?> clss, Bundle bundle) {
|
|
||||||
this.clss = clss;
|
|
||||||
this.bundle = bundle;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A dummy {@link TabContentFactory} that creates an empty view to satisfy the {@link TabHost} API.
|
|
||||||
*
|
|
||||||
* @author Jimmy Shih
|
|
||||||
*/
|
|
||||||
private static class DummyTabFactory implements TabHost.TabContentFactory {
|
|
||||||
|
|
||||||
private final Context context;
|
|
||||||
|
|
||||||
DummyTabFactory(Context context) {
|
|
||||||
this.context = context;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public View createTabContent(String tag) {
|
|
||||||
View view = new View(context);
|
|
||||||
view.setMinimumWidth(0);
|
|
||||||
view.setMinimumHeight(0);
|
|
||||||
return view;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -31,31 +31,30 @@ import android.view.MenuItem;
|
|||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.View.OnClickListener;
|
import android.view.View.OnClickListener;
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
import android.widget.TabHost;
|
|
||||||
import android.widget.TabHost.TabSpec;
|
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
import androidx.core.app.ActivityCompat;
|
import androidx.core.app.ActivityCompat;
|
||||||
|
import androidx.fragment.app.Fragment;
|
||||||
|
import androidx.fragment.app.FragmentPagerAdapter;
|
||||||
import androidx.viewpager.widget.ViewPager;
|
import androidx.viewpager.widget.ViewPager;
|
||||||
|
|
||||||
|
import com.google.android.material.tabs.TabLayout;
|
||||||
|
|
||||||
import de.dennisguse.opentracks.content.ContentProviderUtils;
|
import de.dennisguse.opentracks.content.ContentProviderUtils;
|
||||||
import de.dennisguse.opentracks.content.Track;
|
|
||||||
import de.dennisguse.opentracks.content.TrackDataHub;
|
import de.dennisguse.opentracks.content.TrackDataHub;
|
||||||
import de.dennisguse.opentracks.content.Waypoint;
|
import de.dennisguse.opentracks.content.data.Track;
|
||||||
import de.dennisguse.opentracks.content.Waypoint.WaypointType;
|
import de.dennisguse.opentracks.content.data.Waypoint;
|
||||||
import de.dennisguse.opentracks.content.WaypointCreationRequest;
|
import de.dennisguse.opentracks.fragments.ChartDistanceFragment;
|
||||||
import de.dennisguse.opentracks.fragments.ChartFragment;
|
import de.dennisguse.opentracks.fragments.ChartTimeFragment;
|
||||||
import de.dennisguse.opentracks.fragments.ChooseActivityTypeDialogFragment;
|
import de.dennisguse.opentracks.fragments.ChooseActivityTypeDialogFragment;
|
||||||
import de.dennisguse.opentracks.fragments.ConfirmDeleteDialogFragment;
|
import de.dennisguse.opentracks.fragments.ConfirmDeleteDialogFragment;
|
||||||
import de.dennisguse.opentracks.fragments.FrequencyDialogFragment;
|
|
||||||
import de.dennisguse.opentracks.fragments.StatsFragment;
|
import de.dennisguse.opentracks.fragments.StatsFragment;
|
||||||
import de.dennisguse.opentracks.services.TrackRecordingServiceConnection;
|
import de.dennisguse.opentracks.services.TrackRecordingServiceConnection;
|
||||||
import de.dennisguse.opentracks.settings.SettingsActivity;
|
import de.dennisguse.opentracks.settings.SettingsActivity;
|
||||||
import de.dennisguse.opentracks.util.FileUtils;
|
|
||||||
import de.dennisguse.opentracks.util.IntentUtils;
|
import de.dennisguse.opentracks.util.IntentUtils;
|
||||||
import de.dennisguse.opentracks.util.PreferencesUtils;
|
import de.dennisguse.opentracks.util.PreferencesUtils;
|
||||||
import de.dennisguse.opentracks.util.ToolbarUtils;
|
|
||||||
import de.dennisguse.opentracks.util.TrackIconUtils;
|
import de.dennisguse.opentracks.util.TrackIconUtils;
|
||||||
import de.dennisguse.opentracks.util.TrackUtils;
|
import de.dennisguse.opentracks.util.TrackUtils;
|
||||||
|
|
||||||
@@ -87,7 +86,7 @@ public class TrackDetailActivity extends AbstractListActivity implements ChooseA
|
|||||||
private SharedPreferences sharedPreferences;
|
private SharedPreferences sharedPreferences;
|
||||||
private TrackRecordingServiceConnection trackRecordingServiceConnection;
|
private TrackRecordingServiceConnection trackRecordingServiceConnection;
|
||||||
private TrackDataHub trackDataHub;
|
private TrackDataHub trackDataHub;
|
||||||
private TabHost tabHost;
|
private ViewPager pager;
|
||||||
private TrackController trackController;
|
private TrackController trackController;
|
||||||
|
|
||||||
// From intent
|
// From intent
|
||||||
@@ -95,8 +94,7 @@ public class TrackDetailActivity extends AbstractListActivity implements ChooseA
|
|||||||
|
|
||||||
// Preferences
|
// Preferences
|
||||||
private long recordingTrackId = PreferencesUtils.RECORDING_TRACK_ID_DEFAULT;
|
private long recordingTrackId = PreferencesUtils.RECORDING_TRACK_ID_DEFAULT;
|
||||||
private boolean recordingTrackPaused = PreferencesUtils.RECORDING_TRACK_PAUSED_DEFAULT;
|
private boolean recordingTrackPaused;
|
||||||
private boolean showOnLockScreen = PreferencesUtils.SHOW_TRACKDETAIL_WHILE_RECORDING_ON_LOCKSCREEN;
|
|
||||||
|
|
||||||
private final Runnable bindChangedCallback = new Runnable() {
|
private final Runnable bindChangedCallback = new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
@@ -108,36 +106,35 @@ public class TrackDetailActivity extends AbstractListActivity implements ChooseA
|
|||||||
trackController.update(isRecording(), recordingTrackPaused);
|
trackController.update(isRecording(), recordingTrackPaused);
|
||||||
if (hasPhoto && photoUri != null) {
|
if (hasPhoto && photoUri != null) {
|
||||||
hasPhoto = false;
|
hasPhoto = false;
|
||||||
WaypointCreationRequest waypointCreationRequest = new WaypointCreationRequest(WaypointType.WAYPOINT, false, null, null, null, null, photoUri.toString());
|
long markerId = trackRecordingServiceConnection.addMarker(TrackDetailActivity.this, null, null, null, photoUri.toString());
|
||||||
long markerId = trackRecordingServiceConnection.addMarker(TrackDetailActivity.this, waypointCreationRequest);
|
|
||||||
if (markerId != -1L) {
|
|
||||||
//TODO: Make configurable.
|
|
||||||
FileUtils.updateMediaScanner(TrackDetailActivity.this, photoUri);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
/*
|
|
||||||
* Note that sharedPreferenceChangeListener cannot be an anonymous inner
|
// Note that sharedPreferenceChangeListener cannot be an anonymous inner class. Anonymous inner class will get garbage collected.
|
||||||
* class. Anonymous inner class will get garbage collected.
|
private final OnSharedPreferenceChangeListener sharedPreferenceChangeListener = new OnSharedPreferenceChangeListener() {
|
||||||
*/
|
|
||||||
private final OnSharedPreferenceChangeListener
|
|
||||||
sharedPreferenceChangeListener = new OnSharedPreferenceChangeListener() {
|
|
||||||
@Override
|
@Override
|
||||||
public void onSharedPreferenceChanged(SharedPreferences preferences, String key) {
|
public void onSharedPreferenceChanged(SharedPreferences preferences, String key) {
|
||||||
if (key == null || key.equals(PreferencesUtils.getKey(TrackDetailActivity.this, R.string.recording_track_id_key))) {
|
if (PreferencesUtils.isKey(TrackDetailActivity.this, R.string.recording_track_id_key, key)) {
|
||||||
recordingTrackId = PreferencesUtils.getLong(TrackDetailActivity.this, R.string.recording_track_id_key);
|
recordingTrackId = PreferencesUtils.getRecordingTrackId(TrackDetailActivity.this);
|
||||||
}
|
|
||||||
|
|
||||||
if (key == null || key.equals(PreferencesUtils.getKey(TrackDetailActivity.this, R.string.recording_track_paused_key))) {
|
|
||||||
recordingTrackPaused = PreferencesUtils.getBoolean(TrackDetailActivity.this, R.string.recording_track_paused_key, PreferencesUtils.RECORDING_TRACK_PAUSED_DEFAULT);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (key == null || key.equals(PreferencesUtils.getKey(TrackDetailActivity.this, R.string.trackdetail_show_on_lockscreen_while_recording_key))) {
|
|
||||||
showOnLockScreen = PreferencesUtils.getBoolean(TrackDetailActivity.this, R.string.trackdetail_show_on_lockscreen_while_recording_key, PreferencesUtils.SHOW_TRACKDETAIL_WHILE_RECORDING_ON_LOCKSCREEN);
|
|
||||||
setLockscreenPolicy();
|
setLockscreenPolicy();
|
||||||
|
setScreenOnPolicy();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (PreferencesUtils.isKey(TrackDetailActivity.this, R.string.recording_track_paused_key, key)) {
|
||||||
|
recordingTrackPaused = PreferencesUtils.isRecordingTrackPaused(TrackDetailActivity.this);
|
||||||
|
setLockscreenPolicy();
|
||||||
|
setScreenOnPolicy();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (PreferencesUtils.isKey(TrackDetailActivity.this, R.string.stats_show_on_lockscreen_while_recording_key, key)) {
|
||||||
|
setLockscreenPolicy();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (PreferencesUtils.isKey(TrackDetailActivity.this, R.string.stats_keep_screen_on_while_recording_key, key)) {
|
||||||
|
setScreenOnPolicy();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (key == null) return;
|
if (key == null) return;
|
||||||
@@ -157,8 +154,6 @@ public class TrackDetailActivity extends AbstractListActivity implements ChooseA
|
|||||||
private MenuItem insertPhotoMenuItem;
|
private MenuItem insertPhotoMenuItem;
|
||||||
private MenuItem markerListMenuItem;
|
private MenuItem markerListMenuItem;
|
||||||
private MenuItem shareMenuItem;
|
private MenuItem shareMenuItem;
|
||||||
private MenuItem voiceFrequencyMenuItem;
|
|
||||||
private MenuItem splitFrequencyMenuItem;
|
|
||||||
|
|
||||||
private final OnClickListener recordListener = new OnClickListener() {
|
private final OnClickListener recordListener = new OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
@@ -188,11 +183,13 @@ public class TrackDetailActivity extends AbstractListActivity implements ChooseA
|
|||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
recordingTrackPaused = PreferencesUtils.isRecordingTrackPausedDefault(this);
|
||||||
|
|
||||||
hasCamera = getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA);
|
hasCamera = getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA);
|
||||||
photoUri = savedInstanceState != null ? (Uri) savedInstanceState.getParcelable(PHOTO_URI_KEY) : null;
|
photoUri = savedInstanceState != null ? (Uri) savedInstanceState.getParcelable(PHOTO_URI_KEY) : null;
|
||||||
hasPhoto = savedInstanceState != null && savedInstanceState.getBoolean(HAS_PHOTO_KEY, false);
|
hasPhoto = savedInstanceState != null && savedInstanceState.getBoolean(HAS_PHOTO_KEY, false);
|
||||||
|
|
||||||
contentProviderUtils = ContentProviderUtils.Factory.get(this);
|
contentProviderUtils = new ContentProviderUtils(this);
|
||||||
handleIntent(getIntent());
|
handleIntent(getIntent());
|
||||||
|
|
||||||
sharedPreferences = PreferencesUtils.getSharedPreferences(this);
|
sharedPreferences = PreferencesUtils.getSharedPreferences(this);
|
||||||
@@ -200,25 +197,46 @@ public class TrackDetailActivity extends AbstractListActivity implements ChooseA
|
|||||||
trackRecordingServiceConnection = new TrackRecordingServiceConnection(this, bindChangedCallback);
|
trackRecordingServiceConnection = new TrackRecordingServiceConnection(this, bindChangedCallback);
|
||||||
trackDataHub = TrackDataHub.newInstance(this);
|
trackDataHub = TrackDataHub.newInstance(this);
|
||||||
|
|
||||||
tabHost = findViewById(R.id.tackdetail_tabhost);
|
FragmentPagerAdapter adapter = new FragmentPagerAdapter(getSupportFragmentManager(), 1) {
|
||||||
tabHost.setup();
|
@Override
|
||||||
|
public int getCount() {
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
|
|
||||||
ViewPager viewPager = findViewById(R.id.pager);
|
@NonNull
|
||||||
TabsAdapter tabsAdapter = new TabsAdapter(this, tabHost, viewPager);
|
@Override
|
||||||
|
public Fragment getItem(int position) {
|
||||||
TabSpec statsTabSpec = tabHost.newTabSpec(StatsFragment.STATS_FRAGMENT_TAG).setIndicator(getString(R.string.track_detail_stats_tab));
|
switch (position) {
|
||||||
tabsAdapter.addTab(statsTabSpec, StatsFragment.class, null);
|
case 0:
|
||||||
|
return new StatsFragment();
|
||||||
TabSpec chartTabSpec = tabHost.newTabSpec(ChartFragment.CHART_FRAGMENT_TAG).setIndicator(getString(R.string.track_detail_chart_tab));
|
case 1:
|
||||||
tabsAdapter.addTab(chartTabSpec, ChartFragment.class, null);
|
return new ChartTimeFragment();
|
||||||
|
case 2:
|
||||||
|
return new ChartDistanceFragment();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public CharSequence getPageTitle(int position) {
|
||||||
|
switch (position) {
|
||||||
|
case 0:
|
||||||
|
return getString(R.string.track_detail_stats_tab);
|
||||||
|
case 1:
|
||||||
|
return getString(R.string.settings_chart_by_time);
|
||||||
|
case 2:
|
||||||
|
return getString(R.string.settings_chart_by_distance);
|
||||||
|
}
|
||||||
|
return "Unknown Tab";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
pager = findViewById(R.id.track_detail_activity_view_pager);
|
||||||
|
pager.setAdapter(adapter);
|
||||||
|
TabLayout tabs = findViewById(R.id.track_detail_activity_tablayout);
|
||||||
|
tabs.setupWithViewPager(pager);
|
||||||
if (savedInstanceState != null) {
|
if (savedInstanceState != null) {
|
||||||
tabHost.setCurrentTabByTag(savedInstanceState.getString(CURRENT_TAB_TAG_KEY));
|
pager.setCurrentItem(savedInstanceState.getInt(CURRENT_TAB_TAG_KEY));
|
||||||
}
|
|
||||||
|
|
||||||
// Set the background after all three tabs are added
|
|
||||||
for (int i = 0; i < tabHost.getTabWidget().getChildCount(); i++) {
|
|
||||||
tabHost.getTabWidget().getChildAt(i).setBackgroundResource(R.drawable.tab_indicator);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
trackController = new TrackController(this, trackRecordingServiceConnection, false, recordListener, stopListener);
|
trackController = new TrackController(this, trackRecordingServiceConnection, false, recordListener, stopListener);
|
||||||
@@ -227,16 +245,31 @@ public class TrackDetailActivity extends AbstractListActivity implements ChooseA
|
|||||||
@Override
|
@Override
|
||||||
public void onAttachedToWindow() {
|
public void onAttachedToWindow() {
|
||||||
setLockscreenPolicy();
|
setLockscreenPolicy();
|
||||||
|
setScreenOnPolicy();
|
||||||
super.onAttachedToWindow();
|
super.onAttachedToWindow();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setLockscreenPolicy() {
|
private void setLockscreenPolicy() {
|
||||||
|
boolean showOnLockScreen = PreferencesUtils.shouldShowStatsOnLockscreen(TrackDetailActivity.this)
|
||||||
|
&& PreferencesUtils.isRecording(this);
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O_MR1) {
|
||||||
setShowWhenLocked(showOnLockScreen);
|
setShowWhenLocked(showOnLockScreen);
|
||||||
|
} else if (showOnLockScreen) {
|
||||||
|
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
|
||||||
} else {
|
} else {
|
||||||
if (showOnLockScreen)
|
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
|
||||||
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
|
}
|
||||||
else getWindow().clearFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
|
}
|
||||||
|
|
||||||
|
private void setScreenOnPolicy() {
|
||||||
|
boolean keepScreenOn = PreferencesUtils.shouldKeepScreenOn(TrackDetailActivity.this)
|
||||||
|
&& PreferencesUtils.isRecording(this);
|
||||||
|
|
||||||
|
if (keepScreenOn) {
|
||||||
|
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||||
|
} else {
|
||||||
|
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -271,14 +304,15 @@ public class TrackDetailActivity extends AbstractListActivity implements ChooseA
|
|||||||
protected void onStop() {
|
protected void onStop() {
|
||||||
super.onStop();
|
super.onStop();
|
||||||
sharedPreferences.unregisterOnSharedPreferenceChangeListener(sharedPreferenceChangeListener);
|
sharedPreferences.unregisterOnSharedPreferenceChangeListener(sharedPreferenceChangeListener);
|
||||||
trackRecordingServiceConnection.unbind();
|
trackRecordingServiceConnection.unbind(this);
|
||||||
trackDataHub.stop();
|
trackDataHub.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onSaveInstanceState(Bundle outState) {
|
protected void onSaveInstanceState(@NonNull Bundle outState) {
|
||||||
super.onSaveInstanceState(outState);
|
super.onSaveInstanceState(outState);
|
||||||
outState.putString(CURRENT_TAB_TAG_KEY, tabHost.getCurrentTabTag());
|
outState.putInt(CURRENT_TAB_TAG_KEY, pager.getCurrentItem());
|
||||||
|
|
||||||
if (photoUri != null) {
|
if (photoUri != null) {
|
||||||
outState.putParcelable(PHOTO_URI_KEY, photoUri);
|
outState.putParcelable(PHOTO_URI_KEY, photoUri);
|
||||||
}
|
}
|
||||||
@@ -316,12 +350,7 @@ public class TrackDetailActivity extends AbstractListActivity implements ChooseA
|
|||||||
insertMarkerMenuItem = menu.findItem(R.id.track_detail_insert_marker);
|
insertMarkerMenuItem = menu.findItem(R.id.track_detail_insert_marker);
|
||||||
insertPhotoMenuItem = menu.findItem(R.id.track_detail_insert_photo);
|
insertPhotoMenuItem = menu.findItem(R.id.track_detail_insert_photo);
|
||||||
insertPhotoMenuItem.setVisible(new Intent(MediaStore.ACTION_IMAGE_CAPTURE).resolveActivity(getPackageManager()) != null);
|
insertPhotoMenuItem.setVisible(new Intent(MediaStore.ACTION_IMAGE_CAPTURE).resolveActivity(getPackageManager()) != null);
|
||||||
|
|
||||||
shareMenuItem = menu.findItem(R.id.track_detail_share);
|
shareMenuItem = menu.findItem(R.id.track_detail_share);
|
||||||
ToolbarUtils.setupShareActionProviderCompat(this, shareMenuItem, new long[]{trackId});
|
|
||||||
|
|
||||||
voiceFrequencyMenuItem = menu.findItem(R.id.track_detail_voice_frequency);
|
|
||||||
splitFrequencyMenuItem = menu.findItem(R.id.track_detail_split_frequency);
|
|
||||||
markerListMenuItem = menu.findItem(R.id.track_detail_markers);
|
markerListMenuItem = menu.findItem(R.id.track_detail_markers);
|
||||||
|
|
||||||
return super.onCreateOptionsMenu(menu);
|
return super.onCreateOptionsMenu(menu);
|
||||||
@@ -343,11 +372,12 @@ public class TrackDetailActivity extends AbstractListActivity implements ChooseA
|
|||||||
.putExtra(MarkerEditActivity.EXTRA_TRACK_ID, trackId);
|
.putExtra(MarkerEditActivity.EXTRA_TRACK_ID, trackId);
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
return true;
|
return true;
|
||||||
|
case R.id.track_detail_share:
|
||||||
|
intent = IntentUtils.newShareFileIntent(this, new long[]{trackId});
|
||||||
|
intent = Intent.createChooser(intent, null);
|
||||||
|
startActivity(intent);
|
||||||
|
return true;
|
||||||
case R.id.track_detail_insert_photo:
|
case R.id.track_detail_insert_photo:
|
||||||
if (!FileUtils.isExternalStorageWriteable() || ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_DENIED) {
|
|
||||||
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, EXTERNAL_STORAGE_PERMISSION_REQUEST_CODE);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
createWaypointWithPicture();
|
createWaypointWithPicture();
|
||||||
return true;
|
return true;
|
||||||
case R.id.track_detail_menu_show_on_map:
|
case R.id.track_detail_menu_show_on_map:
|
||||||
@@ -358,12 +388,6 @@ public class TrackDetailActivity extends AbstractListActivity implements ChooseA
|
|||||||
.putExtra(MarkerListActivity.EXTRA_TRACK_ID, trackId);
|
.putExtra(MarkerListActivity.EXTRA_TRACK_ID, trackId);
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
return true;
|
return true;
|
||||||
case R.id.track_detail_voice_frequency:
|
|
||||||
FrequencyDialogFragment.showDialog(getSupportFragmentManager(), R.string.voice_frequency_key, PreferencesUtils.VOICE_FREQUENCY_DEFAULT, R.string.menu_voice_frequency);
|
|
||||||
return true;
|
|
||||||
case R.id.track_detail_split_frequency:
|
|
||||||
FrequencyDialogFragment.showDialog(getSupportFragmentManager(), R.string.split_frequency_key, PreferencesUtils.SPLIT_FREQUENCY_DEFAULT, R.string.menu_split_frequency);
|
|
||||||
return true;
|
|
||||||
case R.id.track_detail_edit:
|
case R.id.track_detail_edit:
|
||||||
intent = IntentUtils.newIntent(this, TrackEditActivity.class)
|
intent = IntentUtils.newIntent(this, TrackEditActivity.class)
|
||||||
.putExtra(TrackEditActivity.EXTRA_TRACK_ID, trackId);
|
.putExtra(TrackEditActivity.EXTRA_TRACK_ID, trackId);
|
||||||
@@ -417,16 +441,6 @@ public class TrackDetailActivity extends AbstractListActivity implements ChooseA
|
|||||||
return trackDataHub;
|
return trackDataHub;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the track id.
|
|
||||||
*/
|
|
||||||
public long getTrackId() {
|
|
||||||
return trackId;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handles the data in the intent.
|
|
||||||
*/
|
|
||||||
private void handleIntent(Intent intent) {
|
private void handleIntent(Intent intent) {
|
||||||
trackId = intent.getLongExtra(EXTRA_TRACK_ID, -1L);
|
trackId = intent.getLongExtra(EXTRA_TRACK_ID, -1L);
|
||||||
long markerId = intent.getLongExtra(EXTRA_MARKER_ID, -1L);
|
long markerId = intent.getLongExtra(EXTRA_MARKER_ID, -1L);
|
||||||
@@ -465,8 +479,6 @@ public class TrackDetailActivity extends AbstractListActivity implements ChooseA
|
|||||||
insertPhotoMenuItem.setVisible(hasCamera && isRecording() && !isPaused);
|
insertPhotoMenuItem.setVisible(hasCamera && isRecording() && !isPaused);
|
||||||
shareMenuItem.setVisible(!isRecording());
|
shareMenuItem.setVisible(!isRecording());
|
||||||
markerListMenuItem.setShowAsAction(isRecording() ? MenuItem.SHOW_AS_ACTION_NEVER : MenuItem.SHOW_AS_ACTION_IF_ROOM);
|
markerListMenuItem.setShowAsAction(isRecording() ? MenuItem.SHOW_AS_ACTION_NEVER : MenuItem.SHOW_AS_ACTION_IF_ROOM);
|
||||||
voiceFrequencyMenuItem.setVisible(isRecording());
|
|
||||||
splitFrequencyMenuItem.setVisible(isRecording());
|
|
||||||
String title;
|
String title;
|
||||||
if (isRecording()) {
|
if (isRecording()) {
|
||||||
title = getString(isPaused ? R.string.generic_paused : R.string.generic_recording);
|
title = getString(isPaused ? R.string.generic_paused : R.string.generic_recording);
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ import android.widget.Spinner;
|
|||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
import de.dennisguse.opentracks.content.ContentProviderUtils;
|
import de.dennisguse.opentracks.content.ContentProviderUtils;
|
||||||
import de.dennisguse.opentracks.content.Track;
|
import de.dennisguse.opentracks.content.data.Track;
|
||||||
import de.dennisguse.opentracks.fragments.ChooseActivityTypeDialogFragment;
|
import de.dennisguse.opentracks.fragments.ChooseActivityTypeDialogFragment;
|
||||||
import de.dennisguse.opentracks.services.TrackRecordingServiceConnection;
|
import de.dennisguse.opentracks.services.TrackRecordingServiceConnection;
|
||||||
import de.dennisguse.opentracks.util.TrackIconUtils;
|
import de.dennisguse.opentracks.util.TrackIconUtils;
|
||||||
@@ -73,7 +73,7 @@ public class TrackEditActivity extends AbstractActivity implements ChooseActivit
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
contentProviderUtils = ContentProviderUtils.Factory.get(this);
|
contentProviderUtils = new ContentProviderUtils(this);
|
||||||
track = contentProviderUtils.getTrack(trackId);
|
track = contentProviderUtils.getTrack(trackId);
|
||||||
if (track == null) {
|
if (track == null) {
|
||||||
Log.e(TAG, "No track for " + trackId);
|
Log.e(TAG, "No track for " + trackId);
|
||||||
@@ -175,7 +175,7 @@ public class TrackEditActivity extends AbstractActivity implements ChooseActivit
|
|||||||
@Override
|
@Override
|
||||||
protected void onStop() {
|
protected void onStop() {
|
||||||
super.onStop();
|
super.onStop();
|
||||||
trackRecordingServiceConnection.unbind();
|
trackRecordingServiceConnection.unbind(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ import androidx.loader.content.Loader;
|
|||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
import de.dennisguse.opentracks.content.ContentProviderUtils;
|
import de.dennisguse.opentracks.content.ContentProviderUtils;
|
||||||
import de.dennisguse.opentracks.content.TracksColumns;
|
import de.dennisguse.opentracks.content.data.TracksColumns;
|
||||||
import de.dennisguse.opentracks.fragments.ConfirmDeleteDialogFragment;
|
import de.dennisguse.opentracks.fragments.ConfirmDeleteDialogFragment;
|
||||||
import de.dennisguse.opentracks.services.ITrackRecordingService;
|
import de.dennisguse.opentracks.services.ITrackRecordingService;
|
||||||
import de.dennisguse.opentracks.services.TrackRecordingServiceConnection;
|
import de.dennisguse.opentracks.services.TrackRecordingServiceConnection;
|
||||||
@@ -60,8 +60,8 @@ import de.dennisguse.opentracks.util.ActivityUtils;
|
|||||||
import de.dennisguse.opentracks.util.IntentUtils;
|
import de.dennisguse.opentracks.util.IntentUtils;
|
||||||
import de.dennisguse.opentracks.util.ListItemUtils;
|
import de.dennisguse.opentracks.util.ListItemUtils;
|
||||||
import de.dennisguse.opentracks.util.PreferencesUtils;
|
import de.dennisguse.opentracks.util.PreferencesUtils;
|
||||||
|
import de.dennisguse.opentracks.util.ServiceUtils;
|
||||||
import de.dennisguse.opentracks.util.StringUtils;
|
import de.dennisguse.opentracks.util.StringUtils;
|
||||||
import de.dennisguse.opentracks.util.ToolbarUtils;
|
|
||||||
import de.dennisguse.opentracks.util.TrackIconUtils;
|
import de.dennisguse.opentracks.util.TrackIconUtils;
|
||||||
import de.dennisguse.opentracks.util.TrackUtils;
|
import de.dennisguse.opentracks.util.TrackUtils;
|
||||||
|
|
||||||
@@ -115,9 +115,6 @@ public class TrackListActivity extends AbstractListActivity implements ConfirmDe
|
|||||||
public void onPrepare(Menu menu, int[] positions, long[] trackIds, boolean showSelectAll) {
|
public void onPrepare(Menu menu, int[] positions, long[] trackIds, boolean showSelectAll) {
|
||||||
boolean isSingleSelection = trackIds.length == 1;
|
boolean isSingleSelection = trackIds.length == 1;
|
||||||
|
|
||||||
MenuItem shareMenuItem = menu.findItem(R.id.list_context_menu_share);
|
|
||||||
ToolbarUtils.setupShareActionProvider(TrackListActivity.this, shareMenuItem, trackIds);
|
|
||||||
|
|
||||||
menu.findItem(R.id.list_context_menu_edit).setVisible(isSingleSelection);
|
menu.findItem(R.id.list_context_menu_edit).setVisible(isSingleSelection);
|
||||||
menu.findItem(R.id.list_context_menu_select_all).setVisible(showSelectAll);
|
menu.findItem(R.id.list_context_menu_select_all).setVisible(showSelectAll);
|
||||||
}
|
}
|
||||||
@@ -128,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.
|
* Note that sharedPreferenceChangeListener cannot be an anonymous inner class.
|
||||||
@@ -138,22 +135,17 @@ public class TrackListActivity extends AbstractListActivity implements ConfirmDe
|
|||||||
sharedPreferenceChangeListener = new OnSharedPreferenceChangeListener() {
|
sharedPreferenceChangeListener = new OnSharedPreferenceChangeListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onSharedPreferenceChanged(SharedPreferences preferences, String key) {
|
public void onSharedPreferenceChanged(SharedPreferences preferences, String key) {
|
||||||
if (key == null || key.equals(PreferencesUtils.getKey(TrackListActivity.this, R.string.stats_units_key))) {
|
if (PreferencesUtils.isKey(TrackListActivity.this, R.string.stats_units_key, key)) {
|
||||||
metricUnits = PreferencesUtils.isMetricUnits(TrackListActivity.this);
|
metricUnits = PreferencesUtils.isMetricUnits(TrackListActivity.this);
|
||||||
}
|
}
|
||||||
if (key == null || key.equals(
|
if (PreferencesUtils.isKey(TrackListActivity.this, R.string.recording_track_id_key, key)) {
|
||||||
PreferencesUtils.getKey(TrackListActivity.this, R.string.recording_track_id_key))) {
|
recordingTrackId = PreferencesUtils.getRecordingTrackId(TrackListActivity.this);
|
||||||
recordingTrackId = PreferencesUtils.getLong(
|
|
||||||
TrackListActivity.this, R.string.recording_track_id_key);
|
|
||||||
if (key != null && PreferencesUtils.isRecording(recordingTrackId)) {
|
if (key != null && PreferencesUtils.isRecording(recordingTrackId)) {
|
||||||
trackRecordingServiceConnection.startAndBind();
|
trackRecordingServiceConnection.startAndBind(TrackListActivity.this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (key == null || key.equals(PreferencesUtils.getKey(
|
if (PreferencesUtils.isKey(TrackListActivity.this, R.string.recording_track_paused_key, key)) {
|
||||||
TrackListActivity.this, R.string.recording_track_paused_key))) {
|
recordingTrackPaused = PreferencesUtils.isRecordingTrackPaused(TrackListActivity.this);
|
||||||
recordingTrackPaused = PreferencesUtils.getBoolean(TrackListActivity.this,
|
|
||||||
R.string.recording_track_paused_key,
|
|
||||||
PreferencesUtils.RECORDING_TRACK_PAUSED_DEFAULT);
|
|
||||||
}
|
}
|
||||||
if (key != null) {
|
if (key != null) {
|
||||||
runOnUiThread(new Runnable() {
|
runOnUiThread(new Runnable() {
|
||||||
@@ -172,7 +164,7 @@ public class TrackListActivity extends AbstractListActivity implements ConfirmDe
|
|||||||
// Menu items
|
// Menu items
|
||||||
private MenuItem searchMenuItem;
|
private MenuItem searchMenuItem;
|
||||||
private MenuItem startGpsMenuItem;
|
private MenuItem startGpsMenuItem;
|
||||||
private MenuItem deleteAllMenuItem;
|
// private MenuItem deleteAllMenuItem;
|
||||||
|
|
||||||
private final OnClickListener stopListener = new OnClickListener() {
|
private final OnClickListener stopListener = new OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
@@ -229,12 +221,11 @@ public class TrackListActivity extends AbstractListActivity implements ConfirmDe
|
|||||||
|
|
||||||
private final OnClickListener recordListener = new OnClickListener() {
|
private final OnClickListener recordListener = new OnClickListener() {
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
if (recordingTrackId == PreferencesUtils.RECORDING_TRACK_ID_DEFAULT) {
|
if (!PreferencesUtils.isRecording(recordingTrackId)) {
|
||||||
// Not recording -> Recording
|
// Not recording -> Recording
|
||||||
updateMenuItems(false, true);
|
updateMenuItems(false, true);
|
||||||
startRecording();
|
startRecording();
|
||||||
} else {
|
} else if (recordingTrackPaused) {
|
||||||
if (recordingTrackPaused) {
|
|
||||||
// Paused -> Resume
|
// Paused -> Resume
|
||||||
updateMenuItems(false, true);
|
updateMenuItems(false, true);
|
||||||
trackRecordingServiceConnection.resumeTrack();
|
trackRecordingServiceConnection.resumeTrack();
|
||||||
@@ -245,7 +236,6 @@ public class TrackListActivity extends AbstractListActivity implements ConfirmDe
|
|||||||
trackRecordingServiceConnection.pauseTrack();
|
trackRecordingServiceConnection.pauseTrack();
|
||||||
trackController.update(true, true);
|
trackController.update(true, true);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -253,7 +243,9 @@ public class TrackListActivity extends AbstractListActivity implements ConfirmDe
|
|||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
contentProviderUtils = ContentProviderUtils.Factory.get(this);
|
recordingTrackPaused = PreferencesUtils.isRecordingTrackPausedDefault(this);
|
||||||
|
|
||||||
|
contentProviderUtils = new ContentProviderUtils(this);
|
||||||
sharedPreferences = PreferencesUtils.getSharedPreferences(this);
|
sharedPreferences = PreferencesUtils.getSharedPreferences(this);
|
||||||
|
|
||||||
trackRecordingServiceConnection = new TrackRecordingServiceConnection(this, bindChangedCallback);
|
trackRecordingServiceConnection = new TrackRecordingServiceConnection(this, bindChangedCallback);
|
||||||
@@ -352,7 +344,7 @@ public class TrackListActivity extends AbstractListActivity implements ConfirmDe
|
|||||||
super.onStop();
|
super.onStop();
|
||||||
|
|
||||||
sharedPreferences.unregisterOnSharedPreferenceChangeListener(sharedPreferenceChangeListener);
|
sharedPreferences.unregisterOnSharedPreferenceChangeListener(sharedPreferenceChangeListener);
|
||||||
trackRecordingServiceConnection.unbind();
|
trackRecordingServiceConnection.unbind(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -379,14 +371,13 @@ public class TrackListActivity extends AbstractListActivity implements ConfirmDe
|
|||||||
ActivityUtils.configureSearchWidget(this, searchMenuItem, trackController);
|
ActivityUtils.configureSearchWidget(this, searchMenuItem, trackController);
|
||||||
|
|
||||||
startGpsMenuItem = menu.findItem(R.id.track_list_start_gps);
|
startGpsMenuItem = menu.findItem(R.id.track_list_start_gps);
|
||||||
deleteAllMenuItem = menu.findItem(R.id.track_list_delete_all);
|
|
||||||
|
|
||||||
return super.onCreateOptionsMenu(menu);
|
return super.onCreateOptionsMenu(menu);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onPrepareOptionsMenu(Menu menu) {
|
public boolean onPrepareOptionsMenu(Menu menu) {
|
||||||
boolean isGpsStarted = TrackRecordingServiceConnection.isRecordingServiceRunning(this);
|
boolean isGpsStarted = ServiceUtils.isTrackRecordingServiceRunning(this);
|
||||||
boolean isRecording = PreferencesUtils.isRecording(recordingTrackId);
|
boolean isRecording = PreferencesUtils.isRecording(recordingTrackId);
|
||||||
updateMenuItems(isGpsStarted, isRecording);
|
updateMenuItems(isGpsStarted, isRecording);
|
||||||
|
|
||||||
@@ -406,7 +397,7 @@ public class TrackListActivity extends AbstractListActivity implements ConfirmDe
|
|||||||
intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
|
intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
} else {
|
} else {
|
||||||
startGps = !TrackRecordingServiceConnection.isRecordingServiceRunning(this);
|
startGps = !ServiceUtils.isTrackRecordingServiceRunning(this);
|
||||||
|
|
||||||
// Show toast
|
// Show toast
|
||||||
Toast toast = Toast.makeText(this, startGps ? R.string.gps_starting : R.string.gps_stopping, Toast.LENGTH_SHORT);
|
Toast toast = Toast.makeText(this, startGps ? R.string.gps_starting : R.string.gps_stopping, Toast.LENGTH_SHORT);
|
||||||
@@ -415,14 +406,14 @@ public class TrackListActivity extends AbstractListActivity implements ConfirmDe
|
|||||||
|
|
||||||
// Invoke trackRecordingService
|
// Invoke trackRecordingService
|
||||||
if (startGps) {
|
if (startGps) {
|
||||||
trackRecordingServiceConnection.startAndBind();
|
trackRecordingServiceConnection.startAndBind(this);
|
||||||
bindChangedCallback.run();
|
bindChangedCallback.run();
|
||||||
} else {
|
} else {
|
||||||
ITrackRecordingService trackRecordingService = trackRecordingServiceConnection.getServiceIfBound();
|
ITrackRecordingService trackRecordingService = trackRecordingServiceConnection.getServiceIfBound();
|
||||||
if (trackRecordingService != null) {
|
if (trackRecordingService != null) {
|
||||||
trackRecordingService.stopGps();
|
trackRecordingService.stopGps();
|
||||||
}
|
}
|
||||||
trackRecordingServiceConnection.unbindAndStop();
|
trackRecordingServiceConnection.unbindAndStop(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update menu after starting or stopping gps
|
// Update menu after starting or stopping gps
|
||||||
@@ -433,9 +424,6 @@ public class TrackListActivity extends AbstractListActivity implements ConfirmDe
|
|||||||
intent = IntentUtils.newIntent(this, MarkerListActivity.class);
|
intent = IntentUtils.newIntent(this, MarkerListActivity.class);
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
return true;
|
return true;
|
||||||
case R.id.track_list_delete_all:
|
|
||||||
deleteTracks(new long[]{-1L});
|
|
||||||
return true;
|
|
||||||
case R.id.track_list_settings:
|
case R.id.track_list_settings:
|
||||||
intent = IntentUtils.newIntent(this, SettingsActivity.class);
|
intent = IntentUtils.newIntent(this, SettingsActivity.class);
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
@@ -503,9 +491,6 @@ public class TrackListActivity extends AbstractListActivity implements ConfirmDe
|
|||||||
startGpsMenuItem.setIcon(isGpsStarted ? R.drawable.ic_gps_fixed_24dp : R.drawable.ic_gps_off_24dp);
|
startGpsMenuItem.setIcon(isGpsStarted ? R.drawable.ic_gps_fixed_24dp : R.drawable.ic_gps_off_24dp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (deleteAllMenuItem != null) {
|
|
||||||
deleteAllMenuItem.setVisible(hasTrack && !isRecording);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -513,7 +498,7 @@ public class TrackListActivity extends AbstractListActivity implements ConfirmDe
|
|||||||
*/
|
*/
|
||||||
private void startRecording() {
|
private void startRecording() {
|
||||||
startNewRecording = true;
|
startNewRecording = true;
|
||||||
trackRecordingServiceConnection.startAndBind();
|
trackRecordingServiceConnection.startAndBind(this);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If the binding has happened, then invoke the callback to start a new recording.
|
* If the binding has happened, then invoke the callback to start a new recording.
|
||||||
@@ -531,12 +516,18 @@ public class TrackListActivity extends AbstractListActivity implements ConfirmDe
|
|||||||
* @return true if handled.
|
* @return true if handled.
|
||||||
*/
|
*/
|
||||||
private boolean handleContextItem(int itemId, long[] trackIds) {
|
private boolean handleContextItem(int itemId, long[] trackIds) {
|
||||||
|
Intent intent;
|
||||||
switch (itemId) {
|
switch (itemId) {
|
||||||
case R.id.list_context_menu_show_on_map:
|
case R.id.list_context_menu_show_on_map:
|
||||||
IntentUtils.showTrackOnMap(this, trackIds);
|
IntentUtils.showTrackOnMap(this, trackIds);
|
||||||
return true;
|
return true;
|
||||||
|
case R.id.list_context_menu_share:
|
||||||
|
intent = IntentUtils.newShareFileIntent(this, trackIds);
|
||||||
|
intent = Intent.createChooser(intent, null);
|
||||||
|
startActivity(intent);
|
||||||
|
return true;
|
||||||
case R.id.list_context_menu_edit:
|
case R.id.list_context_menu_edit:
|
||||||
Intent intent = IntentUtils.newIntent(this, TrackEditActivity.class)
|
intent = IntentUtils.newIntent(this, TrackEditActivity.class)
|
||||||
.putExtra(TrackEditActivity.EXTRA_TRACK_ID, trackIds[0]);
|
.putExtra(TrackEditActivity.EXTRA_TRACK_ID, trackIds[0]);
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
* the License.
|
* the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package de.dennisguse.opentracks;
|
package de.dennisguse.opentracks.chart;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
@@ -23,8 +23,6 @@ import android.graphics.Paint.Align;
|
|||||||
import android.graphics.Paint.Style;
|
import android.graphics.Paint.Style;
|
||||||
import android.graphics.Path;
|
import android.graphics.Path;
|
||||||
|
|
||||||
import androidx.annotation.VisibleForTesting;
|
|
||||||
|
|
||||||
import java.text.NumberFormat;
|
import java.text.NumberFormat;
|
||||||
|
|
||||||
import de.dennisguse.opentracks.stats.ExtremityMonitor;
|
import de.dennisguse.opentracks.stats.ExtremityMonitor;
|
||||||
@@ -203,7 +201,6 @@ class ChartValueSeries {
|
|||||||
/**
|
/**
|
||||||
* Gets the interval value.
|
* Gets the interval value.
|
||||||
*/
|
*/
|
||||||
@VisibleForTesting
|
|
||||||
int getInterval() {
|
int getInterval() {
|
||||||
return interval;
|
return interval;
|
||||||
}
|
}
|
||||||
@@ -218,7 +215,6 @@ class ChartValueSeries {
|
|||||||
/**
|
/**
|
||||||
* Gets the max marker value.
|
* Gets the max marker value.
|
||||||
*/
|
*/
|
||||||
@VisibleForTesting
|
|
||||||
int getMaxMarkerValue() {
|
int getMaxMarkerValue() {
|
||||||
return maxMarkerValue;
|
return maxMarkerValue;
|
||||||
}
|
}
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
* the License.
|
* the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package de.dennisguse.opentracks;
|
package de.dennisguse.opentracks.chart;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
@@ -27,33 +27,40 @@ import android.graphics.Paint.Style;
|
|||||||
import android.graphics.Path;
|
import android.graphics.Path;
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
|
import android.view.GestureDetector;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
import android.view.VelocityTracker;
|
import android.view.ScaleGestureDetector;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewConfiguration;
|
|
||||||
import android.widget.Scroller;
|
import android.widget.Scroller;
|
||||||
|
|
||||||
|
import androidx.core.view.GestureDetectorCompat;
|
||||||
|
|
||||||
import java.text.NumberFormat;
|
import java.text.NumberFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import de.dennisguse.opentracks.content.Waypoint;
|
import de.dennisguse.opentracks.MarkerDetailActivity;
|
||||||
|
import de.dennisguse.opentracks.R;
|
||||||
|
import de.dennisguse.opentracks.content.data.Waypoint;
|
||||||
import de.dennisguse.opentracks.stats.ExtremityMonitor;
|
import de.dennisguse.opentracks.stats.ExtremityMonitor;
|
||||||
import de.dennisguse.opentracks.util.IntentUtils;
|
import de.dennisguse.opentracks.util.IntentUtils;
|
||||||
|
import de.dennisguse.opentracks.util.MarkerUtils;
|
||||||
import de.dennisguse.opentracks.util.StringUtils;
|
import de.dennisguse.opentracks.util.StringUtils;
|
||||||
import de.dennisguse.opentracks.util.UnitConversions;
|
import de.dennisguse.opentracks.util.UnitConversions;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Visualization of the chart.
|
* Visualization of the chart.
|
||||||
|
* Provides support for zooming (via pinch), scrolling, flinging, and selecting shown markers (single touch).
|
||||||
*
|
*
|
||||||
* @author Sandor Dornbush
|
* @author Sandor Dornbush
|
||||||
* @author Leif Hendrik Wilden
|
* @author Leif Hendrik Wilden
|
||||||
*/
|
*/
|
||||||
public class ChartView extends View {
|
public class ChartView extends View {
|
||||||
|
|
||||||
public static final float MEDIUM_TEXT_SIZE = 18f;
|
static final float MEDIUM_TEXT_SIZE = 18f;
|
||||||
public static final float SMALL_TEXT_SIZE = 12f;
|
static final float SMALL_TEXT_SIZE = 12f;
|
||||||
|
|
||||||
public static final int Y_AXIS_INTERVALS = 5;
|
static final int Y_AXIS_INTERVALS = 5;
|
||||||
|
|
||||||
public static final int NUM_SERIES = 6;
|
public static final int NUM_SERIES = 6;
|
||||||
public static final int ELEVATION_SERIES = 0;
|
public static final int ELEVATION_SERIES = 0;
|
||||||
@@ -74,25 +81,28 @@ public class ChartView extends View {
|
|||||||
private static final int SPACER = 4;
|
private static final int SPACER = 4;
|
||||||
private static final int Y_AXIS_OFFSET = 16;
|
private static final int Y_AXIS_OFFSET = 16;
|
||||||
|
|
||||||
|
//TODO Determine from actual size of the used drawable
|
||||||
|
private static final float WAYPOINT_X_ANCHOR = 13f / 48f;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
X_FRACTION_FORMAT.setMaximumFractionDigits(1);
|
X_FRACTION_FORMAT.setMaximumFractionDigits(1);
|
||||||
X_FRACTION_FORMAT.setMinimumFractionDigits(1);
|
X_FRACTION_FORMAT.setMinimumFractionDigits(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
private final ChartValueSeries[] series = new ChartValueSeries[NUM_SERIES];
|
private final ChartValueSeries[] series = new ChartValueSeries[NUM_SERIES];
|
||||||
private final ArrayList<double[]> chartData = new ArrayList<>();
|
private final List<double[]> chartData = new ArrayList<>();
|
||||||
private final ArrayList<Waypoint> waypoints = new ArrayList<>();
|
private final List<Waypoint> waypoints = new ArrayList<>();
|
||||||
private final ExtremityMonitor xExtremityMonitor = new ExtremityMonitor();
|
private final ExtremityMonitor xExtremityMonitor = new ExtremityMonitor();
|
||||||
private final Paint axisPaint;
|
private final Paint axisPaint;
|
||||||
private final Paint xAxisMarkerPaint;
|
private final Paint xAxisMarkerPaint;
|
||||||
private final Paint gridPaint;
|
private final Paint gridPaint;
|
||||||
|
private final Paint markerPaint;
|
||||||
private final Drawable pointer;
|
private final Drawable pointer;
|
||||||
|
private final Drawable waypointMarker;
|
||||||
private final int markerWidth;
|
private final int markerWidth;
|
||||||
private final int markerHeight;
|
private final int markerHeight;
|
||||||
private final Scroller scroller;
|
private final Scroller scroller;
|
||||||
private double maxX = 1.0;
|
private double maxX = 1.0;
|
||||||
private VelocityTracker velocityTracker = null;
|
|
||||||
private float lastMotionEventX = -1;
|
|
||||||
private int zoomLevel = 1;
|
private int zoomLevel = 1;
|
||||||
|
|
||||||
private int leftBorder = BORDER;
|
private int leftBorder = BORDER;
|
||||||
@@ -107,18 +117,84 @@ public class ChartView extends View {
|
|||||||
private int effectiveWidth = 0;
|
private int effectiveWidth = 0;
|
||||||
private int effectiveHeight = 0;
|
private int effectiveHeight = 0;
|
||||||
|
|
||||||
private boolean chartByDistance = true;
|
private boolean chartByDistance;
|
||||||
private boolean metricUnits = true;
|
private boolean metricUnits = true;
|
||||||
private boolean reportSpeed = true;
|
private boolean reportSpeed = true;
|
||||||
private boolean showPointer = false;
|
private boolean showPointer = false;
|
||||||
|
|
||||||
/**
|
private GestureDetectorCompat detectorScrollFlingTab = new GestureDetectorCompat(getContext(), new GestureDetector.SimpleOnGestureListener() {
|
||||||
* Constructor.
|
|
||||||
*
|
@Override
|
||||||
* @param context the context
|
public boolean onDown(MotionEvent e) {
|
||||||
*/
|
if (!scroller.isFinished()) {
|
||||||
public ChartView(Context context) {
|
scroller.abortAnimation();
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
|
||||||
|
if (Math.abs(distanceX) > 0) {
|
||||||
|
int availableToScroll = effectiveWidth * (zoomLevel - 1) - getScrollX();
|
||||||
|
if (availableToScroll > 0) {
|
||||||
|
scrollBy(Math.min(availableToScroll, (int) distanceX));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
|
||||||
|
fling((int) -velocityX);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onSingleTapConfirmed(MotionEvent event) {
|
||||||
|
// Check if the y event is within markerHeight of the marker center
|
||||||
|
if (Math.abs(event.getY() - topBorder - spacer - markerHeight / 2f) < markerHeight) {
|
||||||
|
int minDistance = Integer.MAX_VALUE;
|
||||||
|
Waypoint nearestWaypoint = null;
|
||||||
|
synchronized (waypoints) {
|
||||||
|
for (Waypoint waypoint : waypoints) {
|
||||||
|
int distance = Math.abs(getX(getWaypointXValue(waypoint)) - (int) event.getX() - getScrollX());
|
||||||
|
if (distance < minDistance) {
|
||||||
|
minDistance = distance;
|
||||||
|
nearestWaypoint = waypoint;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (nearestWaypoint != null && minDistance < markerWidth) {
|
||||||
|
Intent intent = IntentUtils.newIntent(getContext(), MarkerDetailActivity.class)
|
||||||
|
.putExtra(MarkerDetailActivity.EXTRA_MARKER_ID, nearestWaypoint.getId());
|
||||||
|
getContext().startActivity(intent);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
private ScaleGestureDetector detectorZoom = new ScaleGestureDetector(getContext(), new ScaleGestureDetector.SimpleOnScaleGestureListener() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onScale(ScaleGestureDetector detector) {
|
||||||
|
float scaleFactor = detector.getScaleFactor();
|
||||||
|
if (scaleFactor >= 1.1f) {
|
||||||
|
zoomIn();
|
||||||
|
return true;
|
||||||
|
} else if (scaleFactor <= 0.9) {
|
||||||
|
zoomOut();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
public ChartView(Context context, boolean chartByDistance) {
|
||||||
super(context);
|
super(context);
|
||||||
|
this.chartByDistance = chartByDistance;
|
||||||
|
|
||||||
series[ELEVATION_SERIES] = new ChartValueSeries(context,
|
series[ELEVATION_SERIES] = new ChartValueSeries(context,
|
||||||
Integer.MIN_VALUE,
|
Integer.MIN_VALUE,
|
||||||
@@ -186,7 +262,7 @@ public class ChartView extends View {
|
|||||||
gridPaint.setAntiAlias(false);
|
gridPaint.setAntiAlias(false);
|
||||||
gridPaint.setPathEffect(new DashPathEffect(new float[]{3, 2}, 0));
|
gridPaint.setPathEffect(new DashPathEffect(new float[]{3, 2}, 0));
|
||||||
|
|
||||||
Paint markerPaint = new Paint();
|
markerPaint = new Paint();
|
||||||
markerPaint.setStyle(Style.STROKE);
|
markerPaint.setStyle(Style.STROKE);
|
||||||
markerPaint.setColor(context.getResources().getColor(android.R.color.darker_gray));
|
markerPaint.setColor(context.getResources().getColor(android.R.color.darker_gray));
|
||||||
markerPaint.setAntiAlias(false);
|
markerPaint.setAntiAlias(false);
|
||||||
@@ -194,12 +270,9 @@ public class ChartView extends View {
|
|||||||
pointer = context.getResources().getDrawable(R.drawable.ic_logo_color_24dp);
|
pointer = context.getResources().getDrawable(R.drawable.ic_logo_color_24dp);
|
||||||
pointer.setBounds(0, 0, pointer.getIntrinsicWidth(), pointer.getIntrinsicHeight());
|
pointer.setBounds(0, 0, pointer.getIntrinsicWidth(), pointer.getIntrinsicHeight());
|
||||||
|
|
||||||
Drawable statisticsMarker = getResources().getDrawable(R.drawable.ic_marker_yellow_pushpin);
|
waypointMarker = MarkerUtils.getDefaultPhoto(context);
|
||||||
markerWidth = statisticsMarker.getIntrinsicWidth();
|
markerWidth = waypointMarker.getIntrinsicWidth();
|
||||||
markerHeight = statisticsMarker.getIntrinsicHeight();
|
markerHeight = waypointMarker.getIntrinsicHeight();
|
||||||
statisticsMarker.setBounds(0, 0, markerWidth, markerHeight);
|
|
||||||
|
|
||||||
Drawable waypointMarker = getResources().getDrawable(R.drawable.ic_marker_blue_pushpin);
|
|
||||||
waypointMarker.setBounds(0, 0, markerWidth, markerHeight);
|
waypointMarker.setBounds(0, 0, markerWidth, markerHeight);
|
||||||
|
|
||||||
scroller = new Scroller(context);
|
scroller = new Scroller(context);
|
||||||
@@ -222,16 +295,6 @@ public class ChartView extends View {
|
|||||||
series[index].setEnabled(enabled);
|
series[index].setEnabled(enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets chart by distance.
|
|
||||||
* It is expected that after changing this value, data will be reloaded.
|
|
||||||
*
|
|
||||||
* @param value true for by distance, false for by time
|
|
||||||
*/
|
|
||||||
public void setChartByDistance(boolean value) {
|
|
||||||
chartByDistance = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets metric units.
|
* Sets metric units.
|
||||||
*
|
*
|
||||||
@@ -264,11 +327,10 @@ public class ChartView extends View {
|
|||||||
*
|
*
|
||||||
* @param dataPoints an array of data points to be added
|
* @param dataPoints an array of data points to be added
|
||||||
*/
|
*/
|
||||||
public void addDataPoints(ArrayList<double[]> dataPoints) {
|
public void addDataPoints(List<double[]> dataPoints) {
|
||||||
synchronized (chartData) {
|
synchronized (chartData) {
|
||||||
chartData.addAll(dataPoints);
|
chartData.addAll(dataPoints);
|
||||||
for (int i = 0; i < dataPoints.size(); i++) {
|
for (double[] dataPoint : dataPoints) {
|
||||||
double[] dataPoint = dataPoints.get(i);
|
|
||||||
xExtremityMonitor.update(dataPoint[0]);
|
xExtremityMonitor.update(dataPoint[0]);
|
||||||
for (int j = 0; j < series.length; j++) {
|
for (int j = 0; j < series.length; j++) {
|
||||||
if (!Double.isNaN(dataPoint[j + 1])) {
|
if (!Double.isNaN(dataPoint[j + 1])) {
|
||||||
@@ -410,79 +472,14 @@ public class ChartView extends View {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onTouchEvent(MotionEvent event) {
|
public boolean onTouchEvent(MotionEvent event) {
|
||||||
if (velocityTracker == null) {
|
boolean isZoom = detectorZoom.onTouchEvent(event);
|
||||||
velocityTracker = VelocityTracker.obtain();
|
boolean isScrollTab = detectorScrollFlingTab.onTouchEvent(event);
|
||||||
}
|
return isZoom || isScrollTab;
|
||||||
velocityTracker.addMovement(event);
|
|
||||||
float x = event.getX();
|
|
||||||
switch (event.getAction()) {
|
|
||||||
case MotionEvent.ACTION_DOWN:
|
|
||||||
// Stop the fling
|
|
||||||
if (!scroller.isFinished()) {
|
|
||||||
scroller.abortAnimation();
|
|
||||||
}
|
|
||||||
lastMotionEventX = x;
|
|
||||||
break;
|
|
||||||
case MotionEvent.ACTION_MOVE:
|
|
||||||
if (lastMotionEventX == -1) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
// Scroll to follow the motion event
|
|
||||||
int deltaX = (int) (lastMotionEventX - x);
|
|
||||||
lastMotionEventX = x;
|
|
||||||
if (deltaX < 0) {
|
|
||||||
if (getScrollX() > 0) {
|
|
||||||
scrollBy(deltaX);
|
|
||||||
}
|
|
||||||
} else if (deltaX > 0) {
|
|
||||||
int availableToScroll = effectiveWidth * (zoomLevel - 1) - getScrollX();
|
|
||||||
if (availableToScroll > 0) {
|
|
||||||
scrollBy(Math.min(availableToScroll, deltaX));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case MotionEvent.ACTION_UP:
|
|
||||||
// Check if the y event is within markerHeight of the marker center
|
|
||||||
if (Math.abs(event.getY() - topBorder - spacer - markerHeight / 2) < markerHeight) {
|
|
||||||
int minDistance = Integer.MAX_VALUE;
|
|
||||||
Waypoint nearestWaypoint = null;
|
|
||||||
synchronized (waypoints) {
|
|
||||||
for (int i = 0; i < waypoints.size(); i++) {
|
|
||||||
Waypoint waypoint = waypoints.get(i);
|
|
||||||
int distance = Math.abs(getX(getWaypointXValue(waypoint)) - (int) event.getX() - getScrollX());
|
|
||||||
if (distance < minDistance) {
|
|
||||||
minDistance = distance;
|
|
||||||
nearestWaypoint = waypoint;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (nearestWaypoint != null && minDistance < markerWidth) {
|
|
||||||
Intent intent = IntentUtils.newIntent(getContext(), MarkerDetailActivity.class)
|
|
||||||
.putExtra(MarkerDetailActivity.EXTRA_MARKER_ID, nearestWaypoint.getId());
|
|
||||||
getContext().startActivity(intent);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
VelocityTracker myVelocityTracker = velocityTracker;
|
|
||||||
myVelocityTracker.computeCurrentVelocity(1000);
|
|
||||||
int initialVelocity = (int) myVelocityTracker.getXVelocity();
|
|
||||||
if (Math.abs(initialVelocity) > ViewConfiguration.getMinimumFlingVelocity()) {
|
|
||||||
fling(-initialVelocity);
|
|
||||||
}
|
|
||||||
if (velocityTracker != null) {
|
|
||||||
velocityTracker.recycle();
|
|
||||||
velocityTracker = null;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||||
updateEffectiveDimensionsIfChanged(
|
updateEffectiveDimensionsIfChanged(View.MeasureSpec.getSize(widthMeasureSpec), View.MeasureSpec.getSize(heightMeasureSpec));
|
||||||
View.MeasureSpec.getSize(widthMeasureSpec), View.MeasureSpec.getSize(heightMeasureSpec));
|
|
||||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -498,6 +495,7 @@ public class ChartView extends View {
|
|||||||
|
|
||||||
clipToGraphArea(canvas);
|
clipToGraphArea(canvas);
|
||||||
drawDataSeries(canvas);
|
drawDataSeries(canvas);
|
||||||
|
drawWaypoints(canvas);
|
||||||
drawGrid(canvas);
|
drawGrid(canvas);
|
||||||
|
|
||||||
canvas.restore();
|
canvas.restore();
|
||||||
@@ -538,6 +536,33 @@ public class ChartView extends View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Draws the waypoints.
|
||||||
|
*
|
||||||
|
* @param canvas the canvas
|
||||||
|
*/
|
||||||
|
private void drawWaypoints(Canvas canvas) {
|
||||||
|
synchronized (waypoints) {
|
||||||
|
for (int i = 0; i < waypoints.size(); i++) {
|
||||||
|
final Waypoint waypoint = waypoints.get(i);
|
||||||
|
if (waypoint.getLocation() == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
double xValue = getWaypointXValue(waypoint);
|
||||||
|
if (xValue > maxX) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
canvas.save();
|
||||||
|
float x = getX(getWaypointXValue(waypoint));
|
||||||
|
canvas.drawLine(x, topBorder + spacer + markerHeight / 2, x, topBorder + effectiveHeight, markerPaint);
|
||||||
|
canvas.translate(x - (markerWidth * WAYPOINT_X_ANCHOR), topBorder + spacer);
|
||||||
|
|
||||||
|
waypointMarker.draw(canvas);
|
||||||
|
canvas.restore();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Draws the grid.
|
* Draws the grid.
|
||||||
*
|
*
|
||||||
@@ -545,9 +570,9 @@ public class ChartView extends View {
|
|||||||
*/
|
*/
|
||||||
private void drawGrid(Canvas canvas) {
|
private void drawGrid(Canvas canvas) {
|
||||||
// X axis grid
|
// X axis grid
|
||||||
ArrayList<Double> xAxisMarkerPositions = getXAxisMarkerPositions(getXAxisInterval());
|
List<Double> xAxisMarkerPositions = getXAxisMarkerPositions(getXAxisInterval());
|
||||||
for (int i = 0; i < xAxisMarkerPositions.size(); i++) {
|
for (double position : xAxisMarkerPositions) {
|
||||||
int x = getX(xAxisMarkerPositions.get(i));
|
int x = getX(position);
|
||||||
canvas.drawLine(x, topBorder, x, topBorder + effectiveHeight, gridPaint);
|
canvas.drawLine(x, topBorder, x, topBorder + effectiveHeight, gridPaint);
|
||||||
}
|
}
|
||||||
// Y axis grid
|
// Y axis grid
|
||||||
@@ -619,10 +644,10 @@ public class ChartView extends View {
|
|||||||
canvas.drawText(label, x + effectiveWidth + spacer, y + yOffset, axisPaint);
|
canvas.drawText(label, x + effectiveWidth + spacer, y + yOffset, axisPaint);
|
||||||
|
|
||||||
double interval = getXAxisInterval();
|
double interval = getXAxisInterval();
|
||||||
ArrayList<Double> markerPositions = getXAxisMarkerPositions(interval);
|
|
||||||
NumberFormat numberFormat = interval < 1 ? X_FRACTION_FORMAT : X_NUMBER_FORMAT;
|
NumberFormat numberFormat = interval < 1 ? X_FRACTION_FORMAT : X_NUMBER_FORMAT;
|
||||||
for (int i = 0; i < markerPositions.size(); i++) {
|
|
||||||
drawXAxisMarker(canvas, markerPositions.get(i), numberFormat, spacer + yOffset);
|
for (double markerPosition : getXAxisMarkerPositions(interval)) {
|
||||||
|
drawXAxisMarker(canvas, markerPosition, numberFormat, spacer + yOffset);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -632,8 +657,7 @@ public class ChartView extends View {
|
|||||||
private String getXAxisLabel() {
|
private String getXAxisLabel() {
|
||||||
Context context = getContext();
|
Context context = getContext();
|
||||||
if (chartByDistance) {
|
if (chartByDistance) {
|
||||||
return metricUnits ? context.getString(R.string.unit_kilometer)
|
return metricUnits ? context.getString(R.string.unit_kilometer) : context.getString(R.string.unit_mile);
|
||||||
: context.getString(R.string.unit_mile);
|
|
||||||
} else {
|
} else {
|
||||||
return context.getString(R.string.description_time);
|
return context.getString(R.string.description_time);
|
||||||
}
|
}
|
||||||
@@ -673,8 +697,8 @@ public class ChartView extends View {
|
|||||||
/**
|
/**
|
||||||
* Gets the x axis marker positions.
|
* Gets the x axis marker positions.
|
||||||
*/
|
*/
|
||||||
private ArrayList<Double> getXAxisMarkerPositions(double interval) {
|
private List<Double> getXAxisMarkerPositions(double interval) {
|
||||||
ArrayList<Double> markers = new ArrayList<>();
|
List<Double> markers = new ArrayList<>();
|
||||||
markers.add(0d);
|
markers.add(0d);
|
||||||
for (int i = 1; i * interval < maxX; i++) {
|
for (int i = 1; i * interval < maxX; i++) {
|
||||||
markers.add(i * interval);
|
markers.add(i * interval);
|
||||||
@@ -733,8 +757,7 @@ public class ChartView extends View {
|
|||||||
* @param yValue the y value
|
* @param yValue the y value
|
||||||
* @return the marker width.
|
* @return the marker width.
|
||||||
*/
|
*/
|
||||||
private float drawYAxisMarker(
|
private float drawYAxisMarker(ChartValueSeries chartValueSeries, Canvas canvas, int xPosition, int yValue) {
|
||||||
ChartValueSeries chartValueSeries, Canvas canvas, int xPosition, int yValue) {
|
|
||||||
String marker = chartValueSeries.formatMarker(yValue);
|
String marker = chartValueSeries.formatMarker(yValue);
|
||||||
Paint paint = chartValueSeries.getMarkerPaint();
|
Paint paint = chartValueSeries.getMarkerPaint();
|
||||||
Rect rect = getRect(paint, marker);
|
Rect rect = getRect(paint, marker);
|
||||||
@@ -785,8 +808,7 @@ public class ChartView extends View {
|
|||||||
private void drawPaths() {
|
private void drawPaths() {
|
||||||
boolean[] hasMoved = new boolean[series.length];
|
boolean[] hasMoved = new boolean[series.length];
|
||||||
|
|
||||||
for (int i = 0; i < chartData.size(); i++) {
|
for (double[] dataPoint : chartData) {
|
||||||
double[] dataPoint = chartData.get(i);
|
|
||||||
for (int j = 0; j < series.length; j++) {
|
for (int j = 0; j < series.length; j++) {
|
||||||
double value = dataPoint[j + 1];
|
double value = dataPoint[j + 1];
|
||||||
if (Double.isNaN(value)) {
|
if (Double.isNaN(value)) {
|
||||||
@@ -869,8 +891,7 @@ public class ChartView extends View {
|
|||||||
topBorder = (int) (density * BORDER + titleDimensions[0] * (titleDimensions[1] + spacer));
|
topBorder = (int) (density * BORDER + titleDimensions[0] * (titleDimensions[1] + spacer));
|
||||||
Rect xAxisLabelRect = getRect(axisPaint, getXAxisLabel());
|
Rect xAxisLabelRect = getRect(axisPaint, getXAxisLabel());
|
||||||
// border + x axis marker + spacer + .5 x axis label
|
// border + x axis marker + spacer + .5 x axis label
|
||||||
bottomBorder = (int) (density * BORDER + getRect(xAxisMarkerPaint, "1").height() + spacer
|
bottomBorder = (int) (density * BORDER + getRect(xAxisMarkerPaint, "1").height() + spacer + (xAxisLabelRect.height() / 2));
|
||||||
+ (xAxisLabelRect.height() / 2));
|
|
||||||
rightBorder = (int) (density * BORDER + xAxisLabelRect.width() + spacer);
|
rightBorder = (int) (density * BORDER + xAxisLabelRect.width() + spacer);
|
||||||
updateEffectiveDimensions();
|
updateEffectiveDimensions();
|
||||||
}
|
}
|
||||||
@@ -34,6 +34,10 @@ import android.util.Log;
|
|||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.VisibleForTesting;
|
import androidx.annotation.VisibleForTesting;
|
||||||
|
|
||||||
|
import de.dennisguse.opentracks.content.data.TrackPointsColumns;
|
||||||
|
import de.dennisguse.opentracks.content.data.TracksColumns;
|
||||||
|
import de.dennisguse.opentracks.content.data.WaypointsColumns;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A {@link ContentProvider} that handles access to track points, tracks, and waypoints tables.
|
* A {@link ContentProvider} that handles access to track points, tracks, and waypoints tables.
|
||||||
*
|
*
|
||||||
@@ -56,11 +60,11 @@ public abstract class CustomContentProvider extends ContentProvider {
|
|||||||
public CustomContentProvider() {
|
public CustomContentProvider() {
|
||||||
uriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
|
uriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
|
||||||
uriMatcher.addURI(ContentProviderUtils.AUTHORITY_PACKAGE, TrackPointsColumns.TABLE_NAME, UrlType.TRACKPOINTS.ordinal());
|
uriMatcher.addURI(ContentProviderUtils.AUTHORITY_PACKAGE, TrackPointsColumns.TABLE_NAME, UrlType.TRACKPOINTS.ordinal());
|
||||||
uriMatcher.addURI(ContentProviderUtils.AUTHORITY_PACKAGE, TrackPointsColumns.TABLE_NAME + "/#", UrlType.TRACKPOINTS_ID.ordinal());
|
uriMatcher.addURI(ContentProviderUtils.AUTHORITY_PACKAGE, TrackPointsColumns.TABLE_NAME + "/#", UrlType.TRACKPOINTS_BY_ID.ordinal());
|
||||||
uriMatcher.addURI(ContentProviderUtils.AUTHORITY_PACKAGE, TracksColumns.TABLE_NAME, UrlType.TRACKS.ordinal());
|
uriMatcher.addURI(ContentProviderUtils.AUTHORITY_PACKAGE, TracksColumns.TABLE_NAME, UrlType.TRACKS.ordinal());
|
||||||
uriMatcher.addURI(ContentProviderUtils.AUTHORITY_PACKAGE, TracksColumns.TABLE_NAME + "/#", UrlType.TRACKS_ID.ordinal());
|
uriMatcher.addURI(ContentProviderUtils.AUTHORITY_PACKAGE, TracksColumns.TABLE_NAME + "/#", UrlType.TRACKS_BY_ID.ordinal());
|
||||||
uriMatcher.addURI(ContentProviderUtils.AUTHORITY_PACKAGE, WaypointsColumns.TABLE_NAME, UrlType.WAYPOINTS.ordinal());
|
uriMatcher.addURI(ContentProviderUtils.AUTHORITY_PACKAGE, WaypointsColumns.TABLE_NAME, UrlType.WAYPOINTS.ordinal());
|
||||||
uriMatcher.addURI(ContentProviderUtils.AUTHORITY_PACKAGE, WaypointsColumns.TABLE_NAME + "/#", UrlType.WAYPOINTS_ID.ordinal());
|
uriMatcher.addURI(ContentProviderUtils.AUTHORITY_PACKAGE, WaypointsColumns.TABLE_NAME + "/#", UrlType.WAYPOINTS_BY_ID.ordinal());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -128,15 +132,15 @@ public abstract class CustomContentProvider extends ContentProvider {
|
|||||||
switch (getUrlType(url)) {
|
switch (getUrlType(url)) {
|
||||||
case TRACKPOINTS:
|
case TRACKPOINTS:
|
||||||
return TrackPointsColumns.CONTENT_TYPE;
|
return TrackPointsColumns.CONTENT_TYPE;
|
||||||
case TRACKPOINTS_ID:
|
case TRACKPOINTS_BY_ID:
|
||||||
return TrackPointsColumns.CONTENT_ITEMTYPE;
|
return TrackPointsColumns.CONTENT_ITEMTYPE;
|
||||||
case TRACKS:
|
case TRACKS:
|
||||||
return TracksColumns.CONTENT_TYPE;
|
return TracksColumns.CONTENT_TYPE;
|
||||||
case TRACKS_ID:
|
case TRACKS_BY_ID:
|
||||||
return TracksColumns.CONTENT_ITEMTYPE;
|
return TracksColumns.CONTENT_ITEMTYPE;
|
||||||
case WAYPOINTS:
|
case WAYPOINTS:
|
||||||
return WaypointsColumns.CONTENT_TYPE;
|
return WaypointsColumns.CONTENT_TYPE;
|
||||||
case WAYPOINTS_ID:
|
case WAYPOINTS_BY_ID:
|
||||||
return WaypointsColumns.CONTENT_ITEMTYPE;
|
return WaypointsColumns.CONTENT_ITEMTYPE;
|
||||||
default:
|
default:
|
||||||
throw new IllegalArgumentException("Unknown URL " + url);
|
throw new IllegalArgumentException("Unknown URL " + url);
|
||||||
@@ -192,7 +196,7 @@ public abstract class CustomContentProvider extends ContentProvider {
|
|||||||
queryBuilder.setTables(TrackPointsColumns.TABLE_NAME);
|
queryBuilder.setTables(TrackPointsColumns.TABLE_NAME);
|
||||||
sortOrder = sort != null ? sort : TrackPointsColumns.DEFAULT_SORT_ORDER;
|
sortOrder = sort != null ? sort : TrackPointsColumns.DEFAULT_SORT_ORDER;
|
||||||
break;
|
break;
|
||||||
case TRACKPOINTS_ID:
|
case TRACKPOINTS_BY_ID:
|
||||||
queryBuilder.setTables(TrackPointsColumns.TABLE_NAME);
|
queryBuilder.setTables(TrackPointsColumns.TABLE_NAME);
|
||||||
queryBuilder.appendWhere("_id=" + url.getPathSegments().get(1));
|
queryBuilder.appendWhere("_id=" + url.getPathSegments().get(1));
|
||||||
break;
|
break;
|
||||||
@@ -200,7 +204,7 @@ public abstract class CustomContentProvider extends ContentProvider {
|
|||||||
queryBuilder.setTables(TracksColumns.TABLE_NAME);
|
queryBuilder.setTables(TracksColumns.TABLE_NAME);
|
||||||
sortOrder = sort != null ? sort : TracksColumns.DEFAULT_SORT_ORDER;
|
sortOrder = sort != null ? sort : TracksColumns.DEFAULT_SORT_ORDER;
|
||||||
break;
|
break;
|
||||||
case TRACKS_ID:
|
case TRACKS_BY_ID:
|
||||||
queryBuilder.setTables(TracksColumns.TABLE_NAME);
|
queryBuilder.setTables(TracksColumns.TABLE_NAME);
|
||||||
queryBuilder.appendWhere("_id=" + url.getPathSegments().get(1));
|
queryBuilder.appendWhere("_id=" + url.getPathSegments().get(1));
|
||||||
break;
|
break;
|
||||||
@@ -208,7 +212,7 @@ public abstract class CustomContentProvider extends ContentProvider {
|
|||||||
queryBuilder.setTables(WaypointsColumns.TABLE_NAME);
|
queryBuilder.setTables(WaypointsColumns.TABLE_NAME);
|
||||||
sortOrder = sort != null ? sort : WaypointsColumns.DEFAULT_SORT_ORDER;
|
sortOrder = sort != null ? sort : WaypointsColumns.DEFAULT_SORT_ORDER;
|
||||||
break;
|
break;
|
||||||
case WAYPOINTS_ID:
|
case WAYPOINTS_BY_ID:
|
||||||
queryBuilder.setTables(WaypointsColumns.TABLE_NAME);
|
queryBuilder.setTables(WaypointsColumns.TABLE_NAME);
|
||||||
queryBuilder.appendWhere("_id=" + url.getPathSegments().get(1));
|
queryBuilder.appendWhere("_id=" + url.getPathSegments().get(1));
|
||||||
break;
|
break;
|
||||||
@@ -229,7 +233,7 @@ public abstract class CustomContentProvider extends ContentProvider {
|
|||||||
table = TrackPointsColumns.TABLE_NAME;
|
table = TrackPointsColumns.TABLE_NAME;
|
||||||
whereClause = where;
|
whereClause = where;
|
||||||
break;
|
break;
|
||||||
case TRACKPOINTS_ID:
|
case TRACKPOINTS_BY_ID:
|
||||||
table = TrackPointsColumns.TABLE_NAME;
|
table = TrackPointsColumns.TABLE_NAME;
|
||||||
whereClause = TrackPointsColumns._ID + "=" + url.getPathSegments().get(1);
|
whereClause = TrackPointsColumns._ID + "=" + url.getPathSegments().get(1);
|
||||||
if (!TextUtils.isEmpty(where)) {
|
if (!TextUtils.isEmpty(where)) {
|
||||||
@@ -240,7 +244,7 @@ public abstract class CustomContentProvider extends ContentProvider {
|
|||||||
table = TracksColumns.TABLE_NAME;
|
table = TracksColumns.TABLE_NAME;
|
||||||
whereClause = where;
|
whereClause = where;
|
||||||
break;
|
break;
|
||||||
case TRACKS_ID:
|
case TRACKS_BY_ID:
|
||||||
table = TracksColumns.TABLE_NAME;
|
table = TracksColumns.TABLE_NAME;
|
||||||
whereClause = TracksColumns._ID + "=" + url.getPathSegments().get(1);
|
whereClause = TracksColumns._ID + "=" + url.getPathSegments().get(1);
|
||||||
if (!TextUtils.isEmpty(where)) {
|
if (!TextUtils.isEmpty(where)) {
|
||||||
@@ -251,7 +255,7 @@ public abstract class CustomContentProvider extends ContentProvider {
|
|||||||
table = WaypointsColumns.TABLE_NAME;
|
table = WaypointsColumns.TABLE_NAME;
|
||||||
whereClause = where;
|
whereClause = where;
|
||||||
break;
|
break;
|
||||||
case WAYPOINTS_ID:
|
case WAYPOINTS_BY_ID:
|
||||||
table = WaypointsColumns.TABLE_NAME;
|
table = WaypointsColumns.TABLE_NAME;
|
||||||
whereClause = WaypointsColumns._ID + "=" + url.getPathSegments().get(1);
|
whereClause = WaypointsColumns._ID + "=" + url.getPathSegments().get(1);
|
||||||
if (!TextUtils.isEmpty(where)) {
|
if (!TextUtils.isEmpty(where)) {
|
||||||
@@ -330,8 +334,7 @@ public abstract class CustomContentProvider extends ContentProvider {
|
|||||||
*/
|
*/
|
||||||
private Uri insertTrack(Uri url, ContentValues contentValues) {
|
private Uri insertTrack(Uri url, ContentValues contentValues) {
|
||||||
boolean hasStartTime = contentValues.containsKey(TracksColumns.STARTTIME);
|
boolean hasStartTime = contentValues.containsKey(TracksColumns.STARTTIME);
|
||||||
boolean hasStartId = contentValues.containsKey(TracksColumns.STARTID);
|
if (!hasStartTime) {
|
||||||
if (!hasStartTime || !hasStartId) {
|
|
||||||
throw new IllegalArgumentException("Both start time and start id values are required.");
|
throw new IllegalArgumentException("Both start time and start id values are required.");
|
||||||
}
|
}
|
||||||
long rowId = db.insert(TracksColumns.TABLE_NAME, TracksColumns._ID, contentValues);
|
long rowId = db.insert(TracksColumns.TABLE_NAME, TracksColumns._ID, contentValues);
|
||||||
@@ -362,7 +365,11 @@ public abstract class CustomContentProvider extends ContentProvider {
|
|||||||
*/
|
*/
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
enum UrlType {
|
enum UrlType {
|
||||||
TRACKPOINTS, TRACKPOINTS_ID, TRACKS, TRACKS_ID, WAYPOINTS, WAYPOINTS_ID
|
TRACKPOINTS,
|
||||||
|
TRACKPOINTS_BY_ID,
|
||||||
|
TRACKS, TRACKS_BY_ID,
|
||||||
|
WAYPOINTS,
|
||||||
|
WAYPOINTS_BY_ID
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -25,6 +25,10 @@ import android.util.Log;
|
|||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import de.dennisguse.opentracks.content.data.TrackPointsColumns;
|
||||||
|
import de.dennisguse.opentracks.content.data.TracksColumns;
|
||||||
|
import de.dennisguse.opentracks.content.data.WaypointsColumns;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates observers/listeners and manages their registration with {@link DataSource}.
|
* Creates observers/listeners and manages their registration with {@link DataSource}.
|
||||||
* The observers/listeners calls {@link DataSourceListener} when data changes.
|
* The observers/listeners calls {@link DataSourceListener} when data changes.
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2010 Google Inc.
|
* Copyright 2012 Google Inc.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||||
* use this file except in compliance with the License. You may obtain a copy of
|
* use this file except in compliance with the License. You may obtain a copy of
|
||||||
@@ -13,16 +13,37 @@
|
|||||||
* License for the specific language governing permissions and limitations under
|
* License for the specific language governing permissions and limitations under
|
||||||
* the License.
|
* the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package de.dennisguse.opentracks.content;
|
package de.dennisguse.opentracks.content;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.util.Pair;
|
||||||
|
|
||||||
|
import androidx.annotation.VisibleForTesting;
|
||||||
|
|
||||||
|
import de.dennisguse.opentracks.R;
|
||||||
|
import de.dennisguse.opentracks.content.data.Track;
|
||||||
import de.dennisguse.opentracks.stats.TripStatistics;
|
import de.dennisguse.opentracks.stats.TripStatistics;
|
||||||
|
import de.dennisguse.opentracks.util.StringUtils;
|
||||||
|
import de.dennisguse.opentracks.util.UnitConversions;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An interface for an object that can generate descriptions of track and waypoint.
|
* Generates descriptions for tracks and waypoints.
|
||||||
*
|
*
|
||||||
* @author Sandor Dornbush
|
* @author Jimmy Shih
|
||||||
*/
|
*/
|
||||||
public interface DescriptionGenerator {
|
public class DescriptionGenerator {
|
||||||
|
|
||||||
|
private static final String HTML_LINE_BREAK = "<br>";
|
||||||
|
private static final String HTML_PARAGRAPH_SEPARATOR = "<p>";
|
||||||
|
private static final String TEXT_LINE_BREAK = "\n";
|
||||||
|
private static final String TEXT_PARAGRAPH_SEPARATOR = "\n\n";
|
||||||
|
|
||||||
|
private Context context;
|
||||||
|
|
||||||
|
public DescriptionGenerator(Context context) {
|
||||||
|
this.context = context;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates a track description.
|
* Generates a track description.
|
||||||
@@ -30,12 +51,196 @@ public interface DescriptionGenerator {
|
|||||||
* @param track the track
|
* @param track the track
|
||||||
* @param html true to output html, false to output plain text
|
* @param html true to output html, false to output plain text
|
||||||
*/
|
*/
|
||||||
String generateTrackDescription(Track track, boolean html);
|
public String generateTrackDescription(Track track, boolean html) {
|
||||||
|
String paragraphSeparator = html ? HTML_PARAGRAPH_SEPARATOR : TEXT_PARAGRAPH_SEPARATOR;
|
||||||
|
String lineBreak = html ? HTML_LINE_BREAK : TEXT_LINE_BREAK;
|
||||||
|
StringBuilder builder = new StringBuilder();
|
||||||
|
|
||||||
|
// Created by
|
||||||
|
String creator = html
|
||||||
|
? "<a href='" + context.getString(R.string.app_web_url) + "'>" + context.getString(R.string.app_name) + "</a>"
|
||||||
|
: context.getString(R.string.app_name);
|
||||||
|
builder.append(creator);
|
||||||
|
|
||||||
|
builder.append(paragraphSeparator);
|
||||||
|
|
||||||
|
writeString(track.getName(), builder, R.string.generic_name_line, lineBreak);
|
||||||
|
writeString(track.getCategory(), builder, R.string.description_activity_type, lineBreak);
|
||||||
|
writeString(track.getDescription(), builder, R.string.generic_description_line, lineBreak);
|
||||||
|
builder.append(generateTripStatisticsDescription(track.getTripStatistics(), html));
|
||||||
|
|
||||||
|
return builder.toString();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate a waypoint description from a trip statistics.
|
* Writes a string to a string builder.
|
||||||
*
|
*
|
||||||
* @param tripStatistics the trip statistics
|
* @param text the string
|
||||||
|
* @param builder the string builder
|
||||||
|
* @param resId the resource id containing one string placeholder
|
||||||
|
* @param lineBreak the line break
|
||||||
*/
|
*/
|
||||||
String generateWaypointDescription(TripStatistics tripStatistics);
|
private void writeString(String text, StringBuilder builder, int resId, String lineBreak) {
|
||||||
|
if (text == null || text.length() == 0) {
|
||||||
|
text = context.getString(R.string.value_unknown);
|
||||||
|
}
|
||||||
|
builder.append(context.getString(resId, text));
|
||||||
|
builder.append(lineBreak);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generates a description for a {@link TripStatistics}.
|
||||||
|
*
|
||||||
|
* @param stats the trip statistics
|
||||||
|
* @param html true to use "<br>" for line break instead of "\n"
|
||||||
|
*/
|
||||||
|
private String generateTripStatisticsDescription(TripStatistics stats, boolean html) {
|
||||||
|
String lineBreak = html ? HTML_LINE_BREAK : TEXT_LINE_BREAK;
|
||||||
|
StringBuilder builder = new StringBuilder();
|
||||||
|
|
||||||
|
// Total distance
|
||||||
|
writeDistance(stats.getTotalDistance(), builder, R.string.description_total_distance, lineBreak);
|
||||||
|
|
||||||
|
// Total time
|
||||||
|
writeTime(stats.getTotalTime(), builder, R.string.description_total_time, lineBreak);
|
||||||
|
|
||||||
|
// Moving time
|
||||||
|
writeTime(stats.getMovingTime(), builder, R.string.description_moving_time, lineBreak);
|
||||||
|
|
||||||
|
// Average speed
|
||||||
|
writeSpeed(stats.getAverageSpeed(), builder, R.string.description_average_speed, lineBreak);
|
||||||
|
|
||||||
|
// Average moving speed
|
||||||
|
writeSpeed(stats.getAverageMovingSpeed(), builder, R.string.description_average_moving_speed, lineBreak);
|
||||||
|
|
||||||
|
// Max speed
|
||||||
|
writeSpeed(stats.getMaxSpeed(), builder, R.string.description_max_speed, lineBreak);
|
||||||
|
|
||||||
|
// Average pace
|
||||||
|
writePace(stats.getAverageSpeed(), builder, R.string.description_average_pace_in_minute, lineBreak);
|
||||||
|
|
||||||
|
// Average moving pace
|
||||||
|
writePace(stats.getAverageMovingSpeed(), builder, R.string.description_average_moving_pace_in_minute, lineBreak);
|
||||||
|
|
||||||
|
// Fastest pace
|
||||||
|
writePace(stats.getMaxSpeed(), builder, R.string.description_fastest_pace_in_minute, lineBreak);
|
||||||
|
|
||||||
|
// Max elevation
|
||||||
|
writeElevation(stats.getMaxElevation(), builder, R.string.description_max_elevation, lineBreak);
|
||||||
|
|
||||||
|
// Min elevation
|
||||||
|
writeElevation(stats.getMinElevation(), builder, R.string.description_min_elevation, lineBreak);
|
||||||
|
|
||||||
|
// Elevation gain
|
||||||
|
writeElevation(stats.getTotalElevationGain(), builder, R.string.description_elevation_gain, lineBreak);
|
||||||
|
|
||||||
|
// Max grade
|
||||||
|
writeGrade(stats.getMaxGrade(), builder, R.string.description_max_grade, lineBreak);
|
||||||
|
|
||||||
|
// Min grade
|
||||||
|
writeGrade(stats.getMinGrade(), builder, R.string.description_min_grade, lineBreak);
|
||||||
|
|
||||||
|
// Recorded time
|
||||||
|
builder.append(context.getString(R.string.description_recorded_time, StringUtils.formatDateTime(context, stats.getStartTime())));
|
||||||
|
builder.append(lineBreak);
|
||||||
|
|
||||||
|
return builder.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Writes distance.
|
||||||
|
*
|
||||||
|
* @param distance distance in meters
|
||||||
|
* @param builder StringBuilder to append distance
|
||||||
|
* @param resId resource id of distance string
|
||||||
|
* @param lineBreak line break string
|
||||||
|
*/
|
||||||
|
@VisibleForTesting
|
||||||
|
void writeDistance(double distance, StringBuilder builder, int resId, String lineBreak) {
|
||||||
|
double distanceInKm = distance * UnitConversions.M_TO_KM;
|
||||||
|
double distanceInMi = distanceInKm * UnitConversions.KM_TO_MI;
|
||||||
|
builder.append(context.getString(resId, distanceInKm, distanceInMi));
|
||||||
|
builder.append(lineBreak);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Writes time.
|
||||||
|
*
|
||||||
|
* @param time time in milliseconds.
|
||||||
|
* @param builder StringBuilder to append time
|
||||||
|
* @param resId resource id of time string
|
||||||
|
* @param lineBreak line break string
|
||||||
|
*/
|
||||||
|
@VisibleForTesting
|
||||||
|
void writeTime(long time, StringBuilder builder, int resId, String lineBreak) {
|
||||||
|
builder.append(context.getString(resId, StringUtils.formatElapsedTime(time)));
|
||||||
|
builder.append(lineBreak);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Writes speed.
|
||||||
|
*
|
||||||
|
* @param speed speed in meters per second
|
||||||
|
* @param builder StringBuilder to append speed
|
||||||
|
* @param resId resource id of speed string
|
||||||
|
* @param lineBreak line break string
|
||||||
|
*/
|
||||||
|
@VisibleForTesting
|
||||||
|
void writeSpeed(double speed, StringBuilder builder, int resId, String lineBreak) {
|
||||||
|
double speedInKmHr = speed * UnitConversions.MS_TO_KMH;
|
||||||
|
double speedInMiHr = speedInKmHr * UnitConversions.KM_TO_MI;
|
||||||
|
builder.append(context.getString(resId, speedInKmHr, speedInMiHr));
|
||||||
|
builder.append(lineBreak);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Writes pace.
|
||||||
|
*
|
||||||
|
* @param speed speed in meters per second
|
||||||
|
* @param builder StringBuilder to append pace
|
||||||
|
* @param resId resource id of pace string
|
||||||
|
* @param lineBreak line break string
|
||||||
|
*/
|
||||||
|
@VisibleForTesting
|
||||||
|
void writePace(double speed, StringBuilder builder, int resId, String lineBreak) {
|
||||||
|
Pair<String, String> paceInMetrics = StringUtils.getSpeedParts(context, speed, true, false);
|
||||||
|
Pair<String, String> paceInImperial = StringUtils.getSpeedParts(context, speed, false, false);
|
||||||
|
|
||||||
|
String formattedPaceMetrics = paceInMetrics.first != null ? paceInMetrics.first : context.getString(R.string.value_unknown);
|
||||||
|
String formattedPaceImperial = paceInImperial.first != null ? paceInImperial.first : context.getString(R.string.value_unknown);
|
||||||
|
|
||||||
|
builder.append(context.getString(resId, formattedPaceMetrics, formattedPaceImperial));
|
||||||
|
builder.append(lineBreak);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Writes elevation.
|
||||||
|
*
|
||||||
|
* @param elevation elevation in meters
|
||||||
|
* @param builder StringBuilder to append elevation
|
||||||
|
* @param resId resource id of elevation string
|
||||||
|
* @param lineBreak line break string
|
||||||
|
*/
|
||||||
|
@VisibleForTesting
|
||||||
|
void writeElevation(double elevation, StringBuilder builder, int resId, String lineBreak) {
|
||||||
|
long elevationInM = Math.round(elevation);
|
||||||
|
long elevationInFt = Math.round(elevation * UnitConversions.M_TO_FT);
|
||||||
|
builder.append(context.getString(resId, elevationInM, elevationInFt));
|
||||||
|
builder.append(lineBreak);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Writes grade.
|
||||||
|
*
|
||||||
|
* @param grade grade in fraction
|
||||||
|
* @param builder StringBuilder to append grade
|
||||||
|
* @param resId resource id grade string
|
||||||
|
* @param lineBreak line break string
|
||||||
|
*/
|
||||||
|
@VisibleForTesting
|
||||||
|
void writeGrade(double grade, StringBuilder builder, int resId, String lineBreak) {
|
||||||
|
long gradeInPercent = Double.isNaN(grade) || Double.isInfinite(grade) ? 0L : Math.round(grade * 100);
|
||||||
|
builder.append(context.getString(resId, gradeInPercent));
|
||||||
|
builder.append(lineBreak);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,243 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2012 Google Inc.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
|
||||||
* use this file except in compliance with the License. You may obtain a copy of
|
|
||||||
* the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
||||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
||||||
* License for the specific language governing permissions and limitations under
|
|
||||||
* the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package de.dennisguse.opentracks.content;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.util.Pair;
|
|
||||||
|
|
||||||
import androidx.annotation.VisibleForTesting;
|
|
||||||
|
|
||||||
import de.dennisguse.opentracks.R;
|
|
||||||
import de.dennisguse.opentracks.stats.TripStatistics;
|
|
||||||
import de.dennisguse.opentracks.util.StringUtils;
|
|
||||||
import de.dennisguse.opentracks.util.UnitConversions;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Jimmy Shih
|
|
||||||
*/
|
|
||||||
public class DescriptionGeneratorImpl implements DescriptionGenerator {
|
|
||||||
|
|
||||||
private static final String HTML_LINE_BREAK = "<br>";
|
|
||||||
private static final String HTML_PARAGRAPH_SEPARATOR = "<p>";
|
|
||||||
private static final String TEXT_LINE_BREAK = "\n";
|
|
||||||
private static final String TEXT_PARAGRAPH_SEPARATOR = "\n\n";
|
|
||||||
|
|
||||||
private Context context;
|
|
||||||
|
|
||||||
public DescriptionGeneratorImpl(Context context) {
|
|
||||||
this.context = context;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String generateTrackDescription(Track track, boolean html) {
|
|
||||||
String paragraphSeparator = html ? HTML_PARAGRAPH_SEPARATOR : TEXT_PARAGRAPH_SEPARATOR;
|
|
||||||
String lineBreak = html ? HTML_LINE_BREAK : TEXT_LINE_BREAK;
|
|
||||||
StringBuilder builder = new StringBuilder();
|
|
||||||
|
|
||||||
// Created by
|
|
||||||
String creator = html
|
|
||||||
? "<a href='" + context.getString(R.string.app_web_url) + "'>" + context.getString(R.string.app_name) + "</a>"
|
|
||||||
: context.getString(R.string.app_name);
|
|
||||||
builder.append(creator);
|
|
||||||
|
|
||||||
builder.append(paragraphSeparator);
|
|
||||||
|
|
||||||
writeString(track.getName(), builder, R.string.generic_name_line, lineBreak);
|
|
||||||
writeString(track.getCategory(), builder, R.string.description_activity_type, lineBreak);
|
|
||||||
writeString(track.getDescription(), builder, R.string.generic_description_line, lineBreak);
|
|
||||||
builder.append(generateTripStatisticsDescription(track.getTripStatistics(), html));
|
|
||||||
|
|
||||||
return builder.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String generateWaypointDescription(TripStatistics tripStatistics) {
|
|
||||||
return generateTripStatisticsDescription(tripStatistics, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Writes a string to a string builder.
|
|
||||||
*
|
|
||||||
* @param text the string
|
|
||||||
* @param builder the string builder
|
|
||||||
* @param resId the resource id containing one string placeholder
|
|
||||||
* @param lineBreak the line break
|
|
||||||
*/
|
|
||||||
private void writeString(String text, StringBuilder builder, int resId, String lineBreak) {
|
|
||||||
if (text == null || text.length() == 0) {
|
|
||||||
text = context.getString(R.string.value_unknown);
|
|
||||||
}
|
|
||||||
builder.append(context.getString(resId, text));
|
|
||||||
builder.append(lineBreak);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Generates a description for a {@link TripStatistics}.
|
|
||||||
*
|
|
||||||
* @param stats the trip statistics
|
|
||||||
* @param html true to use "<br>" for line break instead of "\n"
|
|
||||||
*/
|
|
||||||
private String generateTripStatisticsDescription(TripStatistics stats, boolean html) {
|
|
||||||
String lineBreak = html ? HTML_LINE_BREAK : TEXT_LINE_BREAK;
|
|
||||||
StringBuilder builder = new StringBuilder();
|
|
||||||
|
|
||||||
// Total distance
|
|
||||||
writeDistance(stats.getTotalDistance(), builder, R.string.description_total_distance, lineBreak);
|
|
||||||
|
|
||||||
// Total time
|
|
||||||
writeTime(stats.getTotalTime(), builder, R.string.description_total_time, lineBreak);
|
|
||||||
|
|
||||||
// Moving time
|
|
||||||
writeTime(stats.getMovingTime(), builder, R.string.description_moving_time, lineBreak);
|
|
||||||
|
|
||||||
// Average speed
|
|
||||||
writeSpeed(stats.getAverageSpeed(), builder, R.string.description_average_speed, lineBreak);
|
|
||||||
|
|
||||||
// Average moving speed
|
|
||||||
writeSpeed(stats.getAverageMovingSpeed(), builder, R.string.description_average_moving_speed, lineBreak);
|
|
||||||
|
|
||||||
// Max speed
|
|
||||||
writeSpeed(stats.getMaxSpeed(), builder, R.string.description_max_speed, lineBreak);
|
|
||||||
|
|
||||||
// Average pace
|
|
||||||
writePace(stats.getAverageSpeed(), builder, R.string.description_average_pace_in_minute, lineBreak);
|
|
||||||
|
|
||||||
// Average moving pace
|
|
||||||
writePace(stats.getAverageMovingSpeed(), builder, R.string.description_average_moving_pace_in_minute, lineBreak);
|
|
||||||
|
|
||||||
// Fastest pace
|
|
||||||
writePace(stats.getMaxSpeed(), builder, R.string.description_fastest_pace_in_minute, lineBreak);
|
|
||||||
|
|
||||||
// Max elevation
|
|
||||||
writeElevation(stats.getMaxElevation(), builder, R.string.description_max_elevation, lineBreak);
|
|
||||||
|
|
||||||
// Min elevation
|
|
||||||
writeElevation(stats.getMinElevation(), builder, R.string.description_min_elevation, lineBreak);
|
|
||||||
|
|
||||||
// Elevation gain
|
|
||||||
writeElevation(stats.getTotalElevationGain(), builder, R.string.description_elevation_gain, lineBreak);
|
|
||||||
|
|
||||||
// Max grade
|
|
||||||
writeGrade(stats.getMaxGrade(), builder, R.string.description_max_grade, lineBreak);
|
|
||||||
|
|
||||||
// Min grade
|
|
||||||
writeGrade(stats.getMinGrade(), builder, R.string.description_min_grade, lineBreak);
|
|
||||||
|
|
||||||
// Recorded time
|
|
||||||
builder.append(context.getString(R.string.description_recorded_time, StringUtils.formatDateTime(context, stats.getStartTime())));
|
|
||||||
builder.append(lineBreak);
|
|
||||||
|
|
||||||
return builder.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Writes distance.
|
|
||||||
*
|
|
||||||
* @param distance distance in meters
|
|
||||||
* @param builder StringBuilder to append distance
|
|
||||||
* @param resId resource id of distance string
|
|
||||||
* @param lineBreak line break string
|
|
||||||
*/
|
|
||||||
@VisibleForTesting
|
|
||||||
void writeDistance(double distance, StringBuilder builder, int resId, String lineBreak) {
|
|
||||||
double distanceInKm = distance * UnitConversions.M_TO_KM;
|
|
||||||
double distanceInMi = distanceInKm * UnitConversions.KM_TO_MI;
|
|
||||||
builder.append(context.getString(resId, distanceInKm, distanceInMi));
|
|
||||||
builder.append(lineBreak);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Writes time.
|
|
||||||
*
|
|
||||||
* @param time time in milliseconds.
|
|
||||||
* @param builder StringBuilder to append time
|
|
||||||
* @param resId resource id of time string
|
|
||||||
* @param lineBreak line break string
|
|
||||||
*/
|
|
||||||
@VisibleForTesting
|
|
||||||
void writeTime(long time, StringBuilder builder, int resId, String lineBreak) {
|
|
||||||
builder.append(context.getString(resId, StringUtils.formatElapsedTime(time)));
|
|
||||||
builder.append(lineBreak);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Writes speed.
|
|
||||||
*
|
|
||||||
* @param speed speed in meters per second
|
|
||||||
* @param builder StringBuilder to append speed
|
|
||||||
* @param resId resource id of speed string
|
|
||||||
* @param lineBreak line break string
|
|
||||||
*/
|
|
||||||
@VisibleForTesting
|
|
||||||
void writeSpeed(double speed, StringBuilder builder, int resId, String lineBreak) {
|
|
||||||
double speedInKmHr = speed * UnitConversions.MS_TO_KMH;
|
|
||||||
double speedInMiHr = speedInKmHr * UnitConversions.KM_TO_MI;
|
|
||||||
builder.append(context.getString(resId, speedInKmHr, speedInMiHr));
|
|
||||||
builder.append(lineBreak);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Writes pace.
|
|
||||||
*
|
|
||||||
* @param speed speed in meters per second
|
|
||||||
* @param builder StringBuilder to append pace
|
|
||||||
* @param resId resource id of pace string
|
|
||||||
* @param lineBreak line break string
|
|
||||||
*/
|
|
||||||
@VisibleForTesting
|
|
||||||
void writePace(double speed, StringBuilder builder, int resId, String lineBreak) {
|
|
||||||
Pair<String, String> paceInMetrics = StringUtils.getSpeedParts(context, speed, true, false);
|
|
||||||
Pair<String, String> paceInImperial = StringUtils.getSpeedParts(context, speed, false, false);
|
|
||||||
|
|
||||||
String formattedPaceMetrics = paceInMetrics.first != null ? paceInMetrics.first : context.getString(R.string.value_unknown);
|
|
||||||
String formattedPaceImperial = paceInImperial.first != null ? paceInImperial.first : context.getString(R.string.value_unknown);
|
|
||||||
|
|
||||||
builder.append(context.getString(resId, formattedPaceMetrics, formattedPaceImperial));
|
|
||||||
builder.append(lineBreak);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Writes elevation.
|
|
||||||
*
|
|
||||||
* @param elevation elevation in meters
|
|
||||||
* @param builder StringBuilder to append elevation
|
|
||||||
* @param resId resource id of elevation string
|
|
||||||
* @param lineBreak line break string
|
|
||||||
*/
|
|
||||||
@VisibleForTesting
|
|
||||||
void writeElevation(double elevation, StringBuilder builder, int resId, String lineBreak) {
|
|
||||||
long elevationInM = Math.round(elevation);
|
|
||||||
long elevationInFt = Math.round(elevation * UnitConversions.M_TO_FT);
|
|
||||||
builder.append(context.getString(resId, elevationInM, elevationInFt));
|
|
||||||
builder.append(lineBreak);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Writes grade.
|
|
||||||
*
|
|
||||||
* @param grade grade in fraction
|
|
||||||
* @param builder StringBuilder to append grade
|
|
||||||
* @param resId resource id grade string
|
|
||||||
* @param lineBreak line break string
|
|
||||||
*/
|
|
||||||
@VisibleForTesting
|
|
||||||
void writeGrade(double grade, StringBuilder builder, int resId, String lineBreak) {
|
|
||||||
long gradeInPercent = Double.isNaN(grade) || Double.isInfinite(grade) ? 0L : Math.round(grade * 100);
|
|
||||||
builder.append(context.getString(resId, gradeInPercent));
|
|
||||||
builder.append(lineBreak);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package de.dennisguse.opentracks.content;
|
||||||
|
|
||||||
|
import android.location.Location;
|
||||||
|
import android.location.LocationManager;
|
||||||
|
|
||||||
|
import de.dennisguse.opentracks.content.data.TrackPoint;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new {@link TrackPoint}.
|
||||||
|
* An implementation can create new instances or reuse existing instances for optimization.
|
||||||
|
*/
|
||||||
|
public class LocationFactory {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The default {@link LocationFactory} which creates a location each time.
|
||||||
|
*/
|
||||||
|
public static LocationFactory DEFAULT_LOCATION_FACTORY = new LocationFactory();
|
||||||
|
|
||||||
|
public Location createLocation() {
|
||||||
|
return new TrackPoint(LocationManager.GPS_PROVIDER);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package de.dennisguse.opentracks.content;
|
||||||
|
|
||||||
|
import android.database.Cursor;
|
||||||
|
import android.location.Location;
|
||||||
|
|
||||||
|
import java.util.Iterator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A lightweight wrapper around the original {@link Cursor} with a method to clean up.
|
||||||
|
*/
|
||||||
|
public interface LocationIterator extends Iterator<Location>, AutoCloseable {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the most recently retrieved track point id by {@link #next()}.
|
||||||
|
*/
|
||||||
|
long getLocationId();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Closes the iterator.
|
||||||
|
*/
|
||||||
|
void close();
|
||||||
|
}
|
||||||
@@ -28,6 +28,10 @@ import java.util.Locale;
|
|||||||
import java.util.SortedSet;
|
import java.util.SortedSet;
|
||||||
import java.util.TreeSet;
|
import java.util.TreeSet;
|
||||||
|
|
||||||
|
import de.dennisguse.opentracks.content.data.Track;
|
||||||
|
import de.dennisguse.opentracks.content.data.TracksColumns;
|
||||||
|
import de.dennisguse.opentracks.content.data.Waypoint;
|
||||||
|
import de.dennisguse.opentracks.content.data.WaypointsColumns;
|
||||||
import de.dennisguse.opentracks.stats.TripStatistics;
|
import de.dennisguse.opentracks.stats.TripStatistics;
|
||||||
import de.dennisguse.opentracks.util.LocationUtils;
|
import de.dennisguse.opentracks.util.LocationUtils;
|
||||||
import de.dennisguse.opentracks.util.UnitConversions;
|
import de.dennisguse.opentracks.util.UnitConversions;
|
||||||
@@ -243,7 +247,6 @@ public class SearchEngine {
|
|||||||
score *= getTitleBoost(query, track.getName(), track.getDescription(), track.getCategory());
|
score *= getTitleBoost(query, track.getName(), track.getDescription(), track.getCategory());
|
||||||
|
|
||||||
TripStatistics statistics = track.getTripStatistics();
|
TripStatistics statistics = track.getTripStatistics();
|
||||||
score *= getDistanceBoost(query, statistics.getMeanLatitude(), statistics.getMeanLongitude());
|
|
||||||
|
|
||||||
long meanTimestamp = (statistics.getStartTime() + statistics.getStopTime()) / 2L;
|
long meanTimestamp = (statistics.getStartTime() + statistics.getStopTime()) / 2L;
|
||||||
score *= getTimeBoost(query, meanTimestamp);
|
score *= getTimeBoost(query, meanTimestamp);
|
||||||
|
|||||||
@@ -21,6 +21,8 @@ import java.io.IOException;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
import de.dennisguse.opentracks.android.IContentResolver;
|
import de.dennisguse.opentracks.android.IContentResolver;
|
||||||
|
import de.dennisguse.opentracks.content.data.Track;
|
||||||
|
import de.dennisguse.opentracks.content.data.TracksColumns;
|
||||||
import de.dennisguse.opentracks.io.file.TrackFileFormat;
|
import de.dennisguse.opentracks.io.file.TrackFileFormat;
|
||||||
import de.dennisguse.opentracks.io.file.exporter.TrackExporter;
|
import de.dennisguse.opentracks.io.file.exporter.TrackExporter;
|
||||||
|
|
||||||
@@ -198,7 +200,7 @@ public class ShareContentProvider extends CustomContentProvider implements ICont
|
|||||||
@Nullable
|
@Nullable
|
||||||
@Override
|
@Override
|
||||||
public ParcelFileDescriptor openFile(@NonNull Uri uri, @NonNull String mode) throws FileNotFoundException {
|
public ParcelFileDescriptor openFile(@NonNull Uri uri, @NonNull String mode) throws FileNotFoundException {
|
||||||
ContentProviderUtils contentProviderUtils = new ContentProviderUtilsImpl(this);
|
ContentProviderUtils contentProviderUtils = new ContentProviderUtils(this);
|
||||||
|
|
||||||
long[] trackIds = parseURI(uri);
|
long[] trackIds = parseURI(uri);
|
||||||
final Track[] tracks = new Track[trackIds.length];
|
final Track[] tracks = new Track[trackIds.length];
|
||||||
|
|||||||
@@ -30,7 +30,8 @@ import java.util.EnumSet;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import de.dennisguse.opentracks.R;
|
import de.dennisguse.opentracks.R;
|
||||||
import de.dennisguse.opentracks.content.ContentProviderUtils.LocationIterator;
|
import de.dennisguse.opentracks.content.data.Track;
|
||||||
|
import de.dennisguse.opentracks.content.data.Waypoint;
|
||||||
import de.dennisguse.opentracks.util.LocationUtils;
|
import de.dennisguse.opentracks.util.LocationUtils;
|
||||||
import de.dennisguse.opentracks.util.PreferencesUtils;
|
import de.dennisguse.opentracks.util.PreferencesUtils;
|
||||||
|
|
||||||
@@ -41,17 +42,24 @@ import de.dennisguse.opentracks.util.PreferencesUtils;
|
|||||||
*/
|
*/
|
||||||
public class TrackDataHub implements DataSourceListener {
|
public class TrackDataHub implements DataSourceListener {
|
||||||
|
|
||||||
|
public synchronized static TrackDataHub newInstance(Context context) {
|
||||||
|
return new TrackDataHub(context, new TrackDataManager(), new ContentProviderUtils(context), TARGET_DISPLAYED_TRACK_POINTS);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Target number of track points displayed by the map overlay.
|
* Target number of track points displayed by the map overlay.
|
||||||
* We may display more than this number of points.
|
* We may display more than this number of points.
|
||||||
*/
|
*/
|
||||||
static final int TARGET_DISPLAYED_TRACK_POINTS = 5000;
|
@Deprecated
|
||||||
|
private static final int TARGET_DISPLAYED_TRACK_POINTS = 5000;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Maximum number of waypoints to displayed.
|
* Maximum number of waypoints to displayed.
|
||||||
*/
|
*/
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
|
@Deprecated
|
||||||
private static final int MAX_DISPLAYED_WAYPOINTS = 128;
|
private static final int MAX_DISPLAYED_WAYPOINTS = 128;
|
||||||
|
|
||||||
private static final String TAG = TrackDataHub.class.getSimpleName();
|
private static final String TAG = TrackDataHub.class.getSimpleName();
|
||||||
|
|
||||||
private final Context context;
|
private final Context context;
|
||||||
@@ -96,11 +104,6 @@ public class TrackDataHub implements DataSourceListener {
|
|||||||
resetSamplingState();
|
resetSamplingState();
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized static TrackDataHub newInstance(Context context) {
|
|
||||||
return new TrackDataHub(context, new TrackDataManager(), ContentProviderUtils.Factory.get(
|
|
||||||
context), TARGET_DISPLAYED_TRACK_POINTS);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void start() {
|
public void start() {
|
||||||
if (started) {
|
if (started) {
|
||||||
Log.i(TAG, "TrackDataHub already started, ignoring start.");
|
Log.i(TAG, "TrackDataHub already started, ignoring start.");
|
||||||
@@ -254,13 +257,13 @@ public class TrackDataHub implements DataSourceListener {
|
|||||||
runInHandlerThread(new Runnable() {
|
runInHandlerThread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (key == null || key.equals(PreferencesUtils.getKey(context, R.string.recording_track_id_key))) {
|
if (PreferencesUtils.isKey(context, R.string.recording_track_id_key, key)) {
|
||||||
recordingTrackId = PreferencesUtils.getLong(context, R.string.recording_track_id_key);
|
recordingTrackId = PreferencesUtils.getRecordingTrackId(context);
|
||||||
}
|
}
|
||||||
if (key == null || key.equals(PreferencesUtils.getKey(context, R.string.recording_track_paused_key))) {
|
if (PreferencesUtils.isKey(context, R.string.recording_track_paused_key, key)) {
|
||||||
recordingTrackPaused = PreferencesUtils.getBoolean(context, R.string.recording_track_paused_key, PreferencesUtils.RECORDING_TRACK_PAUSED_DEFAULT);
|
recordingTrackPaused = PreferencesUtils.isRecordingTrackPaused(context);
|
||||||
}
|
}
|
||||||
if (key == null || key.equals(PreferencesUtils.getKey(context, R.string.stats_units_key))) {
|
if (PreferencesUtils.isKey(context, R.string.stats_units_key, key)) {
|
||||||
metricUnits = PreferencesUtils.isMetricUnits(context);
|
metricUnits = PreferencesUtils.isMetricUnits(context);
|
||||||
if (key != null) {
|
if (key != null) {
|
||||||
for (TrackDataListener trackDataListener : trackDataManager.getListeners(TrackDataType.PREFERENCE)) {
|
for (TrackDataListener trackDataListener : trackDataManager.getListeners(TrackDataType.PREFERENCE)) {
|
||||||
@@ -270,7 +273,7 @@ public class TrackDataHub implements DataSourceListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (key == null || key.equals(PreferencesUtils.getKey(context, R.string.stats_rate_key))) {
|
if (PreferencesUtils.isKey(context, R.string.stats_rate_key, key)) {
|
||||||
reportSpeed = PreferencesUtils.isReportSpeed(context);
|
reportSpeed = PreferencesUtils.isReportSpeed(context);
|
||||||
if (key != null) {
|
if (key != null) {
|
||||||
for (TrackDataListener trackDataListener : trackDataManager.getListeners(TrackDataType.PREFERENCE)) {
|
for (TrackDataListener trackDataListener : trackDataManager.getListeners(TrackDataType.PREFERENCE)) {
|
||||||
@@ -280,8 +283,8 @@ public class TrackDataHub implements DataSourceListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (key == null || key.equals(PreferencesUtils.getKey(context, R.string.recording_gps_accuracy_key))) {
|
if (PreferencesUtils.isKey(context, R.string.recording_gps_accuracy_key, key)) {
|
||||||
recordingGpsAccuracy = PreferencesUtils.getInt(context, R.string.recording_gps_accuracy_key, PreferencesUtils.RECORDING_GPS_ACCURACY_DEFAULT);
|
recordingGpsAccuracy = PreferencesUtils.getRecordingGPSAccuracy(context);
|
||||||
if (key != null) {
|
if (key != null) {
|
||||||
for (TrackDataListener trackDataListener : trackDataManager.getListeners(TrackDataType.PREFERENCE)) {
|
for (TrackDataListener trackDataListener : trackDataManager.getListeners(TrackDataType.PREFERENCE)) {
|
||||||
if (trackDataListener.onRecordingGpsAccuracy(recordingGpsAccuracy)) {
|
if (trackDataListener.onRecordingGpsAccuracy(recordingGpsAccuracy)) {
|
||||||
@@ -290,8 +293,8 @@ public class TrackDataHub implements DataSourceListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (key == null || key.equals(PreferencesUtils.getKey(context, R.string.recording_distance_interval_key))) {
|
if (PreferencesUtils.isKey(context, R.string.recording_distance_interval_key, key)) {
|
||||||
recordingDistanceInterval = PreferencesUtils.getInt(context, R.string.recording_distance_interval_key, PreferencesUtils.RECORDING_DISTANCE_INTERVAL_DEFAULT);
|
recordingDistanceInterval = PreferencesUtils.getRecordingDistanceInterval(context);
|
||||||
if (key != null) {
|
if (key != null) {
|
||||||
for (TrackDataListener trackDataListener : trackDataManager.getListeners(TrackDataType.PREFERENCE)) {
|
for (TrackDataListener trackDataListener : trackDataManager.getListeners(TrackDataType.PREFERENCE)) {
|
||||||
if (trackDataListener.onRecordingDistanceIntervalChanged(recordingDistanceInterval)) {
|
if (trackDataListener.onRecordingDistanceIntervalChanged(recordingDistanceInterval)) {
|
||||||
@@ -398,8 +401,7 @@ public class TrackDataHub implements DataSourceListener {
|
|||||||
trackDataListener.clearWaypoints();
|
trackDataListener.clearWaypoints();
|
||||||
}
|
}
|
||||||
|
|
||||||
try (Cursor cursor = contentProviderUtils.getWaypointCursor(
|
try (Cursor cursor = contentProviderUtils.getWaypointCursor(selectedTrackId, -1L, MAX_DISPLAYED_WAYPOINTS)) {
|
||||||
selectedTrackId, -1L, MAX_DISPLAYED_WAYPOINTS)) {
|
|
||||||
if (cursor != null && cursor.moveToFirst()) {
|
if (cursor != null && cursor.moveToFirst()) {
|
||||||
do {
|
do {
|
||||||
Waypoint waypoint = contentProviderUtils.createWaypoint(cursor);
|
Waypoint waypoint = contentProviderUtils.createWaypoint(cursor);
|
||||||
@@ -448,7 +450,7 @@ public class TrackDataHub implements DataSourceListener {
|
|||||||
int samplingFrequency = -1;
|
int samplingFrequency = -1;
|
||||||
boolean includeNextPoint = false;
|
boolean includeNextPoint = false;
|
||||||
|
|
||||||
try (LocationIterator locationIterator = contentProviderUtils.getTrackPointLocationIterator(selectedTrackId, localLastSeenLocationId + 1, false, ContentProviderUtils.DEFAULT_LOCATION_FACTORY)) {
|
try (LocationIterator locationIterator = contentProviderUtils.getTrackPointLocationIterator(selectedTrackId, localLastSeenLocationId + 1, false, LocationFactory.DEFAULT_LOCATION_FACTORY)) {
|
||||||
|
|
||||||
while (locationIterator.hasNext()) {
|
while (locationIterator.hasNext()) {
|
||||||
Location location = locationIterator.next();
|
Location location = locationIterator.next();
|
||||||
@@ -468,12 +470,8 @@ public class TrackDataHub implements DataSourceListener {
|
|||||||
samplingFrequency = 1 + (int) (numTotalPoints / targetNumPoints);
|
samplingFrequency = 1 + (int) (numTotalPoints / targetNumPoints);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!LocationUtils.isValidLocation(location)) {
|
if (!LocationUtils.isValidLocation(location)) { //This can be split markers (not anymore supported feature)
|
||||||
// TODO: also include the last valid point before a split
|
includeNextPoint = true;
|
||||||
for (TrackDataListener trackDataListener : sampledInListeners) {
|
|
||||||
trackDataListener.onSegmentSplit(location);
|
|
||||||
includeNextPoint = true;
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// Also include the last point if the selected track is not recording.
|
// Also include the last point if the selected track is not recording.
|
||||||
if (includeNextPoint || (localNumLoadedPoints % samplingFrequency == 0) || (locationId == lastTrackPointId && !isSelectedTrackRecording())) {
|
if (includeNextPoint || (localNumLoadedPoints % samplingFrequency == 0) || (locationId == lastTrackPointId && !isSelectedTrackRecording())) {
|
||||||
|
|||||||
@@ -18,6 +18,9 @@ package de.dennisguse.opentracks.content;
|
|||||||
|
|
||||||
import android.location.Location;
|
import android.location.Location;
|
||||||
|
|
||||||
|
import de.dennisguse.opentracks.content.data.Track;
|
||||||
|
import de.dennisguse.opentracks.content.data.Waypoint;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Listener for track data changes.
|
* Listener for track data changes.
|
||||||
*
|
*
|
||||||
@@ -51,14 +54,9 @@ public interface TrackDataListener {
|
|||||||
*/
|
*/
|
||||||
void onSampledOutTrackPoint(Location location);
|
void onSampledOutTrackPoint(Location location);
|
||||||
|
|
||||||
/**
|
|
||||||
* Called when an invalid track point representing a segment split is read.
|
|
||||||
*/
|
|
||||||
void onSegmentSplit(Location location);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when finish sending new track points.
|
* Called when finish sending new track points.
|
||||||
* This gets called after every batch of calls to {@link #onSampledInTrackPoint(Location)}, {@link #onSampledOutTrackPoint(Location)} and {@link #onSegmentSplit(Location)}.
|
* This gets called after every batch of calls to {@link #onSampledInTrackPoint(Location)} and {@link #onSampledOutTrackPoint(Location)}.
|
||||||
*/
|
*/
|
||||||
void onNewTrackPointsDone();
|
void onNewTrackPointsDone();
|
||||||
|
|
||||||
|
|||||||
@@ -1,85 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010 Google Inc.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
|
||||||
* use this file except in compliance with the License. You may obtain a copy of
|
|
||||||
* the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
||||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
||||||
* License for the specific language governing permissions and limitations under
|
|
||||||
* the License.
|
|
||||||
*/
|
|
||||||
package de.dennisguse.opentracks.content;
|
|
||||||
|
|
||||||
import de.dennisguse.opentracks.content.Waypoint.WaypointType;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A request for the service to create a waypoint at the current location.
|
|
||||||
*
|
|
||||||
* @author Sandor Dornbush
|
|
||||||
*/
|
|
||||||
public class WaypointCreationRequest {
|
|
||||||
|
|
||||||
public final static WaypointCreationRequest DEFAULT_WAYPOINT = new WaypointCreationRequest(WaypointType.WAYPOINT, false);
|
|
||||||
|
|
||||||
public final static WaypointCreationRequest DEFAULT_STATISTICS = new WaypointCreationRequest(WaypointType.STATISTICS, false);
|
|
||||||
|
|
||||||
public final static WaypointCreationRequest DEFAULT_START_TRACK = new WaypointCreationRequest(WaypointType.STATISTICS, true);
|
|
||||||
|
|
||||||
private WaypointType type;
|
|
||||||
|
|
||||||
// true if this marker contains the track statistics
|
|
||||||
private boolean isTrackStatistics;
|
|
||||||
|
|
||||||
private String name;
|
|
||||||
private String category;
|
|
||||||
private String description;
|
|
||||||
private String iconUrl;
|
|
||||||
private String photoUrl;
|
|
||||||
|
|
||||||
private WaypointCreationRequest(WaypointType type, boolean isTrackStatistics) {
|
|
||||||
this(type, isTrackStatistics, null, null, null, null, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public WaypointCreationRequest(WaypointType type, boolean isTrackStatistics, String name, String category, String description, String iconUrl, String photoUrl) {
|
|
||||||
this.type = type;
|
|
||||||
this.isTrackStatistics = isTrackStatistics;
|
|
||||||
this.name = name;
|
|
||||||
this.category = category;
|
|
||||||
this.description = description;
|
|
||||||
this.iconUrl = iconUrl;
|
|
||||||
this.photoUrl = photoUrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
public WaypointType getType() {
|
|
||||||
return type;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isTrackStatistics() {
|
|
||||||
return isTrackStatistics;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getCategory() {
|
|
||||||
return category;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDescription() {
|
|
||||||
return description;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getIconUrl() {
|
|
||||||
return iconUrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getPhotoUrl() {
|
|
||||||
return photoUrl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
* the License.
|
* the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package de.dennisguse.opentracks.content;
|
package de.dennisguse.opentracks.content.data;
|
||||||
|
|
||||||
import android.location.Location;
|
import android.location.Location;
|
||||||
|
|
||||||
@@ -35,8 +35,6 @@ public class Track {
|
|||||||
private String name = "";
|
private String name = "";
|
||||||
private String description = "";
|
private String description = "";
|
||||||
private String category = "";
|
private String category = "";
|
||||||
private long startId = -1L;
|
|
||||||
private long stopId = -1L;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The number of location points (present even if the points themselves are not loaded)
|
* The number of location points (present even if the points themselves are not loaded)
|
||||||
@@ -84,22 +82,6 @@ public class Track {
|
|||||||
this.category = category;
|
this.category = category;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getStartId() {
|
|
||||||
return startId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setStartId(long startId) {
|
|
||||||
this.startId = startId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getStopId() {
|
|
||||||
return stopId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setStopId(long stopId) {
|
|
||||||
this.stopId = stopId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getNumberOfPoints() {
|
public int getNumberOfPoints() {
|
||||||
return numberOfPoints;
|
return numberOfPoints;
|
||||||
}
|
}
|
||||||
@@ -13,7 +13,7 @@
|
|||||||
* License for the specific language governing permissions and limitations under
|
* License for the specific language governing permissions and limitations under
|
||||||
* the License.
|
* the License.
|
||||||
*/
|
*/
|
||||||
package de.dennisguse.opentracks.content;
|
package de.dennisguse.opentracks.content.data;
|
||||||
|
|
||||||
import android.location.Location;
|
import android.location.Location;
|
||||||
|
|
||||||
@@ -24,21 +24,16 @@ import de.dennisguse.opentracks.content.sensor.SensorDataSet;
|
|||||||
*
|
*
|
||||||
* @author Sandor Dornbush
|
* @author Sandor Dornbush
|
||||||
*/
|
*/
|
||||||
public class SensorDataSetLocation extends Location {
|
public class TrackPoint extends Location {
|
||||||
|
|
||||||
private SensorDataSet sensorDataSet = null;
|
private SensorDataSet sensorDataSet = null;
|
||||||
|
|
||||||
/**
|
public TrackPoint(Location location, SensorDataSet sensorDataSet) {
|
||||||
* The id of this location from the provider.
|
|
||||||
*/
|
|
||||||
private int id = -1;
|
|
||||||
|
|
||||||
public SensorDataSetLocation(Location location, SensorDataSet sensorDataSet) {
|
|
||||||
super(location);
|
super(location);
|
||||||
this.sensorDataSet = sensorDataSet;
|
this.sensorDataSet = sensorDataSet;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SensorDataSetLocation(String provider) {
|
public TrackPoint(String provider) {
|
||||||
super(provider);
|
super(provider);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,17 +45,8 @@ public class SensorDataSetLocation extends Location {
|
|||||||
this.sensorDataSet = sensorDataSet;
|
this.sensorDataSet = sensorDataSet;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(int id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void reset() {
|
public void reset() {
|
||||||
super.reset();
|
super.reset();
|
||||||
sensorDataSet = null;
|
sensorDataSet = null;
|
||||||
id = -1;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -14,11 +14,13 @@
|
|||||||
* the License.
|
* the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package de.dennisguse.opentracks.content;
|
package de.dennisguse.opentracks.content.data;
|
||||||
|
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.provider.BaseColumns;
|
import android.provider.BaseColumns;
|
||||||
|
|
||||||
|
import de.dennisguse.opentracks.content.ContentProviderUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constants for the track points table.
|
* Constants for the track points table.
|
||||||
*
|
*
|
||||||
@@ -14,11 +14,13 @@
|
|||||||
* the License.
|
* the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package de.dennisguse.opentracks.content;
|
package de.dennisguse.opentracks.content.data;
|
||||||
|
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.provider.BaseColumns;
|
import android.provider.BaseColumns;
|
||||||
|
|
||||||
|
import de.dennisguse.opentracks.content.ContentProviderUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constants for the tracks table.
|
* Constants for the tracks table.
|
||||||
*
|
*
|
||||||
@@ -36,22 +38,28 @@ public interface TracksColumns extends BaseColumns {
|
|||||||
String NAME = "name"; // track name
|
String NAME = "name"; // track name
|
||||||
String DESCRIPTION = "description"; // track description
|
String DESCRIPTION = "description"; // track description
|
||||||
String CATEGORY = "category"; // track activity type
|
String CATEGORY = "category"; // track activity type
|
||||||
String STARTID = "startid"; // first track point id
|
@Deprecated
|
||||||
String STOPID = "stopid"; // last track point id
|
String STARTID = "startid"; // first track point id // TODO UNUSED
|
||||||
|
@Deprecated
|
||||||
|
String STOPID = "stopid"; // last track point id // TODO UNUSED
|
||||||
String STARTTIME = "starttime"; // track start time
|
String STARTTIME = "starttime"; // track start time
|
||||||
String STOPTIME = "stoptime"; // track stop time
|
String STOPTIME = "stoptime"; // track stop time
|
||||||
String NUMPOINTS = "numpoints"; // number of track points
|
String NUMPOINTS = "numpoints"; // number of track points
|
||||||
String TOTALDISTANCE = "totaldistance"; // total distance
|
String TOTALDISTANCE = "totaldistance"; // total distance
|
||||||
String TOTALTIME = "totaltime"; // total time
|
String TOTALTIME = "totaltime"; // total time
|
||||||
String MOVINGTIME = "movingtime"; // moving time
|
String MOVINGTIME = "movingtime"; // moving time
|
||||||
String MINLAT = "minlat"; // minimum latitude
|
|
||||||
String MAXLAT = "maxlat"; // maximum latitude
|
|
||||||
String MINLON = "minlon"; // minimum longitude
|
|
||||||
String MAXLON = "maxlon"; // maximum longitude
|
|
||||||
String AVGSPEED = "avgspeed"; // average speed
|
|
||||||
|
|
||||||
// average moving speed
|
@Deprecated
|
||||||
String AVGMOVINGSPEED = "avgmovingspeed";
|
String MINLAT = "minlat"; // minimum latitude // TODO UNUSED
|
||||||
|
@Deprecated
|
||||||
|
String MAXLAT = "maxlat"; // maximum latitude // TODO UNUSED
|
||||||
|
@Deprecated
|
||||||
|
String MINLON = "minlon"; // minimum longitude //TODO UNUSED
|
||||||
|
@Deprecated
|
||||||
|
String MAXLON = "maxlon"; // maximum longitude //TODO UNUSED
|
||||||
|
|
||||||
|
String AVGSPEED = "avgspeed"; // average speed
|
||||||
|
String AVGMOVINGSPEED = "avgmovingspeed"; // average moving speed
|
||||||
String MAXSPEED = "maxspeed"; // maximum speed
|
String MAXSPEED = "maxspeed"; // maximum speed
|
||||||
String MINELEVATION = "minelevation"; // minimum elevation
|
String MINELEVATION = "minelevation"; // minimum elevation
|
||||||
String MAXELEVATION = "maxelevation"; // maximum elevation
|
String MAXELEVATION = "maxelevation"; // maximum elevation
|
||||||
@@ -14,13 +14,11 @@
|
|||||||
* the License.
|
* the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package de.dennisguse.opentracks.content;
|
package de.dennisguse.opentracks.content.data;
|
||||||
|
|
||||||
import android.location.Location;
|
import android.location.Location;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
|
||||||
import de.dennisguse.opentracks.stats.TripStatistics;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A waypoint.
|
* A waypoint.
|
||||||
*
|
*
|
||||||
@@ -35,31 +33,23 @@ public final class Waypoint {
|
|||||||
private String category = "";
|
private String category = "";
|
||||||
private String icon = "";
|
private String icon = "";
|
||||||
private long trackId = -1L;
|
private long trackId = -1L;
|
||||||
private WaypointType type = WaypointType.WAYPOINT;
|
|
||||||
private double length = 0.0;
|
private double length = 0.0;
|
||||||
private long duration = 0;
|
private long duration = 0;
|
||||||
private long startId = -1L;
|
|
||||||
private long stopId = -1L;
|
|
||||||
private Location location = null;
|
private Location location = null;
|
||||||
private TripStatistics tripStatistics = null;
|
|
||||||
private String photoUrl = "";
|
private String photoUrl = "";
|
||||||
|
|
||||||
public Waypoint() {
|
public Waypoint() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Waypoint(String name, String description, String category, String icon, long trackId, WaypointType type, double length, long duration, long startId, long stopId, Location location, TripStatistics tripStatistics, String photoUrl) {
|
public Waypoint(String name, String description, String category, String icon, long trackId, double length, long duration, Location location, String photoUrl) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.description = description;
|
this.description = description;
|
||||||
this.category = category;
|
this.category = category;
|
||||||
this.icon = icon;
|
this.icon = icon;
|
||||||
this.trackId = trackId;
|
this.trackId = trackId;
|
||||||
this.type = type;
|
|
||||||
this.length = length;
|
this.length = length;
|
||||||
this.duration = duration;
|
this.duration = duration;
|
||||||
this.startId = startId;
|
|
||||||
this.stopId = stopId;
|
|
||||||
this.location = location;
|
this.location = location;
|
||||||
this.tripStatistics = tripStatistics;
|
|
||||||
this.photoUrl = photoUrl;
|
this.photoUrl = photoUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -111,14 +101,6 @@ public final class Waypoint {
|
|||||||
this.trackId = trackId;
|
this.trackId = trackId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public WaypointType getType() {
|
|
||||||
return type;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setType(WaypointType type) {
|
|
||||||
this.type = type;
|
|
||||||
}
|
|
||||||
|
|
||||||
public double getLength() {
|
public double getLength() {
|
||||||
return length;
|
return length;
|
||||||
}
|
}
|
||||||
@@ -135,22 +117,6 @@ public final class Waypoint {
|
|||||||
this.duration = duration;
|
this.duration = duration;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getStartId() {
|
|
||||||
return startId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setStartId(long startId) {
|
|
||||||
this.startId = startId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getStopId() {
|
|
||||||
return stopId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setStopId(long stopId) {
|
|
||||||
this.stopId = stopId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Location getLocation() {
|
public Location getLocation() {
|
||||||
return location;
|
return location;
|
||||||
}
|
}
|
||||||
@@ -159,18 +125,6 @@ public final class Waypoint {
|
|||||||
this.location = location;
|
this.location = location;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isTripStatistics() {
|
|
||||||
return tripStatistics != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public TripStatistics getTripStatistics() {
|
|
||||||
return tripStatistics;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTripStatistics(TripStatistics tripStatistics) {
|
|
||||||
this.tripStatistics = tripStatistics;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getPhotoUrl() {
|
public String getPhotoUrl() {
|
||||||
return photoUrl;
|
return photoUrl;
|
||||||
}
|
}
|
||||||
@@ -186,8 +140,4 @@ public final class Waypoint {
|
|||||||
public boolean hasPhoto() {
|
public boolean hasPhoto() {
|
||||||
return photoUrl != null && !"".equals(photoUrl);
|
return photoUrl != null && !"".equals(photoUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum WaypointType {
|
|
||||||
WAYPOINT, STATISTICS
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -14,11 +14,13 @@
|
|||||||
* the License.
|
* the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package de.dennisguse.opentracks.content;
|
package de.dennisguse.opentracks.content.data;
|
||||||
|
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.provider.BaseColumns;
|
import android.provider.BaseColumns;
|
||||||
|
|
||||||
|
import de.dennisguse.opentracks.content.ContentProviderUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constants for waypoints table.
|
* Constants for waypoints table.
|
||||||
*
|
*
|
||||||
@@ -38,12 +40,16 @@ public interface WaypointsColumns extends BaseColumns {
|
|||||||
String CATEGORY = "category"; // waypoint category
|
String CATEGORY = "category"; // waypoint category
|
||||||
String ICON = "icon"; // waypoint icon
|
String ICON = "icon"; // waypoint icon
|
||||||
String TRACKID = "trackid"; // track id
|
String TRACKID = "trackid"; // track id
|
||||||
String TYPE = "type"; // type
|
@Deprecated
|
||||||
|
String TYPE = "type"; // type // TODO UNUSED
|
||||||
|
|
||||||
String LENGTH = "length"; // length of the track (without smoothing)
|
String LENGTH = "length"; // length of the track (without smoothing)
|
||||||
String DURATION = "duration"; // total duration of the track (not from last waypoint)
|
String DURATION = "duration"; // total duration of the track (not from last waypoint)
|
||||||
String STARTTIME = "starttime"; // start time of the trip statistics
|
String STARTTIME = "starttime"; // start time of the trip statistics
|
||||||
String STARTID = "startid"; // start track point id
|
@Deprecated
|
||||||
String STOPID = "stopid"; // stop track point id
|
String STARTID = "startid"; // start track point id // TODO UNUSED
|
||||||
|
@Deprecated
|
||||||
|
String STOPID = "stopid"; // stop track point id // TODO UNUSED
|
||||||
|
|
||||||
String LONGITUDE = "longitude"; // longitude
|
String LONGITUDE = "longitude"; // longitude
|
||||||
String LATITUDE = "latitude"; // latitude
|
String LATITUDE = "latitude"; // latitude
|
||||||
@@ -53,17 +59,29 @@ public interface WaypointsColumns extends BaseColumns {
|
|||||||
String SPEED = "speed"; // speed
|
String SPEED = "speed"; // speed
|
||||||
String BEARING = "bearing"; // bearing
|
String BEARING = "bearing"; // bearing
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
String TOTALDISTANCE = "totaldistance"; // total distance
|
String TOTALDISTANCE = "totaldistance"; // total distance
|
||||||
|
@Deprecated
|
||||||
String TOTALTIME = "totaltime"; // total time
|
String TOTALTIME = "totaltime"; // total time
|
||||||
|
@Deprecated
|
||||||
String MOVINGTIME = "movingtime"; // moving time
|
String MOVINGTIME = "movingtime"; // moving time
|
||||||
|
@Deprecated
|
||||||
String AVGSPEED = "avgspeed"; // average speed
|
String AVGSPEED = "avgspeed"; // average speed
|
||||||
String AVGMOVINGSPEED = "avgmovingspeed"; // average moving speed
|
|
||||||
String MAXSPEED = "maxspeed"; // max speed
|
@Deprecated
|
||||||
String MINELEVATION = "minelevation"; // min elevation
|
String AVGMOVINGSPEED = "avgmovingspeed"; // average moving speed // TODO UNUSED
|
||||||
String MAXELEVATION = "maxelevation"; // max elevation
|
@Deprecated
|
||||||
String ELEVATIONGAIN = "elevationgain"; // elevation gain
|
String MAXSPEED = "maxspeed"; // max speed // TODO UNUSED
|
||||||
String MINGRADE = "mingrade"; // min grade
|
@Deprecated
|
||||||
String MAXGRADE = "maxgrade"; // max grade
|
String MINELEVATION = "minelevation"; // min elevation // TODO UNUSED
|
||||||
|
@Deprecated
|
||||||
|
String MAXELEVATION = "maxelevation"; // max elevation // TODO UNUSED
|
||||||
|
@Deprecated
|
||||||
|
String ELEVATIONGAIN = "elevationgain"; // elevation gain // TODO UNUSED
|
||||||
|
@Deprecated
|
||||||
|
String MINGRADE = "mingrade"; // min grade // TODO UNUSED
|
||||||
|
@Deprecated
|
||||||
|
String MAXGRADE = "maxgrade"; // max grade // TODO UNUSED
|
||||||
|
|
||||||
String PHOTOURL = "photoUrl"; // url for the photo
|
String PHOTOURL = "photoUrl"; // url for the photo
|
||||||
|
|
||||||
@@ -4,9 +4,9 @@ public final class SensorDataSet {
|
|||||||
|
|
||||||
public static final float DATA_UNAVAILABLE = Float.NaN;
|
public static final float DATA_UNAVAILABLE = Float.NaN;
|
||||||
|
|
||||||
//TODO It might be necessary to consider: sensor if sensor was connected as well.
|
//TODO It might be necessary to consider: if sensor was connected as well.
|
||||||
public String sensorName;
|
private String sensorName;
|
||||||
public String sensorAddress;
|
private String sensorAddress;
|
||||||
private float heartRate;
|
private float heartRate;
|
||||||
private float cadence;
|
private float cadence;
|
||||||
private float power;
|
private float power;
|
||||||
@@ -40,7 +40,7 @@ public final class SensorDataSet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasHeartRate() {
|
public boolean hasHeartRate() {
|
||||||
return !Float.isNaN(heartRate);
|
return !Float.isNaN(heartRate) && heartRate > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getHeartRate() {
|
public float getHeartRate() {
|
||||||
|
|||||||