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
| package com.monresto.net;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class Main extends Activity implements OnClickListener {
String URL = "http://www.monresto.net/android/users.php?";
String P;
String verif;
// private static final String CLASSTAG = SimpleGet.class.getSimpleName();
private EditText getLogin;
private EditText getPassword;
//private TextView getOutput;
private Button getButton;
public static final int CODE_RETOUR = 0;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.main);
this.getLogin = (EditText) findViewById(R.id.get_login);
getLogin.setText("");
this.getPassword = (EditText) findViewById(R.id.get_password);
getPassword.setText("");
//this.getOutput = (TextView) findViewById(R.id.get_output);
this.getButton = (Button) findViewById(R.id.get_button);
this.getButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
//getOutput.setText("");
String logintophp = "&login="+getLogin.getText().toString();
String passwordtophp = "&password="+getPassword.getText().toString();
String P = getHttpResponse(URL+logintophp+passwordtophp);
if(P!=null) {
verif="&test=";
P = getHttpResponse(URL+logintophp+passwordtophp+verif);
Toast.makeText(Main.this, "" +P, Toast.LENGTH_SHORT).show();
verif="&nom=";
String nomclient = getHttpResponse(URL+logintophp+passwordtophp+verif);
Toast.makeText(Main.this, "" +nomclient, Toast.LENGTH_SHORT).show();
verif="&prenom=";
String prenomclient = getHttpResponse(URL+logintophp+passwordtophp+verif);
Toast.makeText(Main.this, "" +prenomclient, Toast.LENGTH_SHORT).show();
}
//Toast.makeText(Main.this, "" +A, Toast.LENGTH_SHORT).show();
//Intent intent = new Intent(Main.this, Acceuil.class);//mContext is the Context variable over here.
//startActivityForResult(intent, CODE_RETOUR);
//startActivity(intent);
//}
//AlertDialog.Builder alt_bld = new AlertDialog.Builder(Main.this);
//alt_bld.setMessage("Salut : " + P)
//.setCancelable(false)
//.setNegativeButton("Entrez", new DialogInterface.OnClickListener() {
//public void onClick(DialogInterface dialog, int id) {
//Toast.makeText(Main.this, "" +P, Toast.LENGTH_SHORT).show();
// Action for 'Validez' Button
//AlertDialog alert = alt_bld.create();
// Title for AlertDialog
//alert.setTitle("monresto.net");
// Icon for AlertDialog
//alert.setIcon(R.drawable.monresto);
//alert.show();
}} );
}
/**
* Perform an HTTP GET with HttpUrlConnection.
*
* @param location
* @return
*/
private String getHttpResponse(String location) {
StringBuffer result = new StringBuffer();
URL url = null;
// Log.d(Constants.LOGTAG, " " + SimpleGet.CLASSTAG + " location = " + location);
try {
url = new URL(location);
// Log.d(Constants.LOGTAG, " " + SimpleGet.CLASSTAG + " url = " + url);
} catch (MalformedURLException e) {
// Log.e(Constants.LOGTAG, " " + SimpleGet.CLASSTAG + " " + e.getMessage());
}
if (url != null) {
try {
HttpURLConnection urlConn = (HttpURLConnection) url.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));
String inputLine;
int lineCount = 0; // limit the lines for the example
while ((lineCount < 10) && ((inputLine = in.readLine()) != null)) {
lineCount++;
// Log.v(Constants.LOGTAG, " " + SimpleGet.CLASSTAG + " inputLine = " + inputLine);
result.append(inputLine);
//result += "\n" + inputLine;
}
in.close();
urlConn.disconnect();
} catch (IOException e) {
// Log.e(Constants.LOGTAG, " " + SimpleGet.CLASSTAG + " " + e.getMessage());
}
} else {
// Log.e(Constants.LOGTAG, " " + SimpleGet.CLASSTAG + " url NULL");
}
return result.toString();
}
public void onClick(View arg0) {
// TODO Auto-generated method stub
}
} |
Partager