PublicAPI: support setting the icon.

Fixes #1282.
This commit is contained in:
Dennis Guse
2022-08-28 14:28:12 +02:00
parent bb549fdc93
commit 5a4919efd2
3 changed files with 22 additions and 11 deletions
+6 -8
View File
@@ -111,19 +111,17 @@ The API can be invoked by sending an explicit Intent to start an activity.
* **Start a recording:** `de.dennisguse.opentracks.publicapi.StartRecording`
* **Stop a recording:** `de.dennisguse.opentracks.publicapi.StopRecording`
For testing via adb: `adb shell am start -n "package/class"`
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_CATEGORY`, and `TRACK_DESCRIPTION`
* Send recorded data to another application via _Dashboard API_: `STATS_TARGET_PACKAGE`
and `STATS_TARGET_CLASS`
* 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.
The Public API is disabled by default to protect the user's privacy, but it can easily be enabled in the settings.
__IMPORTANT__: triggering `StartRecording` does not check if Android permissions (location or
Bluetooth) were granted. If they are not granted`
__IMPORTANT__: triggering `StartRecording` does not check if Android permissions (location or Bluetooth) were granted. If they are not granted, nothing will be recorded.
## Dashboard API (incl. map)
@@ -15,6 +15,7 @@ public class StartRecording extends AbstractAPIActivity {
public static final String EXTRA_TRACK_NAME = "TRACK_NAME";
public static final String EXTRA_TRACK_CATEGORY = "TRACK_CATEGORY";
public static final String EXTRA_TRACK_ICON = "TRACK_ICON";
public static final String EXTRA_TRACK_DESCRIPTION = "TRACK_DESCRIPTION";
public static final String EXTRA_STATS_TARGET_PACKAGE = "STATS_TARGET_PACKAGE";
@@ -40,8 +41,11 @@ public class StartRecording extends AbstractAPIActivity {
ContentProviderUtils contentProviderUtils = new ContentProviderUtils(this);
Track track = contentProviderUtils.getTrack(trackId);
TrackUtils.updateTrack(this, track, bundle.getString(EXTRA_TRACK_NAME, null),
bundle.getString(EXTRA_TRACK_CATEGORY, null), bundle.getString(EXTRA_TRACK_DESCRIPTION, null),
TrackUtils.updateTrack(this, track,
bundle.getString(EXTRA_TRACK_NAME, null),
bundle.getString(EXTRA_TRACK_CATEGORY, null),
bundle.getString(EXTRA_TRACK_ICON, null),
bundle.getString(EXTRA_TRACK_DESCRIPTION, null),
contentProviderUtils);
}
@@ -26,12 +26,17 @@ import de.dennisguse.opentracks.data.models.Track;
*
* @author Jimmy Shih
*/
@Deprecated //TODO Refactor: all this should happen somewhere else (ContentProviderUtils?)
public class TrackUtils {
private TrackUtils() {
}
public static void updateTrack(Context context, Track track, String name, String category, String description, ContentProviderUtils contentProviderUtils) {
updateTrack(context, track, name, category, TrackIconUtils.getIconValue(context, category), description, contentProviderUtils);
}
public static void updateTrack(Context context, Track track, String name, String category, String iconValue, String description, ContentProviderUtils contentProviderUtils) {
boolean update = false;
if (name != null) {
track.setName(name);
@@ -39,9 +44,13 @@ public class TrackUtils {
}
if (category != null) {
track.setCategory(category);
track.setIcon(TrackIconUtils.getIconValue(context, category));
update = true;
}
if (iconValue != null) {
track.setIcon(iconValue);
} else if (category != null){
track.setIcon(TrackIconUtils.getIconValue(context, category));
}
if (description != null) {
track.setDescription(description);
update = true;