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:
Niels Gras
2024-06-04 12:02:31 +02:00
10 changed files with 79 additions and 41 deletions

View File

@@ -39,6 +39,9 @@ public class FitnessActivity extends RobotActivity implements RobotLifecycleCall
private TextView exerciseNameTextView;
private TextView exerciseShortDescriptionTextView;
private TextView exerciseDescriptionTextView;
private static String exerciseVideoUrl;
private final Object lock = new Object();
// Some nice little messages for the user
private static final String[] EXERCISE_NOT_FOUND_MESSAGES = new String[]{
@@ -58,25 +61,20 @@ public class FitnessActivity extends RobotActivity implements RobotLifecycleCall
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
QiSDK.register(this, this);
setContentView(R.layout.activity_fitness);
// Remove the ugly ass bar on top of the view
setSpeechBarDisplayStrategy(SpeechBarDisplayStrategy.IMMERSIVE);
// Fill empty objects with exercise data
this.exerciseNameTextView = findViewById(R.id.textViewFitnessTitle);
this.exerciseDescriptionTextView = findViewById(R.id.textViewDialogDescription);
//this.exerciseDescriptionTextView = findViewById(R.id.textViewDialogDescription);
this.exerciseShortDescriptionTextView = findViewById(R.id.textViewFitnessShortDescription);
// Find the VideoView by its ID
VideoView videoView = findViewById(R.id.videoView);
playVideo(videoView, this);
// 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
// Hide system UI
NavigationManager.hideSystemUI(this);
setSpeechBarDisplayStrategy(SpeechBarDisplayStrategy.IMMERSIVE);
// Initiate info button
Button infoButtonFitness = findViewById(R.id.infoButtonFitness);
@@ -109,8 +107,8 @@ public class FitnessActivity extends RobotActivity implements RobotLifecycleCall
exerciseStatusElement.initialize(exercise, motionProcessor, EXERCISE_COUNT);
motionProcessor.useExercise(exercise);
/* TODO: Remove if not needed */motionProcessor.setRecording(true, 10);
motionProcessor.startListening();
motionProcessor.setInputHandler(exerciseStatusElement);
motionProcessor.startListening();
}, (n) -> {
int randomMessageIndex = (int) Math.floor(Math.random() * EXERCISE_NOT_FOUND_MESSAGES.length);
@@ -119,8 +117,9 @@ public class FitnessActivity extends RobotActivity implements RobotLifecycleCall
NavigationManager.navigateToActivity(this, EndScreenActivity.class);
});
});
// FitnessCycle.playVideo(qiContext, videoView, this);
VideoView videoView = findViewById(R.id.videoView);
Log.e("exerciseVideoUrl", "videoUrl:" + exerciseVideoUrl);
playVideo(videoView, this);
}
/**
@@ -136,10 +135,13 @@ public class FitnessActivity extends RobotActivity implements RobotLifecycleCall
if (exercise == null) {
onFailedFetch.handle(null);
} else {
exerciseNameTextView.setText(exercise.name);
exerciseShortDescriptionTextView.setText(exercise.shortDescription);
exerciseDescriptionTextView.setText(exercise.description);
onSuccessfulFetch.handle(exercise);
this.runOnUiThread(() -> {
exerciseNameTextView.setText(exercise.name);
exerciseShortDescriptionTextView.setText(exercise.shortDescription);
// exerciseDescriptionTextView.setText(exercise.description);
exerciseVideoUrl = exercise.videoUrl;
});
}
})).start();
}
@@ -153,14 +155,7 @@ public class FitnessActivity extends RobotActivity implements RobotLifecycleCall
public static void playVideo(VideoView videoView, Context context) {
// Set up the video player
if (videoView != null) {
Uri videoUri = Uri.parse("android.resource://" + context.getPackageName() + "/" + R.raw.bicepvideo);
videoView.setVideoURI(videoUri);
videoView.setOnCompletionListener(mp -> {
// Repeat the video when it finishes playing
videoView.start();
});
videoView.setVideoPath(exerciseVideoUrl);
videoView.start();
} else {
Log.e("FitnessActivity", "VideoView is null. Check your layout XML.");

View File

@@ -14,7 +14,11 @@ public class GesturePath {
*/
public GesturePath(Vector3f[] vectors) {
if (vectors.length < 2) {
this.segments = new PathSegment[0];
this.segments = new PathSegment[1];
this.segments[0] = new PathSegment(
new Vector3f(0, 0, 0),
new Vector3f(0, 0, 0)
);
return;
}

View File

@@ -160,6 +160,8 @@ public class InputProcessor {
try {
Log.i("MotionProcessor", "Time passed: " + this.secondsPassed + "s");
Log.i("MotionProcessor", "Recording: " + this.recordingMovement + ", " + this.secondsPassed + " / " + this.recordingDurationInSeconds);
Log.i("MotionProcessor", "Received packet data: " + data);
JsonElement json = JsonParser.parseString(data);
@@ -198,18 +200,12 @@ public class InputProcessor {
// Re-calculate time for index calculation
secondsPassed = (System.currentTimeMillis() - lastTime) / 1000.0d;
lastTime = System.currentTimeMillis();
// Supposed index of the current rotation vector in the `rotationVectorPaths` array
int selfIndex = (int) (secondsPassed * sampleRate);
motionDataConsumer.accept(rotation, deviceId);
if (selfIndex >= selfRotationVectorPaths[deviceId].length || selfIndex < 0)
return;
selfRotationVectorPaths[deviceId][selfIndex] = rotation;
if ( this.recordingMovement && this.hasFinished()) {
if ( this.recordingMovement && this.secondsPassed >= this.recordingDurationInSeconds) {
// Do something with the recorded data.
this.recordingMovement = false;
// Convert recorded data from `selfRotationVectorPaths` to string, and
@@ -221,6 +217,11 @@ public class InputProcessor {
Log.i("MotionProcessor", "Converted data: ");
Log.i("MotionProcessor", converted);
}
motionDataConsumer.accept(rotation, deviceId);
if (selfIndex >= selfRotationVectorPaths[deviceId].length || selfIndex < 0)
return;
selfRotationVectorPaths[deviceId][selfIndex] = rotation;
}
}

View File

@@ -47,7 +47,10 @@
android:layout_width="300dp"
android:layout_height="300dp"
android:layout_centerInParent="true"
android:layout_margin="50dp" />
android:layout_marginStart="50dp"
android:layout_marginTop="50dp"
android:layout_marginEnd="50dp"
android:layout_marginBottom="50dp" />
</RelativeLayout>