1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-12-26 02:25:50 +01:00

Add OpenTracksController for interactions with OpenTracks

This commit is contained in:
Arjan Schrijver 2022-02-06 21:36:25 +01:00
parent c8ad21eebf
commit e188e54622
3 changed files with 65 additions and 8 deletions

View File

@ -0,0 +1,56 @@
/* Copyright (C) 2022 Arjan Schrijver
This file is part of Gadgetbridge.
Gadgetbridge is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Gadgetbridge is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
package nodomain.freeyourgadget.gadgetbridge.externalevents;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
public class OpenTracksController extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (intent != null) {
Bundle bundle = intent.getExtras();
if (bundle != null) {
// Handle received OpenTracks Dashboard API intent
}
}
}
public static void sendIntent(Context context, String className) {
Prefs prefs = GBApplication.getPrefs();
String packageName = prefs.getString("opentracks_packagename", "de.dennisguse.opentracks");
Intent intent = new Intent();
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setClassName(packageName, className);
context.startActivity(intent);
}
public static void startRecording(Context context) {
sendIntent(context, "de.dennisguse.opentracks.publicapi.StartRecording");
}
public static void stopRecording(Context context) {
sendIntent(context, "de.dennisguse.opentracks.publicapi.StopRecording");
}
}

View File

@ -86,6 +86,7 @@ import nodomain.freeyourgadget.gadgetbridge.devices.qhybrid.HybridHRActivitySamp
import nodomain.freeyourgadget.gadgetbridge.devices.qhybrid.NotificationHRConfiguration;
import nodomain.freeyourgadget.gadgetbridge.entities.HybridHRActivitySample;
import nodomain.freeyourgadget.gadgetbridge.externalevents.NotificationListener;
import nodomain.freeyourgadget.gadgetbridge.externalevents.OpenTracksController;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
import nodomain.freeyourgadget.gadgetbridge.impl.GBDeviceApp;
import nodomain.freeyourgadget.gadgetbridge.model.CallSpec;
@ -1578,10 +1579,7 @@ public class FossilHRWatchAdapter extends FossilWatchAdapter {
.put("message", "")
.put("type", "success")
);
Intent intent = new Intent();
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setClassName("de.dennisguse.opentracks.debug", "de.dennisguse.opentracks.publicapi.StartRecording");
getContext().startActivity(intent);
OpenTracksController.startRecording(getContext());
}
if (workoutRequest.optString("type").equals("req_distance")) {
workoutResponse.put("workoutApp._.config.gps", new JSONObject()
@ -1611,10 +1609,7 @@ public class FossilHRWatchAdapter extends FossilWatchAdapter {
.put("message", "")
.put("type", "success")
);
Intent intent = new Intent();
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setClassName("de.dennisguse.opentracks.debug", "de.dennisguse.opentracks.publicapi.StopRecording");
getContext().startActivity(intent);
OpenTracksController.stopRecording(getContext());
}
if (workoutRequest.optString("type").equals("req_route")) {
// Send the traveled route as an RLE encoded image (example name: 58270405)

View File

@ -141,6 +141,12 @@
android:layout="@layout/preference_checkbox"
android:summary="@string/pref_summary_location_keep_uptodate"
android:title="@string/pref_title_location_keep_uptodate" />
<EditTextPreference
android:inputType="text"
android:key="opentracks_packagename"
android:defaultValue="de.dennisguse.opentracks"
android:title="OpenTracks package name"
android:summary="Used for starting/stopping GPS track recording from certain wearables that don't have built-in GPS" />
</PreferenceCategory>
<PreferenceCategory android:title="@string/preferences_category_device_specific_settings">