diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 9f95c9a490fe3c2879374579718e7084ed22c68e..dc8cfa34408dcff46292ff147a208ac82382aa75 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,6 +1,10 @@ <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"> + <uses-feature + android:name="android.hardware.camera" + android:required="true" /> + <application android:allowBackup="true" @@ -12,6 +16,16 @@ android:supportsRtl="true" android:theme="@style/Theme.PROJET" tools:targetApi="31"> + <provider + android:name="androidx.core.content.FileProvider" + android:authorities="fr.ul.projet.fileprovider" + android:exported="false" + android:grantUriPermissions="true"> + <meta-data + android:name="android.support.FILE_PROVIDER_PATHS" + android:resource="@xml/file_paths" /> + </provider> + <activity android:name=".MainActivity" android:exported="true"> @@ -24,12 +38,14 @@ <activity android:name=".ModeleActivity" android:exported="false"/> - <activity - android:name=".OpenActivity" - android:exported="false"/> <activity android:name=".PieceActivity" android:exported="false"/> </application> + <uses-permission android:name="android.permission.CAMERA" android:required="true"/> + <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> + <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> + + </manifest> \ No newline at end of file diff --git a/app/src/main/java/fr/ul/projet/MainActivity.java b/app/src/main/java/fr/ul/projet/MainActivity.java index 1f09ad5fc0cb36017f8631e881f0c53d69034f78..2adca7a41c99f6599fe41dcef3af635685949a84 100644 --- a/app/src/main/java/fr/ul/projet/MainActivity.java +++ b/app/src/main/java/fr/ul/projet/MainActivity.java @@ -51,7 +51,8 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe if (result.getResultCode() == MainActivity.RESULT_OK && result.getData() != null){ Uri fileUri = result.getData().getData(); if (fileUri != null){ - Modele modele = new Modele().chargerModele(MainActivity.this, fileUri); + Modele modele = new Modele(); + modele.chargerModele(MainActivity.this, fileUri); if (modele != null){ Intent intent = new Intent(MainActivity.this, ModeleActivity.class); diff --git a/app/src/main/java/fr/ul/projet/ModeleActivity.java b/app/src/main/java/fr/ul/projet/ModeleActivity.java index b52c0eae17c4e2eb9e6671b7b90574adc406ce6e..6e3783ec60bf4a439ab124e30d46697215c0c41e 100644 --- a/app/src/main/java/fr/ul/projet/ModeleActivity.java +++ b/app/src/main/java/fr/ul/projet/ModeleActivity.java @@ -9,7 +9,9 @@ import android.os.Bundle; import android.os.Environment; import android.provider.MediaStore; import android.view.View; +import android.widget.Button; import android.widget.EditText; +import android.widget.LinearLayout; import android.widget.TextView; import android.widget.Toast; @@ -24,12 +26,11 @@ import androidx.core.graphics.Insets; import androidx.core.view.ViewCompat; import androidx.core.view.WindowInsetsCompat; -import java.io.File; -import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; import fr.ul.projet.modele.Modele; +import fr.ul.projet.modele.Piece; public class ModeleActivity extends AppCompatActivity { @@ -40,7 +41,7 @@ public class ModeleActivity extends AppCompatActivity { protected void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); EdgeToEdge.enable(this); - setContentView(R.layout.activity_create); + setContentView(R.layout.activity_modele); this.modele = this.getIntent().getParcelableExtra("modele"); @@ -52,6 +53,7 @@ public class ModeleActivity extends AppCompatActivity { v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom); return insets; }); + afficherPieces(); this.launcher = registerForActivityResult( new ActivityResultContracts.StartActivityForResult(), @@ -66,6 +68,24 @@ public class ModeleActivity extends AppCompatActivity { } + public void afficherPieces(){ + LinearLayout piecesContainer = findViewById(R.id.pieces); + piecesContainer.removeAllViews(); + + for (Piece piece : this.modele.getPieces().values()){ + Button bouton = new Button(this); + bouton.setText(piece.getNom()); + bouton.setOnClickListener(v -> { + modele.setPieceCourante(piece); + Intent intent = new Intent(ModeleActivity.this, PieceActivity.class); + intent.putExtra("modele", modele); + launcher.launch(intent); + }); + + piecesContainer.addView(bouton); + } + } + public void nouvellePiece(View v){ AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("Entrez un nom pour votre pièce"); diff --git a/app/src/main/java/fr/ul/projet/OpenActivity.java b/app/src/main/java/fr/ul/projet/OpenActivity.java deleted file mode 100644 index 5fd7a4258d927efb214477d207fbcb1d88954a19..0000000000000000000000000000000000000000 --- a/app/src/main/java/fr/ul/projet/OpenActivity.java +++ /dev/null @@ -1,37 +0,0 @@ -package fr.ul.projet; - -import android.content.Intent; -import android.os.Bundle; -import android.view.View; -import android.widget.TextView; - -import androidx.activity.EdgeToEdge; -import androidx.appcompat.app.AppCompatActivity; -import androidx.core.graphics.Insets; -import androidx.core.view.ViewCompat; -import androidx.core.view.WindowInsetsCompat; - -public class OpenActivity extends AppCompatActivity { - @Override - protected void onCreate(Bundle savedInstanceState){ - super.onCreate(savedInstanceState); - EdgeToEdge.enable(this); - setContentView(R.layout.activity_open); - - String nomFichier = getIntent().getStringExtra("fichier"); - TextView textView = findViewById(R.id.textView); - textView.setText(nomFichier); - - ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.open), (v, insets) -> { - Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars()); - v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom); - return insets; - }); - - } - - public void home(View v){ - Intent res = new Intent(); - finish(); - } -} diff --git a/app/src/main/java/fr/ul/projet/PieceActivity.java b/app/src/main/java/fr/ul/projet/PieceActivity.java index 9aee0755a13ecc1ffedfe24275381c836c49168a..f4eb1b7dae6dd34d3878c1069d5751101852d5d6 100644 --- a/app/src/main/java/fr/ul/projet/PieceActivity.java +++ b/app/src/main/java/fr/ul/projet/PieceActivity.java @@ -2,10 +2,16 @@ package fr.ul.projet; import android.content.DialogInterface; import android.content.Intent; +import android.net.Uri; import android.os.Bundle; +import android.os.Environment; +import android.provider.MediaStore; +import android.util.Log; import android.view.View; import android.widget.EditText; +import android.widget.ImageView; import android.widget.TextView; +import android.widget.Toast; import androidx.activity.EdgeToEdge; import androidx.activity.result.ActivityResult; @@ -14,19 +20,74 @@ import androidx.activity.result.ActivityResultLauncher; import androidx.activity.result.contract.ActivityResultContracts; import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AppCompatActivity; +import androidx.core.content.FileProvider; import androidx.core.graphics.Insets; import androidx.core.view.ViewCompat; import androidx.core.view.WindowInsetsCompat; +import java.io.File; + import fr.ul.projet.modele.Modele; import fr.ul.projet.modele.Piece; public class PieceActivity extends AppCompatActivity { private Modele modele; + private static final int NB_IMAGES = 4; + private int imageIndex = 0; private Piece piece; + private Uri photoUri; private ActivityResultLauncher<Intent> launcher; + private final ActivityResultLauncher<Intent> pickImageLauncher = registerForActivityResult( + new ActivityResultContracts.StartActivityForResult(), + result -> { + if (result.getResultCode() == RESULT_OK && result.getData() != null && imageIndex < NB_IMAGES) { + Uri imageUri = result.getData().getData(); + if (imageUri != null) { + switch (imageIndex){ + case 0: + PieceActivity.this.piece.setPhotoNord(imageUri.getPath()); + break; + case 1: + PieceActivity.this.piece.setPhotoSud(imageUri.getPath()); + break; + case 2: + PieceActivity.this.piece.setPhotoEst(imageUri.getPath()); + break; + case 3: + PieceActivity.this.piece.setPhotoOuest(imageUri.getPath()); + break; + } + } + imageIndex++; + } + }); + + private final ActivityResultLauncher<Intent> cameraLauncher = registerForActivityResult( + new ActivityResultContracts.StartActivityForResult(), + result -> { + if (result.getResultCode() == RESULT_OK && imageIndex < NB_IMAGES) { + ImageView imageView = findViewById(R.id.imageView); + imageView.setImageURI(this.photoUri); + /*switch (imageIndex){ + case 0: + PieceActivity.this.piece.setPhotoNord(photoUri.getPath()); + break; + case 1: + PieceActivity.this.piece.setPhotoSud(photoUri.getPath()); + break; + case 2: + PieceActivity.this.piece.setPhotoEst(photoUri.getPath()); + break; + case 3: + PieceActivity.this.piece.setPhotoOuest(photoUri.getPath()); + break; + }*/ + imageIndex++; + } + }); + @Override protected void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); @@ -38,6 +99,30 @@ public class PieceActivity extends AppCompatActivity { this.piece = this.modele.getPieceCourante(); TextView textView = findViewById(R.id.nomPiece); textView.setText(this.modele.getNom()+ " : " + this.piece.getNom()); + ImageView imageView = findViewById(R.id.imageView); + switch (this.modele.getOrientationCourante()){ + + case "Nord": + if (!this.piece.getPhotoNord().equals("")){ + imageView.setImageURI(Uri.fromFile(new File(this.piece.getPhotoNord()))); + } + break; + case "Sud": + if (!this.piece.getPhotoNord().equals("")){ + imageView.setImageURI(Uri.fromFile(new File(this.piece.getPhotoSud()))); + } + break; + case "Est": + if (!this.piece.getPhotoNord().equals("")){ + imageView.setImageURI(Uri.fromFile(new File(this.piece.getPhotoEst()))); + } + break; + case "Ouest": + if (!this.piece.getPhotoNord().equals("")){ + imageView.setImageURI(Uri.fromFile(new File(this.piece.getPhotoOuest()))); + } + break; + } ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.piece), (v, insets) -> { Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars()); @@ -51,13 +136,62 @@ public class PieceActivity extends AppCompatActivity { @Override public void onActivityResult(ActivityResult result){ int resCode = result.getResultCode(); // Code retourné par l'activité - + if (result.getResultCode() == RESULT_OK && result.getData() != null && imageIndex < NB_IMAGES){ + Uri imageUri = result.getData().getData(); + if (imageUri != null) { + switch (imageIndex){ + case 0: + PieceActivity.this.piece.setPhotoNord(imageUri.getPath()); + break; + case 1: + PieceActivity.this.piece.setPhotoSud(imageUri.getPath()); + break; + case 2: + PieceActivity.this.piece.setPhotoEst(imageUri.getPath()); + break; + case 3: + PieceActivity.this.piece.setPhotoOuest(imageUri.getPath()); + break; + } + } + } } } ); } + public void selectionImageDialog(View v){ + if (imageIndex >= NB_IMAGES){ + Toast.makeText(this, "Vous avez déjà sélectionné 4 images", Toast.LENGTH_LONG).show(); + return; + } + AlertDialog.Builder builder = new AlertDialog.Builder(this); + builder.setTitle("Choisir une option") + .setItems(new String[]{"Prendre une photo, Séléctionner une photo"}, (dialog, which) -> { + if (which == 0){ + this.prendrePhoto(); + } else{ + this.selectionnerPhoto(); + } + }) + .show(); + } + + private void prendrePhoto(){ + File photo = new File(getExternalFilesDir(Environment.DIRECTORY_PICTURES), "photo_" + System.currentTimeMillis() + ".jpg"); + this.photoUri = FileProvider.getUriForFile(this, getApplicationContext().getPackageName() + ".fileprovider", photo); + Intent camera = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); + camera.putExtra(MediaStore.EXTRA_OUTPUT, this.photoUri); + cameraLauncher.launch(camera); + } + + private void selectionnerPhoto(){ + Intent intent = new Intent(Intent.ACTION_GET_CONTENT); + intent.setType("image/*"); + pickImageLauncher.launch(intent); + } + public void nouvellePiece(View v){ AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("Entrez un nom pour votre pièce"); diff --git a/app/src/main/java/fr/ul/projet/modele/Modele.java b/app/src/main/java/fr/ul/projet/modele/Modele.java index 7442bb08186b627e2f86f921d9040437790228ef..6b9de199d08871ef01c32d33f36a8e73f98ad8c0 100644 --- a/app/src/main/java/fr/ul/projet/modele/Modele.java +++ b/app/src/main/java/fr/ul/projet/modele/Modele.java @@ -4,55 +4,70 @@ import android.content.Context; import android.net.Uri; import android.os.Parcel; import android.os.Parcelable; - -import com.google.gson.Gson; - +import android.util.Log; +import org.json.JSONArray; import org.json.JSONObject; - import java.io.BufferedReader; -import java.io.BufferedWriter; import java.io.File; -import java.io.FileWriter; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; -import java.io.PrintWriter; import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; import java.util.Map; import fr.ul.projet.outils.FabriqueIdentifiant; + +/** + * Classe du Modèle représentant un bâtiment + * @author Guillaume Potel + * @version 1.0 + * @see Parcelable + */ public class Modele implements Parcelable{ + // Indique si une pièce est à afficher par les vues private boolean pieceAffichee; + // Nom du fichier dans lequel enregistrer les données private String fichierJson; + // Nom du bâtiment private String nom; + // Orientation séléctionnée pour l'affichage d'une des photos de la pièce courante private String orientationCourante; - HashMap<Integer, Piece> pieces; - Piece pieceCourante; + // Collection de toutes les pièces du bâtiment + private HashMap<Integer, Piece> pieces; + // Pièce courante + private Piece pieceCourante; /** - * Constructeur d'un Modèle + * Constructeur de la classe en précisant le nom du bâtiment * */ public Modele(String nom){ this.pieceAffichee = false; this.pieceCourante = null; this.nom = nom; + this.orientationCourante = "Nord"; this.pieces = new HashMap<Integer, Piece>(); this.fichierJson = new File("").getAbsolutePath() + "/" + this.getNom() + FabriqueIdentifiant.getInstance().getCptJson() + ".json"; } + /** + * Constructeur de la classe par défaut + */ public Modele(){ this.pieceAffichee = false; this.pieceCourante = null; this.nom = ""; + this.orientationCourante = "Nord"; this.pieces = new HashMap<Integer, Piece>(); this.fichierJson = new File("").getAbsolutePath() + "/" + this.getNom() + FabriqueIdentifiant.getInstance().getCptJson() + ".json"; } + /** + * Constructeur à partir d'un élément passé dans un Intent + * @param in Element passé dans l'Intent + */ protected Modele(Parcel in){ this.pieceAffichee = in.readByte() != 0; this.fichierJson = in.readString(); @@ -68,6 +83,9 @@ public class Modele implements Parcelable{ this.pieceCourante = in.readParcelable(Piece.class.getClassLoader()); } + /** + * @see Parcelable + */ public static final Creator<Modele> CREATOR = new Creator<Modele>() { @Override public Modele createFromParcel(Parcel parcel) { @@ -80,6 +98,9 @@ public class Modele implements Parcelable{ } }; + /** + * @see Parcelable + */ @Override public void writeToParcel(Parcel dest, int flags){ dest.writeByte((byte) (this.pieceAffichee ? 1 : 0)); @@ -94,65 +115,103 @@ public class Modele implements Parcelable{ dest.writeParcelable(this.pieceCourante, flags); } + /** + * @see Parcelable + */ @Override public int describeContents(){ return 0; } - public void nouveau(){ - this.pieceAffichee = false; - this.pieceCourante = null; - this.fichierJson = new File("").getAbsolutePath() + "/modele" + FabriqueIdentifiant.getInstance().getCptJson() + ".json"; - this.pieces.clear(); - FabriqueIdentifiant.reset(); - } - - /** * Getters et Setters ------------------------------------------------------------------------------------------------------------------------ */ + /** + * Getter du nom du bâtiment + * @return Nom du bâtiment + */ public String getNom() { return this.nom; } + /** + * Setter du nom du bâtiment + * @param nom Nom souhaité pour le bâtiment + */ public void setNom(String nom) { this.nom = nom; } + /** + * Getter de la pièce courante + * @return Pièce courante + */ public Piece getPieceCourante() { return this.pieceCourante; } + /** + * Getter du nom du fichier Json + * @return Nom du fichier Json + */ public String getFichierJson() { return this.fichierJson; } + /** + * Getter de l'orientation courante + * @return Orientation courante de l'application + */ public String getOrientationCourante() { return this.orientationCourante; } + /** + * Getter de la collection des pièces du bâtiment + * @return Collection de pièce + */ public HashMap<Integer, Piece> getPieces() { return this.pieces; } + /** + * Getter du booléen d'affichage ou non d'une pièce + * @return Booléen d'affichage d'une pièce + */ public boolean isPieceAffichee() { return this.pieceAffichee; } + /** + * Setter du nom de fichier Json + * @param fichierJson Nom souhaité pour le fichier Json + */ public void setFichierJson(String fichierJson) { this.fichierJson = fichierJson; } + /** + * Setter de l'orientation courante + * @param orientationCourante L'orientation souhaité + */ public void setOrientationCourante(String orientationCourante) { this.orientationCourante = orientationCourante; } + /** + * Setter du booléen d'affichage d'une pièce + * @param pieceAffichee Affichage ou non d'une pièce + */ public void setPieceAffichee(boolean pieceAffichee) { this.pieceAffichee = pieceAffichee; } + /** + * Setter de la pièce courante + * @param pieceCourante Pièce courante + */ public void setPieceCourante(Piece pieceCourante) { this.pieceCourante = pieceCourante; this.pieceAffichee = true; @@ -162,12 +221,29 @@ public class Modele implements Parcelable{ * Méthodes d'ajout et suppression ------------------------------------------------------------------------------------------------------------------------ */ + /** + * Méthode qui crée et ajouter un pièce au bâtiment. + * Celle-ci deviant automatiquement la pièce à afficher (pièce courante) + * @param nom Nom de la pièce + * @param photoNord Chemin vers la photo représentant l'orientation Nord de la pièce + * @param photoSud Chemin vers la photo représentant l'orientation Sud de la pièce + * @param photoEst Chemin vers la photo représentant l'orientation Est de la pièce + * @param photoOuest Chemin vers la photo représentant l'orientation Ouest de la pièce + */ public void ajouterPiece(String nom, String photoNord, String photoSud, String photoEst, String photoOuest){ Piece piece = new Piece(nom, photoNord, photoSud, photoEst, photoOuest); this.pieces.put(piece.getId(), piece); this.setPieceCourante(piece); } + /** + * Méthode qui modifie les attributs de la pièce courante + * @param nom Nom de la pièce + * @param photoNord Chemin vers la photo représentant l'orientation Nord de la pièce + * @param photoSud Chemin vers la photo représentant l'orientation Sud de la pièce + * @param photoEst Chemin vers la photo représentant l'orientation Est de la pièce + * @param photoOuest Chemin vers la photo représentant l'orientation Ouest de la pièce + */ public void modifierPieceCourante(String nom, String photoNord, String photoSud, String photoEst, String photoOuest){ this.getPieceCourante().setNom(nom); this.getPieceCourante().setPhotoNord(photoNord); @@ -176,6 +252,10 @@ public class Modele implements Parcelable{ this.getPieceCourante().setPhotoOuest(photoOuest); } + /** + * Méthode qui supprime une pièce du bâtiment en fonction de son id + * @param idPiece Id de la pièce à supprimer + */ public void supprimerPiece(int idPiece){ Piece pieceSupp = this.getPieces().get(idPiece); pieceSupp.getAcces().clear(); @@ -191,10 +271,22 @@ public class Modele implements Parcelable{ this.getPieces().remove(idPiece); } + /** + * Méthode qui ajoute un accès de la pièce courante vers une pièce de destination + * @param destination Pièce de destination + * @param x1 Coordonnée x du coin haut gauche du rectangle représenant l'accès + * @param y1 Coordonnée y du coin haut gauche du rectangle représenant l'accès + * @param x2 Coordonnée x du coin bas droit du rectangle représenant l'accès + * @param y2 Coordonnée y du coin bas droit du rectangle représenant l'accès + */ public void ajouterAcces(Piece destination, int x1, int y1, int x2, int y2){ this.getPieceCourante().ajouterAcces(destination, x1, y1, x2, y2); } + /** + * Méthode qui supprime un accès en fonction de son id + * @param idAcces Id de l'accès à supprimer + */ public void supprimerAcces(String idAcces){ this.getPieceCourante().supprimerAcces(idAcces); } @@ -203,10 +295,17 @@ public class Modele implements Parcelable{ * Méthodes de déplacement ------------------------------------------------------------------------------------------------------------------------ */ + /** + * Méthode de déplacement d'une pièce vers une autre grâce à un accés + * @param idAcces Id de l'accés utilisé + */ public void utiliserAcces(String idAcces){ this.setPieceCourante(this.getPieceCourante().getAcces().get(idAcces).getDestination()); } + /** + * Méthode qui met à jour l'orientation courante en la tournant dans le sens horaire + */ public void tournerHoraire(){ switch (this.getOrientationCourante()){ case "NORD": @@ -226,6 +325,9 @@ public class Modele implements Parcelable{ } } + /** + * Méthode qui met à jour l'orientation courante en la tournant dans le sens anti-horaire + */ public void tournerAntiHoraire(){ switch (this.getOrientationCourante()){ case "NORD": @@ -251,11 +353,15 @@ public class Modele implements Parcelable{ * Méthodes de lecture ou écriture d'un modèle ------------------------------------------------------------------------------------------------------------------------ */ + /** + * Méthode qui traduit le bâtiment en structure de donnée Json + * @return Le texte formatté en Json traduisant le bâtiment + */ public String toJson(){ JSONObject modeleJson = new JSONObject(); - List pieces = new LinkedList(); + JSONArray pieces = new JSONArray(); for (Piece p : this.pieces.values()){ - pieces.add(p.toJson()); + pieces.put(p.toJson()); } try{ @@ -269,7 +375,15 @@ public class Modele implements Parcelable{ } - public Modele chargerModele(Context context, Uri fichier){ + /** + * Méthode qui charge le bâtiment via un bâtiment déjà existant en fichier Json + * @param context Context + * @param fichier Fichier du bâtiment à importer + */ + public void chargerModele(Context context, Uri fichier){ + this.pieces.clear(); + this.nom = ""; + this.pieceCourante = null; try (InputStream inputStream = context.getContentResolver().openInputStream(fichier); BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) { @@ -280,14 +394,29 @@ public class Modele implements Parcelable{ } String jsonString = jsonBuilder.toString(); - - // Désérialiser le JSON en un objet Modele avec Gson - Gson gson = new Gson(); - return gson.fromJson(jsonString, Modele.class); + try{ + JSONObject modeleJson = new JSONObject(jsonString); + this.setNom(modeleJson.getString("nom")); + String piecesJsonString = modeleJson.getString("pièces"); + JSONArray piecesJson = new JSONArray(piecesJsonString); + for (int i=0; i<piecesJson.length(); i++){ + JSONObject pieceJson = piecesJson.getJSONObject(i); + Piece piece = new Piece(); + piece.setId(pieceJson.getInt("id")); + piece.setNom(pieceJson.getString("nom")); + piece.setPhotoNord(pieceJson.getString("cheminPhotoNord")); + piece.setPhotoSud(pieceJson.getString("cheminPhotoSud")); + piece.setPhotoEst(pieceJson.getString("cheminPhotoEst")); + piece.setPhotoOuest(pieceJson.getString("cheminPhotoOuest")); + this.pieces.put(piece.getId(), piece); + Log.i("nom piece", piece.getNom()); + } + } catch (Exception e){ + e.printStackTrace(); + } } catch (IOException e) { e.printStackTrace(); - return null; } } diff --git a/app/src/main/java/fr/ul/projet/modele/Piece.java b/app/src/main/java/fr/ul/projet/modele/Piece.java index 9d11be0022ea618580045a080d46dba09bbf8dbc..0afa50612588fe9050a77a82eeb5120057c25375 100644 --- a/app/src/main/java/fr/ul/projet/modele/Piece.java +++ b/app/src/main/java/fr/ul/projet/modele/Piece.java @@ -3,6 +3,8 @@ package fr.ul.projet.modele; import android.os.Parcel; import android.os.Parcelable; +import org.json.JSONObject; + import java.util.HashMap; import java.util.LinkedHashMap; import java.util.Map; @@ -27,6 +29,16 @@ public class Piece implements Parcelable { this.acces = new HashMap<Integer, Acces>(); } + public Piece(){ + this.id = FabriqueIdentifiant.getInstance().getIdentifiantPiece(); + this.photoNord = ""; + this.photoSud = ""; + this.photoEst = ""; + this.photoOuest = ""; + this.nom = ""; + this.acces = new HashMap<Integer, Acces>(); + } + protected Piece(Parcel in){ this.id = in.readInt(); this.nom = in.readString(); @@ -79,6 +91,10 @@ public class Piece implements Parcelable { return this.id; } + public void setId(int i){ + this.id = i; + } + public String getNom() { return this.nom; } @@ -130,15 +146,20 @@ public class Piece implements Parcelable { this.getAcces().remove(idAcces); } - public Map toJson(){ - Map page = new LinkedHashMap(); - page.put("id", this.getId()); - page.put("nom", this.getNom()); - page.put("cheminPhotoNord", this.getPhotoNord()); - page.put("cheminPhotoSud", this.getPhotoSud()); - page.put("cheminPhotoEst", this.getPhotoEst()); - page.put("cheminPhotoOuest", this.getPhotoOuest()); - return page; + public JSONObject toJson(){ + JSONObject piece = new JSONObject(); + try{ + piece.put("id", this.getId()); + piece.put("nom", this.getNom()); + piece.put("cheminPhotoNord", this.getPhotoNord()); + piece.put("cheminPhotoSud", this.getPhotoSud()); + piece.put("cheminPhotoEst", this.getPhotoEst()); + piece.put("cheminPhotoOuest", this.getPhotoOuest()); + } catch (Exception e) { + e.printStackTrace(); + } + + return piece; } diff --git a/app/src/main/res/layout/activity_create.xml b/app/src/main/res/layout/activity_modele.xml similarity index 85% rename from app/src/main/res/layout/activity_create.xml rename to app/src/main/res/layout/activity_modele.xml index 0175487ce089bb9f14ba63d142bf2f325674466b..f6a2ce9c7a1a4d875dbe2897420281ca871c5bde 100644 --- a/app/src/main/res/layout/activity_create.xml +++ b/app/src/main/res/layout/activity_modele.xml @@ -19,6 +19,17 @@ app:layout_constraintTop_toTopOf="parent" app:layout_constraintVertical_bias="0.077" /> + <LinearLayout + android:id="@+id/pieces" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:orientation="vertical" + android:padding="16dp" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintTop_toTopOf="parent" + app:layout_constraintVertical_bias="0.243" /> + <Button android:id="@+id/home" android:layout_width="wrap_content" diff --git a/app/src/main/res/layout/activity_open.xml b/app/src/main/res/layout/activity_open.xml deleted file mode 100644 index c3d849a2443ef64f312eb0408e406485e65192f3..0000000000000000000000000000000000000000 --- a/app/src/main/res/layout/activity_open.xml +++ /dev/null @@ -1,30 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" - xmlns:app="http://schemas.android.com/apk/res-auto" - android:id="@+id/open" - android:layout_width="match_parent" - android:layout_height="match_parent"> - - <TextView - android:id="@+id/textView" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:text="@string/ouvrir_mess" - app:layout_constraintBottom_toBottomOf="parent" - app:layout_constraintEnd_toEndOf="parent" - app:layout_constraintStart_toStartOf="parent" - app:layout_constraintTop_toTopOf="parent" /> - - <Button - android:id="@+id/home" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:onClick="home" - android:text="@string/quitter" - app:layout_constraintBottom_toBottomOf="parent" - app:layout_constraintEnd_toEndOf="parent" - app:layout_constraintHorizontal_bias="0.498" - app:layout_constraintStart_toStartOf="parent" - app:layout_constraintTop_toTopOf="parent" - app:layout_constraintVertical_bias="0.929" /> -</androidx.constraintlayout.widget.ConstraintLayout> \ No newline at end of file diff --git a/app/src/main/res/layout/activity_piece.xml b/app/src/main/res/layout/activity_piece.xml index 02f35146c0478daec98553ce80768d281a215a5e..1c4ee93cb881a39a527be05b6d8963bca3e254d7 100644 --- a/app/src/main/res/layout/activity_piece.xml +++ b/app/src/main/res/layout/activity_piece.xml @@ -14,10 +14,10 @@ android:textSize="34sp" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" - app:layout_constraintHorizontal_bias="0.498" + app:layout_constraintHorizontal_bias="0.494" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" - app:layout_constraintVertical_bias="0.375" /> + app:layout_constraintVertical_bias="0.059" /> <Button android:id="@+id/boutonRetour" @@ -44,4 +44,27 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" app:layout_constraintVertical_bias="0.951" /> + + <ImageView + android:id="@+id/imageView" + android:layout_width="379dp" + android:layout_height="263dp" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent" + tools:srcCompat="@tools:sample/backgrounds/scenic" /> + + <Button + android:id="@+id/button" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:onClick="selectionImageDialog" + android:text="Button" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintHorizontal_bias="0.498" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent" + app:layout_constraintVertical_bias="0.25" /> </androidx.constraintlayout.widget.ConstraintLayout> \ No newline at end of file diff --git a/app/src/main/res/xml/file_paths.xml b/app/src/main/res/xml/file_paths.xml new file mode 100644 index 0000000000000000000000000000000000000000..8e9109d13fc2e4e3fc5ef499c08aa6ddbe0e20c2 --- /dev/null +++ b/app/src/main/res/xml/file_paths.xml @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="utf-8"?> +<paths xmlns:android="http://schemas.android.com/apk/res/android"> + <!-- Spécifie les chemins des fichiers partagés --> + <external-path + name="external_files" + path="." /> +</paths> \ No newline at end of file