package com.hjx.personalcenter.activity; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.support.v4.app.FragmentActivity; import android.text.TextUtils; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.ImageView; import android.widget.TextView; import com.hjx.personalcenter.R; import com.hjx.personalcenter.customdialog.CitysListDialog; import com.hjx.personalcenter.customdialog.CountryDialog; import com.hjx.personalcenter.customdialog.ProvinceListDialog; import com.hjx.personalcenter.db.SaveParam; import com.hjx.personalcenter.http.HttpCode; import com.hjx.personalcenter.http.HttpManager; import com.hjx.personalcenter.interfaces.DialogCallBack; import com.hjx.personalcenter.model.CityInfo; import com.hjx.personalcenter.model.CountyInfo; import com.hjx.personalcenter.model.ProvinceInfo; import com.hjx.personalcenter.util.AlertUtils; import com.hjx.personalcenter.util.GetDevicesUtil; import com.hjx.personalcenter.util.Judgment; import com.hjx.personalcenter.util.PhoneNumCheckUtils; import org.json.JSONObject; import java.util.ArrayList; import java.util.TimerTask; /** * Created by h on 2017/8/9. */ public class ChangeElectronicCardAdressInfoActivity extends FragmentActivity implements View.OnClickListener ,DialogCallBack.ProvincesCallBack ,DialogCallBack.CitysCallBack,DialogCallBack.CountryCallBack{ private ImageView back_forgit; private EditText forot_pwd_phone,forot_pwd_anthcode,newadress; private TextView adress; private Button forot_pwd_sub,forot_pwd_getanthcode; private String typeStr = "general"; private int delayTime=60; private java.util.Timer Delaytimer; Handler handler = new Handler() { @Override public void handleMessage(Message msg) { super.handleMessage(msg); JSONObject jsonObject; String status; switch (msg.what) { case HttpCode.AUTHCODE_SUCESS1: jsonObject = (JSONObject) msg.obj; status = jsonObject.optString("status"); if (status.equals("100")) { AlertUtils.showToast(ChangeElectronicCardAdressInfoActivity.this, "验证码发送成功"); } //AlertUtils.showToast(ForgotPassword.this, jsonObject.optString("message")); break; case HttpCode.AUTHCODE_FAIL1: jsonObject = (JSONObject) msg.obj; AlertUtils.showToast(ChangeElectronicCardAdressInfoActivity.this, jsonObject.optString("验证码发送失败,请检查网络")); break; case 21: if(delayTime<=0){ if(Delaytimer!=null){ Delaytimer.cancel(); } forot_pwd_getanthcode.setEnabled(true); forot_pwd_getanthcode.setClickable(true); forot_pwd_getanthcode.setText("获取验证码"); delayTime=60; }else{ forot_pwd_getanthcode.setEnabled(false); forot_pwd_getanthcode.setClickable(false); forot_pwd_getanthcode.setText(delayTime + " s"); } break; } } }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_change_card_validation); SysApplication.getInstance().addActivity(this); initView(); setLister(); } //获取验证码 private void getauthcode() { forot_pwd_anthcode.requestFocus(); String forot_pwd_phone1 = forot_pwd_phone.getText().toString().trim(); HttpManager.getInstance().authCode(typeStr, forot_pwd_phone1, handler, this); valiDelay(); } private void initView() { forot_pwd_phone = (EditText) findViewById(R.id.et_phonenumber); forot_pwd_anthcode = (EditText) findViewById(R.id.et_authcode); adress = (TextView) findViewById(R.id.et_newpassword); newadress = (EditText) findViewById(R.id.et_again_newpassword); forot_pwd_sub = (Button) findViewById(R.id.btn_ok); forot_pwd_getanthcode = (Button) findViewById(R.id.btn_authcode); back_forgit= (ImageView) findViewById(R.id.cancel); } private void setLister() { back_forgit.setOnClickListener(this); forot_pwd_sub.setOnClickListener(this); forot_pwd_getanthcode.setOnClickListener(this); adress.setOnClickListener(this); } @Override public void onClick(View view) { switch (view.getId()){ case R.id.btn_ok: String forot_pwd_phone1 = forot_pwd_phone.getText().toString().trim(); String forot_pwd_anthcode1 = forot_pwd_anthcode.getText().toString().trim(); String forot_pwd_pwd3 = adress.getText().toString().trim(); String forot_pwd_pwd4 = newadress.getText().toString().trim(); if (TextUtils.isEmpty(forot_pwd_phone1)|| TextUtils.isEmpty(forot_pwd_pwd3) || TextUtils.isEmpty(forot_pwd_pwd4)){ AlertUtils.showToast(ChangeElectronicCardAdressInfoActivity.this, "请将必填项填写完整"); return; }else if (Judgment.getInstance().isPhoneNum(forot_pwd_phone1)){ AlertUtils.showToast(ChangeElectronicCardAdressInfoActivity.this, "手机号码输入有误"); } else { //修改地址接口 String userID = GetDevicesUtil.getDevicesInfo(this).getDeviceNumber(); HttpManager.getInstance().changecardadressinfo(this,userID,forot_pwd_phone1,forot_pwd_anthcode1,forot_pwd_pwd3+forot_pwd_pwd4); } break; case R.id.btn_authcode: forot_pwd_phone1 = forot_pwd_phone.getText().toString().trim(); if (!PhoneNumCheckUtils.isPhone(forot_pwd_phone1)){ AlertUtils.showToast(ChangeElectronicCardAdressInfoActivity.this, "请输入正确的手机号"); }else { forot_pwd_anthcode.requestFocus(); getauthcode(); } break; case R.id.et_newpassword: ProvinceListDialog.getInstance((DialogCallBack.ProvincesCallBack) ChangeElectronicCardAdressInfoActivity.this).show(getSupportFragmentManager(), "ProvinceListDialog"); break; case R.id.cancel: finish(); break; } } @Override public void province1OnItemClick(ArrayList data, int position, int type) { String regionName = data.get(position).getRegionName(); String provice = SaveParam.getInstance().getLoginParam(this,"sheng"); SaveParam.getInstance().saveLoginParam(this,"shi",regionName); CountryDialog.getInstance((DialogCallBack.CountryCallBack) this).show(getSupportFragmentManager(), "CountryDialog"); adress.setText(""); adress.setText(provice+regionName); } @Override public void province2OnItemClick(ArrayList data, int position, int type) { String regionName = data.get(position).getRegionName(); String provices = SaveParam.getInstance().getLoginParam(this,"sheng"); String citys = SaveParam.getInstance().getLoginParam(this,"shi"); adress.setText(""); adress.setText(provices+citys+regionName); } @Override public void provinceOnItemClick(ArrayList data, int position, int type) { String regionName = data.get(position).getRegionName(); SaveParam.getInstance().saveLoginParam(this,"sheng",regionName); CitysListDialog.getInstance((DialogCallBack.CitysCallBack) this).show(getSupportFragmentManager(), "CitysListDialog"); adress.setText(""); adress.setText(regionName); } // 线程类 定时器 public void valiDelay() { Delaytimer = new java.util.Timer(true); TimerTask task = new TimerTask() { public void run() { //每次需要执行的代码放到这里面。 delayTime--; handler.sendEmptyMessage(21); } }; Delaytimer.schedule(task, 1000,1000); } }