sdf
This commit is contained in:
259
app/src/main/java/com/sl/house_property/RegisterActivity.java
Normal file
259
app/src/main/java/com/sl/house_property/RegisterActivity.java
Normal file
@@ -0,0 +1,259 @@
|
||||
package com.sl.house_property;
|
||||
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.view.Gravity;
|
||||
import android.view.View;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.cutil.RegexUtils;
|
||||
import com.sl.house_property.databinding.ActivityRegisterBinding;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
import my_loader.Loader;
|
||||
import my_loader.Resultcode;
|
||||
import http.ApiConfig;
|
||||
import rx.Subscription;
|
||||
import rx.functions.Action1;
|
||||
import utils.Md5;
|
||||
|
||||
public class RegisterActivity extends BaseActivity<ActivityRegisterBinding> implements View.OnClickListener {
|
||||
int recLen = 60;//获取验证,倒计时
|
||||
private ProgressDialog progressDialog;
|
||||
private Loader mGankLoader;
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
protected int getLayoutResId() {
|
||||
return R.layout.activity_register;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
progressDialog=new ProgressDialog(RegisterActivity.this);
|
||||
|
||||
setAbr(getString(R.string.register), new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
finish();
|
||||
}
|
||||
},0,null,0,null,0,null,"");
|
||||
mDataBinding.getcode.setOnClickListener(this);
|
||||
|
||||
mDataBinding.register.setOnClickListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
switch (view.getId()){
|
||||
|
||||
|
||||
case R.id.getcode:
|
||||
if(mDataBinding.registerphone.getText().toString().length()<1){
|
||||
setToast(getString(R.string.me_input_phone_tip));
|
||||
return;
|
||||
}
|
||||
if(!RegexUtils.isMobileExact(mDataBinding.registerphone.getText().toString())){
|
||||
setToast(getString(R.string.me_input_phone_error_tip));
|
||||
return;
|
||||
}
|
||||
getMesgCode(R.id.getcode);
|
||||
break;
|
||||
case R.id.register:
|
||||
if(mDataBinding.registerphone.getText().toString().length()==0){
|
||||
setToast(getString(R.string.me_input_phone_tip));
|
||||
return;
|
||||
}
|
||||
if(!RegexUtils.isMobileExact(mDataBinding.registerphone.getText().toString())){
|
||||
setToast(getString(R.string.me_input_phone_error_tip));
|
||||
return;
|
||||
}
|
||||
|
||||
if(mDataBinding.logincode.getText().toString().length()<1){
|
||||
setToast(getString(R.string.me_input_verification_tip));
|
||||
return;
|
||||
}
|
||||
|
||||
String password = mDataBinding.editpaw.getText().toString();
|
||||
if(password.length()<1){
|
||||
setToast(getString(R.string.me_input_password_tip));
|
||||
return;
|
||||
}
|
||||
// if(password.length()<6){
|
||||
// showToast(getString(R.string.me_input_password_short_tip));
|
||||
//
|
||||
// return;
|
||||
// }
|
||||
if(!tools.RegexUtils.checkPassword(password)){
|
||||
setToast(getString(R.string.me_input_password_fail_tip));
|
||||
return;
|
||||
}
|
||||
|
||||
String againPassword = mDataBinding.editagainpaw.getText().toString().trim();
|
||||
if(againPassword.length()<1){
|
||||
setToast(getString(R.string.me_input_again_password_tip));
|
||||
return;
|
||||
}
|
||||
|
||||
if(!mDataBinding.editpaw.getText().toString().trim().equals(mDataBinding.editagainpaw.getText().toString().trim())){
|
||||
setToast(getString(R.string.me_password_Inconsistent_tip));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if(!mDataBinding.agreewhitemeg.isChecked()){
|
||||
setToast("请先同意注册协议");
|
||||
|
||||
return;
|
||||
}
|
||||
register(view.getId());
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void register(int id) {
|
||||
Map<String,String> map=new HashMap<>();
|
||||
map.put("phone",mDataBinding.registerphone.getText().toString().trim());
|
||||
map.put("password",mDataBinding.editpaw.getText().toString().trim());
|
||||
map.put("code",mDataBinding.logincode.getText().toString().trim());
|
||||
map.put("sign", Md5.md5("Cas"+"UserReg"+Md5.secret));
|
||||
map.put("app", "Cas");
|
||||
map.put("class", "UserReg");
|
||||
getGankList(ApiConfig.BASE_URL,map, getResources().getString(R.string.registering),id);
|
||||
}
|
||||
|
||||
|
||||
private void getMesgCode(int id) {//获取验证码
|
||||
// TODO Auto-generated method stub
|
||||
recLen = 60;
|
||||
/* getRegisterCode.setTextColor(getResources().getColor(R.color.regitergrey));*/
|
||||
|
||||
mDataBinding.getcode.setClickable(false);
|
||||
Map<String,String> map=new HashMap<>();
|
||||
map.put("sendto",mDataBinding.registerphone.getText().toString().trim());
|
||||
map.put("action","register");
|
||||
map.put("sign", Md5.md5("Cas"+"SendCode"+Md5.secret));
|
||||
map.put("app", "Cas");
|
||||
map.put("class", "SendCode");
|
||||
getGankList(ApiConfig.BASE_URL,map, getResources().getString(R.string.getthecodenow),id);
|
||||
// map = new HashMap<String, Object>();
|
||||
// map.put("telephone", editPhoneNo.getText().toString().trim());
|
||||
// getAsyTask(1, map, HttpUrl.registerUser(), "正在获取验证码", HttpNet.PROGRESSVISIBLE, HttpNet.POSTTYPE);//联网
|
||||
|
||||
}
|
||||
|
||||
private void getGankList(final String myurl, Map<String, String> map, String string, final int getcode1) {
|
||||
progressDialog.setMessage(string);
|
||||
|
||||
//map.put("")
|
||||
progressDialog.setCancelable(false);
|
||||
progressDialog.show();
|
||||
mDataBinding.getRoot().postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
progressDialog.dismiss();
|
||||
//setToast(1, getString(R.string.timeout));
|
||||
}
|
||||
},13000);
|
||||
mGankLoader = new Loader();
|
||||
/* Map<String,String> map=new HashMap<String,String>();
|
||||
map.put("phone");*/
|
||||
Subscription subscription = mGankLoader.getMovie(myurl,map).subscribe(new Action1<Resultcode>() {
|
||||
@Override
|
||||
public void call(Resultcode resultcode) {
|
||||
progressDialog.dismiss();
|
||||
//setToast(0,resultcode.status);
|
||||
if((!(resultcode.status==0))){
|
||||
setToast( resultcode.msg);
|
||||
mDataBinding.getcode.setClickable(true);
|
||||
return;
|
||||
}
|
||||
switch (getcode1) {
|
||||
case R.id.getcode:
|
||||
setToast( getString(R.string.megissucess));
|
||||
startTimer();
|
||||
break;
|
||||
|
||||
case R.id.register:
|
||||
setToast( getString(R.string.registersucess));
|
||||
mDataBinding.getRoot().postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
finish();
|
||||
}
|
||||
},1500);
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}, new Action1<Throwable>() {
|
||||
@Override
|
||||
public void call(Throwable throwable) {
|
||||
progressDialog.dismiss();
|
||||
mDataBinding.getcode.setClickable(true);
|
||||
setToast(getString(R.string.getdatafailure));
|
||||
throwable.printStackTrace();
|
||||
}
|
||||
});
|
||||
|
||||
addSubscription(subscription);
|
||||
}
|
||||
|
||||
private void startTimer(){
|
||||
final Timer timer = new Timer();
|
||||
final Handler handler = new Handler() {
|
||||
@Override
|
||||
public void handleMessage(Message msg) {
|
||||
// TODO Auto-generated method stub
|
||||
super.handleMessage(msg);
|
||||
mDataBinding.getcode.setText(recLen + "");
|
||||
if (recLen < 0) {
|
||||
timer.cancel();
|
||||
mDataBinding.getcode.setText("重新获取");
|
||||
mDataBinding.getcode.setClickable(true);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
TimerTask task = new TimerTask() {
|
||||
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
recLen--;
|
||||
Message message = new Message();
|
||||
message.what = 1;
|
||||
handler.sendMessage(message);
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
timer.schedule(task, 1000, 1000);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 用户协议
|
||||
* @param v v
|
||||
*/
|
||||
public void agreementEvent(View v){
|
||||
Intent intent = new Intent(this, RegisterAgreementActivity.class);
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user