mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-12-26 02:25:50 +01:00
Fossil Hybrid HR: Set OpenTracks track category and icon to workout type selected on watch
This commit is contained in:
parent
10265ad697
commit
7ae2ec1dcf
@ -38,4 +38,21 @@ public final class QHybridConstants {
|
||||
put("wellnessApp", "3.15");
|
||||
}
|
||||
};
|
||||
|
||||
public static Map<Integer, String> WORKOUT_TYPES_TO_OPENTRACKS_CATEGORY = new HashMap<Integer, String>() {
|
||||
{
|
||||
put(1, "running");
|
||||
put(2, "cycling");
|
||||
put(8, "walking");
|
||||
put(12, "hiking");
|
||||
}
|
||||
};
|
||||
public static Map<Integer, String> WORKOUT_TYPES_TO_OPENTRACKS_ICON = new HashMap<Integer, String>() {
|
||||
{
|
||||
put(1, "RUN");
|
||||
put(2, "BIKE");
|
||||
put(8, "WALK");
|
||||
put(12, "WALK");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user