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

affichage via boutons orientation ok

parent 0fa7a1b1
No related branches found
No related tags found
No related merge requests found
......@@ -59,7 +59,7 @@ public class MainActivity extends AppCompatActivity {
ouvrirJSON();
textView.setText(habitat.toJSON().toString());
textView.setText(habitat.toString());
}
......@@ -117,7 +117,7 @@ public class MainActivity extends AppCompatActivity {
}else{
Log.i("testJSON", "pbm ouverture");
}
textView.setText(habitat.toJSON().toString());
textView.setText(habitat.toString());
}
public String getFileContent(FileInputStream fis) {
......
......@@ -119,7 +119,6 @@ public class ModeConceptionActivity extends AppCompatActivity {
TextView textView1 = new TextView(this);
textView1.setText(piece.getMurs().toString());
ll.addView(editText);
//ll.addView(textView1);
for(Mur mur : piece.getMurs()){
LinearLayout llMur = new LinearLayout(this);
llMur.setOrientation(LinearLayout.HORIZONTAL);
......@@ -156,16 +155,22 @@ public class ModeConceptionActivity extends AppCompatActivity {
llMur.addView(imageButton);
ll.addView(llMur);
}
Button supprimer = new Button(getBaseContext());
supprimer.setText("Supprimer la pièce");
supprimer.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
habitat.removePiece(piece);
affichePieces();
majHabitat();
}
});
ll.addView(supprimer);
}
}
public void addPiece(View view) {
Piece piece1 = new Piece("p", habitat);
Mur murN = new Mur(piece1, Orientation.NORD, habitat);
Mur murE = new Mur(piece1, Orientation.EST, habitat);
Mur murS = new Mur(piece1, Orientation.SUD, habitat);
Mur murO = new Mur(piece1, Orientation.OUEST, habitat);
piece1.setMurs(murS, murO, murN, murE);
habitat.addPiece(piece1);
affichePieces();
majHabitat();
......@@ -203,4 +208,8 @@ public class ModeConceptionActivity extends AppCompatActivity {
Log.i("testJSON", "pbm");
}
}
public void confirmer(View view) {
finish();
}
}
\ No newline at end of file
......@@ -7,12 +7,14 @@ import android.util.Log;
import android.view.Display;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageView;
import android.widget.Toast;
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;
......@@ -20,6 +22,8 @@ import java.io.FileNotFoundException;
public class ModeImmersionActivity extends AppCompatActivity {
Habitat habitat;
Mur murEnCours;
Piece pieceEnCours;
@Override
protected void onCreate(Bundle savedInstanceState) {
......@@ -60,13 +64,14 @@ public class ModeImmersionActivity extends AppCompatActivity {
}
public void affichePiece(Piece piece){
pieceEnCours = piece;
ImageView imageViewMur = findViewById(R.id.imageViewMur);
Mur mur = piece.getMurs().get(0);
murEnCours = piece.getMurs().get(0);
//On récupère la photo
FileInputStream fis = null;
try {
fis = openFileInput(mur.getId()+".data");
fis = openFileInput(murEnCours.getId()+".data");
} catch (FileNotFoundException e) {
//throw new RuntimeException(e);
}
......@@ -78,4 +83,43 @@ public class ModeImmersionActivity extends AppCompatActivity {
imageViewMur.setImageDrawable(getDrawable(R.drawable.imagemur));
}
}
public void afficheMur(){
ImageView imageViewMur = findViewById(R.id.imageViewMur);
//On récupère la photo
FileInputStream fis = null;
try {
fis = openFileInput(murEnCours.getId()+".data");
} catch (FileNotFoundException e) {
//throw new RuntimeException(e);
}
if (fis != null) {
Bitmap bm = BitmapFactory.decodeStream(fis);
imageViewMur.setImageBitmap(bm);
}else{
Log.i("testDrawable", "pas de photo");
imageViewMur.setImageDrawable(getDrawable(R.drawable.imagemur));
}
}
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();
}
}
\ No newline at end of file
......@@ -88,6 +88,10 @@ public class Habitat implements Parcelable {
piece.setHabitat(this);
}
public void removePiece(Piece piece){
pieces.remove(piece);
}
public JSONObject toJSON(){
JSONObject jsonObject = new JSONObject();
JSONArray jsonArray = new JSONArray();
......
......@@ -3,6 +3,7 @@ package habitat;
import android.graphics.Bitmap;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.Log;
import org.json.JSONException;
import org.json.JSONObject;
import outils.FabriqueId;
......@@ -30,20 +31,25 @@ public class Mur implements Parcelable {
public Mur(JSONObject jsonObjectMur){
try {
id = (int) jsonObjectMur.get("Id");
String Jorientation = (String) jsonObjectMur.get("Orientation");
switch (Jorientation){
case "NORD" :
orientation = Orientation.NORD;
break;
case "SUD" :
orientation = Orientation.SUD;
break;
case "EST" :
orientation = Orientation.EST;
break;
case "OUEST" :
orientation = Orientation.OUEST;
break;
default:
orientation = Orientation.SUD; //Par défaut
break;
}
id = (int) jsonObjectMur.get("Id");
} catch (JSONException e) {
throw new RuntimeException(e);
}
......@@ -106,15 +112,6 @@ public class Mur implements Parcelable {
sb.append(orientation);
sb.append("}");
return sb.toString();
/*
return "Mur{" +
"piece=" + piece +
", orientation=" + orientation +
'}';
*/
}
@Override
......
......@@ -17,6 +17,13 @@ public class Piece implements Parcelable {
this.nom = nom;
this.habitat = habitat;
murs = new ArrayList<>(4);
//On créé les murs
Mur murN = new Mur(this, Orientation.NORD, this.getHabitat());
Mur murE = new Mur(this, Orientation.EST, this.getHabitat());
Mur murS = new Mur(this, Orientation.SUD, this.getHabitat());
Mur murO = new Mur(this, Orientation.OUEST, this.getHabitat());
setMurs(murS, murO, murN, murE);
}
public Piece(JSONObject jsonObjectPiece){
......@@ -81,6 +88,16 @@ public class Piece implements Parcelable {
this.habitat = habitat;
}
public Mur getMurOrientation(Orientation orientation){
Mur result = murs.get(0);
for(Mur mur : murs){
if(mur.getOrientation().equals(orientation)){
result = mur;
}
}
return result;
}
@Override
public String toString() {
return "Piece{nom=" + nom +
......
......@@ -16,12 +16,12 @@
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="360dp"
android:layout_height="640dp"
android:layout_width="358dp"
android:layout_height="581dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toTopOf="@+id/addPiece"
......@@ -35,4 +35,15 @@
>
</LinearLayout>
</ScrollView>
<Button
android:text="Confirmer"
android:layout_width="wrap_content"
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"/>
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
......@@ -15,5 +15,54 @@
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintHorizontal_bias="0.495"
app:layout_constraintVertical_bias="0.406"/>
<Button
android:text="NORD"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button2"
android:onClick="afficheNord"
app:layout_constraintTop_toBottomOf="@+id/imageViewMur"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:layout_marginTop="20dp"
app:layout_constraintHorizontal_bias="0.501"/>
<Button
android:text="EST"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button3"
android:onClick="afficheEst"
app:layout_constraintEnd_toEndOf="parent"
android:layout_marginEnd="40dp"
app:layout_constraintTop_toBottomOf="@+id/button2"
app:layout_constraintBottom_toTopOf="@+id/button5"/>
<Button
android:text="OUEST"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button4"
android:onClick="afficheOuest"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="@+id/button3"
app:layout_constraintHorizontal_bias="0.221"
app:layout_constraintTop_toBottomOf="@+id/button2"
app:layout_constraintBottom_toTopOf="@+id/button5"/>
<Button
android:text="SUD"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button5"
android:onClick="afficheSud"
app:layout_constraintTop_toBottomOf="@+id/button2"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintVertical_bias="0.863"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"/>
</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