Skip to content
Snippets Groups Projects
Commit 1fea123b authored by CHAPUSOT Alexis's avatar CHAPUSOT Alexis
Browse files

prise de photo

parent 9497b962
No related branches found
No related tags found
No related merge requests found
......@@ -8,9 +8,8 @@ android {
defaultConfig {
applicationId = "com.example.buildingbuilder"
minSdk = 24
targetSdk = 30
minSdk = 30
targetSdk = 34
versionCode = 1
versionName = "1.0"
......
package com.example.buildingbuilder;
import android.Manifest;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.view.View;
import android.widget.ImageView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import androidx.camera.core.Camera;
import androidx.camera.core.CameraSelector;
import androidx.camera.core.Preview;
import androidx.camera.core.*;
import androidx.camera.lifecycle.ProcessCameraProvider;
import androidx.camera.view.PreviewView;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.lifecycle.LifecycleOwner;
import com.example.buildingbuilder.Data.BuildingManager;
import com.example.buildingbuilder.Data.Room;
import com.example.buildingbuilder.Data.Wall;
import com.google.common.util.concurrent.ListenableFuture;
import org.jetbrains.annotations.NotNull;
import java.io.File;
import java.util.Locale;
import java.util.concurrent.ExecutionException;
......@@ -26,18 +32,49 @@ public class CameraWithAccelererometre extends AppCompatActivity {
private ListenableFuture<ProcessCameraProvider> cameraProviderFuture;
private PreviewView previewView;
private Boolean updateMode;
private CameraSelector cameraSelector;
private Preview preview;
private ImageCapture imageCapture;
private String position;
private ImageView captureButton;
private File photoFile;
private ImageView cancelPhotoPicture;
private ImageView retryPicture;
private ImageView photoFinal;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_camera_with_accelerometre);
Intent intent = new Intent();
position=intent.getExtras().getString("position");
this.captureButton = findViewById(R.id.PhotoButton);
this.previewView = findViewById(R.id.previewCamera);
cameraProviderFuture = ProcessCameraProvider.getInstance(this);
cancelPhotoPicture = findViewById(R.id.cancelPhotoPicture);
retryPicture = findViewById(R.id.retryPicture);
photoFinal =findViewById(R.id.photoFinal);
photoFinal.setVisibility(View.INVISIBLE);
cancelPhotoPicture.setOnClickListener(view->{
setResult(RESULT_CANCELED);
finish();
});
if(updateMode){
Room room = BuildingManager.getInstance().getCurrentBuilding().getLastWorkingRoom();
//recopie du mur : prendre la string et les acccès à part;
}
else{
BuildingManager.getInstance().getCurrentBuilding().getLastWorkingRoom().addWorkingWall(new Wall());
}
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CAMERA) != PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.CAMERA},
1000);
} else {
setupCamera();
}
setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}
private void setupCamera() {
......@@ -47,6 +84,46 @@ public class CameraWithAccelererometre extends AppCompatActivity {
try {
ProcessCameraProvider cameraProvider = cameraProviderFuture.get();
bindPreview(cameraProvider);
imageCapture =
new ImageCapture.Builder()
.setTargetRotation(getDisplay().getRotation())
.build();
captureButton.setOnClickListener(view -> {
if(updateMode){
//appeler la photo avec copy en plus pour pouvoir remplacer par la suite sans
}
else {
String location = getFilesDir().getAbsolutePath() + "/" + BuildingManager.getInstance().getCurrentBuilding().getUuid()
+'/'+BuildingManager.getInstance().getCurrentBuilding().getLastWorkingRoom().getUuid();
File photoDirectory = new File(location);
if (!photoDirectory.exists()) {
photoDirectory.mkdirs();
}
photoFile = new File(photoDirectory.getAbsolutePath(), "mur" + position);
}
ImageCapture.OutputFileOptions outputFileOptions =
new ImageCapture.OutputFileOptions.Builder(photoFile).build();
imageCapture.takePicture(outputFileOptions, ContextCompat.getMainExecutor(this),
new ImageCapture.OnImageSavedCallback() {
@Override
public void onImageSaved(@NonNull ImageCapture.OutputFileResults outputFileResults) {
cancelPhotoPicture.setVisibility(View.INVISIBLE);
retryPicture.setVisibility(View.VISIBLE);
photoFinal.setVisibility(View.VISIBLE);
}
@Override
public void onError(@NonNull ImageCaptureException exception) {
// Error in saving image
}
});
});
cameraProvider.bindToLifecycle((LifecycleOwner)this, cameraSelector, imageCapture);
} catch (InterruptedException | ExecutionException e) {
// No errors need to be handled for this Future.
// This should never be reached.
......@@ -71,16 +148,15 @@ public class CameraWithAccelererometre extends AppCompatActivity {
}
void bindPreview(@NonNull ProcessCameraProvider cameraProvider) {
Preview preview = new Preview.Builder()
preview = new Preview.Builder()
.build();
CameraSelector cameraSelector = new CameraSelector.Builder()
cameraSelector = new CameraSelector.Builder()
.requireLensFacing(CameraSelector.LENS_FACING_BACK)
.build();
preview.setSurfaceProvider(previewView.getSurfaceProvider());
Camera camera = cameraProvider.bindToLifecycle((LifecycleOwner)this, cameraSelector, preview);
Camera camera = cameraProvider.bindToLifecycle(this, cameraSelector, preview);
}
}
\ No newline at end of file
......@@ -79,7 +79,9 @@ public class Room implements IterableItem {
public Wall getCurrentWall() {
return workingWall;
}
public String getUuid(){
return uuid;
}
public void validWall(String position) {
if(position.equals("north")){
walls[0]=workingWall;
......@@ -95,16 +97,35 @@ public class Room implements IterableItem {
}
}
public boolean hasNorth(){
return walls[0].islocated();
return walls[0] == null || walls[0].islocated();
}
public boolean hasEast(){
return walls[1].islocated();
return walls[1] == null || walls[1].islocated();
}
public boolean hasSouth(){
return walls[2].islocated();
return walls[2] == null || walls[2].islocated();
}
public boolean hasWeast(){
return walls[3].islocated();
return walls[3] == null || walls[3].islocated();
}
public Wall getWall(String position) {
if(position.equals("north")){
return walls[0];
}
if(position.equals("east")){
return walls[1];
}
if(position.equals("south")){
return walls[2];
}
if(position.equals("west")){
return walls[3];
}
return null;
}
public void addWorkingWall(Wall wall) {
workingWall = wall;
}
}
......@@ -3,9 +3,9 @@ package com.example.buildingbuilder.Data;
import java.util.ArrayList;
public class Wall {
ArrayList<Access> access;
private ArrayList<Access> access;
String location;
private String location;
public Wall(){
access = new ArrayList<>();
}
......@@ -16,4 +16,8 @@ public class Wall {
public boolean islocated(){
return location == null;
}
public String getLocation() {
return location;
}
}
......@@ -39,7 +39,7 @@ public class MainActivity extends AppCompatActivity {
addLauncher = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), result -> {
if(result.getResultCode()==RESULT_OK){
Log.i("Main","j'ai validé");
Intent data = result.getData();
Bundle extras = null;
if (data != null) {
......@@ -51,7 +51,8 @@ public class MainActivity extends AppCompatActivity {
}
if (position!=null){
//on fera la mise à jour en fonction de la position
//on fera la mise à jour du monde ajoutant les nouvelles qui ne sont pas dans celle de base plus mettre à jours les info des salles concernés
//parcours tous les murs du monde et si la location est XXX_copy déplacer le fichier en XXX et changer la localisation
}
else{
Building building = BuildingManager.getInstance().getCurrentBuilding();
......
......@@ -2,6 +2,8 @@ package com.example.buildingbuilder;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
......@@ -17,6 +19,10 @@ import com.example.buildingbuilder.Data.BuildingManager;
import com.example.buildingbuilder.Data.Room;
import org.jetbrains.annotations.NotNull;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
public class RoomCreator extends AppCompatActivity {
private boolean updateMode;
private int position;
......@@ -83,15 +89,62 @@ public class RoomCreator extends AppCompatActivity {
wallLauncher = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), result ->{
if (result.getResultCode()==RESULT_OK){
if(updateMode){
//Mise à jour du mur selon la position
//Ecrasé le mur
//reaffichage de l'image selon la position
}
else{
BuildingManager.getInstance().getCurrentBuilding().getLastWorkingRoom().validWall(result.getData().getExtras().getString("position"));
//affichage de l'image selon mur
//affichage du bouton
if(result.getData().getExtras().getString("position").equals("north")){
String location = BuildingManager.getInstance().getCurrentBuilding().getLastWorkingRoom().getWall("north").getLocation();
FileInputStream fis = null;
try {
fis = new FileInputStream(new File(location));
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
}
Bitmap coverPicture = BitmapFactory.decodeStream(fis);
imageMurNord.setImageBitmap(coverPicture);
buttonEditMurNord.setVisibility(View.VISIBLE);
}
if(result.getData().getExtras().getString("position").equals("east")){
String location = BuildingManager.getInstance().getCurrentBuilding().getLastWorkingRoom().getWall("east").getLocation();
FileInputStream fis = null;
try {
fis = new FileInputStream(new File(location));
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
}
Bitmap coverPicture = BitmapFactory.decodeStream(fis);
imageMurEst.setImageBitmap(coverPicture);
buttonEditMurEst.setVisibility(View.VISIBLE);
}
if(result.getData().getExtras().getString("position").equals("weast")){
String location = BuildingManager.getInstance().getCurrentBuilding().getLastWorkingRoom().getWall("west").getLocation();
FileInputStream fis = null;
try {
fis = new FileInputStream(new File(location));
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
}
Bitmap coverPicture = BitmapFactory.decodeStream(fis);
imageMurOuest.setImageBitmap(coverPicture);
buttonEditMurOuest.setVisibility(View.VISIBLE);
}
if(result.getData().getExtras().getString("position").equals("south")){
String location = BuildingManager.getInstance().getCurrentBuilding().getLastWorkingRoom().getWall("south").getLocation();
FileInputStream fis = null;
try {
fis = new FileInputStream(new File(location));
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
}
Bitmap coverPicture = BitmapFactory.decodeStream(fis);
imageMurSud.setImageBitmap(coverPicture);
buttonEditMurSud.setVisibility(View.VISIBLE);
}
}
}
else{
......@@ -101,28 +154,29 @@ public class RoomCreator extends AppCompatActivity {
buttonPhotoMurNord.setOnClickListener(view->{
Intent intentPhoto = new Intent(this,CameraWithAccelererometre.class);
intentPhoto.putExtra("orientation","north");
//si updateMode alors photo->updateMode
intentPhoto.putExtra("updateMode",BuildingManager.getInstance().getCurrentBuilding().getLastWorkingRoom().hasNorth());
wallLauncher.launch(intentPhoto);
});
buttonPhotoMurOuest.setOnClickListener(view->{
Intent intentPhoto = new Intent(this,CameraWithAccelererometre.class);
intentPhoto.putExtra("orientation","West");
//si updateMode alors photo->updateMode
intentPhoto.putExtra("orientation","west");
intentPhoto.putExtra("updateMode",BuildingManager.getInstance().getCurrentBuilding().getLastWorkingRoom().hasWeast());
wallLauncher.launch(intentPhoto);
});
buttonPhotoMurEst.setOnClickListener(view->{
Intent intentPhoto = new Intent(this,CameraWithAccelererometre.class);
intentPhoto.putExtra("orientation","north");
//si updateMode alors photo->updateMode
intentPhoto.putExtra("orientation","east");
intentPhoto.putExtra("updateMode",BuildingManager.getInstance().getCurrentBuilding().getLastWorkingRoom().hasEast());
wallLauncher.launch(intentPhoto);
});
buttonPhotoMurSud.setOnClickListener(view->{
Intent intentPhoto = new Intent(this,CameraWithAccelererometre.class);
intentPhoto.putExtra("orientation","north");
//si updateMode alors photo->updateMode
intentPhoto.putExtra("orientation","south");
intentPhoto.putExtra("updateMode",BuildingManager.getInstance().getCurrentBuilding().getLastWorkingRoom().hasSouth());
wallLauncher.launch(intentPhoto);
});
}
......
......@@ -74,9 +74,7 @@ public class WorldCreator extends AppCompatActivity {
if(!updateMode){
BuildingManager.getInstance().getCurrentBuilding().validRoom();
}else{
//recupèrer la position de la pièce qu'on a souhaité modifier
//mettre à jour la piece avec la pièce temporaire
//retirer la piece temporaire
//garder en mémoire la salle de copy
}
}
else{
......@@ -101,7 +99,7 @@ public class WorldCreator extends AppCompatActivity {
try {
//l'image sera stocké par rapport au monde
//remplacer le nom par copy en cas d'update
String location = BuildingManager.getInstance().getCurrentBuilding().getLocation();
File buildingDirectory = new File(getFilesDir().getAbsolutePath(),BuildingManager.getInstance().getCurrentBuildingUUID());
if (!buildingDirectory.exists()){
if(!buildingDirectory.mkdir()){
......
......@@ -8,14 +8,54 @@
tools:context=".CameraWithAccelererometre">
<FrameLayout
android:id="@+id/container" android:layout_height="316dp" app:layout_constraintTop_toTopOf="parent"
android:id="@+id/container" android:layout_height="313dp"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_width="325dp" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent">
android:layout_width="616dp" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintTop_toTopOf="parent"
android:layout_marginTop="-20dp">
<androidx.camera.view.PreviewView
android:id="@+id/previewCamera" tools:ignore="MissingClass" android:layout_height="match_parent"
android:layout_width="match_parent"/>
android:layout_width="match_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent" app:srcCompat="@drawable/ic_launcher_foreground"
android:id="@+id/ImagePreview" android:visibility="invisible"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent" app:srcCompat="@drawable/ic_launcher_foreground"
android:id="@+id/photoFinal"/>
</androidx.camera.view.PreviewView>
</FrameLayout>
<FrameLayout
android:layout_width="59dp"
android:layout_height="48dp"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent">
<ImageView
android:layout_width="65dp"
android:layout_height="52dp" app:srcCompat="@android:drawable/ic_menu_camera"
android:id="@+id/PhotoButton"
android:layout_marginBottom="28dp"/>
</FrameLayout>
<ImageView
app:srcCompat="@android:drawable/ic_delete"
android:layout_width="95dp"
android:layout_height="41dp" android:id="@+id/cancelPhotoPicture"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:layout_marginStart="200dp"/>
<ImageView
android:layout_width="37dp"
android:layout_height="44dp" app:srcCompat="@drawable/check" android:id="@+id/ConfirmWall"
app:layout_constraintEnd_toEndOf="parent"
android:layout_marginEnd="200dp" app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginBottom="4dp"/>
<ImageView
android:layout_width="65dp"
android:layout_height="52dp" app:srcCompat="@android:drawable/ic_menu_rotate"
android:id="@+id/retryPicture"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent"
android:layout_marginEnd="250dp" android:visibility="invisible"/>
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment