Blame view

src/com/ectrip/cyt/ui/IDHandleRSKActivity.java 11.8 KB
90601e4f   黄灿宏   标准版本 1.扩展设备10 增...
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
  package com.ectrip.cyt.ui;
  
  import android.annotation.SuppressLint;
  import android.content.Context;
  import android.content.Intent;
  import android.os.Bundle;
  import android.os.Handler;
  import android.os.Message;
  import android.text.TextUtils;
  import android.view.View;
  import android.widget.Button;
  import android.widget.LinearLayout;
  import android.widget.TextView;
  import android.widget.Toast;
  
  //import com.ectrip.scanbarcode_jp.NETutils.WebserviceHelper;
  //import com.ectrip.scanbarcode_jp.R;
  //import com.ectrip.scanbarcode_jp.callBack.CheckCallBackRSK;
  //import com.ectrip.scanbarcode_jp.callBack.CheckCallBack_ZJ;
  //import com.ectrip.scanbarcode_jp.constens.ParamContants;
  //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.utils.TimesUtils;
  //import com.ectrip.scanbarcode_jp.view.ToastUtils;
  //import com.ectrip.scanbarcode_jp.zxing.MyMap;
  import com.ectrip.cyt.constant.ParamContants;
  import com.ectrip.cyt.utils.CountDownTimer;
  import com.ectrip.cyt.utils.LogUtil;
  import com.ectrip.cyt.utils.PreferenceUtils;
  import com.ectrip.cyt.utils.SoundUtil;
  import com.ectrip.cyt.utils.TimesUtils;
  import com.ectrip.cyt.utils.ToastUtils;
  import com.rsk.api.ICard;
  import com.rsk.api.ICardInfo;
  
  import com.ectrip.trips.check.R;
  
  import java.util.Date;
  import java.util.Map;
  
  
  public class IDHandleRSKActivity extends BaseActivity {
  
      private String TAG = "IDHandleRSKActivity";
      private TextView topBack;
  //    private TextView tvShipName;
  //    private TextView tvShipCheck;
      private LinearLayout llShip;
      private int type;
      private String gardenID;
      private boolean isShowShip;
      private TextView noId;
  //    private TextView tvCount;
c05c7a9b   黄灿宏   标准版本 1.扩展设备8 2....
55
      private String titleName;
90601e4f   黄灿宏   标准版本 1.扩展设备10 增...
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
      private final int MSG_CHECK = 1;
      private final int MSG_INIT_DEV = 2;
      private final int MSG_CHECK1 = 3;
      private Context mContext;
      @SuppressLint("HandlerLeak")
      private Handler mHandle = new Handler() {
          public void handleMessage(Message msg) {
              switch (msg.what) {
                  case MSG_CHECK:
                      String id = (String) msg.obj;
                      checkByID(id);
                      break;
                  case MSG_INIT_DEV:
                      openDev();
                      break;
                  default:
                      break;
              }
          }
      };
  
      private boolean isIDReaderEnable = false;//身份证模块打开状态
      private boolean mRunFlag = false;//身份证线程运行控制标记
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_id_handle_rsk);
  
          initData();
          initView();
          ininlistener();
  
          mHandle.sendEmptyMessageDelayed(MSG_INIT_DEV, 500);
  
      }
  
      private String lastId = "";
  
      private class IDCardReadThread extends Thread {
          @Override
          public void run() {
              super.run();
  
              while (isIDReaderEnable) {
  
                  try {
                      if (mRunFlag) {
                          ICardInfo iCardInfo = new ICardInfo();
                          int nResult = ICard.Read(iCardInfo);
                          if (nResult == 0) {
                              String id = iCardInfo.id_num;
                              if (TextUtils.equals(lastId, id)&& TimesUtils.over1s(3000)) {
                                  LogUtil.i(TAG, "重复读取身份证");
                                  runOnUiThread(new Runnable() {
                                      @Override
                                      public void run() {
                                          ToastUtils.toast(mContext, "重复读取,请更换证件");
                                      }
                                  });
                              } else {
                                  LogUtil.i(TAG, "身份证读卡成功-2,卡号:" + id.replace(id.substring(6, 14), "****"));
                                  SoundUtil.getInstents(IDHandleRSKActivity.this).playWavSound(R.raw.beep);
                                  lastId = id;
                                  Message msg = Message.obtain();
                                  msg.obj = id;
                                  msg.what = MSG_CHECK;
                                  mHandle.sendMessage(msg);
                              }
                          } else {
                              lastId = "";
                          }
                      }
                      Thread.sleep(300);
                  } catch (Exception e) {
                      lastId = "";
                      e.printStackTrace();
                  }
  
              }
          }
      }
  
  
      private void openDev() {
          int mResult = ICard.Open();
          if (mResult == 0) {
              mRunFlag = true;
              isIDReaderEnable = true;
              Toast.makeText(mContext, "启动成功", Toast.LENGTH_SHORT).show();
  
              IDCardReadThread mIDCardReadThread = new IDCardReadThread();
              mIDCardReadThread.start();
  
          } else {
              mRunFlag = false;
              isIDReaderEnable = false;
              Toast.makeText(mContext, "启动失败,请重启", Toast.LENGTH_SHORT).show();
          }
      }
  
  
      @Override
      protected void onResume() {
          super.onResume();
          mRunFlag = true;
  
  //        int count = PreferenceUtils.getInt(mContext, "count", 0);
  //        tvCount.setText(String.valueOf(count));
  
  //        if (isShowShip) {
  //            getShowShipType();
  //        }
      }
  
  //    private void getShowShipType() {
  //
  //        String count = PreferenceUtils.getString(mContext, ParamContants.GET_PASS_TOTAL, "0/0");
  //        String name = PreferenceUtils.getString(mContext, ParamContants.GET_SHIP_NAME, "");
  //        tvShipCheck.setText(count);
  //        tvShipName.setText(name);
  //    }
  
      @Override
      protected void onPause() {
          super.onPause();
          mRunFlag = false;
          lastId = "";
      }
  
      @Override
      protected void onDestroy() {
          super.onDestroy();
          ICard.Close();
      }
  
      private void initView() {
  //        tvShipName = (TextView) findViewById(R.id.tv_ship_name);
  //        tvShipCheck = (TextView) findViewById(R.id.tv_ship_check);
  //        llShip = (LinearLayout) findViewById(R.id.ll_ship);
          topBack = (TextView) findViewById(R.id.topBack);
          noId = (TextView) findViewById(R.id.tv_no_id);
  //        tvCount = (TextView) findViewById(R.id.top_count);
          TextView title = (TextView) findViewById(R.id.title);
          title.setVisibility(View.VISIBLE);
c05c7a9b   黄灿宏   标准版本 1.扩展设备8 2....
201
  //        title.setText("检票—身份证");
90601e4f   黄灿宏   标准版本 1.扩展设备10 增...
202
203
204
205
206
207
208
209
210
  
  //        if (isShowShip) {
  //            llShip.setVisibility(View.VISIBLE);
  //        } else {
  //            llShip.setVisibility(View.GONE);
  //        }
      }
  
      private void initData() {
c05c7a9b   黄灿宏   标准版本 1.扩展设备8 2....
211
  //        type = getIntent().getIntExtra("type", -1);
90601e4f   黄灿宏   标准版本 1.扩展设备10 增...
212
213
214
  //        gardenID = PreferenceUtils.getString(mContext, ParamContants.GET_ACCID, "");
  //        String showShipType = PreferenceUtils.getString(mContext, "showShipType", "no");
  //        isShowShip = TextUtils.equals(showShipType, "yes");
c05c7a9b   黄灿宏   标准版本 1.扩展设备8 2....
215
216
217
218
219
220
          titleName=getIntent().getStringExtra("titleName");
          if(titleName!=null){
              ((TextView)findViewById(R.id.title)).setText(titleName);
          }else{
              ((TextView)findViewById(R.id.title)).setText(R.string.scan_id);
          }
90601e4f   黄灿宏   标准版本 1.扩展设备10 增...
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
          mContext = this;
      }
  
      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);
