Feat: Amélioration dialogue 'À Propos'

- Remplacement de l'AlertDialog simple par un layout personnalisé (dialog_about.xml).
- Mise à jour du message 'À Propos' avec les informations du groupe et contexte projet.
- Ajout d'un TextView cliquable contenant un lien vers le site web 'legion-muyue.fr'.
- Implémentation de l'ouverture du lien dans un navigateur via Intent dans showAboutDialog().
This commit is contained in:
Augustin ROUX 2025-04-04 14:53:20 +02:00
parent d12f323eae
commit b7655a825a
3 changed files with 85 additions and 6 deletions

View File

@ -9,8 +9,11 @@ package legion.muyue.best2048;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.content.ActivityNotFoundException;
import android.content.DialogInterface; // Assurez-vous que cet import est présent import android.content.DialogInterface; // Assurez-vous que cet import est présent
import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.util.TypedValue; import android.util.TypedValue;
import android.view.Gravity; import android.view.Gravity;
@ -25,6 +28,7 @@ import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.ContextCompat; import androidx.core.content.ContextCompat;
import androidx.gridlayout.widget.GridLayout; import androidx.gridlayout.widget.GridLayout;
import android.widget.Button; import android.widget.Button;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity { public class MainActivity extends AppCompatActivity {
@ -482,14 +486,37 @@ public class MainActivity extends AppCompatActivity {
} }
/** /**
* Affiche une boîte de dialogue simple avec les informations "À Propos". * Affiche la boîte de dialogue "À Propos" en utilisant un layout personnalisé,
* incluant des informations sur l'application et un lien cliquable vers le site web.
*/ */
private void showAboutDialog() { private void showAboutDialog() {
new AlertDialog.Builder(this) AlertDialog.Builder builder = new AlertDialog.Builder(this);
.setTitle(R.string.about_title) LayoutInflater inflater = getLayoutInflater();
.setMessage(R.string.about_message) // Pensez à personnaliser ceci dans strings.xml View dialogView = inflater.inflate(R.layout.dialog_about, null); // Gonfle le layout
.setPositiveButton(R.string.ok, (dialog, which) -> dialog.dismiss()) builder.setView(dialogView);
.show(); builder.setCancelable(true); // Permet de fermer
// Récupère les vues du layout
TextView websiteLinkTextView = dialogView.findViewById(R.id.websiteLinkTextView);
Button okButton = dialogView.findViewById(R.id.dialogOkButtonAbout);
final AlertDialog dialog = builder.create();
// Rend le lien cliquable pour ouvrir le navigateur
websiteLinkTextView.setOnClickListener(v -> {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.about_website_url)));
try {
startActivity(browserIntent);
} catch (ActivityNotFoundException e) {
// Gère le cas aucun navigateur n'est installé
Toast.makeText(this, "Aucun navigateur web trouvé.", Toast.LENGTH_SHORT).show();
}
});
// Bouton OK pour fermer la dialogue
okButton.setOnClickListener(v -> dialog.dismiss());
dialog.show();
} }

View File

@ -0,0 +1,51 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="24dp"
android:background="@drawable/dialog_background">
<TextView
android:id="@+id/dialogTitleAbout"
style="@style/SectionTitle" android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/about_title"
android:gravity="center"
android:layout_marginBottom="16dp"/>
<TextView
android:id="@+id/aboutMessageTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/about_message"
android:textColor="@color/text_tile_low"
android:textSize="16sp"
android:fontFamily="@font/nunito_family"
android:gravity="center"
android:lineSpacingExtra="4dp"
android:layout_marginBottom="16dp"/>
<TextView
android:id="@+id/websiteLinkTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/about_website_text"
android:textColor="@color/design_default_color_primary" android:textSize="16sp"
android:fontFamily="@font/nunito_family"
android:gravity="center"
android:clickable="true" android:focusable="true"
android:background="?android:attr/selectableItemBackground" android:paddingTop="8dp"
android:paddingBottom="8dp"
android:layout_marginBottom="16dp"/>
<Button
android:id="@+id/dialogOkButtonAbout"
style="@style/ButtonStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="0dp" android:layout_marginEnd="0dp"
android:layout_marginTop="8dp" android:layout_marginBottom="0dp"
android:text="@string/ok" />
</LinearLayout>

View File

@ -60,6 +60,7 @@
<string name="how_to_play_instructions">Swipe the screen (Up, Down, Left, Right) to move all the tiles.\n\nWhen two tiles with the same number touch, they merge into one!\n\nReach the 2048 tile to win.\n\nThe game is over if the board is full and no moves are possible.</string> <string name="how_to_play_instructions">Swipe the screen (Up, Down, Left, Right) to move all the tiles.\n\nWhen two tiles with the same number touch, they merge into one!\n\nReach the 2048 tile to win.\n\nThe game is over if the board is full and no moves are possible.</string>
<string name="about_title">About Best 2048</string> <string name="about_title">About Best 2048</string>
<string name="about_message">Version: 1.0 (University Project)\nDeveloped by: La Legion de Muyue\n(Leader: Muyue, Members: 2 others)\n\nBased on the popular game 2048.</string> <string name="about_message">Version: 1.0 (University Project)\nDeveloped by: La Legion de Muyue\n(Leader: Muyue, Members: 2 others)\n\nBased on the popular game 2048.</string>
<string name="about_website_text">Website : legion-muyue.fr</string> <string name="about_website_url">https://legion-muyue.fr</string>
<string name="ok">OK</string> <string name="ok">OK</string>
<string name="settings_title">Settings</string> <string name="settings_title">Settings</string>
<string name="settings_message">Settings screen to be implemented.</string> <string name="settings_message">Settings screen to be implemented.</string>