package com.geo.smallcredit.activity; import org.json.JSONException; import org.json.JSONObject; import net.tsz.afinal.FinalHttp; import net.tsz.afinal.http.AjaxCallBack; import net.tsz.afinal.http.AjaxParams; import android.app.Activity; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.util.Log; import android.view.View; import android.view.View.OnClickListener; import android.view.inputmethod.InputMethodManager; import android.view.Window; import android.widget.Button; import android.widget.EditText; import android.widget.LinearLayout; import android.widget.Toast; import com.geo.smallcredit.R; import com.geo.smallcredit.MainApplication.MainApplication; import com.geo.smallcredit.util.AppConfig; import com.geo.smallcredit.util.CommonUtil; import com.geo.smallcredit.util.PromptManager; import com.geo.smallcredit.util.ToastUtil; import com.geo.smallcredit.utils.net.InternetURL; import com.geo.smallcredit.vo.TimeButton; public class FindPwdActivity extends Activity implements OnClickListener { private EditText etphone, verifyEt; private Button nextBtn; private TimeButton phoneTextView; private Bundle savedInstanceState; private String tel, verify; private LinearLayout mLine; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); MainApplication.getInstance().addActivity(FindPwdActivity.this); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.forgetpwd_find); initView(); initClick(); } private void initClick() { phoneTextView.setOnClickListener(this); nextBtn.setOnClickListener(this); mLine.setOnClickListener(this); } private void initView() { etphone = (EditText) findViewById(R.id.forgetpwd_find_edit); verifyEt = (EditText) findViewById(R.id.forgetpwd_find_verifyedit); phoneTextView = (TimeButton) findViewById(R.id.forgetpwd_find_verifybtn); nextBtn = (Button) findViewById(R.id.forgetpwd_find_nextbtn); mLine = (LinearLayout) findViewById(R.id.forgetpaw_id); } @Override public void onClick(View v) { verify = verifyEt.getText().toString().trim(); tel = etphone.getText().toString().trim(); Log.i("mytag","shoujihao"+tel+"==="+verify); switch (v.getId()) { case R.id.forgetpaw_id: // ����ⲿ������ʧ AppConfig.CloseKey(FindPwdActivity.this, v); break; case R.id.forgetpwd_find_verifybtn: /*** * �ж��Ƿ������� */ int netWork = CommonUtil.isNetworkAvailable(FindPwdActivity.this); if (netWork == 1 || netWork == 2 || netWork == 3) { if ("".equals(tel) || tel == null) { ToastUtil.show(this, "�ֻ��Ų���Ϊ��"); } else if (tel.length() != 11) { ToastUtil.show(FindPwdActivity.this, "������11λ���ֻ���"); } else { // �������ǻ�ȡ��֤�� phoneTextView.onCreate(savedInstanceState); phoneTextView.setTextAfter("������»�ȡ").setTextBefore("��ȡ��֤��").setLenght(60 * 1000); AjaxParams params = new AjaxParams(); params.put("phone",tel); FinalHttp fh = new FinalHttp(); fh.post(InternetURL.CHECKPHONE, params, new AjaxCallBack<String>() { @Override public void onSuccess(String t) { Toast.makeText(FindPwdActivity.this,"��֤�뷢�ͳɹ�", Toast.LENGTH_SHORT).show(); Log.i("mytag", "����" + t); } @Override public void onFailure(Throwable t, int errorNo, String strMsg) { Toast.makeText(FindPwdActivity.this,"��֤�뷢��ʧ��", Toast.LENGTH_SHORT).show(); } }); } } else { PromptManager.showNoNetWork(FindPwdActivity.this); } break; case R.id.forgetpwd_find_nextbtn: int netWorkType = CommonUtil .isNetworkAvailable(FindPwdActivity.this); if (netWorkType == 1 || netWorkType == 2 || netWorkType == 3) { if ("".equals(tel) || tel == null) { ToastUtil.show(FindPwdActivity.this, "�ֻ��Ų���Ϊ��"); } else if (tel.length() != 11) { ToastUtil.show(FindPwdActivity.this, "������11λ���ֻ���"); }else if ("".equals(verify) || verify == null) { ToastUtil.show(FindPwdActivity.this, "��֤�벻��Ϊ��"); } else if (verify.length()!=5) { ToastUtil.show(FindPwdActivity.this, "������5λ��֤��"); } else { AjaxParams params=new AjaxParams(); params.put("phone", tel); params.put("code", verify); FinalHttp fh=new FinalHttp(); fh.post(InternetURL.CHECK_PHONE_NUMBER,params,new AjaxCallBack<String>() { @Override public void onFailure(Throwable t, int errorNo, String strMsg) { super.onFailure(t, errorNo, strMsg); ToastUtil.show(FindPwdActivity.this,"��ȡ����ʧ��"); } @Override public void onSuccess(String t) { super.onSuccess(t); String json=t.toString(); if(!"".equals(json)||json!=null){ try { JSONObject json1=new JSONObject(json); int code=json1.getInt("code"); String info=json1.getString("info"); if(code==200){ Intent it = new Intent(FindPwdActivity.this, ResetPwdActivity.class); it.putExtra("phone",tel); startActivity(it); }else if(code==405){ ToastUtil.show(FindPwdActivity.this,info); }else if(code==406){ ToastUtil.show(FindPwdActivity.this,info); } } catch (JSONException e) { e.printStackTrace(); } } } }); } } else { PromptManager.showNoNetWork(FindPwdActivity.this); } break; } } @Override protected void onDestroy() { phoneTextView.onDestroy(); super.onDestroy(); } }