| | |
| | | package cn.com.basic.face.fragment;
|
| | |
|
| | | import android.app.Activity;
|
| | | import android.content.BroadcastReceiver;
|
| | | import android.content.Context;
|
| | | import android.content.Intent;
|
| | | import android.graphics.Bitmap;
|
| | | import android.graphics.BitmapFactory;
|
| | | import android.net.Uri;
|
| | | import android.os.AsyncTask;
|
| | | import android.os.Environment;
|
| | | import android.provider.MediaStore;
|
| | | import android.util.Base64;
|
| | |
| | | import android.widget.TextView;
|
| | | import android.widget.Toast;
|
| | |
|
| | | import com.alibaba.fastjson.JSON;
|
| | | import com.alibaba.fastjson.JSONArray;
|
| | | import com.bit.rfid.RFIDReader;
|
| | | import com.bit.rfid.ReaderExtra;
|
| | | import com.bsk.zhangbo.demoforbsk.R;
|
| | |
|
| | | import cn.com.basic.face.adapter.SurveillanceFragment;
|
| | |
| | | import cn.com.basic.face.base.PictureTaker;
|
| | | import cn.com.basic.face.dialog.SurveillancePhotoDialog;
|
| | | import cn.com.basic.face.discern.common.CommonVariables;
|
| | | import cn.com.basic.face.discern.common.ResultBean;
|
| | | import cn.com.basic.face.discern.entity.Register;
|
| | | import cn.com.basic.face.discern.query.item.CheckInQueryItem;
|
| | | import cn.com.basic.face.discern.query.item.SurveillanceQueryItem;
|
| | |
| | | import cn.com.basic.face.util.AppApi;
|
| | | import cn.com.basic.face.dialog.DateSelectDialog;
|
| | | import cn.com.basic.face.dialog.CountryDialog;
|
| | | import cn.com.basic.face.util.PostData;
|
| | | import cn.com.basic.face.util.Uploader;
|
| | | import cn.com.basic.face.widget.register.RegisterRightFieldLabelView;
|
| | | import cn.com.basic.face.widget.register.RegisterRightFieldTextView;
|
| | | import cn.com.basic.face.dialog.SelectDialog;
|
| | |
|
| | | 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.http.RequestParams;
|
| | |
|
| | | import java.io.BufferedOutputStream;
|
| | | import java.io.ByteArrayInputStream;
|
| | | import java.io.ByteArrayOutputStream;
|
| | | import java.io.File;
|
| | | import java.io.FileOutputStream;
|
| | | import java.io.Reader;
|
| | | import java.text.SimpleDateFormat;
|
| | | import java.util.ArrayList;
|
| | | import java.util.Date;
|
| | |
| | | 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();
|
| | | DisplayMetrics metrics = getActivity().getResources().getDisplayMetrics();
|
| | |
|
| | | int h1 = fragment_register_surveillance_photo.getHeight();
|
| | | int h2 = fragment_register_upload_custom_photo.getHeight();
|
| | | int h3 = fragment_register_id_card_photo.getHeight();
|
| | |
|
| | | DisplayMetrics displayMetrics = BaseApplication.getInstance().getResources().getDisplayMetrics();
|
| | | float dpHeight = displayMetrics.heightPixels / displayMetrics.density;
|
| | | float dpWidth = displayMetrics.widthPixels / displayMetrics.density;
|
| | |
|
| | | String name = fragment_register_name.getValue();
|
| | | if (name.trim().length() <= 0) {
|
| | |
| | | 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.companyId, company);
|
| | | params.addBodyParameter(Register.FieldNames.birthday, birthday);
|
| | |
|
| | |
|
| | | if (surveillanceQueryItem_selectPhoto != null) {
|
| | | params.addBodyParameter("width", surveillanceQueryItem_selectPhoto.getWidth());
|
| | |
| | | fragment_register_surveillance_photo_img = surveillanceQueryItem_selectPhoto.getBitmap();
|
| | |
|
| | | NativeImg nativeImg = surveillanceQueryItem_selectPhoto.getNativeImg();
|
| | | String str = Base64.encodeToString(nativeImg.image, 0, nativeImg.size, Base64.DEFAULT);
|
| | | byte[] imageBytes = new byte[nativeImg.size];
|
| | | for (int i = 0; i < nativeImg.size; i++) {
|
| | | imageBytes[i] = nativeImg.image[i];
|
| | | }
|
| | | pd.addData("rawSurveillancePhoto", "application/octet-stream", imageBytes);
|
| | |
|
| | | params.addBodyParameter("base64Image", str);
|
| | | }
|
| | |
|
| | | if (surveillanceQueryItem_uploadPhoto != null) {
|
| | | // params.addBodyParameter("width", surveillanceQueryItem_uploadPhoto.getWidth());
|
| | | // params.addBodyParameter("height", surveillanceQueryItem_uploadPhoto.getHeight());
|
| | | // fragment_register_surveillance_photo_img = surveillanceQueryItem_uploadPhoto.getBitmap();
|
| | | //
|
| | | // NativeImg nativeImg = surveillanceQueryItem_uploadPhoto.getNativeImg();
|
| | | // String str = Base64.encodeToString(nativeImg.image, 0, nativeImg.size, Base64.DEFAULT);
|
| | | //
|
| | | // params.addBodyParameter("base64Image", str);
|
| | | params.addBodyParameter("rawSurveillancePhoto", writeToFile("rawSurveillancePhoto", imageBytes));
|
| | | } else {
|
| | | params.addBodyParameter("rawSurveillancePhoto", 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();
|
| | | String encodedImage = Base64.encodeToString(imageBytes, Base64.DEFAULT);
|
| | | params.addBodyParameter(Register.FieldNames.surveillancePhoto, encodedImage);
|
| | | pd.addData(Register.FieldNames.surveillancePhoto, "application/octet-stream", imageBytes);
|
| | |
|
| | | params.addBodyParameter("surveillancePhoto", writeToFile("surveillancePhoto", imageBytes));
|
| | | } else {
|
| | | params.addBodyParameter("surveillancePhoto", 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();
|
| | | String encodedImage = Base64.encodeToString(imageBytes, Base64.DEFAULT);
|
| | | params.addBodyParameter(Register.FieldNames.uploadCustomPhoto, encodedImage);
|
| | | pd.addData(Register.FieldNames.uploadCustomPhoto, "application/octet-stream", imageBytes);
|
| | |
|
| | | params.addBodyParameter("uploadCustomPhoto", writeToFile("uploadCustomPhoto", imageBytes));
|
| | | } else {
|
| | | params.addBodyParameter("uploadCustomPhoto", 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();
|
| | | String encodedImage = Base64.encodeToString(imageBytes, Base64.DEFAULT);
|
| | | params.addBodyParameter(Register.FieldNames.idCardPhoto, encodedImage);
|
| | | pd.addData(Register.FieldNames.idCardPhoto, "application/octet-stream", imageBytes);
|
| | |
|
| | | params.addBodyParameter("idCardPhoto", writeToFile("idCardPhoto", imageBytes));
|
| | | } 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);
|
| | | }
|
| | |
| | | try {
|
| | | Bitmap bitmap = MediaStore.Images.Media.getBitmap(getActivity().getContentResolver(), uri);
|
| | | fragment_register_upload_custom_photo.setImageBitmap(bitmap);
|
| | | //fragment_register_upload_custom_photo_img = bitmap;
|
| | |
|
| | | fragment_register_upload_custom_photo_placeholder_image.setVisibility(View.INVISIBLE);
|
| | | fragment_register_upload_custom_photo_placeholder_text_view.setVisibility(View.INVISIBLE);
|
| | |
|
| | | List<SurveillanceQueryItem> bitmapList = new ArrayList<>();
|
| | | SurveillanceQueryItem item = new SurveillanceQueryItem();
|
| | | // item.setBitmap(bitmap);
|
| | | item.setWidth(bitmap.getWidth()+"");
|
| | | item.setHeight(bitmap.getHeight()+"");
|
| | | item.setLocalUri(uri);
|
| | |
|
| | | // ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
| | | // bitmap.compress(Bitmap.CompressFormat.JPEG, 100, byteArrayOutputStream);
|
| | | // byte[] imageBytes = byteArrayOutputStream.toByteArray();
|
| | | // String encodedImage = Base64.encodeToString(imageBytes, Base64.DEFAULT);
|
| | | // item.setBase64Image(encodedImage);
|
| | | setSurveillanceQueryItem_selectPhoto(item);
|
| | | bitmapList.add(item);
|
| | | bitmapList.add(item);
|
| | |
| | |
|
| | | @OnClick(R.id.fragment_register_id_card_photo)
|
| | | public void fragment_register_id_card_photo_click(View view) {
|
| | | // Intent takePicture = new Intent(MainActivity.getInstance(), PictureTaker.class);
|
| | | // startActivityForResult(takePicture, fragment_register_id_card_photo_);
|
| | | // Intent takePicture = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
|
| | | // startActivityForResult(takePicture, fragment_register_id_card_photo_);
|
| | |
|
| | | Intent intent = new Intent();
|
| | | intent.setAction(MediaStore.ACTION_IMAGE_CAPTURE);
|
| | | idCardImageCaptureFile = new File(Environment.getExternalStorageDirectory(), System.currentTimeMillis()+".jpg");
|
| | |
| | | resetForm();
|
| | | }
|
| | |
|
| | | public void readIdCard() {
|
| | | try {
|
| | | Thread.sleep(100);
|
| | |
|
| | | RFIDReader idCardReader = RFIDReader.getInstance(BaseApplication.getInstance(), "uart");
|
| | | idCardReader.setUartDeviceName("/dev/ttyS1");
|
| | | 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) {
|
| | | 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();
|
| | | }
|
| | | } catch (Exception e) {
|
| | | e.printStackTrace();
|
| | | }
|
| | | }
|
| | |
|
| | | 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.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);
|
| | | }
|
| | |
|
| | | 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);
|
| | | }
|
| | | }
|
| | |
|
| | |
|
| | |
|
| | | }
|