rendu la vue stable sur la rotation

main
juduteyrat 3 years ago
parent ba43598413
commit 2267871179

@ -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;
}
}
}

@ -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) {
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);
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");
}
}
}
}

@ -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,8 +67,13 @@ 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);
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);
Log.d("D", "y=" + y);
@ -89,14 +98,26 @@ public class FragmentPlateau extends Fragment implements ObserverBDJ {
@Override
public void update() {
try {
PlateauView view = (PlateauView) getView().findViewById(R.id.plateauView);
if(view == null){
if (view == null) {
return;
}
view.resetMap();
for (Cellule c: manager.getActualiseurCellule().getArbitre().getPlateau().getCellulesVivantes().getCells().values()) {
for (Cellule c : manager.getActualiseurCellule().getArbitre().getPlateau().getCellulesVivantes().getCells().values()) {
view.addPosCell(c);
}
view.postInvalidate();
}
catch (Exception e){
}
}
@Override
public void onSaveInstanceState(@NonNull Bundle outState) {
super.onSaveInstanceState(outState);
outState.putSerializable("manager",manager);
}
}

@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/vueJeu"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/containerPlateauView"
android:layout_width="match_parent"
android:layout_height="match_parent">
<projet.iut.jeu_de_la_vie.view.PlateauView
android:id="@+id/plateauView"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintBottom_toTopOf="@+id/startnstopButton"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0" />
<Button
android:id="@+id/startnstopButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/start_text"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</FrameLayout>

@ -1,13 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/vueJeu"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/containerPlateauView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/containerPlateauView">
android:layout_height="match_parent">
<projet.iut.jeu_de_la_vie.view.PlateauView
android:id="@+id/plateauView"
@ -15,8 +16,10 @@
android:layout_height="match_parent"
app:layout_constraintBottom_toTopOf="@+id/startnstopButton"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0" />
<Button
android:id="@+id/startnstopButton"

@ -126,12 +126,4 @@
app:layout_constraintStart_toStartOf="@+id/nbColoneLabel"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/test"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="test"
app:layout_constraintBottom_toTopOf="@+id/startButton"
tools:layout_editor_absoluteX="88dp" />
</androidx.constraintlayout.widget.ConstraintLayout>

@ -1,11 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
android:layout_height="match_parent">
<TextView
android:id="@+id/elemnt"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/elemnt"/>
android:layout_height="match_parent" />
</FrameLayout>

@ -1,44 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<CheckBox
android:id="@+id/checkBox33"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<CheckBox
android:id="@+id/checkBox37"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="@+id/checkBox39"
app:layout_constraintStart_toEndOf="@+id/checkBox38"
app:layout_constraintTop_toBottomOf="@+id/checkBox39" />
<CheckBox
android:id="@+id/checkBox38"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="@+id/checkBox33"
app:layout_constraintTop_toBottomOf="@+id/checkBox33" />
<CheckBox
android:id="@+id/checkBox39"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintStart_toEndOf="@+id/checkBox33"
app:layout_constraintTop_toTopOf="@+id/checkBox33" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="quitter"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

@ -1,6 +1,6 @@
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.Jeu_de_la_vie" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<style name="Theme.Jeu_de_la_vie" parent="Theme.MaterialComponents.DayNight.NoActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">@color/purple_200</item>
<item name="colorPrimaryVariant">@color/purple_700</item>

@ -1,6 +1,6 @@
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.Jeu_de_la_vie" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<style name="Theme.Jeu_de_la_vie" parent="Theme.MaterialComponents.DayNight.NoActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">@color/purple_500</item>
<item name="colorPrimaryVariant">@color/purple_700</item>

Loading…
Cancel
Save