Ajout de la gestion de l'erreur si le serveur plante. Et petit correction dans l'uri de FrontPage pour la page signup.php

This commit is contained in:
Bertrand BRUN 2011-02-24 12:51:27 +01:00
parent 1e85062722
commit 0ff04d20d4
5 changed files with 40 additions and 6 deletions

View File

@ -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>

View File

@ -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));
}
})

View File

@ -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);

View File

@ -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();
}
}

View File

@ -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;