séparation option et Menu - respect model MVC
This commit is contained in:
@@ -1,44 +1,27 @@
|
|||||||
package sae.chuzzle;
|
package sae.chuzzle;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Intent;
|
import android.os.Bundle;
|
||||||
import android.os.Bundle;
|
import android.widget.Button;
|
||||||
import android.view.View;
|
|
||||||
import android.widget.Button;
|
public class MenuActivity extends Activity {
|
||||||
|
|
||||||
public class MenuActivity extends Activity implements View.OnClickListener {
|
private Button btnNouvellePartie;
|
||||||
|
private Button btnPartieGraine;
|
||||||
private Button btnNouvellePartie;
|
private Button btnOptions;
|
||||||
private Button btnPartieGraine;
|
|
||||||
private Button btnOptions;
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
@Override
|
super.onCreate(savedInstanceState);
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
setContentView(R.layout.activity_menu);
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
setContentView(R.layout.activity_menu);
|
btnNouvellePartie = findViewById(R.id.btnNouvellePartie);
|
||||||
|
btnPartieGraine = findViewById(R.id.btnPartieGraine);
|
||||||
btnNouvellePartie = findViewById(R.id.btnNouvellePartie);
|
btnOptions = findViewById(R.id.btnOptions);
|
||||||
btnPartieGraine = findViewById(R.id.btnPartieGraine);
|
|
||||||
btnOptions = findViewById(R.id.btnOptions);
|
MenuController controller = new MenuController(this);
|
||||||
|
btnNouvellePartie.setOnClickListener(controller);
|
||||||
btnNouvellePartie.setOnClickListener(this);
|
btnPartieGraine.setOnClickListener(controller);
|
||||||
btnPartieGraine.setOnClickListener(this);
|
btnOptions.setOnClickListener(controller);
|
||||||
btnOptions.setOnClickListener(this);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
if (v == btnNouvellePartie) {
|
|
||||||
long graine = System.currentTimeMillis();
|
|
||||||
Intent intent = new Intent(this, MainActivity.class);
|
|
||||||
intent.putExtra("graine", graine);
|
|
||||||
startActivity(intent);
|
|
||||||
} else if (v == btnPartieGraine) {
|
|
||||||
Intent intent = new Intent(this, SeedActivity.class);
|
|
||||||
startActivity(intent);
|
|
||||||
} else if (v == btnOptions) {
|
|
||||||
Intent intent = new Intent(this, OptionsActivity.class);
|
|
||||||
startActivity(intent);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
package sae.chuzzle;
|
||||||
|
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.view.View;
|
||||||
|
|
||||||
|
public class MenuController implements View.OnClickListener {
|
||||||
|
|
||||||
|
private final MenuActivity activity;
|
||||||
|
|
||||||
|
public MenuController(MenuActivity activity) {
|
||||||
|
this.activity = activity;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
int id = v.getId();
|
||||||
|
if (id == R.id.btnNouvellePartie) {
|
||||||
|
long graine = System.currentTimeMillis();
|
||||||
|
Intent intent = new Intent(activity, MainActivity.class);
|
||||||
|
intent.putExtra("graine", graine);
|
||||||
|
activity.startActivity(intent);
|
||||||
|
} else if (id == R.id.btnPartieGraine) {
|
||||||
|
Intent intent = new Intent(activity, SeedActivity.class);
|
||||||
|
activity.startActivity(intent);
|
||||||
|
} else if (id == R.id.btnOptions) {
|
||||||
|
Intent intent = new Intent(activity, OptionsActivity.class);
|
||||||
|
activity.startActivity(intent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,22 +1,17 @@
|
|||||||
package sae.chuzzle;
|
package sae.chuzzle;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Intent;
|
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.View;
|
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.CheckBox;
|
import android.widget.CheckBox;
|
||||||
import android.widget.CompoundButton;
|
|
||||||
|
|
||||||
public class OptionsActivity extends Activity
|
public class OptionsActivity extends Activity {
|
||||||
implements CompoundButton.OnCheckedChangeListener, View.OnClickListener {
|
|
||||||
|
|
||||||
private SharedPreferences prefs;
|
private SharedPreferences prefs;
|
||||||
private CheckBox checkHard;
|
private CheckBox checkHard;
|
||||||
private Button btnRetour;
|
private Button btnRetour;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
@@ -24,30 +19,13 @@ public class OptionsActivity extends Activity
|
|||||||
|
|
||||||
prefs = getSharedPreferences("chuzzle_prefs", MODE_PRIVATE);
|
prefs = getSharedPreferences("chuzzle_prefs", MODE_PRIVATE);
|
||||||
|
|
||||||
|
|
||||||
checkHard = findViewById(R.id.checkHard);
|
checkHard = findViewById(R.id.checkHard);
|
||||||
btnRetour = findViewById(R.id.btnBack);
|
btnRetour = findViewById(R.id.btnBack);
|
||||||
|
|
||||||
checkHard.setChecked(prefs.getBoolean("hard_mode", false));
|
checkHard.setChecked(prefs.getBoolean("hard_mode", false));
|
||||||
|
|
||||||
|
OptionsController controller = new OptionsController(this, prefs);
|
||||||
checkHard.setOnCheckedChangeListener(this);
|
checkHard.setOnCheckedChangeListener(controller);
|
||||||
btnRetour.setOnClickListener(this);
|
btnRetour.setOnClickListener(controller);
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCheckedChanged(CompoundButton bouton, boolean estCoche) {
|
|
||||||
if (bouton == checkHard) {
|
|
||||||
prefs.edit().putBoolean("hard_mode", estCoche).apply();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
if (v == btnRetour) {
|
|
||||||
Intent intent = new Intent(this, MenuActivity.class);
|
|
||||||
startActivity(intent);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,35 @@
|
|||||||
|
package sae.chuzzle;
|
||||||
|
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.CompoundButton;
|
||||||
|
|
||||||
|
public class OptionsController
|
||||||
|
implements CompoundButton.OnCheckedChangeListener, View.OnClickListener {
|
||||||
|
|
||||||
|
private final OptionsActivity activity;
|
||||||
|
private final SharedPreferences prefs;
|
||||||
|
|
||||||
|
public OptionsController(OptionsActivity activity, SharedPreferences prefs) {
|
||||||
|
this.activity = activity;
|
||||||
|
this.prefs = prefs;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCheckedChanged(CompoundButton bouton, boolean estCoche) {
|
||||||
|
int id = bouton.getId();
|
||||||
|
if (id == R.id.checkHard) {
|
||||||
|
prefs.edit().putBoolean("hard_mode", estCoche).apply();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
int id = v.getId();
|
||||||
|
if (id == R.id.btnBack) {
|
||||||
|
Intent intent = new Intent(activity, MenuActivity.class);
|
||||||
|
activity.startActivity(intent);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user