www

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

commit a8b0e92a083f3c9cdde811c8f75387f4fcf8045f
parent d07f85b9d3b77a32f70f419ff7d0390b28d4e515
Author: Georges Dupéron <jahvascriptmaniac+github@free.fr>
Date:   Wed, 16 Mar 2011 10:31:49 +0100

Avancement sur l'affichage des scores.

Diffstat:
Mcode/PtiClic/res/layout/score.xml | 18+++++++++++-------
Mcode/PtiClic/src/org/pticlic/BaseScore.java | 61++++++++++++++++++++++++++++++-------------------------------
Mcode/PtiClic/src/org/pticlic/model/Network.java | 11++++++-----
3 files changed, 47 insertions(+), 43 deletions(-)

diff --git a/code/PtiClic/res/layout/score.xml b/code/PtiClic/res/layout/score.xml @@ -3,17 +3,21 @@ <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="fill_parent" android:orientation="vertical" -android:id="@+id/LinearLayout01" android:layout_gravity="center" android:layout_width="150dip"> +android:id="@+id/LinearLayout01" android:layout_gravity="center" android:layout_width="fill_parent"> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/linearLayout2" android:orientation="vertical" android:layout_weight="2"> <TextView android:layout_width="fill_parent" android:id="@+id/textView1" android:layout_height="wrap_content" android:text="Votre score est de :" android:gravity="center" android:layout_weight="1"></TextView> <TextView android:layout_width="fill_parent" android:id="@+id/total" android:layout_height="wrap_content" android:text="@+id/total" android:textStyle="bold" android:textSize="25px" android:layout_weight="1" android:gravity="center|top"></TextView> - <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/scoreRel1" android:text="@+id/scoreRel1"></TextView> - <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/scoreRel2" android:text="@+id/scoreRel2"></TextView> - <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/scoreRel3" android:text="@+id/scoreRel3"></TextView> - <TextView android:layout_height="wrap_content" android:layout_width="wrap_content" android:id="@+id/scoreRel4" android:text="@+id/scoreRel4"></TextView> + <TextView android:layout_height="wrap_content" android:id="@+id/scoreRel1" android:text="@+id/scoreRel1" android:layout_width="fill_parent"></TextView> + <TextView android:layout_height="wrap_content" android:id="@+id/scoreWords1" android:layout_width="fill_parent" android:paddingLeft="40dip" android:text="@+id/scoreWords1"></TextView> + <TextView android:layout_height="wrap_content" android:id="@+id/scoreRel2" android:text="@+id/scoreRel2" android:layout_width="fill_parent"></TextView> + <TextView android:layout_height="wrap_content" android:id="@+id/scoreWords2" android:text="@+id/scoreWords2" android:layout_width="fill_parent" android:paddingLeft="40dip"></TextView> + <TextView android:layout_height="wrap_content" android:id="@+id/scoreRel3" android:text="@+id/scoreRel3" android:layout_width="fill_parent"></TextView> + <TextView android:layout_height="wrap_content" android:id="@+id/scoreWords3" android:text="@+id/scoreWords3" android:layout_width="fill_parent" android:paddingLeft="40dip"></TextView> + <TextView android:layout_height="wrap_content" android:id="@+id/scoreRel4" android:text="@+id/scoreRel4" android:layout_width="fill_parent"></TextView> + <TextView android:layout_height="wrap_content" android:id="@+id/scoreWords4" android:text="@+id/scoreWords4" android:layout_width="fill_parent" android:paddingLeft="40dip"></TextView> </LinearLayout> -<LinearLayout android:layout_width="fill_parent" android:id="@+id/linearLayout1" android:layout_weight="1" android:layout_height="wrap_content"> - <Button android:id="@+id/saw" android:text="J'ai vu !" android:layout_height="wrap_content" android:layout_width="fill_parent" android:layout_gravity="top"></Button> +<LinearLayout android:id="@+id/linearLayout1" android:layout_weight="1" android:layout_height="wrap_content" android:layout_width="fill_parent" android:gravity="center_horizontal" android:paddingTop="20dip"> + <Button android:id="@+id/saw" android:text="J'ai vu !" android:layout_height="wrap_content" android:layout_gravity="top" android:layout_width="150dip"></Button> </LinearLayout> diff --git a/code/PtiClic/src/org/pticlic/BaseScore.java b/code/PtiClic/src/org/pticlic/BaseScore.java @@ -1,12 +1,11 @@ package org.pticlic; -import java.text.DecimalFormat; - import org.pticlic.exception.PtiClicException; import org.pticlic.model.Constant; import org.pticlic.model.Match; import org.pticlic.model.Network; import org.pticlic.model.Network.Mode; +import org.pticlic.model.Network.ScoreResponse; import android.app.Activity; import android.app.AlertDialog; @@ -25,43 +24,29 @@ import android.widget.TextView; * Permet l'affichage du score obtenu par le joueur lors de sa partie. */ public class BaseScore extends Activity implements OnClickListener{ - - private Match gamePlayed; + + private Match gamePlayed; + private ScoreResponse sr = null; private void networkStuff() { + SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this); String id = sp.getString(Constant.USER_ID, "joueur"); String passwd = sp.getString(Constant.USER_PASSWD, ""); + String serverURL = sp.getString(Constant.SERVER_URL, Constant.SERVER); Mode mode = null; - + if (getIntent().getExtras() != null) { // GamePlayed contient toutes les infos sur la partie jouee this.gamePlayed = (Match) getIntent().getExtras().get(Constant.SCORE_GAMEPLAYED); mode = (Mode) getIntent().getExtras().get(Constant.SCORE_MODE); } - + // TODO : factoriser le serverUrl dans Network - SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this); - String serverURL = sp.getString(Constant.SERVER_URL, Constant.SERVER); + sp.edit().remove(Constant.NEW_BASE_GAME).commit(); Network network = new Network(serverURL, mode, id, passwd); try { - } - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.score); - - - // Permet de regler la precision : rajoute/enlever des # pour modifier la precision - DecimalFormat dfrmtr = new DecimalFormat("#.##"); - Double score = network.sendGame(gamePlayed); - ((TextView)findViewById(R.id.total)).setText(String.valueOf(dfrmtr.format(score))); - // TODO : Attention, le cast en (BaseGame) n'est pas sûr ! - ((TextView)findViewById(R.id.scoreRel1)).setText("Foo1"); - ((TextView)findViewById(R.id.scoreRel2)).setText("Foo2"); - ((TextView)findViewById(R.id.scoreRel3)).setText("Foo3"); - ((TextView)findViewById(R.id.scoreRel4)).setText("Foo4"); - sp.edit().putString(Constant.NEW_BASE_GAME, network.getNewGame()).commit(); + sr = network.sendBaseGame(gamePlayed); + sp.edit().putString(Constant.NEW_BASE_GAME, sr.getNewGame()).commit(); } catch (PtiClicException e) { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle(getString(R.string.app_name)) @@ -91,21 +76,35 @@ public class BaseScore extends Activity implements OnClickListener{ AlertDialog alert = builder.create(); alert.show(); } + } + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.score); + + this.networkStuff(); + + ((TextView)findViewById(R.id.total)).setText("42"); + // TODO : Attention, le cast en (BaseGame) n'est pas sûr ! + ((TextView)findViewById(R.id.scoreRel1)).setText("Foo1"); + ((TextView)findViewById(R.id.scoreRel2)).setText("Foo2"); + ((TextView)findViewById(R.id.scoreRel3)).setText("Foo3"); + ((TextView)findViewById(R.id.scoreRel4)).setText("Foo4"); ((Button)findViewById(R.id.saw)).setOnClickListener(this); - + } - + @Override public void onBackPressed() { super.onBackPressed(); - + finish(); } - + protected double calculateTotal(){ throw new UnsupportedOperationException(); - //return this.corrects - this.manquants - this.mauvais; } @Override diff --git a/code/PtiClic/src/org/pticlic/model/Network.java b/code/PtiClic/src/org/pticlic/model/Network.java @@ -283,7 +283,6 @@ public class Network { } public ScoreResponse sendBaseGame(Match game) throws PtiClicException, Exception { - double score = -1; Gson gson = null; String json = null; @@ -324,11 +323,13 @@ public class Network { // Comme gson ne renvoie pas une erreur si l'objet qui recupere ne correspond pas a la classe qu'il attends. // On creer tout d'abord une objet error et si celui-ci est vide on creer l'objet score, sinon on lance // une exception. - PtiClicException.Error error = gson.fromJson(json, PtiClicException.Error.class); - if (error.getMsg() == null) { - return gson.fromJson(json, ScoreResponse.class); + int foo = 42; + ScoreResponse sr = gson.fromJson(json, ScoreResponse.class); + foo = foo + 1; + if (sr.getNewGame() == null) { + throw new PtiClicException(gson.fromJson(json, PtiClicException.Error.class)); } else { - throw new PtiClicException(error); + return sr; } } }