SharedPreferences sp;
EditText etUserNo;
EditText etPwd;
Button bnLogin;
public boolean Islogin=false;
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.loginactivity);
initview();
sp=getSharedPreferences("UserInfo",MODE_PRIVATE);
}
public void initview(){
etUserNo= (EditText) findViewById(R.id.etUserNo);
etPwd= (EditText) findViewById(R.id.etPwd);
bnLogin= (Button) findViewById(R.id.bnLogin);
bnLogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
switch(v.getId()){
case R.id.bnLogin:
// 登录功能
login();
break;
}
}
});
}
private void login(){
final String LoginName=etUserNo.getText().toString().trim();
final String Pwd=etPwd.getText().toString().trim();
// 判断输入框是否为空
if (TextUtils.isEmpty(LoginName)||TextUtils.isEmpty(Pwd)){
Toast.makeText(this,R.string.Login_btn_title,Toast.LENGTH_SHORT).show();
}else {
finishActivity();
}
new Thread(){
@Override
public void run() {
loginByPost(LoginName,Pwd);
}
}.start();
}
/*
* 跳转主界面
*
* */
public void finishActivity(){
Intent intent=new Intent(LoginActivity.this,FashingBoatActivity.class);
startActivity(intent);
finish();
}
/*
Post请求操作
@LoginName
@Pwd
* */
public void loginByPost(String LoginName, String Pwd) {
OkHttpUtils.post().url(HttpContacts.LOGIN_URL).
addParams("LoginName",LoginName)
.addParams("PassWord",Pwd)
.build()
.execute(new Callback<JsonObject>() {
@Override
public JsonObject parseNetworkResponse(Response response) throws Exception {
return null;
}
@Override
public void onError(Call call, Exception e) {
}
@Override
public void onResponse(JsonObject response) {
getdata(response);
// result = response;
}
});
}
public void getdata(JsonObject object){
Gson gson=new GsonBuilder().setDateFormat("yyyy-MM-dd" ).create();
ResultObj result=gson.fromJson(object.toString(),ResultObj.class);
if(result.getStatus()==200){
finishActivity();
}else{
Toast.makeText(this,R.string.Login_btn,Toast.LENGTH_SHORT).show();
}
}
public void getJson(JsonObject object){
Gson gson=new GsonBuilder().setDateFormat("yyyy-MM-dd" ).create();
CustomPrincipalSerializeModel entity = gson.fromJson(object.toString(), CustomPrincipalSerializeModel.class);
}
为梦想努力_冬
相关分类