Blame view

src/com/ectrip/cyt/ui/MainActivity.java 38 KB
3c2353cd   杜方   1、畅游通核销app源码提交;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
  package com.ectrip.cyt.ui;
  
  import static com.ectrip.cyt.utils.DesUtil.decrypt1;
  import static com.ectrip.cyt.utils.DesUtil.desCrypto;
  
  import android.app.ActionBar;
  import android.app.AlertDialog;
  import android.app.AlertDialog.Builder;
  import android.app.Dialog;
  import android.app.ProgressDialog;
  import android.content.Context;
  import android.content.DialogInterface;
  import android.content.DialogInterface.OnClickListener;
  import android.content.Intent;
  import android.graphics.Bitmap;
  import android.graphics.BitmapFactory;
8094643a   黄灿宏   畅游通核销app: 1.适配之前机...
17
  import android.os.Build;
3c2353cd   杜方   1、畅游通核销app源码提交;
18
  import android.os.Bundle;
07670a44   黄灿宏   畅游通核销app: 1.增加日志上...
19
  import android.os.Handler;
3c2353cd   杜方   1、畅游通核销app源码提交;
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
  import android.text.InputType;
  import android.text.TextUtils;
  import android.util.DisplayMetrics;
  import android.view.Display;
  import android.view.KeyEvent;
  import android.view.View;
  import android.view.WindowManager;
  import android.view.inputmethod.InputMethodManager;
  import android.widget.AdapterView;
  import android.widget.AdapterView.OnItemClickListener;
  import android.widget.EditText;
  import android.widget.GridView;
  import android.widget.ImageView;
  import android.widget.ImageView.ScaleType;
  import android.widget.TextView;
  import android.widget.Toast;
  
  import com.ectrip.cyt.adapter.MainGridDataAdapter;
  import com.ectrip.cyt.base.DataTrans;
  import com.ectrip.cyt.bean.ConfigBean;
  import com.ectrip.cyt.bean.ImageInfo;
  import com.ectrip.cyt.callback.HttpCallback;
  import com.ectrip.cyt.config.BindService;
  import com.ectrip.cyt.config.DevicTool;
  import com.ectrip.cyt.config.MyApp;
  import com.ectrip.cyt.constant.DeviceType;
  import com.ectrip.cyt.constant.LogoType;
  import com.ectrip.cyt.constant.Module;
  import com.ectrip.cyt.constant.OrderCode;
07670a44   黄灿宏   畅游通核销app: 1.增加日志上...
49
  import com.ectrip.cyt.constant.ParamContants;
3c2353cd   杜方   1、畅游通核销app源码提交;
50
51
52
53
  import com.ectrip.cyt.constant.SelectAction;
  import com.ectrip.cyt.constant.constant;
  import com.ectrip.cyt.db.DbManager;
  import com.ectrip.cyt.response.LoginResponse;
07670a44   黄灿宏   畅游通核销app: 1.增加日志上...
54
  import com.ectrip.cyt.service.FtpParamerService;
3c2353cd   杜方   1、畅游通核销app源码提交;
55
  import com.ectrip.cyt.service.OrderRegularDelecteService;
07670a44   黄灿宏   畅游通核销app: 1.增加日志上...
56
  import com.ectrip.cyt.service.UploadLogService;
3c2353cd   杜方   1、畅游通核销app源码提交;
57
58
59
60
61
62
  import com.ectrip.cyt.shield_home.LockLayer.MToast;
  import com.ectrip.cyt.utils.AESEncryptor;
  import com.ectrip.cyt.utils.CommetryUtils;
  import com.ectrip.cyt.utils.DenstityUtils;
  import com.ectrip.cyt.utils.DesUtil;
  import com.ectrip.cyt.utils.LogUtil;
07670a44   黄灿宏   畅游通核销app: 1.增加日志上...
63
  import com.ectrip.cyt.utils.PreferenceUtils;
3c2353cd   杜方   1、畅游通核销app源码提交;
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
  import com.ectrip.cyt.utils.SharedPreferences2Obj;
  import com.ectrip.trips.check.R;
  import com.ectrip.trips.net.HttpHelper;
  import com.fri.idcread.idcread;
  
  import java.io.File;
  import java.io.InputStream;
  import java.lang.reflect.Method;
  import java.util.ArrayList;
  
  import hdx.HdxUtil;
  
  /**
   * @author jigo 首页
   */
  public class MainActivity extends BaseActivity implements OnItemClickListener, View.OnClickListener {
      private final int SETTING_REQUESTCODE = 1;
      private final String TAG = "MainActivity";
      private GridView gridView1;
      private MainGridDataAdapter adapter;
      private ArrayList<ConfigBean> listConfig;
      private ImageView logo;
      private TextView login;
      private TextView unlogin;
      private TextView tv_username;
07670a44   黄灿宏   畅游通核销app: 1.增加日志上...
89
      private final Handler mHandler = new Handler();
3c2353cd   杜方   1、畅游通核销app源码提交;
90
91
92
93
94
95
96
97
98
99
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.app_main);
  
          deleteConfigFile();
          initData();
          initView();
          regularDelecte();
          typeJudgment();
