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

prise photo mur + recup ok

parent 6cd41dbe
Branches
No related tags found
No related merge requests found
...@@ -2,6 +2,9 @@ ...@@ -2,6 +2,9 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
package="com.example.myhabitat" > package="com.example.myhabitat" >
<uses-feature
android:name="android.hardware.camera"
android:required="true"/>
<application <application
android:allowBackup="true" android:allowBackup="true"
......
package com.example.myhabitat; package com.example.myhabitat;
import android.content.Intent; import android.content.Intent;
import android.graphics.Bitmap;
import android.provider.MediaStore;
import android.text.Editable; import android.text.Editable;
import android.text.TextWatcher; import android.text.TextWatcher;
import android.util.Log;
import android.view.View; import android.view.View;
import android.view.inputmethod.EditorInfo; import android.view.inputmethod.EditorInfo;
import android.widget.EditText; import android.widget.*;
import android.widget.LinearLayout; import androidx.activity.result.ActivityResult;
import android.widget.TextView; import androidx.activity.result.ActivityResultCallback;
import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle; import android.os.Bundle;
import habitat.*; import habitat.*;
...@@ -15,14 +20,19 @@ import habitat.*; ...@@ -15,14 +20,19 @@ import habitat.*;
public class PiecesActivity extends AppCompatActivity { public class PiecesActivity extends AppCompatActivity {
private Habitat habitat; private Habitat habitat;
private TextView textView; private TextView textView;
private GestionnaireEditPiece gestionnaire; private GestionnaireEditHabitat gestionnaire;
private ActivityResultLauncher<Intent> launcher;
private ImageButton photoEnCours;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pieces); setContentView(R.layout.activity_pieces);
gestionnaire = new GestionnaireEditPiece(); gestionnaire = new GestionnaireEditHabitat();
photoEnCours = null;
//On récupère Habitat //On récupère Habitat
Intent intent = getIntent(); Intent intent = getIntent();
...@@ -32,13 +42,50 @@ public class PiecesActivity extends AppCompatActivity { ...@@ -32,13 +42,50 @@ public class PiecesActivity extends AppCompatActivity {
this.habitat = habitat; this.habitat = habitat;
this.habitat.setCorrectly(); this.habitat.setCorrectly();
affichePieces(); affichePieces();
/*
textView = findViewById(R.id.textViewPieces);
textView.setText(habitat.toString());
*/
} }
} }
launcher = registerForActivityResult(
// Contrat qui détermine le type de l'interaction
new ActivityResultContracts.StartActivityForResult(),
// Callback appelé lorsque le résultat sera disponible
new ActivityResultCallback<ActivityResult>() {
@Override
public void onActivityResult(ActivityResult result) {
//On récupère les données de habitat
Intent intent = result.getData();
if(intent != null) {
Bundle extras = intent.getExtras();
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);
}
*/
}
}
}
);
} }
private void affichePieces() { private void affichePieces() {
...@@ -50,7 +97,7 @@ public class PiecesActivity extends AppCompatActivity { ...@@ -50,7 +97,7 @@ public class PiecesActivity extends AppCompatActivity {
editText.setText(piece.getNom()); editText.setText(piece.getNom());
editText.setImeOptions(EditorInfo.IME_ACTION_DONE); editText.setImeOptions(EditorInfo.IME_ACTION_DONE);
editText.setSingleLine(); editText.setSingleLine();
gestionnaire.add(editText, piece); gestionnaire.addEditText(editText, piece);
editText.addTextChangedListener(new TextWatcher() { editText.addTextChangedListener(new TextWatcher() {
@Override @Override
...@@ -72,7 +119,28 @@ public class PiecesActivity extends AppCompatActivity { ...@@ -72,7 +119,28 @@ public class PiecesActivity extends AppCompatActivity {
TextView textView1 = new TextView(this); TextView textView1 = new TextView(this);
textView1.setText(piece.getMurs().toString()); textView1.setText(piece.getMurs().toString());
ll.addView(editText); ll.addView(editText);
ll.addView(textView1); //ll.addView(textView1);
for(Mur mur : piece.getMurs()){
LinearLayout llMur = new LinearLayout(this);
llMur.setOrientation(LinearLayout.HORIZONTAL);
ImageButton imageButton = new ImageButton(this);
imageButton.setMaxHeight(50);
imageButton.setMaxWidth(50);
imageButton.setImageBitmap(mur.getPhoto());
gestionnaire.addEditMur(imageButton, mur);
imageButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
photoEnCours = imageButton;
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if (intent.resolveActivity(getPackageManager()) != null){
launcher.launch(intent);
}
}
});
llMur.addView(imageButton);
ll.addView(llMur);
}
} }
} }
......
package habitat;
import android.widget.EditText;
import android.widget.ImageButton;
import java.util.HashMap;
public class GestionnaireEditHabitat {
private HashMap<EditText, Piece> hmapEditText;
private HashMap<ImageButton, Mur> hmapEditMur;
public GestionnaireEditHabitat() {
hmapEditText = new HashMap<EditText, Piece>();
hmapEditMur = new HashMap<ImageButton, Mur>();
}
public void addEditText(EditText editText, Piece piece){
hmapEditText.put(editText, piece);
}
public Piece getPiece(EditText editText){
return hmapEditText.get(editText);
}
public void addEditMur(ImageButton imageButton, Mur mur){
hmapEditMur.put(imageButton, mur);
}
public Mur getMur(ImageButton imageButton){
return hmapEditMur.get(imageButton);
}
public void reset(){
hmapEditText.clear();
hmapEditMur.clear();
}
}
package habitat;
import android.widget.EditText;
import java.util.HashMap;
public class GestionnaireEditPiece {
private HashMap<EditText, Piece> hmap;
public GestionnaireEditPiece() {
hmap = new HashMap<EditText, Piece>();
}
public void add(EditText editText, Piece piece){
hmap.put(editText, piece);
}
public Piece getPiece(EditText editText){
return hmap.get(editText);
}
public void reset(){
hmap.clear();
}
}
...@@ -40,13 +40,6 @@ public class Habitat implements Parcelable { ...@@ -40,13 +40,6 @@ public class Habitat implements Parcelable {
Mur murO = new Mur(piece1, Orientation.OUEST, this); Mur murO = new Mur(piece1, Orientation.OUEST, this);
piece1.setMurs(murS, murO, murN, murE); piece1.setMurs(murS, murO, murN, murE);
pieces.add(piece1); pieces.add(piece1);
Piece piece2 = new Piece("p2", this);
murN = new Mur(piece1, Orientation.NORD, this);
murE = new Mur(piece1, Orientation.EST, this);
murS = new Mur(piece1, Orientation.SUD, this);
murO = new Mur(piece1, Orientation.OUEST, this);
piece2.setMurs(murS, murO, murN, murE);
pieces.add(piece2);
} }
public Habitat(Piece... pieces) { public Habitat(Piece... pieces) {
......
package habitat; package habitat;
import android.graphics.Bitmap;
import android.os.Parcel; import android.os.Parcel;
import android.os.Parcelable; import android.os.Parcelable;
...@@ -8,11 +9,21 @@ public class Mur implements Parcelable { ...@@ -8,11 +9,21 @@ public class Mur implements Parcelable {
private Habitat habitat; private Habitat habitat;
private Piece piece; private Piece piece;
private Orientation orientation; private Orientation orientation;
private Bitmap photo;
public Bitmap getPhoto() {
return photo;
}
public void setPhoto(Bitmap photo) {
this.photo = photo;
}
public Mur(Piece piece, Habitat habitat) { public Mur(Piece piece, Habitat habitat) {
this.habitat = habitat; this.habitat = habitat;
this.piece = piece; this.piece = piece;
this.orientation = Orientation.SUD; //Par défaut this.orientation = Orientation.SUD; //Par défaut
photo = null;
} }
public Mur(Piece piece, Orientation orientation, Habitat habitat) { public Mur(Piece piece, Orientation orientation, Habitat habitat) {
...@@ -23,6 +34,7 @@ public class Mur implements Parcelable { ...@@ -23,6 +34,7 @@ public class Mur implements Parcelable {
protected Mur(Parcel in) { protected Mur(Parcel in) {
orientation = (Orientation) in.readSerializable(); orientation = (Orientation) in.readSerializable();
photo = in.readParcelable(Bitmap.class.getClassLoader());
} }
public static final Creator<Mur> CREATOR = new Creator<Mur>() { public static final Creator<Mur> CREATOR = new Creator<Mur>() {
...@@ -88,5 +100,6 @@ public class Mur implements Parcelable { ...@@ -88,5 +100,6 @@ public class Mur implements Parcelable {
@Override @Override
public void writeToParcel(Parcel dest, int flags) { public void writeToParcel(Parcel dest, int flags) {
dest.writeSerializable(orientation); dest.writeSerializable(orientation);
dest.writeParcelable(photo, flags);
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment