ElectronicCardValidationActivity.java
16.4 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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
package com.hjx.personalcenter.activity;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v4.app.FragmentActivity;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.hjx.personalcenter.R;
import com.hjx.personalcenter.db.Content;
import com.hjx.personalcenter.db.SaveParam;
import com.hjx.personalcenter.http.HttpCode;
import com.hjx.personalcenter.http.HttpManager;
import com.hjx.personalcenter.util.AlertUtils;
import com.hjx.personalcenter.util.GetDevicesUtil;
import com.hjx.personalcenter.util.PhoneNumCheckUtils;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.TimerTask;
/**
* Created by h on 2017/8/9.
*/
public class ElectronicCardValidationActivity extends FragmentActivity implements View.OnClickListener {
private Button btn_card_valiyanzhen, get_authcode;
private EditText phonenumber, anth_6num, activation_code;//;//密码
private ImageButton phone_delete_btn, code_delete_btn, activation_code_delete_btn;
private TextView menu_title;
private ImageView cancel;
private int delayTime = 60;
private LinearLayout rl_authcode, activation_code_layout;
private java.util.Timer Delaytimer;
private String sourceStr = "android";
private String typeStr = "general";
String authcode = "";
Handler handler = new Handler() {
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
JSONObject jsonObject;
String status;
switch (msg.what) {
case HttpCode.AUTHCODE_SUCESS:
jsonObject = (JSONObject) msg.obj;
status = jsonObject.optString("status");
authcode = jsonObject.optString("jsessionid");
if (status.equals("100")) {
AlertUtils.showToast(ElectronicCardValidationActivity.this, "验证码发送成功");
}
break;
case HttpCode.AUTHCODE_FAIL:
AlertUtils.showToast(ElectronicCardValidationActivity.this, "验证码发送失败");
break;
case 21:
if (delayTime <= 0) {
if (Delaytimer != null) {
Delaytimer.cancel();
}
get_authcode.setEnabled(true);
get_authcode.setClickable(true);
get_authcode.setText("获取验证码");
delayTime = 60;
} else {
get_authcode.setEnabled(false);
get_authcode.setClickable(false);
get_authcode.setText(delayTime + " s");
}
break;
case HttpCode.ACTIVATION_SUCCESS:
jsonObject = (JSONObject) msg.obj;
status = jsonObject.optString("status");
if(status.equals("1")){
AlertUtils.showToast(ElectronicCardValidationActivity.this, "激活成功");
String phone = phonenumber.getText().toString().trim();
Intent intent = new Intent();
intent.putExtra(SaveParam.CARDPHONE, phone);
intent.setClass(ElectronicCardValidationActivity.this, ElectronicCardEditInfoActivity.class);
startActivity(intent);
overridePendingTransition(R.anim.rightin, R.anim.rightout);
}else if(status.equals("5001")){
AlertUtils.showToast(ElectronicCardValidationActivity.this, "激活码无效");
}else if(status.equals("0")){
AlertUtils.showToast(ElectronicCardValidationActivity.this, "无法链接到服务器,请检查您的网络或稍后重试");
}
break;
}
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_electroniccard_validation);
SysApplication.getInstance().addActivity(this);
initView();
initData();
initLister();
initTextWatch();
}
private void initView() {
btn_card_valiyanzhen = (Button) findViewById(R.id.btn_card_valiyanzhen);
get_authcode = (Button) findViewById(R.id.btn_authcode);
anth_6num = (EditText) findViewById(R.id.et_authcode);
phonenumber = (EditText) findViewById(R.id.et_phonenumber);
activation_code = (EditText) findViewById(R.id.activation_code);
menu_title = (TextView) findViewById(R.id.menu_title);
cancel = (ImageView) findViewById(R.id.cancel);
code_delete_btn = (ImageButton) findViewById(R.id.code_delete_btn);
phone_delete_btn = (ImageButton) findViewById(R.id.phone_delete_btn);
activation_code_delete_btn = (ImageButton) findViewById(R.id.activation_code_delete_btn);
rl_authcode = (LinearLayout) findViewById(R.id.rl_authcode);
activation_code_layout = (LinearLayout) findViewById(R.id.activation_code_layout);
}
private void initData() {
phonenumber.setText(SaveParam.getInstance().getLoginParam(this, "username"));
if (Content.authcodeflag == 1) {
menu_title.setText("更换绑定");
btn_card_valiyanzhen.setText("确定");
phonenumber.setText("");
rl_authcode.setVisibility(View.VISIBLE);
} else if (Content.authcodeflag == 2) {
menu_title.setText("修改保卡信息");
btn_card_valiyanzhen.setText("确定");
rl_authcode.setVisibility(View.VISIBLE);
anth_6num.requestFocus();
} else {
if (Build.MODEL.toUpperCase().equals("T5 PLUS")) {//T5 PLUS需要输入注册激活码
menu_title.setText("激活机器并确认绑定保卡的手机号");
activation_code_layout.setVisibility(View.VISIBLE);
} else {
menu_title.setText("确认绑定保卡的手机号");
activation_code_layout.setVisibility(View.GONE);
}
btn_card_valiyanzhen.setText("下一步");
anth_6num.requestFocus();
}
}
private void initLister() {
get_authcode.setOnClickListener(this);
btn_card_valiyanzhen.setOnClickListener(this);
cancel.setOnClickListener(this);
phone_delete_btn.setOnClickListener(this);
code_delete_btn.setOnClickListener(this);
activation_code_delete_btn.setOnClickListener(this);
}
/**
* 输入框改变的监听
*/
private void initTextWatch() {
phonenumber.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if (s.toString().length() == 0) {
phone_delete_btn.setVisibility(View.INVISIBLE);
} else {
phone_delete_btn.setVisibility(View.VISIBLE);
}
if (Build.MODEL.toUpperCase().equals("T5 PLUS")) {
if (!menu_title.getText().toString().equals("激活机器并确认绑定保卡的手机号") || s.toString().length() == 0 || !s.toString().equals(SaveParam.getInstance().getLoginParam(ElectronicCardValidationActivity.this, "username"))) {
rl_authcode.setVisibility(View.VISIBLE);
} else {
rl_authcode.setVisibility(View.GONE);
}
} else {
if (!menu_title.getText().toString().equals("确认绑定保卡的手机号") || s.toString().length() == 0 || !s.toString().equals(SaveParam.getInstance().getLoginParam(ElectronicCardValidationActivity.this, "username"))) {
rl_authcode.setVisibility(View.VISIBLE);
} else {
rl_authcode.setVisibility(View.GONE);
}
}
}
@Override
public void afterTextChanged(Editable s) {
}
});
phonenumber.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus) {
if (!phonenumber.getText().toString().isEmpty()) {
phone_delete_btn.setVisibility(View.VISIBLE);
}
} else {
phone_delete_btn.setVisibility(View.INVISIBLE);
}
}
});
anth_6num.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if (s.toString().length() == 0) {
code_delete_btn.setVisibility(View.INVISIBLE);
} else {
code_delete_btn.setVisibility(View.VISIBLE);
}
}
@Override
public void afterTextChanged(Editable s) {
}
});
anth_6num.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus) {
if (!anth_6num.getText().toString().isEmpty()) {
code_delete_btn.setVisibility(View.VISIBLE);
}
} else {
code_delete_btn.setVisibility(View.INVISIBLE);
}
}
});
activation_code.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if (s.toString().length() == 0) {
activation_code_delete_btn.setVisibility(View.INVISIBLE);
} else {
activation_code_delete_btn.setVisibility(View.VISIBLE);
}
}
@Override
public void afterTextChanged(Editable s) {
}
});
activation_code.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus) {
if (!activation_code.getText().toString().isEmpty()) {
activation_code_delete_btn.setVisibility(View.VISIBLE);
}
} else {
activation_code_delete_btn.setVisibility(View.INVISIBLE);
}
}
});
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.btn_card_valiyanzhen:
String userID22 = GetDevicesUtil.getDevicesInfo(this).getDeviceNumber();
String usernameStr = phonenumber.getText().toString().trim();
String authcodeStr = anth_6num.getText().toString().trim();
String activationStr = activation_code.getText().toString().trim();
if (TextUtils.isEmpty(usernameStr)) {
AlertUtils.showToast(ElectronicCardValidationActivity.this, "手机号不能为空");
return;
} else if (activation_code_layout.getVisibility() == View.VISIBLE && TextUtils.isEmpty(activationStr)) {
AlertUtils.showToast(ElectronicCardValidationActivity.this, "注册激活码不能为空");
return;
}else if (rl_authcode.getVisibility() == View.VISIBLE && TextUtils.isEmpty(authcodeStr)) {
AlertUtils.showToast(ElectronicCardValidationActivity.this, "验证码不能为空");
return;
} else if (!PhoneNumCheckUtils.isPhone(usernameStr)) {
AlertUtils.showToast(ElectronicCardValidationActivity.this, "手机号码输入错误");
} else if (!authcode.equals(authcodeStr)) {
AlertUtils.showToast(ElectronicCardValidationActivity.this, "您输入的验证码不正确");
} else {
String userID = SaveParam.getInstance().getLoginParam(this, "userId");
Long auserID = null;
try {
auserID = Long.parseLong(userID);
} catch (NumberFormatException e) {
e.printStackTrace();
}
if (Content.authcodeflag == 1) {
//修改账户手机号
HttpManager.getInstance().changeaccountphone(this,
auserID, usernameStr, authcodeStr);
} else if (Content.authcodeflag == 2) {
//修改保卡手机号
HttpManager.getInstance().changecardinfophone(this,
userID22, usernameStr, authcodeStr);
} else {
if(Build.MODEL.toUpperCase().equals("T5 PLUS")){
HttpManager.getInstance().submitEcard(this,userID22,activationStr,handler);
} else{
String phone = phonenumber.getText().toString().trim();
// SaveParam.getInstance().saveCustomizeParam(this, SaveParam.CARDPHONE, phone);
Intent intent = new Intent();
intent.putExtra(SaveParam.CARDPHONE, phone);
intent.setClass(ElectronicCardValidationActivity.this, ElectronicCardEditInfoActivity.class);
startActivity(intent);
overridePendingTransition(R.anim.rightin, R.anim.rightout);
}
}
// SaveParam.getInstance().saveLoginParam(this,SaveParam.CARDPHONE, phonenumber.getText().toString().trim());
// Intent intent = new Intent();
// intent.setClass(ElectronicCardValidationActivity.this, ElectronicCardEditInfoActivity.class);
// startActivity(intent);
// overridePendingTransition(R.anim.rightin, R.anim.rightout);
}
break;
case R.id.btn_authcode:
String usernameStr1 = phonenumber.getText().toString().trim();
if (!PhoneNumCheckUtils.isPhone(usernameStr1)) {
AlertUtils.showToast(ElectronicCardValidationActivity.this, "请输入正确的手机号");
} else {
anth_6num.requestFocus();
HttpManager.getInstance().authCode(typeStr, usernameStr1, handler, ElectronicCardValidationActivity.this);
valiDelay();
}
break;
case R.id.cancel:
finish();
break;
case R.id.phone_delete_btn:
phonenumber.setText("");
break;
case R.id.code_delete_btn:
anth_6num.setText("");
break;
case R.id.activation_code_delete_btn:
activation_code.setText("");
break;
}
}
// 线程类 定时器
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);
}
}