fitnesscycle class it plays the animation a given amount of reps

This commit is contained in:
2024-05-24 11:29:40 +02:00
parent fdfb216617
commit 3ee81d0e48

View File

@@ -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.");
}
}
}