1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198
|
package com.restomaniak.alpha;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.app.Activity;
import android.net.ParseException;
import android.os.Bundle;
import android.util.Log;
import android.widget.ArrayAdapter;
import android.widget.ExpandableListView;
import android.widget.ListView;
import android.widget.RatingBar;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.Toast;
public class Avis extends Activity {
private ListView maListViewPerso;
private String nomRestaurant;
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
ArrayList<String> donnees = new ArrayList<String>();
private String noteGlobaleString;
private int noteGlobaleInt = 0;
private float resultatNoteGlobale = 0;
private String noteCuisineString;
private int noteCuisineInt = 0;
private float resultatNoteCuisine = 0;
private String noteQualiteString;
private int noteQualiteInt = 0;
private float resultatNoteQualite = 0;
private String noteServiceString;
private int noteServiceInt = 0;
private float resultatNoteService = 0;
private JSONArray jArray;
//private RatingBar noteGlobale;
//private RatingBar noteCuisine;
//private RatingBar noteQualite;
//private RatingBar noteService;
private ListView list = null;
private TextView recupNomUtilisateur = null;
private TextView recupDate = null;
private TextView recupCommentaire = null;
private TextView recupNoteCuisine = null;
private TextView recupNoteQualite = null;
private TextView recupNoteService = null;
private String nomUtilisateur = null;
private String date = null;
private String commentaire = null;
private String cuisine = null;
private String qp = null;
private String service = null;
private int compteur;
private int i = 0;
private int j = 0;
//Création de l'Arraylist qui nous permettra de remplir la listView
ArrayList<HashMap<String, String>> listItem = new ArrayList<HashMap<String, String>>();
//On déclare la HashMap qui contiendra les informations pour un item
HashMap<String, String> map;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.avis);
/***************************************************************************************************************************************************/
/************************************************************Récupération données Bunble************************************************************/
/***************************************************************************************************************************************************/
//On récupère les données du Bundle (le nom du restaurant donc)
Bundle objetbunbleTris = this.getIntent().getExtras();
if (objetbunbleTris !=null ) {
nomRestaurant = this.getIntent().getStringExtra("nomRestaurant");
} else {
//Erreur
nomRestaurant = "Error";
}
//System.out.println("Nom restaurant: " +nomRestaurant);
/***************************************************************************************************************************************************/
/************************************************************Connexion à la base de données*********************************************************/
/***************************************************************************************************************************************************/
String result = null;
InputStream is = null;
JSONObject json_data=null;
try{
//commandes httpClient
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://www.restomaniak.com/mobile/Avis.php");
nameValuePairs.add(new BasicNameValuePair("nomRestaurant", nomRestaurant));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
is = entity.getContent();
}
catch(Exception e){
Log.i("taghttppost",""+e.toString());
Toast.makeText(getBaseContext(),e.toString() ,Toast.LENGTH_LONG).show();
}
//conversion de la réponse en chaine de caractère
try
{
BufferedReader reader = new BufferedReader(new InputStreamReader(is,"UTF-8"));
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null)
{
sb.append(line + "\n");
}
is.close();
result = sb.toString();
}
catch(Exception e)
{
Log.i("tagconvertstr",""+e.toString());
}
//recuperation des donnees json
try{
jArray = new JSONArray(result);
compteur = jArray.length();
System.out.println("Voici le compteur " + compteur);
}
catch(JSONException e)
{
Log.i("tagjsonexp",""+e.toString());
} catch (ParseException e) {
Log.i("tagjsonpars",""+e.toString());
}
if (compteur != 0)
{
//Création et initialisation de l'Adapter pour les personnes
AdapterPersoAvis adapterProutes = new AdapterPersoAvis(this, jArray);
System.out.println(adapterProutes.getCount());
//Récupération du composant ListView
list = (ListView)findViewById(R.id.listviewavis);
//Initialisation de la liste avec les données
list.setAdapter(adapterProutes);
}
}
} |
Partager