forked from upstream-mirrors/OpenTracks
@@ -109,19 +109,20 @@ The API can be invoked by sending an explicit Intent to start an activity.
|
||||
* Debug: `de.dennisguse.opentracks.debug`
|
||||
* Nightly: `de.dennisguse.opentracks.nightly`
|
||||
|
||||
`Class`:
|
||||
|
||||
`Classes`:
|
||||
* **Start a recording:** `de.dennisguse.opentracks.publicapi.StartRecording`
|
||||
* Set track data: `TRACK_NAME`, `TRACK_DESCRIPTION`, `TRACK_CATEGORY`, and `TRACK_ICON` (
|
||||
non-localized identifier
|
||||
see [/src/main/java/de/dennisguse/opentracks/util/TrackIconUtils.java#L38](/src/main/java/de/dennisguse/opentracks/util/TrackIconUtils.java#L38)).
|
||||
NOTE: if `TRACK_ICON` is not present, `TRACK_CATEGORY` will be used to determine the icon (
|
||||
localized).
|
||||
* Send recorded data to another application via _Dashboard API_: `STATS_TARGET_PACKAGE` and
|
||||
`STATS_TARGET_CLASS`
|
||||
* **Stop a recording:** `de.dennisguse.opentracks.publicapi.StopRecording`
|
||||
* **Create a marker:** `de.dennisguse.opentracks.publicapi.CreateMarker`
|
||||
|
||||
For testing via adb: `adb shell am start -e someParameter someValue -n "package/class"`
|
||||
|
||||
`StartRecording` supports the following parameters:
|
||||
|
||||
* Set track data: `TRACK_NAME`, `TRACK_DESCRIPTION`, `TRACK_CATEGORY`, and `TRACK_ICON` (non-localized identifier see [/src/main/java/de/dennisguse/opentracks/util/TrackIconUtils.java#L38](/src/main/java/de/dennisguse/opentracks/util/TrackIconUtils.java#L38)).
|
||||
NOTE: if `TRACK_ICON` is not present, `TRACK_CATEGORY` will be used to determine the icon (localized).
|
||||
* Send recorded data to another application via _Dashboard API_: `STATS_TARGET_PACKAGE` and `STATS_TARGET_CLASS`
|
||||
|
||||
The Public API is disabled by default to protect the user's privacy, but it can easily be enabled in the settings.
|
||||
|
||||
## File formats compatibility with open-source software
|
||||
|
||||
+9
-9
@@ -482,7 +482,7 @@ public class CustomContentProviderUtilsTest {
|
||||
assertEquals(contentProviderUtils.getMarkers(trackId).size(), 1);
|
||||
|
||||
// Get marker id that needs to delete.
|
||||
Marker.Id marker1Id = new Marker.Id(ContentUris.parseId(contentProviderUtils.insertMarker(marker1)));
|
||||
Marker.Id marker1Id = contentProviderUtils.insertMarker(marker1);
|
||||
|
||||
// Delete
|
||||
contentProviderUtils.deleteMarker(context, marker1Id);
|
||||
@@ -509,7 +509,7 @@ public class CustomContentProviderUtilsTest {
|
||||
assertEquals(contentProviderUtils.getMarkers(trackId).size(), 1);
|
||||
|
||||
// Get marker id that needs to delete.
|
||||
Marker.Id marker1Id = new Marker.Id(ContentUris.parseId(contentProviderUtils.insertMarker(marker1)));
|
||||
Marker.Id marker1Id = contentProviderUtils.insertMarker(marker1);
|
||||
|
||||
// Check marker has photo and it's in the external storage.
|
||||
assertTrue(marker1.hasPhoto());
|
||||
@@ -553,11 +553,11 @@ public class CustomContentProviderUtilsTest {
|
||||
// Insert at first.
|
||||
Marker marker1 = new Marker(trackId, contentProviderUtils.getLastValidTrackPoint(trackId));
|
||||
marker1.setDescription(MOCK_DESC);
|
||||
Marker.Id marker1Id = new Marker.Id(ContentUris.parseId(contentProviderUtils.insertMarker(marker1)));
|
||||
Marker.Id marker1Id = contentProviderUtils.insertMarker(marker1);
|
||||
|
||||
Marker marker2 = new Marker(trackId, contentProviderUtils.getLastValidTrackPoint(trackId));
|
||||
marker2.setDescription(MOCK_DESC);
|
||||
Marker.Id marker2Id = new Marker.Id(ContentUris.parseId(contentProviderUtils.insertMarker(marker2)));
|
||||
Marker.Id marker2Id = contentProviderUtils.insertMarker(marker2);
|
||||
|
||||
// Delete
|
||||
assertNotNull(contentProviderUtils.getMarker(marker1Id));
|
||||
@@ -598,7 +598,7 @@ public class CustomContentProviderUtilsTest {
|
||||
|
||||
Marker marker = new Marker(trackId, contentProviderUtils.getLastValidTrackPoint(trackId));
|
||||
marker.setDescription(TEST_DESC);
|
||||
Marker.Id markerId = new Marker.Id(ContentUris.parseId(contentProviderUtils.insertMarker(marker)));
|
||||
Marker.Id markerId = contentProviderUtils.insertMarker(marker);
|
||||
|
||||
assertEquals(TEST_DESC, contentProviderUtils.getMarker(markerId).getDescription());
|
||||
}
|
||||
@@ -614,7 +614,7 @@ public class CustomContentProviderUtilsTest {
|
||||
// Insert at first.
|
||||
Marker marker = new Marker(trackId, contentProviderUtils.getLastValidTrackPoint(trackId));
|
||||
marker.setDescription(TEST_DESC);
|
||||
Marker.Id markerId = new Marker.Id(ContentUris.parseId(contentProviderUtils.insertMarker(marker)));
|
||||
Marker.Id markerId = contentProviderUtils.insertMarker(marker);
|
||||
|
||||
// Update
|
||||
marker = contentProviderUtils.getMarker(markerId);
|
||||
@@ -638,7 +638,7 @@ public class CustomContentProviderUtilsTest {
|
||||
TrackPoint trackPoint = contentProviderUtils.getLastValidTrackPoint(trackId);
|
||||
Marker marker = TestDataUtil.createMarkerWithPhoto(context, trackId, trackPoint);
|
||||
marker.setDescription(TEST_DESC);
|
||||
Marker.Id markerId = new Marker.Id(ContentUris.parseId(contentProviderUtils.insertMarker(marker)));
|
||||
Marker.Id markerId = contentProviderUtils.insertMarker(marker);
|
||||
|
||||
File dir = new File(FileUtils.getPhotoDir(context), "" + trackId.id());
|
||||
assertTrue(dir.exists());
|
||||
@@ -673,7 +673,7 @@ public class CustomContentProviderUtilsTest {
|
||||
TrackPoint trackPoint = contentProviderUtils.getLastValidTrackPoint(trackId);
|
||||
Marker marker = TestDataUtil.createMarkerWithPhoto(context, trackId, trackPoint);
|
||||
marker.setDescription(TEST_DESC);
|
||||
Marker.Id markerId = new Marker.Id(ContentUris.parseId(contentProviderUtils.insertMarker(marker)));
|
||||
Marker.Id markerId = contentProviderUtils.insertMarker(marker);
|
||||
|
||||
File dir = new File(FileUtils.getPhotoDir(context), "" + trackId.id());
|
||||
assertTrue(dir.exists());
|
||||
@@ -709,7 +709,7 @@ public class CustomContentProviderUtilsTest {
|
||||
marker.setDescription(TEST_DESC);
|
||||
Marker otherMarker = TestDataUtil.createMarkerWithPhoto(context, trackId, trackPoint);
|
||||
otherMarker.setDescription(TEST_DESC);
|
||||
Marker.Id markerId = new Marker.Id(ContentUris.parseId(contentProviderUtils.insertMarker(marker)));
|
||||
Marker.Id markerId = contentProviderUtils.insertMarker(marker);
|
||||
contentProviderUtils.insertMarker(otherMarker);
|
||||
|
||||
File dir = new File(FileUtils.getPhotoDir(context), "" + trackId.id());
|
||||
|
||||
@@ -98,6 +98,14 @@ limitations under the License.
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".publicapi.CreateMarker"
|
||||
android:exported="true"
|
||||
android:theme="@style/SplashTheme">
|
||||
<intent-filter>
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<!-- NOTE: the name of the MAIN/LAUNCHER is used by icon packs; if this is changed, icon packs break.-->
|
||||
<activity
|
||||
|
||||
@@ -487,12 +487,11 @@ public class ContentProviderUtils {
|
||||
return markers;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the content provider URI of the inserted marker.
|
||||
*/
|
||||
public Uri insertMarker(@NonNull Marker marker) {
|
||||
// TODO Merge with updateMarker
|
||||
public Marker.Id insertMarker(@NonNull Marker marker) {
|
||||
marker.setId(null);
|
||||
return contentResolver.insert(MarkerColumns.CONTENT_URI, createContentValues(marker));
|
||||
Uri uri = contentResolver.insert(MarkerColumns.CONTENT_URI, createContentValues(marker));
|
||||
return new Marker.Id(ContentUris.parseId(uri));
|
||||
}
|
||||
|
||||
private void deleteMarkerPhoto(Context context, Marker marker) {
|
||||
|
||||
@@ -13,7 +13,7 @@ import de.dennisguse.opentracks.services.TrackRecordingService;
|
||||
import de.dennisguse.opentracks.services.TrackRecordingServiceConnection;
|
||||
import de.dennisguse.opentracks.settings.PreferencesUtils;
|
||||
|
||||
public abstract class AbstractAPIActivity extends AppCompatActivity {
|
||||
abstract class AbstractAPIActivity extends AppCompatActivity {
|
||||
|
||||
private final String TAG = AbstractAPIActivity.class.getSimpleName();
|
||||
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package de.dennisguse.opentracks.publicapi;
|
||||
|
||||
import de.dennisguse.opentracks.services.TrackRecordingService;
|
||||
|
||||
public class CreateMarker extends AbstractAPIActivity {
|
||||
|
||||
@Override
|
||||
protected void execute(TrackRecordingService service) {
|
||||
service.createMarker();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isPostExecuteStopService() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,7 @@ import de.dennisguse.opentracks.ui.markers.MarkerEditActivity;
|
||||
import de.dennisguse.opentracks.util.IntentUtils;
|
||||
|
||||
/**
|
||||
* Public API to creates a Marker for a given track with a given location
|
||||
* INTERNAL: only meant for clients of OSMDashboard API.
|
||||
*/
|
||||
public class CreateMarkerActivity extends AppCompatActivity {
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ import de.dennisguse.opentracks.ui.markers.MarkerDetailActivity;
|
||||
import de.dennisguse.opentracks.util.IntentUtils;
|
||||
|
||||
/**
|
||||
* Public api to show an existing marker
|
||||
* INTERNAL: only meant for clients of OSMDashboard API.
|
||||
*/
|
||||
public class ShowMarkerActivity extends AppCompatActivity {
|
||||
|
||||
|
||||
@@ -36,7 +36,9 @@ import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.time.Duration;
|
||||
|
||||
import de.dennisguse.opentracks.data.ContentProviderUtils;
|
||||
import de.dennisguse.opentracks.data.models.Distance;
|
||||
import de.dennisguse.opentracks.data.models.Marker;
|
||||
import de.dennisguse.opentracks.data.models.Track;
|
||||
import de.dennisguse.opentracks.data.models.TrackPoint;
|
||||
import de.dennisguse.opentracks.sensors.sensorData.SensorDataSet;
|
||||
@@ -243,6 +245,20 @@ public class TrackRecordingService extends Service implements TrackPointCreator.
|
||||
gpsStatusObservable.postValue(STATUS_GPS_DEFAULT);
|
||||
}
|
||||
|
||||
public Marker.Id createMarker() {
|
||||
if (!isRecording()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
//TODO This contains some duplication to TrackRecodingActivity's Marker creation
|
||||
TrackPoint trackPoint = trackRecordingManager.getLastStoredTrackPointWithLocation();
|
||||
if (trackPoint == null) {
|
||||
return null;
|
||||
}
|
||||
Marker marker = new Marker(recordingStatus.trackId(), trackPoint);
|
||||
return new ContentProviderUtils(this).insertMarker(marker);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean newTrackPoint(TrackPoint trackPoint, Distance thresholdHorizontalAccuracy) {
|
||||
if (!isRecording()) {
|
||||
|
||||
Reference in New Issue
Block a user