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
| package com.example.basedonnees;
import java.io.InputStream;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicHeader;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.protocol.HTTP;
import org.json.JSONObject;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Looper;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RatingBar;
import android.widget.Spinner;
public class Forulaire extends Activity{
Button Valider;
Bundle objetbunble;
String Ecole;
String Note;
Button Retour;
String Comm;
EditText txt;
String qualite;
public void onCreate(Bundle savedInstanceState) {
Log.i("form1","form1");
super.onCreate(savedInstanceState);
//acceder à la nouvelle vue donc la page de description
Log.i("form2","form2");
setContentView(R.layout.formulary);
Log.i("form","form");
Valider = (Button)findViewById(R.id.validation);
Valider.setOnClickListener(ValiderListener);
Retour = (Button)findViewById(R.id.ArriereForm);
Retour.setOnClickListener(RetourListener);
}
private OnClickListener ValiderListener = new OnClickListener() {
@Override
public void onClick(View v) {
Spinner s = (Spinner) findViewById(R.id.Classe);
qualite=s.getSelectedItem().toString();
Log.i("rating1","rating1");
RatingBar ratingBar = (RatingBar) findViewById(R.id.mainRatingBar);
Note=Float.toString(ratingBar.getRating());
Log.i("rating2","rating2");
txt=(EditText) findViewById(R.id.CommentaireLaisse);
Comm=txt.getText().toString();
Log.i("rating3","rating3");
Log.i("Comm",""+Comm);
Log.i("qualite",""+qualite);
Log.i("note",""+Note);
objetbunble = Forulaire.this.getIntent().getExtras();
//verifier les données
if ((objetbunble != null) && (objetbunble.containsKey("Ecole"))) {
//récupérer l'url
Ecole = Forulaire.this.getIntent().getStringExtra("Ecole");
}else {
//Erreur
Ecole="error";
}
Log.i("EcolePresentation",Ecole);
/*HttpClient httpClient = new DefaultHttpClient();
HttpPost postRequest = new HttpPost("http://192.168.15.116/ecoles/RecupForm.php");
postRequest.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpClient.execute(postRequest);
JSONObject object = new JSONObject();
try {
object.put("Ecole", Ecole);
object.put("Qualite", qualite);
object.put("Note", Note);
object.put("Commentaire", Comm);
} catch (JSONException e) {
e.printStackTrace();
}*/
Thread t = new Thread() {
public void run() {
Looper.prepare(); //For Preparing Message Pool for the child Thread
HttpClient client = new DefaultHttpClient();
HttpConnectionParams.setConnectionTimeout(client.getParams(), 10000); //Timeout Limit
HttpResponse response;
JSONObject object = new JSONObject();
try {
HttpPost post = new HttpPost("http://192.168.15.116/ecoles/RecupForm.php");
object.put("Ecole", Ecole);
object.put("Qualite", qualite);
object.put("Note", Note);
object.put("Commentaire", Comm);
Log.i("object", ""+object);
StringEntity se = new StringEntity( object.toString());
se.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
Log.i("se", ""+se);
post.setEntity(se);
response = client.execute(post);
Log.i("response", ""+response);
/*Checking response */
if(response!=null){
InputStream in = response.getEntity().getContent(); //Get the data in the entity
Log.i("in", ""+in);
}
} catch(Exception e) {
e.printStackTrace();
Log.i("Error", "Cannot Estabilish Connection");
}
Looper.loop(); //Loop in the message queue
}
};
t.start();
Intent intent = new Intent( Forulaire.this, Redirection.class);
Forulaire.this.startActivity(intent);
}
};
private OnClickListener RetourListener = new OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent( Forulaire.this, PresentationEcoles.class);
Forulaire.this.startActivity(intent);
}
};
} |
Partager