package com.txsc.activity; import java.util.HashMap; import lib.view.ViewUtils; import lib.view.annotation.ViewInject; import com.txsc.MyApplication; import com.txsc.NetActivity; import com.txsc.R; import com.txsc.bean.StatusBean; import com.txsc.constants.Url; import com.txsc.utils.CheckUtil; import com.txsc.utils.JsonUtils; import com.txsc.utils.MD5; import com.txsc.utils.SPUtils; import com.txsc.utils.TextUtils; import com.txsc.utils.ToastUtil; import android.content.Intent; import android.os.Bundle; import android.text.Editable; import android.text.TextWatcher; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.ImageView; import android.widget.TextView; /** * 注册 * * @author Admin * */ public class User_RegistAty extends NetActivity { @ViewInject(R.id.p2_img_regist_title_back) private ImageView imgBack; @ViewInject(R.id.p2_edit_regist_username) private EditText editUName; @ViewInject(R.id.p2_edit_regist_password) private EditText editUPass; @ViewInject(R.id.p2_edit_regist_confirm) private EditText editUPass2; // @ViewInject(R.id.p2_edit_regist_consignee) // private EditText editConsignee; @ViewInject(R.id.p2_edit_regist_phone) private EditText editPhone; @ViewInject(R.id.p2_edit_regist_hotelname) private EditText editHotelName; // @ViewInject(R.id.p2_edit_regist_address) // private EditText editAddr; // @ViewInject(R.id.p2_edit_regist_map) private TextView textMap; @ViewInject(R.id.p2_edit_regist_testing) private TextView textTest; @ViewInject(R.id.p2_btn_regist_regist) private Button btnRegist; @ViewInject(R.id.p2_edit_regist_address) private EditText editAddr; private String editAddrString; public static double sh_longitude = 0, sh_latitude = 0; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); MyApplication.getInstance().addActivity(this); setContentView(R.layout.p2_main_regist_layout); ViewUtils.inject(this); btnRegist.setOnClickListener(this); imgBack.setOnClickListener(this); textMap.setOnClickListener(this); textTest.setOnClickListener(this); editUName.addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { textTest.setText("检测"); } @Override public void afterTextChanged(Editable s) { } }); } @Override public void success(String result, int tag) { StatusBean bean = JsonUtils.parseNetResult(result).getStatus(); if (tag == 0) { if (bean.getCode() == 200) { ToastUtil.show(getApplicationContext(), "恭喜您,用户名可用", 500); textTest.setText("可用"); } else { ToastUtil.show(getApplicationContext(), bean.getMessage(), 500); editUName.setText(""); editUName.requestFocus(); } } else if (tag == 1) { if (bean.getCode() == 200) { ToastUtil.show(getApplicationContext(), "恭喜您,注册成功", 500); User_RegistAty.this.finish(); } else { ToastUtil.show(getApplicationContext(), "注册失败," + bean.getMessage(), 500); } } } @Override protected void onResume() { super.onResume(); if (sh_longitude != 0 || sh_latitude != 0) { textMap.setText("已选择,点击更改"); } } @Override public void onclick(View v) { if (v == imgBack) { User_RegistAty.this.finish(); } else if (v == btnRegist) { String h_username = editUName.getText().toString().replace(" ", ""); String h_password = editUPass.getText().toString().replace(" ", ""); String h_password2 = editUPass2.getText().toString() .replace(" ", ""); String sh_name = editHotelName.getText().toString() .replace(" ", ""); String sh_phone = editPhone.getText().toString().replace(" ", ""); editAddrString = editAddr.getText().toString(); // String sh_address = editAddr.getText().toString().replace(" ", // ""); if (TextUtils.isBlank(h_username)) { ToastUtil.show(User_RegistAty.this, "请输入用户名", 500); return; } if (TextUtils.isBlank(editAddrString)) { ToastUtil.show(User_RegistAty.this, "请填写详细地址", 500); return; } if (!textTest.getText().toString().equals("可用")) { ToastUtil.show(User_RegistAty.this, "请检测用户名是否可用", 500); return; } if (TextUtils.isBlank(h_password)) { ToastUtil.show(User_RegistAty.this, "密码不能为空,请输入", 500); editUPass.requestFocus(); return; } if (!h_password.equals(h_password2)) { ToastUtil.show(User_RegistAty.this, "两次输入密码不一致,请重新输入", 500); editUPass.setText(""); editUPass2.setText(""); editUPass.requestFocus(); return; } if (TextUtils.isBlank(sh_phone)) { ToastUtil.show(User_RegistAty.this, "手机号码不能为空,请输入", 500); editPhone.requestFocus(); return; } if (!CheckUtil.isMobile(sh_phone)) { ToastUtil.show(User_RegistAty.this, "请输入正确的手机号", 500); editPhone.setText(""); editPhone.requestFocus(); return; } if (TextUtils.isBlank(sh_name)) { ToastUtil.show(User_RegistAty.this, "饭店名称不能为空,请输入", 500); editHotelName.requestFocus(); return; } // if (TextUtils.isBlank(sh_address)) { // ToastUtil.show(User_RegistAty.this, "收货地址不能为空,请输入", 500); // editAddr.requestFocus(); // return; // } if (sh_longitude == 0 && sh_latitude == 0) { Intent intent = new Intent(User_RegistAty.this, User_RegPosiAty.class); startActivity(intent); return; } HashMap<String, String> params = new HashMap<String, String>(); params.put("agent_id", SPUtils.getAgentID(this)); params.put("h_username", h_username); params.put("h_password", MD5.getMD5ofStr(h_password)); params.put("sh_phone", sh_phone); params.put("sh_name", sh_name); params.put("sh_address", editAddrString); // agent_id=TRest5763cd2d5b3745ccww56&h_username=user22&h_password=123455 // &sh_name=aabbdd&sh_phone=135324512968&sh_address=123123 // params.put("sh_address", sh_address); params.put("sh_longitude", sh_longitude + ""); params.put("sh_latitude", sh_latitude + ""); params.put( "port_password", MD5.getMD5ofStr(Url.KET + SPUtils.getAgentID(this) + h_username)); asynNet(Url.Reg_Regist, params, 1); } else if (v == textTest) { if (textTest.getText().toString().equals("可用")) { ToastUtil.show(User_RegistAty.this, "用户名可用", 500); return; } String uName = editUName.getText().toString().replace(" ", ""); if (TextUtils.isBlank(uName)) { ToastUtil.show(User_RegistAty.this, "请输入用户名后再检测", 500); return; } HashMap<String, String> params = new HashMap<String, String>(); params.put("h_username", uName); params.put("port_password", MD5.getMD5ofStr(Url.KET + uName)); asynNet(Url.Reg_CheckName, params, 0); // http://192.168.1.31:101/user/checkAvailName.ashx?h_username=jjjkj&port_password=a93f9bc82a3ab59112dc1102c90a6bc1 } else if (v == textMap) { Intent intent = new Intent(User_RegistAty.this, User_RegPosiAty.class); startActivity(intent); } } // @Override // protected void onActivityResult(int requestCode, int resultCode, Intent // data) { // super.onActivityResult(requestCode, resultCode, data); // if (data != null) { // switch (resultCode) { // case 212: // sh_longitude = data.getDoubleExtra("longitude", 0); // sh_latitude = data.getDoubleExtra("latitude", 0); // textMap.setText("已选择,点击更改"); // break; // default: // break; // } // } // } }