package com.example.java4androidmysql;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.conn.params.ConnManagerParams;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.EntityUtils;
import android.os.AsyncTask;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity extends Activity {
public static final String URL = "http://192.168.2.1:8080/JavaRegisterMysql/login";
public static String res="";
public static String name = "";
public static String code = "";
public static String phone =" ";
public static String chose="0";
Button connectButton=null;
Button registerButton=null;
EditText noteUser=null;
EditText notePassword=null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
connectButton=(Button)findViewById(R.id.btnConnect);
registerButton=(Button)findViewById(R.id.btnRegister);
noteUser=(EditText)findViewById(R.id.editUserName);
notePassword=(EditText)findViewById(R.id.editPassword);
connectButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Toast.makeText(MainActivity.this, "正在登录", Toast.LENGTH_SHORT).show();
name = noteUser.getText().toString().trim();
code = notePassword.getText().toString().trim();
chose="1";
new SubmitAsyncTask().execute(URL);
Toast.makeText(MainActivity.this, "res = "+res, Toast.LENGTH_SHORT).show();
if(res.equals("2")){
Toast.makeText(MainActivity.this, "登录成功", Toast.LENGTH_SHORT).show();
}else if(res.equals("1")){
Toast.makeText(MainActivity.this, "用户名或密码错误", Toast.LENGTH_SHORT).show();
}else if(res.equals("3")){
Toast.makeText(MainActivity.this, "注册失败", Toast.LENGTH_SHORT).show();
}else if(res.equals("4")){
Toast.makeText(MainActivity.this, "注册成功", Toast.LENGTH_SHORT).show();
}else if(res.equals("-1")){
Toast.makeText(MainActivity.this, "网络异常", Toast.LENGTH_SHORT).show();
}
}
});
noteUser.setText("ab");
notePassword.setText("123456");
registerButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent intent=new Intent();
intent.setClass(MainActivity.this, Register.class);
MainActivity.this.startActivity(intent);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}