import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import com.bwei.mango.MainActivity;
import com.bwei.mango.R;
import com.bwei.mango.nsg.Log;
import com.bwei.mango.utils.GsonObjectCallback;
import com.bwei.mango.utils.OkHttp3Utils;
import java.io.IOException;
import java.util.HashMap;
import okhttp3.Call;
public class Denglu extends AppCompatActivity {
private Button button2;
private EditText editText1;
private EditText editText2;
private TextView text2;
private String mUrl = "http://120.27.23.105/user/login";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_denglu);
button2 = (Button) findViewById(R.id.button2);
editText1 = (EditText) findViewById(R.id.editText2);
editText2 = (EditText) findViewById(R.id.editText3);
text2 = (TextView) findViewById(R.id.textView2);
button2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
HashMap map = new HashMap();
String user = editText1.getText().toString();
String pass = editText2.getText().toString();
map.put("mobile",user);
map.put("password",pass);
OkHttp3Utils.getInstance().doPost("http://120.27.23.105/user/login", map, new GsonObjectCallback<Log>() {
@Override
public void onUi(Log log) {
String s = log.getMsg();
Toast.makeText(Denglu.this,s,Toast.LENGTH_SHORT).show();
if (s.equals("登录成功")){
Intent intent = new Intent(Denglu.this, MainActivity.class);
startActivity(intent);
Toast.makeText(Denglu.this,s,Toast.LENGTH_SHORT).show();
}else {
Toast.makeText(Denglu.this,s,Toast.LENGTH_SHORT).show();
}
}
@Override
public void onFailed(Call call, IOException e) {
}
});
}
});
text2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(Denglu.this, Zhuce.class);
startActivity(intent);
}
});
}
}
接口注册
package com.bwei.mango.adpter;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import com.bwei.mango.R;
import com.bwei.mango.nsg.Log;
import com.bwei.mango.utils.GsonObjectCallback;
import com.bwei.mango.utils.OkHttp3Utils;
import java.io.IOException;
import java.util.HashMap;
import okhttp3.Call;
public class Zhuce extends AppCompatActivity {
private EditText editText4;
private EditText editText5;
private EditText editText6;
private EditText editText7;
private Button button;
HashMap map;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_zhuce);
editText4 = (EditText) findViewById(R.id.editText4);
editText5 = (EditText) findViewById(R.id.editText5);
editText6 = (EditText) findViewById(R.id.editText6);
editText7 = (EditText) findViewById(R.id.editText7);
button = (Button) findViewById(R.id.button);
map = new HashMap();
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final String user=editText4.getText().toString();
final String pass=editText5.getText().toString();
final String pass2 = editText6.getText().toString();
final String email = editText7.getText().toString();
map.put("mobile",user);
map.put("password",pass);
OkHttp3Utils.getInstance().doPost("http://120.27.23.105/user/reg", map, new GsonObjectCallback<Log>() {
@Override
public void onUi(Log zhu) {
String s = zhu.getMsg();
if(s.equals("注册成功")){
if (!TextUtils.isEmpty(email)) {
if (pass.equals(pass2)) {
Intent intent = new Intent(Zhuce.this, Denglu.class);
startActivity(intent);
Toast.makeText(Zhuce.this, s, Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(Zhuce.this, "密码不一致,请重新输入密码", Toast.LENGTH_SHORT).show();
}
} else {
Toast.makeText(Zhuce.this, "以上信息不能为空", Toast.LENGTH_SHORT).show();
}
}else {
Toast.makeText(Zhuce.this,s, Toast.LENGTH_SHORT).show();
}
}
@Override
public void onFailed(Call call, IOException e) {
}
});
}
});
}
}