ChangeElectronicCardAdressInfoActivity.java
6.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
package com.hjx.personalcenter.activity;
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import com.hjx.personalcenter.R;
import com.hjx.personalcenter.http.HttpCode;
import com.hjx.personalcenter.http.HttpManager;
import com.hjx.personalcenter.util.AlertUtils;
import com.hjx.personalcenter.util.Judgment;
import com.hjx.personalcenter.util.PhoneNumCheckUtils;
import org.json.JSONObject;
/**
* Created by h on 2017/8/9.
*/
public class ChangeElectronicCardAdressInfoActivity extends Activity implements View.OnClickListener{
private ImageView back_forgit;
private EditText forot_pwd_phone,forot_pwd_anthcode,adress,newadress;
private Button forot_pwd_sub,forot_pwd_getanthcode;
private String typeStr = "register";
private int i = 0;
private Thread thread;
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 1:
forot_pwd_getanthcode.setEnabled(false);
forot_pwd_getanthcode.setClickable(false);
forot_pwd_getanthcode.setText(Integer.toString(i--)+" s");
if (i<=0){
forot_pwd_getanthcode.setEnabled(true);
forot_pwd_getanthcode.setClickable(true);
forot_pwd_getanthcode.setText("获取验证码");
}
break;
}
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_change_card_validation);
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);
i = 60;
if(thread == null){
thread = new Thread( new ThreadShow());
thread.start();
}
}
private void initView() {
forot_pwd_phone = (EditText) findViewById(R.id.et_phonenumber);
forot_pwd_anthcode = (EditText) findViewById(R.id.et_authcode);
adress = (EditText) 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);
}
@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 {
//修改地址接口
HttpManager.getInstance().changecardadressinfo(this,111,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.cancel:
finish();
break;
}
}
// 线程类 定时器
class ThreadShow implements Runnable {
@Override
public void run() {
// TODO Auto-generated method stub
while (true) {
try {
Thread.sleep(1000);
Message msg = new Message();
msg.what = 1;
handler.sendMessage(msg);
System.out.println("send...");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
System.out.println("thread error...");
}
}
}
}
}