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; private String titleName; 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); // title.setText("检票—身份证"); // if (isShowShip) { // llShip.setVisibility(View.VISIBLE); // } else { // llShip.setVisibility(View.GONE); // } } private void initData() { // type = getIntent().getIntExtra("type", -1); // gardenID = PreferenceUtils.getString(mContext, ParamContants.GET_ACCID, ""); // String showShipType = PreferenceUtils.getString(mContext, "showShipType", "no"); // isShowShip = TextUtils.equals(showShipType, "yes"); 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); } 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); // phone.putExtra("type", type); 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); // } // } // // } // //}