diff --git a/code/src/Fitbot/app/src/main/java/com/example/fitbot/ui/activities/FitnessActivity.java b/code/src/Fitbot/app/src/main/java/com/example/fitbot/ui/activities/FitnessActivity.java index 8ab63fd..ebd7ab6 100644 --- a/code/src/Fitbot/app/src/main/java/com/example/fitbot/ui/activities/FitnessActivity.java +++ b/code/src/Fitbot/app/src/main/java/com/example/fitbot/ui/activities/FitnessActivity.java @@ -35,6 +35,7 @@ import com.example.fitbot.util.processing.InputProcessor; public class FitnessActivity extends RobotActivity implements RobotLifecycleCallbacks { + public static int progress = 1; // Private fields for the FitnessActivity class. private InputProcessor motionProcessor; private Exercise currentExercise; @@ -42,7 +43,6 @@ public class FitnessActivity extends RobotActivity implements RobotLifecycleCall // Progress circle for the exercises private ProgressBar progressCircle; private TextView progressText; - private int progress = 1; private final int maxProgress = 10; // Exercise status element data @@ -78,7 +78,7 @@ public class FitnessActivity extends RobotActivity implements RobotLifecycleCall QiSDK.register(this, this); setContentView(R.layout.activity_fitness); videoView = findViewById(R.id.videoView); - + ExerciseManager.TOTAL_REPETITIONS_PERFORMED = 0; // Fill empty objects with exercise data this.exerciseNameTextView = findViewById(R.id.textViewFitnessTitle); this.exerciseShortDescriptionTextView = findViewById(R.id.textViewFitnessShortDescription); @@ -190,6 +190,7 @@ public class FitnessActivity extends RobotActivity implements RobotLifecycleCall if (progress >= 10) { runOnUiThread(() -> NavigationManager.navigateToActivity(this, EndScreenActivity.class)); InputProcessor.exercisesRemaining = 1; + progress = 1; } } diff --git a/code/src/Fitbot/app/src/main/java/com/example/fitbot/util/processing/InputProcessor.java b/code/src/Fitbot/app/src/main/java/com/example/fitbot/util/processing/InputProcessor.java index 9d07109..263c636 100644 --- a/code/src/Fitbot/app/src/main/java/com/example/fitbot/util/processing/InputProcessor.java +++ b/code/src/Fitbot/app/src/main/java/com/example/fitbot/util/processing/InputProcessor.java @@ -25,7 +25,7 @@ import java.util.List; public class InputProcessor { - private List[] selfRotationVectorPaths = null; + private List[] selfRotationVectorPaths = new ArrayList[2]; // Relative path of the motion data private Vector3f[][] targetRotationVectorPaths; // Target path of the motion data @@ -78,11 +78,10 @@ public class InputProcessor { * Constructor for the motion processor. */ public InputProcessor(FitnessActivity parentActivity) { - this.parentActivity = parentActivity; - - // Initialize each ArrayList in the array this.selfRotationVectorPaths[0] = new ArrayList<>(); this.selfRotationVectorPaths[1] = new ArrayList<>(); + this.parentActivity = parentActivity; + // Initialize each ArrayList in the array } /** @@ -118,10 +117,11 @@ public class InputProcessor { while (exercisesRemaining > 0) { - if ( this.totalChecks == 0 || this.selfRotationVectorPaths == null - || this.selfRotationVectorPaths.length == 0 - || this.selfRotationVectorPaths[0].size() == 0 - || this.selfRotationVectorPaths[1].size() == 0) + if (this.totalChecks == 0 || this.selfRotationVectorPaths == null + || this.selfRotationVectorPaths.length == 0 + || this.selfRotationVectorPaths[0] == null + || this.selfRotationVectorPaths[0].size() == 0 + || this.selfRotationVectorPaths[1].size() == 0) continue; boolean isFaulty = this.isFaultyMovement(); @@ -134,8 +134,7 @@ public class InputProcessor { this.checksPerformed++; - if (this.checksPerformed >= this.totalChecks) - { + if (this.checksPerformed >= this.totalChecks) { this.checksPerformed = 0; this.exercisesRemaining--; acquireExercise(); @@ -244,9 +243,11 @@ public class InputProcessor { * incoming connections. */ public void startListening() { + this.selfRotationVectorPaths = new ArrayList[]{new ArrayList(), new ArrayList()}; // Create socket server this.server = WebServer.createServer(); - + // + FitnessActivity.progress = 1; Log.i("MotionProcessor", "Listening for incoming connections."); // Check if the socket @@ -264,8 +265,7 @@ public class InputProcessor { */ private void acquireExercise() { - if ( this.exercisesRemaining <= 0) - { + if (this.exercisesRemaining <= 0) { Log.i("InputProcessor", "Exercises finished"); this.parentActivity.runOnUiThread(() -> { NavigationManager.navigateToActivity(this.parentActivity, EndScreenActivity.class); @@ -430,28 +430,29 @@ public class InputProcessor { public boolean isFaultyMovement() { boolean upMovementDetected = false; boolean downMovementDetected = false; - + for (List path : selfRotationVectorPaths) { if (path.size() < 2) { continue; // Skip if there are not enough points to compare } - + Vector3f firstPoint = path.get(0); Vector3f lastPoint = path.get(path.size() - 1); - + float y1 = firstPoint.y; float y2 = lastPoint.y; - + if (y2 > y1) { upMovementDetected = true; } else if (y2 < y1) { downMovementDetected = true; } - + if (upMovementDetected && downMovementDetected) { return false; // Return false for faulty movement if both up and down movements are detected } } - + return true; // Return true for faulty movement if only up or down movement is detected - }} + } +}