import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.LinearLayout; import android.widget.RelativeLayout; import android.widget.TextView; import android.widget.Toast; import com.stategrid.echarge.R; import com.stategrid.echarge.entry.base.BaseActivity; import com.stategrid.echarge.entry.base.BaseApi; import com.stategrid.echarge.entry.base.Interface; import com.stategrid.echarge.module.my.bean.PublicBean; import com.stategrid.echarge.module.server.activity.BaseHtmlActivity; import com.stategrid.echarge.utils.EditTextNullUtil; import com.stategrid.echarge.utils.IntentUtil; import com.stategrid.echarge.utils.RetrofitUtils; import com.stategrid.echarge.utils.ToastUtil; import com.stategrid.echarge.view.ClearEditText; import com.stategrid.echarge.view.TimerButton; import java.util.HashMap; import retrofit2.Call; import retrofit2.Callback; import retrofit2.Response; import retrofit2.Retrofit; /** * Created by ZN on 2018/1/2. * 注册(整体页面) */ public class RegisterActivity extends BaseActivity implements View.OnClickListener { private RelativeLayout mRlBlack; private ClearEditText mEtPhone; private ClearEditText mEtPassword; private ClearEditText mEtVerificationCode; private TimerButton mTbVerificationCode; private LinearLayout mLlDeal; private Button mBtRegist; private TextView mTvBack; @Override public void setContent() { setContentView(R.layout.activity_register); } @Override public void findView() { mRlBlack = (RelativeLayout) findViewById(R.id.rl_black); mEtPhone = (ClearEditText) findViewById(R.id.et_phone); mEtPassword = (ClearEditText) findViewById(R.id.et_password); mEtVerificationCode = (ClearEditText) findViewById(R.id.et_verification_code); mTbVerificationCode = (TimerButton) findViewById(R.id.tb_verification_code); mLlDeal = (LinearLayout) findViewById(R.id.ll_deal); mBtRegist = (Button) findViewById(R.id.bt_regist); mTvBack = (TextView) findViewById(R.id.tv_back); } @Override public void setValue() { mRlBlack.setOnClickListener(this); mTbVerificationCode.setOnClickListener(this); mLlDeal.setOnClickListener(this); mBtRegist.setOnClickListener(this); mTvBack.setOnClickListener(this); } @Override public void onClick(View v) { switch (v.getId()) { case R.id.rl_black: finish(); break; case R.id.tb_verification_code: mTbVerificationCode.startTimer(); HashMap map = new HashMap(); map.put("consType", "01"); map.put("nationalCode", "86"); // byte[] b = EditTextNullUtil.getString(mEtPhone).getBytes(); // try { // // byte[] a = SM2Util.encrypt(b).getBytes(); // map.put("phone", Base64Util.encode(a)); // } catch (IOException e) { // e.printStackTrace(); // } map.put("phone", EditTextNullUtil.getString(mEtPhone)); Retrofit retrofit = RetrofitUtils.retrofitutild(RegisterActivity.this, Interface.BASEURL2, "数据加载中..."); BaseApi registerApi = retrofit.create(BaseApi.class); Call<PublicBean> call = registerApi.getPhonecode(map); call.enqueue(new Callback<PublicBean>() { @Override public void onResponse(Call<PublicBean> call, Response<PublicBean> response) { PublicBean publicBean = response.body(); if (publicBean.getCode() == 0) { Toast.makeText(RegisterActivity.this, "验证码发送成功", Toast.LENGTH_SHORT).show(); } else { Toast.makeText(RegisterActivity.this, publicBean.getMsg(), Toast.LENGTH_SHORT).show(); } RetrofitUtils.loadingDialog.dismiss(); } @Override public void onFailure(Call<PublicBean> call, Throwable t) { Toast.makeText(RegisterActivity.this, "联网失败", Toast.LENGTH_SHORT).show(); t.printStackTrace(); RetrofitUtils.loadingDialog.dismiss(); } }); break; case R.id.ll_deal: Bundle bundle = new Bundle(); bundle.putString("title", "用户协议"); bundle.putString("url", "http//www.baidu.com"); IntentUtil.startIntent(RegisterActivity.this, bundle, BaseHtmlActivity.class); break; case R.id.bt_regist: if (EditTextNullUtil.isEmpty(mEtPhone)) { ToastUtil.showToast(RegisterActivity.this, "请输入手机号"); // ToastShow.showCustomDialog(RegisterActivity.this, "请输入手机号"); } else if (!EditTextNullUtil.isMobile(mEtPhone)) { ToastUtil.showToast(RegisterActivity.this, "请输入正确的手机号"); } else if (EditTextNullUtil.isEmpty(mEtPassword)) { ToastUtil.showToast(RegisterActivity.this, "请输入密码"); // ToastShow.showCustomDialog(RegisterActivity.this, "请输入密码"); } else if (!(mEtPassword.getText().toString().length() > 8) || !EditTextNullUtil.isValidate(mEtPassword)) { ToastUtil.showToast(RegisterActivity.this, "密码至少八位至多十六位,并且要包括字母、数字、符号"); // ToastShow.showCustomDialog(RegisterActivity.this, "密码至少八位,并且要包括字母、数字、符号"); // }else if (EditTextNullUtil.isMobile(mEtPhone)) { // ToastShow.showCustomDialog(RegisterActivity.this, "请输入正确的手机号"); } else if (EditTextNullUtil.isEmpty(mEtVerificationCode)) { ToastUtil.showToast(RegisterActivity.this, "请输入验证码"); // ToastShow.showCustomDialog(RegisterActivity.this, "请输入验证码"); } else { HashMap map1 = new HashMap(); map1.put("type", "2"); // byte[] b1 = EditTextNullUtil.getString(mEtPhone).getBytes(); // try { // // byte[] a = SM2Util.encrypt(b1).getBytes(); // map1.put("phone", Base64Util.encode(a)); // // } catch (IOException e) { // e.printStackTrace(); // } // byte[] b = EditTextNullUtil.getString(mEtPassword).getBytes(); // try { // // byte[] a = SM2Util.encrypt(b).getBytes(); // map1.put("password", Base64Util.encode(a)); // // } catch (IOException e) { // e.printStackTrace(); // } map1.put("phone", EditTextNullUtil.getString(mEtPhone)); map1.put("password", EditTextNullUtil.getString(mEtPassword)); map1.put("verifyCode", EditTextNullUtil.getString(mEtVerificationCode)); Retrofit retrofit1 = RetrofitUtils.retrofitutild(RegisterActivity.this, Interface.BASEURL2, "数据加载中..."); BaseApi registerApi1 = retrofit1.create(BaseApi.class); Call<PublicBean> call1 = registerApi1.getRegister(map1); call1.enqueue(new Callback<PublicBean>() { @Override public void onResponse(Call<PublicBean> call, Response<PublicBean> response) { PublicBean publicBean = response.body(); if (publicBean.getCode() == 0) { Toast.makeText(RegisterActivity.this, "注册成功", Toast.LENGTH_SHORT).show(); finish(); } else { Toast.makeText(RegisterActivity.this, publicBean.getMsg(), Toast.LENGTH_SHORT).show(); } RetrofitUtils.loadingDialog.dismiss(); } @Override public void onFailure(Call<PublicBean> call, Throwable t) { t.printStackTrace(); Toast.makeText(RegisterActivity.this, "联网失败", Toast.LENGTH_SHORT).show(); RetrofitUtils.loadingDialog.dismiss(); } }); } break; case R.id.tv_back: finish(); break; } } }
注册界面
最新推荐文章于 2023-07-28 14:40:11 发布