xuxiuxi
2017-05-11 48f6bbfd957f1aba067d6ccf8e4bb00f811d35c8
VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/service/SurveillanceMng.java
@@ -6,6 +6,7 @@
import org.xutils.x;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -32,6 +33,39 @@
        }
    }
    public static class SurveillanceListThread extends Thread {
        @Override
        public void run() {
            try {
                List prevList = SurveillanceMng.getInstance().removeTimeoutItem(null);
                SurveillanceMng.getInstance().registerTopAndCheckInBottom(prevList);
                SurveillanceFragment.getInstance().get_fragment_supervisory_bottom_visitor_list_view().show(prevList);
                Thread.sleep(1000*60*10);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
    private List<SurveillanceQueryItem> removeTimeoutItem(List<SurveillanceQueryItem> prevList) {
        if (prevList == null) {
            prevList = SurveillanceFragment.getInstance().get_fragment_supervisory_bottom_visitor_list_view().getPrevList();
        }
        List<SurveillanceQueryItem> newPrevList = new ArrayList();
        for (SurveillanceQueryItem item : prevList) {
            if (item.getRegisterOrCheckIn() == CommonVariables.Surveillance.VISIT_REGISTER_ITEM_TYPE) {
                Date now = new Date();
                Date createTime = item.getCreateTime();
                long minutes = (now.getTime() - createTime.getTime()) / 1000 / 60;
                if (minutes*1.0 / 10 >= 1) {
                    continue;
                }
                newPrevList.add(item);
            }
        }
        return newPrevList;
    }
    public void addBitmap(final List<SurveillanceQueryItem> bitmapList, byte[] byteArray, int len, String cameraInOrOut) {
        if (!BaseApplication.deviceAvailable) {
            return;
@@ -44,9 +78,12 @@
        x.http().post(params, new BaseCommonCallBack() {
            public void success() {
                List<SurveillanceQueryItem> items = getList(SurveillanceQueryItem.class);
                List prevList = SurveillanceFragment.getInstance().get_fragment_supervisory_bottom_visit_list_view().getPrevList();
                List prevVisitorList = SurveillanceFragment.getInstance().get_fragment_supervisory_bottom_visitor_list_view().getPrevList();
                List prevAttendanceList = SurveillanceFragment.getInstance().get_fragment_supervisory_bottom_attendance_list_view().getPrevList();
                List newList = new ArrayList();
                List newVisitorList = new ArrayList();
                List newAttendanceList = new ArrayList();
                for (int i = 0; items != null && i < items.size(); i++) {
                    SurveillanceQueryItem item = items.get(i);
@@ -54,25 +91,82 @@
                    if (type == CommonVariables.Surveillance.VISIT_REGISTER_ITEM_TYPE
                            || type == CommonVariables.Surveillance.VISIT_CHECK_IN_ITEM_TYPE
                            ) {
                        newList.add(0, item);
                        newVisitorList.add(0, item);
                        if (i < bitmapList.size()) {
                            SurveillanceQueryItem surveillanceQueryItem = bitmapList.get(i);
                            item.setBitmap(surveillanceQueryItem.getBitmap());
                            item.setBase64Image(surveillanceQueryItem.getBase64Image());
                            item.setNativeImg(surveillanceQueryItem.getNativeImg());
                            item.setWidth(surveillanceQueryItem.getWidth());
                            item.setHeight(surveillanceQueryItem.getHeight());
                        }
                    }
                    if (type ==  CommonVariables.Surveillance.VISIT_ATTENDANCE_ITEM_TYPE) {
                        newAttendanceList.add(item);
                        if (i < bitmapList.size()) {
                            SurveillanceQueryItem surveillanceQueryItem = bitmapList.get(i);
                            item.setBitmap(surveillanceQueryItem.getBitmap());
                            item.setBase64Image(surveillanceQueryItem.getBase64Image());
                            item.setNativeImg(surveillanceQueryItem.getNativeImg());
                            item.setWidth(surveillanceQueryItem.getWidth());
                            item.setHeight(surveillanceQueryItem.getHeight());
                        }
                    }
                }
                if (newList.size() > 0) {
                    prevList.addAll(0, newList);
                    registerTopAndCheckInBottom(prevList);
                    SurveillanceFragment.getInstance().get_fragment_supervisory_bottom_visit_list_view().show(prevList);
                if (newVisitorList.size() > 0) {
                    prevVisitorList.addAll(0, newVisitorList);
                    registerTopAndCheckInBottom(prevVisitorList);
                    SurveillanceFragment.getInstance().get_fragment_supervisory_bottom_visitor_list_view().show(prevVisitorList);
                }
                if (newAttendanceList.size() > 0) {
                    prevAttendanceList.addAll(0, newAttendanceList);
                    if (prevAttendanceList.size() > 20) {
                        prevAttendanceList = prevAttendanceList.subList(0, 20);
                    }
                    SurveillanceFragment.getInstance().get_fragment_supervisory_bottom_attendance_list_view().show(prevAttendanceList);
                }
            }
        });
    }
    public List getSurveillancePhotoList() {
        List<SurveillanceQueryItem> prevVisitorList = SurveillanceFragment.getInstance().get_fragment_supervisory_bottom_visitor_list_view().getPrevList();
        List<SurveillanceQueryItem> registerList = new ArrayList();
        int n = 9;
        for (SurveillanceQueryItem surveillanceQueryItem : prevVisitorList) {
            if (surveillanceQueryItem.getRegisterOrCheckIn() == CommonVariables.Surveillance.VISIT_REGISTER_ITEM_TYPE) {
                if (registerList.size() > n*2) {
                    break;
                }
                surveillanceQueryItem.setSurveillancePhotoSelected(false);
                registerList.add(surveillanceQueryItem);
            }
        }
        SurveillanceQueryItem item;
        List items = new ArrayList();
        int m = 0;
        for (int i = 0; i < n*2; i++) {
            if (i % 2 == 0) {
                if (m < registerList.size()) {
                    item = registerList.get(m);
                    m++;
                } else {
                    item = getBlankItem();
                }
            } else {
                if (n < registerList.size()) {
                    item = registerList.get(n);
                    n++;
                } else {
                    item = getBlankItem();
                }
            }
            items.add(item);
        }
        return items;
    }
    private void registerTopAndCheckInBottom(List<SurveillanceQueryItem> list) {
@@ -80,8 +174,8 @@
        List<SurveillanceQueryItem> checkInList = new ArrayList<SurveillanceQueryItem>();
        removeDuplicateCheckIn(list);
        int i1 = 0, j = 0;
        int maxRegister = 20;
        int maxCheckIn = 20;
        int maxRegister = 50;
        int maxCheckIn = 50;
        for (SurveillanceQueryItem item : list) {
            if (item.getRegisterOrCheckIn() == Constant.Surveillance.VISIT_REGISTER_ITEM_TYPE) {
                if (i1 < maxRegister) {