Grand nettoyage de l'application Android
This commit is contained in:
parent
5a6b63eddb
commit
4eb8fd8aa5
|
@ -3,6 +3,5 @@
|
|||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="src" path="gen"/>
|
||||
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
|
||||
<classpathentry kind="lib" path="lib/gson-1.6.jar"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
|
|
|
@ -1,30 +0,0 @@
|
|||
<?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"
|
||||
android:background="#000">
|
||||
|
||||
|
||||
<LinearLayout android:layout_height="wrap_content"
|
||||
android:layout_width="fill_parent">
|
||||
|
||||
<ImageView android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" android:src="@drawable/icon"></ImageView>
|
||||
|
||||
<TextView android:layout_width="fill_parent"
|
||||
android:textSize="30dip" android:text="@string/app_name"
|
||||
android:layout_height="wrap_content" android:textStyle="bold"></TextView>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<TextView android:text="@string/version" android:id="@+id/infoVersion"
|
||||
android:layout_width="fill_parent" android:layout_height="wrap_content"
|
||||
android:gravity="center"></TextView>
|
||||
|
||||
<WebView android:id="@+id/textContent"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:background="#000"></WebView>
|
||||
|
||||
</LinearLayout>
|
|
@ -1,7 +0,0 @@
|
|||
<?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">
|
||||
<ImageView android:id="@+id/ImageView01" android:src="@drawable/splash" android:layout_gravity="center_vertical|center_horizontal|center" android:layout_width="fill_parent" android:layout_height="fill_parent"></ImageView>
|
||||
</LinearLayout>
|
|
@ -1,36 +0,0 @@
|
|||
package org.pticlic;
|
||||
|
||||
import org.pticlic.js.JavaScriptInterface;
|
||||
import org.pticlic.model.Constant;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.webkit.WebView;
|
||||
|
||||
public class FrontPage extends Activity {
|
||||
|
||||
private WebView webView;
|
||||
private JavaScriptInterface js = null;
|
||||
|
||||
/** Called when the activity is first created. */
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.frontpage);
|
||||
|
||||
webView = (WebView) findViewById(R.id.webview);
|
||||
webView.getSettings().setJavaScriptEnabled(true);
|
||||
|
||||
js = new JavaScriptInterface(this, webView);
|
||||
webView.addJavascriptInterface(js, "PtiClicAndroid");
|
||||
Log.i("[INFO]", Constant.SERVER + Constant.SERVER_URL);
|
||||
webView.loadUrl(Constant.SERVER + Constant.SERVER_URL);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
webView.goBack();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,50 +0,0 @@
|
|||
package org.pticlic;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.webkit.WebSettings;
|
||||
import android.webkit.WebView;
|
||||
import android.widget.TextView;
|
||||
|
||||
public class Information extends Activity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.info);
|
||||
|
||||
((TextView)findViewById(R.id.infoVersion)).setText("version : " + getString(R.string.version));
|
||||
InputStream in = getResources().openRawResource(R.raw.info);
|
||||
WebView webview = (WebView)findViewById(R.id.textContent);
|
||||
webview.setBackgroundColor(Color.WHITE);
|
||||
webview.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
|
||||
WebSettings webSettings = webview.getSettings();
|
||||
webSettings.setJavaScriptEnabled(true);
|
||||
|
||||
if (in != null) {
|
||||
|
||||
InputStreamReader tmp = new InputStreamReader(in);
|
||||
BufferedReader reader = new BufferedReader(tmp);
|
||||
String html;
|
||||
StringBuffer buf = new StringBuffer();
|
||||
|
||||
try {
|
||||
while ((html = reader.readLine()) != null) {
|
||||
buf.append(html + "\n");
|
||||
}
|
||||
|
||||
in.close();
|
||||
webview.loadData(html, "text/html", "UTF-8");
|
||||
|
||||
} catch (IOException e) {
|
||||
//TODO : Ajouter un boite de dialog indiquant qu'une erreur est arrivee.
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,56 +0,0 @@
|
|||
package org.pticlic;
|
||||
|
||||
import org.pticlic.model.Constant;
|
||||
import org.pticlic.model.Network;
|
||||
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceActivity;
|
||||
import android.widget.Toast;
|
||||
|
||||
public class Preference extends PreferenceActivity implements OnSharedPreferenceChangeListener {
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see android.preference.PreferenceActivity#onCreate(android.os.Bundle)
|
||||
*/
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
addPreferencesFromResource(R.xml.prefs);
|
||||
|
||||
SharedPreferences prefs = getPreferenceManager().getSharedPreferences();
|
||||
prefs.registerOnSharedPreferenceChangeListener(this);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
||||
if (key.equals("passwd")) {
|
||||
|
||||
SharedPreferences.Editor editor = sharedPreferences.edit();
|
||||
editor.putBoolean(Constant.SERVER_AUTH, false);
|
||||
editor.commit();
|
||||
|
||||
if (Network.isConnected(this)) {
|
||||
if (Network.isLoginCorrect(this)) {
|
||||
Toast.makeText(this,
|
||||
getString(R.string.preferences_loginmdp_valid),
|
||||
Toast.LENGTH_LONG).show();
|
||||
|
||||
} else {
|
||||
Toast.makeText(this,
|
||||
getString(R.string.preferences_loginmdp_notvalid),
|
||||
Toast.LENGTH_LONG).show();
|
||||
}
|
||||
} else {
|
||||
Toast.makeText(this,
|
||||
getString(R.string.preferences_nonetworks),
|
||||
Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -65,6 +65,10 @@ public class JavaScriptInterface {
|
|||
webView.reload();
|
||||
}
|
||||
|
||||
public boolean isAndroid() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Permet de quitter l'application
|
||||
*
|
||||
*/
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package org.pticlic.model;
|
||||
|
||||
public class Constant {
|
||||
public static final String SERVER_URL = "unstable/code/serveur/php/jeu.html";
|
||||
public static final String SERVER_URL = "jeu.html";
|
||||
public static final String SERVER_AUTH = "SERVER_AUTH";
|
||||
public static final String SERVER = "http://www.pticlic.fr/";
|
||||
|
||||
|
|
|
@ -1,99 +0,0 @@
|
|||
package org.pticlic.model;
|
||||
|
||||
/***
|
||||
Copyright (c) 2009
|
||||
Author: Stefan Klumpp <stefan.klumpp@gmail.com>
|
||||
Web: http://stefanklumpp.com
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
not use this file except in compliance with the License. You may obtain
|
||||
a copy of the License at
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
|
||||
import org.apache.http.Header;
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.HttpResponse;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.impl.client.DefaultHttpClient;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
public class HttpClient {
|
||||
private static final String TAG = "HttpClient";
|
||||
|
||||
public static String SendHttpPost(String URL) {
|
||||
|
||||
try {
|
||||
DefaultHttpClient httpclient = new DefaultHttpClient();
|
||||
HttpGet httpPostRequest = new HttpGet(URL);
|
||||
|
||||
//StringEntity se;
|
||||
//se = new StringEntity(str);
|
||||
|
||||
// Set HTTP parameters
|
||||
//httpPostRequest.setEntity(se);
|
||||
httpPostRequest.setHeader("Accept", "application/json");
|
||||
httpPostRequest.setHeader("Content-type", "application/json");
|
||||
httpPostRequest.setHeader("Accept-Encoding", "gzip"); // only set this parameter if you would like to use gzip compression
|
||||
|
||||
long t = System.currentTimeMillis();
|
||||
HttpResponse response = (HttpResponse) httpclient.execute(httpPostRequest);
|
||||
Log.i(TAG, "HTTPResponse received in [" + (System.currentTimeMillis()-t) + "ms]");
|
||||
|
||||
// Get hold of the response entity (-> the data):
|
||||
HttpEntity entity = response.getEntity();
|
||||
|
||||
if (entity != null) {
|
||||
// Read the content stream
|
||||
InputStream instream = entity.getContent();
|
||||
Header contentEncoding = response.getFirstHeader("Content-Encoding");
|
||||
if (contentEncoding != null && contentEncoding.getValue().equalsIgnoreCase("gzip")) {
|
||||
instream = new GZIPInputStream(instream);
|
||||
}
|
||||
|
||||
// convert content stream to a String
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(instream));
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
String line = null;
|
||||
try {
|
||||
while ((line = reader.readLine()) != null) {
|
||||
sb.append(line + "\n");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
instream.close();
|
||||
instream = null;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return sb.toString();
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// More about HTTP exception handling in another tutorial.
|
||||
// For now we just print the stack trace.
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,108 +0,0 @@
|
|||
package org.pticlic.model;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.preference.PreferenceManager;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @author Bertrand BRUN
|
||||
*
|
||||
* Cette classe permet de dialoguer avec le serveur de PtiClic pour récupérée soit des parties
|
||||
* soit le score qu'a réalisé un utilisateur.
|
||||
* Elle permet aussi d'envoyer au serveur les parties realiser par l'utilisateur pour que le serveur
|
||||
* puisse insérer la contribution de l'utilisateur, mais aussi pouvoir calculer le score de celui-ci.
|
||||
*
|
||||
*/
|
||||
public class Network {
|
||||
|
||||
public static class Check implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
private boolean loginOk = false;
|
||||
|
||||
public boolean isLoginOk() {
|
||||
return loginOk;
|
||||
}
|
||||
|
||||
public void setLoginOk(boolean loginOk) {
|
||||
this.loginOk = loginOk;
|
||||
}
|
||||
}
|
||||
|
||||
String newGameJson = null;
|
||||
|
||||
public enum Action {
|
||||
CHECK_LOGIN(3);
|
||||
|
||||
private final int value;
|
||||
|
||||
Action(int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
private String value() { return String.valueOf(value); }
|
||||
}
|
||||
|
||||
/**
|
||||
* Permet de savoir si l'application a access a internet ou non
|
||||
*
|
||||
* @param context l'activite permettant de tester l'access a internet
|
||||
* @return <code>true</code> si on a access a internet <code>false</code> sinon
|
||||
*/
|
||||
public static boolean isConnected(Context context) {
|
||||
ConnectivityManager cm = (ConnectivityManager)context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
if (cm != null && (cm.getActiveNetworkInfo() == null
|
||||
|| !cm.getActiveNetworkInfo().isConnected())) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Permet de verifier que la combinaison login/mdp est correct
|
||||
*
|
||||
* @param context l'activite permettant de tester l'access a internet
|
||||
* @param id l'identifiant de l'utilisateur
|
||||
* @param passwd le mot de passe de l'utilisateur
|
||||
* @return <code>true</code> si la combinaison login/mdp est correct <code>false</code> sinon
|
||||
*/
|
||||
public static boolean isLoginCorrect(Context context) {
|
||||
|
||||
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
String serverURL = sp.getString(Constant.SERVER_URL, Constant.SERVER) + "/server.php";
|
||||
String id = sp.getString(Constant.USER_ID, "joueur");
|
||||
String passwd = sp.getString(Constant.USER_PASSWD, "");
|
||||
Boolean auth = sp.getBoolean(Constant.SERVER_AUTH, false);
|
||||
|
||||
if (auth) {
|
||||
return auth;
|
||||
}
|
||||
|
||||
Gson gson = null;
|
||||
String json = null;
|
||||
boolean res = false;
|
||||
|
||||
String urlS = serverURL
|
||||
+ "?action=" + Action.CHECK_LOGIN.value()
|
||||
+ "&user=" + id
|
||||
+ "&passwd=" + passwd;
|
||||
|
||||
gson = new Gson();
|
||||
json = HttpClient.SendHttpPost(urlS);
|
||||
|
||||
Check check = gson.fromJson(json, Check.class);
|
||||
res = check.isLoginOk();
|
||||
|
||||
SharedPreferences.Editor editor = sp.edit();
|
||||
editor.putBoolean(Constant.SERVER_AUTH, res);
|
||||
editor.commit();
|
||||
|
||||
return res;
|
||||
}
|
||||
}
|
|
@ -634,7 +634,7 @@ La connexion entre les contrôlleurs et le vues est réalisé grâce à la metho
|
|||
L'ADT est un plugin développé par Google pour faciliter le developpement d'application \android{} avec Eclipse. Il propose un menu permettant de créer des projets de type \android{} déjà parametré selon les besoins. Mais aussi un gestionnaire d'emulateur, une disposition (au sens d'Eclipse) DDMS permettant de contrôler l'emulateur\dots{}
|
||||
|
||||
\section{Revirement des choix de developpement} % TODO : Devrait peut etre etre deplacé
|
||||
A la fin de la première iteration, nous avons décidé de ne plus utiliser le système de création de vue proposé par le SDK d'\android{}, car, pour nous, la création de vue en passant par le format proposé nous prennait énormement de temps. \android{} supportant le framework WebKit ainsi que javascript dans son integralité et notre groupe ayant un peu plus d'expérience dans le développement d'application web (de part notre formation), nous avons décidé de développer les vues de l'application PtiClic en HTML5/Javascript. De ce faite, l'application à été simplifié (une seul Activité) et une classe \verb!JavascriptInterface! réalisant un pont entre le code javascript et les fonctionnalitées du téléphone.
|
||||
A la fin de la première iteration, nous avons décidé de ne plus utiliser le système de création de vue proposé par le SDK d'\android{}, car, pour nous, la création de vue en passant par le format proposé nous prennait énormement de temps. \android{} supportant le framework WebKit ainsi que javascript dans son integralité et notre groupe ayant un peu plus d'expérience dans le développement d'application web (de part notre formation), nous avons décidé de développer les vues de l'application PtiClic en HTML5/Javascript. De ce faite, l'application à été simplifié (une seul Activité) et une classe \verb!JavascriptInterface! réalisant un pont entre le code javascript et les fonctionnalitées du téléphone à été ajouté.
|
||||
Un autre avantage à l'utilisation d'une application web pour développer PtiClic est le publique visé. En effet, le but de ce jeu étant de récupère des données d'un grand nombres d'utilisateur, fournir l'application à d'autres personnes que celles disposant d'un smartphone sous \android{} nous a semblé interressante. C'est pourquoi avec la version 2 nous avons aussi une application jouable à partir d'un navigateur internet <<normal>>, ce qui permet à un plus grand nombres de personnes de pouvoir jouer à PtiClic.
|
||||
|
||||
\section{Discussion}
|
||||
|
|
Loading…
Reference in New Issue
Block a user