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

début creation ouverture

parent a81eb0c6
Branches
No related tags found
No related merge requests found
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
<option name="filePathToZoomLevelMap"> <option name="filePathToZoomLevelMap">
<map> <map>
<entry key="app/src/main/res/layout/activity_boussole.xml" value="0.3098958333333333" /> <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_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_conception.xml" value="0.32864583333333336" />
<entry key="app/src/main/res/layout/activity_mode_immersion.xml" value="0.3333333333333333" /> <entry key="app/src/main/res/layout/activity_mode_immersion.xml" value="0.3333333333333333" />
......
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<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 <uses-feature
android:name="android.hardware.camera" android:name="android.hardware.camera"
android:required="true"/> android:required="true" />
<application <application
android:allowBackup="true" android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules" android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules" android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher" android:icon="@mipmap/ic_launcher"
android:label="@string/app_name" android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round" android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/Theme.MyHabitat" android:theme="@style/Theme.MyHabitat"
tools:targetApi="31"> tools:targetApi="31" >
<activity <activity
android:name=".ModeConceptionActivity" android:name=".CreationOuvertureActivity"
android:exported="false"/> android:exported="false" />
<activity <activity
android:name=".ModeImmersionActivity" android:name=".ModeConceptionActivity"
android:exported="false"/> android:exported="false" />
<activity <activity
android:name=".MainActivity" android:name=".ModeImmersionActivity"
android:exported="true"> android:exported="false" />
<activity
android:name=".MainActivity"
android:exported="true" >
<intent-filter> <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> </intent-filter>
</activity> </activity>
</application> </application>
......
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
...@@ -218,4 +218,10 @@ public class ModeConceptionActivity extends AppCompatActivity { ...@@ -218,4 +218,10 @@ public class ModeConceptionActivity extends AppCompatActivity {
public void confirmer(View view) { public void confirmer(View view) {
finish(); 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
...@@ -121,28 +121,9 @@ public class ModeImmersionActivity extends AppCompatActivity implements SensorEv ...@@ -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 @Override
public void onSensorChanged(SensorEvent event) { public void onSensorChanged(SensorEvent event) {
// On récupère l'angle // On récupère l'angle
float angle = -(Math.round(event.values[0])); float angle = -(Math.round(event.values[0]));
...@@ -155,30 +136,27 @@ public class ModeImmersionActivity extends AppCompatActivity implements SensorEv ...@@ -155,30 +136,27 @@ public class ModeImmersionActivity extends AppCompatActivity implements SensorEv
if(imageViewBoussole == null) { if(imageViewBoussole == null) {
imageViewBoussole = findViewById(R.id.imageViewBoussole); imageViewBoussole = findViewById(R.id.imageViewBoussole);
} }
runOnUiThread(new Runnable() {
@Override imageViewBoussole.startAnimation(rotateAnimation);
public void run() {
imageViewBoussole.startAnimation(rotateAnimation);
if(angle<(-45) && angle>=(-135)){
murEnCours = pieceEnCours.getMurOrientation(Orientation.EST);
if(angle<(-45) && angle>=(-135)){ } else if (angle<(-135) && angle>=(-225)) {
murEnCours = pieceEnCours.getMurOrientation(Orientation.EST); murEnCours = pieceEnCours.getMurOrientation(Orientation.SUD);
} else if (angle<(-135) && angle>=(-225)) { } else if (angle<(-225) && angle>=(-315)) {
murEnCours = pieceEnCours.getMurOrientation(Orientation.SUD); murEnCours = pieceEnCours.getMurOrientation(Orientation.OUEST);
} else if (angle<(-225) && angle>=(-315)) { }else{
murEnCours = pieceEnCours.getMurOrientation(Orientation.OUEST); murEnCours = pieceEnCours.getMurOrientation(Orientation.NORD);
}else{ }
murEnCours = pieceEnCours.getMurOrientation(Orientation.NORD); afficheMur();
}
afficheMur();
}
});
//Maj de l'angle de depart //Maj de l'angle de depart
debut = angle; debut = angle;
try { try {
Thread.sleep(10); Thread.sleep(5);
} catch (InterruptedException e) { } catch (InterruptedException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
......
package habitat;
import android.graphics.Rect;
public class Ouverture {
private Mur depart;
private Mur arrivee;
private Rect rect;
public Ouverture() {
}
}
<?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
...@@ -7,24 +7,13 @@ ...@@ -7,24 +7,13 @@
android:layout_height="match_parent" android:layout_height="match_parent"
tools:context=".ModeConceptionActivity"> 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 <ScrollView
android:id="@+id/scroll" android:id="@+id/scroll"
android:layout_width="358dp" android:layout_width="0dp"
android:layout_height="581dp" android:layout_height="0dp"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toTopOf="@+id/addPiece" app:layout_constraintBottom_toTopOf="@id/button2"
app:layout_constraintStart_toStartOf="parent"> app:layout_constraintStart_toStartOf="parent">
<LinearLayout <LinearLayout
...@@ -42,8 +31,31 @@ ...@@ -42,8 +31,31 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:id="@+id/button" android:id="@+id/button"
android:onClick="confirmer" android:onClick="confirmer"
app:layout_constraintTop_toBottomOf="@+id/addPiece"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="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> </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