171 lines
8.1 KiB
Plaintext
171 lines
8.1 KiB
Plaintext
|
package com.example.administrator.ximengjianyu.activity.home;
|
|||
|
|
|||
|
import android.app.Activity;
|
|||
|
import android.content.Intent;
|
|||
|
import android.support.v7.app.AppCompatActivity;
|
|||
|
import android.os.Bundle;
|
|||
|
import android.text.TextUtils;
|
|||
|
import android.util.Log;
|
|||
|
import android.view.View;
|
|||
|
import android.view.Window;
|
|||
|
import android.view.WindowManager;
|
|||
|
import android.widget.Button;
|
|||
|
import android.widget.EditText;
|
|||
|
import android.widget.Toast;
|
|||
|
|
|||
|
import com.cm.utils.net.HttpUtils;
|
|||
|
import com.cm.utils.net.response.GsonResponseHandler;
|
|||
|
import com.example.administrator.ximengjianyu.R;
|
|||
|
import com.example.administrator.ximengjianyu.activity.LoginActivity;
|
|||
|
import com.example.administrator.ximengjianyu.base.MyApplication;
|
|||
|
import com.example.administrator.ximengjianyu.beans.NewPasswordBean;
|
|||
|
import com.example.administrator.ximengjianyu.beans.TuiChuBean;
|
|||
|
import com.example.administrator.ximengjianyu.global.Constants;
|
|||
|
import com.example.administrator.ximengjianyu.global.UserInfo;
|
|||
|
import com.example.administrator.ximengjianyu.utils.CacheUtils;
|
|||
|
import com.example.administrator.ximengjianyu.utils.EdittextUtils;
|
|||
|
import com.google.gson.Gson;
|
|||
|
|
|||
|
import java.util.HashMap;
|
|||
|
import java.util.Map;
|
|||
|
|
|||
|
import butterknife.ButterKnife;
|
|||
|
|
|||
|
|
|||
|
public class NewPwdActivity extends AppCompatActivity implements View.OnClickListener{
|
|||
|
|
|||
|
private EditText jiu_pwd;
|
|||
|
private EditText new_pwd;
|
|||
|
private EditText new_pwd_again;
|
|||
|
private Button new_pwd_btn;
|
|||
|
private String mOldPasswordContent;//旧密码
|
|||
|
private String mNewPasswordContent;//新密码密码
|
|||
|
private String mConfirmPasswordContent;//确认密码
|
|||
|
private Activity mActivity;
|
|||
|
private Map<String, String> tuichumap;
|
|||
|
@Override
|
|||
|
protected void onCreate(Bundle savedInstanceState) {
|
|||
|
super.onCreate(savedInstanceState);
|
|||
|
requestWindowFeature(Window.FEATURE_NO_TITLE);
|
|||
|
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
|||
|
setContentView(R.layout.activity_new_pwd);
|
|||
|
ButterKnife.bind(this);
|
|||
|
mActivity=this;
|
|||
|
getSupportActionBar().hide(); //隐藏标题栏
|
|||
|
//初始化控件
|
|||
|
intiView();
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
private void intiView() {
|
|||
|
jiu_pwd = (EditText) findViewById(R.id.jiu_pwd);
|
|||
|
new_pwd = (EditText) findViewById(R.id.new_pwd);
|
|||
|
new_pwd_again = (EditText) findViewById(R.id.new_pwd_again);
|
|||
|
new_pwd_btn = (Button) findViewById(R.id.new_pwd_btn);
|
|||
|
new_pwd_btn.setOnClickListener(this);
|
|||
|
}
|
|||
|
|
|||
|
@Override
|
|||
|
public void onClick(View view) {
|
|||
|
switch (view.getId()){
|
|||
|
case R.id.new_pwd_btn:
|
|||
|
mOldPasswordContent = jiu_pwd.getText().toString().trim();
|
|||
|
mNewPasswordContent = new_pwd.getText().toString().trim();
|
|||
|
mConfirmPasswordContent = new_pwd_again.getText().toString().trim();
|
|||
|
if (TextUtils.isEmpty(mOldPasswordContent)) { //原始密码为空
|
|||
|
Toast.makeText(mActivity, "原始密码为空,请输入"
|
|||
|
, Toast.LENGTH_SHORT).show();
|
|||
|
//让原始密码获取焦点并弹出软键盘
|
|||
|
EdittextUtils.getEdittext().showSoftInputFromWindow(mActivity, jiu_pwd);
|
|||
|
} else if (TextUtils.isEmpty(mNewPasswordContent)) { //新密码为空
|
|||
|
Toast.makeText(mActivity, "新密码为空,请输入", Toast.LENGTH_SHORT).show();
|
|||
|
//新密码获取焦点,并把确认密码置为空
|
|||
|
EdittextUtils.getEdittext().showSoftInputFromWindow(mActivity, new_pwd);
|
|||
|
new_pwd_again.setText(null);
|
|||
|
} else if (TextUtils.isEmpty(mConfirmPasswordContent)) {
|
|||
|
//确认密码为空,让其获取焦点
|
|||
|
Toast.makeText(mActivity, "确认密码为空,请输入", Toast.LENGTH_SHORT).show();
|
|||
|
EdittextUtils.getEdittext().showSoftInputFromWindow(mActivity, new_pwd_again);
|
|||
|
} else if (mNewPasswordContent.length() < 6) {
|
|||
|
Toast.makeText(mActivity, "密码长度需大于6位", Toast.LENGTH_SHORT).show();
|
|||
|
} else if (mNewPasswordContent.length() > 18) {
|
|||
|
Toast.makeText(mActivity, "密码数不能超过十八位", Toast.LENGTH_SHORT).show();
|
|||
|
} else if (!mNewPasswordContent.equals(mConfirmPasswordContent)) {
|
|||
|
Toast.makeText(mActivity, "密码输入不同,请重新输入", Toast.LENGTH_SHORT).show();
|
|||
|
}else if (mNewPasswordContent.equals(mOldPasswordContent)) {
|
|||
|
Toast.makeText(mActivity, "密码不能相同,请重新输入", Toast.LENGTH_SHORT).show();
|
|||
|
} else {
|
|||
|
//连接服务器,更换密码,更换密码之后,回到登录页面,重写输入密码,进行判断
|
|||
|
changePasswordThroughInternet();
|
|||
|
}
|
|||
|
break;
|
|||
|
}
|
|||
|
}
|
|||
|
/**
|
|||
|
* 该方法进行一些列的联网操作,默认是更改失败
|
|||
|
*/
|
|||
|
private void changePasswordThroughInternet() {
|
|||
|
Map<String, String> map = new HashMap<>();
|
|||
|
map.put("token", UserInfo.getToken(mActivity));
|
|||
|
Log.e("--newpwd--token",UserInfo.getToken(mActivity));
|
|||
|
map.put("password", mOldPasswordContent);
|
|||
|
map.put("newPassword", mNewPasswordContent);
|
|||
|
HttpUtils.getInstance().post(Constants.CHANGE_PASSWORD, map, new GsonResponseHandler<NewPasswordBean>() {
|
|||
|
@Override
|
|||
|
public void onSuccess(int statusCode, NewPasswordBean response) {
|
|||
|
Toast.makeText(mActivity, response.getMsg(), Toast.LENGTH_SHORT).show();
|
|||
|
if ("200".equals(response.getState())) {
|
|||
|
//退出聊天服务器
|
|||
|
tuichulogin();
|
|||
|
CacheUtils.removePro(mActivity, Constants.LOGIN_PASSWORD_SP);
|
|||
|
MyApplication.getInstance().restartLoginActivity(mActivity);
|
|||
|
}else if ("400".equals(response.getState())){
|
|||
|
Toast.makeText(mActivity,response.getMsg(),Toast.LENGTH_SHORT).show();
|
|||
|
}else if ("202".equals(response.getState())) { //跳转到登录页面,并关闭其他activity
|
|||
|
//token会话失效,需要进入登录页面重新登录
|
|||
|
Intent intent=new Intent(NewPwdActivity.this,LoginActivity.class);
|
|||
|
startActivity(intent);
|
|||
|
finish();
|
|||
|
// judgeHasClickedSave();
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
@Override
|
|||
|
public void onFailure(int statusCode, String error_msg) {
|
|||
|
Toast.makeText(mActivity, "更改密码失败", Toast.LENGTH_SHORT).show();
|
|||
|
}
|
|||
|
});
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
//退出登录
|
|||
|
public void tuichulogin() {
|
|||
|
tuichumap = new HashMap<String, String>();
|
|||
|
tuichumap.put("token", UserInfo.getToken(mActivity));
|
|||
|
HttpUtils.getInstance().post(mActivity, Constants.TUICHUDENGLU, tuichumap, new GsonResponseHandler<TuiChuBean>() {
|
|||
|
@Override
|
|||
|
public void onSuccess(int statusCode, TuiChuBean response) {
|
|||
|
if ("200".equals(response.getState())) {
|
|||
|
Intent intent = new Intent(NewPwdActivity.this, LoginActivity.class);
|
|||
|
startActivity(intent);
|
|||
|
finish();
|
|||
|
} else if ("400".equals(response.getState())) {
|
|||
|
Toast.makeText(mActivity, response.getMsg(), Toast.LENGTH_SHORT).show();
|
|||
|
}else if ("202".equals(response.getState())) { //跳转到登录页面,并关闭其他activity
|
|||
|
//token会话失效,需要进入登录页面重新登录
|
|||
|
Intent intent = new Intent(NewPwdActivity.this, LoginActivity.class);
|
|||
|
startActivity(intent);
|
|||
|
finish();
|
|||
|
// judgeHasClickedSave();
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
@Override
|
|||
|
public void onFailure(int statusCode, String error_msg) {
|
|||
|
|
|||
|
}
|
|||
|
});
|
|||
|
}
|
|||
|
|
|||
|
}
|