Renamed functions for clarity
This commit is contained in:
@@ -28,6 +28,9 @@ public class ExerciseManager {
|
|||||||
private static final String PROPERTY_PATH = "path";
|
private static final String PROPERTY_PATH = "path";
|
||||||
private static final String PROPERTY_NAME = "name";
|
private static final String PROPERTY_NAME = "name";
|
||||||
|
|
||||||
|
// The delimiter used to separate the paths of the sensors.
|
||||||
|
public static final String PATH_DELIMITER = ";";
|
||||||
|
|
||||||
public static final int SENSOR_COUNT = 2;
|
public static final int SENSOR_COUNT = 2;
|
||||||
|
|
||||||
private static final String[] REQUIRED_PROPERTIES = {
|
private static final String[] REQUIRED_PROPERTIES = {
|
||||||
@@ -80,7 +83,7 @@ public class ExerciseManager {
|
|||||||
*
|
*
|
||||||
* @return The exercise, if it exists on the server. Otherwise null.
|
* @return The exercise, if it exists on the server. Otherwise null.
|
||||||
*/
|
*/
|
||||||
public static Exercise retrieveExercise() {
|
public static Exercise fetchExerciseFromDatabase() {
|
||||||
String response = sendHTTP(
|
String response = sendHTTP(
|
||||||
HOST_ADDRESS, "POST", "application/json", null
|
HOST_ADDRESS, "POST", "application/json", null
|
||||||
);
|
);
|
||||||
@@ -99,7 +102,7 @@ public class ExerciseManager {
|
|||||||
// Path data is split into two parts, due to the left and right hand.
|
// Path data is split into two parts, due to the left and right hand.
|
||||||
// If one wants to add support for more sensors, one will have to adjust the Exercise
|
// If one wants to add support for more sensors, one will have to adjust the Exercise
|
||||||
// class to support more paths.
|
// class to support more paths.
|
||||||
String[] leftRightData = content.get(PROPERTY_PATH).getAsString().split(";");
|
String[] leftRightData = content.get(PROPERTY_PATH).getAsString().split(PATH_DELIMITER);
|
||||||
|
|
||||||
if (leftRightData.length != SENSOR_COUNT)
|
if (leftRightData.length != SENSOR_COUNT)
|
||||||
return null;
|
return null;
|
||||||
|
@@ -71,7 +71,7 @@ public class FitnessActivity extends RobotActivity implements RobotLifecycleCall
|
|||||||
// This will provide the element with the appropriate dimensions for drawing
|
// This will provide the element with the appropriate dimensions for drawing
|
||||||
// the canvas properly.
|
// the canvas properly.
|
||||||
personalMotionPreviewElement.post(() -> {
|
personalMotionPreviewElement.post(() -> {
|
||||||
this.acquireExercise((exercise) -> {
|
this.fetchExerciseAsync((exercise) -> {
|
||||||
// Acquire paths from the exercise and provide them to the motion processor
|
// Acquire paths from the exercise and provide them to the motion processor
|
||||||
Vector3f[][] vectors = new Vector3f[][]{exercise.leftPath.getVectors(), exercise.rightPath.getVectors()};
|
Vector3f[][] vectors = new Vector3f[][]{exercise.leftPath.getVectors(), exercise.rightPath.getVectors()};
|
||||||
|
|
||||||
@@ -97,11 +97,11 @@ public class FitnessActivity extends RobotActivity implements RobotLifecycleCall
|
|||||||
* Whenever the retrieval failed, it will have the robot say something to the user
|
* Whenever the retrieval failed, it will have the robot say something to the user
|
||||||
* to inform them about the issue.
|
* to inform them about the issue.
|
||||||
*/
|
*/
|
||||||
public void acquireExercise(Exercise.ExerciseFetchHandler onSuccessfulFetch, Exercise.ExerciseFetchHandler onFailedFetch) {
|
public void fetchExerciseAsync(Exercise.ExerciseFetchHandler onSuccessfulFetch, Exercise.ExerciseFetchHandler onFailedFetch) {
|
||||||
// For some stupid reason we cannot perform network operations on the main thread.
|
// For some stupid reason we cannot perform network operations on the main thread.
|
||||||
// therefore we'll have to do it like this...
|
// therefore we'll have to do it like this...
|
||||||
(new Thread(() -> {
|
(new Thread(() -> {
|
||||||
Exercise exercise = ExerciseManager.retrieveExercise();
|
Exercise exercise = ExerciseManager.fetchExerciseFromDatabase();
|
||||||
if (exercise == null) {
|
if (exercise == null) {
|
||||||
onFailedFetch.handle(null);
|
onFailedFetch.handle(null);
|
||||||
} else {
|
} else {
|
||||||
|
@@ -122,7 +122,7 @@ public class ExerciseStatusElement extends View implements IInputHandler {
|
|||||||
// Move on to the next exercise, or finish.
|
// Move on to the next exercise, or finish.
|
||||||
if (this.exerciseCount > 0) {
|
if (this.exerciseCount > 0) {
|
||||||
this.exerciseCount--;
|
this.exerciseCount--;
|
||||||
this.parentActivity.acquireExercise((newExercise) -> {
|
this.parentActivity.fetchExerciseAsync((newExercise) -> {
|
||||||
this.motionProcessor.useExercise(newExercise);
|
this.motionProcessor.useExercise(newExercise);
|
||||||
}, (failed) -> {
|
}, (failed) -> {
|
||||||
// Move to main screen
|
// Move to main screen
|
||||||
|
@@ -3,6 +3,7 @@ package com.example.fitbot.util.processing;
|
|||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.example.fitbot.exercise.Exercise;
|
import com.example.fitbot.exercise.Exercise;
|
||||||
|
import com.example.fitbot.exercise.ExerciseManager;
|
||||||
import com.example.fitbot.util.server.WebServer;
|
import com.example.fitbot.util.server.WebServer;
|
||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
@@ -220,6 +221,13 @@ public class InputProcessor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Function for converting the recorded data to a string.
|
||||||
|
* This function will convert the recorded data to a string
|
||||||
|
* that can be sent to a database or other storage.
|
||||||
|
*
|
||||||
|
* @return The converted string.
|
||||||
|
*/
|
||||||
private String convertRecordedDataToString()
|
private String convertRecordedDataToString()
|
||||||
{
|
{
|
||||||
// First, remove empty entries
|
// First, remove empty entries
|
||||||
@@ -251,7 +259,7 @@ public class InputProcessor {
|
|||||||
}
|
}
|
||||||
// Add a separator between devices
|
// Add a separator between devices
|
||||||
if ( deviceId < selfRotationVectorPaths.length - 1)
|
if ( deviceId < selfRotationVectorPaths.length - 1)
|
||||||
pathBuilder.append(";");
|
pathBuilder.append(ExerciseManager.PATH_DELIMITER);
|
||||||
}
|
}
|
||||||
return pathBuilder.toString();
|
return pathBuilder.toString();
|
||||||
}
|
}
|
||||||
|
@@ -1,6 +1,5 @@
|
|||||||
package com.example.fitbot;
|
package com.example.fitbot;
|
||||||
|
|
||||||
import com.example.fitbot.exercise.EMuscleGroup;
|
|
||||||
import com.example.fitbot.exercise.Exercise;
|
import com.example.fitbot.exercise.Exercise;
|
||||||
import com.example.fitbot.exercise.ExerciseManager;
|
import com.example.fitbot.exercise.ExerciseManager;
|
||||||
|
|
||||||
@@ -11,7 +10,7 @@ public class DatabaseFetchingTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDatabaseFetching() {
|
public void testDatabaseFetching() {
|
||||||
Exercise exercise = ExerciseManager.retrieveExercise();
|
Exercise exercise = ExerciseManager.fetchExerciseFromDatabase();
|
||||||
assert exercise != null;
|
assert exercise != null;
|
||||||
System.out.println("\n---------------------------------");
|
System.out.println("\n---------------------------------");
|
||||||
System.out.println("Exercise:");
|
System.out.println("Exercise:");
|
||||||
|
Reference in New Issue
Block a user