This commit is contained in:
JZITNIK-github 2024-07-05 18:13:24 +02:00
commit ea5a1c1a5d
Signed by: jzitnik
GPG Key ID: C577A802A6AF4EF3
8 changed files with 152 additions and 0 deletions

3
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,3 @@
{
"java.configuration.updateBuildConfiguration": "interactive"
}

25
pom.xml Normal file
View File

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>cz.jzitnik</groupId>
<artifactId>fit</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>com.garmin</groupId>
<artifactId>fit</artifactId>
<version>21.141.0</version>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,59 @@
package cz.jzitnik;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.Scanner;
import com.garmin.fit.*;
class CustomFitListener implements MesgListener {
private List<Mesg> messages = new ArrayList<>();
@Override
public void onMesg(Mesg mesg) {
messages.add(mesg);
}
public void modifyData() {
for (int i = 0; i < messages.size(); i++) {
Mesg mesg = messages.get(i);
if (mesg.getNum() == MesgNum.EVENT) {
EventMesg eventMesg = new EventMesg(mesg);
if (eventMesg.getEventType() == EventType.STOP_ALL) {
Scanner scanner = new Scanner(System.in);
System.out.print("Rok: ");
int year = Integer.parseInt(scanner.nextLine());
System.out.print("Měsíc: ");
int month = Integer.parseInt(scanner.nextLine()) - 1;
System.out.print("Den: ");
int day = Integer.parseInt(scanner.nextLine());
System.out.print("Hodina: ");
int hour = Integer.parseInt(scanner.nextLine());
System.out.print("Minuta: ");
int minute = Integer.parseInt(scanner.nextLine());
System.out.print("Sekunda: ");
int second = Integer.parseInt(scanner.nextLine());
Calendar calendar = Calendar.getInstance();
calendar.set(year, month, day, hour, minute, second);
Date date = calendar.getTime();
DateTime dateTime = new DateTime(date);
eventMesg.setTimestamp(dateTime);
messages.set(i, eventMesg);
}
}
}
}
public List<Mesg> getMessages() {
return messages;
}
}

View File

@ -0,0 +1,32 @@
package cz.jzitnik;
import java.io.FileInputStream;
import java.io.IOException;
import com.garmin.fit.*;
import com.garmin.fit.Fit.ProtocolVersion;
public class Editor {
public static void edit(String inputFilePath, String outputFilePath) throws IOException {
FileInputStream inputStream = new FileInputStream(inputFilePath);
Decode decode = new Decode();
MesgBroadcaster mesgBroadcaster = new MesgBroadcaster(decode);
CustomFitListener listener = new CustomFitListener();
mesgBroadcaster.addListener(listener);
decode.read(inputStream, mesgBroadcaster, mesgBroadcaster);
inputStream.close();
listener.modifyData();
FileEncoder fileEncoder = new FileEncoder(new java.io.File(outputFilePath), ProtocolVersion.V1_0);
for (Mesg mesg : listener.getMessages()) {
fileEncoder.write(mesg);
}
fileEncoder.close();
System.out.println("Soubor byl úspěšně upraven.");
}
}

View File

@ -0,0 +1,33 @@
package cz.jzitnik;
import java.io.IOException;
import javax.swing.JFileChooser;
public class Main {
public static void main(String[] args) throws IOException {
JFileChooser fileChooser = new JFileChooser();
int returnValue = fileChooser.showOpenDialog(null);
if (returnValue != JFileChooser.APPROVE_OPTION) {
return;
}
java.io.File fromFile = fileChooser.getSelectedFile();
JFileChooser fileSaveChooser = new JFileChooser();
fileSaveChooser.setDialogType(JFileChooser.SAVE_DIALOG);
int returnValueSave = fileSaveChooser.showSaveDialog(null);
if (returnValueSave != JFileChooser.APPROVE_OPTION) {
return;
}
java.io.File toFile = fileSaveChooser.getSelectedFile();
Editor.edit(fromFile.getAbsolutePath(), toFile.getAbsolutePath());
}
}

Binary file not shown.

Binary file not shown.

Binary file not shown.