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

chgt nom piece ok

parent 0a185963
No related branches found
No related tags found
No related merge requests found
package com.example.myhabitat;
import android.content.Intent;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import habitat.Habitat;
import habitat.Mur;
import habitat.Orientation;
import habitat.Piece;
import habitat.*;
public class PiecesActivity extends AppCompatActivity {
private Habitat habitat;
private TextView textView;
private GestionnaireEditPiece gestionnaire;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pieces);
gestionnaire = new GestionnaireEditPiece();
//On récupère Habitat
Intent intent = getIntent();
if (intent != null){
......@@ -26,12 +31,51 @@ public class PiecesActivity extends AppCompatActivity {
if (habitat != null){
this.habitat = habitat;
this.habitat.setCorrectly();
affichePieces();
/*
textView = findViewById(R.id.textViewPieces);
textView.setText(habitat.toString());
*/
}
}
}
private void affichePieces() {
gestionnaire.reset();
LinearLayout ll = findViewById(R.id.linearLayout);
ll.removeAllViews();
for(Piece piece : habitat.getPieces()){
EditText editText = new EditText(this);
editText.setText(piece.getNom());
editText.setImeOptions(EditorInfo.IME_ACTION_DONE);
editText.setSingleLine();
gestionnaire.add(editText, piece);
editText.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
gestionnaire.getPiece(editText).setNom(String.valueOf(editText.getText()));
majHabitat();
}
});
TextView textView1 = new TextView(this);
textView1.setText(piece.getMurs().toString());
ll.addView(editText);
ll.addView(textView1);
}
}
public void addPiece(View view) {
Piece piece1 = new Piece("p", habitat);
Mur murN = new Mur(piece1, Orientation.NORD, habitat);
......@@ -40,7 +84,11 @@ public class PiecesActivity extends AppCompatActivity {
Mur murO = new Mur(piece1, Orientation.OUEST, habitat);
piece1.setMurs(murS, murO, murN, murE);
habitat.getPieces().add(piece1);
textView.setText(habitat.toString());
affichePieces();
majHabitat();
}
public void majHabitat(){
Intent intent = new Intent().putExtra("Habitat", habitat);
setResult(RESULT_OK, intent);
}
......
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();
}
}
......@@ -7,16 +7,6 @@
android:layout_height="match_parent"
tools:context=".PiecesActivity">
<TextView
android:text="TextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textViewPieces"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"/>
<Button
android:text="Ajouter une piece"
android:layout_width="wrap_content"
......@@ -25,7 +15,19 @@
android:onClick="addPiece"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:layout_marginTop="40dp"
app:layout_constraintTop_toBottomOf="@+id/textViewPieces"
app:layout_constraintBottom_toBottomOf="parent"/>
app:layout_constraintBottom_toBottomOf="parent"
/>
<LinearLayout
android:id="@+id/linearLayout"
android:orientation="vertical"
android:layout_width="314dp"
android:layout_height="596dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintVertical_bias="1.0"
android:layout_marginTop="200dp"
app:layout_constraintBottom_toTopOf="@+id/addPiece"
app:layout_constraintEnd_toEndOf="parent">
</LinearLayout>
</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