8094643a   黄灿宏   畅游通核销app: 1.适配之前机...
100
          LogUtil.e(TAG, "硬件序列号 : " + getSerialNumber() + ",型号 :" + Build.MODEL);
07670a44   黄灿宏   畅游通核销app: 1.增加日志上...
101
102
103
104
105
106
          mHandler.postDelayed(new Runnable() {
              @Override
              public void run() {
                  initService();
              }
          }, 3000);
3c2353cd   杜方   1、畅游通核销app源码提交;
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
      }
  
      /**
       * 删除配置文件
       */
  
      private void deleteConfigFile() {
  
          try {
  
              File file = new File(constant.SelectionDir);
  
              if (file.exists()) {
  
                  file.delete();
              }
  
          } catch (Exception e) {
              e.printStackTrace();
          }
  
      }
  
07670a44   黄灿宏   畅游通核销app: 1.增加日志上...
130
131
132
133
134
135
136
137
138
      private void initService() {
  
          Intent ftp = new Intent(this, FtpParamerService.class);
          startService(ftp);
  
          Intent upLoad = new Intent(this, UploadLogService.class);
          startService(upLoad);
      }
  
3c2353cd   杜方   1、畅游通核销app源码提交;
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
  
      /**
       * 获取硬件的序列号
       */
      public String getSerialNumber() {
          String serial = null;
          try {
              Class<?> c = Class.forName("android.os.SystemProperties");
              Method get = c.getMethod("get", String.class);
              serial = (String) get.invoke(c, "ro.serialno");
          } catch (Exception e) {
              e.printStackTrace();
          }
          return serial;
      }
  
      /**
       * 机器类型判断
       */
      private void typeJudgment() {
8094643a   黄灿宏   畅游通核销app: 1.适配之前机...
159
160
161
  //        //机型
  //        String model = Build.MODEL;
  //        String sn = android.os.Build.MODEL;
3c2353cd   杜方   1、畅游通核销app源码提交;
162
163
164
          // 得到存储的类型
          Integer type = SharedPreferences2Obj.getInstance(MainActivity.this)
                  .setName("MachineType").getObject("type", Integer.class);
8094643a   黄灿宏   畅游通核销app: 1.适配之前机...
165
  
3c2353cd   杜方   1、畅游通核销app源码提交;
166
167
168
169
170
171
172
173
174
175
176
177
          //如果未存储类型
          if (type == null || type == 0) {
              DisplayMetrics metrics = new DisplayMetrics();
              getWindowManager().getDefaultDisplay().getMetrics(metrics);
              int width = metrics.widthPixels;
              int height = metrics.heightPixels;
              if ((getSerialNumber() != null && getSerialNumber().contains("CYT") && getSerialNumber()
                      .substring(0, 3).equals("CYT"))
                      || (getSerialNumber() != null
                      && getSerialNumber().contains("CTY") && getSerialNumber()
                      .substring(0, 3).equals("CTY"))) {
                  // 新的pos机
8094643a   黄灿宏   畅游通核销app: 1.适配之前机...
178
                  LogUtil.i(TAG, getString(R.string.new_pos));
3c2353cd   杜方   1、畅游通核销app源码提交;
179
180
181
182
183
184
185
186
                  SharedPreferences2Obj.getInstance(MainActivity.this)
                          .setName("MachineType")
                          .setObject("type", DeviceType.New_POS.getValue());
              } else if ((getSerialNumber() != null
                      && getSerialNumber().contains("LY") && getSerialNumber()
                      .substring(0, 2).equals("LY"))) {
                  release();
                  // 新的手持pos机
8094643a   黄灿宏   畅游通核销app: 1.适配之前机...
187
                  LogUtil.i(TAG, getString(R.string.new_handset_pos));
3c2353cd   杜方   1、畅游通核销app源码提交;
188
189
190
191
192
193
194
195
196
                  SharedPreferences2Obj
                          .getInstance(MainActivity.this)
                          .setName("MachineType")
                          .setObject("type",
                                  DeviceType.New_HANDSET_POS.getValue());
              } else if ((getSerialNumber() != null
                      && getSerialNumber().contains("DY") && getSerialNumber()
                      .substring(0, 2).equals("DY"))) {
                  // 新的身份证pos机
8094643a   黄灿宏   畅游通核销app: 1.适配之前机...
197
                  LogUtil.i(TAG, getString(R.string.new_id_pos));
3c2353cd   杜方   1、畅游通核销app源码提交;
198
199
200
                  SharedPreferences2Obj.getInstance(MainActivity.this)
                          .setName("MachineType")
                          .setObject("type", DeviceType.New_IDPOS.getValue());
8094643a   黄灿宏   畅游通核销app: 1.适配之前机...
201
202
              } else if (DevicTool.isHiboryPos()) {
                  LogUtil.i(TAG, "5501H手持机");
72876d86   杜方   畅游通核销app: 1.增加550...
203
204
205
                  SharedPreferences2Obj.getInstance(MainActivity.this)
                          .setName("MachineType")
                          .setObject("type", DeviceType.BLACK_ID_POS.getValue());
8094643a   黄灿宏   畅游通核销app: 1.适配之前机...
206
207
208
209
210
              } else if (DevicTool.isRSKPos()) {
                  LogUtil.i(TAG, "RSK手持机");
                  SharedPreferences2Obj.getInstance(MainActivity.this)
                          .setName("MachineType")
                          .setObject("type", DeviceType.ID_CARD_POS_RSK.getValue());
3c2353cd   杜方   1、畅游通核销app源码提交;
211
212
              } else if (HdxUtil.SetIDCARDPower(1) != -1) {
                  // 身份证pos机
8094643a   黄灿宏   畅游通核销app: 1.适配之前机...
213
                  LogUtil.i(TAG, getString(R.string.id_pos));
3c2353cd   杜方   1、畅游通核销app源码提交;
214
215
216
217
218
219
220
                  SharedPreferences2Obj.getInstance(MainActivity.this)
                          .setName("MachineType")
                          .setObject("type", DeviceType.ID_POS.getValue());
              } else if (idcread.isIdcard("/dev/ttySAC1")
                      || DevicTool.getInstance().isSerialPortHandset()) {
                  release();
                  // 黄色手持机
8094643a   黄灿宏   畅游通核销app: 1.适配之前机...
221
                  LogUtil.i(TAG, getString(R.string.handset));
3c2353cd   杜方   1、畅游通核销app源码提交;
222
223
224
225
226
227
228
229
230
                  SharedPreferences2Obj.getInstance(MainActivity.this)
                          .setName("MachineType")
                          .setObject("type", DeviceType.HANDSET.getValue());
              } else if ((DevicTool.getInstance().isSerialPort() || DevicTool
                      .getInstance().isIdPosPrint())
                      && width <= 350
                      && height <= 500) {
                  release();
                  // 小pos机
8094643a   黄灿宏   畅游通核销app: 1.适配之前机...
231
                  LogUtil.i(TAG, getString(R.string.small_pos));
3c2353cd   杜方   1、畅游通核销app源码提交;
232
233
234
235
236
237
                  SharedPreferences2Obj.getInstance(MainActivity.this)
                          .setName("MachineType")
                          .setObject("type", DeviceType.SMALL_POS.getValue());
              } else if (DevicTool.getInstance().isSerialPort()
                      || DevicTool.getInstance().isIdPosPrint()) {
                  // 一般pos机
8094643a   黄灿宏   畅游通核销app: 1.适配之前机...
238
                  LogUtil.i(TAG, getString(R.string.general_pos));
3c2353cd   杜方   1、畅游通核销app源码提交;
239
240
241
242
243
244
245
                  SharedPreferences2Obj.getInstance(MainActivity.this)
                          .setName("MachineType")
                          .setObject("type", DeviceType.GENERAL_POS.getValue());
              }
              //盛本pos机测试*******************************
              else if (BindService.getInstance().isBasewin()) {
                  // 盛本pos机
8094643a   黄灿宏   畅游通核销app: 1.适配之前机...
246
                  LogUtil.i(TAG, "盛本POS机");
3c2353cd   杜方   1、畅游通核销app源码提交;
247
248
249
250
251
252
253
254
                  SharedPreferences2Obj.getInstance(MainActivity.this)
                          .setName("MachineType")
                          .setObject("type", DeviceType.BASEWIN_REB_POS.getValue());
              }
              //盛本pos机测试*******************************
              else {
                  release();
                  // 手机
8094643a   黄灿宏   畅游通核销app: 1.适配之前机...
255
                  LogUtil.i(TAG, getString(R.string.mobile));
3c2353cd   杜方   1、畅游通核销app源码提交;
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
                  SharedPreferences2Obj.getInstance(MainActivity.this)
                          .setName("MachineType")
                          .setObject("type", DeviceType.MOBILE.getValue());
              }
          }
      }
  
      /**
       * 释放常亮
       */
      public void release() {
          try {
              if (wakeLock != null) {
                  wakeLock.release();
              }
          } catch (Exception e) {
              e.printStackTrace();
          }
      }
  
      /**
       * 开启服务去清除一定时间以上的数据
       */
      private void regularDelecte() {
          Intent intent = new Intent(MainActivity.this,
                  OrderRegularDelecteService.class);
          startService(intent);
      }
  
      @Override
      protected void onResume() {
          super.onResume();
          initConn();
          if (MyApp.getInstance().getAccountId() != null) {
              if (!TextUtils.isEmpty(MyApp.getInstance().getUsername())) {
                  login.setVisibility(View.GONE);
                  tv_username.setVisibility(View.VISIBLE);
                  tv_username.setText(MyApp.getInstance().getUsername() + " 已登录");
              }
          }
      }
  
      private boolean initConn() {
          listConfig = DbManager.GetConfigs();
          if (listConfig != null && listConfig.size() > 0) {
              MyApp.getInstance().setServiceIp(listConfig.get(0).getEc_ip());
              MyApp.getInstance().KeyStr = listConfig.get(0).getEc_identity();
07670a44   黄灿宏   畅游通核销app: 1.增加日志上...
303
              setFtpUrl(listConfig.get(0).getEc_ip());
3c2353cd   杜方   1、畅游通核销app源码提交;
304
305
306
307
              try {
                  String ec_signkey = AESEncryptor.decrypt(constant.decrypt,
                          listConfig.get(0).getEc_signkey());
                  MyApp.getInstance().setSignkey(ec_signkey);
8094643a   黄灿宏   畅游通核销app: 1.适配之前机...
308
                  LogUtil.i("MainActivity", "ec_signkey = " + ec_signkey);
3c2353cd   杜方   1、畅游通核销app源码提交;
309
310
311
312
              } catch (Exception e) {
                  e.printStackTrace();
              }
              MyApp.getInstance().setIdentity(listConfig.get(0).getEc_identity());
8094643a   黄灿宏   畅游通核销app: 1.适配之前机...
313
              LogUtil.i("MainActivity", "getEc_identity = " + listConfig.get(0).getEc_identity());
3c2353cd   杜方   1、畅游通核销app源码提交;
314
315
316
317
318
319
320
321
322
323
324
325
326
327
              LogUtil.d(TAG, getString(R.string.current_ip)
                      + MyApp.getInstance().getServiceIp());
              return true;
          } else {
              Intent intent = new Intent(MainActivity.this,
                      SettingsActivity.class);
              intent.putExtra("titleName", getString(R.string.system_setting));
              intent.putExtra("mode", "0");
              startActivityForResult(intent, SETTING_REQUESTCODE);
              return false;
          }
  
      }
  
07670a44   黄灿宏   畅游通核销app: 1.增加日志上...
328
329
330
331
332
333
      private void setFtpUrl(String ec_ip) {
          int endIndex = ec_ip.trim().indexOf("/");
          String url = ec_ip.trim().substring(0, endIndex);
          PreferenceUtils.putString(MyApp.getInstance(), ParamContants.SET_ip,url);
      }
  
3c2353cd   杜方   1、畅游通核销app源码提交;
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
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
      private void initView() {
          gridView1 = (GridView) findViewById(R.id.gridView1);
          adapter = new MainGridDataAdapter(MainActivity.this, initData());
          gridView1.setAdapter(adapter);
          gridView1.setOnItemClickListener(this);
  
          login = (TextView) findViewById(R.id.login);
          unlogin = (TextView) findViewById(R.id.unlogin);
          tv_username = (TextView) findViewById(R.id.username);
  
          login.setOnClickListener(this);
          unlogin.setOnClickListener(this);
  
          logo = (ImageView) findViewById(R.id.logo);
          if (constant.logoMark == LogoType.CYT.getValue()) {
  
              if (DevicTool.getInstance().isTablet(this)) {
                  setImg(logo, R.drawable.main_cyt_pad);
              } else {
                  setImg(logo, R.drawable.main_cyt);
              }
  
          } else if (constant.logoMark == LogoType.QNE.getValue()) {
              if (DevicTool.getInstance().isTablet(this)) {
                  setImg(logo, R.drawable.main_qnr_pad);
              } else {
  
                  setImg(logo, R.drawable.main_qne);
              }
          } else if (constant.logoMark == LogoType.EMC.getValue()) {
              if (DevicTool.getInstance().isTablet(this)) {
                  setImg(logo, R.drawable.main_emc_pad);
              } else {
  
                  setImg(logo, R.drawable.main_emc);
              }
          } else if (constant.logoMark == LogoType.LLT.getValue()) {
              if (DevicTool.getInstance().isTablet(this)) {
                  setImg(logo, R.drawable.main_lly_pad);
              } else {
  
                  setImg(logo, R.drawable.main_lly);
              }
          }
  
      }
  
      @SuppressWarnings("deprecation")
      private void setImg(ImageView imageView, int drawableId) {
          BitmapFactory.Options opt = new BitmapFactory.Options();
          opt.inPreferredConfig = Bitmap.Config.RGB_565;
          opt.inPurgeable = true;
          opt.inInputShareable = true;
          InputStream is = getResources().openRawResource(drawableId);
          Bitmap bm = BitmapFactory.decodeStream(is, null, opt);
          if (bm != null) {
              imageView.setScaleType(ScaleType.FIT_XY);
              imageView.setImageBitmap(bm);
          }
      }
  
      /**
       * 获取四个按钮的图片\文字
       *
       * @return
       */
      private ArrayList<ImageInfo> initData() {
          ArrayList<ImageInfo> data = new ArrayList<ImageInfo>();
          data.add(new ImageInfo(getString(R.string.check),
                  R.drawable.check_selector, R.drawable.icon_bg02, Module.CHECK));
          data.add(new ImageInfo(getString(R.string.reprint),
                  R.drawable.repaint_selector, R.drawable.icon_bg02, Module.REPRINT));
8094643a   黄灿宏   畅游通核销app: 1.适配之前机...
406
407
          data.add(new ImageInfo(getString(R.string.query),
                  R.drawable.check_order, R.drawable.icon_bg02, Module.QUERY));
3c2353cd   杜方   1、畅游通核销app源码提交;
408
409
410
411
412
413
          data.add(new ImageInfo(getString(R.string.system_setting),
                  R.drawable.set_selector, R.drawable.icon_bg02, Module.SETTING));
          data.add(new ImageInfo(getString(R.string.statistic),
                  R.drawable.statistic_selector, R.drawable.icon_bg02,
                  Module.STATISTIC));
          data.add(new ImageInfo(getString(R.string.about),
9e9f1eb7   杜方   1、畅游通核销app:新增主界面关...
414
                  R.drawable.about, R.drawable.icon_bg02,
3c2353cd   杜方   1、畅游通核销app源码提交;
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
                  Module.ABOUT));
          return data;
      }
  
      @Override
      public boolean onKeyDown(int keyCode, KeyEvent event) {
          if (keyCode == KeyEvent.KEYCODE_BACK) {
              dialog(SelectAction.Back.getValue());
          }
          return false;
      }
  
      ;
  
      private void dialog(final int i) {
          final EditText inputpress = new EditText(this);
          inputpress.setInputType(InputType.TYPE_CLASS_TEXT
                  | InputType.TYPE_TEXT_VARIATION_PASSWORD);
          Builder builder = new AlertDialog.Builder(this);
          if (i == SelectAction.Reprint.getValue()) {
              builder.setTitle(getString(R.string.input_pwd));
          } else if (i == SelectAction.Back.getValue()) {
              builder.setTitle(getString(R.string.input_exit_pwd));
          }
          builder.setIcon(android.R.drawable.ic_dialog_info);
          builder.setView(inputpress).setPositiveButton(
                  getString(R.string.btn_ok),
                  new DialogInterface.OnClickListener() {
                      @Override
                      public void onClick(DialogInterface dialog, int which) {
                          String password = inputpress.getText().toString();
                          if (listConfig != null
                                  && listConfig.size() > 0
                                  && password.equals(listConfig.get(0)
                                  .getEc_passwd())) {
                              if (i == SelectAction.Reprint.getValue()) {
                                  Intent intent;
                                  intent = new Intent(MainActivity.this,
                                          SelectActionActivity.class);
                                  // 设置选择的模式
                                  SharedPreferences2Obj
                                          .getInstance(MainActivity.this)
                                          .setName("SelectAction")
                                          .setObject("Select",
                                                  SelectAction.Reprint.getValue());
                                  SharedPreferences2Obj
                                          .getInstance(MainActivity.this)
                                          .setName("SelectAction")
                                          .setObject("titleName",
                                                  getString(R.string.reprint));
                                  intent.putExtra("titleName",
                                          getString(R.string.reprint));
                                  startActivity(intent);
                              } else if (i == SelectAction.Back.getValue()) {
                                  try {
                                      CommetryUtils
                                              .releaseCommery(MainActivity.this);
                                  } catch (Exception e) {
                                      e.printStackTrace();
                                  }
                                  finish();
                              }
                          } else if (listConfig != null && listConfig.size() == 0
                                  && constant.pwd.equals(password)) {
                              try {
                                  CommetryUtils.releaseCommery(MainActivity.this);
                              } catch (Exception e) {
                                  e.printStackTrace();
                              }
                              finish();
                          } else {
                              if (i == SelectAction.Back.getValue()) {
                                  MToast(MainActivity.this,
                                          getString(R.string.pwd_error_noexit),
                                          MToast.LENGTH_SHORT);
                              } else {
                                  MToast(MainActivity.this,
                                          getString(R.string.pwd_error),
                                          MToast.LENGTH_SHORT);
                              }
                          }
                          // 强制隐藏键盘
                          hideInpu(inputpress);
                      }
                  });
          builder.setNegativeButton(getString(R.string.btn_cancel),
                  new OnClickListener() {
                      @Override
                      public void onClick(DialogInterface dialog, int which) {
                          // 强制隐藏键盘
                          hideInpu(inputpress);
                      }
                  });
          AlertDialog dialog = builder.create();
          if (MyApp.getInstance().isHandset) {
              dialog.getWindow().setType(
                      WindowManager.LayoutParams.TYPE_SYSTEM_ERROR);
          }
          dialog.show();
      }
  
      @Override
      protected void onActivityResult(int requestCode, int resultCode, Intent data) {
          switch (requestCode) {
              case 1:
                  if (resultCode == 1) {
                      if (data == null) {
                          return;
                      }
                      if (initConn()) {
                          openDialog(getString(R.string.warm_prompt),
                                  getString(R.string.modiffy_success),
                                  getString(R.string.btn_ok));
                      }
                  }
                  break;
          }
      }
  
      private void openDialog(String title, String message, String button) {
          Builder builder = new Builder(MainActivity.this);
          builder.setTitle(title);
          builder.setMessage(message);
          builder.setNegativeButton(getString(R.string.btn_ok),
                  new OnClickListener() {
                      @Override
                      public void onClick(DialogInterface dialog, int which) {
                          try {
                              dialog.dismiss();
                          } catch (Exception e) {
                              e.printStackTrace();
                          } catch (Throwable e) {
                              e.printStackTrace();
                          }
                      }
                  });
          Dialog dialog = builder.create();
          if (MyApp.getInstance().isHandset) {
              dialog.getWindow().setType(
                      WindowManager.LayoutParams.TYPE_SYSTEM_ERROR);
          }
          dialog.show();
      }
  
      /*
       * 下面就是四个点击模块
       */
      @Override
      public void onItemClick(AdapterView<?> parent, View view, int position,
                              long id) {
          ImageInfo obj = (ImageInfo) view.getTag(R.id.imageView1);
          Intent intent = null;
          listConfig = DbManager.GetConfigs();
          switch (obj.getTag()) {
              case CHECK: // 检票
                  MyApp.getInstance().setCheckType(-1);
                  if (listConfig != null && listConfig.size() > 0) {
                      intent = new Intent(MainActivity.this,
                              SelectActionActivity.class);
                      intent.putExtra("titleName", getString(R.string.check));
                      SharedPreferences2Obj.getInstance(MainActivity.this)
                              .setName("SelectAction")
                              .setObject("Select", SelectAction.Check.getValue());
                      SharedPreferences2Obj.getInstance(MainActivity.this)
                              .setName("SelectAction")
                              .setObject("titleName", getString(R.string.check));
                      // 设置选择的模式
                      MyApp.getInstance().setTempMode(0);
                      startActivity(intent);
                  } else {
                      intent = new Intent(MainActivity.this, SettingsActivity.class);
                      intent.putExtra("titleName", getString(R.string.system_setting));
                      intent.putExtra("mode", "0");
                      startActivityForResult(intent, SETTING_REQUESTCODE);
                  }
                  break;
              case REPRINT: // 补打
                  MyApp.getInstance().setCheckType(-1);
                  if (listConfig != null && listConfig.size() > 0) {
                      Boolean isEncrypt = SharedPreferences2Obj
                              .getInstance(MainActivity.this).setName("config")
                              .getObject("isEncrypt", Boolean.class);
                      if (isEncrypt != null && isEncrypt) {
                          dialog(SelectAction.Reprint.getValue());
                      } else {
                          intent = new Intent(MainActivity.this,
                                  SelectActionActivity.class);
                          // 设置选择的模式
                          SharedPreferences2Obj
                                  .getInstance(MainActivity.this)
                                  .setName("SelectAction")
                                  .setObject("Select",
                                          SelectAction.Reprint.getValue());
                          SharedPreferences2Obj
                                  .getInstance(MainActivity.this)
                                  .setName("SelectAction")
                                  .setObject("titleName", getString(R.string.reprint));
                          intent.putExtra("titleName", getString(R.string.reprint));
                          startActivity(intent);
                      }
                  } else {
                      intent = new Intent(MainActivity.this, SettingsActivity.class);
                      intent.putExtra("titleName", getString(R.string.system_setting));
                      intent.putExtra("mode", "0");
                      startActivityForResult(intent, SETTING_REQUESTCODE);
                  }
                  break;
              case QUERY: // 查询
                  if (listConfig != null && listConfig.size() > 0) {
                      intent = new Intent(MainActivity.this,
                              SelectActionActivity.class);
                      // 设置选择的模式
                      intent.putExtra("titleName", getString(R.string.query));
                      SharedPreferences2Obj.getInstance(MainActivity.this)
                              .setName("SelectAction")
                              .setObject("Select", SelectAction.Query.getValue());
                      SharedPreferences2Obj.getInstance(MainActivity.this)
                              .setName("SelectAction")
                              .setObject("titleName", getString(R.string.query));
                      MyApp.getInstance().setTempMode(1);
                      startActivity(intent);
                  } else {
                      intent = new Intent(MainActivity.this, SettingsActivity.class);
                      intent.putExtra("titleName", getString(R.string.system_setting));
                      intent.putExtra("mode", "0");
                      startActivityForResult(intent, SETTING_REQUESTCODE);
                  }
                  break;
              case STATISTIC:// 统计
                  MyApp.getInstance().setCheckType(-100);
                  intent = new Intent(MainActivity.this, StatisticsActivity.class);
                  intent.putExtra("titleName", getString(R.string.statistic));
                  startActivity(intent);
                  break;
              case ABOUT:
                  intent = new Intent(MainActivity.this, AboutActivity.class);
                  intent.putExtra("titleName", getString(R.string.about));
                  startActivity(intent);
                  break;
              case SETTING: // 设置
                  MyApp.getInstance().setCheckType(-1);
                  if (listConfig != null && listConfig.size() > 0) {
                      final EditText inputpress = new EditText(MainActivity.this);
                      inputpress.setInputType(InputType.TYPE_CLASS_TEXT
                              | InputType.TYPE_TEXT_VARIATION_PASSWORD);
                      Builder builder = new AlertDialog.Builder(MainActivity.this);
                      builder.setTitle(getString(R.string.input_pwd));
                      builder.setIcon(android.R.drawable.ic_dialog_info);
                      builder.setView(inputpress).setPositiveButton(
                              getString(R.string.btn_ok),
                              new DialogInterface.OnClickListener() {
                                  @Override
                                  public void onClick(DialogInterface dialog,
                                                      int which) {
                                      String password = inputpress.getText()
                                              .toString();
                                      if (password.equals(listConfig.get(0)
                                              .getEc_passwd())) {
                                          Intent intent = new Intent(
                                                  MainActivity.this,
                                                  SettingsActivity.class);
                                          intent.putExtra("titleName",
                                                  getString(R.string.system_setting));
                                          intent.putExtra("mode", "1");
                                          startActivityForResult(intent,
                                                  SETTING_REQUESTCODE);
                                      } else {
                                          MToast(MainActivity.this,
                                                  getString(R.string.pwd_error),
                                                  MToast.LENGTH_SHORT);
                                      }
                                      // 隐藏软键盘
                                      hideInpu(inputpress);
                                  }
                              });
                      builder.setNegativeButton(getString(R.string.btn_cancel),
                              new OnClickListener() {
                                  @Override
                                  public void onClick(DialogInterface dialog,
                                                      int which) {
                                      hideInpu(inputpress);
                                  }
                              });
                      AlertDialog dialog = builder.create();
                      if (MyApp.getInstance().isHandset) {
                          dialog.getWindow().setType(
                                  WindowManager.LayoutParams.TYPE_SYSTEM_ERROR);
                      }
                      dialog.show();
                  } else {
                      intent = new Intent(MainActivity.this, SettingsActivity.class);
                      intent.putExtra("titleName", getString(R.string.system_setting));
                      intent.putExtra("mode", "0");
                      startActivityForResult(intent, SETTING_REQUESTCODE);
                  }
                  break;
              default:
          }
      }
  
      /**
       * 隐藏软件盘
       */
      private void hideInpu(View view) {
          // 隐藏软键盘
          InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
          imm.hideSoftInputFromWindow(view.getWindowToken(), 0); // 强制隐藏键盘
      }
  
      @Override
      public void onClick(View view) {
  
          switch (view.getId()) {
              case R.id.login:
                  loginTimps();
                  break;
  
              case R.id.unlogin:
                  MyApp.getInstance().setAccountId(null);
                  MyApp.getInstance().setUsername(null);
                  tv_username.setText("");
                  tv_username.setVisibility(View.GONE);
                  login.setVisibility(View.VISIBLE);
                  Toast.makeText(this, "注销成功!", Toast.LENGTH_LONG).show();
                  break;
          }
  
      }
  
  
      private void loginTimps() {
  
          View view = View.inflate(this, R.layout.login_dialog, null);
          TextView popTitle = (TextView) view.findViewById(R.id.pop_title);
          TextView text_ok = (TextView) view.findViewById(R.id.text_ok);
          TextView text_no = (TextView) view.findViewById(R.id.text_no);
  
          popTitle.setText("操作员登录");
          text_ok.setText("确定");
  
          AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
          final AlertDialog dialog = builder.create();
          dialog.setView(view);
          dialog.show();
          WindowManager.LayoutParams lp = dialog.getWindow().getAttributes();
  
          WindowManager manager = this.getWindowManager();
          Display display = manager.getDefaultDisplay();
          int width = display.getWidth();
  
          lp.width = DenstityUtils.dp2px(this, 300);
          lp.height = ActionBar.LayoutParams.WRAP_CONTENT;
          dialog.getWindow().setAttributes(lp);
  
          final EditText et_username = (EditText) dialog.findViewById(R.id.pop_suername);
          final EditText et_password = (EditText) dialog.findViewById(R.id.pop_password);
  
          text_ok.setOnClickListener(new View.OnClickListener() {
  
              @Override
              public void onClick(View v) {
  
                  final String username = et_username.getText().toString().trim();
                  if (TextUtils.isEmpty(username)) {
                      Toast.makeText(MainActivity.this, "请输入用户名!", Toast.LENGTH_SHORT).show();
                      return;
                  }
  
                  String password = et_password.getText().toString().trim();
                  if (TextUtils.isEmpty(password)) {
                      Toast.makeText(MainActivity.this, "请输入密码!", Toast.LENGTH_SHORT).show();
                      return;
                  }
  
                  HttpHelper.getInstance(MainActivity.this).login(username, password, new HttpCallback<DataTrans>() {
                      ProgressDialog dialog = null;
                      private String signed;
                      private String data;
                      private int lastItem;
  
                      @Override
                      public void onPreCallback() {
                          if (dialog == null) {
                              // 显示ProgressDialog
                              dialog = new ProgressDialog(MainActivity.this);
                              dialog.setMessage("正在登录");
                              dialog.setCanceledOnTouchOutside(true);
                              dialog.setCancelable(true);
                              try {
                                  if (dialog != null && !dialog.isShowing()) {
                                      dialog.show();
                                  }
                              } catch (Exception e) {
                                  e.printStackTrace();
                              }
                          } else {
                              dialog.setMessage("登录中...");
                          }
                      }
  
                      @Override
                      public void onCompletedCallback(DataTrans result) {
  
                      }
  
                      @Override
                      public void afterCompletedCallback(DataTrans result) {
  
                          if (result != null) {
                              signed = result.getSigned();
                              data = result.getData();
                              parse2(result.getData(), LoginResponse.class, MainActivity.this);
                          } else {
                              if (dialog != null && dialog.isShowing()) {
                                  try {
                                      dialog.dismiss();
                                  } catch (Exception e) {
                                      e.printStackTrace();
                                  } catch (Throwable e) {
                                      e.printStackTrace();
                                  }
                              }
                              Toast.makeText(MainActivity.this, "登录失败!", Toast.LENGTH_SHORT).show();
                          }
  
                      }
  
                      @Override
                      public void onFailureCallback(String FailureStr) {
                          if (dialog != null && dialog.isShowing()) {
                              try {
                                  dialog.dismiss();
                              } catch (Exception e) {
                                  e.printStackTrace();
                              } catch (Throwable e) {
                                  e.printStackTrace();
                              }
                          }
  
                          Toast.makeText(MainActivity.this, FailureStr, Toast.LENGTH_SHORT).show();
  
                      }
  
                      @Override
                      public void onStopCallback() {
  
                      }
  
                      @Override
                      public void onAgainParseCallback(Object parse) {
  
                          if (dialog != null && dialog.isShowing()) {
                              try {
                                  dialog.dismiss();
                              } catch (Exception e) {
                                  e.printStackTrace();
                              } catch (Throwable e) {
                                  e.printStackTrace();
                              }
                          }
  
                          if (parse != null) {
                              LoginResponse loginResponse = (LoginResponse) parse;
                              String code = loginResponse.getCode();
                              if (code != null && OrderCode.SUCESS.getValue().equals(code)) {
  
                                  if (loginResponse.getAccountId() != null) {
  
                                      dialog.dismiss();
                                      MyApp.getInstance().setAccountId(loginResponse.getAccountId());
                                      MyApp.getInstance().setUsername(username);
                                      login.setVisibility(View.GONE);
                                      tv_username.setVisibility(View.VISIBLE);
                                      tv_username.setText(username + " 已登录");
                                      Toast.makeText(MainActivity.this, "登录成功!", Toast.LENGTH_SHORT).show();
                                  } else {
                                      Toast.makeText(MainActivity.this, "登录失败,请重试!", Toast.LENGTH_SHORT).show();
                                  }
                              }
  
                          } else {
                              Toast.makeText(MainActivity.this, "登录失败,请重试!", Toast.LENGTH_SHORT).show();
                          }
  
                      }
                  });
  
                  if (dialog.isShowing()) {
                      dialog.dismiss();
                  }
  
              }
          });
  
          text_no.setOnClickListener(new View.OnClickListener() {
  
              @Override
              public void onClick(View v) {
                  dialog.dismiss();
              }
          });
  
      }
  }