diff --git a/app/src/main/java/com/example/mastermind/MainActivity.java b/app/src/main/java/com/example/mastermind/MainActivity.java
index 3c47404..9599c52 100644
--- a/app/src/main/java/com/example/mastermind/MainActivity.java
+++ b/app/src/main/java/com/example/mastermind/MainActivity.java
@@ -11,6 +11,7 @@ public class MainActivity extends Activity {
private Button mORDI;
private Button mSettings;
private Button mRules;
+ private boolean pionV;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -25,6 +26,9 @@ public class MainActivity extends Activity {
public void onClick(View v) {
Intent HotSeat = new Intent(MainActivity.this, GameActivity.class);
HotSeat.putExtra("bot", false);
+ if(pionV) {
+ HotSeat.putExtra("pionVide", true);
+ }
startActivity(HotSeat);
}
});
@@ -33,6 +37,9 @@ public class MainActivity extends Activity {
public void onClick(View v) {
Intent ordi = new Intent(MainActivity.this, GameActivity.class);
ordi.putExtra("bot", true);
+ if(pionV) {
+ ordi.putExtra("pionVide", true);
+ }
startActivity(ordi);
}
});
@@ -40,7 +47,7 @@ public class MainActivity extends Activity {
@Override
public void onClick(View v) {
Intent settings = new Intent(MainActivity.this, SettingsActivity.class);
- startActivity(settings);
+ startActivityForResult(settings, 1);
}
});
mRules.setOnClickListener(new View.OnClickListener() {
@@ -51,4 +58,13 @@ public class MainActivity extends Activity {
}
});
}
+
+ @Override
+ public void onActivityResult(int requestCode, int resultCode, Intent data) {
+ super.onActivityResult(requestCode, resultCode, data);
+
+ if(requestCode == 1) {
+ pionV = data.getBooleanExtra("pionV", false);
+ }
+ }
}
\ No newline at end of file
diff --git a/app/src/main/java/com/example/mastermind/SettingsActivity.java b/app/src/main/java/com/example/mastermind/SettingsActivity.java
index d14d52e..bb75131 100644
--- a/app/src/main/java/com/example/mastermind/SettingsActivity.java
+++ b/app/src/main/java/com/example/mastermind/SettingsActivity.java
@@ -1,33 +1,44 @@
package com.example.mastermind;
+import android.app.Activity;
+import android.content.Intent;
import android.os.Bundle;
+import android.view.View;
+import android.widget.Button;
+import android.widget.CompoundButton;
+import android.widget.Switch;
-import androidx.appcompat.app.ActionBar;
-import androidx.appcompat.app.AppCompatActivity;
-import androidx.preference.PreferenceFragmentCompat;
-
-public class SettingsActivity extends AppCompatActivity {
+public class SettingsActivity extends Activity {
+ private Button mButton;
+ private Switch mSwitch;
+ private boolean pionV;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.settings_activity);
- if (savedInstanceState == null) {
- getSupportFragmentManager()
- .beginTransaction()
- .replace(R.id.settings, new SettingsFragment())
- .commit();
- }
- ActionBar actionBar = getSupportActionBar();
- if (actionBar != null) {
- actionBar.setDisplayHomeAsUpEnabled(true);
- }
- }
- public static class SettingsFragment extends PreferenceFragmentCompat {
- @Override
- public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
- setPreferencesFromResource(R.xml.root_preferences, rootKey);
- }
+ mButton = findViewById(R.id.backButton);
+ mSwitch = findViewById(R.id.switchPion);
+
+ mSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
+ @Override
+ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
+ if(isChecked) {
+ pionV = true;
+ } else {
+ pionV = false;
+ }
+ }
+ });
+ mButton.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ Intent intent = new Intent();
+ intent.putExtra("pionV", pionV);
+ setResult(1, intent);
+ finish();
+ }
+ });
}
}
\ No newline at end of file
diff --git a/app/src/main/res/layout/settings_activity.xml b/app/src/main/res/layout/settings_activity.xml
index 00a568f..5ef483f 100644
--- a/app/src/main/res/layout/settings_activity.xml
+++ b/app/src/main/res/layout/settings_activity.xml
@@ -1,10 +1,46 @@
+ android:background="@color/cardview_dark_background"
+ android:orientation="vertical"
+ tools:ignore="UseSwitchCompatOrMaterialXml">
-
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 293277e..a2aa6e0 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -7,6 +7,7 @@
Paramètres
+ < Retour au menu
Autoriser les pions vides
Cette fonctionnalité augmente la difficulté du jeu pour l\'attaquant
diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml
new file mode 100644
index 0000000..4270bc8
--- /dev/null
+++ b/app/src/main/res/xml/preferences.xml
@@ -0,0 +1,14 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file