xuxiuxi
2017-06-28 f6fcbe3c965b4ad906ac8b327bb5b301c0ebd348
VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/fragment/RegisterFragment.java
@@ -53,10 +53,13 @@
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.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
@@ -138,9 +141,32 @@
        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) {
//        RegisterMng.getInstance().add(null);
//        if (1==1) {
//            return;
//        }
        if (!BaseApplication.deviceAvailable) {
            return;
@@ -226,6 +252,17 @@
        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());
            params.addBodyParameter("height", surveillanceQueryItem_selectPhoto.getHeight());
@@ -237,6 +274,10 @@
                imageBytes[i] = nativeImg.image[i];
            }
            pd.addData("rawSurveillancePhoto", "application/octet-stream", imageBytes);
            params.addBodyParameter("rawSurveillancePhoto", writeToFile("rawSurveillancePhoto", imageBytes));
        } else {
            params.addBodyParameter("rawSurveillancePhoto", writeToFile("rawSurveillancePhoto", new byte[]{}));
        }
        if (fragment_register_surveillance_photo_img != null) {
@@ -244,6 +285,10 @@
            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));
        } else {
            params.addBodyParameter("surveillancePhoto", writeToFile("surveillancePhoto", new byte[]{}));
        }
        if (fragment_register_upload_custom_photo_img != null) {
@@ -251,6 +296,10 @@
            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));
        } else {
            params.addBodyParameter("uploadCustomPhoto", writeToFile("uploadCustomPhoto", new byte[]{}));
        }
        if (fragment_register_id_card_photo_img != null) {
@@ -258,6 +307,10 @@
            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));
        } else {
            params.addBodyParameter("idCardPhoto", writeToFile("idCardPhoto", new byte[]{}));
        }
@@ -266,8 +319,8 @@
            @Override
            protected String doInBackground(String... urls) {
                try {
                    Uploader uploader = new Uploader("", AppApi.BASE_URL + AppApi.REGISTER_ADD);
                    json = uploader.upload("", pd);
//                    Uploader uploader = new Uploader("", AppApi.BASE_URL + AppApi.REGISTER_ADD);
//                    json = uploader.upload("", pd);
                    return json;
                } catch (Exception e) {
                    e.printStackTrace();
@@ -286,9 +339,11 @@
            }
        }
        ConnectionTask task = new ConnectionTask();
        String[] params1 = new String[2];
        task.execute(params1);
//        ConnectionTask task = new ConnectionTask();
//        String[] params1 = new String[2];
//        task.execute(params1);
        RegisterMng.getInstance().add(params);
    }
    public void set_fragment_register_surveillance_photo(SurveillanceQueryItem item) {