Compare commits
140 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 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 | |||
| 9bd4ba489c | |||
| dd55b50dad | |||
| 1719d21a5b | |||
| 75ef8d99d4 | |||
| ae06fd1680 | |||
| 2b03f7dea8 | |||
| 7591b012b4 | |||
| 0e089f49f3 | |||
| 5ad1856b13 | |||
| 965dbbe829 | |||
| 262c9886df | |||
| ac5a9ea65d | |||
| ed9b4c8f3d | |||
| 209aa6a8a5 | |||
| 81ee6ac1fa | |||
| 024dd603cb | |||
| 50654c6baf | |||
| 8c9bf60fc6 | |||
| a83eb0b983 | |||
| ab3cbfea0f | |||
| c93e5ca1a6 | |||
| c2841092da | |||
| 8b11e1d611 | |||
| 6375a851b2 |
@@ -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 +1,36 @@
|
|||||||
# OpenTrack: Developer information
|
# OpenTracks: Developer information
|
||||||
|
|
||||||
## Create releases for FDroid
|
## Craft new releases
|
||||||
|
|
||||||
1. Get next _version code_ (master branch): `git rev-list HEAD --count master`
|
1. Get next _version code_ (master branch): `git rev-list HEAD --count master`
|
||||||
2. Decide on _version name_ (semantic versioning)
|
2. Decide on _version name_ (semantic versioning)
|
||||||
3. Manually update _version code_ and _version name_ in `AndroidManifest.xml` (used by FDroid)
|
3. Manually update _version code_ and _version name_ in `AndroidManifest.xml` (used by FDroid)
|
||||||
4. Create changelog (`_version code_.txt`)
|
4. Create changelog (`_version code_.txt`)
|
||||||
5. Create commit with all changes
|
5. Create commit with all changes
|
||||||
6. Push commits
|
6. Tag newly create commit with _version name_ (e.g., v3.2.1)
|
||||||
7. Tag newly create commit with _version name_
|
7. Push commits and tags to public repository
|
||||||
8. Push the tagged 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. Update store meta data (e.g., description and screenshots)
|
||||||
|
`fastlane supply --version_code $(git rev-list HEAD --count master) --skip_upload_apk`
|
||||||
|
(requires API key)
|
||||||
|
2. Build signed apk
|
||||||
|
(requires keystore)
|
||||||
|
3. Upload signed apk to [Google Play Console](https://play.google.com/apps/publish)
|
||||||
|
|
||||||
|
## Translations (localization)
|
||||||
|
|
||||||
|
Translations of the OpenTracks are handled in Transifex: [https://www.transifex.com/opentracks](https://www.transifex.com/opentracks/).
|
||||||
@@ -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.
|
||||||
|
|
||||||
|
<table>
|
||||||
|
<tr>
|
||||||
|
<th>Free</th>
|
||||||
|
<th>Paid</th>
|
||||||
|
<th>Donations</th>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
<a href="https://f-droid.org/packages/de.dennisguse.opentracks">
|
<a href="https://f-droid.org/packages/de.dennisguse.opentracks">
|
||||||
<img src="https://fdroid.gitlab.io/artwork/badge/get-it-on.png" alt="Get it on F-Droid" height="60">
|
<img alt="Get it on F-Droid" src="https://fdroid.gitlab.io/artwork/badge/get-it-on.png" height="60" align="middle">
|
||||||
</a>
|
</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
|
||||||
|
|
||||||
|
|||||||
@@ -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.2'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -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
|
||||||
@@ -70,19 +74,21 @@ android {
|
|||||||
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 {
|
||||||
implementation 'androidx.appcompat:appcompat:1.1.0'
|
implementation 'androidx.appcompat:appcompat:1.1.0'
|
||||||
|
implementation 'androidx.preference:preference:1.1.0'
|
||||||
|
|
||||||
androidTestImplementation 'androidx.test:core:1.2.0'
|
androidTestImplementation 'androidx.test:core:1.2.0'
|
||||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
|
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
|
||||||
|
|||||||
@@ -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
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
OpenTracks – ein GPS-Tracker, der deine Daten für sich behält.
|
||||||
|
Erfasst deine Kilometer, ohne dass es jemand anderes tut.
|
||||||
|
|
||||||
|
Funktionen & Features:
|
||||||
|
* zeichnet Sport und andere Outdooraktivitäten auf
|
||||||
|
* unterstützt das Markieren interessanter Orte, inkl. Foto-Funktion
|
||||||
|
* zeichnet deine Herzfrequenz auf (unterstützt Bluetooth-LE-Sensoren)
|
||||||
|
* exportiert deine Daten als KML oder GPX
|
||||||
|
* funktioniert ganz ohne Internet
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
OpenTracks – ein GPS-Tracker, der deine Daten für sich behält.
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
v3.2: OpenTracks
|
v3.2.0: OpenTracks
|
||||||
|
|
||||||
Changes:
|
Changes:
|
||||||
- Removed Widget
|
- Removed Widget
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
v3.2.1: OpenTracks
|
||||||
|
|
||||||
|
Changes:
|
||||||
|
- Settings are now on a single page
|
||||||
|
|
||||||
|
Developer:
|
||||||
|
- Settings moved to Androidx compat (uses fragments)
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
v3.2.2: OpenTracks
|
||||||
|
|
||||||
|
Changes:
|
||||||
|
- Removed aggregated stats
|
||||||
|
- Migrated to Material Design
|
||||||
|
|
||||||
|
Bugfix:
|
||||||
|
- Fixed export of sensor data
|
||||||
|
- Fixed import of incomplete sensor data
|
||||||
|
|
||||||
|
Developer:
|
||||||
|
- Replaced actionbar with toolbar
|
||||||
|
- Migrated to androidx appcompat (incl. Material Design)
|
||||||
@@ -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)
|
||||||
@@ -3,6 +3,6 @@ OpenTracks is a sport tracking application that completely respects your privacy
|
|||||||
Features:
|
Features:
|
||||||
* Sport tracking: track your sport and outdoor activities
|
* Sport tracking: track your sport and outdoor activities
|
||||||
* Photos and markers: mark interesting locations while tracking
|
* Photos and markers: mark interesting locations while tracking
|
||||||
* Heart rate: supports bluetooth LE sensors
|
* Heart rate: supports Bluetooth LE sensors
|
||||||
* Export data: Export tracks either as KML or GPX
|
* Export data: export tracks either as KML or GPX
|
||||||
* No Internet access: Internet is not used
|
* No Internet access: Internet is not used
|
||||||
|
After Width: | Height: | Size: 16 KiB |
|
After Width: | Height: | Size: 52 KiB |
|
Before Width: | Height: | Size: 62 KiB After Width: | Height: | Size: 62 KiB |
|
Before Width: | Height: | Size: 129 KiB After Width: | Height: | Size: 129 KiB |
|
Before Width: | Height: | Size: 76 KiB After Width: | Height: | Size: 76 KiB |
|
Before Width: | Height: | Size: 85 KiB After Width: | Height: | Size: 85 KiB |
@@ -0,0 +1 @@
|
|||||||
|
OpenTracks
|
||||||
@@ -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 est une application de suivi d'activités sportives qui respecte totalement 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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -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}.
|
||||||
*
|
*
|
||||||
@@ -35,22 +35,19 @@ 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.ContentProviderUtils.LocationIterator;
|
|
||||||
import de.dennisguse.opentracks.content.Waypoint.WaypointType;
|
import de.dennisguse.opentracks.content.Waypoint.WaypointType;
|
||||||
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!";
|
||||||
@@ -70,13 +67,13 @@ public class CustomContentProviderUtilsImplTest {
|
|||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
providerUtils = ContentProviderUtils.Factory.get(context);
|
providerUtils = new ContentProviderUtils(context);
|
||||||
providerUtils.deleteAllTracks(context);
|
providerUtils.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,36 +103,36 @@ 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) providerUtils).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 = providerUtils.getTrackPointLocationIterator(trackId, -1L, descending, locationFactory)) {
|
||||||
while (it.hasNext()) {
|
while (it.hasNext()) {
|
||||||
@@ -174,7 +171,7 @@ public class CustomContentProviderUtilsImplTest {
|
|||||||
// 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 = providerUtils.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 +187,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() {
|
||||||
@@ -214,11 +211,10 @@ public class CustomContentProviderUtilsImplTest {
|
|||||||
Track track = providerUtils.createTrack(cursorMock);
|
Track track = providerUtils.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() {
|
||||||
@@ -247,7 +243,7 @@ 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() {
|
||||||
@@ -282,7 +278,7 @@ public class CustomContentProviderUtilsImplTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests the method {@link ContentProviderUtilsImpl#getAllTracks()}
|
* Tests the method {@link ContentProviderUtils#getAllTracks()}
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testGetAllTracks() {
|
public void testGetAllTracks() {
|
||||||
@@ -295,7 +291,7 @@ public class CustomContentProviderUtilsImplTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests the method {@link ContentProviderUtilsImpl#getLastTrack()}
|
* Tests the method {@link ContentProviderUtils#getLastTrack()}
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testGetLastTrack() {
|
public void testGetLastTrack() {
|
||||||
@@ -305,7 +301,7 @@ public class CustomContentProviderUtilsImplTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests the method {@link ContentProviderUtilsImpl#getTrack(long)}
|
* Tests the method {@link ContentProviderUtils#getTrack(long)}
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testGetTrack() {
|
public void testGetTrack() {
|
||||||
@@ -315,7 +311,7 @@ public class CustomContentProviderUtilsImplTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests the method {@link ContentProviderUtilsImpl#updateTrack(Track)}
|
* Tests the method {@link ContentProviderUtils#updateTrack(Track)}
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testUpdateTrack() {
|
public void testUpdateTrack() {
|
||||||
@@ -332,7 +328,7 @@ public class CustomContentProviderUtilsImplTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests the method {@link ContentProviderUtilsImpl#createContentValues(Waypoint)}.
|
* Tests the method {@link ContentProviderUtils#createContentValues(Waypoint)}.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testCreateContentValues_waypoint() {
|
public void testCreateContentValues_waypoint() {
|
||||||
@@ -370,7 +366,7 @@ public class CustomContentProviderUtilsImplTest {
|
|||||||
waypoint.setLocation(location);
|
waypoint.setLocation(location);
|
||||||
providerUtils.insertWaypoint(waypoint);
|
providerUtils.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);
|
||||||
@@ -383,7 +379,7 @@ public class CustomContentProviderUtilsImplTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests the method {@link ContentProviderUtilsImpl#createWaypoint(Cursor)}.
|
* Tests the method {@link ContentProviderUtils#createWaypoint(Cursor)}.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testCreateWaypoint() {
|
public void testCreateWaypoint() {
|
||||||
@@ -414,12 +410,11 @@ public class CustomContentProviderUtilsImplTest {
|
|||||||
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, DescriptionGenerator)}
|
||||||
* when there is only one waypoint in the track.
|
* when there is only one waypoint in the track.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
@@ -440,7 +435,7 @@ public class CustomContentProviderUtilsImplTest {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String generateWaypointDescription(TripStatistics tripStatistics) {
|
public String generateWaypointDescription(TripStatistics tripStatistics) {
|
||||||
return CustomContentProviderUtilsImplTest.MOCK_DESC;
|
return CustomContentProviderUtilsTest.MOCK_DESC;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -455,7 +450,7 @@ public class CustomContentProviderUtilsImplTest {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests the method
|
* Tests the method
|
||||||
* {@link ContentProviderUtilsImpl#deleteWaypoint(Context, long, DescriptionGenerator)}
|
* {@link ContentProviderUtils#deleteWaypoint(Context, long, DescriptionGenerator)}
|
||||||
* when there is more than one waypoint in the track.
|
* when there is more than one waypoint in the track.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
@@ -498,7 +493,7 @@ public class CustomContentProviderUtilsImplTest {
|
|||||||
DescriptionGenerator descriptionGenerator = new DescriptionGenerator() {
|
DescriptionGenerator descriptionGenerator = new DescriptionGenerator() {
|
||||||
@Override
|
@Override
|
||||||
public String generateWaypointDescription(TripStatistics tripStatistics) {
|
public String generateWaypointDescription(TripStatistics tripStatistics) {
|
||||||
return CustomContentProviderUtilsImplTest.MOCK_DESC;
|
return CustomContentProviderUtilsTest.MOCK_DESC;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -511,12 +506,12 @@ public class CustomContentProviderUtilsImplTest {
|
|||||||
providerUtils.deleteWaypoint(context, waypoint1Id, descriptionGenerator);
|
providerUtils.deleteWaypoint(context, waypoint1Id, descriptionGenerator);
|
||||||
Assert.assertNull(providerUtils.getWaypoint(waypoint1Id));
|
Assert.assertNull(providerUtils.getWaypoint(waypoint1Id));
|
||||||
|
|
||||||
Assert.assertEquals(CustomContentProviderUtilsImplTest.MOCK_DESC, providerUtils.getWaypoint(waypoint2Id)
|
Assert.assertEquals(CustomContentProviderUtilsTest.MOCK_DESC, providerUtils.getWaypoint(waypoint2Id)
|
||||||
.getDescription());
|
.getDescription());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests the method {@link ContentProviderUtilsImpl#getFirstWaypointId(long)}.
|
* Tests the method {@link ContentProviderUtils#getFirstWaypointId(long)}.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testGetFirstWaypointId() {
|
public void testGetFirstWaypointId() {
|
||||||
@@ -538,7 +533,7 @@ public class CustomContentProviderUtilsImplTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests the method {@link ContentProviderUtilsImpl#getNextWaypointNumber(long, WaypointType)}.
|
* Tests the method {@link ContentProviderUtils#getNextWaypointNumber(long, WaypointType)}.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testGetNextWaypointNumber() {
|
public void testGetNextWaypointNumber() {
|
||||||
@@ -597,8 +592,8 @@ public class CustomContentProviderUtilsImplTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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() {
|
||||||
@@ -615,7 +610,7 @@ public class CustomContentProviderUtilsImplTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests the method {@link ContentProviderUtilsImpl#updateWaypoint(Waypoint)}.
|
* Tests the method {@link ContentProviderUtils#updateWaypoint(Waypoint)}.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testUpdateWaypoint() {
|
public void testUpdateWaypoint() {
|
||||||
@@ -637,7 +632,7 @@ public class CustomContentProviderUtilsImplTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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() {
|
||||||
@@ -653,7 +648,7 @@ public class CustomContentProviderUtilsImplTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests the method {@link ContentProviderUtilsImpl#createTrackPoint(Cursor)}.
|
* Tests the method {@link ContentProviderUtils#createTrackPoint(Cursor)}.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testCreateTrackPoint() {
|
public void testCreateTrackPoint() {
|
||||||
@@ -709,12 +704,11 @@ public class CustomContentProviderUtilsImplTest {
|
|||||||
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() {
|
||||||
@@ -728,7 +722,7 @@ public class CustomContentProviderUtilsImplTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests the method {@link ContentProviderUtilsImpl#getFirstTrackPointId(long)}.
|
* Tests the method {@link ContentProviderUtils#getFirstTrackPointId(long)}.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testGetFirstTrackPointId() {
|
public void testGetFirstTrackPointId() {
|
||||||
@@ -741,7 +735,7 @@ public class CustomContentProviderUtilsImplTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests the method {@link ContentProviderUtilsImpl#getLastTrackPointId(long)}.
|
* Tests the method {@link ContentProviderUtils#getLastTrackPointId(long)}.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testGetLastTrackPointId() {
|
public void testGetLastTrackPointId() {
|
||||||
@@ -754,7 +748,7 @@ public class CustomContentProviderUtilsImplTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests the method {@link ContentProviderUtilsImpl#getLastValidTrackPoint(long)}.
|
* Tests the method {@link ContentProviderUtils#getLastValidTrackPoint(long)}.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testGetLastValidTrackPoint() {
|
public void testGetLastValidTrackPoint() {
|
||||||
@@ -768,7 +762,7 @@ public class CustomContentProviderUtilsImplTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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() {
|
||||||
@@ -787,7 +781,7 @@ public class CustomContentProviderUtilsImplTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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() {
|
||||||
@@ -806,7 +800,7 @@ public class CustomContentProviderUtilsImplTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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() {
|
||||||
@@ -822,7 +816,7 @@ public class CustomContentProviderUtilsImplTest {
|
|||||||
|
|
||||||
long startTrackPointId = trackpointIds[9];
|
long startTrackPointId = trackpointIds[9];
|
||||||
|
|
||||||
LocationIterator locationIterator = providerUtils.getTrackPointLocationIterator(trackId, startTrackPointId, true, ContentProviderUtils.DEFAULT_LOCATION_FACTORY);
|
LocationIterator locationIterator = providerUtils.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,7 +827,7 @@ 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() {
|
||||||
@@ -849,7 +843,7 @@ public class CustomContentProviderUtilsImplTest {
|
|||||||
|
|
||||||
long startTrackPointId = trackpointIds[0];
|
long startTrackPointId = trackpointIds[0];
|
||||||
|
|
||||||
LocationIterator locationIterator = providerUtils.getTrackPointLocationIterator(trackId, startTrackPointId, false, ContentProviderUtils.DEFAULT_LOCATION_FACTORY);
|
LocationIterator locationIterator = providerUtils.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();
|
||||||
@@ -896,7 +890,7 @@ public class CustomContentProviderUtilsImplTest {
|
|||||||
/**
|
/**
|
||||||
* 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 CustomContentProviderUtilsTest#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) {
|
||||||
@@ -58,7 +58,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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,17 +17,20 @@
|
|||||||
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.chart.ChartView;
|
||||||
import de.dennisguse.opentracks.content.SensorDataSetLocation;
|
import de.dennisguse.opentracks.content.SensorDataSetLocation;
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -112,7 +112,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);
|
||||||
|
|||||||
@@ -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.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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -199,7 +210,7 @@ public class GpxFileTrackImporterTest extends AbstractTestFileTrackImporter {
|
|||||||
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.getFirstTrackPointId(TRACK_ID_0)).thenReturn(TRACK_POINT_ID_0);
|
||||||
when(contentProviderUtils.getLastTrackPointId(TRACK_ID_0)).thenReturn(TRACK_POINT_ID_0);
|
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);
|
when(contentProviderUtils.getTrack(PreferencesUtils.getRecordingTrackId(context))).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.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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
||||||
@@ -74,17 +71,10 @@ public class TrackRecordingServiceTest {
|
|||||||
private Context context = ApplicationProvider.getApplicationContext();
|
private Context context = ApplicationProvider.getApplicationContext();
|
||||||
private ContentProviderUtils providerUtils;
|
private ContentProviderUtils providerUtils;
|
||||||
|
|
||||||
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,15 +84,12 @@ public class TrackRecordingServiceTest {
|
|||||||
};
|
};
|
||||||
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.
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
@@ -133,121 +120,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 = providerUtils.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 +148,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 +163,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 +186,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);
|
||||||
@@ -388,12 +238,12 @@ public class TrackRecordingServiceTest {
|
|||||||
@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 trackId = service.getRecordingTrackId();
|
||||||
long waypointId = service.insertWaypoint(WaypointCreationRequest.DEFAULT_WAYPOINT);
|
long waypointId = service.insertWaypoint(WaypointCreationRequest.DEFAULT_WAYPOINT);
|
||||||
Assert.assertNotEquals(-1L, waypointId);
|
Assert.assertNotEquals(-1L, waypointId);
|
||||||
Waypoint wpt = providerUtils.getWaypoint(waypointId);
|
Waypoint wpt = providerUtils.getWaypoint(waypointId);
|
||||||
@@ -404,46 +254,7 @@ public class TrackRecordingServiceTest {
|
|||||||
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());
|
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -68,15 +68,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 +100,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 +122,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 +136,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 +148,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 +165,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 +179,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 +203,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,9 +218,7 @@ 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);
|
|
||||||
} else if (i % 7 == 0) {
|
|
||||||
service.insertWaypoint(WaypointCreationRequest.DEFAULT_WAYPOINT);
|
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -60,10 +60,15 @@ public class FileUtilsTest extends TestCase {
|
|||||||
*/
|
*/
|
||||||
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));
|
assertEquals(expected, FileUtils.sanitizeFileName(name));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testSanitizeFileNameWithSuffix() {
|
||||||
|
String name = "FileName.jpeg";
|
||||||
|
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.
|
||||||
|
|||||||
@@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -149,8 +149,7 @@ public class StringUtilsTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests {@link StringUtils#getTime(String)} with fractional seconds and time
|
* Tests {@link StringUtils#getTime(String)} with fractional seconds and time zone.
|
||||||
* zone.
|
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testGetTime_fractionalAndTimezone() {
|
public void testGetTime_fractionalAndTimezone() {
|
||||||
@@ -183,7 +182,7 @@ public class StringUtilsTest {
|
|||||||
* Tests {@link StringUtils#getTimeParts(long)} with a positive number.
|
* Tests {@link StringUtils#getTimeParts(long)} with a positive number.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testGetTimeParts_postive() {
|
public void testGetTimeParts_positive() {
|
||||||
int[] parts = StringUtils.getTimeParts(61000);
|
int[] parts = StringUtils.getTimeParts(61000);
|
||||||
Assert.assertEquals(1, parts[0]);
|
Assert.assertEquals(1, parts[0]);
|
||||||
Assert.assertEquals(1, parts[1]);
|
Assert.assertEquals(1, parts[1]);
|
||||||
@@ -200,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,8 +16,8 @@ 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="3054"
|
android:versionCode="3195"
|
||||||
android:versionName="v3.2.0"> <!-- For FDroid. -->
|
android:versionName="v3.2.10"> <!-- For FDroid. -->
|
||||||
<!-- Permission to initialize services -->
|
<!-- Permission to initialize services -->
|
||||||
<application
|
<application
|
||||||
android:name=".Startup"
|
android:name=".Startup"
|
||||||
@@ -25,17 +25,18 @@ limitations under the License.
|
|||||||
android:hardwareAccelerated="true"
|
android:hardwareAccelerated="true"
|
||||||
android:icon="@drawable/ic_logo_color_24dp"
|
android:icon="@drawable/ic_logo_color_24dp"
|
||||||
android:label="@string/app_name"
|
android:label="@string/app_name"
|
||||||
|
android:requestLegacyExternalStorage="true"
|
||||||
android:theme="@style/ThemeCustom">
|
android:theme="@style/ThemeCustom">
|
||||||
|
|
||||||
<!-- Activities -->
|
<!-- Activities -->
|
||||||
<activity android:name=".AboutActivity" />
|
<activity android:name=".AboutActivity" />
|
||||||
|
|
||||||
<activity
|
|
||||||
android:name=".AggregatedStatsActivity"
|
|
||||||
android:label="@string/menu_aggregated_statistics" />
|
|
||||||
|
|
||||||
<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">
|
||||||
@@ -54,10 +55,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">
|
||||||
@@ -97,13 +98,8 @@ limitations under the License.
|
|||||||
android:name=".io.file.exporter.ExportActivity"
|
android:name=".io.file.exporter.ExportActivity"
|
||||||
android:theme="@style/ThemeCustomTransparent" />
|
android:theme="@style/ThemeCustomTransparent" />
|
||||||
|
|
||||||
<activity android:name=".settings.RecordingSettingsActivity" />
|
|
||||||
|
|
||||||
<activity android:name=".settings.SettingsActivity" />
|
<activity android:name=".settings.SettingsActivity" />
|
||||||
|
|
||||||
<activity android:name=".settings.StatsSettingsActivity" />
|
|
||||||
|
|
||||||
<!-- Services -->
|
|
||||||
<provider
|
<provider
|
||||||
android:name=".content.ShareContentProvider"
|
android:name=".content.ShareContentProvider"
|
||||||
android:authorities="${applicationId}.content"
|
android:authorities="${applicationId}.content"
|
||||||
@@ -120,19 +116,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>
|
||||||
@@ -147,44 +135,23 @@ 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.READ_EXTERNAL_STORAGE" />
|
||||||
|
|
||||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||||
</manifest>
|
</manifest>
|
||||||
|
|||||||
@@ -17,23 +17,28 @@
|
|||||||
package de.dennisguse.opentracks;
|
package de.dennisguse.opentracks;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.speech.tts.TextToSpeech;
|
|
||||||
|
|
||||||
import androidx.fragment.app.FragmentActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
import androidx.appcompat.widget.Toolbar;
|
||||||
|
|
||||||
|
import de.dennisguse.opentracks.util.TTSUtils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Jimmy Shih
|
* @author Jimmy Shih
|
||||||
*/
|
*/
|
||||||
public abstract class AbstractActivity extends FragmentActivity {
|
public abstract class AbstractActivity extends AppCompatActivity {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
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());
|
||||||
|
|
||||||
|
Toolbar toolbar = findViewById(R.id.toolbar);
|
||||||
|
setSupportActionBar(toolbar);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -16,24 +16,7 @@
|
|||||||
|
|
||||||
package de.dennisguse.opentracks;
|
package de.dennisguse.opentracks;
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.app.SearchManager;
|
|
||||||
import android.content.ComponentName;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.util.Log;
|
|
||||||
import android.util.SparseBooleanArray;
|
|
||||||
import android.view.ActionMode;
|
|
||||||
import android.view.Menu;
|
|
||||||
import android.view.MenuItem;
|
|
||||||
import android.view.View;
|
|
||||||
import android.widget.AbsListView;
|
|
||||||
import android.widget.ListView;
|
|
||||||
import android.widget.SearchView;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
import de.dennisguse.opentracks.fragments.ConfirmDeleteDialogFragment;
|
import de.dennisguse.opentracks.fragments.ConfirmDeleteDialogFragment;
|
||||||
import de.dennisguse.opentracks.fragments.ConfirmDeleteDialogFragment.ConfirmDeleteCaller;
|
import de.dennisguse.opentracks.fragments.ConfirmDeleteDialogFragment.ConfirmDeleteCaller;
|
||||||
@@ -58,115 +41,6 @@ public abstract class AbstractListActivity extends AbstractActivity implements C
|
|||||||
protected static final int GPS_REQUEST_CODE = 6;
|
protected static final int GPS_REQUEST_CODE = 6;
|
||||||
private static final int DELETE_REQUEST_CODE = 3;
|
private static final int DELETE_REQUEST_CODE = 3;
|
||||||
|
|
||||||
public static void configureListViewContextualMenu(final ListView listView, final ContextualActionModeCallback contextualActionModeCallback) {
|
|
||||||
listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
|
|
||||||
listView.setMultiChoiceModeListener(new AbsListView.MultiChoiceModeListener() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
|
|
||||||
mode.getMenuInflater().inflate(R.menu.list_context_menu, menu);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
|
|
||||||
contextualActionModeCallback.onPrepare(menu, getCheckedPositions(listView), listView.getCheckedItemIds(), true);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDestroyActionMode(ActionMode mode) {
|
|
||||||
// Do nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) {
|
|
||||||
mode.invalidate();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
|
|
||||||
if (contextualActionModeCallback.onClick(item.getItemId(), getCheckedPositions(listView), listView.getCheckedItemIds())) {
|
|
||||||
mode.finish();
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the checked positions in a list view.
|
|
||||||
*
|
|
||||||
* @param list the list view
|
|
||||||
*/
|
|
||||||
private int[] getCheckedPositions(ListView list) {
|
|
||||||
SparseBooleanArray positions = list.getCheckedItemPositions();
|
|
||||||
ArrayList<Integer> arrayList = new ArrayList<>();
|
|
||||||
for (int i = 0; i < positions.size(); i++) {
|
|
||||||
int key = positions.keyAt(i);
|
|
||||||
if (positions.valueAt(i)) {
|
|
||||||
arrayList.add(key);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
int[] result = new int[arrayList.size()];
|
|
||||||
for (int i = 0; i < arrayList.size(); i++) {
|
|
||||||
result[i] = arrayList.get(i);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void configureSearchWidget(Activity activity, final MenuItem menuItem, final TrackController trackController) {
|
|
||||||
final SearchView searchView = (SearchView) menuItem.getActionView();
|
|
||||||
SearchManager searchManager = (SearchManager) activity.getSystemService(Context.SEARCH_SERVICE);
|
|
||||||
if (searchManager != null) {
|
|
||||||
//NOTE: for some reason activity.getComponentName() did not trigger the SearchListActivity
|
|
||||||
searchView.setSearchableInfo(searchManager.getSearchableInfo(new ComponentName(activity, SearchListActivity.class)));
|
|
||||||
} else {
|
|
||||||
Log.w(TAG, "Could not retrieve SearchManager.");
|
|
||||||
}
|
|
||||||
searchView.setQueryRefinementEnabled(true);
|
|
||||||
searchView.setSubmitButtonEnabled(true);
|
|
||||||
searchView.setOnQueryTextFocusChangeListener(new View.OnFocusChangeListener() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onFocusChange(View v, boolean hasFocus) {
|
|
||||||
// Hide and show trackController when searchable widget has focus/no focus
|
|
||||||
if (trackController != null) {
|
|
||||||
if (hasFocus) {
|
|
||||||
trackController.hide();
|
|
||||||
} else {
|
|
||||||
trackController.show();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
|
|
||||||
@Override
|
|
||||||
public boolean onQueryTextSubmit(String query) {
|
|
||||||
menuItem.collapseActionView();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onQueryTextChange(String newText) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
searchView.setOnSuggestionListener(new SearchView.OnSuggestionListener() {
|
|
||||||
@Override
|
|
||||||
public boolean onSuggestionSelect(int position) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onSuggestionClick(int position) {
|
|
||||||
menuItem.collapseActionView();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
if (requestCode == DELETE_REQUEST_CODE) {
|
if (requestCode == DELETE_REQUEST_CODE) {
|
||||||
@@ -182,8 +56,7 @@ public abstract class AbstractListActivity extends AbstractActivity implements C
|
|||||||
* @param trackIds the track ids
|
* @param trackIds the track ids
|
||||||
*/
|
*/
|
||||||
protected void deleteTracks(long[] trackIds) {
|
protected void deleteTracks(long[] trackIds) {
|
||||||
ConfirmDeleteDialogFragment.newInstance(trackIds)
|
ConfirmDeleteDialogFragment.showDialog(getSupportFragmentManager(), trackIds);
|
||||||
.show(getSupportFragmentManager(), ConfirmDeleteDialogFragment.CONFIRM_DELETE_DIALOG_TAG);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -192,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;
|
||||||
@@ -209,10 +82,9 @@ public abstract class AbstractListActivity extends AbstractActivity implements C
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the track recording service connection. For stopping the current
|
* Gets the track recording service connection.
|
||||||
* recording if need to delete the current recording track.
|
* For stopping the current recording if need to delete the current recording track.
|
||||||
*/
|
*/
|
||||||
@NonNull
|
|
||||||
abstract protected TrackRecordingServiceConnection getTrackRecordingServiceConnection();
|
abstract protected TrackRecordingServiceConnection getTrackRecordingServiceConnection();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,62 +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.os.Bundle;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import de.dennisguse.opentracks.content.ContentProviderUtils;
|
|
||||||
import de.dennisguse.opentracks.content.Track;
|
|
||||||
import de.dennisguse.opentracks.stats.TripStatistics;
|
|
||||||
import de.dennisguse.opentracks.util.StatsUtils;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* An activity to view aggregated stats from all recorded tracks.
|
|
||||||
*
|
|
||||||
* @author Fergus Nelson
|
|
||||||
*/
|
|
||||||
public class AggregatedStatsActivity extends AbstractActivity {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
StatsUtils.setTripStatisticsValues(this, getTripStatistics(), null);
|
|
||||||
StatsUtils.setLocationValues(this, null, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected int getLayoutResId() {
|
|
||||||
return R.layout.stats;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the aggregated trip statistics for all the recorded tracks or null if
|
|
||||||
* there is no track.
|
|
||||||
*/
|
|
||||||
private TripStatistics getTripStatistics() {
|
|
||||||
List<Track> tracks = ContentProviderUtils.Factory.get(this).getAllTracks();
|
|
||||||
TripStatistics tripStatistics = null;
|
|
||||||
if (!tracks.isEmpty()) {
|
|
||||||
tripStatistics = new TripStatistics(tracks.iterator().next().getTripStatistics());
|
|
||||||
for (int i = 1; i < tracks.size(); i++) {
|
|
||||||
tripStatistics.merge(tracks.get(i).getTripStatistics());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return tripStatistics;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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,8 +71,7 @@ public class MarkerEditActivity extends AbstractActivity {
|
|||||||
waypointSection = findViewById(R.id.marker_edit_waypoint_section);
|
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);
|
||||||
|
|
||||||
@@ -127,7 +126,7 @@ public class MarkerEditActivity extends AbstractActivity {
|
|||||||
if (newMarker) {
|
if (newMarker) {
|
||||||
statisticsSection.setVisibility(View.GONE);
|
statisticsSection.setVisibility(View.GONE);
|
||||||
waypointSection.setVisibility(View.VISIBLE);
|
waypointSection.setVisibility(View.VISIBLE);
|
||||||
int nextWaypointNumber = trackId == -1L ? -1 : ContentProviderUtils.Factory.get(this).getNextWaypointNumber(trackId, WaypointType.WAYPOINT);
|
int nextWaypointNumber = trackId == -1L ? -1 : new ContentProviderUtils(this).getNextWaypointNumber(trackId, WaypointType.WAYPOINT);
|
||||||
if (nextWaypointNumber == -1) {
|
if (nextWaypointNumber == -1) {
|
||||||
nextWaypointNumber = 0;
|
nextWaypointNumber = 0;
|
||||||
}
|
}
|
||||||
@@ -136,7 +135,7 @@ 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();
|
||||||
@@ -182,6 +181,6 @@ public class MarkerEditActivity extends AbstractActivity {
|
|||||||
waypoint.setCategory(waypointMarkerType.getText().toString());
|
waypoint.setCategory(waypointMarkerType.getText().toString());
|
||||||
waypoint.setDescription(waypointDescription.getText().toString());
|
waypoint.setDescription(waypointDescription.getText().toString());
|
||||||
}
|
}
|
||||||
ContentProviderUtils.Factory.get(this).updateWaypoint(waypoint);
|
new ContentProviderUtils(this).updateWaypoint(waypoint);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,14 +22,11 @@ import android.content.SharedPreferences;
|
|||||||
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
|
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.ContextMenu;
|
|
||||||
import android.view.ContextMenu.ContextMenuInfo;
|
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.AdapterView;
|
import android.widget.AdapterView;
|
||||||
import android.widget.AdapterView.AdapterContextMenuInfo;
|
|
||||||
import android.widget.AdapterView.OnItemClickListener;
|
import android.widget.AdapterView.OnItemClickListener;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
|
|
||||||
@@ -42,12 +39,13 @@ 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.Track;
|
||||||
import de.dennisguse.opentracks.content.Waypoint.WaypointType;
|
|
||||||
import de.dennisguse.opentracks.content.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.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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -71,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() {
|
||||||
@@ -130,7 +127,9 @@ public class MarkerListActivity extends AbstractActivity implements DeleteMarker
|
|||||||
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);
|
||||||
|
|
||||||
long trackId = getIntent().getLongExtra(EXTRA_TRACK_ID, -1L);
|
long trackId = getIntent().getLongExtra(EXTRA_TRACK_ID, -1L);
|
||||||
@@ -152,7 +151,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);
|
||||||
@@ -161,13 +159,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);
|
||||||
|
|
||||||
@@ -175,7 +173,7 @@ public class MarkerListActivity extends AbstractActivity implements DeleteMarker
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
listView.setAdapter(resourceCursorAdapter);
|
listView.setAdapter(resourceCursorAdapter);
|
||||||
AbstractListActivity.configureListViewContextualMenu(listView, contextualActionModeCallback);
|
ActivityUtils.configureListViewContextualMenu(listView, contextualActionModeCallback);
|
||||||
|
|
||||||
LoaderManager.getInstance(this).initLoader(0, null, new LoaderCallbacks<Cursor>() {
|
LoaderManager.getInstance(this).initLoader(0, null, new LoaderCallbacks<Cursor>() {
|
||||||
@NonNull
|
@NonNull
|
||||||
@@ -234,7 +232,7 @@ public class MarkerListActivity extends AbstractActivity implements DeleteMarker
|
|||||||
insertMarkerMenuItem = menu.findItem(R.id.marker_list_insert_marker);
|
insertMarkerMenuItem = menu.findItem(R.id.marker_list_insert_marker);
|
||||||
|
|
||||||
searchMenuItem = menu.findItem(R.id.marker_list_search);
|
searchMenuItem = menu.findItem(R.id.marker_list_search);
|
||||||
AbstractListActivity.configureSearchWidget(this, searchMenuItem, null);
|
ActivityUtils.configureSearchWidget(this, searchMenuItem, null);
|
||||||
|
|
||||||
return super.onCreateOptionsMenu(menu);
|
return super.onCreateOptionsMenu(menu);
|
||||||
}
|
}
|
||||||
@@ -246,7 +244,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());
|
||||||
@@ -256,24 +254,6 @@ public class MarkerListActivity extends AbstractActivity implements DeleteMarker
|
|||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
|
|
||||||
super.onCreateContextMenu(menu, v, menuInfo);
|
|
||||||
getMenuInflater().inflate(R.menu.list_context_menu, menu);
|
|
||||||
|
|
||||||
AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
|
|
||||||
contextualActionModeCallback.onPrepare(menu, new int[]{info.position}, new long[]{info.id}, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onContextItemSelected(MenuItem item) {
|
|
||||||
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
|
|
||||||
if (handleContextItem(item.getItemId(), new long[]{info.id})) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return super.onContextItemSelected(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles a context item selection.
|
* Handles a context item selection.
|
||||||
*
|
*
|
||||||
@@ -300,8 +280,7 @@ public class MarkerListActivity extends AbstractActivity implements DeleteMarker
|
|||||||
if (markerIds.length > 1 && markerIds.length == listView.getCount()) {
|
if (markerIds.length > 1 && markerIds.length == listView.getCount()) {
|
||||||
markerIds = new long[]{-1L};
|
markerIds = new long[]{-1L};
|
||||||
}
|
}
|
||||||
DeleteMarkerDialogFragment.newInstance(markerIds)
|
DeleteMarkerDialogFragment.showDialog(getSupportFragmentManager(), markerIds);
|
||||||
.show(getSupportFragmentManager(), DeleteMarkerDialogFragment.DELETE_MARKER_DIALOG_TAG);
|
|
||||||
return true;
|
return true;
|
||||||
case R.id.list_context_menu_select_all:
|
case R.id.list_context_menu_select_all:
|
||||||
int size = listView.getCount();
|
int size = listView.getCount();
|
||||||
|
|||||||
@@ -22,14 +22,11 @@ import android.content.SharedPreferences;
|
|||||||
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
|
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.ContextMenu;
|
|
||||||
import android.view.ContextMenu.ContextMenuInfo;
|
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.AdapterView;
|
import android.widget.AdapterView;
|
||||||
import android.widget.AdapterView.AdapterContextMenuInfo;
|
|
||||||
import android.widget.AdapterView.OnItemClickListener;
|
import android.widget.AdapterView.OnItemClickListener;
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
@@ -49,14 +46,15 @@ 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.Track;
|
||||||
import de.dennisguse.opentracks.content.Waypoint;
|
import de.dennisguse.opentracks.content.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;
|
||||||
import de.dennisguse.opentracks.services.TrackRecordingServiceConnection;
|
import de.dennisguse.opentracks.services.TrackRecordingServiceConnection;
|
||||||
import de.dennisguse.opentracks.stats.TripStatistics;
|
import de.dennisguse.opentracks.stats.TripStatistics;
|
||||||
|
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.TrackIconUtils;
|
import de.dennisguse.opentracks.util.TrackIconUtils;
|
||||||
@@ -103,34 +101,35 @@ 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() {
|
||||||
@Override
|
@Override
|
||||||
public void onPrepare(Menu menu, int[] positions, long[] ids, boolean showSelectAll) {
|
public void onPrepare(Menu menu, int[] positions, long[] ids, boolean showSelectAll) {
|
||||||
boolean isRecording = recordingTrackId != PreferencesUtils.RECORDING_TRACK_ID_DEFAULT;
|
boolean isRecording = PreferencesUtils.isRecording(recordingTrackId);
|
||||||
boolean isSingleSelection = positions.length == 1;
|
boolean isSingleSelection = positions.length == 1;
|
||||||
|
|
||||||
boolean isSingleSelectionTrack;
|
boolean isSingleSelectionTrack;
|
||||||
if (isSingleSelection) {
|
if (isSingleSelection) {
|
||||||
Map<String, Object> item = arrayAdapter.getItem(positions[0]);
|
Map<String, Object> item = arrayAdapter.getItem(positions[0]);
|
||||||
Long trackId = (Long) item.get(TRACK_ID_FIELD);
|
|
||||||
Track track = contentProviderUtils.getTrack(trackId);
|
|
||||||
|
|
||||||
isSingleSelectionTrack = item.get(MARKER_ID_FIELD) == null;
|
isSingleSelectionTrack = item.get(MARKER_ID_FIELD) == null;
|
||||||
} else {
|
} else {
|
||||||
isSingleSelectionTrack = false;
|
isSingleSelectionTrack = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Not recording, one item, item is a track
|
// Not recording, one item, item is a track
|
||||||
menu.findItem(R.id.list_context_menu_share).setVisible(!isRecording && isSingleSelection && isSingleSelectionTrack);
|
MenuItem shareMenuItem = menu.findItem(R.id.list_context_menu_share);
|
||||||
//TODO Setup shareIntent.
|
if (isSingleSelectionTrack) {
|
||||||
|
shareMenuItem.setVisible(!isRecording);
|
||||||
|
}
|
||||||
|
|
||||||
// One item, item is a marker
|
// One item, item is a marker
|
||||||
menu.findItem(R.id.list_context_menu_show_on_map).setVisible(isSingleSelection && !isSingleSelectionTrack);
|
menu.findItem(R.id.list_context_menu_show_on_map).setVisible(isSingleSelection && !isSingleSelectionTrack);
|
||||||
// One item, can be a track or a marker
|
// One item, can be a track or a marker
|
||||||
menu.findItem(R.id.list_context_menu_edit).setVisible(isSingleSelection);
|
menu.findItem(R.id.list_context_menu_edit).setVisible(isSingleSelection);
|
||||||
// One item. If track, no restriction.
|
// One item. If track, no restriction.
|
||||||
menu.findItem(R.id.list_context_menu_delete).setVisible(isSingleSelection && (isSingleSelectionTrack));
|
menu.findItem(R.id.list_context_menu_delete).setVisible(isSingleSelection && isSingleSelectionTrack);
|
||||||
// Disable select all, no action is available for multiple selection
|
// Disable select all, no action is available for multiple selection
|
||||||
menu.findItem(R.id.list_context_menu_select_all).setVisible(false);
|
menu.findItem(R.id.list_context_menu_select_all).setVisible(false);
|
||||||
}
|
}
|
||||||
@@ -144,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() {
|
||||||
@@ -169,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);
|
||||||
@@ -222,7 +223,7 @@ public class SearchListActivity extends AbstractListActivity implements DeleteMa
|
|||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
AbstractListActivity.configureListViewContextualMenu(listView, contextualActionModeCallback);
|
ActivityUtils.configureListViewContextualMenu(listView, contextualActionModeCallback);
|
||||||
handleIntent(getIntent());
|
handleIntent(getIntent());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -259,24 +260,6 @@ public class SearchListActivity extends AbstractListActivity implements DeleteMa
|
|||||||
handleIntent(intent);
|
handleIntent(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
|
|
||||||
super.onCreateContextMenu(menu, v, menuInfo);
|
|
||||||
getMenuInflater().inflate(R.menu.list_context_menu, menu);
|
|
||||||
|
|
||||||
AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
|
|
||||||
contextualActionModeCallback.onPrepare(menu, new int[]{info.position}, new long[]{info.id}, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onContextItemSelected(MenuItem item) {
|
|
||||||
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
|
|
||||||
if (handleContextItem(item.getItemId(), new int[]{info.position})) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return super.onContextItemSelected(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onKeyUp(int keyCode, KeyEvent event) {
|
public boolean onKeyUp(int keyCode, KeyEvent event) {
|
||||||
if (keyCode == KeyEvent.KEYCODE_SEARCH) {
|
if (keyCode == KeyEvent.KEYCODE_SEARCH) {
|
||||||
@@ -301,13 +284,14 @@ public class SearchListActivity extends AbstractListActivity implements DeleteMa
|
|||||||
Long markerId = (Long) item.get(MARKER_ID_FIELD);
|
Long markerId = (Long) item.get(MARKER_ID_FIELD);
|
||||||
Intent intent;
|
Intent intent;
|
||||||
switch (itemId) {
|
switch (itemId) {
|
||||||
case R.id.list_context_menu_share:
|
|
||||||
//TODO
|
|
||||||
Log.e(TAG, "Not implemented");
|
|
||||||
return true;
|
|
||||||
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)
|
||||||
@@ -323,7 +307,7 @@ public class SearchListActivity extends AbstractListActivity implements DeleteMa
|
|||||||
return true;
|
return true;
|
||||||
case R.id.list_context_menu_delete:
|
case R.id.list_context_menu_delete:
|
||||||
if (markerId != null) {
|
if (markerId != null) {
|
||||||
DeleteMarkerDialogFragment.newInstance(new long[]{markerId}).show(getSupportFragmentManager(), DeleteMarkerDialogFragment.DELETE_MARKER_DIALOG_TAG);
|
DeleteMarkerDialogFragment.showDialog(getSupportFragmentManager(), new long[]{markerId});
|
||||||
} else {
|
} else {
|
||||||
deleteTracks(new long[]{trackId});
|
deleteTracks(new long[]{trackId});
|
||||||
}
|
}
|
||||||
@@ -409,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
|
||||||
@@ -421,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());
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import android.widget.TabHost;
|
|||||||
import android.widget.TabHost.TabContentFactory;
|
import android.widget.TabHost.TabContentFactory;
|
||||||
import android.widget.TabWidget;
|
import android.widget.TabWidget;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
import androidx.fragment.app.FragmentActivity;
|
import androidx.fragment.app.FragmentActivity;
|
||||||
import androidx.fragment.app.FragmentPagerAdapter;
|
import androidx.fragment.app.FragmentPagerAdapter;
|
||||||
@@ -79,6 +80,7 @@ public class TabsAdapter extends FragmentPagerAdapter implements TabHost.OnTabCh
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@NonNull
|
||||||
public Fragment getItem(int position) {
|
public Fragment getItem(int position) {
|
||||||
TabInfo info = tabInfos.get(position);
|
TabInfo info = tabInfos.get(position);
|
||||||
return Fragment.instantiate(context, info.clss.getName(), info.bundle);
|
return Fragment.instantiate(context, info.clss.getName(), info.bundle);
|
||||||
|
|||||||
@@ -130,11 +130,11 @@ public class TrackController {
|
|||||||
handlerUpdateTotalTime.removeCallbacks(updateTotalTimeRunnable);
|
handlerUpdateTotalTime.removeCallbacks(updateTotalTimeRunnable);
|
||||||
}
|
}
|
||||||
|
|
||||||
void hide() {
|
public void hide() {
|
||||||
containerView.setVisibility(View.GONE);
|
containerView.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void show() {
|
public void show() {
|
||||||
containerView.setVisibility(View.VISIBLE);
|
containerView.setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,7 +31,6 @@ 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.ShareActionProvider;
|
|
||||||
import android.widget.TabHost;
|
import android.widget.TabHost;
|
||||||
import android.widget.TabHost.TabSpec;
|
import android.widget.TabHost.TabSpec;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
@@ -46,11 +45,10 @@ import de.dennisguse.opentracks.content.TrackDataHub;
|
|||||||
import de.dennisguse.opentracks.content.Waypoint;
|
import de.dennisguse.opentracks.content.Waypoint;
|
||||||
import de.dennisguse.opentracks.content.Waypoint.WaypointType;
|
import de.dennisguse.opentracks.content.Waypoint.WaypointType;
|
||||||
import de.dennisguse.opentracks.content.WaypointCreationRequest;
|
import de.dennisguse.opentracks.content.WaypointCreationRequest;
|
||||||
import de.dennisguse.opentracks.fragments.ChartFragment;
|
import de.dennisguse.opentracks.fragments.ChartDistanceFragment;
|
||||||
|
import de.dennisguse.opentracks.fragments.ChartTimeFragment;
|
||||||
import de.dennisguse.opentracks.fragments.ChooseActivityTypeDialogFragment;
|
import de.dennisguse.opentracks.fragments.ChooseActivityTypeDialogFragment;
|
||||||
import de.dennisguse.opentracks.fragments.ChooseActivityTypeDialogFragment.ChooseActivityTypeCaller;
|
|
||||||
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;
|
||||||
@@ -66,7 +64,7 @@ import de.dennisguse.opentracks.util.TrackUtils;
|
|||||||
* @author Leif Hendrik Wilden
|
* @author Leif Hendrik Wilden
|
||||||
* @author Rodrigo Damazio
|
* @author Rodrigo Damazio
|
||||||
*/
|
*/
|
||||||
public class TrackDetailActivity extends AbstractListActivity implements ChooseActivityTypeCaller, ConfirmDeleteDialogFragment.ConfirmDeleteCaller {
|
public class TrackDetailActivity extends AbstractListActivity implements ChooseActivityTypeDialogFragment.ChooseActivityTypeCaller, ConfirmDeleteDialogFragment.ConfirmDeleteCaller {
|
||||||
|
|
||||||
public static final String EXTRA_TRACK_ID = "track_id";
|
public static final String EXTRA_TRACK_ID = "track_id";
|
||||||
public static final String EXTRA_MARKER_ID = "marker_id";
|
public static final String EXTRA_MARKER_ID = "marker_id";
|
||||||
@@ -96,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
|
||||||
@@ -120,25 +117,29 @@ public class TrackDetailActivity extends AbstractListActivity implements ChooseA
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
/*
|
|
||||||
* 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;
|
||||||
@@ -158,8 +159,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
|
||||||
@@ -189,11 +188,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);
|
||||||
@@ -210,8 +211,11 @@ public class TrackDetailActivity extends AbstractListActivity implements ChooseA
|
|||||||
TabSpec statsTabSpec = tabHost.newTabSpec(StatsFragment.STATS_FRAGMENT_TAG).setIndicator(getString(R.string.track_detail_stats_tab));
|
TabSpec statsTabSpec = tabHost.newTabSpec(StatsFragment.STATS_FRAGMENT_TAG).setIndicator(getString(R.string.track_detail_stats_tab));
|
||||||
tabsAdapter.addTab(statsTabSpec, StatsFragment.class, null);
|
tabsAdapter.addTab(statsTabSpec, StatsFragment.class, null);
|
||||||
|
|
||||||
TabSpec chartTabSpec = tabHost.newTabSpec(ChartFragment.CHART_FRAGMENT_TAG).setIndicator(getString(R.string.track_detail_chart_tab));
|
TabSpec chartTimeTabSpec = tabHost.newTabSpec(ChartTimeFragment.CHART_FRAGMENT_TAG).setIndicator(getString(R.string.settings_chart_by_time));
|
||||||
tabsAdapter.addTab(chartTabSpec, ChartFragment.class, null);
|
tabsAdapter.addTab(chartTimeTabSpec, ChartTimeFragment.class, null);
|
||||||
|
|
||||||
|
TabSpec chartDistanceTabSpec = tabHost.newTabSpec(ChartDistanceFragment.CHART_FRAGMENT_TAG).setIndicator(getString(R.string.settings_chart_by_distance));
|
||||||
|
tabsAdapter.addTab(chartDistanceTabSpec, ChartDistanceFragment.class, null);
|
||||||
|
|
||||||
if (savedInstanceState != null) {
|
if (savedInstanceState != null) {
|
||||||
tabHost.setCurrentTabByTag(savedInstanceState.getString(CURRENT_TAB_TAG_KEY));
|
tabHost.setCurrentTabByTag(savedInstanceState.getString(CURRENT_TAB_TAG_KEY));
|
||||||
@@ -228,16 +232,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 {
|
} else if (showOnLockScreen) {
|
||||||
if (showOnLockScreen)
|
|
||||||
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
|
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
|
||||||
else getWindow().clearFlags(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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -277,7 +296,7 @@ public class TrackDetailActivity extends AbstractListActivity implements ChooseA
|
|||||||
}
|
}
|
||||||
|
|
||||||
@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.putString(CURRENT_TAB_TAG_KEY, tabHost.getCurrentTabTag());
|
||||||
if (photoUri != null) {
|
if (photoUri != null) {
|
||||||
@@ -317,13 +336,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);
|
||||||
ShareActionProvider shareActionProvider = (ShareActionProvider) shareMenuItem.getActionProvider();
|
|
||||||
shareActionProvider.setShareIntent(IntentUtils.newShareFileIntent(this, 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);
|
||||||
@@ -345,6 +358,11 @@ 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) {
|
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);
|
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, EXTERNAL_STORAGE_PERMISSION_REQUEST_CODE);
|
||||||
@@ -360,14 +378,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.newInstance(R.string.voice_frequency_key, PreferencesUtils.VOICE_FREQUENCY_DEFAULT, R.string.menu_voice_frequency)
|
|
||||||
.show(getSupportFragmentManager(), FrequencyDialogFragment.FREQUENCY_DIALOG_TAG);
|
|
||||||
return true;
|
|
||||||
case R.id.track_detail_split_frequency:
|
|
||||||
FrequencyDialogFragment.newInstance(R.string.split_frequency_key, PreferencesUtils.SPLIT_FREQUENCY_DEFAULT, R.string.menu_split_frequency)
|
|
||||||
.show(getSupportFragmentManager(), FrequencyDialogFragment.FREQUENCY_DIALOG_TAG);
|
|
||||||
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);
|
||||||
@@ -395,6 +405,7 @@ public class TrackDetailActivity extends AbstractListActivity implements ChooseA
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -420,16 +431,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);
|
||||||
@@ -468,8 +469,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);
|
||||||
@@ -487,7 +486,7 @@ public class TrackDetailActivity extends AbstractListActivity implements ChooseA
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void chooseActivityType(String category) {
|
public void chooseActivityType(String category) {
|
||||||
ChooseActivityTypeDialogFragment.newInstance(category).show(getSupportFragmentManager(), ChooseActivityTypeDialogFragment.CHOOSE_ACTIVITY_TYPE_DIALOG_TAG);
|
ChooseActivityTypeDialogFragment.showDialog(getSupportFragmentManager(), category);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -28,10 +28,11 @@ import android.widget.Button;
|
|||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.Spinner;
|
import android.widget.Spinner;
|
||||||
|
|
||||||
|
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.Track;
|
||||||
import de.dennisguse.opentracks.fragments.ChooseActivityTypeDialogFragment;
|
import de.dennisguse.opentracks.fragments.ChooseActivityTypeDialogFragment;
|
||||||
import de.dennisguse.opentracks.fragments.ChooseActivityTypeDialogFragment.ChooseActivityTypeCaller;
|
|
||||||
import de.dennisguse.opentracks.services.TrackRecordingServiceConnection;
|
import de.dennisguse.opentracks.services.TrackRecordingServiceConnection;
|
||||||
import de.dennisguse.opentracks.util.TrackIconUtils;
|
import de.dennisguse.opentracks.util.TrackIconUtils;
|
||||||
import de.dennisguse.opentracks.util.TrackUtils;
|
import de.dennisguse.opentracks.util.TrackUtils;
|
||||||
@@ -41,7 +42,7 @@ import de.dennisguse.opentracks.util.TrackUtils;
|
|||||||
*
|
*
|
||||||
* @author Leif Hendrik Wilden
|
* @author Leif Hendrik Wilden
|
||||||
*/
|
*/
|
||||||
public class TrackEditActivity extends AbstractActivity implements ChooseActivityTypeCaller {
|
public class TrackEditActivity extends AbstractActivity implements ChooseActivityTypeDialogFragment.ChooseActivityTypeCaller {
|
||||||
|
|
||||||
public static final String EXTRA_TRACK_ID = "track_id";
|
public static final String EXTRA_TRACK_ID = "track_id";
|
||||||
public static final String EXTRA_NEW_TRACK = "new_track";
|
public static final String EXTRA_NEW_TRACK = "new_track";
|
||||||
@@ -72,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);
|
||||||
@@ -119,9 +120,7 @@ public class TrackEditActivity extends AbstractActivity implements ChooseActivit
|
|||||||
@Override
|
@Override
|
||||||
public boolean onTouch(View v, MotionEvent event) {
|
public boolean onTouch(View v, MotionEvent event) {
|
||||||
if (event.getAction() == MotionEvent.ACTION_UP) {
|
if (event.getAction() == MotionEvent.ACTION_UP) {
|
||||||
ChooseActivityTypeDialogFragment.newInstance(activityType.getText().toString()).show(
|
ChooseActivityTypeDialogFragment.showDialog(getSupportFragmentManager(), activityType.getText().toString());
|
||||||
getSupportFragmentManager(),
|
|
||||||
ChooseActivityTypeDialogFragment.CHOOSE_ACTIVITY_TYPE_DIALOG_TAG);
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -130,9 +129,7 @@ public class TrackEditActivity extends AbstractActivity implements ChooseActivit
|
|||||||
@Override
|
@Override
|
||||||
public boolean onKey(View v, int keyCode, KeyEvent event) {
|
public boolean onKey(View v, int keyCode, KeyEvent event) {
|
||||||
if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER) {
|
if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER) {
|
||||||
ChooseActivityTypeDialogFragment.newInstance(activityType.getText().toString()).show(
|
ChooseActivityTypeDialogFragment.showDialog(getSupportFragmentManager(), activityType.getText().toString());
|
||||||
getSupportFragmentManager(),
|
|
||||||
ChooseActivityTypeDialogFragment.CHOOSE_ACTIVITY_TYPE_DIALOG_TAG);
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -182,7 +179,7 @@ public class TrackEditActivity extends AbstractActivity implements ChooseActivit
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSaveInstanceState(Bundle outState) {
|
public void onSaveInstanceState(@NonNull Bundle outState) {
|
||||||
super.onSaveInstanceState(outState);
|
super.onSaveInstanceState(outState);
|
||||||
outState.putString(ICON_VALUE_KEY, iconValue);
|
outState.putString(ICON_VALUE_KEY, iconValue);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,8 +28,6 @@ import android.location.LocationManager;
|
|||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.ContextMenu;
|
|
||||||
import android.view.ContextMenu.ContextMenuInfo;
|
|
||||||
import android.view.Gravity;
|
import android.view.Gravity;
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
@@ -37,14 +35,12 @@ import android.view.MenuItem;
|
|||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.View.OnClickListener;
|
import android.view.View.OnClickListener;
|
||||||
import android.widget.AdapterView;
|
import android.widget.AdapterView;
|
||||||
import android.widget.AdapterView.AdapterContextMenuInfo;
|
|
||||||
import android.widget.AdapterView.OnItemClickListener;
|
import android.widget.AdapterView.OnItemClickListener;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
import android.widget.SearchView;
|
|
||||||
import android.widget.ShareActionProvider;
|
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.appcompat.widget.SearchView;
|
||||||
import androidx.core.app.ActivityCompat;
|
import androidx.core.app.ActivityCompat;
|
||||||
import androidx.cursoradapter.widget.ResourceCursorAdapter;
|
import androidx.cursoradapter.widget.ResourceCursorAdapter;
|
||||||
import androidx.loader.app.LoaderManager;
|
import androidx.loader.app.LoaderManager;
|
||||||
@@ -60,9 +56,11 @@ 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;
|
||||||
import de.dennisguse.opentracks.settings.SettingsActivity;
|
import de.dennisguse.opentracks.settings.SettingsActivity;
|
||||||
|
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.TrackIconUtils;
|
import de.dennisguse.opentracks.util.TrackIconUtils;
|
||||||
import de.dennisguse.opentracks.util.TrackUtils;
|
import de.dennisguse.opentracks.util.TrackUtils;
|
||||||
@@ -117,10 +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);
|
|
||||||
ShareActionProvider shareActionProvider = (ShareActionProvider) shareMenuItem.getActionProvider();
|
|
||||||
shareActionProvider.setShareIntent(trackIds.length == 0 ? null : IntentUtils.newShareFileIntent(TrackListActivity.this, 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);
|
||||||
}
|
}
|
||||||
@@ -131,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.
|
||||||
@@ -141,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(
|
if (key != null && PreferencesUtils.isRecording(recordingTrackId)) {
|
||||||
TrackListActivity.this, R.string.recording_track_id_key);
|
|
||||||
if (key != null && recordingTrackId != PreferencesUtils.RECORDING_TRACK_ID_DEFAULT) {
|
|
||||||
trackRecordingServiceConnection.startAndBind();
|
trackRecordingServiceConnection.startAndBind();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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() {
|
||||||
@@ -164,7 +153,7 @@ public class TrackListActivity extends AbstractListActivity implements ConfirmDe
|
|||||||
public void run() {
|
public void run() {
|
||||||
TrackListActivity.this.invalidateOptionsMenu();
|
TrackListActivity.this.invalidateOptionsMenu();
|
||||||
LoaderManager.getInstance(TrackListActivity.this).restartLoader(0, null, loaderCallbacks);
|
LoaderManager.getInstance(TrackListActivity.this).restartLoader(0, null, loaderCallbacks);
|
||||||
boolean isRecording = recordingTrackId != PreferencesUtils.RECORDING_TRACK_ID_DEFAULT;
|
boolean isRecording = PreferencesUtils.isRecording(recordingTrackId);
|
||||||
trackController.update(isRecording, recordingTrackPaused);
|
trackController.update(isRecording, recordingTrackPaused);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -175,8 +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 aggregatedStatisticsMenuItem;
|
// private MenuItem deleteAllMenuItem;
|
||||||
private MenuItem deleteAllMenuItem;
|
|
||||||
|
|
||||||
private final OnClickListener stopListener = new OnClickListener() {
|
private final OnClickListener stopListener = new OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
@@ -200,7 +188,7 @@ public class TrackListActivity extends AbstractListActivity implements ConfirmDe
|
|||||||
runOnUiThread(new Runnable() {
|
runOnUiThread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
trackController.update(recordingTrackId != PreferencesUtils.RECORDING_TRACK_ID_DEFAULT, recordingTrackPaused);
|
trackController.update(PreferencesUtils.isRecording(recordingTrackId), recordingTrackPaused);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -233,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();
|
||||||
@@ -250,14 +237,15 @@ public class TrackListActivity extends AbstractListActivity implements ConfirmDe
|
|||||||
trackController.update(true, true);
|
trackController.update(true, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
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);
|
||||||
@@ -317,7 +305,8 @@ public class TrackListActivity extends AbstractListActivity implements ConfirmDe
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
listView.setAdapter(resourceCursorAdapter);
|
listView.setAdapter(resourceCursorAdapter);
|
||||||
AbstractListActivity.configureListViewContextualMenu(listView, contextualActionModeCallback);
|
|
||||||
|
ActivityUtils.configureListViewContextualMenu(listView, contextualActionModeCallback);
|
||||||
|
|
||||||
LoaderManager.getInstance(this).initLoader(0, null, loaderCallbacks);
|
LoaderManager.getInstance(this).initLoader(0, null, loaderCallbacks);
|
||||||
showStartupDialogs();
|
showStartupDialogs();
|
||||||
@@ -339,8 +328,7 @@ public class TrackListActivity extends AbstractListActivity implements ConfirmDe
|
|||||||
// Update UI
|
// Update UI
|
||||||
this.invalidateOptionsMenu();
|
this.invalidateOptionsMenu();
|
||||||
LoaderManager.getInstance(this).restartLoader(0, null, loaderCallbacks);
|
LoaderManager.getInstance(this).restartLoader(0, null, loaderCallbacks);
|
||||||
boolean isRecording = recordingTrackId != PreferencesUtils.RECORDING_TRACK_ID_DEFAULT;
|
trackController.onResume(PreferencesUtils.isRecording(recordingTrackId), recordingTrackPaused);
|
||||||
trackController.onResume(isRecording, recordingTrackPaused);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -380,25 +368,22 @@ public class TrackListActivity extends AbstractListActivity implements ConfirmDe
|
|||||||
getMenuInflater().inflate(R.menu.track_list, menu);
|
getMenuInflater().inflate(R.menu.track_list, menu);
|
||||||
|
|
||||||
searchMenuItem = menu.findItem(R.id.track_list_search);
|
searchMenuItem = menu.findItem(R.id.track_list_search);
|
||||||
AbstractListActivity.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);
|
||||||
aggregatedStatisticsMenuItem = menu.findItem(R.id.track_list_aggregated_statistics);
|
|
||||||
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 = recordingTrackId != PreferencesUtils.RECORDING_TRACK_ID_DEFAULT;
|
boolean isRecording = PreferencesUtils.isRecording(recordingTrackId);
|
||||||
updateMenuItems(isGpsStarted, isRecording);
|
updateMenuItems(isGpsStarted, isRecording);
|
||||||
|
|
||||||
View searchView = searchMenuItem.getActionView();
|
SearchView searchView = (SearchView) searchMenuItem.getActionView();
|
||||||
if (searchView instanceof SearchView) {
|
searchView.setQuery("", false);
|
||||||
((SearchView) searchView).setQuery("", false);
|
|
||||||
}
|
|
||||||
return super.onPrepareOptionsMenu(menu);
|
return super.onPrepareOptionsMenu(menu);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -412,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);
|
||||||
@@ -439,13 +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_aggregated_statistics:
|
|
||||||
intent = IntentUtils.newIntent(this, AggregatedStatsActivity.class);
|
|
||||||
startActivity(intent);
|
|
||||||
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);
|
||||||
@@ -454,24 +432,6 @@ public class TrackListActivity extends AbstractListActivity implements ConfirmDe
|
|||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
|
|
||||||
super.onCreateContextMenu(menu, v, menuInfo);
|
|
||||||
getMenuInflater().inflate(R.menu.list_context_menu, menu);
|
|
||||||
|
|
||||||
AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
|
|
||||||
contextualActionModeCallback.onPrepare(menu, new int[]{info.position}, new long[]{info.id}, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onContextItemSelected(MenuItem item) {
|
|
||||||
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
|
|
||||||
if (handleContextItem(item.getItemId(), new long[]{info.id})) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return super.onContextItemSelected(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onKeyUp(int keyCode, KeyEvent event) {
|
public boolean onKeyUp(int keyCode, KeyEvent event) {
|
||||||
if (keyCode == KeyEvent.KEYCODE_SEARCH && searchMenuItem != null) {
|
if (keyCode == KeyEvent.KEYCODE_SEARCH && searchMenuItem != null) {
|
||||||
@@ -531,12 +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 (aggregatedStatisticsMenuItem != null) {
|
|
||||||
aggregatedStatisticsMenuItem.setVisible(hasTrack);
|
|
||||||
}
|
|
||||||
if (deleteAllMenuItem != null) {
|
|
||||||
deleteAllMenuItem.setVisible(hasTrack && !isRecording);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -562,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.MarkerDetailActivity;
|
||||||
|
import de.dennisguse.opentracks.R;
|
||||||
import de.dennisguse.opentracks.content.Waypoint;
|
import de.dennisguse.opentracks.content.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 - (float) (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();
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package de.dennisguse.opentracks.content;
|
||||||
|
|
||||||
|
import android.location.Location;
|
||||||
|
import android.location.LocationManager;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a new {@link SensorDataSetLocation}.
|
||||||
|
* 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 SensorDataSetLocation(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,11 +28,6 @@ public class SensorDataSetLocation extends Location {
|
|||||||
|
|
||||||
private SensorDataSet sensorDataSet = null;
|
private SensorDataSet sensorDataSet = null;
|
||||||
|
|
||||||
/**
|
|
||||||
* The id of this location from the provider.
|
|
||||||
*/
|
|
||||||
private int id = -1;
|
|
||||||
|
|
||||||
public SensorDataSetLocation(Location location, SensorDataSet sensorDataSet) {
|
public SensorDataSetLocation(Location location, SensorDataSet sensorDataSet) {
|
||||||
super(location);
|
super(location);
|
||||||
this.sensorDataSet = sensorDataSet;
|
this.sensorDataSet = sensorDataSet;
|
||||||
@@ -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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -198,7 +198,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,6 @@ 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.util.LocationUtils;
|
import de.dennisguse.opentracks.util.LocationUtils;
|
||||||
import de.dennisguse.opentracks.util.PreferencesUtils;
|
import de.dennisguse.opentracks.util.PreferencesUtils;
|
||||||
|
|
||||||
@@ -41,17 +40,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 +102,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.");
|
||||||
@@ -208,7 +209,7 @@ public class TrackDataHub implements DataSourceListener {
|
|||||||
* Returns true if the selected track is recording.
|
* Returns true if the selected track is recording.
|
||||||
*/
|
*/
|
||||||
public boolean isSelectedTrackRecording() {
|
public boolean isSelectedTrackRecording() {
|
||||||
return selectedTrackId == recordingTrackId && recordingTrackId != PreferencesUtils.RECORDING_TRACK_ID_DEFAULT;
|
return selectedTrackId == recordingTrackId && PreferencesUtils.isRecording(recordingTrackId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -254,13 +255,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 +271,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 +281,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 +291,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 +399,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 +448,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 +468,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
|
|
||||||
for (TrackDataListener trackDataListener : sampledInListeners) {
|
|
||||||
trackDataListener.onSegmentSplit(location);
|
|
||||||
includeNextPoint = true;
|
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())) {
|
||||||
|
|||||||
@@ -51,14 +51,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();
|
||||||
|
|
||||||
|
|||||||
@@ -188,6 +188,7 @@ public final class Waypoint {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public enum WaypointType {
|
public enum WaypointType {
|
||||||
WAYPOINT, STATISTICS
|
WAYPOINT,
|
||||||
|
STATISTICS //Always the first waypoint; only one can exist.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,8 +26,7 @@ public class WaypointCreationRequest {
|
|||||||
|
|
||||||
public final static WaypointCreationRequest DEFAULT_WAYPOINT = new WaypointCreationRequest(WaypointType.WAYPOINT, false);
|
public final static WaypointCreationRequest DEFAULT_WAYPOINT = new WaypointCreationRequest(WaypointType.WAYPOINT, false);
|
||||||
|
|
||||||
public final static WaypointCreationRequest DEFAULT_STATISTICS = new WaypointCreationRequest(WaypointType.STATISTICS, false);
|
@Deprecated // TODO Do not create per
|
||||||
|
|
||||||
public final static WaypointCreationRequest DEFAULT_START_TRACK = new WaypointCreationRequest(WaypointType.STATISTICS, true);
|
public final static WaypointCreationRequest DEFAULT_START_TRACK = new WaypointCreationRequest(WaypointType.STATISTICS, true);
|
||||||
|
|
||||||
private WaypointType type;
|
private WaypointType type;
|
||||||
|
|||||||
@@ -2,11 +2,11 @@ package de.dennisguse.opentracks.content.sensor;
|
|||||||
|
|
||||||
public final class SensorDataSet {
|
public final class SensorDataSet {
|
||||||
|
|
||||||
public static final float DATA_UNAVAILABLE = Integer.MAX_VALUE;
|
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 heartRate != DATA_UNAVAILABLE;
|
return !Float.isNaN(heartRate) && heartRate > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getHeartRate() {
|
public float getHeartRate() {
|
||||||
@@ -48,7 +48,7 @@ public final class SensorDataSet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasCadence() {
|
public boolean hasCadence() {
|
||||||
return cadence != DATA_UNAVAILABLE;
|
return !Float.isNaN(cadence);
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getCadence() {
|
public float getCadence() {
|
||||||
@@ -56,7 +56,7 @@ public final class SensorDataSet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasPower() {
|
public boolean hasPower() {
|
||||||
return power != DATA_UNAVAILABLE;
|
return !Float.isNaN(power);
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getPower() {
|
public float getPower() {
|
||||||
@@ -77,7 +77,7 @@ public final class SensorDataSet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasBatteryLevel() {
|
public boolean hasBatteryLevel() {
|
||||||
return batteryLevel != DATA_UNAVAILABLE;
|
return !Float.isNaN(batteryLevel);
|
||||||
}
|
}
|
||||||
|
|
||||||
public float getBatteryLevel() {
|
public float getBatteryLevel() {
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ public enum SensorState {
|
|||||||
NONE,
|
NONE,
|
||||||
CONNECTING,
|
CONNECTING,
|
||||||
CONNECTED,
|
CONNECTED,
|
||||||
|
DISCONNECTING,
|
||||||
DISCONNECTED;
|
DISCONNECTED;
|
||||||
|
|
||||||
public static String getStateAsString(SensorState state, Context c) {
|
public static String getStateAsString(SensorState state, Context c) {
|
||||||
@@ -18,6 +19,8 @@ public enum SensorState {
|
|||||||
return c.getString(R.string.sensor_state_connecting);
|
return c.getString(R.string.sensor_state_connecting);
|
||||||
case CONNECTED:
|
case CONNECTED:
|
||||||
return c.getString(R.string.sensor_state_connected);
|
return c.getString(R.string.sensor_state_connected);
|
||||||
|
case DISCONNECTING:
|
||||||
|
return c.getString(R.string.sensor_state_disconnected);
|
||||||
case DISCONNECTED:
|
case DISCONNECTED:
|
||||||
return c.getString(R.string.sensor_state_disconnected);
|
return c.getString(R.string.sensor_state_disconnected);
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package de.dennisguse.opentracks.fragments;
|
||||||
|
|
||||||
|
public class ChartDistanceFragment extends ChartFragment {
|
||||||
|
|
||||||
|
public static final String CHART_FRAGMENT_TAG = ChartDistanceFragment.class.getSimpleName();
|
||||||
|
|
||||||
|
public ChartDistanceFragment() {
|
||||||
|
super(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -22,19 +22,20 @@ import android.view.LayoutInflater;
|
|||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.view.ViewGroup.LayoutParams;
|
import android.view.ViewGroup.LayoutParams;
|
||||||
import android.widget.ZoomControls;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
import androidx.annotation.VisibleForTesting;
|
import androidx.annotation.VisibleForTesting;
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
import androidx.fragment.app.FragmentActivity;
|
import androidx.fragment.app.FragmentActivity;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import de.dennisguse.opentracks.ChartView;
|
|
||||||
import de.dennisguse.opentracks.R;
|
import de.dennisguse.opentracks.R;
|
||||||
import de.dennisguse.opentracks.TrackDetailActivity;
|
import de.dennisguse.opentracks.TrackDetailActivity;
|
||||||
|
import de.dennisguse.opentracks.chart.ChartView;
|
||||||
import de.dennisguse.opentracks.content.SensorDataSetLocation;
|
import de.dennisguse.opentracks.content.SensorDataSetLocation;
|
||||||
import de.dennisguse.opentracks.content.Track;
|
import de.dennisguse.opentracks.content.Track;
|
||||||
import de.dennisguse.opentracks.content.TrackDataHub;
|
import de.dennisguse.opentracks.content.TrackDataHub;
|
||||||
@@ -54,11 +55,11 @@ import de.dennisguse.opentracks.util.UnitConversions;
|
|||||||
* @author Sandor Dornbush
|
* @author Sandor Dornbush
|
||||||
* @author Rodrigo Damazio
|
* @author Rodrigo Damazio
|
||||||
*/
|
*/
|
||||||
public class ChartFragment extends Fragment implements TrackDataListener {
|
public abstract class ChartFragment extends Fragment implements TrackDataListener {
|
||||||
|
|
||||||
public static final String CHART_FRAGMENT_TAG = "chartFragment";
|
private static final String STATE_CHART_VIEW_BY_DISTANCE_KEY = "chartViewByDistance";
|
||||||
|
|
||||||
private final ArrayList<double[]> pendingPoints = new ArrayList<>();
|
private final List<double[]> pendingPoints = new ArrayList<>();
|
||||||
|
|
||||||
private TrackDataHub trackDataHub;
|
private TrackDataHub trackDataHub;
|
||||||
|
|
||||||
@@ -68,18 +69,17 @@ public class ChartFragment extends Fragment implements TrackDataListener {
|
|||||||
|
|
||||||
private boolean metricUnits = true;
|
private boolean metricUnits = true;
|
||||||
private boolean reportSpeed = true;
|
private boolean reportSpeed = true;
|
||||||
private int recordingDistanceInterval = PreferencesUtils.RECORDING_DISTANCE_INTERVAL_DEFAULT;
|
private int recordingDistanceInterval;
|
||||||
|
|
||||||
// Modes of operation
|
// Modes of operation
|
||||||
private boolean chartByDistance = true;
|
private boolean chartByDistance;
|
||||||
private boolean[] chartShow = new boolean[]{true, true, true, true, true, true};
|
private boolean[] chartShow = new boolean[]{true, true, true, true, true, true};
|
||||||
|
|
||||||
// UI elements
|
// UI elements
|
||||||
private ChartView chartView;
|
private ChartView chartView;
|
||||||
private ZoomControls zoomControls;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A runnable that will enable/disable zoom controls and orange pointer as appropriate and redraw.
|
* A runnable that will set the orange pointer as appropriate and redraw.
|
||||||
*/
|
*/
|
||||||
private final Runnable updateChart = new Runnable() {
|
private final Runnable updateChart = new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
@@ -88,46 +88,34 @@ public class ChartFragment extends Fragment implements TrackDataListener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
zoomControls.setIsZoomInEnabled(chartView.canZoomIn());
|
|
||||||
zoomControls.setIsZoomOutEnabled(chartView.canZoomOut());
|
|
||||||
chartView.setShowPointer(isSelectedTrackRecording());
|
chartView.setShowPointer(isSelectedTrackRecording());
|
||||||
chartView.invalidate();
|
chartView.invalidate();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
public ChartFragment(boolean chartByDistance) {
|
||||||
|
this.chartByDistance = chartByDistance;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
/*
|
recordingDistanceInterval = PreferencesUtils.getRecordingDistanceIntervalDefault(getContext());
|
||||||
* Create a chartView here to store data thus won't need to reload all the data on every onStart or onResume.
|
|
||||||
*/
|
// Create a chartView here to store data thus won't need to reload all the data on every onStart or onResume.
|
||||||
chartView = new ChartView(getActivity());
|
chartView = new ChartView(getContext(), chartByDistance);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
View view = inflater.inflate(R.layout.chart, container, false);
|
return inflater.inflate(R.layout.chart, container, false);
|
||||||
zoomControls = view.findViewById(R.id.chart_zoom_controls);
|
|
||||||
zoomControls.setOnZoomInClickListener(new View.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
zoomIn();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
zoomControls.setOnZoomOutClickListener(new View.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
zoomOut();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return view;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStart() {
|
public void onStart() {
|
||||||
super.onStart();
|
super.onStart();
|
||||||
ViewGroup layout = getActivity().findViewById(R.id.chart_view_layout);
|
ViewGroup layout = getView().findViewById(R.id.chart_view_layout);
|
||||||
LayoutParams layoutParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
|
LayoutParams layoutParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
|
||||||
layout.addView(chartView, layoutParams);
|
layout.addView(chartView, layoutParams);
|
||||||
}
|
}
|
||||||
@@ -149,10 +137,24 @@ public class ChartFragment extends Fragment implements TrackDataListener {
|
|||||||
@Override
|
@Override
|
||||||
public void onStop() {
|
public void onStop() {
|
||||||
super.onStop();
|
super.onStop();
|
||||||
ViewGroup layout = getActivity().findViewById(R.id.chart_view_layout);
|
ViewGroup layout = getView().findViewById(R.id.chart_view_layout);
|
||||||
layout.removeView(chartView);
|
layout.removeView(chartView);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSaveInstanceState(@NonNull Bundle outState) {
|
||||||
|
super.onSaveInstanceState(outState);
|
||||||
|
outState.putBoolean(STATE_CHART_VIEW_BY_DISTANCE_KEY, chartByDistance);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onViewStateRestored(@Nullable Bundle savedInstanceState) {
|
||||||
|
super.onViewStateRestored(savedInstanceState);
|
||||||
|
if (savedInstanceState != null) {
|
||||||
|
chartByDistance = savedInstanceState.getBoolean(STATE_CHART_VIEW_BY_DISTANCE_KEY);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTrackUpdated(Track track) {
|
public void onTrackUpdated(Track track) {
|
||||||
if (isResumed()) {
|
if (isResumed()) {
|
||||||
@@ -197,13 +199,6 @@ public class ChartFragment extends Fragment implements TrackDataListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onSegmentSplit(Location location) {
|
|
||||||
if (isResumed()) {
|
|
||||||
fillDataPoint(location, null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onNewTrackPointsDone() {
|
public void onNewTrackPointsDone() {
|
||||||
if (isResumed()) {
|
if (isResumed()) {
|
||||||
@@ -263,10 +258,8 @@ public class ChartFragment extends Fragment implements TrackDataListener {
|
|||||||
}
|
}
|
||||||
reportSpeed = speed;
|
reportSpeed = speed;
|
||||||
chartView.setReportSpeed(reportSpeed);
|
chartView.setReportSpeed(reportSpeed);
|
||||||
boolean chartShowSpeed = PreferencesUtils.getBoolean(
|
setSeriesEnabled(ChartView.SPEED_SERIES, reportSpeed);
|
||||||
getActivity(), R.string.chart_show_speed_key, PreferencesUtils.CHART_SHOW_SPEED_DEFAULT);
|
setSeriesEnabled(ChartView.PACE_SERIES, !reportSpeed);
|
||||||
setSeriesEnabled(ChartView.SPEED_SERIES, chartShowSpeed && reportSpeed);
|
|
||||||
setSeriesEnabled(ChartView.PACE_SERIES, chartShowSpeed && !reportSpeed);
|
|
||||||
runOnUiThread(new Runnable() {
|
runOnUiThread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
@@ -303,32 +296,14 @@ public class ChartFragment extends Fragment implements TrackDataListener {
|
|||||||
*/
|
*/
|
||||||
private void checkChartSettings() {
|
private void checkChartSettings() {
|
||||||
boolean needUpdate = false;
|
boolean needUpdate = false;
|
||||||
if (chartByDistance != PreferencesUtils.isChartByDistance(getActivity())) {
|
|
||||||
chartByDistance = !chartByDistance;
|
if (setSeriesEnabled(ChartView.SPEED_SERIES, reportSpeed)) {
|
||||||
chartView.setChartByDistance(chartByDistance);
|
|
||||||
reloadTrackDataHub();
|
|
||||||
needUpdate = true;
|
needUpdate = true;
|
||||||
}
|
}
|
||||||
if (setSeriesEnabled(ChartView.ELEVATION_SERIES, PreferencesUtils.getBoolean(getActivity(), R.string.chart_show_elevation_key, PreferencesUtils.CHART_SHOW_ELEVATION_DEFAULT))) {
|
if (setSeriesEnabled(ChartView.PACE_SERIES, !reportSpeed)) {
|
||||||
needUpdate = true;
|
needUpdate = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean chartShowSpeed = PreferencesUtils.getBoolean(getActivity(), R.string.chart_show_speed_key, PreferencesUtils.CHART_SHOW_SPEED_DEFAULT);
|
|
||||||
if (setSeriesEnabled(ChartView.SPEED_SERIES, chartShowSpeed && reportSpeed)) {
|
|
||||||
needUpdate = true;
|
|
||||||
}
|
|
||||||
if (setSeriesEnabled(ChartView.PACE_SERIES, chartShowSpeed && !reportSpeed)) {
|
|
||||||
needUpdate = true;
|
|
||||||
}
|
|
||||||
if (setSeriesEnabled(ChartView.POWER_SERIES, PreferencesUtils.getBoolean(getActivity(), R.string.chart_show_power_key, PreferencesUtils.CHART_SHOW_POWER_DEFAULT))) {
|
|
||||||
needUpdate = true;
|
|
||||||
}
|
|
||||||
if (setSeriesEnabled(ChartView.CADENCE_SERIES, PreferencesUtils.getBoolean(getActivity(), R.string.chart_show_cadence_key, PreferencesUtils.CHART_SHOW_CADENCE_DEFAULT))) {
|
|
||||||
needUpdate = true;
|
|
||||||
}
|
|
||||||
if (setSeriesEnabled(ChartView.HEART_RATE_SERIES, PreferencesUtils.getBoolean(getActivity(), R.string.chart_show_heart_rate_key, PreferencesUtils.CHART_SHOW_HEART_RATE_DEFAULT))) {
|
|
||||||
needUpdate = true;
|
|
||||||
}
|
|
||||||
if (needUpdate) {
|
if (needUpdate) {
|
||||||
chartView.postInvalidate();
|
chartView.postInvalidate();
|
||||||
}
|
}
|
||||||
@@ -352,8 +327,8 @@ public class ChartFragment extends Fragment implements TrackDataListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resumes the trackDataHub. Needs to be synchronized because trackDataHub can
|
* Resumes the trackDataHub.
|
||||||
* be accessed by multiple threads.
|
* Needs to be synchronized because trackDataHub can be accessed by multiple threads.
|
||||||
*/
|
*/
|
||||||
private synchronized void resumeTrackDataHub() {
|
private synchronized void resumeTrackDataHub() {
|
||||||
trackDataHub = ((TrackDetailActivity) getActivity()).getTrackDataHub();
|
trackDataHub = ((TrackDetailActivity) getActivity()).getTrackDataHub();
|
||||||
@@ -363,8 +338,8 @@ public class ChartFragment extends Fragment implements TrackDataListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pauses the trackDataHub. Needs to be synchronized because trackDataHub can
|
* Pauses the trackDataHub.
|
||||||
* be accessed by multiple threads.
|
* Needs to be synchronized because trackDataHub can be accessed by multiple threads.
|
||||||
*/
|
*/
|
||||||
private synchronized void pauseTrackDataHub() {
|
private synchronized void pauseTrackDataHub() {
|
||||||
trackDataHub.unregisterTrackDataListener(this);
|
trackDataHub.unregisterTrackDataListener(this);
|
||||||
@@ -372,16 +347,16 @@ public class ChartFragment extends Fragment implements TrackDataListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if the selected track is recording. Needs to be synchronized
|
* Returns true if the selected track is recording.
|
||||||
* because trackDataHub can be accessed by multiple threads.
|
* Needs to be synchronized because trackDataHub can be accessed by multiple threads.
|
||||||
*/
|
*/
|
||||||
private synchronized boolean isSelectedTrackRecording() {
|
private synchronized boolean isSelectedTrackRecording() {
|
||||||
return trackDataHub != null && trackDataHub.isSelectedTrackRecording();
|
return trackDataHub != null && trackDataHub.isSelectedTrackRecording();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reloads the trackDataHub. Needs to be synchronized because trackDataHub can
|
* Reloads the trackDataHub.
|
||||||
* be accessed by multiple threads.
|
* Needs to be synchronized because trackDataHub can be accessed by multiple threads.
|
||||||
*/
|
*/
|
||||||
private synchronized void reloadTrackDataHub() {
|
private synchronized void reloadTrackDataHub() {
|
||||||
if (trackDataHub != null) {
|
if (trackDataHub != null) {
|
||||||
@@ -389,24 +364,6 @@ public class ChartFragment extends Fragment implements TrackDataListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* To zoom in.
|
|
||||||
*/
|
|
||||||
private void zoomIn() {
|
|
||||||
chartView.zoomIn();
|
|
||||||
zoomControls.setIsZoomInEnabled(chartView.canZoomIn());
|
|
||||||
zoomControls.setIsZoomOutEnabled(chartView.canZoomOut());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* To zoom out.
|
|
||||||
*/
|
|
||||||
private void zoomOut() {
|
|
||||||
chartView.zoomOut();
|
|
||||||
zoomControls.setIsZoomInEnabled(chartView.canZoomIn());
|
|
||||||
zoomControls.setIsZoomOutEnabled(chartView.canZoomOut());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Runs a runnable on the UI thread if possible.
|
* Runs a runnable on the UI thread if possible.
|
||||||
*
|
*
|
||||||
@@ -438,9 +395,6 @@ public class ChartFragment extends Fragment implements TrackDataListener {
|
|||||||
double elevation = Double.NaN;
|
double elevation = Double.NaN;
|
||||||
double speed = Double.NaN;
|
double speed = Double.NaN;
|
||||||
double pace = Double.NaN;
|
double pace = Double.NaN;
|
||||||
double heartRate = Double.NaN;
|
|
||||||
double cadence = Double.NaN;
|
|
||||||
double power = Double.NaN;
|
|
||||||
|
|
||||||
if (tripStatisticsUpdater != null) {
|
if (tripStatisticsUpdater != null) {
|
||||||
tripStatisticsUpdater.addLocation(location, recordingDistanceInterval);
|
tripStatisticsUpdater.addLocation(location, recordingDistanceInterval);
|
||||||
@@ -466,6 +420,10 @@ public class ChartFragment extends Fragment implements TrackDataListener {
|
|||||||
}
|
}
|
||||||
pace = speed == 0 ? 0.0 : 60.0 / speed;
|
pace = speed == 0 ? 0.0 : 60.0 / speed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double heartRate = Double.NaN;
|
||||||
|
double cadence = Double.NaN;
|
||||||
|
double power = Double.NaN;
|
||||||
if (location instanceof SensorDataSetLocation && ((SensorDataSetLocation) location).getSensorDataSet() != null) {
|
if (location instanceof SensorDataSetLocation && ((SensorDataSetLocation) location).getSensorDataSet() != null) {
|
||||||
SensorDataSet sensorDataSet = ((SensorDataSetLocation) location).getSensorDataSet();
|
SensorDataSet sensorDataSet = ((SensorDataSetLocation) location).getSensorDataSet();
|
||||||
if (sensorDataSet.hasHeartRate()) {
|
if (sensorDataSet.hasHeartRate()) {
|
||||||
@@ -479,6 +437,7 @@ public class ChartFragment extends Fragment implements TrackDataListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TODO: Is related to ChartView.ELEVATION_SERIES etc.
|
||||||
if (data != null) {
|
if (data != null) {
|
||||||
data[0] = timeOrDistance;
|
data[0] = timeOrDistance;
|
||||||
data[1] = elevation;
|
data[1] = elevation;
|
||||||
|
|||||||