ChangeElectronicCardAdressInfoActivity.java
8.62 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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
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 = "register";
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<CityInfo.CitiesBean> 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<CountyInfo.CountiesBean> 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<ProvinceInfo.ProvincesBean> 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);
}
}