From 7ae2ec1dcf8e3b2898aa44f697cdfedff2cba1e5 Mon Sep 17 00:00:00 2001 From: Arjan Schrijver Date: Sun, 17 Jul 2022 21:34:17 +0200 Subject: [PATCH] Fossil Hybrid HR: Set OpenTracks track category and icon to workout type selected on watch --- .../devices/qhybrid/QHybridConstants.java | 17 +++++++++++++++++ .../opentracks/OpenTracksController.java | 16 +++++++++++++--- .../workout/WorkoutRequestHandler.java | 7 +++++-- 3 files changed, 35 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/qhybrid/QHybridConstants.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/qhybrid/QHybridConstants.java index 60e3183e4..4a05e2cef 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/qhybrid/QHybridConstants.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/qhybrid/QHybridConstants.java @@ -38,4 +38,21 @@ public final class QHybridConstants { put("wellnessApp", "3.15"); } }; + + public static Map WORKOUT_TYPES_TO_OPENTRACKS_CATEGORY = new HashMap() { + { + put(1, "running"); + put(2, "cycling"); + put(8, "walking"); + put(12, "hiking"); + } + }; + public static Map WORKOUT_TYPES_TO_OPENTRACKS_ICON = new HashMap() { + { + put(1, "RUN"); + put(2, "BIKE"); + put(8, "WALK"); + put(12, "WALK"); + } + }; } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/opentracks/OpenTracksController.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/opentracks/OpenTracksController.java index 3f1f590a4..08c8736fd 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/opentracks/OpenTracksController.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/externalevents/opentracks/OpenTracksController.java @@ -86,7 +86,7 @@ public class OpenTracksController extends Activity { moveTaskToBack(true); } - public static void sendIntent(Context context, String className) { + public static void sendIntent(Context context, String className, String category, String icon) { Prefs prefs = GBApplication.getPrefs(); String packageName = prefs.getString("opentracks_packagename", "de.dennisguse.opentracks"); Intent intent = new Intent(); @@ -94,6 +94,12 @@ public class OpenTracksController extends Activity { intent.setClassName(packageName, className); intent.putExtra("STATS_TARGET_PACKAGE", context.getPackageName()); intent.putExtra("STATS_TARGET_CLASS", OpenTracksController.class.getName()); + if (category != null) { + intent.putExtra("TRACK_CATEGORY", category); + } + if (icon != null) { + intent.putExtra("TRACK_ICON", icon); + } try { context.startActivity(intent); } catch (Exception e) { @@ -102,11 +108,15 @@ public class OpenTracksController extends Activity { } public static void startRecording(Context context) { - sendIntent(context, "de.dennisguse.opentracks.publicapi.StartRecording"); + sendIntent(context, "de.dennisguse.opentracks.publicapi.StartRecording", null, null); + } + + public static void startRecording(Context context, String category, String icon) { + sendIntent(context, "de.dennisguse.opentracks.publicapi.StartRecording", category, icon); } public static void stopRecording(Context context) { - sendIntent(context, "de.dennisguse.opentracks.publicapi.StopRecording"); + sendIntent(context, "de.dennisguse.opentracks.publicapi.StopRecording", null, null); OpenTracksContentObserver openTracksObserver = GBApplication.app().getOpenTracksObserver(); if (openTracksObserver != null) { openTracksObserver.finish(); diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil_hr/workout/WorkoutRequestHandler.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil_hr/workout/WorkoutRequestHandler.java index 8bb941f06..56d419756 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil_hr/workout/WorkoutRequestHandler.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/qhybrid/requests/fossil_hr/workout/WorkoutRequestHandler.java @@ -25,6 +25,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import nodomain.freeyourgadget.gadgetbridge.GBApplication; +import nodomain.freeyourgadget.gadgetbridge.devices.qhybrid.QHybridConstants; import nodomain.freeyourgadget.gadgetbridge.externalevents.opentracks.OpenTracksController; public class WorkoutRequestHandler { @@ -41,9 +42,11 @@ public class WorkoutRequestHandler { JSONObject workoutResponse = new JSONObject(); if (workoutRequest.optString("state").equals("started") && workoutRequest.optString("gps").equals("on")) { int activityType = workoutRequest.optInt("activity", -1); - LOG.info("Workout started, activity type is " + activityType); + String activityCategory = QHybridConstants.WORKOUT_TYPES_TO_OPENTRACKS_CATEGORY.get(activityType); + String activityIcon = QHybridConstants.WORKOUT_TYPES_TO_OPENTRACKS_ICON.get(activityType); + LOG.info("Workout started, activity type is " + activityType + "/" + activityCategory); addStateResponse(workoutResponse, "success", ""); - OpenTracksController.startRecording(context); + OpenTracksController.startRecording(context, activityCategory, activityIcon); } else if (workoutRequest.optString("type").equals("req_distance")) { long timeSecs = GBApplication.app().getOpenTracksObserver().getTimeMillisChange() / 1000; float distanceCM = GBApplication.app().getOpenTracksObserver().getDistanceMeterChange() * 100;