From df84ff5644d796e67a3258a82e5fe601748f74a7 Mon Sep 17 00:00:00 2001 From: Claire G Date: Sun, 9 Apr 2023 19:15:36 +0200 Subject: [PATCH] Modifs page parametre + debut recup si pion vide --- .../com/example/mastermind/MainActivity.java | 18 ++++++- .../example/mastermind/SettingsActivity.java | 53 +++++++++++-------- app/src/main/res/layout/settings_activity.xml | 46 ++++++++++++++-- app/src/main/res/values/strings.xml | 1 + app/src/main/res/xml/preferences.xml | 14 +++++ 5 files changed, 105 insertions(+), 27 deletions(-) create mode 100644 app/src/main/res/xml/preferences.xml 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"> - + + +