c05c7a9b   黄灿宏   标准版本 1.扩展设备8 2....
236
  //                phone.putExtra("type", type);
90601e4f   黄灿宏   标准版本 1.扩展设备10 增...
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
                  startActivity(phone);
              }
          });
      }
  
      /**
       * 处理扫描结果
       *
       * @param barcode
       */
  
      private void checkByID(final String barcode) {
          String data = "";
          LogUtil.d(TAG,"获取的身份证号:" +barcode);
  
          Intent intent = new Intent(IDHandleRSKActivity.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;
  //        mRunFlag = false;
  
  //        //检票
  //        String reqZJ = PreferenceUtils.getString(mContext, "reqZJ", "no");
  //        if (reqZJ.equals("yes") && type == 1) {
  //            data = gardenID + "," + barcode;
  //            WebserviceHelper.getInstance().checkTickt(data, "CheckTicket", new CheckCallBack_ZJ(IDHandleRSKActivity.this) {
  //                @Override
  //                public void getMap(Map map) {
  //                    getCheckTicketResult(map);
  //                }
  //
  //                @Override
  //                public void failureToDo() {
  //                    mRunFlag = true;
  //                }
  //            }, 7);
  //        } else {
  //            if (type == 1) {
  //                data = gardenID + "," + barcode + ",JP";
  //            } else {
  //                data = gardenID + "," + barcode + ",CX";
  //            }
  //            WebserviceHelper.getInstance().test(data, "CheckscTicketmebile", new CheckCallBackRSK
  //                    (IDHandleRSKActivity.this) {
  //
  //                @Override
  //                public void failureToDo() {
  //                    mRunFlag = true;
  //                }
  //
  //                @Override
  //                public void getMap(Map map) {
  //                    getCheckTicketResult(map);
  //
  //                }
  //            }, 2);
          }
      }
  
  //    private void getCheckTicketResult(Map map) {
  //        MyMap myMap = new MyMap();
  //        myMap.setMap(map);
  //        String ticketFlag = map.get("message1").toString();
  //        if (TextUtils.isEmpty(ticketFlag)) {
  //            Toast.makeText(mContext, "获取检票数据不成功...", Toast.LENGTH_SHORT).show();
  //            return;
  //        }
  //        int flag = Integer.parseInt(ticketFlag);
  //        LogUtil.i(TAG, "票状态--------> " + flag);
  //        String checkFaceType = PreferenceUtils.getString(mContext, "checkFaceType", "no");
  //        if (TextUtils.equals(checkFaceType, "yes")) {
  //            //传递Map到ShowResult.java 显示
  //            myMap.getMap().put("finger", "RL");
  //            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);
  //        } else {
  //            if (flag == 1) {//登记指纹
  //                SoundUtil.getInstents(mContext).playSound(R.raw.dengjizhiwen, -1);
  //                Toast.makeText(mContext, "请登记指纹!", Toast.LENGTH_SHORT).show();
  //            } else if (flag == 2) {//验证指纹
  //                SoundUtil.getInstents(mContext).playSound(R.raw.yanzhengzhiwen, -1);
  //                Toast.makeText(mContext, "请验证指纹!", Toast.LENGTH_SHORT).show();
  //            } 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);
  //            }
  //        }
  //
  //    }
  //
  //}