diff --git a/Sources/app/src/main/java/com/furwaz/roomview/PhotoActivity.java b/Sources/app/src/main/java/com/furwaz/roomview/PhotoActivity.java index 3b96bc6545bf0661854083c7177a63ed69d64e96..0cd08eebf67624e2bbd53ca8db338cfdefc4f9a3 100644 --- a/Sources/app/src/main/java/com/furwaz/roomview/PhotoActivity.java +++ b/Sources/app/src/main/java/com/furwaz/roomview/PhotoActivity.java @@ -1,7 +1,13 @@ package com.furwaz.roomview; +import androidx.annotation.NonNull; import androidx.appcompat.app.AppCompatActivity; +import androidx.constraintlayout.widget.ConstraintLayout; +import androidx.core.app.ActivityCompat; +import androidx.core.content.ContextCompat; +import android.Manifest; +import android.animation.ValueAnimator; import android.content.pm.ActivityInfo; import android.content.pm.PackageManager; import android.hardware.Camera; @@ -11,7 +17,10 @@ import android.hardware.SensorEventListener; import android.hardware.SensorManager; import android.os.Bundle; import android.util.Log; +import android.util.TypedValue; import android.view.View; +import android.view.animation.Animation; +import android.view.animation.TranslateAnimation; import android.widget.Button; import android.widget.FrameLayout; import android.widget.ImageButton; @@ -23,9 +32,11 @@ import android.widget.Toast; import java.io.File; import Common.BuildingManager; +import Common.Callback; import Common.ImageManager; import Popups.WalkPopup; import Structures.BuildingInfo; +import Structures.Orientation; import Structures.PhotoInfo; import Structures.RoomInfo; import Structures.WalkInfo; @@ -38,6 +49,9 @@ public class PhotoActivity extends AppCompatActivity implements SensorEventListe protected static final int MODE_EDIT = 1; protected static final int MODE_PHOTO = 2; + Callback _on_resolve_callback; + Callback _on_reject_callback; + SensorManager sm = null; Sensor accelerometer = null; LevelCanvas levelView = null; @@ -47,6 +61,9 @@ public class PhotoActivity extends AppCompatActivity implements SensorEventListe ZoneInfo zone = null; PhotoInfo photo = null; + Orientation displayed_orient = Orientation.NORTH; + LinearLayout orient_layout = null; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -94,23 +111,32 @@ public class PhotoActivity extends AppCompatActivity implements SensorEventListe Toast.makeText(this, "Error : no camera detected on this device", Toast.LENGTH_SHORT).show(); this.finish(); } - Camera c = getCamera(); FrameLayout cam_prev = findViewById(R.id.camera_preview); - CameraPreview camPrev = new CameraPreview(this, c); - cam_prev.addView(camPrev); - - Button btn_nope = findViewById(R.id.btn_nope); - Button btn_foto = findViewById(R.id.btn_foto); + ImageButton btn_nope = findViewById(R.id.btn_nope); + ImageButton btn_foto = findViewById(R.id.btn_foto); btn_nope.setOnClickListener(view -> { this.finish(); }); - btn_foto.setOnClickListener(view -> { - c.takePicture(null, null, (bytes, camera) -> { - photo.setImage(bytes); - setViewMode(MODE_EDIT); + + getCamera(c -> { + Camera camera = (Camera) c; + CameraPreview camPrev = new CameraPreview(this, camera); + cam_prev.addView(camPrev); + + btn_foto.setOnClickListener(view -> { + camera.takePicture(null, null, (bytes, cam) -> { + photo.setImage(bytes); + setViewMode(MODE_EDIT); + }); }); + + return null; + }, error -> { + Toast.makeText(this, (String) error, Toast.LENGTH_SHORT).show(); + finish(); + return null; }); levelView = findViewById(R.id.level_view); @@ -147,6 +173,40 @@ public class PhotoActivity extends AppCompatActivity implements SensorEventListe selector.setPhoto(photo); } + public int getOrientationLayoutPadding(Orientation orient) { + switch (orient) { + case NORTH: return 0; + case EST: return 80; + case SOUTH: return 160; + case WEST: return 240; + } + return 0; + } + + public void displayOrientation(Orientation orient) { + if (this.displayed_orient == orient) return; + + float old_padding = TypedValue.applyDimension( + TypedValue.COMPLEX_UNIT_DIP, + getOrientationLayoutPadding(this.displayed_orient), + getResources().getDisplayMetrics() + ); + float new_padding = TypedValue.applyDimension( + TypedValue.COMPLEX_UNIT_DIP, + getOrientationLayoutPadding(orient), + getResources().getDisplayMetrics() + ); + this.displayed_orient = orient; + + if (orient_layout == null) { + orient_layout = findViewById(R.id.orient_layout); + } + ValueAnimator animator = ValueAnimator.ofInt(-(int) old_padding, -(int) new_padding); + animator.addUpdateListener(valueAnimator -> orient_layout.setPadding((int) valueAnimator.getAnimatedValue(), 0, 0, 0)); + animator.setDuration(400); + animator.start(); + } + @Override protected void onPause() { super.onPause(); @@ -177,21 +237,41 @@ public class PhotoActivity extends AppCompatActivity implements SensorEventListe if (sensorEvent.sensor == accelerometer) { float x_val = sensorEvent.values[0]; float y_val = sensorEvent.values[1]; - float z_val = sensorEvent.values[2]; float orient = (float) Math.atan2(y_val, x_val); if (levelView != null) levelView.askForDraw(orient); + if (orient < 1) + displayOrientation(Orientation.NORTH); + else displayOrientation(Orientation.EST); } } - protected Camera getCamera() { + protected void getCamera(Callback onResolve, Callback onReject) { + this._on_resolve_callback = onResolve; + this._on_reject_callback = onReject; + if (ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA) == PackageManager.PERMISSION_DENIED) + { + ActivityCompat.requestPermissions(this, new String[] {Manifest.permission.CAMERA}, 621); + return; + } Camera c = null; try { c = Camera.open(); + onResolve.call(c); } catch (Exception e) { - Toast.makeText(this, "Error opening camera: "+e, Toast.LENGTH_SHORT).show(); + onReject.call("Error opening camera: "); + } + } + + @Override + public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { + super.onRequestPermissionsResult(requestCode, permissions, grantResults); + if (requestCode != 621) return; + if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { + getCamera(_on_resolve_callback, _on_reject_callback); + } else { + if (_on_reject_callback != null) _on_reject_callback.call( getResources().getString(R.string.camera_error) ); } - return c; } private boolean checkCameraHardware() { diff --git a/Sources/app/src/main/res/drawable/ic_baseline_camera_24.xml b/Sources/app/src/main/res/drawable/ic_baseline_camera_24.xml new file mode 100644 index 0000000000000000000000000000000000000000..c40747e5cf1fd7d39b1bbb168d50aa681425aef4 --- /dev/null +++ b/Sources/app/src/main/res/drawable/ic_baseline_camera_24.xml @@ -0,0 +1,5 @@ +<vector android:height="24dp" android:tint="@color/slate_50" + android:viewportHeight="24" android:viewportWidth="24" + android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android"> + <path android:fillColor="@android:color/white" android:pathData="M9.4,10.5l4.77,-8.26C13.47,2.09 12.75,2 12,2c-2.4,0 -4.6,0.85 -6.32,2.25l3.66,6.35 0.06,-0.1zM21.54,9c-0.92,-2.92 -3.15,-5.26 -6,-6.34L11.88,9h9.66zM21.8,10h-7.49l0.29,0.5 4.76,8.25C21,16.97 22,14.61 22,12c0,-0.69 -0.07,-1.35 -0.2,-2zM8.54,12l-3.9,-6.75C3.01,7.03 2,9.39 2,12c0,0.69 0.07,1.35 0.2,2h7.49l-1.15,-2zM2.46,15c0.92,2.92 3.15,5.26 6,6.34L12.12,15L2.46,15zM13.73,15l-3.9,6.76c0.7,0.15 1.42,0.24 2.17,0.24 2.4,0 4.6,-0.85 6.32,-2.25l-3.66,-6.35 -0.93,1.6z"/> +</vector> diff --git a/Sources/app/src/main/res/drawable/ic_baseline_cancel_24.xml b/Sources/app/src/main/res/drawable/ic_baseline_cancel_24.xml new file mode 100644 index 0000000000000000000000000000000000000000..bf27b253479da007b907927be9d616dd910a7660 --- /dev/null +++ b/Sources/app/src/main/res/drawable/ic_baseline_cancel_24.xml @@ -0,0 +1,5 @@ +<vector android:height="24dp" android:tint="@color/slate_50" + android:viewportHeight="24" android:viewportWidth="24" + android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android"> + <path android:fillColor="@android:color/white" android:pathData="M12,2C6.47,2 2,6.47 2,12s4.47,10 10,10 10,-4.47 10,-10S17.53,2 12,2zM17,15.59L15.59,17 12,13.41 8.41,17 7,15.59 10.59,12 7,8.41 8.41,7 12,10.59 15.59,7 17,8.41 13.41,12 17,15.59z"/> +</vector> diff --git a/Sources/app/src/main/res/drawable/ic_baseline_check_24.xml b/Sources/app/src/main/res/drawable/ic_baseline_check_24.xml new file mode 100644 index 0000000000000000000000000000000000000000..4b5d2897670ab6956b6e83f57344da8dccb4b352 --- /dev/null +++ b/Sources/app/src/main/res/drawable/ic_baseline_check_24.xml @@ -0,0 +1,5 @@ +<vector android:height="24dp" android:tint="@color/slate_50" + android:viewportHeight="24" android:viewportWidth="24" + android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android"> + <path android:fillColor="@android:color/white" android:pathData="M9,16.17L4.83,12l-1.42,1.41L9,19 21,7l-1.41,-1.41z"/> +</vector> diff --git a/Sources/app/src/main/res/drawable/ic_baseline_delete_forever_24.xml b/Sources/app/src/main/res/drawable/ic_baseline_delete_forever_24.xml index f54f7d4d762206d5232528a5b1060f16576c7b4c..e58351127f09e85563d8b953b2414d333b9b04ed 100644 --- a/Sources/app/src/main/res/drawable/ic_baseline_delete_forever_24.xml +++ b/Sources/app/src/main/res/drawable/ic_baseline_delete_forever_24.xml @@ -1,4 +1,4 @@ -<vector android:height="24dp" android:tint="#FFFFFF" +<vector android:height="24dp" android:tint="@color/slate_50" android:viewportHeight="24" android:viewportWidth="24" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android"> <path android:fillColor="@android:color/white" android:pathData="M6,19c0,1.1 0.9,2 2,2h8c1.1,0 2,-0.9 2,-2L18,7L6,7v12zM8.46,11.88l1.41,-1.41L12,12.59l2.12,-2.12 1.41,1.41L13.41,14l2.12,2.12 -1.41,1.41L12,15.41l-2.12,2.12 -1.41,-1.41L10.59,14l-2.13,-2.12zM15.5,4l-1,-1h-5l-1,1L5,4v2h14L19,4z"/> diff --git a/Sources/app/src/main/res/drawable/icon_background_full.xml b/Sources/app/src/main/res/drawable/icon_background_full.xml new file mode 100644 index 0000000000000000000000000000000000000000..60005bcc81ac53f27d39a3f6b923211ae0abc7d1 --- /dev/null +++ b/Sources/app/src/main/res/drawable/icon_background_full.xml @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="utf-8"?> +<shape xmlns:android="http://schemas.android.com/apk/res/android"> + <stroke android:width="4dp" android:color="@color/blue_500" /> + <solid android:color="@color/slate_50"/> + <corners android:radius="8dp"/> + <padding android:left="0dp" android:top="0dp" android:right="0dp" android:bottom="0dp" /> +</shape> \ No newline at end of file diff --git a/Sources/app/src/main/res/layout/activity_photo.xml b/Sources/app/src/main/res/layout/activity_photo.xml index 9987bd8fc63783947a95b2347b4b2cbbb6ea0f1e..db9260b5a1d727bca382d47916fbba4dea3e079f 100644 --- a/Sources/app/src/main/res/layout/activity_photo.xml +++ b/Sources/app/src/main/res/layout/activity_photo.xml @@ -39,7 +39,7 @@ <LinearLayout android:id="@+id/camera_hud" - android:visibility="gone" + android:visibility="visible" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> @@ -65,48 +65,132 @@ <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" - android:orientation="horizontal" + android:orientation="vertical" android:layout_marginBottom="20dp" android:gravity="bottom|center"> <LinearLayout - android:layout_width="0dp" - android:layout_weight="1" + android:layout_width="match_parent" android:layout_height="wrap_content" - android:orientation="horizontal" - android:gravity="center"> - <Button - android:id="@+id/btn_nope" - android:text="@string/cancel" - android:backgroundTint="@color/red_500" + android:gravity="center" + android:layout_marginBottom="8dp" + android:orientation="horizontal"> + <LinearLayout android:layout_width="wrap_content" - android:layout_height="wrap_content"/> + android:layout_height="wrap_content" + android:background="@drawable/icon_background_full" + android:padding="8dp" + android:orientation="horizontal"> + <TextView + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:textStyle="bold" + android:textColor="@color/slate_600" + android:textSize="18sp" + android:text="@string/orientation"/> + <TextView + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:textStyle="bold" + android:textColor="@color/slate_700" + android:textSize="18sp" + android:layout_marginStart="4dp" + android:layout_marginEnd="4dp" + android:text=":"/> + <LinearLayout + android:id="@+id/orient_layout" + android:clipToPadding="true" + android:layout_width="80dp" + android:layout_height="wrap_content" + android:gravity="left" + android:orientation="horizontal"> + <TextView + android:layout_width="80dp" + android:layout_height="wrap_content" + android:textStyle="bold" + android:textColor="@color/blue_500" + android:textSize="18sp" + android:textAlignment="center" + android:text="@string/north"/> + <TextView + android:layout_width="80dp" + android:layout_height="wrap_content" + android:textStyle="bold" + android:textColor="@color/blue_500" + android:textSize="18sp" + android:textAlignment="center" + android:text="@string/est"/> + <TextView + android:layout_width="80dp" + android:layout_height="wrap_content" + android:textStyle="bold" + android:textColor="@color/blue_500" + android:textSize="18sp" + android:textAlignment="center" + android:text="@string/south"/> + <TextView + android:layout_width="80dp" + android:layout_height="wrap_content" + android:textStyle="bold" + android:textColor="@color/blue_500" + android:textSize="18sp" + android:textAlignment="center" + android:text="@string/west"/> + </LinearLayout> + </LinearLayout> </LinearLayout> <LinearLayout - android:layout_width="0dp" - android:layout_weight="1" + android:layout_width="match_parent" android:layout_height="wrap_content" - android:orientation="horizontal" - android:gravity="center"> - <Button - android:id="@+id/btn_foto" - android:text="@string/done" - android:layout_width="wrap_content" - android:layout_height="wrap_content"/> - </LinearLayout> + android:orientation="horizontal"> + <LinearLayout + android:layout_width="0dp" + android:layout_weight="1" + android:layout_height="wrap_content" + android:orientation="horizontal" + android:gravity="center" + android:padding="6dp"> - <LinearLayout - android:layout_width="0dp" - android:layout_weight="1" - android:layout_height="wrap_content" - android:orientation="horizontal" /> + <ImageButton + android:id="@+id/btn_nope" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:backgroundTint="@color/red_500" + android:background="@drawable/icon_background" + android:src="@drawable/ic_baseline_cancel_24" + android:padding="10dp"/> + </LinearLayout> + + <LinearLayout + android:layout_width="0dp" + android:layout_weight="1" + android:layout_height="wrap_content" + android:orientation="horizontal" + android:gravity="center"> + + <ImageButton + android:id="@+id/btn_foto" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:backgroundTint="@color/blue_500" + android:background="@drawable/icon_background" + android:src="@drawable/ic_baseline_camera_24" + android:padding="16dp"/> + </LinearLayout> + + <LinearLayout + android:layout_width="0dp" + android:layout_weight="1" + android:layout_height="wrap_content" + android:orientation="horizontal" /> + </LinearLayout> </LinearLayout> </LinearLayout> <LinearLayout android:id="@+id/edit_hud" - android:visibility="visible" + android:visibility="gone" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> @@ -174,11 +258,13 @@ android:layout_height="wrap_content" android:gravity="center" android:orientation="horizontal"> + <Button android:id="@+id/btn_photo" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:text="@string/change_photo"/> + android:text="@string/edit" + app:icon="@drawable/ic_baseline_edit_24" /> </LinearLayout> <LinearLayout android:layout_width="0dp" @@ -186,11 +272,14 @@ android:layout_height="wrap_content" android:gravity="center" android:orientation="horizontal"> + <Button android:id="@+id/btn_done" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:text="@string/done"/> + android:text="@string/done" + android:backgroundTint="@color/blue_500" + app:icon="@drawable/ic_baseline_check_24" /> </LinearLayout> </LinearLayout> </LinearLayout> diff --git a/Sources/app/src/main/res/values-fr/strings.xml b/Sources/app/src/main/res/values-fr/strings.xml index 10e0ed51f495ee9ac471c90c70f893000ea6e74e..8dde6a5327e6be6dbb05b4881981332d037cd75a 100644 --- a/Sources/app/src/main/res/values-fr/strings.xml +++ b/Sources/app/src/main/res/values-fr/strings.xml @@ -97,4 +97,5 @@ <string name="no_directions_desc">Aucun itinéraire disponible entre ces pièces</string> <string name="go_to_value">Allez dans la pièce {{value}}</string> <string name="go_to_value_desc">Allez dans la pièce {{value1}} en utilisant le passage {{value2}}</string> + <string name="camera_error">Erreur : La camera ne peux pas être utilisée\n(Vérifiez peut-être les permissions de l\'app)</string> </resources> \ No newline at end of file diff --git a/Sources/app/src/main/res/values/strings.xml b/Sources/app/src/main/res/values/strings.xml index 1427a9091b0fab0656320b0ec0a8ea291dd1263c..31dbd8aad22275270e63f845059aefc5b4722025 100644 --- a/Sources/app/src/main/res/values/strings.xml +++ b/Sources/app/src/main/res/values/strings.xml @@ -97,4 +97,5 @@ <string name="no_directions_desc">No route available between those rooms</string> <string name="go_to_value">Go to the room {{value}}</string> <string name="go_to_value_desc">Go to the room {{value1}} by using the path {{value2}}</string> + <string name="camera_error">Error : The camera cannot be open !\n(Maybe check the app\'s permissions)</string> </resources> \ No newline at end of file