| | |
| | | import cn.com.basic.face.widget.register.RegisterRightFieldTextView;
|
| | | import cn.com.basic.face.dialog.SelectDialog;
|
| | |
|
| | | import com.facebook.common.file.FileUtils;
|
| | | import com.ivsign.android.IDCReader.IDCReaderSDK;
|
| | | import com.lidroid.xutils.view.annotation.ViewInject;
|
| | | import com.lidroid.xutils.view.annotation.event.OnClick;
|
| | |
|
| | | import org.xutils.common.util.FileUtil;
|
| | | import org.xutils.common.util.IOUtil;
|
| | | import org.xutils.http.RequestParams;
|
| | |
|
| | | import java.io.BufferedOutputStream;
|
| | | import java.io.ByteArrayInputStream;
|
| | | import java.io.ByteArrayOutputStream;
|
| | | import java.io.File;
|
| | | import java.io.FileInputStream;
|
| | | import java.io.FileOutputStream;
|
| | | import java.io.IOException;
|
| | | import java.io.RandomAccessFile;
|
| | | import java.io.Reader;
|
| | | import java.text.SimpleDateFormat;
|
| | | import java.util.ArrayList;
|
| | |
| | |
|
| | | private File idCardImageCaptureFile = null;
|
| | |
|
| | | private String idCardHeadPhotoPath = "";
|
| | |
|
| | | private static RegisterFragment instance = new RegisterFragment();
|
| | |
|
| | | public static RegisterFragment getInstance() {
|
| | |
| | |
|
| | | @OnClick(R.id.fragment_register_save)
|
| | | public void fragment_register_save_click(View v) {
|
| | | readIdCard();
|
| | | //BaseApplication.getInstance().bindService();
|
| | | if (1==1) {
|
| | | return;
|
| | | }
|
| | |
|
| | | // RegisterMng.getInstance().add(null);
|
| | | // if (1==1) {
|
| | | // return;
|
| | | // }
|
| | |
|
| | | if (!BaseApplication.deviceAvailable) {
|
| | | return;
|
| | | }
|
| | |
|
| | | // SurveillanceMng.getInstance().addBitmap(new ArrayList(), new byte[]{1,2,3}, 3, "1");
|
| | | //
|
| | | // if (1==1) {
|
| | | // return;
|
| | | // }
|
| | | RequestParams params = new RequestParams();
|
| | |
|
| | | String name = fragment_register_name.getValue();
|
| | |
| | | } else {
|
| | | params.addBodyParameter("idCardPhoto", writeToFile("idCardPhoto", new byte[]{}));
|
| | | }
|
| | |
|
| | |
|
| | | class ConnectionTask extends AsyncTask<String, Void, String> {
|
| | | private String json = "";
|
| | | @Override
|
| | | protected String doInBackground(String... urls) {
|
| | | try {
|
| | | // Uploader uploader = new Uploader("", AppApi.BASE_URL + AppApi.REGISTER_ADD);
|
| | | // json = uploader.upload("", pd);
|
| | | return json;
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | return null;
|
| | | }
|
| | |
|
| | | @Override
|
| | | protected void onPostExecute(String result) {
|
| | | try {
|
| | | Toast.makeText(BaseApplication.getInstance(),"添加成功", Toast.LENGTH_SHORT).show();
|
| | | //RegisterFragment.getInstance().resetForm();
|
| | | } catch(Exception e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | }
|
| | |
|
| | | }
|
| | | // ConnectionTask task = new ConnectionTask();
|
| | | // String[] params1 = new String[2];
|
| | | // task.execute(params1);
|
| | |
|
| | | RegisterMng.getInstance().add(params);
|
| | | RegisterMng.getInstance().add(params, idCardHeadPhotoPath);
|
| | | }
|
| | |
|
| | | public void set_fragment_register_surveillance_photo(SurveillanceQueryItem item) {
|
| | |
| | | selectedCustomPhotoId = -1;
|
| | | selectedSurveillancePhotoId = -1;
|
| | |
|
| | | idCardHeadPhotoPath = "";
|
| | |
|
| | | fragment_register_name.setValue("徐修溪"+Math.random());
|
| | | fragment_register_phone.setValue("13691348767");
|
| | | fragment_register_id_num.setValue("36041419292222222");
|
| | |
| | | fragment_register_remark.setValue("备注");
|
| | |
|
| | | fragment_register_name.setValue("");
|
| | | fragment_register_phone.setValue("");
|
| | | fragment_register_id_num.setValue("");
|
| | | fragment_register_birthday.setValue("");
|
| | | fragment_register_company.setValue("");
|
| | | fragment_register_remark.setValue("");
|
| | |
|
| | | fragment_register_gender.setValue("男");
|
| | | fragment_register_id_class.setValue("身份证");
|
| | |
| | | @Override
|
| | | protected void initData() {
|
| | | resetForm();
|
| | | new ReadIdCardThread().start();
|
| | | }
|
| | |
|
| | | public void fillFormWithIdCard() {
|
| | | try {
|
| | | fragment_register_name.setValue(idCard_name);
|
| | | fragment_register_id_num.setValue(idCard_idNumber);
|
| | |
|
| | | 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_id_class.setValue("身份证");
|
| | | BitmapFactory.Options options = new BitmapFactory.Options();
|
| | | options.inPreferredConfig = Bitmap.Config.ARGB_8888;
|
| | | Bitmap bitmap = BitmapFactory.decodeFile(idCardHeadPhotoPath, 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(1000);
|
| | | readIdCard();
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | public void readIdCard() {
|
| | | try {
|
| | | Thread.sleep(100);
|
| | | if (!registerFragmentVisible) {
|
| | | return;
|
| | | }
|
| | |
|
| | | RFIDReader idCardReader = RFIDReader.getInstance(BaseApplication.getInstance(), "uart");
|
| | | idCardReader.setUartDeviceName("/dev/ttyS1");
|
| | |
| | | idCardReader.control(ReaderExtra.ID_READ_TEXT_PHOTO, baos);
|
| | | String textPhoto = byteArrayToHexString(baos.toByteArray());
|
| | | if (textPhoto != null) {
|
| | | String[] decodeInfo = new String[10];
|
| | | StringBuilder imagePath = new StringBuilder();
|
| | | 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);
|
| | | String name = decodeInfo[0];
|
| | | String sex = decodeInfo[1];
|
| | | String nation = decodeInfo[2];
|
| | | String birth = decodeInfo[3];
|
| | | String address = decodeInfo[4];
|
| | | String idNumber = decodeInfo[5];
|
| | | String office = decodeInfo[6];
|
| | | String validDate = decodeInfo[7] + "-" + decodeInfo[8];
|
| | | String photo = imagePath.toString();
|
| | | 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];
|
| | |
|
| | | comparePictures();
|
| | | 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();
|
| | | }
|
| | | }
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | }
|
| | |
|
| | | private void comparePictures() {
|
| | | private boolean registerFragmentVisible = false;
|
| | |
|
| | | @Override
|
| | | public void setMenuVisibility(boolean menuVisible) {
|
| | | super.setMenuVisibility(menuVisible);
|
| | | registerFragmentVisible = menuVisible;
|
| | | }
|
| | |
|
| | | private void testComparePicturesWithJpeg() {
|
| | |
|
| | | RequestParams params = new RequestParams();
|
| | |
|
| | | if (fragment_register_surveillance_photo_img != null) {
|
| | | 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();
|
| | | fragment_register_surveillance_photo_img.compress(Bitmap.CompressFormat.JPEG, 100, 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 (fragment_register_id_card_photo_img != null) {
|
| | | 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();
|
| | | fragment_register_id_card_photo_img.compress(Bitmap.CompressFormat.JPEG, 100, 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[]{}));
|
| | | }
|
| | |
|
| | |
| | | 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[]{};
|
| | | }
|
| | |
|
| | |
|
| | | }
|