From 0ba6cbedf041caa82ddd784c7ac188525cbfa6e7 Mon Sep 17 00:00:00 2001 From: wuyijun Date: Wed, 6 Dec 2023 20:21:00 +0800 Subject: [PATCH 1/5] Mirror the target control of ObjectNavFragment if front facing camera is used --- .../main/java/org/openbot/objectNav/ObjectNavFragment.java | 7 ++++++- .../robot/src/main/java/org/openbot/vehicle/Control.java | 4 ++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/android/robot/src/main/java/org/openbot/objectNav/ObjectNavFragment.java b/android/robot/src/main/java/org/openbot/objectNav/ObjectNavFragment.java index be04a4950..159653e90 100644 --- a/android/robot/src/main/java/org/openbot/objectNav/ObjectNavFragment.java +++ b/android/robot/src/main/java/org/openbot/objectNav/ObjectNavFragment.java @@ -477,7 +477,12 @@ protected void processFrame(Bitmap bitmap, ImageProxy image) { } tracker.trackResults(mappedRecognitions, frameNum); - handleDriveCommand(tracker.updateTarget()); + Control target = tracker.updateTarget(); + if (lensFacing == CameraSelector.LENS_FACING_FRONT) { + handleDriveCommand(target.mirror()); + } else { + handleDriveCommand(target); + } binding.trackingOverlay.postInvalidate(); } diff --git a/android/robot/src/main/java/org/openbot/vehicle/Control.java b/android/robot/src/main/java/org/openbot/vehicle/Control.java index 94f25d82b..e5d89938b 100644 --- a/android/robot/src/main/java/org/openbot/vehicle/Control.java +++ b/android/robot/src/main/java/org/openbot/vehicle/Control.java @@ -16,4 +16,8 @@ public float getLeft() { public float getRight() { return right; } + + public Control mirror() { + return new Control(this.right, this.left); + } } From 16b36bbaab8c9ef832b6511f29257563a8fd0e58 Mon Sep 17 00:00:00 2001 From: wuyijun Date: Thu, 14 Dec 2023 21:58:03 +0800 Subject: [PATCH 2/5] The convention for the front camera varies across phones. Adding an icon to mirror controls next to the camera flip icon, instead of always mirroring control when using front camera. --- .../org/openbot/objectNav/ObjectNavFragment.java | 9 ++++++++- .../src/main/res/drawable/ic_mirror_control.xml | 16 ++++++++++++++++ .../main/res/drawable/ic_mirror_control_off.xml | 16 ++++++++++++++++ .../src/main/res/drawable/mirror_control.xml | 6 ++++++ .../src/main/res/layout/fragment_object_nav.xml | 14 ++++++++++++-- 5 files changed, 58 insertions(+), 3 deletions(-) create mode 100644 android/robot/src/main/res/drawable/ic_mirror_control.xml create mode 100644 android/robot/src/main/res/drawable/ic_mirror_control_off.xml create mode 100644 android/robot/src/main/res/drawable/mirror_control.xml diff --git a/android/robot/src/main/java/org/openbot/objectNav/ObjectNavFragment.java b/android/robot/src/main/java/org/openbot/objectNav/ObjectNavFragment.java index 159653e90..5bbf32cc5 100644 --- a/android/robot/src/main/java/org/openbot/objectNav/ObjectNavFragment.java +++ b/android/robot/src/main/java/org/openbot/objectNav/ObjectNavFragment.java @@ -58,6 +58,7 @@ public class ObjectNavFragment extends CameraFragment { private Detector detector; + private boolean mirrorControl; private Matrix frameToCropTransform; private Bitmap croppedBitmap; private int sensorOrientation; @@ -146,6 +147,8 @@ public void onNothingSelected(AdapterView parent) {} binding.cameraToggle.setOnClickListener(v -> toggleCamera()); + binding.mirrorControl.setOnClickListener(v -> mirrorControl()); + List models = getModelNames(f -> f.type.equals(Model.TYPE.DETECTOR) && f.pathType != Model.PATH_TYPE.URL); initModelSpinner(binding.modelSpinner, models, preferencesManager.getObjectNavModel()); @@ -228,6 +231,10 @@ public void onNothingSelected(AdapterView parent) {} }); } + private void mirrorControl() { + mirrorControl = !mirrorControl; + } + private void updateCropImageInfo() { // Timber.i("%s x %s",getPreviewSize().getWidth(), getPreviewSize().getHeight()); // Timber.i("%s x %s",getMaxAnalyseImageSize().getWidth(), @@ -478,7 +485,7 @@ protected void processFrame(Bitmap bitmap, ImageProxy image) { tracker.trackResults(mappedRecognitions, frameNum); Control target = tracker.updateTarget(); - if (lensFacing == CameraSelector.LENS_FACING_FRONT) { + if (mirrorControl) { handleDriveCommand(target.mirror()); } else { handleDriveCommand(target); diff --git a/android/robot/src/main/res/drawable/ic_mirror_control.xml b/android/robot/src/main/res/drawable/ic_mirror_control.xml new file mode 100644 index 000000000..eda568095 --- /dev/null +++ b/android/robot/src/main/res/drawable/ic_mirror_control.xml @@ -0,0 +1,16 @@ + + + + + diff --git a/android/robot/src/main/res/drawable/ic_mirror_control_off.xml b/android/robot/src/main/res/drawable/ic_mirror_control_off.xml new file mode 100644 index 000000000..6264f1aa8 --- /dev/null +++ b/android/robot/src/main/res/drawable/ic_mirror_control_off.xml @@ -0,0 +1,16 @@ + + + + + diff --git a/android/robot/src/main/res/drawable/mirror_control.xml b/android/robot/src/main/res/drawable/mirror_control.xml new file mode 100644 index 000000000..387d0c578 --- /dev/null +++ b/android/robot/src/main/res/drawable/mirror_control.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/android/robot/src/main/res/layout/fragment_object_nav.xml b/android/robot/src/main/res/layout/fragment_object_nav.xml index 8eee6817c..545be0cd0 100644 --- a/android/robot/src/main/res/layout/fragment_object_nav.xml +++ b/android/robot/src/main/res/layout/fragment_object_nav.xml @@ -90,10 +90,20 @@ android:scaleType="center" android:src="@drawable/ic_cameraswitch" android:text="@string/camera_facing_back" - app:layout_constraintTop_toTopOf="@+id/autoLinearLayout" - app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintBottom_toBottomOf="@+id/mirrorControl" + app:layout_constraintEnd_toStartOf="@+id/mirrorControl" + app:layout_constraintTop_toTopOf="@+id/mirrorControl" app:tint="@color/openBotBlue" /> + + Date: Sat, 16 Dec 2023 17:53:27 +0800 Subject: [PATCH 3/5] Change the mirror icon appearance --- .../main/res/drawable/ic_mirror_control.xml | 23 +++++++++++-------- .../res/drawable/ic_mirror_control_off.xml | 10 ++------ 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/android/robot/src/main/res/drawable/ic_mirror_control.xml b/android/robot/src/main/res/drawable/ic_mirror_control.xml index eda568095..12ccc2ef8 100644 --- a/android/robot/src/main/res/drawable/ic_mirror_control.xml +++ b/android/robot/src/main/res/drawable/ic_mirror_control.xml @@ -4,13 +4,16 @@ android:viewportWidth="24" android:viewportHeight="24" android:tint="@color/openBotBlue"> - - - - + + + + + + \ No newline at end of file diff --git a/android/robot/src/main/res/drawable/ic_mirror_control_off.xml b/android/robot/src/main/res/drawable/ic_mirror_control_off.xml index 6264f1aa8..0b02a48e6 100644 --- a/android/robot/src/main/res/drawable/ic_mirror_control_off.xml +++ b/android/robot/src/main/res/drawable/ic_mirror_control_off.xml @@ -5,12 +5,6 @@ android:viewportHeight="24" android:tint="?attr/colorControlNormal"> - - + android:pathData="M15,21h2v-2h-2v2zM19,9h2L21,7h-2v2zM3,5v14c0,1.1 0.9,2 2,2h4v-2L5,19L5,5h4L9,3L5,3c-1.1,0 -2,0.9 -2,2zM19,3v2h2c0,-1.1 -0.9,-2 -2,-2zM11,23h2L13,1h-2v22zM19,17h2v-2h-2v2zM15,5h2L17,3h-2v2zM19,13h2v-2h-2v2zM19,21c1.1,0 2,-0.9 2,-2h-2v2z" + android:fillColor="#FF000000"/> From 4d3ed6d7bd5084387af61884a6fbc24230b1d8e1 Mon Sep 17 00:00:00 2001 From: wuyijun Date: Sat, 16 Dec 2023 19:44:31 +0800 Subject: [PATCH 4/5] Adjust layout of icons --- .../src/main/res/layout/fragment_object_nav.xml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/android/robot/src/main/res/layout/fragment_object_nav.xml b/android/robot/src/main/res/layout/fragment_object_nav.xml index 545be0cd0..61d87fa6f 100644 --- a/android/robot/src/main/res/layout/fragment_object_nav.xml +++ b/android/robot/src/main/res/layout/fragment_object_nav.xml @@ -65,7 +65,7 @@ android:id="@+id/usbToggle" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_marginEnd="16dp" + android:layout_marginEnd="12dp" android:button="@drawable/usb_toggle" app:layout_constraintBottom_toBottomOf="@+id/camera_toggle" app:layout_constraintEnd_toStartOf="@+id/camera_toggle" @@ -75,7 +75,7 @@ android:id="@+id/bleToggle" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_marginEnd="16dp" + android:layout_marginEnd="12dp" android:button="@drawable/ble_toggle" app:layout_constraintBottom_toBottomOf="@+id/camera_toggle" app:layout_constraintEnd_toStartOf="@+id/camera_toggle" @@ -85,22 +85,22 @@ android:id="@+id/camera_toggle" android:layout_width="40dp" android:layout_height="40dp" - android:layout_marginRight="16dp" + android:layout_marginEnd="12dp" android:background="@android:color/transparent" android:scaleType="center" android:src="@drawable/ic_cameraswitch" android:text="@string/camera_facing_back" - app:layout_constraintBottom_toBottomOf="@+id/mirrorControl" + app:layout_constraintTop_toTopOf="@+id/autoLinearLayout" app:layout_constraintEnd_toStartOf="@+id/mirrorControl" - app:layout_constraintTop_toTopOf="@+id/mirrorControl" app:tint="@color/openBotBlue" /> From 3643a270fbb0e4ef928fa85e54ab6ea6a97b6ad2 Mon Sep 17 00:00:00 2001 From: wuyijun Date: Sat, 16 Dec 2023 19:53:58 +0800 Subject: [PATCH 5/5] Adjust layout of icons --- android/robot/src/main/res/layout/fragment_object_nav.xml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/android/robot/src/main/res/layout/fragment_object_nav.xml b/android/robot/src/main/res/layout/fragment_object_nav.xml index 61d87fa6f..f8ff6cfc6 100644 --- a/android/robot/src/main/res/layout/fragment_object_nav.xml +++ b/android/robot/src/main/res/layout/fragment_object_nav.xml @@ -65,7 +65,7 @@ android:id="@+id/usbToggle" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_marginEnd="12dp" + android:layout_marginEnd="8dp" android:button="@drawable/usb_toggle" app:layout_constraintBottom_toBottomOf="@+id/camera_toggle" app:layout_constraintEnd_toStartOf="@+id/camera_toggle" @@ -75,7 +75,7 @@ android:id="@+id/bleToggle" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_marginEnd="12dp" + android:layout_marginEnd="8dp" android:button="@drawable/ble_toggle" app:layout_constraintBottom_toBottomOf="@+id/camera_toggle" app:layout_constraintEnd_toStartOf="@+id/camera_toggle" @@ -85,7 +85,7 @@ android:id="@+id/camera_toggle" android:layout_width="40dp" android:layout_height="40dp" - android:layout_marginEnd="12dp" + android:layout_marginEnd="8dp" android:background="@android:color/transparent" android:scaleType="center" android:src="@drawable/ic_cameraswitch" @@ -98,7 +98,7 @@ android:id="@+id/mirrorControl" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_marginEnd="12dp" + android:layout_marginEnd="8dp" android:button="@drawable/mirror_control" android:layout_marginTop="8dp" app:layout_constraintTop_toTopOf="@+id/autoLinearLayout"