| | |
| | | import com.basic.security.utils.IdCard; |
| | | import com.basic.security.utils.SocketUtil; |
| | | import com.basic.security.utils.ToastUtil; |
| | | import com.telpo.tps550.api.idcard.IdentityMsg; |
| | | |
| | | import org.apache.commons.io.IOUtils; |
| | | |
| | | import java.io.ByteArrayOutputStream; |
| | | import java.io.File; |
| | | import java.io.FileOutputStream; |
| | | import java.nio.ByteBuffer; |
| | | import java.text.SimpleDateFormat; |
| | |
| | | static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); |
| | | static long lastTimeShowVerificationSuccess = System.currentTimeMillis(); |
| | | static long lastTimeShowVerificationFail = System.currentTimeMillis(); |
| | | static com.telpo.tps550.api.idcard.IdCard idCardTps650 = null; |
| | | private static IntentFilter filter; |
| | | private static BroadcastReceiver receiver; |
| | | private volatile static boolean inRead = false; |
| | |
| | | |
| | | // static ReadUtil readUtil; |
| | | public static void startReadIdCard() { |
| | | BaseApplication.getApplication().executorService.execute(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | while (true) { |
| | | try { |
| | | Result result = mReader.read(); |
| | | if (result.error == IDCardReader.RESULT_OK) { |
| | | IDCard idCard = (IDCard) result.data; |
| | | System.out.println("IdCardManager.run " + idCard); |
| | | AndroidBmpUtil.save(idCard.getPhoto(), Constants.attachmentPath + idCard.getNumber() + ".bmp"); |
| | | MainActivity activity = BaseApplication.getApplication().activity; |
| | | if (activity != null) { |
| | | if (activity.currentFragment == activity.fragment_su_auto_ic_wait_idcard |
| | | || activity.currentFragment == activity.fragment_su_logged_ic_wait_idcard |
| | | || (activity.currentFragment == activity.fragment_person_manage && activity.fragment_person_manage.needIdCardInfo())) { |
| | | if (1 == 1) { |
| | | IdCard idcard = new IdCard(); |
| | | idcard.birthday = idCard.getBirthday().getTime();//intent.getLongExtra("birthday", 0); |
| | | idcard.cardNumber = idCard.getNumber();// intent.getStringExtra("cardNumber"); |
| | | idcard.gender = idCard.getSex().toString();//intent.getStringExtra("gender"); |
| | | idcard.name = idCard.getName();//intent.getStringExtra("name").trim(); |
| | | idcard.headBitmap = idCard.getPhoto();//BitmapFactory.decodeFile("/sdcard/security_excel_attachment/" + idcard.cardNumber + ".bmp"); |
| | | ByteArrayOutputStream stream = new ByteArrayOutputStream(); |
| | | idcard.headBitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream); |
| | | idcard.jpgData = stream.toByteArray(); |
| | | //BitmapFactory.decodeByteArray(idcard.jpgData, 0, idcard.jpgData.length); |
| | | BaseApplication.getApplication().detectLock.lock(); |
| | | idcard.featureData = FaceId.instance.extractFeature1(getPixelsBGR(idcard.headBitmap), idcard.headBitmap.getWidth(), idcard.headBitmap.getHeight()); |
| | | BaseApplication.getApplication().detectLock.unlock(); |
| | | BaseFragment.idCardReadTime = System.currentTimeMillis(); |
| | | System.out.println("IdCardManager.onReceive 2"); |
| | | BaseFragment.idCard = idcard; |
| | | saveIdCard(idcard); |
| | | if (Constants.isTps650) { |
| | | BaseApplication.getApplication().activity.runOnUiThread(() -> { |
| | | try { |
| | | if (idCardTps650 == null) { |
| | | idCardTps650 = new com.telpo.tps550.api.idcard.IdCard(BaseApplication.getApplication().activity); |
| | | } |
| | | BaseApplication.getApplication().executorService.execute(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | while (true) { |
| | | try { |
| | | IdentityMsg info = idCardTps650.checkIdCardOverseas(3000); |
| | | if (info != null) { |
| | | byte[] image = idCardTps650.getIdCardImageOverseas(info); |
| | | String cardNumber = info.getNo(); |
| | | Bitmap photo = idCardTps650.decodeIdCardImageOverseas(image); |
| | | AndroidBmpUtil.save(photo, Constants.attachmentPath + cardNumber + ".bmp"); |
| | | String name = info.getName(); |
| | | name = name.replace(" ", ""); |
| | | MainActivity activity = BaseApplication.getApplication().activity; |
| | | if (activity != null) { |
| | | if (activity.currentFragment == activity.fragment_su_auto_ic_wait_idcard |
| | | || activity.currentFragment == activity.fragment_su_logged_ic_wait_idcard |
| | | || (activity.currentFragment == activity.fragment_person_manage && activity.fragment_person_manage.needIdCardInfo())) { |
| | | if (1 == 1) { |
| | | IdCard idcard = new IdCard(); |
| | | // idcard.birthday = info.getBorn()+"";//intent.getLongExtra("birthday", 0); |
| | | idcard.cardNumber = cardNumber;// intent.getStringExtra("cardNumber"); |
| | | idcard.gender = info.getSex();//intent.getStringExtra("gender"); |
| | | idcard.name = name;//intent.getStringExtra("name").trim(); |
| | | idcard.headBitmap = photo;//BitmapFactory.decodeFile("/sdcard/security_excel_attachment/" + idcard.cardNumber + ".bmp"); |
| | | ByteArrayOutputStream stream = new ByteArrayOutputStream(); |
| | | idcard.headBitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream); |
| | | idcard.jpgData = stream.toByteArray(); |
| | | //BitmapFactory.decodeByteArray(idcard.jpgData, 0, idcard.jpgData.length); |
| | | saveIdCardToSdcard(idcard); |
| | | BaseApplication.getApplication().detectLock.lock(); |
| | | File file = new File(Constants.attachmentPath + idcard.cardNumber + ".jpg"); |
| | | idcard.featureData = FaceId.instance.extractFeature(file.getAbsolutePath()); |
| | | BaseApplication.getApplication().detectLock.unlock(); |
| | | BaseFragment.idCardReadTime = System.currentTimeMillis(); |
| | | System.out.println("IdCardManager.onReceive 2"); |
| | | BaseFragment.idCard = idcard; |
| | | saveIdCard(idcard); |
| | | } |
| | | } |
| | | IdCard idcard = new IdCard(); |
| | | // idcard.birthday = idCard.getBirthday().getTime();//intent.getLongExtra("birthday", 0); |
| | | idcard.cardNumber = cardNumber;// intent.getStringExtra("cardNumber"); |
| | | idcard.gender = info.getSex();//intent.getStringExtra("gender"); |
| | | idcard.name = name;//intent.getStringExtra("name").trim(); |
| | | idcard.headBitmap = photo;//BitmapFactory.decodeFile("/sdcard/security_excel_attachment/" + idcard.cardNumber + ".bmp"); |
| | | ByteArrayOutputStream stream = new ByteArrayOutputStream(); |
| | | idcard.headBitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream); |
| | | idcard.jpgData = stream.toByteArray(); |
| | | idcard.createTime = System.currentTimeMillis(); |
| | | System.out.println("IdCardManager.onReceive " + idcard.name); |
| | | saveIdCardToSdcard(idcard); |
| | | BaseApplication.getApplication().detectLock.lock(); |
| | | File file = new File(Constants.attachmentPath + idcard.cardNumber + ".jpg"); |
| | | idcard.featureData = FaceId.instance.extractFeature(file.getAbsolutePath()); |
| | | BaseApplication.getApplication().detectLock.unlock(); |
| | | lastIdCard = idcard; |
| | | SocketUtil.rpcCallSendIdCard(idcard); |
| | | } |
| | | |
| | | } else { |
| | | SystemClock.sleep(4*1000); |
| | | } |
| | | } |
| | | if (1 == 1) { |
| | | if (1 == 1) { |
| | | IdCard idcard = new IdCard(); |
| | | // idcard.birthday = intent.getLongExtra("birthday", 0); |
| | | // idcard.cardNumber = intent.getStringExtra("cardNumber"); |
| | | // idcard.gender = intent.getStringExtra("gender"); |
| | | // idcard.name = intent.getStringExtra("name").trim(); |
| | | // idcard.headBitmap = BitmapFactory.decodeFile("/sdcard/security_excel_attachment/" + idcard.cardNumber + ".bmp"); |
| | | idcard.birthday = idCard.getBirthday().getTime();//intent.getLongExtra("birthday", 0); |
| | | idcard.cardNumber = idCard.getNumber();// intent.getStringExtra("cardNumber"); |
| | | idcard.gender = idCard.getSex().toString();//intent.getStringExtra("gender"); |
| | | idcard.name = idCard.getName();//intent.getStringExtra("name").trim(); |
| | | idcard.headBitmap = idCard.getPhoto();//BitmapFactory.decodeFile("/sdcard/security_excel_attachment/" + idcard.cardNumber + ".bmp"); |
| | | ByteArrayOutputStream stream = new ByteArrayOutputStream(); |
| | | idcard.headBitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream); |
| | | idcard.jpgData = stream.toByteArray(); |
| | | idcard.createTime = System.currentTimeMillis(); |
| | | System.out.println("IdCardManager.onReceive " + idcard.name); |
| | | BaseApplication.getApplication().detectLock.lock(); |
| | | idcard.featureData = FaceId.instance.extractFeature1(getPixelsBGR(idcard.headBitmap), idcard.headBitmap.getWidth(), idcard.headBitmap.getHeight()); |
| | | BaseApplication.getApplication().detectLock.unlock(); |
| | | lastIdCard = idcard; |
| | | saveIdCardToSdcard(idcard); |
| | | SocketUtil.rpcCallSendIdCard(idcard); |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | }); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | }); |
| | | return; |
| | | } |
| | | if (Constants.isAraBM) { |
| | | BaseApplication.getApplication().executorService.execute(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | if (!Constants.USE_GRAY_CAMERA) { |
| | | return; |
| | | } |
| | | while (true) { |
| | | try { |
| | | Result result = mReader.read(); |
| | | if (result.error == IDCardReader.RESULT_OK) { |
| | | IDCard idCard = (IDCard) result.data; |
| | | System1.out.println("IdCardManager.run " + idCard); |
| | | AndroidBmpUtil.save(idCard.getPhoto(), Constants.attachmentPath + idCard.getNumber() + ".bmp"); |
| | | MainActivity activity = BaseApplication.getApplication().activity; |
| | | if (activity != null) { |
| | | if (activity.currentFragment == activity.fragment_su_auto_ic_wait_idcard |
| | | || activity.currentFragment == activity.fragment_su_logged_ic_wait_idcard |
| | | || (activity.currentFragment == activity.fragment_person_manage && activity.fragment_person_manage.needIdCardInfo())) { |
| | | if (1 == 1) { |
| | | IdCard idcard = new IdCard(); |
| | | idcard.birthday = idCard.getBirthday().getTime();//intent.getLongExtra("birthday", 0); |
| | | idcard.cardNumber = idCard.getNumber();// intent.getStringExtra("cardNumber"); |
| | | idcard.gender = idCard.getSex().toString();//intent.getStringExtra("gender"); |
| | | idcard.name = idCard.getName();//intent.getStringExtra("name").trim(); |
| | | idcard.headBitmap = idCard.getPhoto();//BitmapFactory.decodeFile("/sdcard/security_yuyin_attachment/" + idcard.cardNumber + ".bmp"); |
| | | ByteArrayOutputStream stream = new ByteArrayOutputStream(); |
| | | idcard.headBitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream); |
| | | idcard.jpgData = stream.toByteArray(); |
| | | //BitmapFactory.decodeByteArray(idcard.jpgData, 0, idcard.jpgData.length); |
| | | BaseApplication.getApplication().detectLock.lock(); |
| | | idcard.featureData = FaceId.instance.extractFeature1(getPixelsBGR(idcard.headBitmap), idcard.headBitmap.getWidth(), idcard.headBitmap.getHeight()); |
| | | BaseApplication.getApplication().detectLock.unlock(); |
| | | BaseFragment.idCardReadTime = System.currentTimeMillis(); |
| | | System1.out.println("IdCardManager.onReceive 2"); |
| | | BaseFragment.idCard = idcard; |
| | | saveIdCard(idcard); |
| | | } |
| | | } |
| | | if (1 == 1) { |
| | | if (1 == 1) { |
| | | IdCard idcard = new IdCard(); |
| | | idcard.birthday = idCard.getBirthday().getTime();//intent.getLongExtra("birthday", 0); |
| | | idcard.cardNumber = idCard.getNumber();// intent.getStringExtra("cardNumber"); |
| | | idcard.gender = idCard.getSex().toString();//intent.getStringExtra("gender"); |
| | | idcard.name = idCard.getName();//intent.getStringExtra("name").trim(); |
| | | idcard.headBitmap = idCard.getPhoto();//BitmapFactory.decodeFile("/sdcard/security_yuyin_attachment/" + idcard.cardNumber + ".bmp"); |
| | | ByteArrayOutputStream stream = new ByteArrayOutputStream(); |
| | | idcard.headBitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream); |
| | | idcard.jpgData = stream.toByteArray(); |
| | | idcard.createTime = System.currentTimeMillis(); |
| | | System1.out.println("IdCardManager.onReceive " + idcard.name); |
| | | BaseApplication.getApplication().detectLock.lock(); |
| | | idcard.featureData = FaceId.instance.extractFeature1(getPixelsBGR(idcard.headBitmap), idcard.headBitmap.getWidth(), idcard.headBitmap.getHeight()); |
| | | BaseApplication.getApplication().detectLock.unlock(); |
| | | lastIdCard = idcard; |
| | | saveIdCardToSdcard(idcard); |
| | | SocketUtil.rpcCallSendIdCard(idcard); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }); |
| | | }); |
| | | } |
| | | |
| | | if (Constants.indoorOutdoorInOne) { |
| | | return; |
| | | } |
| | |
| | | // BaseApplication.getApplication().executorService.execute(()->{ |
| | | // while (true) { |
| | | // try { |
| | | // System.out.println("IdCardManager.startReadIdCard " + 1); |
| | | // System1.out.println("IdCardManager.startReadIdCard " + 1); |
| | | // if (readUtil.isPort()) { |
| | | // System.out.println("IdCardManager.startReadIdCard " + 2); |
| | | // System1.out.println("IdCardManager.startReadIdCard " + 2); |
| | | // IDCard idCard = readUtil.readCard(); |
| | | // System.out.println("ReadIDCardService.run idCard=" + idCard); |
| | | // System1.out.println("ReadIDCardService.run idCard=" + idCard); |
| | | // if (idCard != null) { |
| | | // Bitmap headBitmap = BitmapFactory.decodeFile(idCard.getIdPhoto()); |
| | | // IdCard c = new IdCard(); |
| | |
| | | } |
| | | activity.readCardUtil = new ReadCardUtil(activity, new ReadCardUtil.OnReadCardListener() { |
| | | public void onReadCardSucceed(String s, CardInfo cardInfo, Intent intent) { |
| | | System.out.println("IdCardManager.onReadCardSucceed"); |
| | | System1.out.println("IdCardManager.onReadCardSucceed"); |
| | | if (activity != null) { |
| | | if (activity.currentFragment == activity.fragment_su_auto_ic_wait_idcard || activity.currentFragment == activity.fragment_su_logged_ic_wait_idcard |
| | | || (activity.currentFragment == activity.fragment_person_manage && activity.fragment_person_manage.needIdCardInfo())) { |
| | |
| | | } |
| | | |
| | | public void onReadCardFail(int i, String s) { |
| | | System.out.println("IdCardManager.onReadCardFail"); |
| | | System1.out.println("IdCardManager.onReadCardFail"); |
| | | } |
| | | }); |
| | | filter = new IntentFilter(); |
| | | filter.addAction("read.id.card.data"); |
| | | receiver = new BroadcastReceiver() { |
| | | public void onReceive(Context context, Intent intent) { |
| | | System.out.println("IdCardManager.onReceive 1"); |
| | | System1.out.println("IdCardManager.onReceive 1"); |
| | | if (activity != null) { |
| | | if (activity.currentFragment == activity.fragment_su_auto_ic_wait_idcard |
| | | || activity.currentFragment == activity.fragment_su_logged_ic_wait_idcard |
| | |
| | | idcard.cardNumber = intent.getStringExtra("cardNumber"); |
| | | idcard.gender = intent.getStringExtra("gender"); |
| | | idcard.name = intent.getStringExtra("name").trim(); |
| | | idcard.headBitmap = BitmapFactory.decodeFile("/sdcard/security_excel_attachment/" + idcard.cardNumber + ".bmp"); |
| | | idcard.headBitmap = BitmapFactory.decodeFile("/sdcard/security_yuyin_attachment/" + idcard.cardNumber + ".bmp"); |
| | | ByteArrayOutputStream stream = new ByteArrayOutputStream(); |
| | | idcard.headBitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream); |
| | | idcard.jpgData = stream.toByteArray(); |
| | |
| | | idcard.featureData = FaceId.instance.extractFeature1(getPixelsBGR(idcard.headBitmap), idcard.headBitmap.getWidth(), idcard.headBitmap.getHeight()); |
| | | BaseApplication.getApplication().detectLock.unlock(); |
| | | BaseFragment.idCardReadTime = System.currentTimeMillis(); |
| | | System.out.println("IdCardManager.onReceive 2"); |
| | | System1.out.println("IdCardManager.onReceive 2"); |
| | | BaseFragment.idCard = idcard; |
| | | saveIdCard(idcard); |
| | | } |
| | |
| | | idcard.cardNumber = intent.getStringExtra("cardNumber"); |
| | | idcard.gender = intent.getStringExtra("gender"); |
| | | idcard.name = intent.getStringExtra("name").trim(); |
| | | idcard.headBitmap = BitmapFactory.decodeFile("/sdcard/security_excel_attachment/" + idcard.cardNumber + ".bmp"); |
| | | idcard.headBitmap = BitmapFactory.decodeFile("/sdcard/security_yuyin_attachment/" + idcard.cardNumber + ".bmp"); |
| | | ByteArrayOutputStream stream = new ByteArrayOutputStream(); |
| | | idcard.headBitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream); |
| | | idcard.jpgData = stream.toByteArray(); |
| | | // idcard.headBitmap = BitmapFactory.decodeByteArray(idcard.jpgData, 0, idcard.jpgData.length); |
| | | idcard.createTime = System.currentTimeMillis(); |
| | | System.out.println("IdCardManager.onReceive " + idcard.name); |
| | | System1.out.println("IdCardManager.onReceive " + idcard.name); |
| | | BaseApplication.getApplication().detectLock.lock(); |
| | | idcard.featureData = FaceId.instance.extractFeature1(getPixelsBGR(idcard.headBitmap), idcard.headBitmap.getWidth(), idcard.headBitmap.getHeight()); |
| | | BaseApplication.getApplication().detectLock.unlock(); |
| | |
| | | saveIdCardToSdcard(idcard); |
| | | SocketUtil.rpcCallSendIdCard(idcard); |
| | | // BaseFragment.idCardReadTime = System.currentTimeMillis(); |
| | | // System.out.println("IdCardManager.onReceive 2"); |
| | | // System1.out.println("IdCardManager.onReceive 2"); |
| | | // BaseFragment.idCard = idcard; |
| | | // saveIdCard(idcard); |
| | | } |