2024-05-29 15:15:14 +02:00
4 changed files with 23 additions and 1 deletions

View File

@@ -91,6 +91,7 @@ public class FitnessActivity extends RobotActivity implements RobotLifecycleCall
@Override
protected void onDestroy() {
super.onDestroy();
QiSDK.unregister(this,this);
QiSDK.unregister(this, this);
this.personalMotionPreviewElement.onDestroy();
}
}

View File

@@ -94,6 +94,14 @@ public class PersonalMotionPreviewElement extends View {
this.paths = exercise.getPath();
}
public void onDestroy()
{
if ( this.motionProcessor != null )
this.motionProcessor.stopListening();
this.motionProcessor = null;
}
/**
* Function for providing a QiContext to the PersonalMotionPreviewElement.
* This function will be called by the parent activity when the QiContext is available.

View File

@@ -71,6 +71,9 @@ public class MotionProcessor {
public void parsePacket(@NotNull String data) {
try {
Log.i("MotionProcessor", "Received packet data: " + data);
JsonElement json = JsonParser.parseString(data);
if (!json.isJsonObject())
@@ -106,6 +109,7 @@ public class MotionProcessor {
addMotionData(motionData);
} catch (Exception e) {
// Don't do anything ... just ignore the exception
Log.i("MotionProcessor", "Failed to parse packet data.");
}
}

View File

@@ -6,6 +6,7 @@ import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.Socket;
@@ -63,6 +64,7 @@ public class WebServer implements Runnable {
// Find a new connection
Socket newSocket = this.serverSocket.accept();
InputStream streamIn = newSocket.getInputStream();
OutputStream streamOut = newSocket.getOutputStream();
// Read the incoming data
BufferedReader reader = new BufferedReader(new InputStreamReader(streamIn));
@@ -71,7 +73,14 @@ public class WebServer implements Runnable {
while ((line = reader.readLine()) != null)
builder.append(line).append("\n");
// Send generic message back
streamOut.write("HTTP/1.1 200 OK\n".getBytes());
streamOut.write("Content-Type: text/html\n".getBytes());
streamOut.write("Connection: close\n".getBytes());
streamIn.close(); // Closes the reader, stream and socket connection.
streamOut.close();
newSocket.close();
String[] data = builder.toString().split("\n\n");