Merge branch 'main' of ssh://gitlab.fdmci.hva.nl/propedeuse-hbo-ict/onderwijs/2023-2024/out-a-se-ti/blok-4/muupooviixee66

This commit is contained in:
SebasKoedam
2024-06-05 15:07:26 +02:00
2 changed files with 19 additions and 37 deletions

View File

@@ -128,16 +128,13 @@ public class FitnessActivity extends RobotActivity implements RobotLifecycleCall
// Acquire paths from the exercise and provide them to the motion processor
motionProcessor = new InputProcessor(this);
motionProcessor.useExercise(exercise);
/* TODO: Remove if not needed */
motionProcessor.setRecording(true, 10);
motionProcessor.startListening();
}, (n) -> {
int randomMessageIndex = (int) Math.floor(Math.random() * EXERCISE_NOT_FOUND_MESSAGES.length);
Pepper.say(EXERCISE_NOT_FOUND_MESSAGES[randomMessageIndex]);
Pepper.say(EXERCISE_NOT_FOUND_SEEK_HELP_MESSAGE);
NavigationManager.navigateToActivity(this, EndScreenActivity.class);
// Run on main thread to prevent crashes (wack)
this.runOnUiThread(() -> NavigationManager.navigateToActivity(this, EndScreenActivity.class));
});
}
@@ -152,10 +149,14 @@ public class FitnessActivity extends RobotActivity implements RobotLifecycleCall
new Thread(() -> {
Exercise exercise = ExerciseManager.fetchExerciseFromDatabase();
if (exercise == null) {
runOnUiThread(() -> onFailedFetch.handle(null));
onFailedFetch.handle(null);
// Main thread stuff
runOnUiThread(() -> NavigationManager.navigateToActivity(this, MainActivity.class));
} else {
onSuccessfulFetch.handle(exercise);
runOnUiThread(() -> {
exerciseNameTextView.setText(exercise.name);
exerciseShortDescriptionTextView.setText(exercise.shortDescription);
// exerciseDescriptionTextView.setText(exercise.description);
@@ -171,25 +172,10 @@ public class FitnessActivity extends RobotActivity implements RobotLifecycleCall
loadingCircle.setVisibility(View.GONE);
if ( videoView.isPlaying() )
{
QiContext qiContext = null;
Animation animationarmraise = AnimationBuilder.with(qiContext) // Create the builder with the context.
.withResources(R.raw.armraise) // Set the animation resource.
.build(); // Build the animation.
animate = AnimateBuilder.with(qiContext) // Create the builder with the context.
.withAnimation(animationarmraise) // Set the animation.
.build(); // Build the animate action.
Future<Void> animateFuture = animate.async().run();
}
else
{
Log.e("FitnessActivity", "VideoView is null. Check your layout XML.");
}
Pepper.animate("armraise");
// Start checking for user movement once the video has loaded
this.motionProcessor.startListening();
this.motionProcessor.startCheckingUserMovement();
return true;

View File

@@ -101,21 +101,19 @@ public class InputProcessor {
* This function will start a thread that will check for user movement
* and compare the last rotation vectors to the target rotation vectors.
*/
public void startCheckingUserMovement()
{
public void startCheckingUserMovement() {
// Error checking thread.
(new Thread(() -> {
while (this.exercisesRemaining > 0)
{
while (this.exercisesRemaining > 0) {
boolean isFaulty = this.isFaultyMovement();
if ( isFaulty ) {
if (isFaulty) {
this.onInadequateRepetition();
} else this.onAdequateRepetition();
this.checksPerformed++;
if ( this.checksPerformed >= this.totalChecks )
if (this.checksPerformed >= this.totalChecks)
acquireExercise();
try {
@@ -134,7 +132,9 @@ public class InputProcessor {
*/
private void nextExercise(Exercise exercise) {
if (this.exercisesRemaining-- <= 0) {
NavigationManager.navigateToActivity(this.parentActivity, EndScreenActivity.class);
// Move to end screen on main activity
this.parentActivity.runOnUiThread(() -> NavigationManager.navigateToActivity(this.parentActivity, EndScreenActivity.class));
return;
}
@@ -230,14 +230,12 @@ public class InputProcessor {
* Function for acquiring the next exercise from the database.
* Upon successful retrieval, it will call the nextExercise method.
*/
private void acquireExercise()
{
private void acquireExercise() {
this.exercisesRemaining--;
this.parentActivity.fetchExerciseAsync(this::nextExercise, (nil) -> {
Log.i("MotionProcessor", "Failed to fetch exercise data.");
NavigationManager.navigateToActivity(this.parentActivity, MainActivity.class);
});
}
@@ -397,8 +395,7 @@ public class InputProcessor {
int i, referenceIndex;
float distance;
for ( i = 0; i < selfRotationVectorPaths.length; i++)
{
for (i = 0; i < selfRotationVectorPaths.length; i++) {
referenceIndex = (int) (Math.round(
((this.secondsPassed % this.exerciseRepetitionDurationInSeconds) /
(this.exerciseRepetitionDurationInSeconds)) * this.targetRotationVectorPaths[i].length))
@@ -407,8 +404,7 @@ public class InputProcessor {
distance = this.selfRotationVectorPaths[i].get(this.selfRotationVectorPaths[i].size() - 1).distance(
this.targetRotationVectorPaths[i][referenceIndex]);
if (distance > ExerciseManager.EXERCISE_ERROR_MARGIN)
{
if (distance > ExerciseManager.EXERCISE_ERROR_MARGIN) {
Log.i("MotionProcessor", "Faulty movement detected: " + distance + " > " + ExerciseManager.EXERCISE_ERROR_MARGIN);
return true;
}