Luca's attempt at fixing app
This commit is contained in:
@@ -162,7 +162,7 @@ public class FitnessActivity extends RobotActivity implements RobotLifecycleCall
|
|||||||
Pepper.provideContext(null, this.getClass()); // Remove the context (unavailable)
|
Pepper.provideContext(null, this.getClass()); // Remove the context (unavailable)
|
||||||
|
|
||||||
// Go to the main screen
|
// Go to the main screen
|
||||||
NavigationManager.navigateToActivity(this, MainActivity.class);
|
// NavigationManager.navigateToActivity(this, MainActivity.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -86,40 +86,9 @@ public class ExerciseStatusElement extends View implements IInputHandler {
|
|||||||
Pepper.say(STARTING_PHRASES[(int) Math.floor(Math.random() * STARTING_PHRASES.length)]);
|
Pepper.say(STARTING_PHRASES[(int) Math.floor(Math.random() * STARTING_PHRASES.length)]);
|
||||||
|
|
||||||
// Handler that is called every time the motion processor receives new data.
|
// Handler that is called every time the motion processor receives new data.
|
||||||
this.motionProcessor.setInputHandler((rotationVector, deviceId) -> {
|
|
||||||
|
|
||||||
Log.i("MotionProcessor", "Rotation vector received: " + rotationVector);
|
|
||||||
Log.i("MotionProcessor", "Last error offset:" + this.motionProcessor.getError(deviceId, this.motionProcessor.secondsPassed()));
|
|
||||||
|
|
||||||
// Check whether the current exercise has been completed.
|
|
||||||
// This is determined by the duration of the exercise, and the amount of time that has passed.
|
|
||||||
// The duration of the exercise originates from the database, and is stored in seconds.
|
|
||||||
// Whenever 'useExercise' is called, the timer resets and this method will be called again.
|
|
||||||
if (this.motionProcessor.hasFinished()) {
|
|
||||||
// If for some reason the parent activity is not defined,
|
|
||||||
// move back to the main screen.
|
|
||||||
if (this.parentActivity == null) {
|
|
||||||
// Move to main screen
|
|
||||||
NavigationManager.navigateToActivity(getContext(), MainActivity.class);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// Move on to the next exercise, or finish.
|
|
||||||
if (this.exerciseCount > 0) {
|
|
||||||
this.exerciseCount--;
|
|
||||||
this.parentActivity.fetchExerciseAsync((newExercise) -> {
|
|
||||||
this.motionProcessor.useExercise(newExercise);
|
|
||||||
|
|
||||||
// Whenever the database retrieval failed, we return to the main screen.
|
|
||||||
}, (failed) -> {
|
|
||||||
// Move to main screen
|
|
||||||
NavigationManager.navigateToActivity(parentActivity, MainActivity.class);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
// Finish the exercise.
|
|
||||||
NavigationManager.navigateToActivity(parentActivity, EndScreenActivity.class);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -130,6 +99,7 @@ public class ExerciseStatusElement extends View implements IInputHandler {
|
|||||||
public void setExercise(Exercise exercise) {
|
public void setExercise(Exercise exercise) {
|
||||||
this.motionProcessor.useExercise(exercise);
|
this.motionProcessor.useExercise(exercise);
|
||||||
this.exercise = exercise;
|
this.exercise = exercise;
|
||||||
|
Log.i("MotionProcessor", "Updating exercise in ExerciseStatusElement");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -157,6 +127,40 @@ public class ExerciseStatusElement extends View implements IInputHandler {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void accept(Vector3f rotationVector, int sensorId) {
|
public void accept(Vector3f rotationVector, int sensorId) {
|
||||||
|
Log.i("MotionProcessor", "Rotation vector received: " + rotationVector);
|
||||||
|
Log.i("MotionProcessor", "Last error offset:" + this.motionProcessor.getError(sensorId, this.motionProcessor.secondsPassed()));
|
||||||
|
|
||||||
|
// Check whether the current exercise has been completed.
|
||||||
|
// This is determined by the duration of the exercise, and the amount of time that has passed.
|
||||||
|
// The duration of the exercise originates from the database, and is stored in seconds.
|
||||||
|
// Whenever 'useExercise' is called, the timer resets and this method will be called again.
|
||||||
|
if (this.motionProcessor.hasFinished() && !this.motionProcessor.isRecording()) {
|
||||||
|
// If for some reason the parent activity is not defined,
|
||||||
|
// move back to the main screen.
|
||||||
|
if (this.parentActivity == null) {
|
||||||
|
// Move to main screen
|
||||||
|
Log.i("MotionProcessor", "Parent activity was null.");
|
||||||
|
NavigationManager.navigateToActivity(getContext(), MainActivity.class);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Move on to the next exercise, or finish.
|
||||||
|
if (this.exerciseCount > 0) {
|
||||||
|
this.exerciseCount--;
|
||||||
|
this.parentActivity.fetchExerciseAsync((newExercise) -> {
|
||||||
|
this.motionProcessor.useExercise(newExercise);
|
||||||
|
|
||||||
|
// Whenever the database retrieval failed, we return to the main screen.
|
||||||
|
}, (failed) -> {
|
||||||
|
// Move to main screen
|
||||||
|
Log.i("MotionProcessor", "Failed to fetch exercise from database");
|
||||||
|
NavigationManager.navigateToActivity(parentActivity, MainActivity.class);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// Finish the exercise.
|
||||||
|
Log.i("MotionProcessor", "Exercise has finished");
|
||||||
|
NavigationManager.navigateToActivity(parentActivity, EndScreenActivity.class);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -335,4 +335,8 @@ public class InputProcessor {
|
|||||||
public float secondsPassed() {
|
public float secondsPassed() {
|
||||||
return (float) secondsPassed;
|
return (float) secondsPassed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isRecording() {
|
||||||
|
return this.recordingMovement;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user