InputCodeActivity.java
6.07 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
package com.ectrip.cyt.ui;
import java.lang.reflect.Method;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.InputType;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import com.ectrip.cyt.shield_home.LockLayer.MToast;
import com.ectrip.cyt.utils.ActivitiesManager;
import com.ectrip.cyt.utils.CommetryUtils;
import com.ectrip.cyt.utils.SharedPreferences2Obj;
import com.ectrip.trips.check.R;
import com.ectrip.trips.view.LongClickButton;
import com.ectrip.trips.view.LongClickButton.LongClickRepeatListener;
/**
* 验证码输入界面
*/
public class InputCodeActivity extends BaseActivity implements
View.OnClickListener,LongClickRepeatListener {
private String titleName;
private EditText et_sfz;// 验证码
private TextView one, two, three, four, five, six, seven, eight, nine, zero,
X_btn, topBtns;
private LongClickButton delete;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.app_input_idcard);
ActivitiesManager.getInstance().pushActivity(this);
initView();
}
@SuppressLint("NewApi")
private void initView() {
SharedPreferences2Obj.getInstance(InputCodeActivity.this)
.setName("SelectAction").setObject("isStatistic", "0"); // 非统计
titleName = getIntent().getStringExtra("titleName");
if (titleName != null) {
((TextView) findViewById(R.id.title)).setText(titleName);
} else {
((TextView) findViewById(R.id.title))
.setText(getString(R.string.input_verify_code));
}
((TextView) findViewById(R.id.title)).setVisibility(View.VISIBLE);
topBtns = (Button) findViewById(R.id.topBtns);
topBtns.setVisibility(View.VISIBLE);
findViewById(R.id.topBack).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
et_sfz = (EditText) findViewById(R.id.input_idcard);
et_sfz.setHint(getString(R.string.input_verify_code));
one = (TextView) findViewById(R.id.one);
one.setOnClickListener(this);
two = (TextView) findViewById(R.id.two);
two.setOnClickListener(this);
three = (TextView) findViewById(R.id.three);
three.setOnClickListener(this);
four = (TextView) findViewById(R.id.four);
four.setOnClickListener(this);
five = (TextView) findViewById(R.id.five);
five.setOnClickListener(this);
six = (TextView) findViewById(R.id.six);
six.setOnClickListener(this);
seven = (TextView) findViewById(R.id.seven);
seven.setOnClickListener(this);
eight = (TextView) findViewById(R.id.eight);
eight.setOnClickListener(this);
nine = (TextView) findViewById(R.id.nine);
nine.setOnClickListener(this);
zero = (TextView) findViewById(R.id.zero);
zero.setOnClickListener(this);
X_btn = (TextView) findViewById(R.id.X_btn);
X_btn.setOnClickListener(this);
delete = (LongClickButton) findViewById(R.id.delete);
delete.setOnClickListener(this);
delete.setLongClickRepeatListener(this);
topBtns.setText(getString(R.string.topbtn_ok));
topBtns.setOnClickListener(this);
et_sfz.requestFocus();
if (android.os.Build.VERSION.SDK_INT >= 11) {
try {
et_sfz.setShowSoftInputOnFocus(false);
} catch (Exception e) {
e.printStackTrace();
textViewShow(et_sfz);
// et_sfz.setInputType(InputType.TYPE_NULL);
} catch (Throwable e) {
e.printStackTrace();
textViewShow(et_sfz);
// et_sfz.setInputType(InputType.TYPE_NULL);
}
} else {
textViewShow(et_sfz);
// et_sfz.setInputType(InputType.TYPE_NULL);
}
}
private void textViewShow(EditText message) {
if (android.os.Build.VERSION.SDK_INT <= 10) {
message.setInputType(InputType.TYPE_NULL);
} else {
getWindow().setSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
try {
Class<EditText> cls = EditText.class;
Method setSoftInputShownOnFocus = cls.getMethod(
"setSoftInputShownOnFocus", boolean.class);
setSoftInputShownOnFocus.setAccessible(true);
setSoftInputShownOnFocus.invoke(message, false);
} catch (Exception e) {
}
}
}
@Override
public void onClick(View v) {
int index = 0;
Editable editable = null;
if (et_sfz.isFocused()) {
index = et_sfz.getSelectionStart();
editable = et_sfz.getText();
}
switch (v.getId()) {
case R.id.topBtns:
String str = et_sfz.getText().toString();
if (str == null || "".equals(str)) {
MToast(InputCodeActivity.this,
getString(R.string.verify_not_null),
MToast.LENGTH_SHORT);
return;
}
Intent intent = new Intent(InputCodeActivity.this,
CodeOrderListActivity.class);
intent.putExtra("mode", 0);
intent.putExtra("code", str);
intent.putExtra("titleName", getString(R.string.order_list));
startActivity(intent);
break;
case R.id.delete:
if (editable.length() > 0) {
try {
editable.delete(index - 1, index);
} catch (Exception e) {
if (editable.length() > 0) {
editable.delete(index, index + 1);
}
}
}
break;
default:
if (editable.length() < 18) {
editable.insert(index, ((TextView) v).getText());
}
break;
}
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
try {
CommetryUtils.releaseCommery(this);
} catch (Exception e) {
e.printStackTrace();
}
finish();
}
return false;
}
@Override
protected void onDestroy() {
super.onDestroy();
try {
CommetryUtils.releaseCommery(this);
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void repeatAction() {
int index = 0;
Editable editable = null;
if (et_sfz.isFocused()) {
index = et_sfz.getSelectionStart();
editable = et_sfz.getText();
}
if (editable.length() > 0) {
try {
editable.delete(index - 1, index);
} catch (Exception e) {
if (editable.length() > 0) {
editable.delete(index, index + 1);
}
}
}
}
}