From 3ee81d0e481acf57762e0effd4cd5d3c53b8d4e5 Mon Sep 17 00:00:00 2001 From: Sam Hos Date: Fri, 24 May 2024 11:29:40 +0200 Subject: [PATCH] fitnesscycle class it plays the animation a given amount of reps --- .../example/fitbot/sports/FitnessCycle.java | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 code/src/Fitbot/app/src/main/java/com/example/fitbot/sports/FitnessCycle.java diff --git a/code/src/Fitbot/app/src/main/java/com/example/fitbot/sports/FitnessCycle.java b/code/src/Fitbot/app/src/main/java/com/example/fitbot/sports/FitnessCycle.java new file mode 100644 index 0000000..78ebe78 --- /dev/null +++ b/code/src/Fitbot/app/src/main/java/com/example/fitbot/sports/FitnessCycle.java @@ -0,0 +1,53 @@ +package com.example.fitbot.sports; + +import static com.example.fitbot.sports.Animations.PlayAnimation; + +import android.net.Uri; +import android.os.Handler; +import android.support.v7.app.AppCompatActivity; + +import com.aldebaran.qi.sdk.QiContext; +import com.aldebaran.qi.sdk.builder.AnimateBuilder; +import com.aldebaran.qi.sdk.builder.AnimationBuilder; +import com.aldebaran.qi.sdk.object.actuation.Animate; +import com.aldebaran.qi.sdk.object.actuation.Animation; + +import java.util.concurrent.atomic.AtomicInteger; + + +public class FitnessCycle extends AppCompatActivity { + + public static void FitnessManager(String Exercise, int Reps, QiContext qiContext, String videoView){ + AtomicInteger repCount = new AtomicInteger(0); + + Animation animation = AnimationBuilder.with(qiContext) + .withResources(qiContext.getResources().getIdentifier(Exercise, "raw", qiContext.getPackageName())) + .build(); + + Animate animate = AnimateBuilder.with(qiContext) + .withAnimation(animation) + .build(); + + // Add a listener for when a label is reached + animate.addOnLabelReachedListener((label, time) -> { + // Increment repCount when the end of a repetition is reached + if ("end".equals(label)) { + repCount.incrementAndGet(); + } + }); + + // Run the animation the desired number of times + for (int i = 0; i < Reps; i++) { + animate.run(); + } + + // Set up the video player + if (videoView != null) { + Uri videoUri = Uri.parse("android.resource://" + qiContext.getPackageName() + "/" + R.raw.bicepvideo); + videoView.setVideoURI(videoUri); + videoView.start(); + } else { + Log.e("FitnessActivity", "VideoView is null. Check your layout XML."); + } + } +} \ No newline at end of file