From 0ab0c685c1a0ffb6ebc319efd89e73fcc5d11816 Mon Sep 17 00:00:00 2001 From: Luca Warmenhoven Date: Fri, 26 Apr 2024 11:23:31 +0200 Subject: [PATCH 1/9] Updated SportMenuItem --- .../java/com/example/fitbot/MainActivity.java | 11 ++++++++++- .../example/fitbot/speech/SpeechGenerator.java | 18 +++++++++++++----- .../com/example/fitbot/ui/SportMenuItem.java | 15 ++++++++------- 3 files changed, 31 insertions(+), 13 deletions(-) diff --git a/code/src/Fitbot/app/src/main/java/com/example/fitbot/MainActivity.java b/code/src/Fitbot/app/src/main/java/com/example/fitbot/MainActivity.java index 65f5e43..6820fd7 100644 --- a/code/src/Fitbot/app/src/main/java/com/example/fitbot/MainActivity.java +++ b/code/src/Fitbot/app/src/main/java/com/example/fitbot/MainActivity.java @@ -1,6 +1,8 @@ package com.example.fitbot; +import android.content.Intent; import android.os.Bundle; +import android.widget.Button; import com.aldebaran.qi.sdk.QiContext; import com.aldebaran.qi.sdk.QiSDK; @@ -8,6 +10,7 @@ import com.aldebaran.qi.sdk.RobotLifecycleCallbacks; import com.aldebaran.qi.sdk.builder.SayBuilder; import com.aldebaran.qi.sdk.design.activity.RobotActivity; import com.aldebaran.qi.sdk.object.conversation.Say; +import com.example.fitbot.ui.SportMenuActivity; public class MainActivity extends RobotActivity implements RobotLifecycleCallbacks { @@ -17,6 +20,12 @@ public class MainActivity extends RobotActivity implements RobotLifecycleCallbac super.onCreate(savedInstanceState); // Register the RobotLifecycleCallbacks to this Activity. QiSDK.register(this, this); + + Button button = findViewById(R.id.menu_switch_btn); + button.setOnClickListener(v -> { + Intent i = new Intent(MainActivity.this, SportMenuActivity.class); + startActivity(i); + }); } @Override @@ -30,7 +39,7 @@ public class MainActivity extends RobotActivity implements RobotLifecycleCallbac public void onRobotFocusGained(QiContext qiContext) { // Create a new say action. Say say = SayBuilder.with(qiContext) // Create the builder with the context. - .withText("Hallo hoe gaat het?") // Set the text to say. + .withText("Hallo, heb je zin om sportieve activiteiten te verrichten?") // Set the text to say. .build(); // Build the say action. // Execute the action. diff --git a/code/src/Fitbot/app/src/main/java/com/example/fitbot/speech/SpeechGenerator.java b/code/src/Fitbot/app/src/main/java/com/example/fitbot/speech/SpeechGenerator.java index 61c265a..c731a72 100644 --- a/code/src/Fitbot/app/src/main/java/com/example/fitbot/speech/SpeechGenerator.java +++ b/code/src/Fitbot/app/src/main/java/com/example/fitbot/speech/SpeechGenerator.java @@ -6,6 +6,9 @@ import com.aldebaran.qi.sdk.object.locale.Language; import com.aldebaran.qi.sdk.object.locale.Locale; import com.aldebaran.qi.sdk.object.locale.Region; +/** + * SpeechGenerator class for generating speech for the robot + */ public class SpeechGenerator { private static final Locale DUTCH_LOCALE = new Locale(Language.DUTCH, Region.NETHERLANDS); @@ -21,13 +24,18 @@ public class SpeechGenerator { say(phrase, ctx, DUTCH_LOCALE); } - - - public static void say(String text, QiContext ctx, Locale locale) + /** + * Function for making the robot say something with a specific locale + * @param phrase The phrase to make the robot say + * @param ctx The QiContext to use + * @param locale The locale to use + */ + public static void say(String phrase, QiContext ctx, Locale locale) { - SayBuilder.with(ctx) + SayBuilder + .with(ctx) .withLocale(locale) - .withText(text) + .withText(phrase) .build() .run(); } diff --git a/code/src/Fitbot/app/src/main/java/com/example/fitbot/ui/SportMenuItem.java b/code/src/Fitbot/app/src/main/java/com/example/fitbot/ui/SportMenuItem.java index 1d6f394..f571a81 100644 --- a/code/src/Fitbot/app/src/main/java/com/example/fitbot/ui/SportMenuItem.java +++ b/code/src/Fitbot/app/src/main/java/com/example/fitbot/ui/SportMenuItem.java @@ -12,16 +12,15 @@ import com.example.fitbot.sports.ESportType; public class SportMenuItem extends View { - private Paint backgroundPaint, textPaint; - private String title, description; - private Bitmap imageResource; - private Rect imageRect, elementRect; - private ESportType type; + private final Paint backgroundPaint, textPaint; + private final String title; + private final Bitmap imageResource; + private final Rect imageRect, elementRect; + private final ESportType type; - public SportMenuItem(Context context, ESportType type, String title, String description, Bitmap backgroundImage) { + public SportMenuItem(Context context, ESportType type, String title, Bitmap backgroundImage) { super(context); this.title = title; - this.description = description; this.imageResource = backgroundImage; this.imageRect = new Rect(0, 0, this.imageResource.getWidth(), this.imageResource.getHeight()); this.elementRect = new Rect(0, 0, this.getWidth(), this.getHeight()); @@ -29,6 +28,7 @@ public class SportMenuItem extends View { this.backgroundPaint = new Paint(); this.textPaint = new Paint(); this.textPaint.setTextAlign(Paint.Align.CENTER); + this.backgroundPaint.setColor(0xFFF0F0F0); this.textPaint.setColor(0xFF000000); @@ -41,5 +41,6 @@ public class SportMenuItem extends View { canvas.drawBitmap(this.imageResource, this.imageRect, this.elementRect, null); canvas.drawRoundRect(0, 0, getWidth(), getHeight(), 10, 10, backgroundPaint); canvas.drawText(title, getWidth() / 2.0f, this.textPaint.getFontMetrics().top, textPaint); + canvas.drawText("Categorie: " + type.getName(), getWidth() / 2.0f, getHeight() - this.textPaint.getFontMetrics().bottom, textPaint); } } From 0cdb66e72fded1e3a63aee198ab31dce631e8db2 Mon Sep 17 00:00:00 2001 From: Luca Warmenhoven Date: Tue, 7 May 2024 13:48:20 +0200 Subject: [PATCH 2/9] Added expert-review-tips.md and known-issues.md --- docs/documentation/known-issues.md | 19 +++++++++++++++++++ docs/personalDocs/Luca/expert-review-tips.md | 9 +++++++++ 2 files changed, 28 insertions(+) create mode 100644 docs/documentation/known-issues.md create mode 100644 docs/personalDocs/Luca/expert-review-tips.md diff --git a/docs/documentation/known-issues.md b/docs/documentation/known-issues.md new file mode 100644 index 0000000..6484223 --- /dev/null +++ b/docs/documentation/known-issues.md @@ -0,0 +1,19 @@ + + +## Android Studio gradle could not sync with project (MacOS) + +A solution to this issue is by removing the cache files in the gradle folder. +This can be done by executing the following command: + +```bash +sudo rm -rf ~/.gradle/caches/ +``` + +If the issue presists, one can remove the existing gradle executables in the +following path: + +> `/Users/.../.gradle/wrapper/dists/` + +If the issue still remains, one can try removing the gradle files in the project +and try to sync the project again. This can be done by removing the gradle files in +the project source directory and then syncing the project again. diff --git a/docs/personalDocs/Luca/expert-review-tips.md b/docs/personalDocs/Luca/expert-review-tips.md new file mode 100644 index 0000000..fb147bc --- /dev/null +++ b/docs/personalDocs/Luca/expert-review-tips.md @@ -0,0 +1,9 @@ + +## Expert review #1 + +### Document as you go +Documenteer alle problemen die voorkomen bij het project en noteer de +oplossingen voor deze problemen. Dit kan bijvoorbeeld d.m.v. een command die +cache files verwijderd, of op welke manier je een project fixt. Dit kan toekomstige +problemen voorkomen. + From d173546ea2659218258344eedbe57540164ea647 Mon Sep 17 00:00:00 2001 From: Luca Warmenhoven Date: Tue, 7 May 2024 15:09:54 +0200 Subject: [PATCH 3/9] Removed unused files, added motion processing classes --- code/src/Fitbot/.idea/misc.xml | 17 +++--- .../Fitbot/app/src/main/AndroidManifest.xml | 5 +- .../java/com/example/fitbot/MainActivity.java | 14 +---- .../java/com/example/fitbot/MainScreen.java | 1 + .../example/fitbot/processing/MotionData.java | 55 ++++++++++++++++++ .../fitbot/processing/MotionInputStream.java | 31 ++++++++++ .../fitbot/processing/MotionProcessor.java | 4 ++ .../example/fitbot/ui/SportItemActivity.java | 21 ------- .../example/fitbot/ui/SportMenuActivity.java | 22 ------- .../com/example/fitbot/ui/SportMenuItem.java | 46 --------------- .../{robotLogo.png => robot_logo.png} | Bin .../app/src/main/res/layout/activity_main.xml | 5 +- .../Fitbot/app/src/main/res/layout/header.xml | 2 +- 13 files changed, 110 insertions(+), 113 deletions(-) create mode 100644 code/src/Fitbot/app/src/main/java/com/example/fitbot/processing/MotionData.java create mode 100644 code/src/Fitbot/app/src/main/java/com/example/fitbot/processing/MotionInputStream.java create mode 100644 code/src/Fitbot/app/src/main/java/com/example/fitbot/processing/MotionProcessor.java delete mode 100644 code/src/Fitbot/app/src/main/java/com/example/fitbot/ui/SportItemActivity.java delete mode 100644 code/src/Fitbot/app/src/main/java/com/example/fitbot/ui/SportMenuActivity.java delete mode 100644 code/src/Fitbot/app/src/main/java/com/example/fitbot/ui/SportMenuItem.java rename code/src/Fitbot/app/src/main/res/drawable/{robotLogo.png => robot_logo.png} (100%) diff --git a/code/src/Fitbot/.idea/misc.xml b/code/src/Fitbot/.idea/misc.xml index 7b1e4ee..429eb49 100644 --- a/code/src/Fitbot/.idea/misc.xml +++ b/code/src/Fitbot/.idea/misc.xml @@ -3,19 +3,18 @@ diff --git a/code/src/Fitbot/app/src/main/AndroidManifest.xml b/code/src/Fitbot/app/src/main/AndroidManifest.xml index 1c9e481..bd9a6b6 100644 --- a/code/src/Fitbot/app/src/main/AndroidManifest.xml +++ b/code/src/Fitbot/app/src/main/AndroidManifest.xml @@ -16,7 +16,8 @@ android:exported="false" /> + android:exported="true"> + @@ -25,7 +26,7 @@ android:exported="false" /> + android:exported="true" /> diff --git a/code/src/Fitbot/app/src/main/java/com/example/fitbot/MainActivity.java b/code/src/Fitbot/app/src/main/java/com/example/fitbot/MainActivity.java index 9f51f41..9e610d4 100644 --- a/code/src/Fitbot/app/src/main/java/com/example/fitbot/MainActivity.java +++ b/code/src/Fitbot/app/src/main/java/com/example/fitbot/MainActivity.java @@ -1,7 +1,5 @@ package com.example.fitbot; -import android.content.Intent; -import android.support.v7.app.AppCompatActivity; import android.content.Intent; import android.os.Bundle; import android.widget.Button; @@ -9,13 +7,8 @@ import android.widget.Button; import com.aldebaran.qi.sdk.QiContext; import com.aldebaran.qi.sdk.QiSDK; import com.aldebaran.qi.sdk.RobotLifecycleCallbacks; -import com.aldebaran.qi.sdk.builder.AnimateBuilder; -import com.aldebaran.qi.sdk.builder.AnimationBuilder; import com.aldebaran.qi.sdk.builder.SayBuilder; import com.aldebaran.qi.sdk.design.activity.RobotActivity; -import com.aldebaran.qi.sdk.design.activity.conversationstatus.SpeechBarDisplayStrategy; -import com.aldebaran.qi.sdk.object.actuation.Animate; -import com.aldebaran.qi.sdk.object.actuation.Animation; import com.aldebaran.qi.sdk.object.conversation.Phrase; import com.aldebaran.qi.sdk.object.conversation.Say; import com.aldebaran.qi.sdk.object.locale.Language; @@ -30,13 +23,12 @@ public class MainActivity extends RobotActivity implements RobotLifecycleCallbac protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Register the RobotLifecycleCallbacks to this Activity. - QiSDK.register(this, this); - Button button = findViewById(R.id.menu_switch_btn); button.setOnClickListener(v -> { - Intent i = new Intent(MainActivity.this, SportMenuActivity.class); - startActivity(i); + startActivity(new Intent(MainActivity.this, SportMenuActivity.class)); }); + QiSDK.register(this, this); + } @Override diff --git a/code/src/Fitbot/app/src/main/java/com/example/fitbot/MainScreen.java b/code/src/Fitbot/app/src/main/java/com/example/fitbot/MainScreen.java index bc39699..7622ca9 100644 --- a/code/src/Fitbot/app/src/main/java/com/example/fitbot/MainScreen.java +++ b/code/src/Fitbot/app/src/main/java/com/example/fitbot/MainScreen.java @@ -32,6 +32,7 @@ public class MainScreen extends AppCompatActivity { /*---Navigation Drawer Menu---*/ navigationView.bringToFront(); + ActionBarDrawerToggle toggle=new ActionBarDrawerToggle(this,drawerLayout,toolbar,R.string.navigation_drawer_open,R.string.navigation_drawer_close); drawerLayout.addDrawerListener(toggle); diff --git a/code/src/Fitbot/app/src/main/java/com/example/fitbot/processing/MotionData.java b/code/src/Fitbot/app/src/main/java/com/example/fitbot/processing/MotionData.java new file mode 100644 index 0000000..4cc2abf --- /dev/null +++ b/code/src/Fitbot/app/src/main/java/com/example/fitbot/processing/MotionData.java @@ -0,0 +1,55 @@ +package com.example.fitbot.processing; + +public class MotionData { + + // Data of the motion sensor + public float accelerationX; + public float accelerationY; + public float accelerationZ; + public float rotationX; + public float rotationY; + public float rotationZ; + + // Delimiter for the data received from the motion sensor + private static final String DATA_DELIMITER = ";"; + + /** + * Constructor for the MotionData class. + * + * @param accelerationX The acceleration in the X axis in m/s^2. + * @param accelerationY The acceleration in the Y axis in m/s^2. + * @param accelerationZ The acceleration in the Z axis in m/s^2. + * @param rotationX The rotation in the X axis in degrees. + * @param rotationY The rotation in the Y axis in degrees. + * @param rotationZ The rotation in the Z axis in degrees. + */ + public MotionData(float accelerationX, float accelerationY, float accelerationZ, float rotationX, float rotationY, float rotationZ) { + this.accelerationX = accelerationX; + this.accelerationY = accelerationY; + this.accelerationZ = accelerationZ; + this.rotationX = rotationX; + this.rotationY = rotationY; + this.rotationZ = rotationZ; + } + + /** + * Function for decoding a string into a MotionData object. + * This string must contain the data of the motion sensor + * separated by the delimiter. (;) + * + * @param data The string containing the data of the motion sensor. + * @return An instance of MotionData. + */ + public static MotionData decode(String data) { + String[] parts = data.split(DATA_DELIMITER); + return new MotionData( + Float.parseFloat(parts[0]), + Float.parseFloat(parts[1]), + Float.parseFloat(parts[2]), + Float.parseFloat(parts[3]), + Float.parseFloat(parts[4]), + Float.parseFloat(parts[5]) + ); + } + +} diff --git a/code/src/Fitbot/app/src/main/java/com/example/fitbot/processing/MotionInputStream.java b/code/src/Fitbot/app/src/main/java/com/example/fitbot/processing/MotionInputStream.java new file mode 100644 index 0000000..1598693 --- /dev/null +++ b/code/src/Fitbot/app/src/main/java/com/example/fitbot/processing/MotionInputStream.java @@ -0,0 +1,31 @@ +package com.example.fitbot.processing; + +import java.io.InputStream; + +/** + * Class representing the input stream of the motion sensor. + * This class will be responsible for reading the data from + * the motion sensor and processing it, by creating a + * server and starting a WebSocket connection with the ESP32. + */ +public class MotionInputStream extends InputStream { + + /** + * Function for starting the listening process + * of the motion sensor. This function will + * @return An instance of MotionInputStream. + */ + public static MotionInputStream startListening() + { + // Create server + + + return null; + } + + + @Override + public int read() { + return 0; + } +} diff --git a/code/src/Fitbot/app/src/main/java/com/example/fitbot/processing/MotionProcessor.java b/code/src/Fitbot/app/src/main/java/com/example/fitbot/processing/MotionProcessor.java new file mode 100644 index 0000000..9e0e13e --- /dev/null +++ b/code/src/Fitbot/app/src/main/java/com/example/fitbot/processing/MotionProcessor.java @@ -0,0 +1,4 @@ +package com.example.fitbot.processing; + +public class MotionProcessor { +} diff --git a/code/src/Fitbot/app/src/main/java/com/example/fitbot/ui/SportItemActivity.java b/code/src/Fitbot/app/src/main/java/com/example/fitbot/ui/SportItemActivity.java deleted file mode 100644 index 481605d..0000000 --- a/code/src/Fitbot/app/src/main/java/com/example/fitbot/ui/SportItemActivity.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.example.fitbot.ui; - -import android.os.Bundle; -import android.support.v7.app.AppCompatActivity; - -import com.example.fitbot.R; - -public class SportItemActivity extends AppCompatActivity { - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_sport_item); - } - - @Override - protected void onDestroy() { - super.onDestroy(); - } - -} diff --git a/code/src/Fitbot/app/src/main/java/com/example/fitbot/ui/SportMenuActivity.java b/code/src/Fitbot/app/src/main/java/com/example/fitbot/ui/SportMenuActivity.java deleted file mode 100644 index d6d060a..0000000 --- a/code/src/Fitbot/app/src/main/java/com/example/fitbot/ui/SportMenuActivity.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.example.fitbot.ui; - -import android.os.Bundle; -import android.support.v7.app.AppCompatActivity; - -import com.example.fitbot.R; - - -public class SportMenuActivity extends AppCompatActivity { - - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_sport_menu); - } - - @Override - protected void onDestroy() { - super.onDestroy(); - } -} \ No newline at end of file diff --git a/code/src/Fitbot/app/src/main/java/com/example/fitbot/ui/SportMenuItem.java b/code/src/Fitbot/app/src/main/java/com/example/fitbot/ui/SportMenuItem.java deleted file mode 100644 index f571a81..0000000 --- a/code/src/Fitbot/app/src/main/java/com/example/fitbot/ui/SportMenuItem.java +++ /dev/null @@ -1,46 +0,0 @@ -package com.example.fitbot.ui; - -import android.content.Context; -import android.content.Intent; -import android.graphics.Bitmap; -import android.graphics.Canvas; -import android.graphics.Paint; -import android.graphics.Rect; -import android.view.View; - -import com.example.fitbot.sports.ESportType; - -public class SportMenuItem extends View { - - private final Paint backgroundPaint, textPaint; - private final String title; - private final Bitmap imageResource; - private final Rect imageRect, elementRect; - private final ESportType type; - - public SportMenuItem(Context context, ESportType type, String title, Bitmap backgroundImage) { - super(context); - this.title = title; - this.imageResource = backgroundImage; - this.imageRect = new Rect(0, 0, this.imageResource.getWidth(), this.imageResource.getHeight()); - this.elementRect = new Rect(0, 0, this.getWidth(), this.getHeight()); - this.type = type; - this.backgroundPaint = new Paint(); - this.textPaint = new Paint(); - this.textPaint.setTextAlign(Paint.Align.CENTER); - - this.backgroundPaint.setColor(0xFFF0F0F0); - this.textPaint.setColor(0xFF000000); - - this.setOnClickListener(v -> context.startActivity(new Intent(context, SportItemActivity.class))); - } - - @Override - protected void onDraw(Canvas canvas) { - super.onDraw(canvas); - canvas.drawBitmap(this.imageResource, this.imageRect, this.elementRect, null); - canvas.drawRoundRect(0, 0, getWidth(), getHeight(), 10, 10, backgroundPaint); - canvas.drawText(title, getWidth() / 2.0f, this.textPaint.getFontMetrics().top, textPaint); - canvas.drawText("Categorie: " + type.getName(), getWidth() / 2.0f, getHeight() - this.textPaint.getFontMetrics().bottom, textPaint); - } -} diff --git a/code/src/Fitbot/app/src/main/res/drawable/robotLogo.png b/code/src/Fitbot/app/src/main/res/drawable/robot_logo.png similarity index 100% rename from code/src/Fitbot/app/src/main/res/drawable/robotLogo.png rename to code/src/Fitbot/app/src/main/res/drawable/robot_logo.png 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 75bba1c..b160bcf 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 @@ -19,14 +19,17 @@ android:layout_height="match_parent" android:layout_gravity="start" app:headerLayout="@layout/header" + app:menu="@menu/main_menu" />