From 7e60d5e5e611808df5119ea79b0b5e9de49e053e Mon Sep 17 00:00:00 2001 From: Sam Hos Date: Wed, 29 May 2024 15:35:29 +0200 Subject: [PATCH 01/55] fixed type error causing bootloop --- .../arduino/Movement-sensor-code/Connectivity.cpp | 2 +- .../Movement-sensor-code/Movement-sensor-code.ino | 15 +++++---------- code/arduino/Movement-sensor-code/headerFIle.h | 4 +++- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/code/arduino/Movement-sensor-code/Connectivity.cpp b/code/arduino/Movement-sensor-code/Connectivity.cpp index a1c30c4..367e114 100644 --- a/code/arduino/Movement-sensor-code/Connectivity.cpp +++ b/code/arduino/Movement-sensor-code/Connectivity.cpp @@ -4,7 +4,7 @@ void Connectivity::connectWiFi(char* ssid, char* pass){ WiFi.mode(WIFI_STA); WiFi.begin(ssid, pass); while (WiFi.status() != WL_CONNECTED) { - Serial.println("connecting to wifi"); + // Serial.println("connecting to wifi"); delay(1000); } Serial.println(WiFi.localIP()); diff --git a/code/arduino/Movement-sensor-code/Movement-sensor-code.ino b/code/arduino/Movement-sensor-code/Movement-sensor-code.ino index 89ac75b..35b30bb 100644 --- a/code/arduino/Movement-sensor-code/Movement-sensor-code.ino +++ b/code/arduino/Movement-sensor-code/Movement-sensor-code.ino @@ -1,31 +1,27 @@ #include "headerFile.h" // SensorManager::Rotation offset; -#define BUFFER_SIZE 1024 - -#define DEVICE_ID 1 - -char *buffer = (char *)malloc(sizeof(char) * BUFFER_SIZE); void setup() { - Serial.begin(9600); + // Serial.begin(9600); // Serial.println("startup"); //connect to internet and start sensor connectivity.connectWiFi(ssid, pass); sensorManager.sensorSetup(); } +unsigned long lastTime = 0; // will store the last time the code was run + void loop() { SensorManager::eulerAngles eulerRotation = sensorManager.getEulerAngles(); SensorManager::acceleration rotationAcceleration = sensorManager.getAcelleration(); - unsigned long lastTime = 0; // will store the last time the code was run unsigned long currentTime = millis(); if (currentTime - lastTime >= 100) { // 100 ms has passed memset(buffer, 0, BUFFER_SIZE); sprintf( buffer, - "{\"deviceId\": %d, \"rotationX\": %d, \"rotationY\": %d, \"rotationZ\": %d, \"accelerationX\": %d, \"accelerationY\": %d, \"accelerationZ\": %d, \"type\": %s}", + "{\"deviceId\": %d, \"rotationX\": %f, \"rotationY\": %f, \"rotationZ\": %f, \"accelerationX\": %f, \"accelerationY\": %f, \"accelerationZ\": %f, \"type\": %s}", DEVICE_ID, eulerRotation.roll, eulerRotation.pitch, @@ -34,8 +30,7 @@ void loop() { rotationAcceleration.y, rotationAcceleration.z, "data"); - // Serial.println(connectivity.httpPost("192.168.137.45", "/", 3445, message.c_str(), message.length(), "json")); - // Serial.println(message); + // %d = int, %f = floatation, %s = string connectivity.httpPost("192.168.137.45", "/", 3445, buffer, strlen(buffer), "application/json"); lastTime = currentTime; } diff --git a/code/arduino/Movement-sensor-code/headerFIle.h b/code/arduino/Movement-sensor-code/headerFIle.h index b7b8220..b065b3e 100644 --- a/code/arduino/Movement-sensor-code/headerFIle.h +++ b/code/arduino/Movement-sensor-code/headerFIle.h @@ -8,6 +8,8 @@ Connectivity connectivity; WebSocketsClient webSocket; #define USE_SERIAL Serial - #define ssid "1235678i" #define pass "12345678" +#define BUFFER_SIZE 1024 +#define DEVICE_ID 1 +char *buffer = (char *)malloc(sizeof(char) * BUFFER_SIZE); From a6977b057cbd58e17c2cfee886ebf6b78a09c02f Mon Sep 17 00:00:00 2001 From: Luca Warmenhoven Date: Wed, 29 May 2024 15:39:13 +0200 Subject: [PATCH 02/55] Added more logging for debugging functionality --- .../PersonalMotionPreviewElement.java | 41 ++++++++++++++++++- .../util/processing/MotionProcessor.java | 1 - 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/code/src/Fitbot/app/src/main/java/com/example/fitbot/ui/components/PersonalMotionPreviewElement.java b/code/src/Fitbot/app/src/main/java/com/example/fitbot/ui/components/PersonalMotionPreviewElement.java index 0109112..d498761 100644 --- a/code/src/Fitbot/app/src/main/java/com/example/fitbot/ui/components/PersonalMotionPreviewElement.java +++ b/code/src/Fitbot/app/src/main/java/com/example/fitbot/ui/components/PersonalMotionPreviewElement.java @@ -22,6 +22,8 @@ import org.joml.Vector2f; import org.joml.Vector3f; import org.joml.Vector4f; +import java.util.ArrayList; +import java.util.List; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReference; @@ -44,6 +46,11 @@ public class PersonalMotionPreviewElement extends View { private final Paint targetPaint = new Paint(); private final Paint backgroundColor = new Paint(); + private Matrix4f modelViewMatrix = new Matrix4f(); // The model view matrix for the 3D to 2D transformation. + private Matrix4f projectionMatrix = new Matrix4f(); // The projection matrix for the 3D to 2D transformation. + private final Vector4f objectPosition = new Vector4f(0, 0, -1, 1); // The location of the object in 3D space. + private List vectors = new ArrayList<>(); + private static final String[] USER_PHRASES = { "Veel success met de oefening!", @@ -122,6 +129,8 @@ public class PersonalMotionPreviewElement extends View { int progress = (int)this.motionProcessor.getError(this.paths[0], processed); this.exerciseProgress.set(Math.min(1000, Math.max(0, progress))); Log.i("MotionProcessor", "Processed data: " + progress + " (" + preprocessed + ")"); + Vector2f parsed = projectVertex(processed, this.getWidth(), this.getHeight()); + this.vectors.add(parsed); }); saySomethingNice(); } @@ -147,6 +156,31 @@ public class PersonalMotionPreviewElement extends View { } + private Vector2f projectVertex(Vector3f point, int virtualWidth, int virtualHeight) { + + modelViewMatrix + .identity() + .translate(-objectPosition.x, -objectPosition.y, -objectPosition.z); + + // Transform the projection matrix to a perspective projection matrix + // Perspective transformation conserves the depth of the object + projectionMatrix + .identity() + .perspective((float) Math.toRadians(70), (float) virtualWidth / virtualHeight, .01f, 10000.0f); + + // Convert world coordinates to screen-space using MVP matrix + Vector4f screenCoordinates = new Vector4f(point, 1.0f) + .mul(this.modelViewMatrix) + .mul(this.projectionMatrix); + + // Normalize screen coordinates from (-1, 1) to (0, virtualWidth) and (0, virtualHeight) + float normalizedX = (screenCoordinates.x / screenCoordinates.w + 1.0f) * 0.5f * virtualWidth; + float normalizedY = (1.0f - screenCoordinates.y / screenCoordinates.w) * 0.5f * virtualHeight; + return new Vector2f(normalizedX, normalizedY); + } + + + @Override public void onDraw(Canvas canvas) { canvas.drawRect(0, 0, getWidth(), getHeight(), backgroundColor); @@ -154,6 +188,11 @@ public class PersonalMotionPreviewElement extends View { if (this.exercise == null) return; + for ( Vector2f point : this.vectors) + { + canvas.drawRect(point.x, point.y, point.x + 5, point.y + 5, this.referencePaint); + } +/* // Draw target circle float targetRadius = (this.screenDimensions.x + this.screenDimensions.y) / 5.0f; canvas.drawCircle(this.screenDimensions.x / 2, this.screenDimensions.y / 2, targetRadius, this.targetPaint); @@ -165,7 +204,7 @@ public class PersonalMotionPreviewElement extends View { (int)(255 * exerciseProgress.get()/1000.0f), 0 ) - ); + );*/ this.invalidate(); diff --git a/code/src/Fitbot/app/src/main/java/com/example/fitbot/util/processing/MotionProcessor.java b/code/src/Fitbot/app/src/main/java/com/example/fitbot/util/processing/MotionProcessor.java index 875f731..7264805 100644 --- a/code/src/Fitbot/app/src/main/java/com/example/fitbot/util/processing/MotionProcessor.java +++ b/code/src/Fitbot/app/src/main/java/com/example/fitbot/util/processing/MotionProcessor.java @@ -108,7 +108,6 @@ public class MotionProcessor { addMotionData(motionData); } catch (Exception e) { - // Don't do anything ... just ignore the exception Log.i("MotionProcessor", "Failed to parse packet data."); } } From bd9ace61e9724c8688a7dc57823b3c2db2feddaa Mon Sep 17 00:00:00 2001 From: Luca Warmenhoven Date: Wed, 29 May 2024 15:55:37 +0200 Subject: [PATCH 03/55] Added more logging for debugging functionality --- .../PersonalMotionPreviewElement.java | 24 +++++++++++++++++-- .../util/processing/MotionProcessor.java | 14 +++++++---- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/code/src/Fitbot/app/src/main/java/com/example/fitbot/ui/components/PersonalMotionPreviewElement.java b/code/src/Fitbot/app/src/main/java/com/example/fitbot/ui/components/PersonalMotionPreviewElement.java index d498761..eca81f6 100644 --- a/code/src/Fitbot/app/src/main/java/com/example/fitbot/ui/components/PersonalMotionPreviewElement.java +++ b/code/src/Fitbot/app/src/main/java/com/example/fitbot/ui/components/PersonalMotionPreviewElement.java @@ -24,6 +24,7 @@ import org.joml.Vector4f; import java.util.ArrayList; import java.util.List; +import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReference; @@ -48,8 +49,11 @@ public class PersonalMotionPreviewElement extends View { private Matrix4f modelViewMatrix = new Matrix4f(); // The model view matrix for the 3D to 2D transformation. private Matrix4f projectionMatrix = new Matrix4f(); // The projection matrix for the 3D to 2D transformation. - private final Vector4f objectPosition = new Vector4f(0, 0, -1, 1); // The location of the object in 3D space. - private List vectors = new ArrayList<>(); + private final Vector4f objectPosition = new Vector4f(0, 0, -2, 1); // The location of the object in 3D space. + private ConcurrentLinkedQueue vectors = new ConcurrentLinkedQueue<>(); + + private Vector2f[] axisVectors; + private static final String[] USER_PHRASES = { @@ -99,6 +103,17 @@ public class PersonalMotionPreviewElement extends View { this.exercise = exercise; this.paths = exercise.getPath(); + + this.axisVectors = new Vector2f[] { + + projectVertex(new Vector3f(-1.0f, 0, 0), getWidth(), getHeight()), + projectVertex(new Vector3f(1.0f, 0, 0), getWidth(), getHeight()), + projectVertex(new Vector3f(0, -1.0f, 0), getWidth(), getHeight()), + projectVertex(new Vector3f(0, 1.0f, 0), getWidth(), getHeight()), + projectVertex(new Vector3f(0, 0, -1.0f), getWidth(), getHeight()), + projectVertex(new Vector3f(0, 0, 1.0f), getWidth(), getHeight()) + + }; } public void onDestroy() @@ -188,6 +203,11 @@ public class PersonalMotionPreviewElement extends View { if (this.exercise == null) return; + for (int i = 0; i < axisVectors.length/2; i++) + { + canvas.drawLine(axisVectors[i*2].x, axisVectors[i*2].y, axisVectors[i*2+1].x, axisVectors[i*2+1].y, this.targetPaint); + } + for ( Vector2f point : this.vectors) { canvas.drawRect(point.x, point.y, point.x + 5, point.y + 5, this.referencePaint); diff --git a/code/src/Fitbot/app/src/main/java/com/example/fitbot/util/processing/MotionProcessor.java b/code/src/Fitbot/app/src/main/java/com/example/fitbot/util/processing/MotionProcessor.java index 7264805..016a520 100644 --- a/code/src/Fitbot/app/src/main/java/com/example/fitbot/util/processing/MotionProcessor.java +++ b/code/src/Fitbot/app/src/main/java/com/example/fitbot/util/processing/MotionProcessor.java @@ -9,6 +9,8 @@ import com.google.gson.JsonObject; import com.google.gson.JsonParser; import org.jetbrains.annotations.NotNull; +import org.joml.Matrix3d; +import org.joml.Vector3d; import org.joml.Vector3f; import java.util.ArrayList; @@ -24,7 +26,7 @@ public class MotionProcessor { private Vector3f ZERO = new Vector3f(0, 0, 0); - private final float sampleRate = 10.0F; // samples/second + private final float sampleRate = 1.0f / 10.0F; // samples/second private IMotionDataConsumer motionDataConsumer = (p1, p2, p3, p4, p5) -> { }; private WebServer server; @@ -164,12 +166,14 @@ public class MotionProcessor { // Rotate the acceleration vector back by the rotation vector to make it // perpendicular to the gravity vector, then apply double integration to get the relative position. // s = 1/2 * a * t^2 + // Step 2: Create rotation matrices for each axis + // Step 4: Rotate the acceleration vector + return motionData.acceleration - .rotateX(-motionData.rotation.x) - .rotateY(-motionData.rotation.y) .rotateZ(-motionData.rotation.z) - .div(2) - .mul(sampleRate * sampleRate); + .rotateY(-motionData.rotation.y) + .rotateX(-motionData.rotation.x) + .mul(sampleRate * sampleRate / 2); } /** From 9b71df061ff3fbad8baed89dc47bc5738ac49864 Mon Sep 17 00:00:00 2001 From: Sam Hos Date: Wed, 29 May 2024 15:56:04 +0200 Subject: [PATCH 04/55] change array --- .../fitbot/ui/components/PersonalMotionPreviewElement.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/code/src/Fitbot/app/src/main/java/com/example/fitbot/ui/components/PersonalMotionPreviewElement.java b/code/src/Fitbot/app/src/main/java/com/example/fitbot/ui/components/PersonalMotionPreviewElement.java index d498761..76e8c65 100644 --- a/code/src/Fitbot/app/src/main/java/com/example/fitbot/ui/components/PersonalMotionPreviewElement.java +++ b/code/src/Fitbot/app/src/main/java/com/example/fitbot/ui/components/PersonalMotionPreviewElement.java @@ -24,6 +24,7 @@ import org.joml.Vector4f; import java.util.ArrayList; import java.util.List; +import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReference; @@ -49,7 +50,7 @@ public class PersonalMotionPreviewElement extends View { private Matrix4f modelViewMatrix = new Matrix4f(); // The model view matrix for the 3D to 2D transformation. private Matrix4f projectionMatrix = new Matrix4f(); // The projection matrix for the 3D to 2D transformation. private final Vector4f objectPosition = new Vector4f(0, 0, -1, 1); // The location of the object in 3D space. - private List vectors = new ArrayList<>(); + private ConcurrentLinkedQueue vectors = new ConcurrentLinkedQueue<>(); private static final String[] USER_PHRASES = { From 6ffbb503c92b5c185367bb6740171fecf1d02caf Mon Sep 17 00:00:00 2001 From: Luca Warmenhoven Date: Wed, 29 May 2024 16:06:10 +0200 Subject: [PATCH 05/55] Added more logging for debugging functionality --- .../PersonalMotionPreviewElement.java | 20 ++++++++----------- .../util/processing/MotionProcessor.java | 6 ++++-- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/code/src/Fitbot/app/src/main/java/com/example/fitbot/ui/components/PersonalMotionPreviewElement.java b/code/src/Fitbot/app/src/main/java/com/example/fitbot/ui/components/PersonalMotionPreviewElement.java index eca81f6..4154037 100644 --- a/code/src/Fitbot/app/src/main/java/com/example/fitbot/ui/components/PersonalMotionPreviewElement.java +++ b/code/src/Fitbot/app/src/main/java/com/example/fitbot/ui/components/PersonalMotionPreviewElement.java @@ -2,7 +2,6 @@ package com.example.fitbot.ui.components; import android.content.Context; import android.graphics.Canvas; -import android.graphics.Color; import android.graphics.Paint; import android.graphics.Path; import android.util.AttributeSet; @@ -13,8 +12,6 @@ import com.aldebaran.qi.sdk.QiContext; import com.example.fitbot.exercise.Exercise; import com.example.fitbot.util.FitnessCycle; import com.example.fitbot.util.path.GesturePath; -import com.example.fitbot.util.path.PathSegment; -import com.example.fitbot.util.processing.MotionData; import com.example.fitbot.util.processing.MotionProcessor; import org.joml.Matrix4f; @@ -22,11 +19,8 @@ import org.joml.Vector2f; import org.joml.Vector3f; import org.joml.Vector4f; -import java.util.ArrayList; -import java.util.List; import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.atomic.AtomicInteger; -import java.util.concurrent.atomic.AtomicReference; public class PersonalMotionPreviewElement extends View { @@ -47,9 +41,11 @@ public class PersonalMotionPreviewElement extends View { private final Paint targetPaint = new Paint(); private final Paint backgroundColor = new Paint(); - private Matrix4f modelViewMatrix = new Matrix4f(); // The model view matrix for the 3D to 2D transformation. + private Matrix4f modelMatrix = new Matrix4f(); // The model view matrix for the 3D to 2D transformation. + private Matrix4f viewMatrix = new Matrix4f() + .lookAt(new Vector3f(4, 4, 4), new Vector3f(0, 0, 0), new Vector3f(0, 1, 0)); // The view matrix for the 3D to 2D transformation. private Matrix4f projectionMatrix = new Matrix4f(); // The projection matrix for the 3D to 2D transformation. - private final Vector4f objectPosition = new Vector4f(0, 0, -2, 1); // The location of the object in 3D space. + private final Vector4f objectPosition = new Vector4f(0, 0, 0, 1); // The location of the object in 3D space. private ConcurrentLinkedQueue vectors = new ConcurrentLinkedQueue<>(); private Vector2f[] axisVectors; @@ -172,8 +168,7 @@ public class PersonalMotionPreviewElement extends View { private Vector2f projectVertex(Vector3f point, int virtualWidth, int virtualHeight) { - - modelViewMatrix + modelMatrix .identity() .translate(-objectPosition.x, -objectPosition.y, -objectPosition.z); @@ -185,8 +180,9 @@ public class PersonalMotionPreviewElement extends View { // Convert world coordinates to screen-space using MVP matrix Vector4f screenCoordinates = new Vector4f(point, 1.0f) - .mul(this.modelViewMatrix) - .mul(this.projectionMatrix); + .mul(this.projectionMatrix) + .mul(this.viewMatrix) + .mul(this.modelMatrix); // Normalize screen coordinates from (-1, 1) to (0, virtualWidth) and (0, virtualHeight) float normalizedX = (screenCoordinates.x / screenCoordinates.w + 1.0f) * 0.5f * virtualWidth; diff --git a/code/src/Fitbot/app/src/main/java/com/example/fitbot/util/processing/MotionProcessor.java b/code/src/Fitbot/app/src/main/java/com/example/fitbot/util/processing/MotionProcessor.java index 016a520..de35e7d 100644 --- a/code/src/Fitbot/app/src/main/java/com/example/fitbot/util/processing/MotionProcessor.java +++ b/code/src/Fitbot/app/src/main/java/com/example/fitbot/util/processing/MotionProcessor.java @@ -169,11 +169,13 @@ public class MotionProcessor { // Step 2: Create rotation matrices for each axis // Step 4: Rotate the acceleration vector - return motionData.acceleration + return motionData.rotation + .mul(5); + /*return motionData.acceleration .rotateZ(-motionData.rotation.z) .rotateY(-motionData.rotation.y) .rotateX(-motionData.rotation.x) - .mul(sampleRate * sampleRate / 2); + .mul(sampleRate * sampleRate / 2);*/ } /** From 2426e7b2e22947318b4ac4db01feb0765e925870 Mon Sep 17 00:00:00 2001 From: Luca Warmenhoven Date: Wed, 29 May 2024 16:11:43 +0200 Subject: [PATCH 06/55] Updated PersonalMotionPreviewElement --- .../components/PersonalMotionPreviewElement.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/code/src/Fitbot/app/src/main/java/com/example/fitbot/ui/components/PersonalMotionPreviewElement.java b/code/src/Fitbot/app/src/main/java/com/example/fitbot/ui/components/PersonalMotionPreviewElement.java index 4154037..141b0bc 100644 --- a/code/src/Fitbot/app/src/main/java/com/example/fitbot/ui/components/PersonalMotionPreviewElement.java +++ b/code/src/Fitbot/app/src/main/java/com/example/fitbot/ui/components/PersonalMotionPreviewElement.java @@ -102,12 +102,12 @@ public class PersonalMotionPreviewElement extends View { this.axisVectors = new Vector2f[] { - projectVertex(new Vector3f(-1.0f, 0, 0), getWidth(), getHeight()), - projectVertex(new Vector3f(1.0f, 0, 0), getWidth(), getHeight()), - projectVertex(new Vector3f(0, -1.0f, 0), getWidth(), getHeight()), - projectVertex(new Vector3f(0, 1.0f, 0), getWidth(), getHeight()), - projectVertex(new Vector3f(0, 0, -1.0f), getWidth(), getHeight()), - projectVertex(new Vector3f(0, 0, 1.0f), getWidth(), getHeight()) + projectVertex(new Vector3f(-100.0f, 0, 0), getWidth(), getHeight()), + projectVertex(new Vector3f(100.0f, 0, 0), getWidth(), getHeight()), + projectVertex(new Vector3f(0, -100.0f, 0), getWidth(), getHeight()), + projectVertex(new Vector3f(0, 100.0f, 0), getWidth(), getHeight()), + projectVertex(new Vector3f(0, 0, -100.0f), getWidth(), getHeight()), + projectVertex(new Vector3f(0, 0, 100.0f), getWidth(), getHeight()) }; } @@ -142,6 +142,9 @@ public class PersonalMotionPreviewElement extends View { Log.i("MotionProcessor", "Processed data: " + progress + " (" + preprocessed + ")"); Vector2f parsed = projectVertex(processed, this.getWidth(), this.getHeight()); this.vectors.add(parsed); + // Remove the first element if the array is too big + if (this.vectors.size() > 100) + this.vectors.poll(); }); saySomethingNice(); } From 34dc294d062f5b9ddce80b07bacff63c96791c00 Mon Sep 17 00:00:00 2001 From: SebasKoedam Date: Wed, 29 May 2024 16:12:23 +0200 Subject: [PATCH 07/55] fixed the main menu bars and theme --- code/src/Fitbot/app/src/main/res/drawable/box_background.xml | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 code/src/Fitbot/app/src/main/res/drawable/box_background.xml diff --git a/code/src/Fitbot/app/src/main/res/drawable/box_background.xml b/code/src/Fitbot/app/src/main/res/drawable/box_background.xml new file mode 100644 index 0000000..a8b409b --- /dev/null +++ b/code/src/Fitbot/app/src/main/res/drawable/box_background.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file From 4b46738bf04b65db35e87f7f3b79e10104a6c041 Mon Sep 17 00:00:00 2001 From: SebasKoedam Date: Wed, 29 May 2024 16:12:37 +0200 Subject: [PATCH 08/55] fixed the main menu bars and theme --- code/src/Fitbot/.idea/misc.xml | 6 +- .../fitbot/ui/activities/MainActivity.java | 69 ++++++++++++++----- .../src/main/res/drawable/box_background.xml | 8 ++- .../src/main/res/layout/activity_fitness.xml | 2 +- .../app/src/main/res/layout/activity_main.xml | 55 ++++++++------- .../Fitbot/app/src/main/res/layout/header.xml | 2 +- .../Fitbot/app/src/main/res/values/colors.xml | 8 ++- .../Fitbot/app/src/main/res/values/styles.xml | 9 ++- 8 files changed, 109 insertions(+), 50 deletions(-) diff --git a/code/src/Fitbot/.idea/misc.xml b/code/src/Fitbot/.idea/misc.xml index c120dfd..1807d5f 100644 --- a/code/src/Fitbot/.idea/misc.xml +++ b/code/src/Fitbot/.idea/misc.xml @@ -20,6 +20,7 @@ + @@ -27,13 +28,14 @@ - + - + + diff --git a/code/src/Fitbot/app/src/main/java/com/example/fitbot/ui/activities/MainActivity.java b/code/src/Fitbot/app/src/main/java/com/example/fitbot/ui/activities/MainActivity.java index ca30bf2..2297d65 100644 --- a/code/src/Fitbot/app/src/main/java/com/example/fitbot/ui/activities/MainActivity.java +++ b/code/src/Fitbot/app/src/main/java/com/example/fitbot/ui/activities/MainActivity.java @@ -11,26 +11,34 @@ import android.support.v7.app.ActionBarDrawerToggle; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.Toolbar; import android.util.Log; +import android.view.View; +import android.view.WindowManager; import android.widget.Button; import com.example.fitbot.R; public class MainActivity extends AppCompatActivity { - //Variables + // Variables DrawerLayout drawerLayout; NavigationView navigationView; Toolbar toolbar; Button startButton; @SuppressLint("WrongViewCast") - @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); - Button startButton = findViewById(R.id.startButton); + // Set full screen mode + getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, + WindowManager.LayoutParams.FLAG_FULLSCREEN); + + // Hide system UI + hideSystemUI(); + + startButton = findViewById(R.id.startButton); startButton.setOnClickListener(v -> { Uri videoUri = Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.bicepvideo); Intent intent = new Intent(MainActivity.this, FitnessActivity.class); @@ -48,32 +56,61 @@ public class MainActivity extends AppCompatActivity { toolbar = findViewById(R.id.toolbar); startButton = findViewById(R.id.startButton); - startButton.setOnClickListener(v -> { // Switch to fitness activity - Log.i("MainActivity", "Switching to FitnessActivity"); - Intent intent = new Intent(MainActivity.this, FitnessActivity.class); - startActivity(intent); - }); + // Hide the action bar + if (getSupportActionBar() != null) { + getSupportActionBar().hide(); + } /*---Tool Bar---*/ setSupportActionBar(toolbar); // Make the toolbar act as the action bar - getSupportActionBar().setDisplayShowTitleEnabled(false); // Remove the title from the toolbar + if (getSupportActionBar() != null) { + getSupportActionBar().setDisplayShowTitleEnabled(false); // Remove the title from the toolbar + } /*---Navigation Drawer Menu---*/ navigationView.bringToFront(); // Make the navigation drawer menu clickable - ActionBarDrawerToggle toggle=new // Create a toggle for the navigation drawer - ActionBarDrawerToggle(this,drawerLayout,toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close); + ActionBarDrawerToggle toggle = new // Create a toggle for the navigation drawer + ActionBarDrawerToggle(this, drawerLayout, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close) { + @Override + public void onDrawerOpened(View drawerView) { + super.onDrawerOpened(drawerView); + hideSystemUI(); + } + + @Override + public void onDrawerClosed(View drawerView) { + super.onDrawerClosed(drawerView); + hideSystemUI(); + } + }; drawerLayout.addDrawerListener(toggle); toggle.syncState(); // Synchronize the state of the navigation drawer } + private void hideSystemUI() { + View decorView = getWindow().getDecorView(); + // Hide the status bar and navigation bar + int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN + | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION + | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY; + decorView.setSystemUiVisibility(uiOptions); + } + @Override - public void onBackPressed(){ // Close the navigation drawer when the back button is pressed - if(drawerLayout.isDrawerOpen(GravityCompat.START)){ - drawerLayout.closeDrawer(GravityCompat.START); + public void onWindowFocusChanged(boolean hasFocus) { + super.onWindowFocusChanged(hasFocus); + if (hasFocus) { + hideSystemUI(); } - else - {super.onBackPressed(); + } + + @Override + public void onBackPressed() { // Close the navigation drawer when the back button is pressed + if (drawerLayout.isDrawerOpen(GravityCompat.START)) { + drawerLayout.closeDrawer(GravityCompat.START); + } else { + super.onBackPressed(); } } } diff --git a/code/src/Fitbot/app/src/main/res/drawable/box_background.xml b/code/src/Fitbot/app/src/main/res/drawable/box_background.xml index a8b409b..53f8ad7 100644 --- a/code/src/Fitbot/app/src/main/res/drawable/box_background.xml +++ b/code/src/Fitbot/app/src/main/res/drawable/box_background.xml @@ -1,4 +1,6 @@ - - - \ No newline at end of file + + + + + \ No newline at end of file diff --git a/code/src/Fitbot/app/src/main/res/layout/activity_fitness.xml b/code/src/Fitbot/app/src/main/res/layout/activity_fitness.xml index 1ddca4c..b204eb8 100644 --- a/code/src/Fitbot/app/src/main/res/layout/activity_fitness.xml +++ b/code/src/Fitbot/app/src/main/res/layout/activity_fitness.xml @@ -5,7 +5,7 @@ xmlns:tools="http://schemas.android.com/tools" android:id="@+id/drawer_layout" android:layout_width="match_parent" android:layout_height="match_parent" -android:background="@color/black" +android:background="@color/darkBlue" android:fitsSystemWindows="true" android:theme="@android:style/Theme.NoTitleBar.Fullscreen" tools:context=".ui.activities.FitnessActivity" diff --git a/code/src/Fitbot/app/src/main/res/layout/activity_main.xml b/code/src/Fitbot/app/src/main/res/layout/activity_main.xml index 49bfb75..032d214 100644 --- a/code/src/Fitbot/app/src/main/res/layout/activity_main.xml +++ b/code/src/Fitbot/app/src/main/res/layout/activity_main.xml @@ -4,9 +4,7 @@ android:id="@+id/drawer_layout" android:layout_width="match_parent" android:layout_height="match_parent" - android:background="#232323" android:fitsSystemWindows="true" - android:theme="@android:style/Theme.NoTitleBar.Fullscreen" tools:context=".ui.activities.MainActivity" tools:openDrawer="start"> @@ -26,36 +24,41 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" /> - + app:layout_constraintTop_toTopOf="parent"> - + + + +