www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit 0ff04d20d497fe338b9b01a66787499e20c5a62d
parent 1e8506272207a4a2b0a7809336362f0e7d7e9b80
Author: Bertrand BRUN <bertrand0brun@gmail.com>
Date:   Thu, 24 Feb 2011 12:51:27 +0100

Ajout de la gestion de l'erreur si le serveur plante. Et petit correction dans l'uri de FrontPage pour la page signup.php
Diffstat:
Mcode/PtiClic/res/values/strings.xml | 1+
Mcode/PtiClic/src/org/pticlic/FrontPage.java | 7++++++-
Mcode/PtiClic/src/org/pticlic/Score.java | 16+++++++++++++++-
Mcode/PtiClic/src/org/pticlic/games/BaseGame.java | 14++++++++++++++
Mcode/PtiClic/src/org/pticlic/model/Network.java | 8++++----
5 files changed, 40 insertions(+), 6 deletions(-)

diff --git a/code/PtiClic/res/values/strings.xml b/code/PtiClic/res/values/strings.xml @@ -5,4 +5,5 @@ <string name="play_label">Jouer</string> <string name="textInfo"></string> <string name="version">0.1</string> +<string name="server_down">Il y a actuellement un probleme avec le serveur. Veuillez re-essayer dans quelque minutes.</string> </resources> diff --git a/code/PtiClic/src/org/pticlic/FrontPage.java b/code/PtiClic/src/org/pticlic/FrontPage.java @@ -1,6 +1,7 @@ package org.pticlic; import org.pticlic.games.BaseGame; +import org.pticlic.model.Constant; import org.pticlic.model.Network; import android.app.Activity; @@ -18,6 +19,8 @@ import android.widget.TextView; public class FrontPage extends Activity implements OnClickListener{ + private Uri uri = null; + /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { @@ -29,6 +32,9 @@ public class FrontPage extends Activity implements OnClickListener{ ((ImageView)findViewById(R.id.play)).setOnClickListener(this); ((ImageView)findViewById(R.id.infoButton)).setOnClickListener(this); + SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this); + String serverURL = sp.getString(Constant.SERVER_URL, Constant.SERVER); + Uri.parse(serverURL + "/signup.php"); } @Override @@ -74,7 +80,6 @@ public class FrontPage extends Activity implements OnClickListener{ public void onClick(DialogInterface dialog, int id) { dialog.dismiss(); // TODO : Essayer de trouver comment mettre l'url qui est dans les preferences. - Uri uri = Uri.parse("http://dumbs.fr/~bbrun/pticlic/signup.php"); startActivity(new Intent(Intent.ACTION_VIEW, uri)); } }) diff --git a/code/PtiClic/src/org/pticlic/Score.java b/code/PtiClic/src/org/pticlic/Score.java @@ -32,7 +32,7 @@ public class Score extends Activity implements OnClickListener{ setContentView(R.layout.score); SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this); - String serverURL = sp.getString(Constant.SERVER_URL, "http://dumbs.fr/~bbrun/pticlic/pticlic.php"); // TODO : Mettre comme valeur par defaut l'adresse reel du serveur + String serverURL = sp.getString(Constant.SERVER_URL, Constant.SERVER); String id = sp.getString(Constant.USER_ID, "joueur"); String passwd = sp.getString(Constant.USER_PASSWD, ""); Mode mode = null; @@ -64,6 +64,20 @@ public class Score extends Activity implements OnClickListener{ }); AlertDialog alert = builder.create(); alert.show(); + } catch (Exception e) { + AlertDialog.Builder builder = new AlertDialog.Builder(this); + builder.setTitle(getString(R.string.app_name)) + .setIcon(android.R.drawable.ic_dialog_alert) + .setMessage(R.string.server_down) + .setCancelable(false) + .setNegativeButton("Ok", new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + dialog.cancel(); + finish(); + } + }); + AlertDialog alert = builder.create(); + alert.show(); } ((Button)findViewById(R.id.saw)).setOnClickListener(this); diff --git a/code/PtiClic/src/org/pticlic/games/BaseGame.java b/code/PtiClic/src/org/pticlic/games/BaseGame.java @@ -102,6 +102,20 @@ public class BaseGame extends Activity implements OnClickListener { }); AlertDialog alert = builder.create(); alert.show(); + } catch (Exception e) { + AlertDialog.Builder builder = new AlertDialog.Builder(this); + builder.setTitle(getString(R.string.app_name)) + .setIcon(android.R.drawable.ic_dialog_alert) + .setMessage(getString(R.string.server_down)) + .setCancelable(false) + .setNegativeButton("Ok", new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int id) { + dialog.cancel(); + finish(); + } + }); + AlertDialog alert = builder.create(); + alert.show(); } } diff --git a/code/PtiClic/src/org/pticlic/model/Network.java b/code/PtiClic/src/org/pticlic/model/Network.java @@ -155,7 +155,7 @@ public class Network { * @param nbGames Le nombre de parties que l'on veut récupérer. * @return */ - public DownloadedGame getGames(int nbGames) throws PtiClicException { + public DownloadedGame getGames(int nbGames) throws PtiClicException, Exception { switch (mode) { case SIMPLE_GAME: return DownloadBaseGame(nbGames); @@ -164,7 +164,7 @@ public class Network { } } - private DownloadedBaseGame DownloadBaseGame(int nbGames) throws PtiClicException { + private DownloadedBaseGame DownloadBaseGame(int nbGames) throws PtiClicException, Exception { DownloadedBaseGame game = null; URL url = null; Gson gson = null; @@ -267,7 +267,7 @@ public class Network { * @param game La partie jouee par l'utilisateur * @return Le score sous forme JSON. */ - public double sendGame(Match game) throws PtiClicException { + public double sendGame(Match game) throws PtiClicException, Exception { switch (mode) { case SIMPLE_GAME: return sendBaseGame(game); @@ -277,7 +277,7 @@ public class Network { } - public double sendBaseGame(Match game) throws PtiClicException { + public double sendBaseGame(Match game) throws PtiClicException, Exception { double score = -1; URL url = null; Gson gson = null;