diff --git a/code/app/src/main/java/projet/iut/jeu_de_la_vie/view/LauncherActivity.java b/code/app/src/main/java/projet/iut/jeu_de_la_vie/view/LauncherActivity.java
index a21a60a..8f143c5 100644
--- a/code/app/src/main/java/projet/iut/jeu_de_la_vie/view/LauncherActivity.java
+++ b/code/app/src/main/java/projet/iut/jeu_de_la_vie/view/LauncherActivity.java
@@ -27,7 +27,7 @@ public class LauncherActivity extends AppCompatActivity {
private Button start;
static int width;
static int height;
- static Boolean isPortrait = true;
+ public static Boolean isPortrait = true;
@Override
protected void onResume(){
@@ -88,6 +88,12 @@ public class LauncherActivity extends AppCompatActivity {
@Override
protected void onStart (){
super.onStart();
+ if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT){
+ isPortrait = true;
+ }
+ else if(getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE){
+ isPortrait = false;
+ }
//FragmentPlateau fragment = new FragmentPlateau();
//fragment.setPlateau(manager.getActualiseurCellule().getArbitre().getPlateau());
}
@@ -138,15 +144,4 @@ public class LauncherActivity extends AppCompatActivity {
manager = (Manager) savedInstanceState.getSerializable("manager");
}
- @Override
- public void onConfigurationChanged (Configuration newconfig){
- Log.d("affichage","gros tu force");
- if (newconfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
- isPortrait = false;
- } else if (newconfig.orientation == Configuration.ORIENTATION_PORTRAIT){
- isPortrait = true;
- }
-
- }
-
}
diff --git a/code/app/src/main/java/projet/iut/jeu_de_la_vie/view/PlateauView.java b/code/app/src/main/java/projet/iut/jeu_de_la_vie/view/PlateauView.java
index 024cfdb..35589ba 100644
--- a/code/app/src/main/java/projet/iut/jeu_de_la_vie/view/PlateauView.java
+++ b/code/app/src/main/java/projet/iut/jeu_de_la_vie/view/PlateauView.java
@@ -1,6 +1,8 @@
package projet.iut.jeu_de_la_vie.view;
+import android.app.Activity;
import android.content.Context;
+import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.graphics.Canvas;
import android.graphics.Color;
@@ -55,6 +57,7 @@ public class PlateauView extends View implements ObserverCV {
private int colones;
private int lignes;
private int dethColor = Color.BLACK;
+ private int modif = 80;
public PlateauView(Context context, int colones, int lignes){
super(context);
@@ -86,14 +89,31 @@ public class PlateauView extends View implements ObserverCV {
}
int width = LauncherActivity.width;
- Log.d("affichage",""+LauncherActivity.isPortrait);
+ int height = LauncherActivity.height;
+
if (LauncherActivity.isPortrait) {
- rect = new Rect(width / colones * j + (width / colones) * 5 / 100, width / colones * i + (width / colones) * 5 / 100, (width / colones * (j + 1)) - (width / colones) * 5 / 100, (width / colones * (i + 1)) - (width / colones) * 5 / 100);
- canvas.drawRect(rect, paint);
+ if (width/colones < height/lignes) {
+ rect = new Rect(width / colones * j + (width / colones) * 5 / 100, width / colones * i + (width / colones) * 5 / 100, (width / colones * (j + 1)) - (width / colones) * 5 / 100, (width / colones * (i + 1)) - (width / colones) * 5 / 100);
+ canvas.drawRect(rect, paint);
+ Log.d("orientation", "portrait");
+ }
+ else {
+ rect = new Rect((height-modif) / lignes * j + ((height-modif) / lignes) * 5 / 100, (height-modif) / lignes * i + ((height-modif) / lignes) * 5 / 100, ((height-modif) / lignes * (j + 1)) - ((height-modif) / lignes) * 5 / 100, ((height-modif) / lignes * (i + 1)) - ((height-modif) / lignes) * 5 / 100);
+ canvas.drawRect(rect, paint);
+ Log.d("orientation", "portrait");
+ }
}
else {
- rect = new Rect(width / lignes * j + (width / lignes) * 5 / 100, width / lignes * i + (width / lignes) * 5 / 100, (width / lignes * (j + 1)) - (width / lignes) * 5 / 100, (width / lignes * (i + 1)) - (width / lignes) * 5 / 100);
- canvas.drawRect(rect, paint);
+ if (height/lignes < width/colones) {
+ rect = new Rect((height - modif) / lignes * j + ((height - modif) / lignes) * 5 / 100, (height - modif) / lignes * i + ((height - modif) / lignes) * 5 / 100, ((height - modif) / lignes * (j + 1)) - ((height - modif) / lignes) * 5 / 100, ((height - modif) / lignes * (i + 1)) - ((height - modif) / lignes) * 5 / 100);
+ canvas.drawRect(rect, paint);
+ Log.d("orientation", "landscpape");
+ }
+ else{
+ rect = new Rect(width / colones * j + (width / colones) * 5 / 100, width / colones * i + (width / colones) * 5 / 100, (width / colones * (j + 1)) - (width / colones) * 5 / 100, (width / colones * (i + 1)) - (width / colones) * 5 / 100);
+ canvas.drawRect(rect, paint);
+ Log.d("orientation", "landscpape");
+ }
}
}
}
diff --git a/code/app/src/main/java/projet/iut/jeu_de_la_vie/view/fragment/FragmentPlateau.java b/code/app/src/main/java/projet/iut/jeu_de_la_vie/view/fragment/FragmentPlateau.java
index 79d00c9..b963363 100644
--- a/code/app/src/main/java/projet/iut/jeu_de_la_vie/view/fragment/FragmentPlateau.java
+++ b/code/app/src/main/java/projet/iut/jeu_de_la_vie/view/fragment/FragmentPlateau.java
@@ -18,6 +18,7 @@ import projet.iut.jeu_de_la_vie.model.boucleDeJeu.observer.ObservableBDJ;
import projet.iut.jeu_de_la_vie.model.boucleDeJeu.observer.ObserverBDJ;
import projet.iut.jeu_de_la_vie.model.cellule.Cellule;
import projet.iut.jeu_de_la_vie.model.cellulesVivantes.observer.ObserverCV;
+import projet.iut.jeu_de_la_vie.view.LauncherActivity;
import projet.iut.jeu_de_la_vie.view.PlateauView;
public class FragmentPlateau extends Fragment implements ObserverBDJ {
@@ -32,8 +33,11 @@ public class FragmentPlateau extends Fragment implements ObserverBDJ {
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- manager.setNumberOfLines((Integer) getArguments().get("colones"));
- manager.setNumberOfColumns((Integer) getArguments().get("lignes"));
+ manager.setNumberOfLines((Integer) getArguments().get("lignes"));
+ manager.setNumberOfColumns((Integer) getArguments().get("colones"));
+ if (savedInstanceState != null){
+ manager = (Manager) savedInstanceState.getSerializable("manager");
+ }
}
@@ -63,7 +67,12 @@ public class FragmentPlateau extends Fragment implements ObserverBDJ {
private boolean tapRect(View view1, MotionEvent motionEvent){
int x = (int) (( (float) manager.getNomberOfColumns() / view1.getWidth()) * motionEvent.getX()-5/100);
int y = (int) (( (float) manager.getNomberOfColumns() / view1.getWidth()) * motionEvent.getY()-5/100);
- return tapRect(view1, x, y);
+ if (LauncherActivity.isPortrait) {
+ return tapRect(view1, x, y);
+ }
+ else {
+ return tapRect(view1, x, y);
+ }
}
private boolean tapRect(View view, int x, int y){
Log.d("D", "x=" + x);
@@ -89,14 +98,26 @@ public class FragmentPlateau extends Fragment implements ObserverBDJ {
@Override
public void update() {
- PlateauView view = (PlateauView) getView().findViewById(R.id.plateauView);
- if(view == null){
- return;
+ try {
+
+ PlateauView view = (PlateauView) getView().findViewById(R.id.plateauView);
+ if (view == null) {
+ return;
+ }
+ view.resetMap();
+ for (Cellule c : manager.getActualiseurCellule().getArbitre().getPlateau().getCellulesVivantes().getCells().values()) {
+ view.addPosCell(c);
+ }
+ view.postInvalidate();
}
- view.resetMap();
- for (Cellule c: manager.getActualiseurCellule().getArbitre().getPlateau().getCellulesVivantes().getCells().values()) {
- view.addPosCell(c);
+ catch (Exception e){
+
}
- view.postInvalidate();
+ }
+
+ @Override
+ public void onSaveInstanceState(@NonNull Bundle outState) {
+ super.onSaveInstanceState(outState);
+ outState.putSerializable("manager",manager);
}
}
diff --git a/code/app/src/main/res/layout-land/fragment_plateau.xml b/code/app/src/main/res/layout-land/fragment_plateau.xml
new file mode 100644
index 0000000..26fe558
--- /dev/null
+++ b/code/app/src/main/res/layout-land/fragment_plateau.xml
@@ -0,0 +1,34 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/code/app/src/main/res/layout/fragment_plateau.xml b/code/app/src/main/res/layout/fragment_plateau.xml
index 2a21514..481df92 100644
--- a/code/app/src/main/res/layout/fragment_plateau.xml
+++ b/code/app/src/main/res/layout/fragment_plateau.xml
@@ -1,13 +1,14 @@
+ android:layout_height="match_parent">
+ app:layout_constraintTop_toTopOf="parent"
+ app:layout_constraintVertical_bias="0.0" />
-
-
\ No newline at end of file
diff --git a/code/app/src/main/res/layout/text_item.xml b/code/app/src/main/res/layout/text_item.xml
index 04dff22..3787fab 100644
--- a/code/app/src/main/res/layout/text_item.xml
+++ b/code/app/src/main/res/layout/text_item.xml
@@ -1,11 +1,11 @@
+ android:layout_height="match_parent">
+
+ android:layout_height="match_parent" />
diff --git a/code/app/src/main/res/layout/vue_jeu_tmp.xml b/code/app/src/main/res/layout/vue_jeu_tmp.xml
deleted file mode 100644
index 79f5681..0000000
--- a/code/app/src/main/res/layout/vue_jeu_tmp.xml
+++ /dev/null
@@ -1,44 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/code/app/src/main/res/values-night/themes.xml b/code/app/src/main/res/values-night/themes.xml
index 46624ef..9b3c601 100644
--- a/code/app/src/main/res/values-night/themes.xml
+++ b/code/app/src/main/res/values-night/themes.xml
@@ -1,6 +1,6 @@
-