mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-09-01 03:55:47 +02:00
Garmin: View and share gpx files
This commit is contained in:
parent
12ecfa0c4e
commit
49ef8c9f40
@ -49,6 +49,7 @@ import android.widget.TableRow;
|
|||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
import androidx.appcompat.app.AlertDialog;
|
import androidx.appcompat.app.AlertDialog;
|
||||||
import androidx.core.content.FileProvider;
|
import androidx.core.content.FileProvider;
|
||||||
|
|
||||||
@ -73,20 +74,24 @@ import java.util.Iterator;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.database.DBHandler;
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.database.DBHelper;
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.devices.DeviceCoordinator;
|
import nodomain.freeyourgadget.gadgetbridge.devices.DeviceCoordinator;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.entities.BaseActivitySummary;
|
import nodomain.freeyourgadget.gadgetbridge.entities.BaseActivitySummary;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession;
|
|
||||||
import nodomain.freeyourgadget.gadgetbridge.entities.Device;
|
import nodomain.freeyourgadget.gadgetbridge.entities.Device;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.export.ActivityTrackExporter;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.export.GPXExporter;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind;
|
import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.model.ActivityPoint;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.model.ActivitySummaryItems;
|
import nodomain.freeyourgadget.gadgetbridge.model.ActivitySummaryItems;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.model.ActivitySummaryJsonSummary;
|
import nodomain.freeyourgadget.gadgetbridge.model.ActivitySummaryJsonSummary;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.model.ActivitySummaryParser;
|
import nodomain.freeyourgadget.gadgetbridge.model.ActivitySummaryParser;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.model.ActivityTrack;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.fit.FitFile;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.service.devices.garmin.fit.messages.FitRecord;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.util.AndroidUtils;
|
import nodomain.freeyourgadget.gadgetbridge.util.AndroidUtils;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.util.DateTimeUtils;
|
import nodomain.freeyourgadget.gadgetbridge.util.DateTimeUtils;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.util.FileUtils;
|
import nodomain.freeyourgadget.gadgetbridge.util.FileUtils;
|
||||||
@ -141,7 +146,7 @@ public class ActivitySummaryDetail extends AbstractGBActivity {
|
|||||||
final long dateToFilter = bundle.getLong("dateToFilter", 0);
|
final long dateToFilter = bundle.getLong("dateToFilter", 0);
|
||||||
final long deviceFilter = bundle.getLong("deviceFilter", 0);
|
final long deviceFilter = bundle.getLong("deviceFilter", 0);
|
||||||
final String nameContainsFilter = bundle.getString("nameContainsFilter");
|
final String nameContainsFilter = bundle.getString("nameContainsFilter");
|
||||||
final List itemsFilter = (List<Long>) bundle.getSerializable("itemsFilter");
|
final List<Long> itemsFilter = (List<Long>) bundle.getSerializable("itemsFilter");
|
||||||
|
|
||||||
final ActivitySummaryItems items = new ActivitySummaryItems(this, gbDevice, activityFilter, dateFromFilter, dateToFilter, nameContainsFilter, deviceFilter, itemsFilter);
|
final ActivitySummaryItems items = new ActivitySummaryItems(this, gbDevice, activityFilter, dateFromFilter, dateToFilter, nameContainsFilter, deviceFilter, itemsFilter);
|
||||||
final ScrollView layout = findViewById(R.id.activity_summary_detail_scroll_layout);
|
final ScrollView layout = findViewById(R.id.activity_summary_detail_scroll_layout);
|
||||||
@ -184,11 +189,11 @@ public class ActivitySummaryDetail extends AbstractGBActivity {
|
|||||||
makeSummaryHeader(newItem);
|
makeSummaryHeader(newItem);
|
||||||
makeSummaryContent(newItem);
|
makeSummaryContent(newItem);
|
||||||
activitySummariesChartFragment.setDateAndGetData(getGBDevice(currentItem.getDevice()), currentItem.getStartTime().getTime() / 1000, currentItem.getEndTime().getTime() / 1000);
|
activitySummariesChartFragment.setDateAndGetData(getGBDevice(currentItem.getDevice()), currentItem.getStartTime().getTime() / 1000, currentItem.getEndTime().getTime() / 1000);
|
||||||
if (getTrackFile() != null) {
|
if (itemHasGps()) {
|
||||||
showCanvas();
|
showGpsCanvas();
|
||||||
activitySummariesGpsFragment.set_data(getTrackFile());
|
activitySummariesGpsFragment.set_data(getTrackFile());
|
||||||
} else {
|
} else {
|
||||||
hideCanvas();
|
hideGpsCanvas();
|
||||||
}
|
}
|
||||||
|
|
||||||
layout.startAnimation(animFadeRight);
|
layout.startAnimation(animFadeRight);
|
||||||
@ -206,11 +211,11 @@ public class ActivitySummaryDetail extends AbstractGBActivity {
|
|||||||
makeSummaryHeader(newItem);
|
makeSummaryHeader(newItem);
|
||||||
makeSummaryContent(newItem);
|
makeSummaryContent(newItem);
|
||||||
activitySummariesChartFragment.setDateAndGetData(getGBDevice(currentItem.getDevice()), currentItem.getStartTime().getTime() / 1000, currentItem.getEndTime().getTime() / 1000);
|
activitySummariesChartFragment.setDateAndGetData(getGBDevice(currentItem.getDevice()), currentItem.getStartTime().getTime() / 1000, currentItem.getEndTime().getTime() / 1000);
|
||||||
if (getTrackFile() != null) {
|
if (itemHasGps()) {
|
||||||
showCanvas();
|
showGpsCanvas();
|
||||||
activitySummariesGpsFragment.set_data(getTrackFile());
|
activitySummariesGpsFragment.set_data(getTrackFile());
|
||||||
} else {
|
} else {
|
||||||
hideCanvas();
|
hideGpsCanvas();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -227,11 +232,11 @@ public class ActivitySummaryDetail extends AbstractGBActivity {
|
|||||||
makeSummaryHeader(currentItem);
|
makeSummaryHeader(currentItem);
|
||||||
makeSummaryContent(currentItem);
|
makeSummaryContent(currentItem);
|
||||||
activitySummariesChartFragment.setDateAndGetData(getGBDevice(currentItem.getDevice()), currentItem.getStartTime().getTime() / 1000, currentItem.getEndTime().getTime() / 1000);
|
activitySummariesChartFragment.setDateAndGetData(getGBDevice(currentItem.getDevice()), currentItem.getStartTime().getTime() / 1000, currentItem.getEndTime().getTime() / 1000);
|
||||||
if (getTrackFile() != null) {
|
if (itemHasGps()) {
|
||||||
showCanvas();
|
showGpsCanvas();
|
||||||
activitySummariesGpsFragment.set_data(getTrackFile());
|
activitySummariesGpsFragment.set_data(getTrackFile());
|
||||||
} else {
|
} else {
|
||||||
hideCanvas();
|
hideGpsCanvas();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -320,11 +325,11 @@ public class ActivitySummaryDetail extends AbstractGBActivity {
|
|||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
currentItem.setGpxTrack(selectedGpxFile);
|
currentItem.setGpxTrack(selectedGpxFile);
|
||||||
currentItem.update();
|
currentItem.update();
|
||||||
if (getTrackFile() != null) {
|
if (itemHasGps()) {
|
||||||
showCanvas();
|
showGpsCanvas();
|
||||||
activitySummariesGpsFragment.set_data(getTrackFile());
|
activitySummariesGpsFragment.set_data(getTrackFile());
|
||||||
} else {
|
} else {
|
||||||
hideCanvas();
|
hideGpsCanvas();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -590,14 +595,14 @@ public class ActivitySummaryDetail extends AbstractGBActivity {
|
|||||||
|
|
||||||
private void take_share_screenshot(Context context) {
|
private void take_share_screenshot(Context context) {
|
||||||
final ScrollView layout = findViewById(R.id.activity_summary_detail_scroll_layout);
|
final ScrollView layout = findViewById(R.id.activity_summary_detail_scroll_layout);
|
||||||
int width = layout.getChildAt(0).getHeight();
|
final int width = layout.getChildAt(0).getWidth();
|
||||||
int height = layout.getChildAt(0).getWidth();
|
final int height = layout.getChildAt(0).getHeight();
|
||||||
Bitmap screenShot = getScreenShot(layout, width, height, context);
|
final Bitmap screenShot = getScreenShot(layout, height, width, context);
|
||||||
|
|
||||||
String fileName = FileUtils.makeValidFileName("Screenshot-" + ActivityKind.fromCode(currentItem.getActivityKind()).getLabel(context).toLowerCase() + "-" + DateTimeUtils.formatIso8601(currentItem.getStartTime()) + ".png");
|
final String fileName = FileUtils.makeValidFileName("Screenshot-" + ActivityKind.fromCode(currentItem.getActivityKind()).getLabel(context).toLowerCase() + "-" + DateTimeUtils.formatIso8601(currentItem.getStartTime()) + ".png");
|
||||||
try {
|
try {
|
||||||
File targetFile = new File(FileUtils.getExternalFilesDir(), fileName);
|
final File targetFile = new File(FileUtils.getExternalFilesDir(), fileName);
|
||||||
FileOutputStream fOut = new FileOutputStream(targetFile);
|
final FileOutputStream fOut = new FileOutputStream(targetFile);
|
||||||
screenShot.compress(Bitmap.CompressFormat.PNG, 85, fOut);
|
screenShot.compress(Bitmap.CompressFormat.PNG, 85, fOut);
|
||||||
fOut.flush();
|
fOut.flush();
|
||||||
fOut.close();
|
fOut.close();
|
||||||
@ -626,27 +631,70 @@ public class ActivitySummaryDetail extends AbstractGBActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void viewGpxTrack(Context context) {
|
private void viewGpxTrack(Context context) {
|
||||||
final String gpxTrack = currentItem.getGpxTrack();
|
final File trackFile = getTrackFile();
|
||||||
|
if (trackFile == null) {
|
||||||
|
GB.toast(getApplicationContext(), "No GPX track in this activity", Toast.LENGTH_LONG, GB.INFO);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (gpxTrack != null) {
|
|
||||||
try {
|
try {
|
||||||
AndroidUtils.viewFile(gpxTrack, "application/gpx+xml", context);
|
if (trackFile.getName().endsWith(".gpx")) {
|
||||||
} catch (IOException e) {
|
AndroidUtils.viewFile(trackFile.getPath(), "application/gpx+xml", context);
|
||||||
|
} else if (trackFile.getName().endsWith(".fit")) {
|
||||||
|
final File gpxFile = convertFitToGpx(trackFile);
|
||||||
|
AndroidUtils.viewFile(gpxFile.getPath(), "application/gpx+xml", context);
|
||||||
|
} else {
|
||||||
|
GB.toast(getApplicationContext(), "Unknown track format", Toast.LENGTH_LONG, GB.INFO);
|
||||||
|
}
|
||||||
|
} catch (final Exception e) {
|
||||||
GB.toast(getApplicationContext(), "Unable to display GPX track: " + e.getMessage(), Toast.LENGTH_LONG, GB.ERROR, e);
|
GB.toast(getApplicationContext(), "Unable to display GPX track: " + e.getMessage(), Toast.LENGTH_LONG, GB.ERROR, e);
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
GB.toast(getApplicationContext(), "No GPX track in this activity", Toast.LENGTH_LONG, GB.INFO);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void shareGpxTrack(final Context context, final BaseActivitySummary summary) {
|
private void shareGpxTrack(final Context context, final BaseActivitySummary summary) {
|
||||||
|
final File trackFile = getTrackFile();
|
||||||
|
if (trackFile == null) {
|
||||||
|
GB.toast(getApplicationContext(), "No GPX track in this activity", Toast.LENGTH_LONG, GB.INFO);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
AndroidUtils.shareFile(context, new File(summary.getGpxTrack()));
|
if (trackFile.getName().endsWith(".gpx")) {
|
||||||
|
AndroidUtils.shareFile(context, trackFile);
|
||||||
|
} else if (trackFile.getName().endsWith(".fit")) {
|
||||||
|
final File gpxFile = convertFitToGpx(trackFile);
|
||||||
|
AndroidUtils.shareFile(context, gpxFile);
|
||||||
|
} else {
|
||||||
|
GB.toast(getApplicationContext(), "Unknown track format", Toast.LENGTH_LONG, GB.INFO);
|
||||||
|
}
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
GB.toast(context, "Unable to share GPX track: " + e.getMessage(), Toast.LENGTH_LONG, GB.ERROR, e);
|
GB.toast(context, "Unable to share GPX track: " + e.getMessage(), Toast.LENGTH_LONG, GB.ERROR, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private File convertFitToGpx(final File file) throws IOException, ActivityTrackExporter.GPXTrackEmptyException {
|
||||||
|
final FitFile fitFile = FitFile.parseIncoming(file);
|
||||||
|
final List<ActivityPoint> activityPoints = fitFile.getRecords().stream()
|
||||||
|
.filter(r -> r instanceof FitRecord)
|
||||||
|
.map(r -> ((FitRecord) r).toActivityPoint())
|
||||||
|
.filter(ap -> ap.getLocation() != null)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
final ActivityTrack activityTrack = new ActivityTrack();
|
||||||
|
activityTrack.setName(currentItem.getName());
|
||||||
|
activityTrack.addTrackPoints(activityPoints);
|
||||||
|
|
||||||
|
final File cacheDir = getCacheDir();
|
||||||
|
final File rawCacheDir = new File(cacheDir, "gpx");
|
||||||
|
rawCacheDir.mkdir();
|
||||||
|
final File gpxFile = new File(rawCacheDir, file.getName().replace(".fit", ".gpx"));
|
||||||
|
|
||||||
|
final GPXExporter gpxExporter = new GPXExporter();
|
||||||
|
gpxExporter.performExport(activityTrack, gpxFile);
|
||||||
|
|
||||||
|
return gpxFile;
|
||||||
|
}
|
||||||
|
|
||||||
private static void shareRawSummary(final Context context, final BaseActivitySummary summary) {
|
private static void shareRawSummary(final Context context, final BaseActivitySummary summary) {
|
||||||
if (summary.getRawSummaryData() == null) {
|
if (summary.getRawSummaryData() == null) {
|
||||||
GB.toast(context, "No raw summary in this activity", Toast.LENGTH_LONG, GB.WARN);
|
GB.toast(context, "No raw summary in this activity", Toast.LENGTH_LONG, GB.WARN);
|
||||||
@ -681,7 +729,7 @@ public class ActivitySummaryDetail extends AbstractGBActivity {
|
|||||||
boolean hasRawDetails = false;
|
boolean hasRawDetails = false;
|
||||||
|
|
||||||
if (currentItem != null) {
|
if (currentItem != null) {
|
||||||
hasGpx = currentItem.getGpxTrack() != null;
|
hasGpx = itemHasGps();
|
||||||
hasRawSummary = currentItem.getRawSummaryData() != null;
|
hasRawSummary = currentItem.getRawSummaryData() != null;
|
||||||
|
|
||||||
final String rawDetailsPath = currentItem.getRawDetailsPath();
|
final String rawDetailsPath = currentItem.getRawDetailsPath();
|
||||||
@ -698,20 +746,40 @@ public class ActivitySummaryDetail extends AbstractGBActivity {
|
|||||||
devToolsMenu.setVisible(devToolsMenu.getSubMenu().hasVisibleItems());
|
devToolsMenu.setVisible(devToolsMenu.getSubMenu().hasVisibleItems());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showCanvas() {
|
private void showGpsCanvas() {
|
||||||
View gpsView = findViewById(R.id.gpsFragmentHolder);
|
final View gpsView = findViewById(R.id.gpsFragmentHolder);
|
||||||
ViewGroup.LayoutParams params = gpsView.getLayoutParams();
|
final ViewGroup.LayoutParams params = gpsView.getLayoutParams();
|
||||||
params.height = (int) (300 * getApplicationContext().getResources().getDisplayMetrics().density);
|
params.height = (int) (300 * getApplicationContext().getResources().getDisplayMetrics().density);
|
||||||
gpsView.setLayoutParams(params);
|
gpsView.setLayoutParams(params);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void hideCanvas() {
|
private void hideGpsCanvas() {
|
||||||
View gpsView = findViewById(R.id.gpsFragmentHolder);
|
final View gpsView = findViewById(R.id.gpsFragmentHolder);
|
||||||
ViewGroup.LayoutParams params = gpsView.getLayoutParams();
|
final ViewGroup.LayoutParams params = gpsView.getLayoutParams();
|
||||||
params.height = 0;
|
params.height = 0;
|
||||||
gpsView.setLayoutParams(params);
|
gpsView.setLayoutParams(params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean itemHasGps() {
|
||||||
|
if (currentItem.getGpxTrack() != null) {
|
||||||
|
return new File(currentItem.getGpxTrack()).canRead();
|
||||||
|
}
|
||||||
|
final String summaryData = currentItem.getSummaryData();
|
||||||
|
if (summaryData.contains(INTERNAL_HAS_GPS)) {
|
||||||
|
try {
|
||||||
|
final JSONObject summaryDataObject = new JSONObject(summaryData);
|
||||||
|
final JSONObject internalHasGps = summaryDataObject.getJSONObject(INTERNAL_HAS_GPS);
|
||||||
|
return "true".equals(internalHasGps.optString("value", "false"));
|
||||||
|
} catch (final JSONException e) {
|
||||||
|
LOG.error("Failed to parse summary data json", e);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
private File getTrackFile() {
|
private File getTrackFile() {
|
||||||
final String gpxTrack = currentItem.getGpxTrack();
|
final String gpxTrack = currentItem.getGpxTrack();
|
||||||
if (gpxTrack != null) {
|
if (gpxTrack != null) {
|
||||||
@ -734,9 +802,8 @@ public class ActivitySummaryDetail extends AbstractGBActivity {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onCreateOptionsMenu(Menu menu) {
|
public boolean onCreateOptionsMenu(final Menu menu) {
|
||||||
super.onCreateOptionsMenu(menu);
|
super.onCreateOptionsMenu(menu);
|
||||||
mOptionsMenu = menu;
|
mOptionsMenu = menu;
|
||||||
getMenuInflater().inflate(R.menu.activity_take_screenshot_menu, menu);
|
getMenuInflater().inflate(R.menu.activity_take_screenshot_menu, menu);
|
||||||
@ -744,21 +811,12 @@ public class ActivitySummaryDetail extends AbstractGBActivity {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private GBDevice getGBDevice(Device findDevice) {
|
@Nullable
|
||||||
DaoSession daoSession;
|
private static GBDevice getGBDevice(final Device findDevice) {
|
||||||
GBApplication gbApp = (GBApplication) getApplicationContext();
|
return GBApplication.app().getDeviceManager().getDevices()
|
||||||
List<? extends GBDevice> devices = gbApp.getDeviceManager().getDevices();
|
.stream()
|
||||||
|
.filter(d -> d.getAddress().equalsIgnoreCase(findDevice.getIdentifier()))
|
||||||
try (DBHandler handler = GBApplication.acquireDB()) {
|
.findFirst()
|
||||||
daoSession = handler.getDaoSession();
|
.orElse(null);
|
||||||
for (GBDevice device : devices) {
|
|
||||||
Device dbDevice = DBHelper.findDevice(device, daoSession);
|
|
||||||
if (dbDevice.equals(findDevice)) return device;
|
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
|
||||||
LOG.debug("Error getting device: " + e);
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -250,6 +250,11 @@ public class GarminWorkoutParser implements ActivitySummaryParser {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
summaryData.add(
|
||||||
|
INTERNAL_HAS_GPS,
|
||||||
|
String.valueOf(activityPoints.stream().anyMatch(p -> p.getLocation() != null))
|
||||||
|
);
|
||||||
|
|
||||||
summary.setSummaryData(summaryData.toString());
|
summary.setSummaryData(summaryData.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,7 +33,9 @@ import java.util.Date;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.activities.HeartRateUtils;
|
import nodomain.freeyourgadget.gadgetbridge.activities.HeartRateUtils;
|
||||||
|
import nodomain.freeyourgadget.gadgetbridge.entities.User;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.model.ActivityPoint;
|
import nodomain.freeyourgadget.gadgetbridge.model.ActivityPoint;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.model.ActivityTrack;
|
import nodomain.freeyourgadget.gadgetbridge.model.ActivityTrack;
|
||||||
import nodomain.freeyourgadget.gadgetbridge.model.GPSCoordinate;
|
import nodomain.freeyourgadget.gadgetbridge.model.GPSCoordinate;
|
||||||
@ -68,7 +70,11 @@ public class GPXExporter implements ActivityTrackExporter {
|
|||||||
|
|
||||||
ser.startTag(NS_GPX_URI, "gpx");
|
ser.startTag(NS_GPX_URI, "gpx");
|
||||||
ser.attribute(null, "version", "1.1");
|
ser.attribute(null, "version", "1.1");
|
||||||
ser.attribute(null, "creator", getCreator());
|
if (creator != null) {
|
||||||
|
ser.attribute(null, "creator", creator);
|
||||||
|
} else {
|
||||||
|
ser.attribute(null, "creator", GBApplication.app().getNameAndVersion());
|
||||||
|
}
|
||||||
ser.attribute(NS_XSI_URI, "schemaLocation", NS_GPX_URI + " "
|
ser.attribute(NS_XSI_URI, "schemaLocation", NS_GPX_URI + " "
|
||||||
+ TOPOGRAFIX_NAMESPACE_XSD + " "
|
+ TOPOGRAFIX_NAMESPACE_XSD + " "
|
||||||
+ OPENTRACKS_NAMESPACE_URI + " " + OPENTRACKS_NAMESPACE_XSD);
|
+ OPENTRACKS_NAMESPACE_URI + " " + OPENTRACKS_NAMESPACE_XSD);
|
||||||
@ -84,11 +90,16 @@ public class GPXExporter implements ActivityTrackExporter {
|
|||||||
|
|
||||||
private void exportMetadata(XmlSerializer ser, ActivityTrack track) throws IOException {
|
private void exportMetadata(XmlSerializer ser, ActivityTrack track) throws IOException {
|
||||||
ser.startTag(NS_GPX_URI, "metadata");
|
ser.startTag(NS_GPX_URI, "metadata");
|
||||||
|
if (track.getName() != null) {
|
||||||
ser.startTag(NS_GPX_URI, "name").text(track.getName()).endTag(NS_GPX_URI, "name");
|
ser.startTag(NS_GPX_URI, "name").text(track.getName()).endTag(NS_GPX_URI, "name");
|
||||||
|
}
|
||||||
|
|
||||||
|
final User user = track.getUser();
|
||||||
|
if (user != null) {
|
||||||
ser.startTag(NS_GPX_URI, "author");
|
ser.startTag(NS_GPX_URI, "author");
|
||||||
ser.startTag(NS_GPX_URI, "name").text(track.getUser().getName()).endTag(NS_GPX_URI, "name");
|
ser.startTag(NS_GPX_URI, "name").text(user.getName()).endTag(NS_GPX_URI, "name");
|
||||||
ser.endTag(NS_GPX_URI, "author");
|
ser.endTag(NS_GPX_URI, "author");
|
||||||
|
}
|
||||||
|
|
||||||
ser.startTag(NS_GPX_URI, "time").text(formatTime(new Date())).endTag(NS_GPX_URI, "time");
|
ser.startTag(NS_GPX_URI, "time").text(formatTime(new Date())).endTag(NS_GPX_URI, "time");
|
||||||
|
|
||||||
@ -107,7 +118,6 @@ public class GPXExporter implements ActivityTrackExporter {
|
|||||||
ser.endTag(NS_GPX_URI, "extensions");
|
ser.endTag(NS_GPX_URI, "extensions");
|
||||||
|
|
||||||
List<List<ActivityPoint>> segments = track.getSegments();
|
List<List<ActivityPoint>> segments = track.getSegments();
|
||||||
String source = getSource(track);
|
|
||||||
boolean atLeastOnePointExported = false;
|
boolean atLeastOnePointExported = false;
|
||||||
for (List<ActivityPoint> segment : segments) {
|
for (List<ActivityPoint> segment : segments) {
|
||||||
if (segment.isEmpty()) {
|
if (segment.isEmpty()) {
|
||||||
@ -117,7 +127,7 @@ public class GPXExporter implements ActivityTrackExporter {
|
|||||||
|
|
||||||
ser.startTag(NS_GPX_URI, "trkseg");
|
ser.startTag(NS_GPX_URI, "trkseg");
|
||||||
for (ActivityPoint point : segment) {
|
for (ActivityPoint point : segment) {
|
||||||
atLeastOnePointExported |= exportTrackPoint(ser, point, source, segment);
|
atLeastOnePointExported |= exportTrackPoint(ser, point, segment);
|
||||||
}
|
}
|
||||||
ser.endTag(NS_GPX_URI, "trkseg");
|
ser.endTag(NS_GPX_URI, "trkseg");
|
||||||
}
|
}
|
||||||
@ -129,11 +139,7 @@ public class GPXExporter implements ActivityTrackExporter {
|
|||||||
ser.endTag(NS_GPX_URI, "trk");
|
ser.endTag(NS_GPX_URI, "trk");
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getSource(ActivityTrack track) {
|
private boolean exportTrackPoint(XmlSerializer ser, ActivityPoint point, List<ActivityPoint> trackPoints) throws IOException {
|
||||||
return track.getDevice().getName();
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean exportTrackPoint(XmlSerializer ser, ActivityPoint point, String source, List<ActivityPoint> trackPoints) throws IOException {
|
|
||||||
GPSCoordinate location = point.getLocation();
|
GPSCoordinate location = point.getLocation();
|
||||||
if (location == null) {
|
if (location == null) {
|
||||||
return false; // skip invalid points, that just contain hr data, for example
|
return false; // skip invalid points, that just contain hr data, for example
|
||||||
|
@ -140,4 +140,11 @@ public class ActivitySummaryEntries {
|
|||||||
public static final String UNIT_DEGREES = "degrees";
|
public static final String UNIT_DEGREES = "degrees";
|
||||||
|
|
||||||
public static final String GROUP_PACE = "Pace";
|
public static final String GROUP_PACE = "Pace";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Used to signal that this activity has a gps track. This is currently used by ActivitySummaryDetail
|
||||||
|
* to display the share and view gpx buttons, even though there's no gpx file.
|
||||||
|
* FIXME: We should have a cleaner way of doing this.
|
||||||
|
*/
|
||||||
|
public static final String INTERNAL_HAS_GPS = "internal_hasGps";
|
||||||
}
|
}
|
||||||
|
@ -132,6 +132,9 @@ public class ActivitySummaryJsonSummary {
|
|||||||
|
|
||||||
while (keys.hasNext()) {
|
while (keys.hasNext()) {
|
||||||
String key = keys.next();
|
String key = keys.next();
|
||||||
|
if (INTERNAL_HAS_GPS.equals(key)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
JSONObject innerData = (JSONObject) summaryDatalist.get(key);
|
JSONObject innerData = (JSONObject) summaryDatalist.get(key);
|
||||||
Object value = innerData.get("value");
|
Object value = innerData.get("value");
|
||||||
|
@ -575,7 +575,7 @@ class BangleJSActivityTrack {
|
|||||||
point = new ActivityPoint();
|
point = new ActivityPoint();
|
||||||
}
|
}
|
||||||
|
|
||||||
ActivityTrackExporter exporter = createExporter();
|
ActivityTrackExporter exporter = new GPXExporter();
|
||||||
String trackType = "track";
|
String trackType = "track";
|
||||||
switch (ActivityKind.fromCode(summary.getActivityKind())) {
|
switch (ActivityKind.fromCode(summary.getActivityKind())) {
|
||||||
case CYCLING:
|
case CYCLING:
|
||||||
@ -812,12 +812,6 @@ class BangleJSActivityTrack {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ActivityTrackExporter createExporter() {
|
|
||||||
GPXExporter exporter = new GPXExporter();
|
|
||||||
exporter.setCreator(GBApplication.app().getNameAndVersion());
|
|
||||||
return exporter;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static JSONObject addSummaryData(JSONObject summaryData, String key, float value, String unit) {
|
private static JSONObject addSummaryData(JSONObject summaryData, String key, float value, String unit) {
|
||||||
if (value > 0) {
|
if (value > 0) {
|
||||||
try {
|
try {
|
||||||
|
@ -544,7 +544,6 @@ public class CmfActivitySync {
|
|||||||
@Nullable
|
@Nullable
|
||||||
private File exportGpx(final BaseActivitySummary summary, final ActivityTrack activityTrack) {
|
private File exportGpx(final BaseActivitySummary summary, final ActivityTrack activityTrack) {
|
||||||
final GPXExporter exporter = new GPXExporter();
|
final GPXExporter exporter = new GPXExporter();
|
||||||
exporter.setCreator(GBApplication.app().getNameAndVersion());
|
|
||||||
|
|
||||||
final String gpxFileName = FileUtils.makeValidFileName("gadgetbridge-" + DateTimeUtils.formatIso8601(summary.getStartTime()) + ".gpx");
|
final String gpxFileName = FileUtils.makeValidFileName("gadgetbridge-" + DateTimeUtils.formatIso8601(summary.getStartTime()) + ".gpx");
|
||||||
final File gpxTargetFile;
|
final File gpxTargetFile;
|
||||||
|
@ -97,7 +97,7 @@ public class FetchSportsDetailsOperation extends AbstractFetchOperation {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
final ActivityTrack track = detailsParser.parse(buffer.toByteArray());
|
final ActivityTrack track = detailsParser.parse(buffer.toByteArray());
|
||||||
final ActivityTrackExporter exporter = createExporter();
|
final ActivityTrackExporter exporter = new GPXExporter();
|
||||||
final String trackType;
|
final String trackType;
|
||||||
switch (ActivityKind.fromCode(summary.getActivityKind())) {
|
switch (ActivityKind.fromCode(summary.getActivityKind())) {
|
||||||
case CYCLING:
|
case CYCLING:
|
||||||
@ -183,12 +183,6 @@ public class FetchSportsDetailsOperation extends AbstractFetchOperation {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ActivityTrackExporter createExporter() {
|
|
||||||
final GPXExporter exporter = new GPXExporter();
|
|
||||||
exporter.setCreator(GBApplication.app().getNameAndVersion());
|
|
||||||
return exporter;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String getLastSyncTimeKey() {
|
protected String getLastSyncTimeKey() {
|
||||||
return lastSyncTimeKey;
|
return lastSyncTimeKey;
|
||||||
|
@ -118,7 +118,6 @@ public class WorkoutGpsParser extends XiaomiActivityParser {
|
|||||||
|
|
||||||
// Save the gpx file
|
// Save the gpx file
|
||||||
final GPXExporter exporter = new GPXExporter();
|
final GPXExporter exporter = new GPXExporter();
|
||||||
exporter.setCreator(GBApplication.app().getNameAndVersion());
|
|
||||||
|
|
||||||
final String gpxFileName = FileUtils.makeValidFileName("gadgetbridge-" + DateTimeUtils.formatIso8601(fileId.getTimestamp()) + ".gpx");
|
final String gpxFileName = FileUtils.makeValidFileName("gadgetbridge-" + DateTimeUtils.formatIso8601(fileId.getTimestamp()) + ".gpx");
|
||||||
final File gpxTargetFile = new File(FileUtils.getExternalFilesDir(), gpxFileName);
|
final File gpxTargetFile = new File(FileUtils.getExternalFilesDir(), gpxFileName);
|
||||||
|
@ -4,4 +4,5 @@
|
|||||||
<external-path name="external_files" path="."/>
|
<external-path name="external_files" path="."/>
|
||||||
<files-path name="gpx" path="./" />
|
<files-path name="gpx" path="./" />
|
||||||
<cache-path name="raw" path="raw/" />
|
<cache-path name="raw" path="raw/" />
|
||||||
|
<cache-path name="gpx" path="gpx/" />
|
||||||
</paths>
|
</paths>
|
||||||
|
Loading…
Reference in New Issue
Block a user