Merge branch 'main' of https://gitlab.fdmci.hva.nl/propedeuse-hbo-ict/onderwijs/2023-2024/out-a-se-ti/blok-4/muupooviixee66
This commit is contained in:
@@ -20,7 +20,7 @@
|
||||
android:label="@string/app_name"
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/Theme.Fitbot" >
|
||||
android:theme="@style/AppTheme" >
|
||||
<activity
|
||||
android:name=".ui.activities.EndScreenActivity"
|
||||
android:exported="false" />
|
||||
|
@@ -14,7 +14,7 @@ import java.lang.reflect.Constructor;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
|
||||
public class FitnessManager {
|
||||
public class ExerciseManager {
|
||||
|
||||
private static final String HOST_ADDRESS = "http://145.92.8.132";
|
||||
|
||||
@@ -22,7 +22,20 @@ public class FitnessManager {
|
||||
private static final String PROPERTY_VECTORS = "vector_data";
|
||||
private static final String PROPERTY_NAME = "name";
|
||||
private static final String PROPERTY_MUSCLE_GROUP = "muscle_group";
|
||||
private static final String PROPERTY_SEGMENT_SPEED = "segment_speed";
|
||||
|
||||
private static final float DEFAULT_SEGMENT_SPEED = 1.0f;
|
||||
|
||||
/**
|
||||
* Function for sending an HTTP request to the server.
|
||||
*
|
||||
* @param url The URL to send the request to.
|
||||
* @param method The method to use for the request, e.g. GET or POST.
|
||||
* @param contentType The content type of the request.
|
||||
* @param body The body of the request.
|
||||
*
|
||||
* @return The response from the server.
|
||||
*/
|
||||
private static String sendHTTP(String url, String method, String contentType, String body) {
|
||||
try {
|
||||
URLConnection connection = new URL(url).openConnection();
|
||||
@@ -50,7 +63,7 @@ public class FitnessManager {
|
||||
* @param uniqueIdentifier The unique identifier of the exercise
|
||||
* @return The exercise, if it exists on the server. Otherwise null.
|
||||
*/
|
||||
public static <T extends Exercise> Exercise acquireExercise(String uniqueIdentifier, Class<T> referenceClass) {
|
||||
public static Exercise retrieveExercise(String uniqueIdentifier) {
|
||||
String response = sendHTTP(
|
||||
HOST_ADDRESS + "/acquire", "GET", "application/json", "{\"kind\":\"" + uniqueIdentifier + "\"}"
|
||||
);
|
||||
@@ -58,17 +71,13 @@ public class FitnessManager {
|
||||
if (response != null) {
|
||||
try {
|
||||
JsonObject content = JsonParser.parseString(response).getAsJsonObject();
|
||||
Constructor<T> constructor = referenceClass.getConstructor(referenceClass);
|
||||
T instance = null;
|
||||
try {
|
||||
instance = constructor.newInstance(
|
||||
EMuscleGroup.parse(content.get(PROPERTY_MUSCLE_GROUP).getAsInt()),
|
||||
gesturePathFromString(content.get(PROPERTY_VECTORS).getAsString())
|
||||
);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return instance;
|
||||
return new Exercise(
|
||||
EMuscleGroup.parse(content.get(PROPERTY_MUSCLE_GROUP).getAsInt()),
|
||||
content.get(PROPERTY_NAME).getAsString(),
|
||||
content.get(PROPERTY_DESC).getAsString(),
|
||||
gesturePathFromString(content.get(PROPERTY_VECTORS).getAsString()),
|
||||
DEFAULT_SEGMENT_SPEED
|
||||
);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
@@ -79,7 +88,9 @@ public class FitnessManager {
|
||||
/**
|
||||
* Function for converting a string to a GesturePath object.
|
||||
* The input string bytes will be directly converted into 3d vectors.
|
||||
* Every coordinate is composed of 32 bits, so four characters per coordinate.
|
||||
* Every scalar is composed of 32 bits (4 characters), meaning 96 bits per vector.
|
||||
*
|
||||
* Note: ASCII to Vector conversion is done in Big Endian format (most significant byte first).
|
||||
*
|
||||
* @param input The string to convert
|
||||
* @return The GesturePath object
|
||||
@@ -96,6 +107,7 @@ public class FitnessManager {
|
||||
float[] xyz = new float[3];
|
||||
for (int i = 0; i < bytes.length; i += 12) {
|
||||
for (int j = 0; j < 3; j++) {
|
||||
|
||||
xyz[j] = Float.intBitsToFloat(
|
||||
(bytes[i + j * 4] & 0xFF) << 24 |
|
||||
(bytes[i + j * 4 + 1] & 0xFF) << 16 |
|
@@ -2,21 +2,28 @@ package com.example.fitbot.ui.activities;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.util.Log;
|
||||
import android.widget.VideoView;
|
||||
|
||||
import com.aldebaran.qi.sdk.QiContext;
|
||||
import com.aldebaran.qi.sdk.QiSDK;
|
||||
import com.aldebaran.qi.sdk.RobotLifecycleCallbacks;
|
||||
import com.aldebaran.qi.sdk.design.activity.RobotActivity;
|
||||
import com.aldebaran.qi.sdk.design.activity.conversationstatus.SpeechBarDisplayStrategy;
|
||||
import com.example.fitbot.R;
|
||||
import com.example.fitbot.sports.FitnessCycle;
|
||||
import com.example.fitbot.exercise.EMuscleGroup;
|
||||
import com.example.fitbot.exercise.Exercise;
|
||||
import com.example.fitbot.ui.components.PersonalMotionPreviewElement;
|
||||
import com.example.fitbot.util.Animations;
|
||||
import com.example.fitbot.util.ButtonNavigation;
|
||||
import com.example.fitbot.util.path.GesturePath;
|
||||
|
||||
import org.joml.Vector3f;
|
||||
|
||||
public class FitnessActivity extends RobotActivity implements RobotLifecycleCallbacks {
|
||||
|
||||
// PersonalMotionPreviewElement personalMotionPreviewElement;
|
||||
PersonalMotionPreviewElement personalMotionPreviewElement;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@@ -24,12 +31,17 @@ public class FitnessActivity extends RobotActivity implements RobotLifecycleCall
|
||||
QiSDK.register(this, this);
|
||||
setContentView(R.layout.activity_fitness);
|
||||
|
||||
// Remove the ugly ass bar on top of the view
|
||||
setSpeechBarDisplayStrategy(SpeechBarDisplayStrategy.IMMERSIVE);
|
||||
|
||||
// Find the VideoView by its ID
|
||||
VideoView videoView = findViewById(R.id.videoView);
|
||||
|
||||
FitnessCycle.playVideo(videoView, this);
|
||||
|
||||
com.example.fitbot.util.ButtonNavigation.setupButtonNavigation(this, R.id.homeButton, MainActivity.class);
|
||||
com.example.fitbot.util.ButtonNavigation.setupButtonNavigation(this, R.id.buttonComplete, EndScreenActivity.class);
|
||||
ButtonNavigation.setupButtonNavigation(this, R.id.homeButton, MainActivity.class);
|
||||
ButtonNavigation.setupButtonNavigation(this, R.id.buttonComplete, EndScreenActivity.class);
|
||||
// Implement your logic when the robot focus is gained
|
||||
|
||||
GesturePath.Builder gesturePathBuilder = new GesturePath.Builder();
|
||||
|
||||
@@ -45,15 +57,14 @@ public class FitnessActivity extends RobotActivity implements RobotLifecycleCall
|
||||
gesturePathBuilder.addVector(new Vector3f(-.5f, .5f, .5f));
|
||||
gesturePathBuilder.addVector(new Vector3f(-.5f, .5f, -.5f));
|
||||
|
||||
// Uncomment and fix if needed for personalMotionPreviewElement
|
||||
// personalMotionPreviewElement = findViewById(R.id.personalMotionPreviewElement);
|
||||
// personalMotionPreviewElement.post(() -> {
|
||||
// Log.i("FitnessActivity", "PersonalMotionPreviewElement.post()");
|
||||
//
|
||||
// Exercise exercise = new Exercise(EMuscleGroup.ARMS, "Bicep Curls", "Oefening voor de biceps.", gesturePathBuilder.build(), 1);
|
||||
//
|
||||
// personalMotionPreviewElement.initialize(exercise);
|
||||
// });
|
||||
personalMotionPreviewElement = findViewById(R.id.personalMotionPreviewElement);
|
||||
personalMotionPreviewElement.post(() -> {
|
||||
Log.i("FitnessActivity", "PersonalMotionPreviewElement.post()");
|
||||
|
||||
Exercise exercise = new Exercise(EMuscleGroup.ARMS, "Bicep Curls", "Oefening voor de biceps.", gesturePathBuilder.build(), 1);
|
||||
|
||||
personalMotionPreviewElement.initialize(exercise);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -64,6 +75,7 @@ public class FitnessActivity extends RobotActivity implements RobotLifecycleCall
|
||||
|
||||
// FitnessCycle.playVideo(qiContext, videoView, this);
|
||||
|
||||
personalMotionPreviewElement.provideQiContext(qiContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -8,7 +8,9 @@ import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
|
||||
import com.aldebaran.qi.sdk.QiContext;
|
||||
import com.example.fitbot.exercise.Exercise;
|
||||
import com.example.fitbot.speech.SpeechGenerator;
|
||||
import com.example.fitbot.util.path.GesturePath;
|
||||
import com.example.fitbot.util.path.PathSegment;
|
||||
import com.example.fitbot.util.processing.MotionData;
|
||||
@@ -25,6 +27,8 @@ public class PersonalMotionPreviewElement extends View {
|
||||
private double pathTime = 0.0D; // The timestamp at which the path is currently at.
|
||||
private MotionProcessor motionProcessor;
|
||||
|
||||
private QiContext qiContext;
|
||||
|
||||
private Exercise exercise;
|
||||
|
||||
private Path referencePath; // The path the user is supposed to follow.
|
||||
@@ -35,6 +39,12 @@ public class PersonalMotionPreviewElement extends View {
|
||||
private Paint performingPaint;
|
||||
private Paint textPaint;
|
||||
|
||||
private static final String[] USER_PHRASES = {
|
||||
"Veel success met de oefening!",
|
||||
"Je kan het!",
|
||||
"Veel plezier!"
|
||||
};
|
||||
|
||||
// Matrices for the projection of the path segments onto the screen.
|
||||
// Depth buffering sadly is not supported yet due to brain dysfunction
|
||||
private Matrix4f modelViewMatrix = new Matrix4f();
|
||||
@@ -51,7 +61,7 @@ public class PersonalMotionPreviewElement extends View {
|
||||
private final float FOV = 80.0f; // The field of view of the preview path
|
||||
private final float Z_NEAR = 0.1f; // The near clipping plane
|
||||
private final float Z_FAR = 1000.0f; // The far clipping plane
|
||||
private Vector3f objectPosition = new Vector3f(0.0f, 0.0f, 0.0f); // The position of the camera
|
||||
private Vector3f objectPosition = new Vector3f(0.0f, 0.0f, -4.0f); // The position of the camera
|
||||
private Vector2f screenDimensions = new Vector2f(); // Width and height dimensions of the screen
|
||||
private Vector2f rotation = new Vector2f(); // Rotation vector (yaw, pitch)
|
||||
|
||||
@@ -136,13 +146,33 @@ public class PersonalMotionPreviewElement extends View {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Function for providing a QiContext to the PersonalMotionPreviewElement.
|
||||
* @param context The QiContext to provide.
|
||||
*/
|
||||
public void provideQiContext(QiContext context) {
|
||||
this.qiContext = context;
|
||||
saySomethingNice();
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to say something nice to the user :)
|
||||
*/
|
||||
private void saySomethingNice()
|
||||
{
|
||||
if (this.qiContext == null)
|
||||
return;
|
||||
|
||||
SpeechGenerator.say(USER_PHRASES[(int) Math.floor(Math.random() * USER_PHRASES.length)], this.qiContext);
|
||||
}
|
||||
|
||||
/**
|
||||
* Method that calculates the path that will be drawn on the
|
||||
* canvas. This method will be called every time new motion data is received.
|
||||
*/
|
||||
private void calculateDrawingPath(Vector3f transformedVector, MotionData motionData, int sampleIndex, double sampleRate) {
|
||||
// Recalculate the personal path based on the new motion data
|
||||
|
||||
// TODO: Implement
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -155,16 +185,6 @@ public class PersonalMotionPreviewElement extends View {
|
||||
this.referencePath = getDrawablePath(path.getSegments());
|
||||
}
|
||||
|
||||
/**
|
||||
* Method for setting the rotation of the preview path.
|
||||
*
|
||||
* @param yaw The yaw rotation of the preview path.
|
||||
* @param pitch The pitch rotation of the preview path.
|
||||
*/
|
||||
public void setRotation(float yaw, float pitch) {
|
||||
this.rotation.set(Math.toRadians(yaw), Math.toRadians(pitch));
|
||||
}
|
||||
|
||||
/**
|
||||
* Method for projecting a 3D point onto the screen.
|
||||
* This method converts the 3D point to 2D space using a Model-View-Projection matrix transformation.
|
||||
@@ -240,11 +260,9 @@ public class PersonalMotionPreviewElement extends View {
|
||||
canvas.drawPath(referencePath, referencePaint);
|
||||
canvas.drawPath(performingPath, performingPaint);
|
||||
|
||||
canvas.drawText(this.exercise.getTitle(), 10, 40, textPaint);
|
||||
|
||||
timePassed = (System.nanoTime() - startingTime) / 1E9D;
|
||||
|
||||
this.rotation.add(1f, 0);
|
||||
this.rotation.x = (float) (Math.sin(timePassed) * 45);
|
||||
this.referencePath = getDrawablePath(this.path.getSegments());
|
||||
this.invalidate(); // Causes a redraw.
|
||||
}
|
||||
|
@@ -1,26 +1,17 @@
|
||||
//usage: PlayAnimation(animationfile, Qicontext);
|
||||
// https://qisdk.softbankrobotics.com/sdk/doc/pepper-sdk/ch4_api/movement/reference/animation.html
|
||||
|
||||
package com.example.fitbot.sports;
|
||||
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
package com.example.fitbot.util;
|
||||
|
||||
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 com.example.fitbot.ui.activities.MainActivity;
|
||||
|
||||
public class Animations extends AppCompatActivity {
|
||||
|
||||
public class Animations {
|
||||
|
||||
public static void Animate(String AnimationFile, QiContext ctx)
|
||||
{
|
||||
PlayAnimation(AnimationFile, ctx);
|
||||
}
|
||||
|
||||
public static void PlayAnimation(String AnimationFile, QiContext ctx)
|
||||
{
|
||||
int resId = ctx.getResources().getIdentifier(AnimationFile, "raw", ctx.getPackageName());
|
||||
|
@@ -8,6 +8,13 @@ import android.widget.Button;
|
||||
|
||||
public class ButtonNavigation {
|
||||
|
||||
/**
|
||||
* Sets up a button to navigate to a different activity when clicked.
|
||||
*
|
||||
* @param currentActivity The activity that contains the button
|
||||
* @param buttonId The ID of the button
|
||||
* @param targetActivity The activity to navigate to
|
||||
*/
|
||||
public static void setupButtonNavigation(Activity currentActivity, int buttonId, Class<? extends Activity> targetActivity) {
|
||||
Button button = currentActivity.findViewById(buttonId);
|
||||
button.setOnClickListener(v -> {
|
||||
|
@@ -11,17 +11,6 @@ android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
|
||||
tools:context=".ui.activities.FitnessActivity"
|
||||
tools:openDrawer="start">
|
||||
|
||||
<!-- <com.example.fitbot.ui.components.PersonalMotionPreviewElement-->
|
||||
<!-- android:id="@+id/personalMotionPreviewElement"-->
|
||||
<!-- android:layout_width="600dp"-->
|
||||
<!-- android:layout_height="550dp"-->
|
||||
<!-- app:layout_constraintBottom_toBottomOf="parent"-->
|
||||
<!-- app:layout_constraintEnd_toEndOf="parent"-->
|
||||
<!-- app:layout_constraintHorizontal_bias="0.976"-->
|
||||
<!-- app:layout_constraintStart_toStartOf="parent"-->
|
||||
<!-- app:layout_constraintTop_toTopOf="parent"-->
|
||||
<!-- app:layout_constraintVertical_bias="0.064" />-->
|
||||
|
||||
<VideoView
|
||||
android:id="@+id/videoView"
|
||||
android:layout_width="450dp"
|
||||
@@ -33,8 +22,8 @@ tools:openDrawer="start">
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintVertical_bias="0.2" />
|
||||
|
||||
<VideoView
|
||||
android:id="@+id/videoView2"
|
||||
<com.example.fitbot.ui.components.PersonalMotionPreviewElement
|
||||
android:id="@+id/personalMotionPreviewElement"
|
||||
android:layout_width="450dp"
|
||||
android:layout_height="450dp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
|
@@ -2,11 +2,8 @@
|
||||
<resources>
|
||||
<!-- Base application theme. -->
|
||||
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
|
||||
<item name="android:statusBarColor">#00000000</item>
|
||||
<item name="windowActionBar">false</item>
|
||||
<item name="windowNoTitle">true</item>
|
||||
|
||||
|
||||
</style>
|
||||
|
||||
<style name="ButtonStyle">
|
||||
|
Reference in New Issue
Block a user