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
| package Tarabbia.Xamax;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.util.HashMap;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.app.Activity;
import android.app.AlertDialog;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.Toast;
public class calendrier extends Activity implements OnClickListener {
//Variables Globales
private ListView maListViewPerso;
JSONObject json_data;//objet qui récupère les partie de la requête sur le webService PHP
EditText tbValue = null;
//On déclare la HashMap qui contiendra les informations pour un item
public HashMap<String, String> map;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.calendrier);
//affichage du popup
Toast.makeText(this,"Le calendrier de Xamax",Toast.LENGTH_LONG).show();
//Récupération de la listview créée dans le fichier joueurs.xml
maListViewPerso = (ListView) findViewById(R.id.listviewcalendrier);
//Récupération du button
Button btnRechercher = (Button)findViewById(R.id.btnAnnee);
//Récupération du textBox, activation de l'evenement CLICK
tbValue = (EditText)this.findViewById(R.id.editTextAnnee);
btnRechercher.setOnClickListener(this);
}
@Override
protected void onDestroy() {
Log.i("","OnDestroy");
finish();
super.onDestroy();
}
@Override
public void onClick(View v) {
switch (v.getId()){
case R.id.btnAnnee:
if (tbValue.getText().toString().equals("") ) {
Toast.makeText(this, "Veuillez saisir une date dans la \"texte box\" au-dessus", Toast.LENGTH_SHORT).show();
}else{
if(Xamax_infos.listItemCalendrier.size()>0){
Xamax_infos.listItemCalendrier.clear();
}
afficheCalendrier(tbValue.getText().toString());
}
break;
}
}
public void afficheCalendrier (String var){
try{
//mise en place de l'URL du webservice ansi que la requête SQL
JSONArray jArray = new JSONArray(MySqlConnector.getData("http://jonathantarabbia.cwebh.org/xamax_mobile/select.php","calendrier",var));
for(int i=0;i<jArray.length();i++){
json_data = jArray.getJSONObject(i);
map = new HashMap<String, String>();
//on insère un élément titre que l'on récupérera dans le textView titre créé dans le fichier affichageitem.xml
map.put("titre", ""+ json_data.get("Domicile")+ " VS "+ json_data.get("Visiteur"));
//on insère un élément description que l'on récupérera dans le textView description créé dans le fichier affichageitem.xml
map.put("description", "" + json_data.get("dateMatch") );
//on insère la référence à l'image (convertit en String car normalement c'est un int) que l'on récupérera dans l'imageView créé dans le fichier affichageitem.xml
map.put("img", String.valueOf(R.drawable.icon));
//enfin on ajoute cette hashMap dans la arrayList
Xamax_infos.listItemCalendrier.add(map);
}
afficheResultat();
}catch(JSONException e){
Log.e("log_tag", "Erreur de conversion des données "+e.toString());
}
//Enfin on met un écouteur d'évènement sur notre listView
maListViewPerso.setOnItemClickListener(new OnItemClickListener() {
@SuppressWarnings("unchecked")
public void onItemClick(AdapterView<?> a, View v, int position, long id) {
//on récupère la HashMap contenant les infos de notre item (titre, description, img)
HashMap<String, String> map = (HashMap<String, String>) maListViewPerso.getItemAtPosition(position);
//on créer une boite de dialogue
AlertDialog.Builder adb = new AlertDialog.Builder(calendrier.this);
//on attribut un titre à notre boite de dialogue
adb.setTitle("Xamaxien");
//on insère un message à notre boite de dialogue, et ici on affiche le titre de l'item cliqué
adb.setMessage("Votre choix : "+map.get("titre"));
//on indique que l'on veut le bouton ok à notre boite de dialogue
adb.setPositiveButton("Ok", null);
//on affiche la boite de dialogue
adb.show();
}
});
}
private InputStream OpenHttpConnection(String strURL) throws IOException{
InputStream inputStream = null;
URL url = new URL(strURL);
URLConnection conn = url.openConnection();
try{
HttpURLConnection httpConn = (HttpURLConnection)conn;
httpConn.setRequestMethod("GET");
httpConn.connect();
if (httpConn.getResponseCode() == HttpURLConnection.HTTP_OK) {
inputStream = httpConn.getInputStream();
}
}
catch (Exception ex)
{
}
return inputStream;
}
private Bitmap LoadImage(String URL, BitmapFactory.Options options)
{
Bitmap bitmap = null;
InputStream in = null;
try {
in = OpenHttpConnection(URL);
bitmap = BitmapFactory.decodeStream(in, null, options);
in.close();
} catch (IOException e1) {
}
return bitmap;
}
private void afficheResultat(){
//Création d'un SimpleAdapter qui se chargera de mettre les items présent dans notre list (listItem) dans la vue affichageitem
SimpleAdapter mSchedule = new SimpleAdapter (this.getBaseContext(), Xamax_infos.listItemCalendrier, R.layout.affichageitem,
new String[] {"img", "titre", "description"}, new int[] {R.id.img, R.id.titre, R.id.description});
//On attribut à notre listView l'adapter que l'on vient de créer
maListViewPerso.setAdapter(mSchedule);
}
} |
Partager