diff --git a/.idea/misc.xml b/.idea/misc.xml index 27ac2e83b8cd1111eb41e4a6ba539a69bdc954fd..24dd4c6f7d1926f115a8a770e13defd6cbc796cd 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -4,6 +4,7 @@ <option name="filePathToZoomLevelMap"> <map> <entry key="app/src/main/res/layout/activity_boussole.xml" value="0.3098958333333333" /> + <entry key="app/src/main/res/layout/activity_creation_ouverture.xml" value="0.35625" /> <entry key="app/src/main/res/layout/activity_main.xml" value="0.15104166666666666" /> <entry key="app/src/main/res/layout/activity_mode_conception.xml" value="0.32864583333333336" /> <entry key="app/src/main/res/layout/activity_mode_immersion.xml" value="0.3333333333333333" /> diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 8ca2d9d8c2d78a1a30df60a252406f576d614936..c38dabea22a4f0638c6f69e1bc0bddf8c252235d 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,35 +1,38 @@ <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" - xmlns:tools="http://schemas.android.com/tools" - package="com.example.myhabitat"> + xmlns:tools="http://schemas.android.com/tools" + package="com.example.myhabitat" > <uses-feature - android:name="android.hardware.camera" - android:required="true"/> + android:name="android.hardware.camera" + android:required="true" /> <application - android:allowBackup="true" - android:dataExtractionRules="@xml/data_extraction_rules" - android:fullBackupContent="@xml/backup_rules" - android:icon="@mipmap/ic_launcher" - android:label="@string/app_name" - android:roundIcon="@mipmap/ic_launcher_round" - android:supportsRtl="true" - android:theme="@style/Theme.MyHabitat" - tools:targetApi="31"> + android:allowBackup="true" + android:dataExtractionRules="@xml/data_extraction_rules" + android:fullBackupContent="@xml/backup_rules" + android:icon="@mipmap/ic_launcher" + android:label="@string/app_name" + android:roundIcon="@mipmap/ic_launcher_round" + android:supportsRtl="true" + android:theme="@style/Theme.MyHabitat" + tools:targetApi="31" > <activity - android:name=".ModeConceptionActivity" - android:exported="false"/> + android:name=".CreationOuvertureActivity" + android:exported="false" /> <activity - android:name=".ModeImmersionActivity" - android:exported="false"/> + android:name=".ModeConceptionActivity" + android:exported="false" /> <activity - android:name=".MainActivity" - android:exported="true"> + android:name=".ModeImmersionActivity" + android:exported="false" /> + <activity + android:name=".MainActivity" + android:exported="true" > <intent-filter> - <action android:name="android.intent.action.MAIN"/> + <action android:name="android.intent.action.MAIN" /> - <category android:name="android.intent.category.LAUNCHER"/> + <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> diff --git a/app/src/main/java/com/example/myhabitat/CreationOuvertureActivity.java b/app/src/main/java/com/example/myhabitat/CreationOuvertureActivity.java new file mode 100644 index 0000000000000000000000000000000000000000..b83dbe86551ee5a1382e267c32b972b224046e82 --- /dev/null +++ b/app/src/main/java/com/example/myhabitat/CreationOuvertureActivity.java @@ -0,0 +1,200 @@ +package com.example.myhabitat; + +import android.content.Intent; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.graphics.drawable.Drawable; +import android.util.Log; +import android.view.View; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; +import android.widget.ImageView; +import android.widget.Spinner; +import androidx.appcompat.app.AppCompatActivity; +import android.os.Bundle; +import habitat.Habitat; +import habitat.Mur; +import habitat.Orientation; +import habitat.Piece; + +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.lang.reflect.Array; + +public class CreationOuvertureActivity extends AppCompatActivity{ + + private Habitat habitat; + private ImageView imageViewDepart; + private ImageView imageViewArrivee; + private Piece pieceDepart; + private Piece pieceArrivee; + private Orientation orientationPieceDepart; + private Orientation orientationPieceArrivee; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_creation_ouverture); + + //On récupère Habitat + Intent intent = getIntent(); + if (intent != null){ + Habitat habitat = intent.getParcelableExtra("Habitat"); + if (habitat != null){ + this.habitat = habitat; + this.habitat.setCorrectly(); + } + } + + imageViewDepart = findViewById(R.id.imageViewDepart); + imageViewArrivee = findViewById(R.id.imageViewArrivee); + + Spinner spinnerD = findViewById(R.id.spinnerDepart); + Spinner spinnerDOrientation = findViewById(R.id.spinnerDOrientation); + Spinner spinnerA = findViewById(R.id.spinnerArrivee); + Spinner spinnerAOrientation = findViewById(R.id.spinnerAOrientation); + + String[] arrayPieces = new String[habitat.getPieces().size()]; + for(int i=0; i<habitat.getPieces().size(); i++){ + arrayPieces[i] = habitat.getPieces().get(i).getNom(); + } + + String[] arrayOrientation = new String[]{"NORD", "SUD", "EST", "OUEST"}; + + ArrayAdapter arrayAdapterD = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, arrayPieces); + spinnerD.setAdapter(arrayAdapterD); + ArrayAdapter arrayAdapterDOrientation = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, arrayOrientation); + spinnerDOrientation.setAdapter(arrayAdapterDOrientation); + ArrayAdapter arrayAdapterA = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, arrayPieces); + spinnerA.setAdapter(arrayAdapterA); + ArrayAdapter arrayAdapterAOrientation = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, arrayOrientation); + spinnerAOrientation.setAdapter(arrayAdapterAOrientation); + + + spinnerD.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + @Override + public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { + pieceDepart = habitat.getPieces().get(position); + affichePieceDepart(); + } + + @Override + public void onNothingSelected(AdapterView<?> parent) { + + } + }); + + spinnerDOrientation.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + @Override + public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { + switch (position){ + case 0: + orientationPieceDepart = Orientation.NORD; + break; + case 1: + orientationPieceDepart = Orientation.SUD; + break; + case 2: + orientationPieceDepart = Orientation.EST; + break; + case 3: + orientationPieceDepart = Orientation.OUEST; + break; + default: + orientationPieceDepart = Orientation.SUD; + break; + } + affichePieceDepart(); + } + + @Override + public void onNothingSelected(AdapterView<?> parent) { + + } + + }); + + spinnerA.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + @Override + public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { + pieceArrivee = habitat.getPieces().get(position); + affichePieceArrivee(); + } + + @Override + public void onNothingSelected(AdapterView<?> parent) { + + } + }); + + spinnerAOrientation.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { + @Override + public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { + switch (position){ + case 0: + orientationPieceArrivee = Orientation.NORD; + break; + case 1: + orientationPieceArrivee = Orientation.SUD; + break; + case 2: + orientationPieceArrivee = Orientation.EST; + break; + case 3: + orientationPieceArrivee = Orientation.OUEST; + break; + default: + orientationPieceArrivee = Orientation.SUD; + break; + } + affichePieceArrivee(); + } + + @Override + public void onNothingSelected(AdapterView<?> parent) { + + } + }); + } + + + public void affichePieceDepart(){ + if(pieceDepart != null && orientationPieceDepart != null){ + Mur mur = pieceDepart.getMurOrientation(orientationPieceDepart); + FileInputStream fis = null; + try { + fis = openFileInput(mur.getId()+".data"); + } catch (FileNotFoundException e) { + //throw new RuntimeException(e); + } + if (fis != null) { + Bitmap bm = BitmapFactory.decodeStream(fis); + + imageViewDepart.setImageBitmap(bm); + }else{ + imageViewDepart.setImageDrawable(getDrawable(R.drawable.imagemur)); + } + } + } + + + public void affichePieceArrivee(){ + if(pieceArrivee != null && orientationPieceArrivee != null){ + Mur mur = pieceArrivee.getMurOrientation(orientationPieceArrivee); + FileInputStream fis = null; + try { + fis = openFileInput(mur.getId()+".data"); + } catch (FileNotFoundException e) { + //throw new RuntimeException(e); + } + if (fis != null) { + Bitmap bm = BitmapFactory.decodeStream(fis); + + imageViewArrivee.setImageBitmap(bm); + }else{ + imageViewArrivee.setImageDrawable(getDrawable(R.drawable.imagemur)); + } + } + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/example/myhabitat/ModeConceptionActivity.java b/app/src/main/java/com/example/myhabitat/ModeConceptionActivity.java index 1f0711419950f9290e5b0cb0162b0c13b16cba07..2f78f4927d05f64e2a3308c8397c301e9b6ce6a8 100644 --- a/app/src/main/java/com/example/myhabitat/ModeConceptionActivity.java +++ b/app/src/main/java/com/example/myhabitat/ModeConceptionActivity.java @@ -218,4 +218,10 @@ public class ModeConceptionActivity extends AppCompatActivity { public void confirmer(View view) { finish(); } + + public void addOuverture(View view) { + Intent intent = new Intent(this, CreationOuvertureActivity.class); + intent.putExtra("Habitat", habitat); + startActivity(intent); + } } \ No newline at end of file diff --git a/app/src/main/java/com/example/myhabitat/ModeImmersionActivity.java b/app/src/main/java/com/example/myhabitat/ModeImmersionActivity.java index e0db0ed28ec461fad34bfa7625f9c2d24bb6e16e..6c696efbd132bed2115337dc8d6fef44d0d6b0ea 100644 --- a/app/src/main/java/com/example/myhabitat/ModeImmersionActivity.java +++ b/app/src/main/java/com/example/myhabitat/ModeImmersionActivity.java @@ -121,28 +121,9 @@ public class ModeImmersionActivity extends AppCompatActivity implements SensorEv } } - public void afficheSud(View view){ - murEnCours = pieceEnCours.getMurOrientation(Orientation.SUD); - afficheMur(); - } - - public void afficheNord(View view){ - murEnCours = pieceEnCours.getMurOrientation(Orientation.NORD); - afficheMur(); - } - - public void afficheEst(View view){ - murEnCours = pieceEnCours.getMurOrientation(Orientation.EST); - afficheMur(); - } - - public void afficheOuest(View view){ - murEnCours = pieceEnCours.getMurOrientation(Orientation.OUEST); - afficheMur(); - } - @Override public void onSensorChanged(SensorEvent event) { + // On récupère l'angle float angle = -(Math.round(event.values[0])); @@ -155,30 +136,27 @@ public class ModeImmersionActivity extends AppCompatActivity implements SensorEv if(imageViewBoussole == null) { imageViewBoussole = findViewById(R.id.imageViewBoussole); } - runOnUiThread(new Runnable() { - @Override - public void run() { - imageViewBoussole.startAnimation(rotateAnimation); - - - if(angle<(-45) && angle>=(-135)){ - murEnCours = pieceEnCours.getMurOrientation(Orientation.EST); - } else if (angle<(-135) && angle>=(-225)) { - murEnCours = pieceEnCours.getMurOrientation(Orientation.SUD); - } else if (angle<(-225) && angle>=(-315)) { - murEnCours = pieceEnCours.getMurOrientation(Orientation.OUEST); - }else{ - murEnCours = pieceEnCours.getMurOrientation(Orientation.NORD); - } - afficheMur(); - } - }); + + imageViewBoussole.startAnimation(rotateAnimation); + + + if(angle<(-45) && angle>=(-135)){ + murEnCours = pieceEnCours.getMurOrientation(Orientation.EST); + } else if (angle<(-135) && angle>=(-225)) { + murEnCours = pieceEnCours.getMurOrientation(Orientation.SUD); + } else if (angle<(-225) && angle>=(-315)) { + murEnCours = pieceEnCours.getMurOrientation(Orientation.OUEST); + }else{ + murEnCours = pieceEnCours.getMurOrientation(Orientation.NORD); + } + afficheMur(); + //Maj de l'angle de depart debut = angle; try { - Thread.sleep(10); + Thread.sleep(5); } catch (InterruptedException e) { throw new RuntimeException(e); } diff --git a/app/src/main/java/habitat/Ouverture.java b/app/src/main/java/habitat/Ouverture.java new file mode 100644 index 0000000000000000000000000000000000000000..2b4736289729eb1e59aec50aa01b301cbe9cbe88 --- /dev/null +++ b/app/src/main/java/habitat/Ouverture.java @@ -0,0 +1,13 @@ +package habitat; + +import android.graphics.Rect; + +public class Ouverture { + + private Mur depart; + private Mur arrivee; + private Rect rect; + + public Ouverture() { + } +} diff --git a/app/src/main/res/layout/activity_creation_ouverture.xml b/app/src/main/res/layout/activity_creation_ouverture.xml new file mode 100644 index 0000000000000000000000000000000000000000..85397c2d040bb0b8cabe9d840cf6489215406ce3 --- /dev/null +++ b/app/src/main/res/layout/activity_creation_ouverture.xml @@ -0,0 +1,120 @@ +<?xml version="1.0" encoding="utf-8"?> +<androidx.constraintlayout.widget.ConstraintLayout + xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:tools="http://schemas.android.com/tools" + xmlns:app="http://schemas.android.com/apk/res-auto" + android:layout_width="match_parent" + android:layout_height="match_parent" + tools:context=".CreationOuvertureActivity"> + + <ImageView + android:layout_width="186dp" + android:layout_height="187dp" + app:srcCompat="@drawable/imagemur" + android:id="@+id/imageViewArrivee" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintHorizontal_bias="0.502" + android:layout_marginBottom="32dp"/> + + <ImageView + android:layout_width="186dp" + android:layout_height="187dp" + app:srcCompat="@drawable/imagemur" + android:id="@+id/imageViewDepart" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toBottomOf="@+id/spinnerAOrientation" + android:layout_marginTop="60dp" + app:layout_constraintHorizontal_bias="0.502" + app:layout_constraintBottom_toTopOf="@+id/imageViewArrivee" + app:layout_constraintVertical_bias="0.0"/> + + <Spinner + android:layout_width="130dp" + android:layout_height="33dp" + android:id="@+id/spinnerAOrientation" + app:layout_constraintTop_toBottomOf="@+id/textView4" + android:layout_marginTop="16dp" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintHorizontal_bias="0.892"/> + + <TextView + android:text="Direction" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:id="@+id/textView4" + app:layout_constraintTop_toBottomOf="@+id/spinnerArrivee" + android:layout_marginTop="12dp" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintHorizontal_bias="0.83"/> + + <TextView + android:text="Piece de Depart" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:id="@+id/textViewDepart" + app:layout_constraintTop_toTopOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintBottom_toTopOf="@+id/spinnerDepart" + app:layout_constraintHorizontal_bias="0.137" + app:layout_constraintVertical_bias="0.484"/> + + <TextView + android:text="Piece d'Arrivee" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:id="@+id/textViewArrivee" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintHorizontal_bias="0.871" + app:layout_constraintTop_toTopOf="parent" + android:layout_marginTop="16dp"/> + + <Spinner + android:layout_width="181dp" + android:layout_height="32dp" + android:id="@+id/spinnerDepart" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintTop_toTopOf="parent" + android:layout_marginTop="52dp" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintHorizontal_bias="0.0"/> + + <Spinner + android:layout_width="181dp" + android:layout_height="32dp" + android:id="@+id/spinnerArrivee" + app:layout_constraintTop_toBottomOf="@+id/textViewArrivee" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintVertical_bias="0.025" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintHorizontal_bias="1.0"/> + + <TextView + android:text="Direction" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:id="@+id/textView3" + app:layout_constraintTop_toBottomOf="@+id/spinnerDepart" + android:layout_marginTop="12dp" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintHorizontal_bias="0.16"/> + + <Spinner + android:layout_width="130dp" + android:layout_height="33dp" + android:id="@+id/spinnerDOrientation" + app:layout_constraintTop_toBottomOf="@+id/textView3" + android:layout_marginTop="16dp" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintHorizontal_bias="0.097"/> + +</androidx.constraintlayout.widget.ConstraintLayout> \ No newline at end of file diff --git a/app/src/main/res/layout/activity_mode_conception.xml b/app/src/main/res/layout/activity_mode_conception.xml index af2836c072e8daeb2a10de93c66b9460cd1f80b7..e108fdb38e6f18031dcaff7d7c7d77e7fe7e9204 100644 --- a/app/src/main/res/layout/activity_mode_conception.xml +++ b/app/src/main/res/layout/activity_mode_conception.xml @@ -7,24 +7,13 @@ android:layout_height="match_parent" tools:context=".ModeConceptionActivity"> - <Button - android:text="Ajouter une piece" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:id="@+id/addPiece" - android:onClick="addPiece" - app:layout_constraintStart_toStartOf="parent" - app:layout_constraintEnd_toEndOf="parent" - app:layout_constraintBottom_toBottomOf="parent" - android:layout_marginBottom="72dp"/> - <ScrollView android:id="@+id/scroll" - android:layout_width="358dp" - android:layout_height="581dp" + android:layout_width="0dp" + android:layout_height="0dp" app:layout_constraintTop_toTopOf="parent" app:layout_constraintEnd_toEndOf="parent" - app:layout_constraintBottom_toTopOf="@+id/addPiece" + app:layout_constraintBottom_toTopOf="@id/button2" app:layout_constraintStart_toStartOf="parent"> <LinearLayout @@ -42,8 +31,31 @@ android:layout_height="wrap_content" android:id="@+id/button" android:onClick="confirmer" - app:layout_constraintTop_toBottomOf="@+id/addPiece" app:layout_constraintStart_toStartOf="parent" app:layout_constraintEnd_toEndOf="parent" - app:layout_constraintBottom_toBottomOf="parent"/> + app:layout_constraintBottom_toBottomOf="parent" + /> + + <Button + android:text="Ajouter une ouverture" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:id="@+id/button2" + android:onClick="addOuverture" + app:layout_constraintTop_toBottomOf="@+id/scroll" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintEnd_toEndOf="parent" + android:layout_marginTop="24dp"/> + + <Button + android:text="Ajouter une piece" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:id="@+id/addPiece" + android:onClick="addPiece" + app:layout_constraintTop_toBottomOf="@+id/button2" + app:layout_constraintBottom_toTopOf="@+id/button" + app:layout_constraintVertical_bias="0.555" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintEnd_toEndOf="parent"/> </androidx.constraintlayout.widget.ConstraintLayout> \ No newline at end of file