Skip to content
Snippets Groups Projects
Commit aab918f3 authored by SCHILLING Juliette's avatar SCHILLING Juliette
Browse files

enregistrement photo mur ok

parent 5bf97d01
No related branches found
No related tags found
No related merge requests found
......@@ -2,6 +2,7 @@ package com.example.myhabitat;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.provider.MediaStore;
import android.text.Editable;
import android.text.TextWatcher;
......@@ -16,13 +17,18 @@ import androidx.activity.result.contract.ActivityResultContracts;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import habitat.*;
import outils.GestionnaireEditHabitat;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
public class PiecesActivity extends AppCompatActivity {
private Habitat habitat;
private TextView textView;
private GestionnaireEditHabitat gestionnaire;
private ActivityResultLauncher<Intent> launcher;
private ImageButton photoEnCours;
private ImageButton photoEnCours; //Detecte à quel mur associer la photo en cours
@Override
......@@ -59,28 +65,24 @@ public class PiecesActivity extends AppCompatActivity {
Bitmap photoBitmap = (Bitmap) extras.get("data");
//On vérifie que la photo a bien été prise
//Toast.makeText(PiecesActivity.this, "hauteur de l'image : " + photoBitmap.getHeight(), Toast.LENGTH_SHORT);
Log.i("testPhotoBitmap", "hauteur de l'image : " + photoBitmap.getHeight());
gestionnaire.getMur(photoEnCours).setPhoto(photoBitmap);
affichePieces();
/*
//On enregistre la photo
FileOutputStream fos = null;
try {
fos = openFileOutput("image.data", MODE_PRIVATE);
photoBitmap.compress(Bitmap.CompressFormat.PNG, 100, fos);
fos.flush();
Log.i("MainActivity", "La photo a bien été enregistrée");
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
} catch (IOException e) {
throw new RuntimeException(e);
Mur murAssocie = gestionnaire.getMur(photoEnCours);
if(murAssocie != null){
//On enregistre la photo
FileOutputStream fos = null;
try {
fos = openFileOutput(murAssocie.getId()+".data", MODE_PRIVATE);
photoBitmap.compress(Bitmap.CompressFormat.PNG, 100, fos);
fos.flush();
Log.i("enregistrementPhoto", "La photo " + murAssocie.getId()+".data a bien été enregistrée");
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
*/
affichePieces();
}
}
......@@ -126,7 +128,22 @@ public class PiecesActivity extends AppCompatActivity {
ImageButton imageButton = new ImageButton(this);
imageButton.setMaxHeight(50);
imageButton.setMaxWidth(50);
imageButton.setImageBitmap(mur.getPhoto());
//imageButton.setImageBitmap(mur.getPhoto());
//On récupère la photo
FileInputStream fis = null;
try {
fis = openFileInput(mur.getId()+".data");
} catch (FileNotFoundException e) {
//throw new RuntimeException(e);
}
if (fis != null) {
Bitmap bm = BitmapFactory.decodeStream(fis);
imageButton.setImageBitmap(bm);
}
gestionnaire.addEditMur(imageButton, mur);
imageButton.setOnClickListener(new View.OnClickListener() {
@Override
......
......@@ -3,38 +3,32 @@ package habitat;
import android.graphics.Bitmap;
import android.os.Parcel;
import android.os.Parcelable;
import outils.FabriqueId;
public class Mur implements Parcelable {
private Habitat habitat;
private Piece piece;
private Orientation orientation;
private Bitmap photo;
public Bitmap getPhoto() {
return photo;
}
public void setPhoto(Bitmap photo) {
this.photo = photo;
}
private int id; //Utile pour stocker la photo associée au mur
public Mur(Piece piece, Habitat habitat) {
this.habitat = habitat;
this.piece = piece;
this.orientation = Orientation.SUD; //Par défaut
photo = null;
id = FabriqueId.getInstance().getId();
}
public Mur(Piece piece, Orientation orientation, Habitat habitat) {
this.habitat = habitat;
this.piece = piece;
this.orientation = orientation;
id = FabriqueId.getInstance().getId();
}
protected Mur(Parcel in) {
orientation = (Orientation) in.readSerializable();
photo = in.readParcelable(Bitmap.class.getClassLoader());
id = in.readInt();
}
public static final Creator<Mur> CREATOR = new Creator<Mur>() {
......@@ -73,6 +67,14 @@ public class Mur implements Parcelable {
this.habitat = habitat;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
......@@ -100,6 +102,6 @@ public class Mur implements Parcelable {
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeSerializable(orientation);
dest.writeParcelable(photo, flags);
dest.writeInt(id);
}
}
package outils;
public class FabriqueId {
private int id;
private static FabriqueId instance = new FabriqueId();
public static FabriqueId getInstance(){
return instance;
}
private FabriqueId() {
id = 0;
}
public int getId() {
id++;
return id;
}
public void reset(){
id = 0;
}
}
package habitat;
package outils;
import android.widget.EditText;
import android.widget.ImageButton;
import habitat.Mur;
import habitat.Piece;
import java.util.HashMap;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment