Blame view

src/com/ectrip/cyt/ui/IDHandleActivity.java 21.4 KB
c05c7a9b   黄灿宏   标准版本 1.扩展设备8 2....
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
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
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
  package com.ectrip.cyt.ui;
  
  import android.annotation.SuppressLint;
  import android.content.Context;
  import android.content.Intent;
  import android.graphics.Bitmap;
  import android.os.Build;
  import android.os.Bundle;
  import android.os.Environment;
  import android.os.Handler;
  import android.os.Message;
  import android.util.Log;
  import android.view.View;
  import android.widget.Button;
  import android.widget.LinearLayout;
  import android.widget.TextView;
  import android.widget.Toast;
  
  //import com.IDCard.IDCardManager;
  //import com.IDCard.IDCardModel;
  //import com.ectrip.scanbarcode_jp.NETutils.WebserviceHelper;
  //import com.ectrip.scanbarcode_jp.R;
  //import com.ectrip.scanbarcode_jp.callBack.CheckCallBack;
  //import com.ectrip.scanbarcode_jp.callBack.CheckCallBack_ZJ;
  //import com.ectrip.scanbarcode_jp.config.AppContext;
  //import com.ectrip.scanbarcode_jp.constens.ParamContants;
  //import com.ectrip.scanbarcode_jp.constens.ParameterContens;
  //import com.ectrip.scanbarcode_jp.utils.LogUtil;
  //import com.ectrip.scanbarcode_jp.utils.PreferenceUtils;
  //import com.ectrip.scanbarcode_jp.utils.SoundUtil;
  //import com.ectrip.scanbarcode_jp.zxing.MyMap;
  import com.IDCard.IDCardManager;
  import com.IDCard.IDCardModel;
  import com.ectrip.cyt.utils.CountDownTimer;
  import com.ectrip.cyt.utils.LogUtil;
  import com.ectrip.trips.check.R;
  import com.zkteco.android.biometric.core.device.ParameterHelper;
  import com.zkteco.android.biometric.core.device.TransportType;
  import com.zkteco.android.biometric.core.utils.LogHelper;
  import com.zkteco.android.biometric.module.idcard.IDCardReader;
  import com.zkteco.android.biometric.module.idcard.IDCardReaderFactory;
  import com.zkteco.android.biometric.module.idcard.exception.IDCardReaderException;
  import com.zkteco.android.biometric.module.idcard.meta.IDCardInfo;
  
  import java.io.File;
  import java.util.Date;
  import java.util.HashMap;
  import java.util.Map;
  
  
  public class IDHandleActivity extends BaseActivity {
  
      private Bitmap photoBitmap = null;
      private IDCardManager manager;
      private ReadThread thread;
      private Toast toast;
      private TextView topBack;
      private TextView tv_ship_name;
      private TextView tv_ship_check;
      private LinearLayout ll_ship;
      private int type;
      private String gardenID;
      private static final String TAG = "IDHandleActivity";
      private TextView noId;
      private TextView title;
      private TextView count_textView;
      private int count;
      private Context mContext;
  
      private void showToast(String info) {
          if (toast == null) {
              toast = Toast.makeText(mContext, info, Toast.LENGTH_SHORT);
          } else {
              toast.setText(info);
          }
          toast.show();
      }
  
      @SuppressLint("HandlerLeak")
      private Handler handler = new Handler() {
          public void handleMessage(Message msg) {
              switch (msg.what) {
                  case 0:
  //                    showToast("读身份证成功!");
                      Bundle bundle = msg.getData();
                      //获取身份证信息:姓名、性别、出生年、月、日、住址、身份证号、签发机关、有效期开始、结束、(额外信息新地址(一般情况为空))
  //                    String name = bundle.getString("name");
  //                    String sex = bundle.getString("sex");
  //                    String nation = bundle.getString("nation");
  //                    String year = bundle.getString("year");
  //                    String month = bundle.getString("month");
  //                    String day = bundle.getString("day");
  //                    String address = bundle.getString("address");
  //                    String office = bundle.getString("office");
  //                    String start = bundle.getString("begin");
  //                    String stop = bundle.getString("end");
  //                    String newaddress = bundle.getString("newaddress");
                      String id = bundle.getString("id");
                      checkByID(id);
                      break;
                  case 1:
                      showToast("发现身份证!");
                      break;
                  case 2:
                      showToast("");
                      break;
                  case 3:
  
                      break;
                  default:
                      break;
              }
          }
      };
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_id_handle_new);
          type = getIntent().getIntExtra("type", -1);
  //        gardenID = PreferenceUtils.getString(mContext, ParamContants.GET_ACCID, "");
          initView();
          initData();
          ininlistener();
  
          String devType = Build.MODEL;
          if (devType.startsWith("ax6737")) {
              initAX6737();
              return;
          }
  
  
          String path = Environment.getExternalStorageDirectory() + "/IDCard";
          File file_paper = new File(path);
          if (!file_paper.exists()) {
              file_paper.mkdirs();
          }
  
          openDev();
  
      }
  
      private void initAX6737() {
          startIDCardReader();
          try {
              mIdCardReader.open(0);
          } catch (IDCardReaderException e) {
              e.printStackTrace();
          }
          mIDCardReadThread = new IDCardReadThread();
          mRunFlag = true;
          mIDCardReadThread.start();
      }
  //    /**
  //     * 身份证模块打开状态
  //     */
  //    private boolean mIDCardReaderEnable = false;
      /**
       * 身份证线程运行控制标记
       */
      private boolean mRunFlag = false;
  
      /**
       * 初始化身份证阅读器
       */
      private void startIDCardReader() {
          try {
              LogHelper.setLevel(Log.ASSERT);
              // Start fingerprint sensor
              Map<String, Object> idReaderParams = new HashMap<>(2);
              idReaderParams.put(ParameterHelper.PARAM_SERIAL_SERIALNAME, "/dev/ttyMT1");
              idReaderParams.put(ParameterHelper.PARAM_SERIAL_BAUDRATE, 115200);
              mIdCardReader = IDCardReaderFactory.createIDCardReader(this, TransportType.SERIALPORT, idReaderParams);
          } catch (Exception e) {
              e.printStackTrace();
              showToast("身份证模块初始化错误" + e.getMessage());
          }
      }
  
      /**
       * 身份证读取线程
       */
      private IDCardReader mIdCardReader;
      private IDCardReadThread mIDCardReadThread;
  
      private class IDCardReadThread extends Thread {
          @Override
          public void run() {
              while (mRunFlag) {
                  if (mIdCardReader != null) {
                      try {
                          Thread.sleep(1000);
                          boolean cardAvailable = mIdCardReader.findCard(0);
                          LogUtil.i(TAG, "cardAvailable === " + cardAvailable);
                          if (cardAvailable) {
                              boolean selected = mIdCardReader.selectCard(0);
                              LogUtil.i(TAG, "selected === " + selected);
                              if (selected) {
                                  handler.sendEmptyMessage(1);
                                  int readCardEx = mIdCardReader.readCardEx(0, 0);
                                  if (readCardEx == 1 || readCardEx == 2 || readCardEx == 3) {
                                      //居民身份证
                                      IDCardInfo lastIDCardInfo = mIdCardReader.getLastIDCardInfo();
  
                                      Message message = new Message();
                                      Bundle bundle = new Bundle();
                                      bundle.putString("id", lastIDCardInfo.getId());
                                      message.setData(bundle);
                                      handler.sendMessage(message);
                                  }
                              }
                          }
  
                      } catch (Exception e) {
                          LogUtil.i(TAG, "Read card error = " + e.getMessage());
                          e.printStackTrace();
                      }
                  }
              }
              super.run();
          }
      }
  
  
      private void openDev() {
          if (manager == null) {
              manager = new IDCardManager(mContext);
          }
          startFlag = true;
      }
  
      @Override
      protected void onStart() {
          super.onStart();
          startFlag = true;
          runFlag = true;
          thread = new ReadThread();
          thread.start();
      }
  
      @Override
      protected void onStop() {
          super.onStop();
          startFlag = false;
          runFlag = false;
  //        if (manager!=null) {
  //            manager.Close();
  //            manager = null;
  //        }
      }
  
      @Override
      protected void onResume() {
          super.onResume();
  //        showShipType();
  //        count = PreferenceUtils.getInt(mContext, "count", 0);
  //        count_textView.setText(count + "");
      }
  
      private String showShipType;
      private Handler mHandle = new Handler();
  
  //    private void showShipType() {
  //        showShipType = PreferenceUtils.getString(this, "showShipType", "no");
  //        if (showShipType.equals("yes")) {
  //            ll_ship.setVisibility(View.VISIBLE);
  //            mHandle.postDelayed(shipRunable, 100);
  //        } else {
  //            ll_ship.setVisibility(View.GONE);
  //        }
  //    }
  
  //    private Runnable shipRunable = new Runnable() {
  //        @Override
  //        public void run() {
  //            getShowShipType();
  //            mHandle.postDelayed(this, 20 * 1000);
  //        }
  //    };
  
  //    private void getShowShipType() {
  //
  //        String count = PreferenceUtils.getString(mContext, ParamContants.GET_PASS_TOTAL, "0/0");
  //        String name = PreferenceUtils.getString(mContext, ParamContants.GET_SHIP_NAME, "");
  //        tv_ship_check.setText(count);
  //        tv_ship_name.setText(name);
  //    }
  
      @Override
      protected void onPause() {
          super.onPause();
  //        if (mHandle != null && shipRunable != null) {
  //            mHandle.removeCallbacks(shipRunable);
  //        }
      }
  
      @Override
      protected void onDestroy() {
          super.onDestroy();
          startFlag = false;
          if (manager != null) {
              manager.Close();
              manager = null;
          }
          if (mRunFlag) {
              mRunFlag = false;
              mIDCardReadThread.interrupt();
              try {
                  mIdCardReader.close(0);
              } catch (Exception e) {
                  e.printStackTrace();
              }
          }
      }
  
      private void initView() {
  //        tv_ship_name = (TextView) findViewById(R.id.tv_ship_name);
  //        tv_ship_check = (TextView) findViewById(R.id.tv_ship_check);
  //        ll_ship = (LinearLayout) findViewById(R.id.ll_ship);
          topBack = (TextView) findViewById(R.id.topBack);
          noId = (TextView) findViewById(R.id.tv_no_id);
          title = (TextView) findViewById(R.id.title);
  //        count_textView = (TextView) findViewById(R.id.top_count);
          //提示读取身份证区
  //        String keepType = PreferenceUtils.getString(this, "keepScreenOn", "yes");
  //        if (keepType.equals("yes")) {
  //            topBack.setKeepScreenOn(true);
  //        } else {
  //            topBack.setKeepScreenOn(false);
  //        }
  //        if (type == 1) {
              title.setText("检票—身份证");
  //        } else if (type == 2) {
  //            title.setText("监票—身份证");
  //        }
      }
  
  
      private void initData() {
          mContext = this;
  //        String Ip = PreferenceUtils.getString(AppContext.getInstance(), ParameterContens.SET_ip);
  //        String url = "http://" + Ip + "/android/gardenCount.jsp";
  //        Map<String, Object> parme = new HashMap<>();
  //        parme.put(ParamContants.GET_ACCID, gardenID);
  //        try {
  //                new BaseGetProtocol().loadMoreData(this,url,parme, new BaseGetProtocol.onNetCallback() {
  //                @Override
  //                public void onFailure(String erro) {
  //                    topBtns.setText("入园人数未获取");
  //                }
  //
  //                @Override
  //                public void onSuccessed(String jsonGetFromService) {
  //                    topBtns.setText(jsonGetFromService.trim());
  //                }
  //            });
  //        } catch (IOException e) {
  //            e.printStackTrace();
  //        }
      }
  
      private void ininlistener() {
          //点击头部返回键,关闭当前activity
          topBack.setOnClickListener(new View.OnClickListener() {
  
              public void onClick(View v) {
                  finish();
              }
          });
          noId.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  Intent phone = new Intent(mContext, InputIdCardActivity.class);
                  phone.putExtra("type", type);
                  startActivity(phone);
              }
          });
      }
  
      /**
       * 处理扫描结果
       *
       * @param barcode
       */
  
      private void checkByID(final String barcode) {
          String data = "";
  //        tring barcode = idBean.getId();
          LogUtil.d(TAG,"获取的身份证号:" +barcode);
  
          Intent intent = new Intent(IDHandleActivity.this,
                  IDOrderListActivity.class);
          CountDownTimer.firstTime = new Date().getTime();// 不必要的可以删除
          intent.putExtra("mode", 0);
          intent.putExtra("idcardNumber", barcode);
          intent.putExtra("titleName", getString(R.string.order_list));
          startActivity(intent);
  //        ShowResultActivity.barcode = barcode;
  //        startFlag = false;
  //        runFlag = false;
  //        //检票
  //        if (type == 1) {
  //            data = gardenID + "," + barcode + ",JP";
  //            final String finalData1 = data;
  //            String reqZJ = PreferenceUtils.getString(mContext, "reqZJ", "no");
  //            if (reqZJ.equals("yes")) {
  //                WebserviceHelper.getInstance().checkTickt(gardenID + "," + barcode, "CheckTicket", new CheckCallBack_ZJ(IDHandleActivity.this) {
  //                    @Override
  //                    public void getMap(Map map) {
  //                        MyMap myMap = new MyMap();
  //                        myMap.setMap(map);
  //                        if (map == null || map.get("message1") == null) {
  //                            Toast.makeText(context, "获取票信息失败,请重试", Toast.LENGTH_SHORT).show();
  //                            return;
  //                        }
  //                        String ticketFlag = map.get("message1").toString();
  //                        if (ticketFlag != null && !"".equals(ticketFlag)) {
  //                            int flag = Integer.valueOf(ticketFlag);
  //                            LogUtil.i(TAG, "票状态--------> " + flag);
  //                            if (flag == 1) {//登记指纹
  //                                SoundUtil.getInstents(IDHandleActivity.this).playSound(R.raw.dengjizhiwen, -1);
  //                            } else if (flag == 2) {//验证指纹
  //                                SoundUtil.getInstents(IDHandleActivity.this).playSound(R.raw.yanzhengzhiwen, -1);
  //                            } else {//直接信息显示
  //                                //传递Map到ShowResult.java 显示
  //                                Intent intent = new Intent(mContext, ShowResultActivity
  //                                        .class);
  //                                Bundle bundle = new Bundle();
  //                                bundle.putSerializable("resultMap", myMap);
  //                                bundle.putString("activityName", TAG);
  //                                intent.putExtras(bundle);
  //                                intent.putExtra("type", type);
  //                                startActivity(intent);
  //                                // finish();
  //                            }
  //                        }
  //                    }
  //
  //                    @Override
  //                    public void failureToDo() {
  //                        Toast.makeText(context, "检票失败,请重试", Toast.LENGTH_SHORT).show();
  //                    }
  //                }, 7);
  //            } else {
  //                WebserviceHelper.getInstance().test(data, "CheckscTicketmebile", new CheckCallBack
  //                        (IDHandleActivity.this) {
  //
  //                    @Override
  //                    public void failureToDo() {
  //                        Toast.makeText(context, "检票失败,请重试", Toast.LENGTH_SHORT).show();
  //                    }
  //
  //                    @Override
  //                    public void getMap(Map map) {
  //                        MyMap myMap = new MyMap();
  //                        myMap.setMap(map);
  //                        if (map == null || map.get("message1") == null) {
  //                            Toast.makeText(context, "获取票信息失败,请重试", Toast.LENGTH_SHORT).show();
  //                            return;
  //                        }
  //                        String ticketFlag = map.get("message1").toString();
  //                        if (ticketFlag != null && !"".equals(ticketFlag)) {
  //                            int flag = Integer.valueOf(ticketFlag);
  //                            LogUtil.i(TAG, "票状态--------> " + flag);
  //                            if (flag == 1) {//登记指纹
  //                                SoundUtil.getInstents(IDHandleActivity.this).playSound(R.raw.dengjizhiwen, -1);
  //                            } else if (flag == 2) {//验证指纹
  //                                SoundUtil.getInstents(IDHandleActivity.this).playSound(R.raw.yanzhengzhiwen, -1);
  //                            } else {//直接信息显示
  //                                //传递Map到ShowResult.java 显示
  //                                Intent intent = new Intent(mContext, ShowResultActivity
  //                                        .class);
  //                                Bundle bundle = new Bundle();
  //                                bundle.putSerializable("resultMap", myMap);
  //                                bundle.putString("activityName", TAG);
  //                                intent.putExtras(bundle);
  //                                intent.putExtra("type", type);
  //                                startActivity(intent);
  //                                // finish();
  //                            }
  //                        }
  //
  //                    }
  //                }, 2);
  //            }
  //
  //        } else if (type == 2) {
  //            data = gardenID + "," + barcode + ",CX";
  //            final String finalData = data;
  //            WebserviceHelper.getInstance().test(data, "CheckscTicketmebile", new CheckCallBack(IDHandleActivity.this) {
  //
  //                @Override
  //                public void failureToDo() {
  //                    Toast.makeText(context, "获取票信息失败,请重试", Toast.LENGTH_SHORT).show();
  //
  //                }
  //
  //                @Override
  //                public void getMap(Map map) {
  //                    MyMap myMap = new MyMap();
  //                    myMap.setMap(map);
  //                    Intent intent = new Intent(mContext, ShowResultActivity.class);
  //                    Bundle bundle = new Bundle();
  //                    bundle.putSerializable("resultMap", myMap);
  //                    bundle.putString("activityName", TAG);
  //                    intent.putExtras(bundle);
  //                    startActivity(intent);
  //                    // finish();
  //                }
  //            }, 2);
  //        }
      }
  
      private boolean runFlag = true;
      private boolean startFlag = false;
  
      private class ReadThread extends Thread {
          @Override
          public void run() {
              while (runFlag) {
                  if (startFlag && manager != null) {
                      if (manager.FindCard(200)) {
                          handler.sendEmptyMessage(1);
                          IDCardModel model = manager.GetData(1000);
                          if (model != null) {
                              sendMessage(model.getName(), model.getSex(), model.getNation(),
                                      model.getYear(), model.getMonth(), model.getDay(),
                                      model.getAddress(), model.getIDCardNumber(), model.getOffice(),
                                      model.getBeginTime(), model.getEndTime(), model.getOtherData());
                          }
                      }
                  }
                  try {
                      sleep(100);
                  } catch (InterruptedException e) {
                      e.printStackTrace();
                  }
              }
              super.run();
          }
  
          private void sendMessage(String name, String sex, String nation,
                                   String year, String month, String day, String address, String id,
                                   String office, String start, String stop, String newaddress
          ) {
              Message message = new Message();
              Bundle bundle = new Bundle();
  //            bundle.putString("name", name);
  //            bundle.putString("sex", sex);
  //            bundle.putString("nation", nation);
  //            bundle.putString("year", year);
  //            bundle.putString("month", month);
  //            bundle.putString("day", day);
  //            bundle.putString("address", address);
  //            bundle.putString("office", office);
  //            bundle.putString("begin", start);
  //            bundle.putString("end", stop);
  //            bundle.putString("newaddress", newaddress);
              bundle.putString("id", id);
  //            photoBitmap = bitmap;
              message.setData(bundle);
              handler.sendMessage(message);
          }
      }
  
  }