Modification de l'application pour qu'elle puisse utiliser la version html du jeux
This commit is contained in:
parent
7b5b6950c0
commit
8155b58d5c
|
@ -1,24 +1,28 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="org.pticlic"
|
||||
android:versionCode="1" android:versionName="@string/version">
|
||||
<application android:icon="@drawable/icon" android:label="@string/app_name" android:theme="@android:style/Theme.NoTitleBar" android:debuggable="true">
|
||||
<activity android:name=".Main" android:screenOrientation="portrait">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
package="org.pticlic" android:versionCode="1" android:versionName="@string/version">
|
||||
<application android:icon="@drawable/icon" android:label="@string/app_name"
|
||||
android:theme="@android:style/Theme.NoTitleBar" android:debuggable="true">
|
||||
<activity android:name=".Main" android:screenOrientation="portrait">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<activity android:name=".Preference" android:label="Préférence" android:screenOrientation="portrait"></activity>
|
||||
<activity android:name=".games.BaseGame" android:screenOrientation="portrait"></activity>
|
||||
<activity android:label="Information" android:name=".Information" android:screenOrientation="portrait"></activity>
|
||||
<activity android:name="BaseScore" android:label="Score" android:screenOrientation="portrait"></activity>
|
||||
<activity android:name="FrontPage" android:screenOrientation="portrait"></activity>
|
||||
</application>
|
||||
<activity android:name=".Preference" android:label="Préférence"
|
||||
android:screenOrientation="portrait"></activity>
|
||||
|
||||
<activity android:label="Information" android:name=".Information"
|
||||
android:screenOrientation="portrait"></activity>
|
||||
|
||||
<activity android:name="FrontPage" android:screenOrientation="portrait">
|
||||
|
||||
</activity>
|
||||
</application>
|
||||
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
|
||||
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
|
||||
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>
|
||||
</manifest>
|
||||
|
|
|
@ -1,104 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent" android:orientation="vertical"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<LinearLayout android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent" android:orientation="vertical"
|
||||
android:layout_weight="2">
|
||||
|
||||
<LinearLayout android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content" android:orientation="horizontal" android:paddingTop="10dip">
|
||||
|
||||
<TextView android:id="@+id/wordRemaining" android:text="0/10"
|
||||
android:textStyle="bold" android:layout_height="wrap_content"
|
||||
android:layout_width="wrap_content" android:paddingRight="5dip" android:paddingTop="10dip" android:paddingLeft="13dip">
|
||||
</TextView>
|
||||
|
||||
<TextView android:id="@+id/mainWord" android:textStyle="bold" android:textSize="30dip"
|
||||
android:layout_weight="1" android:layout_width="fill_parent" android:paddingBottom="10dip" android:layout_height="90dip" android:gravity="top|center_vertical|center_horizontal" android:text="Un truc super long">
|
||||
</TextView>
|
||||
|
||||
<ImageView android:src="@drawable/aide" android:id="@+id/aideBaseGame"
|
||||
android:paddingRight="10px" android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"></ImageView>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<TextView android:id="@+id/currentWord" android:layout_width="fill_parent"
|
||||
android:text="currentWord" android:textStyle="bold" android:textSize="20dip"
|
||||
android:layout_height="fill_parent" android:gravity="top|center">
|
||||
</TextView>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout android:layout_height="fill_parent"
|
||||
android:layout_width="fill_parent" android:orientation="horizontal" android:id="@+id/menuLayout" android:layout_weight="8">
|
||||
|
||||
<LinearLayout android:layout_height="wrap_content"
|
||||
android:layout_width="fill_parent" android:orientation="horizontal"
|
||||
android:id="@+id/relation1Layout" android:layout_weight="1"
|
||||
android:layout_gravity="center" android:clickable="true">
|
||||
<ImageView android:id="@+id/relation1" android:src="@drawable/contenant"
|
||||
android:layout_weight="1" android:layout_height="wrap_content"
|
||||
android:layout_width="wrap_content" android:layout_marginLeft="10dip">
|
||||
</ImageView>
|
||||
<TextView android:id="@+id/relation1Name"
|
||||
android:text="contenant"
|
||||
android:textStyle="bold" android:textSize="15dip"
|
||||
android:layout_height="wrap_content" android:layout_weight="3"
|
||||
android:layout_gravity="center_vertical" android:visibility="gone" android:layout_width="fill_parent" android:gravity="center">
|
||||
</TextView>
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout android:layout_height="wrap_content"
|
||||
android:layout_width="fill_parent" android:orientation="horizontal"
|
||||
android:id="@+id/relation2Layout" android:layout_weight="1"
|
||||
android:layout_gravity="center" android:clickable="true">
|
||||
<ImageView android:id="@+id/relation2" android:src="@drawable/contenu"
|
||||
android:layout_weight="1" android:layout_height="wrap_content"
|
||||
android:layout_width="wrap_content" android:layout_marginLeft="10dip">
|
||||
</ImageView>
|
||||
<TextView android:id="@+id/relation2Name"
|
||||
android:text="contenu"
|
||||
android:textStyle="bold" android:textSize="15dip"
|
||||
android:layout_height="wrap_content" android:layout_weight="3"
|
||||
android:layout_gravity="center_vertical" android:visibility="gone" android:layout_width="fill_parent" android:gravity="center">
|
||||
</TextView>
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout android:layout_height="wrap_content"
|
||||
android:layout_width="fill_parent" android:orientation="horizontal"
|
||||
android:id="@+id/relation3Layout" android:layout_weight="1"
|
||||
android:layout_gravity="center" android:clickable="true">
|
||||
<ImageView android:id="@+id/relation3" android:src="@drawable/contraire"
|
||||
android:layout_weight="1" android:layout_height="wrap_content"
|
||||
android:layout_width="wrap_content" android:layout_marginLeft="10dip">
|
||||
</ImageView>
|
||||
<TextView android:id="@+id/relation3Name"
|
||||
android:text="contraire"
|
||||
android:textStyle="bold" android:textSize="15dip"
|
||||
android:layout_height="wrap_content" android:layout_weight="3"
|
||||
android:layout_gravity="center_vertical" android:visibility="gone" android:layout_width="fill_parent" android:gravity="center">
|
||||
</TextView>
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout android:layout_height="wrap_content"
|
||||
android:layout_width="fill_parent" android:orientation="horizontal"
|
||||
android:id="@+id/relation4Layout" android:layout_weight="1"
|
||||
android:layout_gravity="center" android:clickable="true">
|
||||
<ImageView android:id="@+id/relation4" android:src="@drawable/synonyme"
|
||||
android:layout_weight="1" android:layout_height="wrap_content"
|
||||
android:layout_width="wrap_content" android:layout_gravity="center" android:layout_marginLeft="10dip">
|
||||
</ImageView>
|
||||
<TextView android:id="@+id/relation4Name"
|
||||
android:text="synonyme"
|
||||
android:textStyle="bold" android:textSize="15dip"
|
||||
android:layout_height="wrap_content" android:layout_weight="3"
|
||||
android:layout_gravity="center_vertical" android:visibility="gone" android:layout_width="fill_parent" android:gravity="center">
|
||||
</TextView>
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
|
@ -1,41 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="fill_parent" android:layout_height="fill_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView android:text="@string/app_name" android:id="@+id/logo"
|
||||
android:layout_width="fill_parent" android:layout_height="wrap_content"
|
||||
android:textSize="50px" android:layout_weight="1" />
|
||||
|
||||
<RelativeLayout android:layout_height="wrap_content"
|
||||
android:id="@+id/RelativeLayout01" android:layout_width="wrap_content"
|
||||
android:layout_gravity="bottom|center_horizontal">
|
||||
|
||||
<ImageView android:layout_height="wrap_content"
|
||||
android:text="@string/play_label" android:layout_width="wrap_content"
|
||||
android:id="@+id/play" android:clickable="true" android:padding="30dip"
|
||||
android:src="@drawable/mode_normal"/>
|
||||
|
||||
<ImageView android:src="@drawable/config"
|
||||
android:layout_height="wrap_content" android:id="@+id/prefs"
|
||||
android:layout_width="wrap_content" android:layout_below="@+id/play"
|
||||
android:layout_alignLeft="@+id/play" android:layout_alignRight="@+id/play"
|
||||
android:padding="30dip"></ImageView>
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
<LinearLayout android:id="@+id/LinearLayout01"
|
||||
android:layout_height="wrap_content" android:layout_width="fill_parent"
|
||||
android:orientation="vertical" android:layout_weight="1">
|
||||
|
||||
<TextView android:layout_height="wrap_content"
|
||||
android:layout_width="fill_parent" android:textStyle="bold"
|
||||
android:gravity="center_horizontal" android:text="@+id/login"
|
||||
android:id="@+id/login"></TextView>
|
||||
<ImageView android:layout_height="wrap_content" android:id="@+id/infoButton"
|
||||
android:layout_width="wrap_content" android:layout_gravity="right"
|
||||
android:layout_weight="5" android:clickable="true" android:src="@drawable/aide" android:paddingRight="10px"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/webview"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
/>
|
|
@ -1,76 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
|
||||
<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="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="@string/score_your_score"
|
||||
android:gravity="center|bottom" android:layout_weight="1" android:textSize="25dip"
|
||||
android:textStyle="bold"></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="25dip"
|
||||
android:layout_weight="1" android:gravity="center|top"></TextView>
|
||||
|
||||
<TextView android:layout_width="fill_parent" android:id="@+id/textView1"
|
||||
android:layout_height="wrap_content" android:text="@string/score_your_answers"
|
||||
android:gravity="center|bottom" android:layout_weight="0.1"
|
||||
android:textSize="25dip" android:textStyle="bold"></TextView>
|
||||
|
||||
<TextView android:layout_width="fill_parent" android:id="@+id/textView1"
|
||||
android:layout_height="wrap_content" android:text="@string/score_explanation"
|
||||
android:gravity="center|top" android:layout_weight="1"
|
||||
android:textSize="15dip"></TextView>
|
||||
|
||||
<TextView android:layout_height="wrap_content" android:id="@+id/scoreRel1"
|
||||
android:text="@+id/scoreRel1" android:layout_width="fill_parent"
|
||||
android:textStyle="bold" android:paddingLeft="10dip"></TextView>
|
||||
|
||||
<TextView android:layout_height="wrap_content" android:id="@+id/scoreWords1"
|
||||
android:layout_width="fill_parent" android:paddingLeft="30dip"
|
||||
android:text="@+id/scoreWords1" android:paddingBottom="5dip"></TextView>
|
||||
|
||||
<TextView android:layout_height="wrap_content" android:id="@+id/scoreRel2"
|
||||
android:text="@+id/scoreRel2" android:layout_width="fill_parent"
|
||||
android:textStyle="bold" android:paddingLeft="10dip"></TextView>
|
||||
|
||||
<TextView android:layout_height="wrap_content" android:id="@+id/scoreWords2"
|
||||
android:text="@+id/scoreWords2" android:layout_width="fill_parent"
|
||||
android:paddingLeft="30dip" android:paddingBottom="5dip"></TextView>
|
||||
|
||||
<TextView android:layout_height="wrap_content" android:id="@+id/scoreRel3"
|
||||
android:text="@+id/scoreRel3" android:layout_width="fill_parent"
|
||||
android:textStyle="bold" android:paddingLeft="10dip"></TextView>
|
||||
|
||||
<TextView android:layout_height="wrap_content" android:id="@+id/scoreWords3"
|
||||
android:text="@+id/scoreWords3" android:layout_width="fill_parent"
|
||||
android:paddingLeft="30dip" android:paddingBottom="5dip"></TextView>
|
||||
|
||||
<TextView android:layout_height="wrap_content" android:id="@+id/scoreRel4"
|
||||
android:text="@+id/scoreRel4" android:layout_width="fill_parent"
|
||||
android:textStyle="bold" android:paddingLeft="10dip"></TextView>
|
||||
|
||||
<TextView android:layout_height="wrap_content" android:id="@+id/scoreWords4"
|
||||
android:text="@+id/scoreWords4" android:layout_width="fill_parent"
|
||||
android:paddingLeft="30dip" android:paddingBottom="5dip"></TextView>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<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>
|
||||
|
||||
|
||||
</LinearLayout>
|
|
@ -1,149 +0,0 @@
|
|||
package org.pticlic;
|
||||
|
||||
import org.pticlic.R.string;
|
||||
import org.pticlic.exception.PtiClicException;
|
||||
import org.pticlic.model.Constant;
|
||||
import org.pticlic.model.DownloadedBaseGame;
|
||||
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;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
|
||||
/**
|
||||
* @author John CHARRON
|
||||
*
|
||||
* Permet l'affichage du score obtenu par le joueur lors de sa partie.
|
||||
*/
|
||||
public class BaseScore extends Activity implements OnClickListener{
|
||||
|
||||
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
|
||||
sp.edit().remove(Constant.NEW_BASE_GAME).commit();
|
||||
Network network = new Network(serverURL, mode, id, passwd);
|
||||
try {
|
||||
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))
|
||||
.setIcon(android.R.drawable.ic_dialog_alert)
|
||||
.setMessage(e.getMessage())
|
||||
.setCancelable(false)
|
||||
.setNegativeButton("Ok", new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
dialog.cancel();
|
||||
finish();
|
||||
}
|
||||
});
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.score);
|
||||
|
||||
this.networkStuff();
|
||||
this.networkStuff();
|
||||
|
||||
// TODO : Attention, le cast en (BaseGame) n'est pas sûr !
|
||||
DownloadedBaseGame bg = (DownloadedBaseGame)gamePlayed.getGame();
|
||||
((TextView)findViewById(R.id.total)).setText(String.valueOf(sr.getScoreTotal()));
|
||||
((TextView)findViewById(R.id.scoreRel1)).setText(bg.getCatString(1));
|
||||
((TextView)findViewById(R.id.scoreRel2)).setText(bg.getCatString(2));
|
||||
((TextView)findViewById(R.id.scoreRel3)).setText(bg.getCatString(3));
|
||||
((TextView)findViewById(R.id.scoreRel4)).setText(bg.getCatString(4));
|
||||
|
||||
String res;
|
||||
String noAnswers = getString(string.score_no_answers);
|
||||
res = "";
|
||||
for (int i : gamePlayed.getRelation1()) {
|
||||
res += bg.getWordInCloud(i).getName();
|
||||
res += " (" + String.valueOf(sr.getScoreOfWord(i)) + "), ";
|
||||
}
|
||||
((TextView)findViewById(R.id.scoreWords1)).setText(res.length() < 1 ? noAnswers : res);
|
||||
|
||||
res = "";
|
||||
for (int i : gamePlayed.getRelation2()) {
|
||||
res += bg.getWordInCloud(i).getName();
|
||||
res += " (" + String.valueOf(sr.getScoreOfWord(i)) + "), ";
|
||||
}
|
||||
((TextView)findViewById(R.id.scoreWords2)).setText(res.length() < 1 ? noAnswers : res);
|
||||
|
||||
res = "";
|
||||
for (int i : gamePlayed.getRelation3()) {
|
||||
res += bg.getWordInCloud(i).getName();
|
||||
res += " (" + String.valueOf(sr.getScoreOfWord(i)) + "), ";
|
||||
}
|
||||
((TextView)findViewById(R.id.scoreWords3)).setText(res.length() < 1 ? noAnswers : res);
|
||||
|
||||
res = "";
|
||||
for (int i : gamePlayed.getRelation4()) {
|
||||
res += bg.getWordInCloud(i).getName();
|
||||
res += " (" + String.valueOf(sr.getScoreOfWord(i)) + "), ";
|
||||
}
|
||||
((TextView)findViewById(R.id.scoreWords4)).setText(res.length() < 1 ? noAnswers : res);
|
||||
|
||||
((Button)findViewById(R.id.saw)).setOnClickListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
super.onBackPressed();
|
||||
|
||||
finish();
|
||||
}
|
||||
|
||||
protected double calculateTotal(){
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (v.getId()==R.id.saw) {
|
||||
finish();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,25 +1,15 @@
|
|||
package org.pticlic;
|
||||
|
||||
import org.pticlic.games.BaseGame;
|
||||
import org.pticlic.model.Constant;
|
||||
import org.pticlic.model.Network;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import android.webkit.WebSettings;
|
||||
import android.webkit.WebView;
|
||||
|
||||
public class FrontPage extends Activity implements OnClickListener{
|
||||
public class FrontPage extends Activity {
|
||||
|
||||
private Uri uri = null;
|
||||
private WebView webView;
|
||||
|
||||
/** Called when the activity is first created. */
|
||||
@Override
|
||||
|
@ -27,83 +17,11 @@ public class FrontPage extends Activity implements OnClickListener{
|
|||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.frontpage);
|
||||
|
||||
// Écoute des clics sur les différents boutons
|
||||
((ImageView)findViewById(R.id.prefs)).setOnClickListener(this);
|
||||
((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
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
|
||||
// On récupère le nom du joueur des préférences.
|
||||
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
Boolean connected = sp.getBoolean(Constant.SERVER_AUTH, false);
|
||||
if (connected) {
|
||||
((TextView)findViewById(R.id.login)).setText(R.string.frontpage_user_connected);
|
||||
} else {
|
||||
((TextView)findViewById(R.id.login)).setText(R.string.frontpage_user_notconnected);
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see android.view.View.OnClickListener#onClick(android.view.View)
|
||||
*/
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
switch (v.getId()) {
|
||||
case (R.id.prefs) : startActivity(new Intent(this, Preference.class)); break;
|
||||
case (R.id.play) : checkAllIsOk(BaseGame.class); break;
|
||||
case (R.id.infoButton) : startActivity(new Intent(this, Information.class)); break;
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
private void checkAllIsOk(Class c) {
|
||||
if (Network.isConnected(this)) {
|
||||
if (Network.isLoginCorrect(this)) {
|
||||
startActivity(new Intent(this, c));
|
||||
} else {
|
||||
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.frontpage_bad_loginmdp))
|
||||
.setCancelable(false)
|
||||
.setNeutralButton(getString(R.string.frontpage_inscription_button), new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
dialog.dismiss();
|
||||
// TODO : Essayer de trouver comment mettre l'url qui est dans les preferences.
|
||||
startActivity(new Intent(Intent.ACTION_VIEW, uri));
|
||||
}
|
||||
})
|
||||
.setPositiveButton(getString(R.string.frontpage_preference_button), new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
dialog.dismiss();
|
||||
startActivity(new Intent(getApplicationContext(), Preference.class));
|
||||
}
|
||||
});
|
||||
AlertDialog alert = builder.create();
|
||||
alert.show();
|
||||
}
|
||||
} else {
|
||||
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.frontpage_no_connection))
|
||||
.setCancelable(false)
|
||||
.setNegativeButton("Ok", new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
dialog.cancel();
|
||||
}
|
||||
});
|
||||
AlertDialog alert = builder.create();
|
||||
alert.show();
|
||||
}
|
||||
webView = (WebView) findViewById(R.id.webview);
|
||||
WebSettings webSettings = webView.getSettings();
|
||||
webSettings.setJavaScriptEnabled(true);
|
||||
|
||||
webView.loadUrl(Constant.SERVER + Constant.SERVER_URL);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -40,7 +40,7 @@ public class Information extends Activity {
|
|||
}
|
||||
|
||||
in.close();
|
||||
webview.loadUrl("http://www.pticlic.fr/html5/code/html5/");
|
||||
webview.loadData(html, "text/html", "UTF-8");
|
||||
|
||||
} catch (IOException e) {
|
||||
//TODO : Ajouter un boite de dialog indiquant qu'une erreur est arrivee.
|
||||
|
|
|
@ -1,433 +0,0 @@
|
|||
package org.pticlic.games;
|
||||
|
||||
import org.pticlic.R;
|
||||
import org.pticlic.BaseScore;
|
||||
import org.pticlic.exception.PtiClicException;
|
||||
import org.pticlic.model.Constant;
|
||||
import org.pticlic.model.DownloadedBaseGame;
|
||||
import org.pticlic.model.Match;
|
||||
import org.pticlic.model.Network;
|
||||
import org.pticlic.model.Network.Mode;
|
||||
import org.pticlic.model.Relation;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.view.Display;
|
||||
import android.view.Gravity;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.animation.AlphaAnimation;
|
||||
import android.view.animation.AnimationSet;
|
||||
import android.view.animation.TranslateAnimation;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.LinearLayout.LayoutParams;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
|
||||
/**
|
||||
* @author Bertrand BRUN et Georges DUPÉRON
|
||||
*
|
||||
* Cette classe est le controlleur du premier jeu.
|
||||
*
|
||||
* Ce premier jeu appeler "Jeux de Base", permet de creer des relations en selectionnant
|
||||
* le type de relation d'un mot du nuage de mot par rapport au mot central.
|
||||
*
|
||||
* La vue de ce jeu se presente sous la forme d'un fenetre presentant en haut le mot central,
|
||||
* et les mots du nuage descende en partant du mot central vers le centre du mobile.
|
||||
* Une fois le mot du nuage afficher, l'utilisateur peut selectionner, parmis les relations
|
||||
* proposer celle qui lui semble le mieux approprier.
|
||||
*
|
||||
*/
|
||||
|
||||
public class BaseGame extends Activity implements OnClickListener {
|
||||
private int currentWord = 0;
|
||||
private TextView currentWordTextView;
|
||||
private TextView wordRemaining;
|
||||
private int nbWord = 0;
|
||||
private DownloadedBaseGame game;
|
||||
private Match match;
|
||||
private Network network;
|
||||
private boolean help = false;
|
||||
private String gameJson;
|
||||
|
||||
/** Called when the activity is first created. */
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.basegame);
|
||||
|
||||
// On recupere du PreferenceManager les differentes information dont on a besoin
|
||||
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
String serverURL = sp.getString(Constant.SERVER_URL, Constant.SERVER);
|
||||
String id = sp.getString(Constant.USER_ID, "joueur");
|
||||
String passwd = sp.getString(Constant.USER_PASSWD, "");
|
||||
gameJson = sp.getString(Constant.NEW_BASE_GAME, null);
|
||||
|
||||
// On initialise la classe permettant la communication avec le serveur.
|
||||
network = new Network(serverURL, Mode.SIMPLE_GAME, id, passwd);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see android.app.Activity#onStart()
|
||||
*/
|
||||
@Override
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
try {
|
||||
Gson gson = new Gson();
|
||||
if (gameJson == null) game = (DownloadedBaseGame)network.getGames(1);
|
||||
else game = gson.fromJson(gameJson, DownloadedBaseGame.class);
|
||||
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
Boolean first = sp.getBoolean(Constant.FIRST_TIME, true);
|
||||
if (first) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setTitle(getString(R.string.basegame_title))
|
||||
.setIcon(android.R.drawable.ic_dialog_info)
|
||||
.setMessage(getString(R.string.basegame_explication))
|
||||
.setCancelable(false)
|
||||
.setNegativeButton("Fermez", new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
dialog.cancel();
|
||||
runMatch();
|
||||
start();
|
||||
}
|
||||
})
|
||||
.setPositiveButton("Ne plus afficher", new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
|
||||
sp.edit().putBoolean(Constant.FIRST_TIME, false).commit();
|
||||
dialog.cancel();
|
||||
runMatch();
|
||||
start();
|
||||
}
|
||||
});
|
||||
AlertDialog alert = builder.create();
|
||||
alert.show();
|
||||
} else {
|
||||
runMatch();
|
||||
start();
|
||||
}
|
||||
} catch (PtiClicException e) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setTitle(getString(R.string.app_name))
|
||||
.setIcon(android.R.drawable.ic_dialog_alert)
|
||||
.setMessage(e.getMessage())
|
||||
.setCancelable(false)
|
||||
.setNegativeButton("Ok", new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int id) {
|
||||
dialog.cancel();
|
||||
finish();
|
||||
}
|
||||
});
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void runMatch() {
|
||||
nbWord = game.getNbWord();
|
||||
|
||||
wordRemaining = (TextView)findViewById(R.id.wordRemaining);
|
||||
wordRemaining.setText((currentWord + 1) + "/" + nbWord);
|
||||
|
||||
// On initialise la partie.
|
||||
match = new Match();
|
||||
match.setGame(game);
|
||||
|
||||
// Boutons des relations
|
||||
ImageView r1 = ((ImageView)findViewById(R.id.relation1));
|
||||
ImageView r2 = ((ImageView)findViewById(R.id.relation2));
|
||||
ImageView r3 = ((ImageView)findViewById(R.id.relation3));
|
||||
ImageView r4 = ((ImageView)findViewById(R.id.relation4));
|
||||
|
||||
|
||||
// TextView des relations
|
||||
TextView rn1 = ((TextView)findViewById(R.id.relation1Name));
|
||||
TextView rn2 = ((TextView)findViewById(R.id.relation2Name));
|
||||
TextView rn3 = ((TextView)findViewById(R.id.relation3Name));
|
||||
TextView rn4 = ((TextView)findViewById(R.id.relation4Name));
|
||||
|
||||
// Bouton d'aide
|
||||
ImageView aide = ((ImageView)findViewById(R.id.aideBaseGame));
|
||||
aide.setOnClickListener(this);
|
||||
|
||||
// On met set le nom du mot central
|
||||
((TextView)findViewById(R.id.mainWord)).setText(DownloadedBaseGame.getName(game.getCentre()));
|
||||
|
||||
Relation r = Relation.getInstance();
|
||||
|
||||
// Écoute des clics sur les relations
|
||||
// TODO : A enlever lorsque l'on aura toutes les images des relations.
|
||||
try {
|
||||
r1.setOnClickListener(this);
|
||||
rn1.setText(String.format(r.getRelationName(game.getCat1()), ((TextView)findViewById(R.id.mainWord)).getText()));
|
||||
r1.setImageResource(r.getRelationImage(game.getCat1()));
|
||||
} catch (Exception e) {
|
||||
r1.setImageResource(R.drawable.icon);
|
||||
}
|
||||
// TODO : A enlever lorsque l'on aura toutes les images des relations.
|
||||
try {
|
||||
r2.setOnClickListener(this);
|
||||
rn2.setText(String.format(r.getRelationName(game.getCat2()), ((TextView)findViewById(R.id.mainWord)).getText()));
|
||||
r2.setImageResource(r.getRelationImage(game.getCat2()));
|
||||
} catch (Exception e) {
|
||||
r2.setImageResource(R.drawable.icon);
|
||||
}
|
||||
// TODO : A enlever lorsque l'on aura toutes les images des relations.
|
||||
try {
|
||||
r3.setOnClickListener(this);
|
||||
rn3.setText(String.format(r.getRelationName(game.getCat3()), ((TextView)findViewById(R.id.mainWord)).getText()));
|
||||
r3.setImageResource(r.getRelationImage(game.getCat3()));
|
||||
} catch (Exception e) {
|
||||
r3.setImageResource(R.drawable.icon);
|
||||
}
|
||||
// TODO : A enlever lorsque l'on aura toutes les images des relations.
|
||||
try {
|
||||
r4.setOnClickListener(this);
|
||||
rn4.setText(String.format(r.getRelationName(game.getCat4()), ((TextView)findViewById(R.id.mainWord)).getText()));
|
||||
r4.setImageResource(r.getRelationImage(game.getCat4()));
|
||||
} catch (Exception e) {
|
||||
r4.setImageResource(R.drawable.icon);
|
||||
}
|
||||
|
||||
this.helpMode();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see android.app.Activity#onActivityResult(int, int, android.content.Intent)
|
||||
*/
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
finish();
|
||||
}
|
||||
|
||||
/**
|
||||
* Cette methode permet au mot courant de partir du mot central vers le centre de l'appareil.
|
||||
*/
|
||||
private void arrivalView() {
|
||||
//On recupere la largueur de l'ecran.
|
||||
Display display = getWindowManager().getDefaultDisplay();
|
||||
int width = display.getWidth();
|
||||
|
||||
// On recupere le centre de mainWord pour l'animation de translation.
|
||||
TextView mainWord = (TextView)findViewById(R.id.mainWord);
|
||||
currentWordTextView = (TextView)findViewById(R.id.currentWord);
|
||||
|
||||
// On defini un ensemble d'animation
|
||||
AnimationSet set = new AnimationSet(true);
|
||||
set.setDuration(1000);
|
||||
set.setFillAfter(true);
|
||||
|
||||
TranslateAnimation translate;
|
||||
if (isInHelpMode())
|
||||
translate = new TranslateAnimation(mainWord.getScrollX() / 2, mainWord.getScrollX() / 2, mainWord.getScrollY() / 2, width / 8);
|
||||
else
|
||||
translate = new TranslateAnimation(mainWord.getScrollX() / 2, mainWord.getScrollX() / 2, mainWord.getScrollY() / 2, width / 4);
|
||||
translate.setDuration(500);
|
||||
set.addAnimation(translate);
|
||||
|
||||
AlphaAnimation alpha = new AlphaAnimation(0, 1);
|
||||
alpha.setDuration(1000);
|
||||
set.addAnimation(alpha);
|
||||
|
||||
// Que l'on rajoute a notre vue.
|
||||
currentWordTextView.startAnimation(set);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private void leaveView() {
|
||||
currentWordTextView.clearAnimation();
|
||||
}
|
||||
|
||||
/**
|
||||
* Cette methode permet de passer au mot courant suivant et de lancer l'animation.
|
||||
*/
|
||||
private void start() {
|
||||
((TextView)findViewById(R.id.currentWord)).setText(DownloadedBaseGame.getName(game.getWordInCloud(currentWord)));
|
||||
arrivalView();
|
||||
}
|
||||
|
||||
/**
|
||||
* Permet de verifier si la partie est fini auquel cas on lance l'activite Score, sinon on passe au mot suivant.
|
||||
*/
|
||||
private void next() {
|
||||
if (++currentWord < nbWord) {
|
||||
wordRemaining.setText((currentWord + 1) + "/" + nbWord);
|
||||
leaveView();
|
||||
start();
|
||||
} else {
|
||||
Intent intent = new Intent(this, BaseScore.class);
|
||||
intent.putExtra(Constant.SCORE_GAMEPLAYED, match);
|
||||
intent.putExtra(Constant.SCORE_MODE, Mode.SIMPLE_GAME);
|
||||
|
||||
startActivityForResult(intent, 0x100);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Cette methode est appeler lorsque l'utilisateur appuie sur le bouton d'aide.
|
||||
* Elle change la disposition des elements de maniere a afficher la description
|
||||
* de l'icone a cote de l'icone.
|
||||
*/
|
||||
private void helpMode() {
|
||||
if (!isInHelpMode()) {
|
||||
help = true;
|
||||
|
||||
LayoutParams layoutParams = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT, 2);
|
||||
|
||||
// On modifie l'affichage du layout
|
||||
LinearLayout menuLayout = ((LinearLayout)findViewById(R.id.menuLayout));
|
||||
menuLayout.setOrientation(LinearLayout.VERTICAL);
|
||||
menuLayout.setLayoutParams(layoutParams);
|
||||
|
||||
// Puis on modifie l'affichage des relations
|
||||
//relation1
|
||||
LinearLayout relationLayout = ((LinearLayout)findViewById(R.id.relation1Layout));
|
||||
relationLayout.setGravity(Gravity.LEFT);
|
||||
|
||||
TextView relationName = ((TextView)findViewById(R.id.relation1Name));
|
||||
relationName.setVisibility(View.VISIBLE);
|
||||
|
||||
//relation2
|
||||
relationLayout = ((LinearLayout)findViewById(R.id.relation2Layout));
|
||||
relationLayout.setGravity(Gravity.LEFT);
|
||||
|
||||
relationName = ((TextView)findViewById(R.id.relation2Name));
|
||||
relationName.setVisibility(View.VISIBLE);
|
||||
|
||||
//relation3
|
||||
relationLayout = ((LinearLayout)findViewById(R.id.relation3Layout));
|
||||
relationLayout.setGravity(Gravity.LEFT);
|
||||
|
||||
relationName = ((TextView)findViewById(R.id.relation3Name));
|
||||
relationName.setVisibility(View.VISIBLE);
|
||||
|
||||
//relation4
|
||||
relationLayout = ((LinearLayout)findViewById(R.id.relation4Layout));
|
||||
relationLayout.setGravity(Gravity.LEFT);
|
||||
|
||||
relationName = ((TextView)findViewById(R.id.relation4Name));
|
||||
relationName.setVisibility(View.VISIBLE);
|
||||
|
||||
|
||||
// On met le mot courant au bon endroit dans la fenetre
|
||||
// On recupere la largueur de l'ecran.
|
||||
Display display = getWindowManager().getDefaultDisplay();
|
||||
int width = display.getWidth();
|
||||
|
||||
//On recupere le centre de mainWord pour l'animation de translation.
|
||||
TextView mainWord = (TextView)findViewById(R.id.mainWord);
|
||||
currentWordTextView = (TextView)findViewById(R.id.currentWord);
|
||||
|
||||
TranslateAnimation translate = new TranslateAnimation(mainWord.getScrollX() / 2, mainWord.getScrollX() / 2, mainWord.getScrollY() / 2, width / 8);
|
||||
translate.setDuration(0);
|
||||
translate.setFillAfter(true);
|
||||
|
||||
currentWordTextView.setAnimation(translate);
|
||||
|
||||
} else {
|
||||
help = false;
|
||||
|
||||
LayoutParams layoutParams = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT, 10);
|
||||
|
||||
// On modifie l'affichage du layout
|
||||
LinearLayout menuLayout = ((LinearLayout)findViewById(R.id.menuLayout));
|
||||
menuLayout.setOrientation(LinearLayout.HORIZONTAL);
|
||||
menuLayout.setLayoutParams(layoutParams);
|
||||
|
||||
// Puis on modifie l'affichage des relations
|
||||
//relation1
|
||||
LinearLayout relationLayout = ((LinearLayout)findViewById(R.id.relation1Layout));
|
||||
relationLayout.setGravity(Gravity.CENTER);
|
||||
|
||||
TextView relationName = ((TextView)findViewById(R.id.relation1Name));
|
||||
relationName.setVisibility(View.GONE);
|
||||
|
||||
//relation2
|
||||
relationLayout = ((LinearLayout)findViewById(R.id.relation2Layout));
|
||||
relationLayout.setGravity(Gravity.CENTER);
|
||||
|
||||
relationName = ((TextView)findViewById(R.id.relation2Name));
|
||||
relationName.setVisibility(View.GONE);
|
||||
|
||||
//relation3
|
||||
relationLayout = ((LinearLayout)findViewById(R.id.relation3Layout));
|
||||
relationLayout.setGravity(Gravity.CENTER);
|
||||
|
||||
relationName = ((TextView)findViewById(R.id.relation3Name));
|
||||
relationName.setVisibility(View.GONE);
|
||||
|
||||
//relation4
|
||||
relationLayout = ((LinearLayout)findViewById(R.id.relation4Layout));
|
||||
relationLayout.setGravity(Gravity.CENTER);
|
||||
|
||||
relationName = ((TextView)findViewById(R.id.relation4Name));
|
||||
relationName.setVisibility(View.GONE);
|
||||
|
||||
// On met le mot courant au bon endroit dans la fenetre
|
||||
// On recupere la largueur de l'ecran.
|
||||
Display display = getWindowManager().getDefaultDisplay();
|
||||
int width = display.getWidth();
|
||||
|
||||
//On recupere le centre de mainWord pour l'animation de translation.
|
||||
TextView mainWord = (TextView)findViewById(R.id.mainWord);
|
||||
currentWordTextView = (TextView)findViewById(R.id.currentWord);
|
||||
|
||||
TranslateAnimation translate = new TranslateAnimation(mainWord.getScrollX() / 2, mainWord.getScrollX() / 2, mainWord.getScrollY() / 2, width / 4);
|
||||
translate.setDuration(0);
|
||||
translate.setFillAfter(true);
|
||||
|
||||
currentWordTextView.setAnimation(translate);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Permet de savoir si l'on se trouve ou non dans le mode d'aide
|
||||
*
|
||||
* @return <code>true</code> si l'on ce trouve dans le mode d'aide <code>false</code> sinon
|
||||
*/
|
||||
private boolean isInHelpMode() {
|
||||
return help;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see android.view.View.OnClickListener#onClick(android.view.View)
|
||||
*/
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
switch (v.getId()) {
|
||||
case (R.id.relation1) : match.add(1, currentWord); next(); break;
|
||||
case (R.id.relation2) : match.add(2, currentWord); next(); break;
|
||||
case (R.id.relation3) : match.add(3, currentWord); next(); break;
|
||||
case (R.id.relation4) : match.add(4, currentWord); next(); break;
|
||||
case (R.id.aideBaseGame) : helpMode(); break;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
package org.pticlic.model;
|
||||
|
||||
public class Constant {
|
||||
public static final String SERVER_URL = "server";
|
||||
public static final String SERVER_URL = "html5/code/html5/";
|
||||
public static final String SERVER_AUTH = "SERVER_AUTH";
|
||||
public static final String SERVER = "http://www.pticlic.fr/";
|
||||
|
||||
|
|
|
@ -1,144 +0,0 @@
|
|||
package org.pticlic.model;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* @author Bertrand BRUN
|
||||
*
|
||||
* Classe metier reprensentant une parti "Normal" telecharge.
|
||||
*/
|
||||
public class DownloadedBaseGame extends DownloadedGame {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public static class Word implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private int id;
|
||||
private String name;
|
||||
|
||||
public Word() {}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
|
||||
private int cat1;
|
||||
private int cat2;
|
||||
private int cat3;
|
||||
private int cat4;
|
||||
private Word center;
|
||||
private Word[] cloud;
|
||||
|
||||
public DownloadedBaseGame() {
|
||||
super();
|
||||
this.cat1 = -1;
|
||||
this.cat2 = -1;
|
||||
this.cat3 = -1;
|
||||
this.cat4 = -1;
|
||||
this.center = null;
|
||||
this.cloud = null;
|
||||
}
|
||||
|
||||
public DownloadedBaseGame(int id, int gid, int pgid, int cat1, int cat2,
|
||||
int cat3, int cat4, Word center, Word[] cloud) {
|
||||
super(id, gid, pgid);
|
||||
this.cat1 = cat1;
|
||||
this.cat2 = cat2;
|
||||
this.cat3 = cat3;
|
||||
this.cat4 = cat4;
|
||||
this.center = center;
|
||||
this.cloud = cloud;
|
||||
}
|
||||
|
||||
public static String getName(Word word) {
|
||||
return word.getName();
|
||||
}
|
||||
|
||||
public int getCat(int numCat) {
|
||||
switch (numCat) {
|
||||
case 1: return getCat1();
|
||||
case 2: return getCat2();
|
||||
case 3: return getCat3();
|
||||
default: return getCat4();
|
||||
}
|
||||
}
|
||||
|
||||
public String getCatString(int numCat) {
|
||||
return String.format(
|
||||
Relation.getInstance().getRelationName(this.getCat(numCat)),
|
||||
center.getName());
|
||||
}
|
||||
|
||||
public int getCat1() {
|
||||
return cat1;
|
||||
}
|
||||
|
||||
public void setCat1(int cat1) {
|
||||
this.cat1 = cat1;
|
||||
}
|
||||
|
||||
public int getCat2() {
|
||||
return cat2;
|
||||
}
|
||||
|
||||
public void setCat2(int cat2) {
|
||||
this.cat2 = cat2;
|
||||
}
|
||||
|
||||
public int getCat3() {
|
||||
return cat3;
|
||||
}
|
||||
|
||||
public void setCat3(int cat3) {
|
||||
this.cat3 = cat3;
|
||||
}
|
||||
|
||||
public int getCat4() {
|
||||
return cat4;
|
||||
}
|
||||
|
||||
public void setCat4(int cat4) {
|
||||
this.cat4 = cat4;
|
||||
}
|
||||
|
||||
public Word getCentre() {
|
||||
return center;
|
||||
}
|
||||
|
||||
public void setCentre(Word center) {
|
||||
this.center = center;
|
||||
}
|
||||
|
||||
public int getNbWord() {
|
||||
return cloud.length;
|
||||
}
|
||||
|
||||
public Word getWordInCloud(int index) {
|
||||
return cloud[index];
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "DownloadedBaseGame [gid=" + gid + ", pgid=" + pgid + ", id=" + id
|
||||
+ ", cat1=" + cat1 + ", cat2=" + cat2 + ", cat3=" + cat3
|
||||
+ ", cat4=" + cat4 + ", center=" + center + ", cloud="
|
||||
+ Arrays.toString(cloud) + "]";
|
||||
}
|
||||
|
||||
}
|
|
@ -1,57 +0,0 @@
|
|||
package org.pticlic.model;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
|
||||
/**
|
||||
* @author Bertrand BRUN
|
||||
*
|
||||
* Classe metier reprensentant n'importe quel le jeu telecharger du serveur.
|
||||
*
|
||||
*/
|
||||
public abstract class DownloadedGame implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
protected int gid;
|
||||
protected int pgid;
|
||||
protected int id;
|
||||
|
||||
public DownloadedGame() {
|
||||
this.id = -1;
|
||||
this.gid = -1;
|
||||
this.pgid = -1;
|
||||
}
|
||||
|
||||
public DownloadedGame(int id, int gid, int pgid) {
|
||||
super();
|
||||
this.id = id;
|
||||
this.gid = gid;
|
||||
this.pgid = pgid;
|
||||
}
|
||||
|
||||
public int getGid() {
|
||||
return gid;
|
||||
}
|
||||
|
||||
public void setGid(int gid) {
|
||||
this.gid = gid;
|
||||
}
|
||||
|
||||
public int getPgid() {
|
||||
return pgid;
|
||||
}
|
||||
|
||||
public void setPgid(int pgid) {
|
||||
this.pgid = pgid;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,74 +0,0 @@
|
|||
package org.pticlic.model;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* @author Bertrand BRUN
|
||||
*
|
||||
* Cette classe represente une partie joue.
|
||||
* Elle sera envoyer au serveur pour que celui-ci
|
||||
* puisse calculer le score obtenue.
|
||||
*
|
||||
*/
|
||||
public class Match implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
private ArrayList<Integer> relation1;
|
||||
private ArrayList<Integer> relation2;
|
||||
private ArrayList<Integer> relation3;
|
||||
private ArrayList<Integer> relation4;
|
||||
private DownloadedGame game;
|
||||
|
||||
public Match() {
|
||||
relation1 = new ArrayList<Integer>();
|
||||
relation2 = new ArrayList<Integer>();
|
||||
relation3 = new ArrayList<Integer>();
|
||||
relation4 = new ArrayList<Integer>();
|
||||
}
|
||||
|
||||
public void setGame(DownloadedGame game) {
|
||||
this.game = game;
|
||||
}
|
||||
|
||||
public DownloadedGame getGame() {
|
||||
return game;
|
||||
}
|
||||
|
||||
public void add(int relation, int word) {
|
||||
switch (relation) {
|
||||
case 1: relation1.add(word); break;
|
||||
case 2: relation2.add(word); break;
|
||||
case 3: relation3.add(word); break;
|
||||
case 4: relation4.add(word); break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the relation1
|
||||
*/
|
||||
public ArrayList<Integer> getRelation1() {
|
||||
return relation1;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the relation2
|
||||
*/
|
||||
public ArrayList<Integer> getRelation2() {
|
||||
return relation2;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the relation3
|
||||
*/
|
||||
public ArrayList<Integer> getRelation3() {
|
||||
return relation3;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the relation4
|
||||
*/
|
||||
public ArrayList<Integer> getRelation4() {
|
||||
return relation4;
|
||||
}
|
||||
}
|
|
@ -1,13 +1,6 @@
|
|||
package org.pticlic.model;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.Serializable;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
import org.pticlic.exception.PtiClicException;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
|
@ -15,7 +8,6 @@ import android.net.ConnectivityManager;
|
|||
import android.preference.PreferenceManager;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.stream.JsonReader;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -175,179 +167,4 @@ public class Network {
|
|||
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cette méthode permet de récupérer du serveur un certain nombre de parties.
|
||||
* @param nbGames Le nombre de parties que l'on veut récupérer.
|
||||
* @return
|
||||
*/
|
||||
public DownloadedGame getGames(int nbGames) throws PtiClicException, Exception {
|
||||
switch (mode) {
|
||||
case SIMPLE_GAME:
|
||||
return DownloadBaseGame(nbGames);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private DownloadedBaseGame DownloadBaseGame(int nbGames) throws PtiClicException, Exception {
|
||||
Gson gson = null;
|
||||
String json = null;
|
||||
DownloadedBaseGame game = null;
|
||||
|
||||
// URLConnection connection = url.openConnection();
|
||||
// connection.addRequestProperty("action", Action.GET_GAMES.value());
|
||||
// connection.addRequestProperty("user", this.id);
|
||||
// connection.addRequestProperty("passwd", this.passwd);
|
||||
// connection.addRequestProperty("nb", String.valueOf(nbGames));
|
||||
// connection.addRequestProperty("mode", mode.value());
|
||||
|
||||
String urlS = this.serverURL
|
||||
+ "?action=" + Action.GET_GAMES.value()
|
||||
+ "&user=" + this.id
|
||||
+ "&passwd=" + this.passwd
|
||||
+ "&nb=" + String.valueOf(nbGames)
|
||||
+ "&mode="+mode.value();
|
||||
|
||||
gson = new Gson();
|
||||
json = HttpClient.SendHttpPost(urlS);
|
||||
|
||||
try {
|
||||
|
||||
//JsonReader reader = new JsonReader(new InputStreamReader(connection.getInputStream(), "UTF-8"));
|
||||
InputStream in = new ByteArrayInputStream(json.getBytes("UTF-8"));
|
||||
JsonReader jsonReader = new JsonReader(new InputStreamReader(in));
|
||||
|
||||
// FIXME : Attention lorsque l'on pourra vraiment recupere plusieur partie, il faudra changer ce qui suit.
|
||||
jsonReader.beginArray();
|
||||
while (jsonReader.hasNext()) {
|
||||
game = makeBaseGame(jsonReader, gson);
|
||||
}
|
||||
jsonReader.endArray();
|
||||
jsonReader.close();
|
||||
} catch (UnsupportedEncodingException e1) {
|
||||
throw new PtiClicException(0, "Impossible de recuperer l'erreur, nous avons pris note de cette erreur.\n Merci");
|
||||
} catch (IOException e1) {
|
||||
throw new PtiClicException(0, "Impossible de recuperer l'erreur, nous avons pris note de cette erreur.\n Merci");
|
||||
} catch (Exception e) {
|
||||
throw new PtiClicException(json);
|
||||
}
|
||||
|
||||
return game;
|
||||
}
|
||||
|
||||
/**
|
||||
* Permet la transformation du Json en une instance de Game.
|
||||
*
|
||||
* @param reader Le Json sous forme d'un flux.
|
||||
* @param gson Une instance de Gson.
|
||||
* @return Une nouvelle instance de Game.
|
||||
* @throws IOException
|
||||
*/
|
||||
private DownloadedBaseGame makeBaseGame(JsonReader reader, Gson gson) throws IOException {
|
||||
int gid = -1;
|
||||
int pgid = -1;
|
||||
int id = -1;
|
||||
int cat1 = -1;
|
||||
int cat2 = -1;
|
||||
int cat3 = -1;
|
||||
int cat4 = -1;
|
||||
DownloadedBaseGame.Word center = null;
|
||||
DownloadedBaseGame.Word[] cloud = null;
|
||||
|
||||
reader.beginObject();
|
||||
while (reader.hasNext()) {
|
||||
String name = reader.nextName();
|
||||
if (name.equals("id")) {
|
||||
id = reader.nextInt();
|
||||
} else if (name.equals("gid")) {
|
||||
gid = reader.nextInt();
|
||||
} else if (name.equals("pgid")) {
|
||||
pgid = reader.nextInt();
|
||||
} else if (name.equals("cat1")) {
|
||||
cat1 = reader.nextInt();
|
||||
} else if (name.equals("cat2")) {
|
||||
cat2 = reader.nextInt();
|
||||
} else if (name.equals("cat3")) {
|
||||
cat3 = reader.nextInt();
|
||||
} else if (name.equals("cat4")) {
|
||||
cat4 = reader.nextInt();
|
||||
} else if (name.equals("center")) {
|
||||
center = gson.fromJson(reader, DownloadedBaseGame.Word.class);
|
||||
} else if (name.equals("cloud")) {
|
||||
cloud = gson.fromJson(reader, DownloadedBaseGame.Word[].class);
|
||||
} else {
|
||||
reader.skipValue();
|
||||
}
|
||||
}
|
||||
reader.endObject();
|
||||
return new DownloadedBaseGame(id, gid, pgid, cat1, cat2, cat3, cat4, center, cloud);
|
||||
}
|
||||
|
||||
/**
|
||||
* Cette méthode permet d'envoyer les parties au serveur pour qu'il puisse les
|
||||
* rajouter à la base de données, et calculer le score.
|
||||
* @param game La partie jouee par l'utilisateur
|
||||
* @return Le score sous forme JSON.
|
||||
*/
|
||||
public ScoreResponse sendGame(Match game) throws PtiClicException, Exception {
|
||||
switch (mode) {
|
||||
case SIMPLE_GAME:
|
||||
return sendBaseGame(game);
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public ScoreResponse sendBaseGame(Match game) throws PtiClicException, Exception {
|
||||
Gson gson = null;
|
||||
String json = null;
|
||||
|
||||
// TODO : ne restera le temps que les requete du serveur passe du GET au POST
|
||||
String urlS = this.serverURL
|
||||
+ "?action=" + Action.SEND_GAME.value()
|
||||
+ "&user=" + this.id
|
||||
+ "&passwd=" + this.passwd
|
||||
+ "&pgid=" + game.getGame().getPgid()
|
||||
+ "&gid=" + game.getGame().getGid()
|
||||
+ "&mode="+mode.value()
|
||||
+ "&nb="+((DownloadedBaseGame)(game.getGame())).getNbWord();
|
||||
|
||||
// TODO : faut gere le mode
|
||||
for (Integer i : game.getRelation1()) {
|
||||
urlS += "&" + i + "=" + ((DownloadedBaseGame)game.getGame()).getCat1() ;
|
||||
}
|
||||
for (Integer i : game.getRelation2()) {
|
||||
urlS += "&" + i + "=" + ((DownloadedBaseGame)game.getGame()).getCat2();
|
||||
}
|
||||
for (Integer i : game.getRelation3()) {
|
||||
urlS += "&" + i + "=" + ((DownloadedBaseGame)game.getGame()).getCat3();
|
||||
}
|
||||
for (Integer i : game.getRelation4()) {
|
||||
urlS += "&" + i + "=" + ((DownloadedBaseGame)game.getGame()).getCat4();
|
||||
}
|
||||
|
||||
// URL url = new URL(this.serverURL); // Attention ! this.serverURL contient "/server.php"
|
||||
// URLConnection connection = url.openConnection();
|
||||
// connection.addRequestProperty("action", Action.SEND_GAME.value());
|
||||
// connection.addRequestProperty("user", this.id);
|
||||
// connection.addRequestProperty("passwd", this.passwd);
|
||||
// connection.addRequestProperty("mode", mode.value());
|
||||
// connection.addRequestProperty("pgid", String.valueOf(game.getGame().getId()));
|
||||
|
||||
gson = new Gson();
|
||||
json = HttpClient.SendHttpPost(urlS);
|
||||
|
||||
// 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.
|
||||
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 {
|
||||
return sr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,88 +0,0 @@
|
|||
package org.pticlic.model;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.pticlic.R;
|
||||
|
||||
/**
|
||||
* @author Bertrand BRUN
|
||||
*
|
||||
* Cette classe permet de recuperer le noms ou l'image d'un relation en fonction du numero de son id.
|
||||
*
|
||||
*/
|
||||
public class Relation {
|
||||
// TODO : Penser a peut etre remplacer les HashMap par une BDD.
|
||||
|
||||
private static Relation instance = null;
|
||||
|
||||
HashMap<Integer, String> stringRelations;
|
||||
HashMap<Integer, Integer> imageRelations;
|
||||
|
||||
private Relation() {
|
||||
imageRelations = new HashMap<Integer, Integer>();
|
||||
imageRelations.put(-1, R.drawable.corbeille);
|
||||
imageRelations.put(0, R.drawable.rapport);
|
||||
imageRelations.put(5, R.drawable.synonyme);
|
||||
imageRelations.put(7, R.drawable.contraire);
|
||||
imageRelations.put(9, R.drawable.contenu);
|
||||
imageRelations.put(10, R.drawable.contenant);
|
||||
|
||||
// ATTENTION ! Tout ce qui est ci-dessous est en double dans relations.php .
|
||||
stringRelations = new HashMap<Integer, String>();
|
||||
stringRelations.put(-1, "Mot non lié à '%s'");
|
||||
stringRelations.put(0, "'%s' est en rapport avec...");
|
||||
stringRelations.put(1, "raffinement sémantique"); // pas utilisé
|
||||
stringRelations.put(2, "raffinement morphologique"); // pas utilisé
|
||||
stringRelations.put(3, "domaine"); // pas utilisé
|
||||
stringRelations.put(4, "r_pos"); // pas utilisé
|
||||
stringRelations.put(5, "'%s' est un synonyme de...");
|
||||
stringRelations.put(6, "'%s' est une sorte de...");
|
||||
stringRelations.put(7, "Un contraire de '%s' est...");
|
||||
stringRelations.put(8, "Un spécifique de '%s' est...");
|
||||
stringRelations.put(9, "... est une partie de '%s'");
|
||||
stringRelations.put(10, "'%s' fait partie de...");
|
||||
stringRelations.put(11, "locution"); // pas utilisé
|
||||
stringRelations.put(12, "potentiel de FL"); // pas utilisé
|
||||
stringRelations.put(13, "Quoi/Qui pourrait '%s'");
|
||||
stringRelations.put(14, "action>patient"); // pas utilisé
|
||||
stringRelations.put(15, "Le lieu pour '%s' est...");
|
||||
stringRelations.put(16, "Un instrument pour '%s' est...");
|
||||
stringRelations.put(17, "Un caractéristique de '%s' est...");
|
||||
stringRelations.put(18, "r_data"); // pas utilisé
|
||||
stringRelations.put(19, "r_lemma"); // pas utilisé
|
||||
stringRelations.put(20, "magn"); // pas utilisé
|
||||
stringRelations.put(21, "antimagn"); // pas utilisé
|
||||
stringRelations.put(22, "'%s' est de la même famille que...");
|
||||
stringRelations.put(29, "predicat"); // pas utilisé
|
||||
stringRelations.put(30, "lieu>action"); // pas utilisé
|
||||
stringRelations.put(31, "action>lieu"); // pas utilisé
|
||||
stringRelations.put(32, "sentiment"); // pas utilisé
|
||||
stringRelations.put(33, "erreur"); // pas utilisé
|
||||
stringRelations.put(34, "manière"); // pas utilisé
|
||||
stringRelations.put(35, "sens/signification"); // pas utilisé
|
||||
stringRelations.put(36, "information potentielle"); // pas utilisé
|
||||
stringRelations.put(37, "rôle télique"); // pas utilisé
|
||||
stringRelations.put(38, "rôle agentif"); // pas utilisé
|
||||
stringRelations.put(41, "conséquence"); // pas utilisé
|
||||
stringRelations.put(42, "cause"); // pas utilisé
|
||||
stringRelations.put(52, "succession"); // pas utilisé
|
||||
stringRelations.put(53, "produit"); // pas utilisé
|
||||
stringRelations.put(54, "est le produit de"); // pas utilisé
|
||||
stringRelations.put(55, "s'oppose à"); // pas utilisé
|
||||
}
|
||||
|
||||
public synchronized static Relation getInstance() {
|
||||
if (instance == null) {
|
||||
instance = new Relation();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
public String getRelationName(int id) {
|
||||
return stringRelations.get(id);
|
||||
}
|
||||
|
||||
public Integer getRelationImage(int id) {
|
||||
return imageRelations.get(id);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user