| | |
| | | import cn.com.basic.face.service.SurveillanceMng;
|
| | | 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;
|
| | |
|
| | |
| | | import com.lidroid.xutils.view.annotation.ViewInject;
|
| | | import com.lidroid.xutils.view.annotation.event.OnClick;
|
| | |
|
| | | import org.xutils.common.util.FileUtil;
|
| | | 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 IdCardReaderThread idCardReaderThread = null;
|
| | |
|
| | | private String idCardHeadPath = "";
|
| | |
|
| | | private static RegisterFragment instance = new RegisterFragment();
|
| | |
|
| | | public static RegisterFragment getInstance() {
|
| | |
| | | resetForm();
|
| | | }
|
| | |
|
| | | private File writeToFile(String fileName, byte[] fileBytes) {
|
| | | try {
|
| | | String dir = MainActivity.getInstance().getFilesDir().getAbsolutePath();
|
| | |
|
| | | File file = new File(dir, fileName);
|
| | | if (file.exists()) {
|
| | | file.delete();
|
| | | }
|
| | | file.createNewFile();
|
| | | BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(new File(dir, fileName)));
|
| | | bos.write(fileBytes);
|
| | | bos.flush();
|
| | | bos.close();
|
| | | return new File(dir, fileName);
|
| | | }catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | return null;
|
| | | }
|
| | |
|
| | | @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();
|
| | |
| | | fragment_register_phone.requestFocus();
|
| | | return;
|
| | | }
|
| | | String gender = fragment_register_gender.getValue();
|
| | | if (gender.trim().length() <= 0) {
|
| | | Toast.makeText(MainActivity.getInstance(), "性别不能为空", Toast.LENGTH_SHORT).show();
|
| | | fragment_register_gender.callOnClick();
|
| | | return;
|
| | | }
|
| | | String id_class = fragment_register_id_class.getValue();
|
| | | if (id_class.trim().length() <= 0) {
|
| | | Toast.makeText(MainActivity.getInstance(), "证件类型不能为空", Toast.LENGTH_SHORT).show();
|
| | | fragment_register_id_class.callOnClick();
|
| | | return;
|
| | | }
|
| | | String country = fragment_register_country.getValue();
|
| | | if (country.trim().length() <= 0) {
|
| | | Toast.makeText(MainActivity.getInstance(), "国籍不能为空", Toast.LENGTH_SHORT).show();
|
| | | fragment_register_country.callOnClick();
|
| | | return;
|
| | | }
|
| | | String id_num = fragment_register_id_num.getValue();
|
| | | if (id_num.trim().length() <= 0) {
|
| | | Toast.makeText(MainActivity.getInstance(), "证件编号不能为空", Toast.LENGTH_SHORT).show();
|
| | | fragment_register_id_num.requestFocus();
|
| | | return;
|
| | | }
|
| | | String birthday = fragment_register_birthday.getValue();
|
| | | if (birthday.trim().length() <= 0) {
|
| | | Toast.makeText(MainActivity.getInstance(), "出生日期不能为空", Toast.LENGTH_SHORT).show();
|
| | | fragment_register_birthday.callOnClick();
|
| | | return;
|
| | | }
|
| | | String company = fragment_register_company.getValue();
|
| | | if (company.trim().length() <= 0) {
|
| | | Toast.makeText(MainActivity.getInstance(), "公司名称不能为空", Toast.LENGTH_SHORT).show();
|
| | | fragment_register_company.requestFocus();
|
| | | return;
|
| | | }
|
| | | String remark = fragment_register_remark.getValue();
|
| | | if (remark.trim().length() <= 0) {
|
| | | Toast.makeText(MainActivity.getInstance(), "备注不能为空", Toast.LENGTH_SHORT).show();
|
| | | fragment_register_remark.requestFocus();
|
| | | return;
|
| | | }
|
| | | String visitor_class = fragment_register_visitor_class.getValue();
|
| | | if (visitor_class.trim().length() <= 0) {
|
| | | String visitor_type = fragment_register_visitor_class.getValue();
|
| | | if (visitor_type.trim().length() <= 0) {
|
| | | Toast.makeText(MainActivity.getInstance(), "访客类型不能为空", Toast.LENGTH_SHORT).show();
|
| | | fragment_register_visitor_class.callOnClick();
|
| | | return;
|
| | | }
|
| | | final PostData pd = new PostData();
|
| | |
|
| | | pd.addValue(Register.FieldNames.username, name);
|
| | | pd.addValue(Register.FieldNames.mobilePhone, phone);
|
| | | pd.addValue(Register.FieldNames.genderId, DictionaryMng.getInstance().getId(gender));
|
| | | pd.addValue(Register.FieldNames.identityTypeId, DictionaryMng.getInstance().getId(id_class));
|
| | | pd.addValue(Register.FieldNames.countryId, DictionaryMng.getInstance().getId(country));
|
| | | pd.addValue(Register.FieldNames.visitorTypeId, DictionaryMng.getInstance().getId(visitor_class));
|
| | | pd.addValue(Register.FieldNames.identifyNum, id_num);
|
| | | pd.addValue(Register.FieldNames.companyId, company);
|
| | | pd.addValue(Register.FieldNames.birthday, birthday);
|
| | |
|
| | |
|
| | | params.addBodyParameter(Register.FieldNames.username, name);
|
| | | params.addBodyParameter(Register.FieldNames.mobilePhone, phone);
|
| | | params.addBodyParameter(Register.FieldNames.genderId, DictionaryMng.getInstance().getId(gender));
|
| | | params.addBodyParameter(Register.FieldNames.identityTypeId, DictionaryMng.getInstance().getId(id_class));
|
| | | params.addBodyParameter(Register.FieldNames.countryId, DictionaryMng.getInstance().getId(country));
|
| | | params.addBodyParameter(Register.FieldNames.visitorTypeId, DictionaryMng.getInstance().getId(visitor_class));
|
| | | params.addBodyParameter(Register.FieldNames.identifyNum, id_num);
|
| | | params.addBodyParameter(Register.FieldNames.genderId, DictionaryMng.getInstance().getId(fragment_register_gender.getValue()));
|
| | | params.addBodyParameter(Register.FieldNames.identityTypeId, DictionaryMng.getInstance().getId(fragment_register_id_class.getValue()));
|
| | | params.addBodyParameter(Register.FieldNames.countryId, DictionaryMng.getInstance().getId(fragment_register_country.getValue()));
|
| | | params.addBodyParameter(Register.FieldNames.visitorTypeId, DictionaryMng.getInstance().getId(visitor_type));
|
| | | params.addBodyParameter(Register.FieldNames.identifyNum, fragment_register_id_num.getValue());
|
| | | params.addBodyParameter(Register.FieldNames.companyId, company);
|
| | | params.addBodyParameter(Register.FieldNames.birthday, birthday);
|
| | |
|
| | | params.addBodyParameter(Register.FieldNames.birthday, fragment_register_birthday.getValue());
|
| | | params.addBodyParameter(Register.FieldNames.remark, fragment_register_remark.getValue());
|
| | |
|
| | | if (surveillanceQueryItem_selectPhoto != null) {
|
| | | params.addBodyParameter("width", surveillanceQueryItem_selectPhoto.getWidth());
|
| | |
| | | for (int i = 0; i < nativeImg.size; i++) {
|
| | | imageBytes[i] = nativeImg.image[i];
|
| | | }
|
| | | pd.addData("rawSurveillancePhoto", "application/octet-stream", imageBytes);
|
| | |
|
| | | params.addBodyParameter("rawSurveillancePhoto", writeToFile("rawSurveillancePhoto", imageBytes));
|
| | | params.addBodyParameter("rawSurveillancePhoto", FileUtil.writeToFile("rawSurveillancePhoto", imageBytes));
|
| | | } else {
|
| | | params.addBodyParameter("rawSurveillancePhoto", writeToFile("rawSurveillancePhoto", new byte[]{}));
|
| | | params.addBodyParameter("rawSurveillancePhoto", FileUtil.writeToFile("rawSurveillancePhoto", new byte[]{}));
|
| | | }
|
| | |
|
| | | if (fragment_register_surveillance_photo_img != null) {
|
| | | ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
| | | fragment_register_surveillance_photo_img.compress(Bitmap.CompressFormat.JPEG, 100, byteArrayOutputStream);
|
| | | byte[] imageBytes = byteArrayOutputStream.toByteArray();
|
| | | pd.addData(Register.FieldNames.surveillancePhoto, "application/octet-stream", imageBytes);
|
| | |
|
| | | params.addBodyParameter("surveillancePhoto", writeToFile("surveillancePhoto", imageBytes));
|
| | | params.addBodyParameter("surveillancePhoto", FileUtil.writeToFile("surveillancePhoto", imageBytes));
|
| | | } else {
|
| | | params.addBodyParameter("surveillancePhoto", writeToFile("surveillancePhoto", new byte[]{}));
|
| | | params.addBodyParameter("surveillancePhoto", FileUtil.writeToFile("surveillancePhoto", new byte[]{}));
|
| | | }
|
| | |
|
| | | if (fragment_register_upload_custom_photo_img != null) {
|
| | | ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
| | | fragment_register_upload_custom_photo_img.compress(Bitmap.CompressFormat.JPEG, 100, byteArrayOutputStream);
|
| | | byte[] imageBytes = byteArrayOutputStream.toByteArray();
|
| | | pd.addData(Register.FieldNames.uploadCustomPhoto, "application/octet-stream", imageBytes);
|
| | |
|
| | | params.addBodyParameter("uploadCustomPhoto", writeToFile("uploadCustomPhoto", imageBytes));
|
| | | params.addBodyParameter("uploadCustomPhoto", FileUtil.writeToFile("uploadCustomPhoto", imageBytes));
|
| | | } else {
|
| | | params.addBodyParameter("uploadCustomPhoto", writeToFile("uploadCustomPhoto", new byte[]{}));
|
| | | params.addBodyParameter("uploadCustomPhoto", FileUtil.writeToFile("uploadCustomPhoto", new byte[]{}));
|
| | | }
|
| | |
|
| | | if (fragment_register_id_card_photo_img != null) {
|
| | | ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
| | | fragment_register_id_card_photo_img.compress(Bitmap.CompressFormat.JPEG, 100, byteArrayOutputStream);
|
| | | byte[] imageBytes = byteArrayOutputStream.toByteArray();
|
| | | pd.addData(Register.FieldNames.idCardPhoto, "application/octet-stream", imageBytes);
|
| | |
|
| | | params.addBodyParameter("idCardPhoto", writeToFile("idCardPhoto", imageBytes));
|
| | | params.addBodyParameter("idCardPhoto", FileUtil.writeToFile("idCardPhoto", imageBytes));
|
| | | } else {
|
| | | params.addBodyParameter("idCardPhoto", writeToFile("idCardPhoto", new byte[]{}));
|
| | | params.addBodyParameter("idCardPhoto", FileUtil.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, idCardHeadPath);
|
| | | }
|
| | |
|
| | | public void set_fragment_register_surveillance_photo(SurveillanceQueryItem item) {
|
| | |
| | | selectedCustomPhotoId = -1;
|
| | | selectedSurveillancePhotoId = -1;
|
| | |
|
| | | idCardHeadPath = "";
|
| | |
|
| | | 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();
|
| | | idCardReaderThread = new IdCardReaderThread();
|
| | | idCardReaderThread.start();
|
| | | }
|
| | |
|
| | | public void readIdCard() {
|
| | | public void fillFormWithIdCard(IdCard idCard) {
|
| | | try {
|
| | | Thread.sleep(100);
|
| | | fragment_register_name.setValue(idCard.getName());
|
| | | fragment_register_id_num.setValue(idCard.getCardNumber());
|
| | |
|
| | | RFIDReader idCardReader = RFIDReader.getInstance(BaseApplication.getInstance(), "uart");
|
| | | idCardReader.setUartDeviceName("/dev/ttyS1");
|
| | | ByteArrayInputStream type = new ByteArrayInputStream("uart".getBytes());
|
| | | idCardReader.control(ReaderExtra.CONNECT, type);
|
| | | SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
|
| | | SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd");
|
| | |
|
| | | 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) {
|
| | | String[] decodeInfo = new String[10];
|
| | | 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();
|
| | |
|
| | | comparePictures();
|
| | | }
|
| | | 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(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);
|
| | | idCardHeadPath = idCard.getHeadPath();
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | }
|
| | |
|
| | | private void comparePictures() {
|
| | | private boolean registerFragmentVisible = false;
|
| | |
|
| | | RequestParams params = new RequestParams();
|
| | |
|
| | | if (fragment_register_surveillance_photo_img != null) {
|
| | | ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
| | | fragment_register_surveillance_photo_img.compress(Bitmap.CompressFormat.JPEG, 100, byteArrayOutputStream);
|
| | | byte[] imageBytes = byteArrayOutputStream.toByteArray();
|
| | |
|
| | | params.addBodyParameter("surveillancePhoto", writeToFile("surveillancePhoto", imageBytes));
|
| | | } else {
|
| | | params.addBodyParameter("surveillancePhoto", writeToFile("surveillancePhoto", new byte[]{}));
|
| | | }
|
| | |
|
| | |
|
| | | if (fragment_register_id_card_photo_img != null) {
|
| | | ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
| | | fragment_register_id_card_photo_img.compress(Bitmap.CompressFormat.JPEG, 100, byteArrayOutputStream);
|
| | | byte[] imageBytes = byteArrayOutputStream.toByteArray();
|
| | |
|
| | | params.addBodyParameter("idCardPhoto", writeToFile("idCardPhoto", imageBytes));
|
| | | } else {
|
| | | params.addBodyParameter("idCardPhoto", writeToFile("idCardPhoto", new byte[]{}));
|
| | | }
|
| | |
|
| | | RegisterMng.getInstance().compareSurveillancePhotoAndIdCardPhoto(params);
|
| | | @Override
|
| | | public void setMenuVisibility(boolean menuVisible) {
|
| | | super.setMenuVisibility(menuVisible);
|
| | | registerFragmentVisible = menuVisible;
|
| | | }
|
| | |
|
| | | 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);
|
| | | }
|
| | | }
|
| | |
|
| | |
|
| | |
|