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 f623e21..433be42 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 @@ -2,9 +2,7 @@ package com.example.fitbot.ui.activities; import android.animation.Animator; import android.animation.AnimatorListenerAdapter; -import android.animation.ArgbEvaluator; import android.animation.ObjectAnimator; -import android.animation.ValueAnimator; import android.app.Dialog; import android.content.Context; import android.content.res.ColorStateList; @@ -59,8 +57,6 @@ public class FitnessActivity extends RobotActivity implements RobotLifecycleCall private VideoView videoView; private QiContext qiContext; - private ObjectAnimator shimmerAnimator; - private final Object lock = new Object(); // Some nice little messages for the user @@ -101,14 +97,6 @@ public class FitnessActivity extends RobotActivity implements RobotLifecycleCall ProgressBar loadingCircle = findViewById(R.id.loadingCircle); loadingCircle.setIndeterminateTintList(ColorStateList.valueOf(Color.RED)); - // Start shimmer animation for loading elements - View shimmerProgressCircle = findViewById(R.id.progressCircle); - View shimmerFitnessTitle = findViewById(R.id.textViewFitnessTitle); - View shimmerFitnessText = findViewById(R.id.textViewFitnessShortDescription); - shimmerAnimation(shimmerProgressCircle); - shimmerAnimation(shimmerFitnessTitle); - shimmerAnimation(shimmerFitnessText); - // Navigation Buttons NavigationManager.setupButtonNavigation(this, R.id.homeButtonFitness, MainActivity.class); NavigationManager.setupButtonNavigation(this, R.id.skipButtonFitness, MainActivity.class); //Needs to skip exercises once those are implemented @@ -140,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)); }); } @@ -164,7 +149,10 @@ 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(() -> { @@ -183,12 +171,11 @@ public class FitnessActivity extends RobotActivity implements RobotLifecycleCall ProgressBar loadingCircle = findViewById(R.id.loadingCircle); loadingCircle.setVisibility(View.GONE); - // Stop shimmer animation - stopShimmerAnimation(); Pepper.animate("armraise"); // Start checking for user movement once the video has loaded + this.motionProcessor.startListening(); this.motionProcessor.startCheckingUserMovement(); return true; @@ -301,24 +288,4 @@ public class FitnessActivity extends RobotActivity implements RobotLifecycleCall }); animator.start(); } - - public void shimmerAnimation(View view) { - ObjectAnimator animator = ObjectAnimator.ofObject( - view, - "backgroundColor", - new ArgbEvaluator(), - ContextCompat.getColor(view.getContext(), R.color.shimmerStartColor), - ContextCompat.getColor(view.getContext(), R.color.shimmerEndColor) - ); - animator.setDuration(1200); - animator.setRepeatCount(ValueAnimator.INFINITE); - animator.setRepeatMode(ValueAnimator.REVERSE); - animator.start(); - } - - public void stopShimmerAnimation() { - if (shimmerAnimator != null && shimmerAnimator.isRunning()) { - shimmerAnimator.cancel(); - } - } } \ No newline at end of file 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 7b0bb13..15ebf2a 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 @@ -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; }