From 5ade7f3782a57abdf418361bd2f9baeb6ad3707e Mon Sep 17 00:00:00 2001
From: xuxiuxi <xuxiuxi@454eff88-639b-444f-9e54-f578c98de674>
Date: 星期五, 07 七月 2017 12:51:52 +0800
Subject: [PATCH]
---
VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/fragment/RegisterFragment.java | 308 +------------------------
VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/util/AppApi.java | 4
VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/util/IdCardReaderThread.java | 140 +++++++++++
VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/service/RegisterMng.java | 131 ++++------
VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/util/IdCard.java | 61 +++++
VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/util/FileUtil.java | 30 ++
6 files changed, 305 insertions(+), 369 deletions(-)
diff --git a/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/fragment/RegisterFragment.java b/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/fragment/RegisterFragment.java
index 2b1c9ea..be628d5 100644
--- a/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/fragment/RegisterFragment.java
+++ b/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/fragment/RegisterFragment.java
@@ -42,6 +42,10 @@
import cn.com.basic.face.util.BitmapUtil;
import cn.com.basic.face.util.Constant;
import cn.com.basic.face.util.FileUtil;
+import static cn.com.basic.face.util.FileUtil.*;
+
+import cn.com.basic.face.util.IdCard;
+import cn.com.basic.face.util.IdCardReaderThread;
import cn.com.basic.face.util.NativeImg;
import cn.com.basic.face.util.OkClickedListener;
@@ -135,7 +139,9 @@
private File idCardImageCaptureFile = null;
- private String idCardHeadPhotoPath = "";
+ private IdCardReaderThread idCardReaderThread = null;
+
+ private String idCardHeadPath = "";
private static RegisterFragment instance = new RegisterFragment();
@@ -236,7 +242,7 @@
} else {
params.addBodyParameter("idCardPhoto", FileUtil.writeToFile("idCardPhoto", new byte[]{}));
}
- RegisterMng.getInstance().add(params, idCardHeadPhotoPath);
+ RegisterMng.getInstance().add(params, idCardHeadPath);
}
public void set_fragment_register_surveillance_photo(SurveillanceQueryItem item) {
@@ -357,7 +363,7 @@
selectedCustomPhotoId = -1;
selectedSurveillancePhotoId = -1;
- idCardHeadPhotoPath = "";
+ idCardHeadPath = "";
fragment_register_name.setValue("寰愪慨婧�"+Math.random());
fragment_register_phone.setValue("13691348767");
@@ -504,100 +510,28 @@
@Override
protected void initData() {
resetForm();
- new ReadIdCardThread().start();
+ idCardReaderThread = new IdCardReaderThread();
+ idCardReaderThread.start();
}
- public void fillFormWithIdCard() {
+ public void fillFormWithIdCard(IdCard idCard) {
try {
- fragment_register_name.setValue(idCard_name);
- fragment_register_id_num.setValue(idCard_idNumber);
+ fragment_register_name.setValue(idCard.getName());
+ fragment_register_id_num.setValue(idCard.getCardNumber());
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd");
- fragment_register_birthday.setValue(sdf1.format(sdf.parse(idCard_birth)));
- fragment_register_gender.setValue(idCard_sex);
+ fragment_register_birthday.setValue(sdf1.format(sdf.parse(idCard.getBirthday())));
+ fragment_register_gender.setValue(idCard.getGender());
fragment_register_id_class.setValue("韬唤璇�");
BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
- Bitmap bitmap = BitmapFactory.decodeFile(idCardHeadPhotoPath, options);
+ Bitmap bitmap = BitmapFactory.decodeFile(idCard.getHeadPath(), options);
fragment_register_id_card_photo.setImageBitmap(bitmap);
fragment_register_id_card_photo_placeholder_image.setVisibility(View.INVISIBLE);
fragment_register_id_card_photo_placeholder_text_view.setVisibility(View.INVISIBLE);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- private String idCard_name = "";
- private String idCard_idNumber = "";
- private String idCard_birth = "";
- private String idCard_sex = "";
-
- class ReadIdCardThread extends Thread {
-
- @Override
- public void run() {
- while(true) {
- try{
- Thread.sleep(2000);
- readIdCard();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
- }
-
- public void readIdCard() {
- try {
- if (!registerFragmentVisible || !RegisterFragment.getInstance().isVisible()) {
- return;
- }
-
- RFIDReader idCardReader = RFIDReader.getInstance(BaseApplication.getInstance(), "uart");
- idCardReader.setUartDeviceName("/dev/ttyS4");
- ByteArrayInputStream type = new ByteArrayInputStream("uart".getBytes());
- idCardReader.control(ReaderExtra.CONNECT, type);
-
- idCardReader.open("id_card");
- String cardId = byteArrayToHexString(idCardReader.getUid());
-
- idCardReader.open("id_sam");
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- idCardReader.control(ReaderExtra.ID_READ_TEXT_PHOTO, baos);
- String textPhoto = byteArrayToHexString(baos.toByteArray());
- if (textPhoto != null) {
- final String[] decodeInfo = new String[10];
- final StringBuilder imagePath = new StringBuilder();
- String path = MainActivity.getInstance().getFilesDir().getAbsolutePath();
- IDCReaderSDK.initialize(path);
- IDCReaderSDK.decodeSamAck(textPhoto, decodeInfo, imagePath);
- idCard_name = decodeInfo[0];
- idCard_sex = decodeInfo[1];
- idCard_idNumber = decodeInfo[5];
- idCard_birth = decodeInfo[3];
-// final String idCardNation = decodeInfo[2];
-// final String idCardAddress = decodeInfo[4];
-// final String idCardIssuingAuthority = decodeInfo[6];
-// final String idCardValidBegin = decodeInfo[7];
-// final String idCardValidEnd = decodeInfo[8];
-
- idCardHeadPhotoPath = imagePath.toString();
-
- if (fragment_register_surveillance_photo_img == null) {
-// MainActivity.getInstance().runOnUiThread(new Runnable() {
-// @Override
-// public void run() {
-// Toast.makeText(BaseApplication.getInstance(),"璇峰厛閫夋嫨浜虹墿鐓х墖", Toast.LENGTH_SHORT).show();
-// }
-// });
- //return;
- testComparePicturesWithJpeg();
- } else {
- testComparePicturesWithJpeg();
- }
- }
+ idCardHeadPath = idCard.getHeadPath();
} catch (Exception e) {
e.printStackTrace();
}
@@ -611,213 +545,7 @@
registerFragmentVisible = menuVisible;
}
- private void testComparePicturesWithJpeg() {
- RequestParams params = new RequestParams();
-
- if (idCardHeadPhotoPath != null && !"".equals(idCardHeadPhotoPath)) {
- BitmapFactory.Options options = new BitmapFactory.Options();
- options.inPreferredConfig = Bitmap.Config.ARGB_8888;
- Bitmap bitmap = BitmapFactory.decodeFile(idCardHeadPhotoPath, options);
-
- ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
- bitmap.compress(Bitmap.CompressFormat.JPEG, 100, byteArrayOutputStream);
- byte[] imageBytes = byteArrayOutputStream.toByteArray();
-
- params.addBodyParameter("surveillancePhotoW",bitmap.getWidth()+"");
- params.addBodyParameter("surveillancePhotoH",bitmap.getWidth()+"");
- params.addBodyParameter("surveillancePhoto", writeToFile("surveillancePhoto", imageBytes));
- } else {
- params.addBodyParameter("surveillancePhotoW", "0");
- params.addBodyParameter("surveillancePhotoH", "0");
- params.addBodyParameter("surveillancePhoto", writeToFile("surveillancePhoto", new byte[]{}));
- }
-
-
- if (idCardHeadPhotoPath != null && !"".equals(idCardHeadPhotoPath)) {
-
- BitmapFactory.Options options = new BitmapFactory.Options();
- options.inPreferredConfig = Bitmap.Config.ARGB_8888;
- Bitmap bitmap = BitmapFactory.decodeFile(idCardHeadPhotoPath, options);
-
- ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
- bitmap.compress(Bitmap.CompressFormat.JPEG, 100, byteArrayOutputStream);
- byte[] imageBytes = byteArrayOutputStream.toByteArray();
-
- params.addBodyParameter("idCardPhotoW",bitmap.getWidth()+"");
- params.addBodyParameter("idCardPhotoH",bitmap.getWidth()+"");
- params.addBodyParameter("idCardPhoto", writeToFile("idCardPhoto", imageBytes));
- } else {
- params.addBodyParameter("idCardPhotoW","0");
- params.addBodyParameter("idCardPhotoH","0");
- params.addBodyParameter("idCardPhoto", writeToFile("idCardHeadPhoto", new byte[]{}));
- }
-
- RegisterMng.getInstance().compareSurveillancePhotoAndIdCardPhoto(params);
- }
-
- private void testComparePicturesWithBmp() {
-
- RequestParams params = new RequestParams();
-
- if (idCardHeadPhotoPath != null && !"".equals(idCardHeadPhotoPath)) {
- BitmapFactory.Options options = new BitmapFactory.Options();
- options.inPreferredConfig = Bitmap.Config.ARGB_8888;
- Bitmap bitmap = BitmapFactory.decodeFile(idCardHeadPhotoPath, options);
- params.addBodyParameter("surveillancePhotoW", bitmap.getWidth() + "");
- params.addBodyParameter("surveillancePhotoH", bitmap.getWidth() + "");
- params.addBodyParameter("surveillancePhoto", writeToFile("surveillancePhoto", readFile(new File(idCardHeadPhotoPath))));
- } else {
- params.addBodyParameter("surveillancePhotoW", "0");
- params.addBodyParameter("surveillancePhotoH", "0");
- params.addBodyParameter("surveillancePhoto", writeToFile("surveillancePhoto", new byte[]{}));
- }
-
-
- if (idCardHeadPhotoPath != null && !"".equals(idCardHeadPhotoPath)) {
- BitmapFactory.Options options = new BitmapFactory.Options();
- options.inPreferredConfig = Bitmap.Config.ARGB_8888;
- Bitmap bitmap = BitmapFactory.decodeFile(idCardHeadPhotoPath, options);
-
-
- params.addBodyParameter("idCardPhotoW",bitmap.getWidth()+"");
- params.addBodyParameter("idCardPhotoH",bitmap.getWidth()+"");
- params.addBodyParameter("idCardPhoto", writeToFile("idCardPhoto", readFile(new File(idCardHeadPhotoPath))));
- } else {
- params.addBodyParameter("idCardPhotoW","0");
- params.addBodyParameter("idCardPhotoH","0");
- params.addBodyParameter("idCardPhoto", writeToFile("idCardPhoto", new byte[]{}));
- }
-
- RegisterMng.getInstance().compareSurveillancePhotoAndIdCardPhoto(params);
- }
-
- private void comparePictures() {
-
- RequestParams params = new RequestParams();
-
-// if (fragment_register_surveillance_photo_img != null) {
-// ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
-// fragment_register_surveillance_photo_img.compress(Bitmap.CompressFormat.PNG, 100, byteArrayOutputStream);
-// byte[] imageBytes = byteArrayOutputStream.toByteArray();
-//
-// params.addBodyParameter("surveillancePhotoW",fragment_register_surveillance_photo_img.getWidth()+"");
-// params.addBodyParameter("surveillancePhotoH",fragment_register_surveillance_photo_img.getHeight()+"");
-//
-// params.addBodyParameter("surveillancePhoto", writeToFile("surveillancePhoto", imageBytes));
-// } else {
-// params.addBodyParameter("surveillancePhotoW","0");
-// params.addBodyParameter("surveillancePhotoH","0");
-// params.addBodyParameter("surveillancePhoto", writeToFile("surveillancePhoto", new byte[]{}));
-// }
-
- if (idCardHeadPhotoPath != null && !"".equals(idCardHeadPhotoPath)) {
- BitmapFactory.Options options = new BitmapFactory.Options();
- options.inPreferredConfig = Bitmap.Config.ARGB_8888;
- Bitmap bitmap = BitmapFactory.decodeFile(idCardHeadPhotoPath, options);
-
- ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
- bitmap.compress(Bitmap.CompressFormat.JPEG, 100, byteArrayOutputStream);
- byte[] imageBytes = byteArrayOutputStream.toByteArray();
-
- params.addBodyParameter("surveillancePhotoW",bitmap.getWidth()+"");
- params.addBodyParameter("surveillancePhotoH",bitmap.getWidth()+"");
- params.addBodyParameter("surveillancePhoto", writeToFile("surveillancePhoto", imageBytes));
-
-
- ///////////////////////////////////
-
-
-
- /////////////////////////////////
-// BitmapFactory.Options options = new BitmapFactory.Options();
-// options.inPreferredConfig = Bitmap.Config.ARGB_8888;
-// Bitmap bitmap = BitmapFactory.decodeFile(idCardHeadPhotoPath, options);
-// params.addBodyParameter("surveillancePhotoW", bitmap.getWidth() + "");
-// params.addBodyParameter("surveillancePhotoH", bitmap.getWidth() + "");
-// params.addBodyParameter("surveillancePhoto", writeToFile("surveillancePhoto", readFile(new File(idCardHeadPhotoPath))));
- } else {
- params.addBodyParameter("surveillancePhotoW", "0");
- params.addBodyParameter("surveillancePhotoH", "0");
- params.addBodyParameter("surveillancePhoto", writeToFile("surveillancePhoto", new byte[]{}));
- }
-
-
- if (idCardHeadPhotoPath != null && !"".equals(idCardHeadPhotoPath)) {
-
- BitmapFactory.Options options = new BitmapFactory.Options();
- options.inPreferredConfig = Bitmap.Config.ARGB_8888;
- Bitmap bitmap = BitmapFactory.decodeFile(idCardHeadPhotoPath, options);
-
- ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
- bitmap.compress(Bitmap.CompressFormat.JPEG, 100, byteArrayOutputStream);
- byte[] imageBytes = byteArrayOutputStream.toByteArray();
-
- params.addBodyParameter("idCardPhotoW",bitmap.getWidth()+"");
- params.addBodyParameter("idCardPhotoH",bitmap.getWidth()+"");
- params.addBodyParameter("idCardPhoto", writeToFile("idCardPhoto", imageBytes));
-
-
- ///////////////////////////////////
-
-// BitmapFactory.Options options = new BitmapFactory.Options();
-// options.inPreferredConfig = Bitmap.Config.ARGB_8888;
-// Bitmap bitmap = BitmapFactory.decodeFile(idCardHeadPhotoPath, options);
-//
-//
-// params.addBodyParameter("idCardPhotoW",bitmap.getWidth()+"");
-// params.addBodyParameter("idCardPhotoH",bitmap.getWidth()+"");
-// params.addBodyParameter("idCardPhoto", writeToFile("idCardPhoto", readFile(new File(idCardHeadPhotoPath))));
- } else {
- params.addBodyParameter("idCardPhotoW","0");
- params.addBodyParameter("idCardPhotoH","0");
- params.addBodyParameter("idCardPhoto", writeToFile("idCardPhoto", new byte[]{}));
- }
-
- RegisterMng.getInstance().compareSurveillancePhotoAndIdCardPhoto(params);
- }
-
- protected static final char[] a = new char[]{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
- public static String byteArrayToHexString(byte[] bytes) {
- if(bytes == null) {
- return null;
- } else {
- char[] hexChars = new char[bytes.length * 2];
-
- for(int j = 0; j < bytes.length; ++j) {
- int v = bytes[j] & 255;
- hexChars[j * 2] = a[v >>> 4];
- hexChars[j * 2 + 1] = a[v & 15];
- }
-
- return new String(hexChars);
- }
- }
- public static byte[] readFile(File file) {
- // Open file
- RandomAccessFile f = null;
- try {
- f = new RandomAccessFile(file, "r");
- // Get and check length
- long longlength = f.length();
- int length = (int) longlength;
- if (length != longlength)
- throw new IOException("File size >= 2 GB");
- // Read file and return data
- byte[] data = new byte[length];
- f.readFully(data);
- return data;
- } catch (Exception e){
- e.printStackTrace();
- } finally {
- try {
- f.close();
- }catch (Exception e) {
- e.printStackTrace();
- }
- }
- return new byte[]{};
- }
}
diff --git a/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/service/RegisterMng.java b/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/service/RegisterMng.java
index b9dc589..849fbc4 100644
--- a/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/service/RegisterMng.java
+++ b/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/service/RegisterMng.java
@@ -15,6 +15,7 @@
import java.util.List;
import cn.com.basic.face.discern.common.BaseCommonCallBack;
+import cn.com.basic.face.util.IdCard;
public class RegisterMng {
@@ -28,82 +29,58 @@
if (!BaseApplication.deviceAvailable) {
return;
}
-// params = new RequestParams();
try {
-// params.setUri(AppApi.BASE_URL +AppApi.REGISTER_ADD);
-// x.http().post(params, new BaseCommonCallBack() {
-// @Override
-// public void success() {
-// Toast.makeText(BaseApplication.getInstance(),"娣诲姞鎴愬姛", Toast.LENGTH_SHORT).show();
-// //RegisterFragment.getInstance().resetForm();
-// }
-// });
-
-
- try {
- File path = BaseApplication.getInstance().getFilesDir();
- File f1 = new File(path, "rawSurveillancePhoto");
- if (!f1.exists()) {
- f1.createNewFile();
- }
- File f0 = new File(path, "f0");
- if (!f0.exists()) {
- f0.createNewFile();
- }
- File f2 = new File(path, "surveillancePhoto");
- if (!f2.exists()) {
- f2.createNewFile();
- }
- File f3 = new File(path, "uploadCustomPhoto");
- if (!f3.exists()) {
- f3.createNewFile();
- }
- File f4 = new File(path, "idCardPhoto");
- if (!f4.exists()) {
- f4.createNewFile();
- }
-
- FileWriter fw0 = new FileWriter(f0);
- fw0.write("test1");
- fw0.close();
-// FileWriter fw1 = new FileWriter(f1);
-// fw1.write("test1");
-// fw1.close();
-// FileWriter fw2 = new FileWriter(f2);
-// fw2.write("test2");
-// fw2.close();
- params.setUri(AppApi.BASE_URL +AppApi.REGISTER_ADD);
- params.addBodyParameter("f0", f0);
- params.addBodyParameter("rawSurveillancePhoto", f1);
- params.addBodyParameter("surveillancePhoto", f2);
- params.addBodyParameter("uploadCustomPhoto", f3);
- params.addBodyParameter("idCardPhoto", f4);
- if (idCardHeadPhoto != null && !"".equals(idCardHeadPhoto)) {
- File f5 = new File(idCardHeadPhoto);
- if (!f5.exists()) {
- f5.createNewFile();
- }
- params.addBodyParameter("idCardHeadPhoto", f5);
- }
- x.http().post(params, new BaseCommonCallBack() {
- @Override
- public void success() {
- Toast.makeText(BaseApplication.getInstance(),"娣诲姞鎴愬姛", Toast.LENGTH_SHORT).show();
- RegisterFragment.getInstance().resetForm();
- }
- });
- }catch(Exception e) {
- e.printStackTrace();
+ File path = BaseApplication.getInstance().getFilesDir();
+ File rawSurveillancePhotoFile = new File(path, "rawSurveillancePhoto");
+ if (!rawSurveillancePhotoFile.exists()) {
+ rawSurveillancePhotoFile.createNewFile();
+ }
+ File f0 = new File(path, "f0");
+ if (!f0.exists()) {
+ f0.createNewFile();
+ }
+ File surveillancePhotoFile = new File(path, "surveillancePhoto");
+ if (!surveillancePhotoFile.exists()) {
+ surveillancePhotoFile.createNewFile();
+ }
+ File uploadCustomPhotoFile = new File(path, "uploadCustomPhoto");
+ if (!uploadCustomPhotoFile.exists()) {
+ uploadCustomPhotoFile.createNewFile();
+ }
+ File idCardPhotoFile = new File(path, "idCardPhoto");
+ if (!idCardPhotoFile.exists()) {
+ idCardPhotoFile.createNewFile();
}
+ FileWriter fw0 = new FileWriter(f0);
+ fw0.write("test1");
+ fw0.close();
+ params.setUri(AppApi.BASE_URL +AppApi.REGISTER_ADD);
+ params.addBodyParameter("f0", f0);
+ params.addBodyParameter("rawSurveillancePhoto", rawSurveillancePhotoFile);
+ params.addBodyParameter("surveillancePhoto", surveillancePhotoFile);
+ params.addBodyParameter("uploadCustomPhoto", uploadCustomPhotoFile);
+ params.addBodyParameter("idCardPhoto", idCardPhotoFile);
+ if (idCardHeadPhoto != null && !"".equals(idCardHeadPhoto)) {
+ File f5 = new File(idCardHeadPhoto);
+ if (!f5.exists()) {
+ f5.createNewFile();
+ }
+ params.addBodyParameter("idCardHeadPhoto", f5);
+ }
+ x.http().post(params, new BaseCommonCallBack() {
+ @Override
+ public void success() {
+ Toast.makeText(BaseApplication.getInstance(),"娣诲姞鎴愬姛", Toast.LENGTH_SHORT).show();
+ RegisterFragment.getInstance().resetForm();
+ }
+ });
}catch(Exception e) {
e.printStackTrace();
-
}
}
-
- public void compareSurveillancePhotoAndIdCardPhoto(RequestParams params) {
+ public void compareSurveillancePhotoAndIdCardPhoto(RequestParams params, final IdCard idCard) {
if (!BaseApplication.deviceAvailable) {
return;
}
@@ -113,13 +90,13 @@
if (!f0.exists()) {
f0.createNewFile();
}
- File f2 = new File(path, "surveillancePhoto");
- if (!f2.exists()) {
- f2.createNewFile();
+ File surveillancePhotoFile = new File(path, "surveillancePhoto");
+ if (!surveillancePhotoFile.exists()) {
+ surveillancePhotoFile.createNewFile();
}
- File f4 = new File(path, "idCardHeadPhoto");
- if (!f4.exists()) {
- f4.createNewFile();
+ File idCardHeadPhotoFile = new File(path, "idCardHeadPhoto");
+ if (!idCardHeadPhotoFile.exists()) {
+ idCardHeadPhotoFile.createNewFile();
}
FileWriter fw0 = new FileWriter(f0);
fw0.write("test1");
@@ -127,8 +104,8 @@
params.setUri(AppApi.BASE_URL +AppApi.REGISTER_ID_CARD_AUTH);
params.addBodyParameter("f0", f0);
- params.addBodyParameter("surveillancePhoto", f2);
- params.addBodyParameter("idCardPhoto", f4);
+ params.addBodyParameter("surveillancePhoto", surveillancePhotoFile);
+ params.addBodyParameter("idCardPhoto", idCardHeadPhotoFile);
x.http().post(params, new BaseCommonCallBack() {
@Override
public void success() {
@@ -140,7 +117,7 @@
double percent = percents.get(0);
if (percent >= 70) {
Toast.makeText(BaseApplication.getInstance(),"璁よ瘉閫氳繃", Toast.LENGTH_SHORT).show();
- RegisterFragment.getInstance().fillFormWithIdCard();
+ RegisterFragment.getInstance().fillFormWithIdCard(idCard);
return;
}
System.out.println("percent="+percent);
diff --git a/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/util/AppApi.java b/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/util/AppApi.java
index 6109931..68901b5 100644
--- a/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/util/AppApi.java
+++ b/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/util/AppApi.java
@@ -5,8 +5,8 @@
//public final static String BASE_URL = "http://192.168.1.137:8333/face/";
public final static String IMAGE_URL_BASE = "http://192.168.1.49:8888/";
-// public final static String BASE_URL = "http://192.168.1.51/face/";
- public final static String BASE_URL = "http://192.168.1.4:8333/face/";
+ public final static String BASE_URL = "http://192.168.1.51/face/";
+// public final static String BASE_URL = "http://192.168.1.4:8333/face/";
public static final String REGISTER_ADD = "Register/o_add.do";
diff --git a/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/util/FileUtil.java b/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/util/FileUtil.java
index df47076..73f5fca 100644
--- a/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/util/FileUtil.java
+++ b/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/util/FileUtil.java
@@ -3,6 +3,8 @@
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.RandomAccessFile;
import cn.com.basic.face.base.MainActivity;
@@ -29,4 +31,32 @@
return null;
}
+
+ public static byte[] readFile(File file) {
+ // Open file
+ RandomAccessFile f = null;
+ try {
+ f = new RandomAccessFile(file, "r");
+ // Get and check length
+ long longlength = f.length();
+ int length = (int) longlength;
+ if (length != longlength)
+ throw new IOException("File size >= 2 GB");
+ // Read file and return data
+ byte[] data = new byte[length];
+ f.readFully(data);
+ return data;
+ } catch (Exception e){
+ e.printStackTrace();
+ } finally {
+ try {
+ f.close();
+ }catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ return new byte[]{};
+ }
+
+
}
diff --git a/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/util/IdCard.java b/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/util/IdCard.java
new file mode 100644
index 0000000..6dda94d
--- /dev/null
+++ b/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/util/IdCard.java
@@ -0,0 +1,61 @@
+package cn.com.basic.face.util;
+
+/**
+ * Created by xiuxi on 2017/7/7.
+ */
+
+public class IdCard {
+ private String name = "";
+ private String cardNumber = "";
+ private String birthday = "";
+ private String gender = "";
+ private String headPath = "";
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getCardNumber() {
+ return cardNumber;
+ }
+
+ public void setCardNumber(String cardNumber) {
+ this.cardNumber = cardNumber;
+ }
+
+ public String getBirthday() {
+ return birthday;
+ }
+
+ public void setBirthday(String birthday) {
+ this.birthday = birthday;
+ }
+
+ public String getGender() {
+ return gender;
+ }
+
+ public void setGender(String gender) {
+ this.gender = gender;
+ }
+
+ public String getHeadPath() {
+ return headPath;
+ }
+
+ public void setHeadPath(String headPath) {
+ this.headPath = headPath;
+ }
+
+ public IdCard(String name, String cardNumber, String birthday, String gender, String headPath) {
+ this.name = name;
+ this.cardNumber = cardNumber;
+ this.birthday = birthday;
+ this.gender = gender;
+ this.headPath = headPath;
+ }
+}
diff --git a/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/util/IdCardReaderThread.java b/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/util/IdCardReaderThread.java
new file mode 100644
index 0000000..487f896
--- /dev/null
+++ b/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/util/IdCardReaderThread.java
@@ -0,0 +1,140 @@
+package cn.com.basic.face.util;
+
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
+
+import com.bit.rfid.RFIDReader;
+import com.bit.rfid.ReaderExtra;
+import com.ivsign.android.IDCReader.IDCReaderSDK;
+
+import org.xutils.http.RequestParams;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+
+import cn.com.basic.face.base.BaseApplication;
+import cn.com.basic.face.base.MainActivity;
+import cn.com.basic.face.fragment.RegisterFragment;
+import cn.com.basic.face.service.RegisterMng;
+
+import static cn.com.basic.face.util.FileUtil.writeToFile;
+
+public class IdCardReaderThread extends Thread {
+
+
+ @Override
+ public void run() {
+ while(true) {
+ try{
+ Thread.sleep(2000);
+ try {
+ if (!RegisterFragment.getInstance().isVisible()) {
+ return;
+ }
+
+ RFIDReader idCardReader = RFIDReader.getInstance(BaseApplication.getInstance(), "uart");
+ idCardReader.setUartDeviceName("/dev/ttyS4");
+ ByteArrayInputStream type = new ByteArrayInputStream("uart".getBytes());
+ idCardReader.control(ReaderExtra.CONNECT, type);
+
+ idCardReader.open("id_card");
+
+ idCardReader.open("id_sam");
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ idCardReader.control(ReaderExtra.ID_READ_TEXT_PHOTO, baos);
+ String textPhoto = byteArrayToHexString(baos.toByteArray());
+
+
+
+ if (textPhoto != null) {
+ final String[] decodeInfo = new String[10];
+ final StringBuilder imagePath = new StringBuilder();
+ String path = MainActivity.getInstance().getFilesDir().getAbsolutePath();
+ IDCReaderSDK.initialize(path);
+ IDCReaderSDK.decodeSamAck(textPhoto, decodeInfo, imagePath);
+
+// if (fragment_register_surveillance_photo_img == null) {
+// // MainActivity.getInstance().runOnUiThread(new Runnable() {
+// // @Override
+// // public void run() {
+// // Toast.makeText(BaseApplication.getInstance(),"璇峰厛閫夋嫨浜虹墿鐓х墖", Toast.LENGTH_SHORT).show();
+// // }
+// // });
+// //return;
+// }
+ testComparePicturesWithJpeg(new IdCard(decodeInfo[0], decodeInfo[5], decodeInfo[3], decodeInfo[1], imagePath.toString()));
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+
+ protected static final char[] a = new char[]{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
+ public static String byteArrayToHexString(byte[] bytes) {
+ if(bytes == null) {
+ return null;
+ } else {
+ char[] hexChars = new char[bytes.length * 2];
+
+ for(int j = 0; j < bytes.length; ++j) {
+ int v = bytes[j] & 255;
+ hexChars[j * 2] = a[v >>> 4];
+ hexChars[j * 2 + 1] = a[v & 15];
+ }
+
+ return new String(hexChars);
+ }
+ }
+
+
+ private void testComparePicturesWithJpeg(IdCard idCard) {
+
+ RequestParams params = new RequestParams();
+
+ if (idCard.getHeadPath() != null && !"".equals(idCard.getHeadPath())) {
+ BitmapFactory.Options options = new BitmapFactory.Options();
+ options.inPreferredConfig = Bitmap.Config.ARGB_8888;
+ Bitmap bitmap = BitmapFactory.decodeFile(idCard.getHeadPath(), options);
+
+ ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+ bitmap.compress(Bitmap.CompressFormat.JPEG, 100, byteArrayOutputStream);
+ byte[] imageBytes = byteArrayOutputStream.toByteArray();
+
+ params.addBodyParameter("surveillancePhotoW",bitmap.getWidth()+"");
+ params.addBodyParameter("surveillancePhotoH",bitmap.getWidth()+"");
+ params.addBodyParameter("surveillancePhoto", writeToFile("surveillancePhoto", imageBytes));
+ } else {
+ params.addBodyParameter("surveillancePhotoW", "0");
+ params.addBodyParameter("surveillancePhotoH", "0");
+ params.addBodyParameter("surveillancePhoto", writeToFile("surveillancePhoto", new byte[]{}));
+ }
+
+
+ if (idCard.getHeadPath() != null && !"".equals(idCard.getHeadPath())) {
+
+ BitmapFactory.Options options = new BitmapFactory.Options();
+ options.inPreferredConfig = Bitmap.Config.ARGB_8888;
+ Bitmap bitmap = BitmapFactory.decodeFile(idCard.getHeadPath(), options);
+
+ ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+ bitmap.compress(Bitmap.CompressFormat.JPEG, 100, byteArrayOutputStream);
+ byte[] imageBytes = byteArrayOutputStream.toByteArray();
+
+ params.addBodyParameter("idCardPhotoW",bitmap.getWidth()+"");
+ params.addBodyParameter("idCardPhotoH",bitmap.getWidth()+"");
+ params.addBodyParameter("idCardPhoto", writeToFile("idCardPhoto", imageBytes));
+ } else {
+ params.addBodyParameter("idCardPhotoW","0");
+ params.addBodyParameter("idCardPhotoH","0");
+ params.addBodyParameter("idCardPhoto", writeToFile("idCardHeadPhoto", new byte[]{}));
+ }
+
+ RegisterMng.getInstance().compareSurveillancePhotoAndIdCardPhoto(params, idCard);
+ }
+
+}
--
Gitblit v1.8.0