package com.basic.security.fragment;
|
|
import android.content.ContextWrapper;
|
import android.graphics.Bitmap;
|
import android.graphics.BitmapFactory;
|
import android.graphics.Color;
|
import android.os.Bundle;
|
import android.text.TextUtils;
|
import android.view.LayoutInflater;
|
import android.view.View;
|
import android.view.ViewGroup;
|
import android.widget.AdapterView;
|
import android.widget.ArrayAdapter;
|
import android.widget.BaseAdapter;
|
import android.widget.Button;
|
import android.widget.CheckBox;
|
import android.widget.EditText;
|
import android.widget.GridView;
|
import android.widget.ImageView;
|
import android.widget.ListView;
|
import android.widget.RadioButton;
|
import android.widget.RelativeLayout;
|
import android.widget.Spinner;
|
import android.widget.TextView;
|
|
import com.basic.security.base.BaseApplication;
|
import com.basic.security.base.BaseFragment;
|
import com.basic.security.manager.DeviceManager;
|
import com.basic.security.manager.FeatureManager;
|
import com.basic.security.manager.GuestManager;
|
import com.basic.security.manager.IdentityManager;
|
import com.basic.security.manager.OrgManager;
|
import com.basic.security.manager.PersonIdentityManager;
|
import com.basic.security.manager.PersonManager;
|
import com.basic.security.manager.VisitManager;
|
import com.basic.security.model.FaceMessage;
|
import com.basic.security.model.Guest;
|
import com.basic.security.model.Identity;
|
import com.basic.security.model.ModelAdapter;
|
import com.basic.security.model.Org;
|
import com.basic.security.model.Person;
|
import com.basic.security.utils.BasicIdUtil;
|
import com.basic.security.utils.CheckIdCard;
|
import com.basic.security.utils.Constants;
|
import com.basic.security.utils.DateEditUtil1;
|
import com.basic.security.utils.DateEditUtilForValidTime;
|
import com.basic.security.utils.DateUtil;
|
import com.basic.security.utils.DetectedResult;
|
import com.basic.security.utils.FaceId;
|
import com.basic.security.utils.LayoutUtil;
|
import com.basic.security.utils.MyHashMap;
|
import com.basic.security.utils.PhoneNumberCheckUtils;
|
import com.basic.security.utils.ResolutionAdaptation;
|
import com.basic.security.utils.SocketUtil;
|
import com.basic.security.utils.ToastUtil;
|
import com.basic.security.widget.ConfirmDialog;
|
import com.basic.security.widget.abslistview.CommonAdapter;
|
import com.basic.security.widget.abslistview.ViewHolder;
|
import com.basic.security.widget.hlistview.HListView;
|
|
import org.androidannotations.annotations.AfterViews;
|
import org.androidannotations.annotations.Click;
|
import org.androidannotations.annotations.EFragment;
|
import org.androidannotations.annotations.UiThread;
|
import org.androidannotations.annotations.ViewById;
|
import org.apache.commons.imaging.ImageFormat;
|
import org.apache.commons.imaging.ImageFormats;
|
import org.apache.commons.imaging.Imaging;
|
|
import java.io.ByteArrayOutputStream;
|
import java.text.SimpleDateFormat;
|
import java.util.ArrayList;
|
import java.util.Arrays;
|
import java.util.Date;
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
import java.util.Set;
|
import java.util.concurrent.locks.Lock;
|
import java.util.concurrent.locks.ReentrantLock;
|
|
@EFragment
|
public class GuestModeFragment extends BaseFragment {
|
public static TreeAdapter respondentOrgTreeAdapter = new TreeAdapter(true, true);
|
public static long lastDeleteTime = System.currentTimeMillis();
|
public final Lock guestListLock = new ReentrantLock();
|
@ViewById
|
public ImageView camera1, guest_picture;
|
//摄像头
|
@ViewById
|
public TextView guest_sign_up_time, guest_visit_time, respondent_name, respondent_identity, respondent_department, respondent_phone,
|
selected_org;
|
// 访客注册
|
@ViewById
|
public HListView guest_identity;
|
@ViewById
|
public RadioButton guest_all_device, guest_this_device;
|
@ViewById
|
public Button guest_save, guest_delete;
|
@ViewById
|
public EditText guest_name, guest_id_card, guest_phone, guest_reason, guest_remark;
|
@ViewById
|
public TextView guest_respondent;
|
@ViewById
|
public TextView guest_sign_up_method;
|
@ViewById
|
public Spinner guest_sign_up_rule;
|
@ViewById
|
public TextView guest_exit_time;
|
@ViewById
|
public Spinner guest_visit_status;
|
@ViewById
|
public TextView guest_visit_valid_time;
|
@ViewById
|
public TextView guest_id_card_text, guest_name_text;
|
public String[] signUpRuleArray = {"允许通行", "有效时间内通行", "确认通行", "拒绝通行"};
|
public String register_rule = signUpRuleArray[0];
|
public String[] guestVisitStatusArray = {"访问中", "已离开"};
|
public byte[] guestFaceJpgArray;
|
public Bitmap guestFaceBitmap;
|
public byte[] guestFaceFeature;
|
public String guestTimeRuleId = "";
|
// 被访人
|
@ViewById
|
public ImageView respondent_picture;
|
@ViewById
|
public GridView respondent_list, guest_list_one, guest_list_two;
|
@ViewById
|
public ListView respondent_org;
|
public CommonAdapter respondentAdapter, guest_list_two_adapter;
|
public CommonAdapter guest_list_one_adapter;
|
public ModelAdapter respondent;
|
@ViewById
|
public RelativeLayout rl_show_organization;
|
@ViewById
|
public View guest_respondent_row, guest_reason_row, guest_remark_row,
|
guest_visit_time_row, guest_visit_status_row, guest_visit_valid_time_row, guest_exit_time_row;
|
public List<ModelAdapter> guest_list_one_data = new ArrayList<>();
|
public List<ModelAdapter> guest_list_two_data = new ArrayList<>();
|
public List<ModelAdapter> allIdentityList = new ArrayList<>();
|
public Map<String, ModelAdapter> checkedIdentityMapByPerson = new MyHashMap<>();
|
public CommonAdapter identityAdapter;
|
public ModelAdapter checkedGuest = null;
|
public List<ModelAdapter> camera1GuestList = new ArrayList<>();
|
public List<ModelAdapter> camera2GuestList = new ArrayList<>();
|
public String camera1Ip, camera2Ip;
|
public Map<String, ModelAdapter> guestCheckedIdentityMap = new HashMap<>();
|
public int flag = -1;
|
public int oneCamera = 1;
|
public int twoCamera = 2;
|
public Camera1FaceListAdapter camera1FaceListAdapter;
|
public ModelAdapter selectedRespondentOrg;
|
public ModelAdapter checkedPerson;
|
public boolean guest_sign_up_rule_from_init = true;
|
public Lock allIdentityListLock = new ReentrantLock();
|
public List<View> face_one_checkedList = new ArrayList<>();
|
public List<View> face_two_checkedList = new ArrayList<>();
|
public List<View> respondent_face_checkedList = new ArrayList<>();
|
public int faceOneCheckedPosition = -1;
|
public int faceTwoCheckedPosition = -1;
|
public int respondentCheckedPosition = -1;
|
public String faceOneCheckedId = "";
|
public String faceTwoCheckedId = "";
|
public String respondent_face_CheckedId = "";
|
public boolean loadData = false;
|
List<ModelAdapter> respondentList = new ArrayList<>();
|
ByteArrayOutputStream jpgBaos = new ByteArrayOutputStream();
|
Object fragment_guest_mode_border_set_lock = new Object();
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd HH:mm");
|
private long exitTime;
|
private long validTime;
|
|
@Click
|
public void guest_delete() {
|
if (checkedGuest != null) {
|
ConfirmDialog confirmDialog = new ConfirmDialog(mainActivity(), "确认是否删除", "确认删除", "取消");
|
confirmDialog.show();
|
confirmDialog.setClickListener(new ConfirmDialog.ClickListenerInterface() {
|
public void doConfirm() {
|
BaseApplication.getApplication().executorService.execute(() -> {
|
if (checkedGuest != null) {
|
try {
|
GuestModeFragment.lastDeleteTime = System.currentTimeMillis();
|
String cameraId = checkedGuest.getString(Guest.camera_id);
|
String personId = checkedGuest.getString(Guest.person_id);
|
try {
|
guestListLock.lock();
|
GuestManager.deleteGuest(checkedGuest);
|
if ("1".equals(cameraId)) {
|
((GuestModeFragment.this)).reloadCameraOneList();
|
}
|
if ("2".equals(cameraId)) {
|
((GuestModeFragment.this)).reloadCameraTwoList();
|
}
|
} catch (Exception e) {
|
e.printStackTrace();
|
} finally {
|
guestListLock.unlock();
|
}
|
if (!TextUtils.isEmpty(personId)) {
|
FeatureManager.removeFeature(personId);
|
ModelAdapter dbPerson = PersonManager.findPersonById(personId);
|
if (dbPerson != null) {
|
PersonManager.deletePerson(dbPerson);
|
}
|
SocketUtil.rpcCallDeletePerson(dbPerson);
|
if (Constants.isIndoor) {
|
GuestManager.removePersonId(personId);
|
}
|
}
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
GuestModeFragment.lastDeleteTime = System.currentTimeMillis();
|
}
|
checkedGuest = null;
|
((GuestModeFragment.this)).initGuest(null);
|
});
|
confirmDialog.dismiss();
|
ToastUtil.show("删除成功");
|
}
|
|
public void doCancel() {
|
confirmDialog.dismiss();
|
}
|
});
|
}
|
}
|
|
public void initGuestGridView1() {
|
guest_list_one_adapter = new CommonAdapter<ModelAdapter>(mainActivity(), com.basic.security.utils.ResolutionAdaptation.face_view_image3(), guest_list_one_data) {
|
protected void convert(ViewHolder viewHolder, ModelAdapter item, int position) {
|
View face_checked = viewHolder.getView(com.basic.security.utils.RUtils.R_id_face_checked);
|
face_one_checkedList.add(face_checked);
|
ImageView imageView = viewHolder.getView(com.basic.security.utils.RUtils.R_id_face);
|
ImageView idcard = viewHolder.getView(com.basic.security.utils.RUtils.R_id_idcard);
|
TextView name = viewHolder.getView(com.basic.security.utils.RUtils.R_id_name);
|
ModelAdapter guest = guest_list_one_data.get(position);
|
if (faceOneCheckedId.equals(guest.getId())) {
|
face_checked.setVisibility(View.VISIBLE);
|
}
|
if (Constants.TRUE.equals(guest.getString(Guest.verified_id_card))) {
|
idcard.setVisibility(View.VISIBLE);
|
} else {
|
idcard.setVisibility(View.GONE);
|
}
|
String nameStr = guest.getString(Guest.name);
|
if (!TextUtils.isEmpty(nameStr)) {
|
name.setText(nameStr);
|
} else {
|
name.setText("");
|
}
|
byte[] blob = guest.getBlob("camera_image_path");
|
Bitmap bitmap = null;
|
if (blob != null) {
|
try {
|
if (blob.length != 0) {
|
bitmap = BitmapFactory.decodeByteArray(blob, 0, blob.length);
|
}
|
} catch (Exception e) {
|
e.printStackTrace();
|
bitmap = BitmapFactory.decodeResource(mainActivity().getResources(), com.basic.security.utils.RUtils.R_drawable_u1280);
|
}
|
} else {
|
bitmap = BitmapFactory.decodeResource(mainActivity().getResources(), com.basic.security.utils.RUtils.R_drawable_u1280);
|
}
|
imageView.setImageBitmap(bitmap);
|
}
|
};
|
guest_list_one.setAdapter(guest_list_one_adapter);
|
guest_list_one.setOnItemClickListener((parent, view, position, id) -> {
|
faceOneCheckedPosition = position;
|
faceOneCheckedId = guest_list_one_data.get(position).getId();
|
for (View face_checked : respondent_face_checkedList) {
|
face_checked.setVisibility(View.GONE);
|
}
|
for (View face_checked : face_two_checkedList) {
|
face_checked.setVisibility(View.GONE);
|
}
|
for (View face_checked : face_one_checkedList) {
|
face_checked.setVisibility(View.GONE);
|
}
|
if (position == faceOneCheckedPosition) {
|
view.findViewById(com.basic.security.utils.RUtils.R_id_face_checked).setVisibility(View.VISIBLE);
|
}
|
initGuest(guest_list_one_data.get(position));
|
});
|
}
|
|
public void initGuestGridView2() {
|
guest_list_two_adapter = new CommonAdapter<ModelAdapter>(mainActivity(), com.basic.security.utils.ResolutionAdaptation.face_view_image3(), guest_list_two_data) {
|
protected void convert(ViewHolder viewHolder, ModelAdapter item, int position) {
|
View face_checked = viewHolder.getView(com.basic.security.utils.RUtils.R_id_face_checked);
|
face_two_checkedList.add(face_checked);
|
ImageView imageView = viewHolder.getView(com.basic.security.utils.RUtils.R_id_face);
|
ImageView idcard = viewHolder.getView(com.basic.security.utils.RUtils.R_id_idcard);
|
TextView name = viewHolder.getView(com.basic.security.utils.RUtils.R_id_name);
|
ModelAdapter guest = guest_list_two_data.get(position);
|
if (faceTwoCheckedId.equals(guest.getId())) {
|
face_checked.setVisibility(View.VISIBLE);
|
}
|
if (Constants.TRUE.equals(guest.getString(Guest.verified_id_card))) {
|
idcard.setVisibility(View.VISIBLE);
|
} else {
|
idcard.setVisibility(View.GONE);
|
}
|
String nameStr = guest.getString(Guest.name);
|
if (!TextUtils.isEmpty(nameStr)) {
|
name.setText(nameStr);
|
} else {
|
name.setText("");
|
}
|
byte[] blob = guest.getBlob("camera_image_path");
|
Bitmap bitmap = null;
|
if (blob != null) {
|
try {
|
if (blob.length != 0) {
|
bitmap = BitmapFactory.decodeByteArray(blob, 0, blob.length);
|
}
|
} catch (Exception e) {
|
e.printStackTrace();
|
bitmap = BitmapFactory.decodeResource(mainActivity().getResources(), com.basic.security.utils.RUtils.R_drawable_u1280);
|
}
|
} else {
|
bitmap = BitmapFactory.decodeResource(mainActivity().getResources(), com.basic.security.utils.RUtils.R_drawable_u1280);
|
}
|
imageView.setImageBitmap(bitmap);
|
}
|
};
|
guest_list_two.setAdapter(guest_list_two_adapter);
|
guest_list_two.setOnItemClickListener((parent, view, position, id) -> {
|
faceTwoCheckedPosition = position;
|
faceTwoCheckedId = guest_list_two_data.get(position).getId();
|
for (View face_checked : face_one_checkedList) {
|
face_checked.setVisibility(View.GONE);
|
}
|
for (View face_checked : respondent_face_checkedList) {
|
face_checked.setVisibility(View.GONE);
|
}
|
for (View face_checked : face_two_checkedList) {
|
face_checked.setVisibility(View.GONE);
|
}
|
if (position == faceTwoCheckedPosition) {
|
view.findViewById(com.basic.security.utils.RUtils.R_id_face_checked).setVisibility(View.VISIBLE);
|
}
|
initGuest(guest_list_two_data.get(position));
|
});
|
}
|
|
public void initGuest(ModelAdapter newCheckedGuest) {
|
BaseApplication.getApplication().executorService.execute(() -> {
|
ModelAdapter person = null;
|
String personId = null;
|
if (newCheckedGuest != null) {
|
personId = newCheckedGuest.getString(Guest.person_id);
|
if (!TextUtils.isEmpty(personId)) {
|
person = PersonManager.findPersonById(personId);
|
if (person == null) {
|
if (!Constants.indoorOutdoorInOne) {
|
person = SocketUtil.rpcCallFindPersonById(personId);
|
}
|
}
|
}
|
}
|
checkedPerson = person;
|
initGuestUI(newCheckedGuest, person);
|
});
|
}
|
|
@UiThread
|
public void initGuestUI(ModelAdapter newCheckedGuest, ModelAdapter person) {
|
if (newCheckedGuest == null) {
|
faceOneCheckedPosition = -1;
|
faceOneCheckedId = "";
|
for (View face_checked : face_one_checkedList) {
|
face_checked.setVisibility(View.GONE);
|
}
|
}
|
guest_sign_up_rule_from_init = true;
|
respondent = null;
|
guest_picture.setImageBitmap(BitmapFactory.decodeResource(mainActivity().getResources(), com.basic.security.utils.RUtils.R_drawable_nobody));
|
guest_name.setText("");
|
guest_id_card.setText("");
|
guest_phone.setText("");
|
guest_sign_up_method.setText("访客注册");
|
guest_sign_up_time.setText(DateUtil.formatTime(System.currentTimeMillis(), "yyyy-MM-dd HH:mm:ss"));
|
guest_reason.setText("");
|
guest_visit_valid_time.setText("");
|
guest_exit_time.setText("");
|
guest_remark.setText("");
|
guest_visit_time.setText("暂无");
|
guest_name.setVisibility(View.VISIBLE);
|
guest_name_text.setVisibility(View.GONE);
|
guest_id_card.setVisibility(View.VISIBLE);
|
guest_id_card_text.setVisibility(View.GONE);
|
try {
|
if (newCheckedGuest != null && Constants.TRUE.equals(newCheckedGuest.getString(Guest.verified_id_card)) && person != null) {
|
String name = newCheckedGuest.getString(Guest.name);
|
if (!TextUtils.isEmpty(name)) {
|
person.setString(Person.name, name);
|
guest_name.setVisibility(View.GONE);
|
guest_name_text.setVisibility(View.VISIBLE);
|
guest_name_text.setText(name);
|
}
|
String idCardNumber = newCheckedGuest.getString(Guest.id_card_number);
|
if (!TextUtils.isEmpty(idCardNumber)) {
|
person.setString(Person.id_card_number, idCardNumber);
|
guest_id_card.setVisibility(View.GONE);
|
guest_id_card_text.setVisibility(View.VISIBLE);
|
guest_id_card_text.setText(idCardNumber);
|
}
|
}
|
if (newCheckedGuest != null && Constants.TRUE.equals(newCheckedGuest.getString(Guest.verified_id_card))) {
|
String name = newCheckedGuest.getString(Guest.name);
|
String idCardNumber = newCheckedGuest.getString(Guest.id_card_number);
|
if (!TextUtils.isEmpty(name)) {
|
guest_name.setText(name);
|
guest_name_text.setText(name);
|
}
|
if (!TextUtils.isEmpty(idCardNumber)) {
|
guest_id_card.setText(idCardNumber);
|
guest_id_card_text.setText(idCardNumber);
|
}
|
guest_name.setVisibility(View.GONE);
|
guest_name_text.setVisibility(View.VISIBLE);
|
guest_id_card.setVisibility(View.GONE);
|
guest_id_card_text.setVisibility(View.VISIBLE);
|
if (person != null) {
|
person.setString(Person.verify_status, "已经验证身份证");
|
}
|
}
|
if (person == null) {
|
guest_sign_up_time.setText(DateEditUtil1.sdf.format(new Date()));
|
}
|
if (person != null) {
|
respondent = PersonManager.findPersonById(person.getString(Person.respondent_ids));
|
}
|
if (respondent != null) {
|
String orgId = respondent.getString(Person.org_id);
|
((GuestModeFragment) this).initRespondent(respondent);
|
guest_respondent.setText(respondent.getString(Person.name));
|
guest_respondent.setTextColor(Color.parseColor("#FFFFFF"));
|
} else {
|
guest_respondent.setText("请在右侧选择被访人");
|
((GuestModeFragment) this).initRespondent(null);
|
guest_respondent.setTextColor(Color.parseColor("#4BA6AD"));
|
}
|
guest_visit_valid_time.setText("");
|
guest_exit_time.setText("");
|
if (person != null) {
|
guest_visit_valid_time.setText(DateEditUtil1.longToDate(person.getString(Person.guest_visit_valid_time)));
|
guest_exit_time.setText(DateEditUtil1.longToDate(person.getString(Person.guest_exit_time)));
|
}
|
checkedGuest = newCheckedGuest;
|
guest_respondent_row.setVisibility(View.VISIBLE);
|
guest_reason_row.setVisibility(View.VISIBLE);
|
guest_visit_time_row.setVisibility(View.VISIBLE);
|
guest_visit_status_row.setVisibility(View.VISIBLE);
|
guest_visit_valid_time_row.setVisibility(View.VISIBLE);
|
guest_exit_time_row.setVisibility(View.VISIBLE);
|
if (person != null) {
|
if (!"访客注册".equals(person.getString(Person.sign_up_method))) {
|
guest_respondent_row.setVisibility(View.GONE);
|
guest_reason_row.setVisibility(View.GONE);
|
guest_remark_row.setVisibility(View.GONE);
|
guest_visit_time_row.setVisibility(View.GONE);
|
guest_visit_status_row.setVisibility(View.GONE);
|
guest_visit_valid_time_row.setVisibility(View.GONE);
|
guest_exit_time_row.setVisibility(View.GONE);
|
}
|
if ("访客注册".equals(person.getString(Person.sign_up_method))) {
|
try {
|
String dbGuestVisitStatus = person.getString(Person.guest_visit_status);
|
if (dbGuestVisitStatus != null) {
|
for (int i = 0; i < guestVisitStatusArray.length; i++) {
|
String guestVisitStatus = guestVisitStatusArray[i];
|
if (dbGuestVisitStatus.equals(guestVisitStatus)) {
|
guest_visit_status.setSelection(i);
|
break;
|
}
|
}
|
}
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
}
|
if (guestFaceFeature != null) {
|
byte[] newGuestFaceFeature = person.getBlob(Person.camera_image_feature);
|
if (newGuestFaceFeature != null) {
|
if (FaceId.instance.compareFeature(guestFaceFeature, newGuestFaceFeature) > 70) {
|
}
|
}
|
}
|
guestFaceJpgArray = null;
|
this.guestFaceBitmap = null;
|
guestFaceFeature = null;
|
Bitmap guestFaceBitmap = null;
|
guestFaceBitmap = null;
|
if (newCheckedGuest != null) {
|
byte[] camera_image_path = newCheckedGuest.getBlob("camera_image_path");
|
if (camera_image_path != null) {
|
try {
|
if (camera_image_path.length != 0) {
|
guestFaceBitmap = BitmapFactory.decodeByteArray(camera_image_path, 0, camera_image_path.length);
|
guestFaceJpgArray = camera_image_path;
|
this.guestFaceBitmap = guestFaceBitmap;
|
}
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
}
|
}
|
guestFaceFeature = person.getBlob(Person.camera_image_feature);
|
if (guestFaceBitmap != null) {
|
guest_picture.setImageBitmap(guestFaceBitmap);
|
}
|
checkedIdentityMapByPerson.clear();
|
// checkTemporaryGuest();
|
guest_name.setText(person.getString("name"));
|
guest_id_card.setText(person.getString("id_card_number"));
|
guest_phone.setText(person.getString("phone"));
|
String type = person.getString("sign_up_method");
|
if ("自助注册".equals(type)) {
|
if ("不需要验证身份证".equals(person.getString("verify_status"))) {
|
type = type + "-普通验证";
|
} else {
|
type = type + "-身份证验证";
|
}
|
} else if ("人工注册".equals(type)) {
|
if ("不需要验证身份证".equals(person.getString("verify_status"))) {
|
type = "人工注册-普通验证";
|
} else {
|
type = "人工注册-身份证验证";
|
}
|
} else if (TextUtils.isEmpty(type)) {
|
type = "访客注册";
|
}
|
guest_sign_up_method.setText(type);
|
if (!TextUtils.isEmpty(person.getString("sign_up_time"))) {
|
guest_sign_up_time.setText(DateUtil.formatTime(Long.parseLong(person.getString("sign_up_time")),
|
"yyyy-MM-dd HH:mm:ss"));
|
} else {
|
guest_sign_up_time.setText(DateUtil.formatTime(System.currentTimeMillis(), "yyyy-MM-dd HH:mm:ss"));
|
}
|
String signUpRule = person.getString("sign_up_rule");
|
if (!TextUtils.isEmpty(signUpRule)) {
|
for (int i = 0; i < signUpRuleArray.length; i++) {
|
String item = signUpRuleArray[i];
|
if (item.equals(signUpRule)) {
|
guest_sign_up_rule.setSelection(i);
|
break;
|
}
|
}
|
}
|
guest_reason.setText(person.getString(Person.guest_visit_reason));
|
guest_remark.setText(person.getString(Person.guest_remark));
|
String lastTime = VisitManager.getLastVisitTime(person.getId());
|
if (TextUtils.isEmpty(lastTime)) {
|
guest_visit_time.setText("暂无");
|
} else {
|
guest_visit_time.setText(DateUtil.formatTime(Long.parseLong(lastTime), "yyyy-MM-dd HH:mm:ss"));
|
}
|
initGuestIdentity(person);
|
} else {
|
boolean newPerson = true;
|
if (newCheckedGuest != null && guestFaceFeature != null) {
|
byte[] newGuestFaceFeature = newCheckedGuest.getBlob(Guest.camera_image_feature);
|
if (newGuestFaceFeature != null) {
|
if (FaceId.instance.compareFeature(guestFaceFeature, newGuestFaceFeature) > 70) {
|
}
|
}
|
}
|
if (checkedGuest == null) {
|
newPerson = false;
|
}
|
guestFaceJpgArray = null;
|
this.guestFaceBitmap = null;
|
guestFaceFeature = null;
|
Bitmap guestFaceBitmap = null;
|
checkedGuest = newCheckedGuest;
|
guestFaceBitmap = null;
|
if (newCheckedGuest != null) {
|
byte[] camera_image_path = newCheckedGuest.getBlob("camera_image_path");
|
if (camera_image_path != null) {
|
try {
|
if (camera_image_path.length != 0) {
|
guestFaceBitmap = BitmapFactory.decodeByteArray(camera_image_path, 0, camera_image_path.length);
|
guestFaceJpgArray = camera_image_path;
|
this.guestFaceBitmap = guestFaceBitmap;
|
}
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
}
|
guestFaceFeature = newCheckedGuest.getBlob(Guest.camera_image_feature);
|
if (guestFaceBitmap != null) {
|
guest_picture.setImageBitmap(guestFaceBitmap);
|
}
|
if (newPerson) {
|
checkedIdentityMapByPerson.clear();
|
checkTemporaryGuest();
|
guest_name.setText(newCheckedGuest.getString("name"));
|
guest_id_card.setText(newCheckedGuest.getString("id_card_number"));
|
guest_phone.setText(newCheckedGuest.getString("phone"));
|
String type = newCheckedGuest.getString("sign_up_method");
|
if ("自助注册".equals(type)) {
|
if ("不需要验证身份证".equals(newCheckedGuest.getString("verify_status"))) {
|
type = type + "-普通验证";
|
} else {
|
type = type + "-身份证验证";
|
}
|
} else if ("人工注册".equals(type)) {
|
if ("不需要验证身份证".equals(newCheckedGuest.getString("verify_status"))) {
|
type = "人工注册-普通验证";
|
} else {
|
type = "人工注册-身份证验证";
|
}
|
} else if (TextUtils.isEmpty(type)) {
|
type = "访客注册";
|
}
|
guest_sign_up_method.setText(type);
|
if (!TextUtils.isEmpty(newCheckedGuest.getString("sign_up_time"))) {
|
guest_sign_up_time.setText(DateUtil.formatTime(Long.parseLong(newCheckedGuest.getString("sign_up_time")),
|
"yyyy-MM-dd HH:mm:ss"));
|
} else {
|
guest_sign_up_time.setText(DateUtil.formatTime(System.currentTimeMillis(), "yyyy-MM-dd HH:mm:ss"));
|
}
|
String signUpRule = newCheckedGuest.getString("sign_up_rule");
|
if (!TextUtils.isEmpty(signUpRule)) {
|
for (int i = 0; i < signUpRuleArray.length; i++) {
|
String item = signUpRuleArray[i];
|
if (item.equals(signUpRule)) {
|
guest_sign_up_rule.setSelection(i);
|
break;
|
}
|
}
|
}
|
guest_reason.setText(newCheckedGuest.getString("visited_reason"));
|
guest_remark.setText(newCheckedGuest.getString("remark"));
|
String lastTime = VisitManager.getLastVisitTime(newCheckedGuest.getId());
|
if (TextUtils.isEmpty(lastTime)) {
|
guest_visit_time.setText("暂无");
|
} else {
|
guest_visit_time.setText(DateUtil.formatTime(Long.parseLong(lastTime), "yyyy-MM-dd HH:mm:ss"));
|
}
|
}
|
}
|
if (newCheckedGuest == null) {
|
guest_picture.setImageBitmap(BitmapFactory.decodeResource(mainActivity().getResources(), com.basic.security.utils.RUtils.R_drawable_nobody));
|
guest_name.setText("");
|
guest_id_card.setText("");
|
guest_phone.setText("");
|
guest_sign_up_method.setText("访客注册");
|
guest_sign_up_time.setText(DateUtil.formatTime(System.currentTimeMillis(), "yyyy-MM-dd HH:mm:ss"));
|
guest_reason.setText("");
|
guest_visit_valid_time.setText("");
|
guest_remark.setText("");
|
guest_visit_time.setText("暂无");
|
}
|
initGuestIdentity(newCheckedGuest);
|
}
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
}
|
|
public void initGuestIdentity(ModelAdapter guest) {
|
if (guest != null) {
|
String table = guest.getString(Constants.TABLE);
|
if ("person".equals(table)) {
|
setIdentityWithPersonInThread(guest.getString(Person.id));
|
} else {
|
setIdentityWithPersonInThread(guest.getString(Guest.person_id));
|
}
|
}
|
allIdentityListLock.lock();
|
allIdentityList.clear();
|
allIdentityList.addAll(IdentityManager.findIdentityList1());
|
allIdentityListLock.unlock();
|
identityAdapter = new CommonAdapter<ModelAdapter>(mainActivity(), com.basic.security.utils.ResolutionAdaptation.identity_checkbox_item2(), allIdentityList) {
|
protected void convert(ViewHolder viewHolder, ModelAdapter item, int position) {
|
CheckBox identityCB = viewHolder.getView(com.basic.security.utils.RUtils.R_id_identity_checkbox);
|
identityCB.setText(item.getString("name"));
|
identityCB.setChecked(checkedIdentityMapByPerson.containsKey(item.getId()));
|
identityCB.setClickable(true);
|
LayoutUtil.checkBox13(identityCB);
|
if (guest != null && "1".equals(guest.getString("auto_init"))) {
|
identityCB.setClickable(false);
|
} else {
|
identityCB.setClickable(true);
|
identityCB.setOnClickListener(v -> {
|
if (checkedIdentityMapByPerson.containsKey(item.getId())) {
|
checkedIdentityMapByPerson.remove(item.getId());
|
} else {
|
checkedIdentityMapByPerson.put(item.getId(), item);
|
}
|
identityAdapter.notifyDataSetChanged();
|
});
|
}
|
}
|
};
|
guest_identity.setAdapter(identityAdapter);
|
}
|
|
public void checkTemporaryGuest() {
|
allIdentityListLock.lock();
|
try {
|
for (ModelAdapter identity : allIdentityList) {
|
if ("访客".equals(identity.getString(Identity.name))) {
|
checkedIdentityMapByPerson.put(identity.getString(Identity.id), identity);
|
}
|
}
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
allIdentityListLock.unlock();
|
}
|
|
public void setIdentityWithPersonInThread(String personId) {
|
BaseApplication.getApplication().executorService.execute(() -> {
|
if (!TextUtils.isEmpty(personId)) {
|
checkedIdentityMapByPerson.clear();
|
checkedIdentityMapByPerson.putAll(PersonIdentityManager.findIdentityMapByPersonId(personId));
|
} else {
|
checkTemporaryGuest();
|
}
|
notifyIdentitySetChanged();
|
});
|
}
|
|
@UiThread
|
public void notifyIdentitySetChanged() {
|
identityAdapter.notifyDataSetChanged();
|
}
|
|
@Click
|
public void respondent_org_rl() {
|
rl_show_organization.setVisibility(View.VISIBLE);
|
respondentOrgTreeAdapter.findTreeNodeList(false);
|
}
|
|
public void orgSelected(ModelAdapter org) {
|
selectedRespondentOrg = org;
|
selected_org.setText(OrgManager.getOrgFullName(org.getId()));
|
rl_show_organization.setVisibility(View.GONE);
|
((GuestModeFragment) this).loadRespondentFromDB();
|
respondent_face_CheckedId = "";
|
}
|
|
@UiThread
|
public void loadRespondentFromDBToUI() {
|
if (respondentList.size() > 0) {
|
initRespondent(null);
|
} else {
|
initRespondent(null);
|
}
|
respondentAdapter.notifyDataSetChanged();
|
}
|
|
public void loadRespondentFromDB() {
|
BaseApplication.getApplication().executorService.execute(() -> {
|
try {
|
List<ModelAdapter> personList = PersonManager.findPersonList("select * from person where "
|
+ Person.sign_up_status + "='已注册' " +
|
" and " + Person.sign_up_method + "!='访客注册' and name!='系统管理员' and " + Person.del_flag + "='0'");
|
if (selectedRespondentOrg != null) {
|
personList = PersonManager.filterByOrgId(personList, selectedRespondentOrg.getString(Org.id));
|
}
|
respondentList.clear();
|
respondentList.addAll(personList);
|
loadRespondentFromDBToUI();
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
});
|
}
|
|
public void initRespondent() {
|
respondentAdapter = new CommonAdapter<ModelAdapter>(mainActivity(), com.basic.security.utils.ResolutionAdaptation.face_view_image1(), respondentList) {
|
protected void convert(ViewHolder viewHolder, ModelAdapter item, int position) {
|
try {
|
ImageView imageView = viewHolder.getView(com.basic.security.utils.RUtils.R_id_face);
|
View face_checked = viewHolder.getView(com.basic.security.utils.RUtils.R_id_face_checked);
|
respondent_face_checkedList.add(face_checked);
|
byte[] blob = respondentList.get(position).getBlob("camera_image_path");
|
Bitmap bitmap = null;
|
ModelAdapter respondent = respondentList.get(position);
|
if (faceOneCheckedId.equals(respondent.getId())) {
|
face_checked.setVisibility(View.VISIBLE);
|
}
|
if (blob != null) {
|
try {
|
if (blob.length != 0) {
|
bitmap = BitmapFactory.decodeByteArray(blob, 0, blob.length);
|
}
|
} catch (Exception e) {
|
e.printStackTrace();
|
bitmap = BitmapFactory.decodeResource(mainActivity().getResources(), com.basic.security.utils.RUtils.R_drawable_u1280);
|
}
|
} else {
|
bitmap = BitmapFactory.decodeResource(mainActivity().getResources(), com.basic.security.utils.RUtils.R_drawable_u1280);
|
}
|
imageView.setImageBitmap(bitmap);
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
}
|
};
|
respondent_list.setAdapter(respondentAdapter);
|
respondent_list.setOnItemClickListener((parent, view, position, id) -> {
|
initRespondent(respondentList.get(position));
|
respondent_face_CheckedId = respondentList.get(position).getId();
|
for (View faceChecked : respondent_face_checkedList) {
|
faceChecked.setVisibility(View.GONE);
|
}
|
view.findViewById(com.basic.security.utils.RUtils.R_id_face_checked).setVisibility(View.VISIBLE);
|
});
|
}
|
|
public void initRespondent(ModelAdapter person) {
|
respondent = person;
|
if (person == null) {
|
Bitmap bitmap = BitmapFactory.decodeResource(mainActivity().getResources(), com.basic.security.utils.RUtils.R_drawable_nobody);
|
respondent_picture.setImageBitmap(bitmap);
|
respondent_name.setText("");
|
respondent_identity.setText("");
|
respondent_department.setText("");
|
respondent_phone.setText("");
|
guest_respondent.setText("请在右侧选择被访人");
|
guest_respondent.setTextColor(Color.parseColor("#4BA6AD"));
|
} else {
|
byte[] blob = person.getBlob("camera_image_path");
|
Bitmap bitmap = null;
|
if (blob != null) {
|
try {
|
if (blob.length != 0) {
|
bitmap = BitmapFactory.decodeByteArray(blob, 0, blob.length);
|
}
|
} catch (Exception e) {
|
e.printStackTrace();
|
bitmap = BitmapFactory.decodeResource(mainActivity().getResources(), com.basic.security.utils.RUtils.R_drawable_u1280);
|
}
|
} else {
|
if ("系统管理员".equals(person.getString(Person.name))) {
|
bitmap = BitmapFactory.decodeResource(mainActivity().getResources(), com.basic.security.utils.RUtils.R_drawable_u1280);
|
} else {
|
bitmap = BitmapFactory.decodeResource(mainActivity().getResources(), com.basic.security.utils.RUtils.R_drawable_nobody);
|
}
|
}
|
respondent_picture.setImageBitmap(bitmap);
|
guest_respondent.setText(person.getString(Person.name));
|
guest_respondent.setTextColor(Color.parseColor("#FFFFFF"));
|
respondent_name.setText(person.getString("name"));
|
String identityNames = IdentityManager.findIdentityNamesByPersonId(person.getString(Person.id));
|
respondent_identity.setText(identityNames);
|
respondent_department.setText(OrgManager.getOrgFullName(person.getString(Person.org_id)));
|
respondent_phone.setText(person.getString("phone"));
|
}
|
}
|
|
public boolean savePersonIdentity(String personId) {
|
List<String> nameList = new ArrayList<>();
|
for (ModelAdapter identityModelAdapter : checkedIdentityMapByPerson.values()) {
|
if (identityModelAdapter != null && !TextUtils.isEmpty(identityModelAdapter.getString("name"))) {
|
nameList.add(identityModelAdapter.getString("name"));
|
}
|
}
|
if (nameList.contains("黑名单") && nameList.contains("管理员")) {
|
ToastUtil.show("管理员和黑名单不能同时选中");
|
return false;
|
}
|
Map<String, ModelAdapter> dbCheckedIdentityMapByPerson = PersonIdentityManager.findIdentityMapByPersonId(personId);
|
for (String identityId : checkedIdentityMapByPerson.keySet()) {
|
if (!dbCheckedIdentityMapByPerson.containsKey(identityId)) {
|
PersonIdentityManager.save(personId, identityId);
|
if (IdentityManager.findIdentityById(identityId) != null &&
|
"管理员".equals(IdentityManager.findIdentityById(identityId).getString("name"))) {
|
PersonIdentityManager.saveAdminIdentity(personId);
|
}
|
}
|
}
|
for (String identityId : dbCheckedIdentityMapByPerson.keySet()) {
|
if (!checkedIdentityMapByPerson.containsKey(identityId)) {
|
PersonIdentityManager.delete(personId, identityId);
|
if (IdentityManager.findIdentityById(identityId) != null &&
|
"管理员".equals(IdentityManager.findIdentityById(identityId).getString("name"))) {
|
PersonIdentityManager.delAdminIdentity(personId);
|
}
|
}
|
}
|
return checkedIdentityMapByPerson.size() > 0;
|
}
|
|
@Click
|
public void guest_save(View view) {
|
if (guestFaceJpgArray == null) {
|
ToastUtil.show("请选择访客头像");
|
return;
|
}
|
BaseApplication.getApplication().executorService.execute(() -> {
|
try {
|
String personId = null;
|
boolean newPerson = false;
|
if (checkedGuest != null && !TextUtils.isEmpty(checkedGuest.getString(Guest.person_id))) {
|
personId = checkedGuest.getString(Guest.person_id);
|
newPerson = false;
|
} else {
|
newPerson = true;
|
}
|
ModelAdapter newPersonAsGuest = new ModelAdapter(BasicIdUtil.getPersonId(guestFaceFeature));
|
if (checkedPerson != null) {
|
newPersonAsGuest = checkedPerson;
|
}
|
if (!TextUtils.isEmpty(personId)) {
|
ModelAdapter person = PersonManager.findPersonById(personId);
|
if (person != null) {
|
newPersonAsGuest = person;
|
}
|
}
|
if (TextUtils.isEmpty(newPersonAsGuest.getString(Person.sign_up_method))) {
|
newPersonAsGuest.setString(Person.sign_up_method, "访客注册");
|
}
|
newPersonAsGuest.setString("table", "person");
|
String name = guest_name.getText().toString().trim();
|
if (TextUtils.isEmpty(name)) {
|
ToastUtil.show("姓名不能为空");
|
return;
|
}
|
if ("访客注册".equals(newPersonAsGuest.getString(Person.sign_up_method))) {
|
if (respondent == null) {
|
ToastUtil.show("被访人不能为空");
|
return;
|
}
|
}
|
String guestVisitValidTime = guest_visit_valid_time.getText().toString();
|
if ("访客注册".equals(newPersonAsGuest.getString(Person.sign_up_method))) {
|
if (TextUtils.isEmpty(guestVisitValidTime)) {
|
ToastUtil.show("请选择有效时间");
|
return;
|
}
|
}
|
String id_card_number = guest_id_card.getText().toString().trim();
|
if (!TextUtils.isEmpty(id_card_number)) {
|
CheckIdCard idCard = new CheckIdCard(id_card_number);
|
if (!idCard.validate()) {
|
ToastUtil.show("请输入正确的身份证号码");
|
return;
|
}
|
}
|
String phone = guest_phone.getText().toString().trim();
|
if (!TextUtils.isEmpty(phone) && !PhoneNumberCheckUtils.isPhone(phone)) {
|
ToastUtil.show("请输入正确的手机号码");
|
return;
|
}
|
savePersonIdentity(newPersonAsGuest.getId());
|
if (checkedIdentityMapByPerson.size() == 0) {
|
ToastUtil.show("请选择访客身份");
|
return;
|
}
|
String guestVisitStatus = guestVisitStatusArray[guest_visit_status.getSelectedItemPosition()];
|
newPersonAsGuest.setString(Person.guest_visit_status, guestVisitStatus);
|
byte[] cameraImageFeature = null;
|
try {
|
if (newPerson) {
|
cameraImageFeature = guestFaceFeature;
|
if (cameraImageFeature == null) {
|
cameraImageFeature = FaceId.instance.extractFeature(ModelAdapter.getAttachmentPath(newPersonAsGuest.getId(), Guest.camera_image_path, Person.tableName));
|
}
|
if (cameraImageFeature != null) {
|
String compareResultStr = FeatureManager.compareFeature(cameraImageFeature, 80);
|
String dbPersonId = compareResultStr.split(",", -1)[0];
|
if (!TextUtils.isEmpty(dbPersonId)) {
|
ModelAdapter dbPerson = PersonManager.findPersonById(dbPersonId);
|
if (dbPerson != null) {
|
newPersonAsGuest = dbPerson;
|
}
|
}
|
}
|
saveBlob(newPersonAsGuest, "camera_image_path", guestFaceJpgArray);
|
FaceId.instance.initSdk(new ContextWrapper(BaseApplication.getApplication().activity).getFilesDir().getAbsolutePath());
|
saveBlob(newPersonAsGuest, "camera_image_feature", cameraImageFeature);
|
}
|
} catch (Exception e) {
|
newPersonAsGuest.deleteAttachment(Person.camera_image_path);
|
e.printStackTrace();
|
ToastUtil.show("保存失败,请试试其他访客头像");
|
return;
|
}
|
if (checkedGuest != null && Constants.TRUE.equals(checkedGuest.getString(Guest.verified_id_card))) {
|
newPersonAsGuest.setString(Person.verify_status, "已经验证身份证");
|
}
|
newPersonAsGuest.setString(Person.phone, phone);
|
newPersonAsGuest.setString(Person.id_card_number, id_card_number);
|
if (!TextUtils.isEmpty(guestVisitValidTime)) {
|
newPersonAsGuest.setString(Person.guest_visit_valid_time, DateEditUtil1.sdf.parse(guestVisitValidTime).getTime() + "");
|
}
|
newPersonAsGuest.setString("name", name);
|
guest_saveUI(newPersonAsGuest, cameraImageFeature, newPerson);
|
} catch (Exception e) {
|
e.printStackTrace();
|
ToastUtil.show("保存失败");
|
}
|
});
|
}
|
|
@UiThread
|
public void guest_saveUI(ModelAdapter newPersonAsGuest, byte[] cameraImageFeature, boolean newPerson) {
|
String signUpRule = signUpRuleArray[guest_sign_up_rule.getSelectedItemPosition()];
|
String guestExitTime = guest_exit_time.getText().toString();
|
String visitReason = guest_reason.getText().toString().trim();
|
String remark = guest_remark.getText().toString().trim();
|
try {
|
if (!TextUtils.isEmpty(guestExitTime)) {
|
newPersonAsGuest.setString(Person.guest_exit_time, DateEditUtil1.sdf.parse(guestExitTime).getTime() + "");
|
} else {
|
newPersonAsGuest.setString(Person.guest_exit_time, "");
|
}
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
if (respondent != null) {
|
newPersonAsGuest.setString(Person.respondent_ids, respondent.getString(Person.id));
|
newPersonAsGuest.setString(Person.respondent_names, respondent.getString(Person.name));
|
}
|
if (newPerson) {
|
newPersonAsGuest.setString(Person.checked_time_rule_id, guestTimeRuleId);
|
newPersonAsGuest.setString(Person.sign_up_method, "访客注册");
|
newPersonAsGuest.setString(Person.sign_up_status, "已注册");
|
newPersonAsGuest.setString(Person.sign_up_rule, signUpRule);
|
newPersonAsGuest.setString(Person.sign_up_time, new Date().getTime() + "");
|
newPersonAsGuest.setString(Person.del_flag, "0");
|
if (cameraImageFeature != null) {
|
FeatureManager.addFeature(newPersonAsGuest.getId(), cameraImageFeature);
|
}
|
}
|
newPersonAsGuest.setString(Person.guest_remark, remark);
|
newPersonAsGuest.setString(Person.guest_enter_time, new Date().getTime() + "");
|
newPersonAsGuest.setString(Person.guest_visit_reason, visitReason);
|
newPersonAsGuest.setString(Person.update_time, new Date().getTime() + "");
|
newPersonAsGuest.setString(Person.device_id, DeviceManager.getDeviceId());
|
newPersonAsGuest.setString(Constants.TABLE, Person.tableName);
|
ToastUtil.show("保存成功 ");
|
PersonManager.savePerson(newPersonAsGuest);
|
GuestManager.updateGuest(checkedGuest, newPersonAsGuest);
|
((GuestModeFragment) this).reloadCameraOneList();
|
((GuestModeFragment) this).reloadCameraTwoList();
|
SocketUtil.rpcCallSavePerson(newPersonAsGuest);
|
}
|
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
return inflater.inflate(ResolutionAdaptation.fragment_guest_mode1(), container, false);
|
}
|
|
@Click
|
public void minus() {
|
String guest_visit_valid_timeStr = guest_visit_valid_time.getText().toString();
|
if (TextUtils.isEmpty(guest_visit_valid_timeStr)) {
|
guest_visit_valid_time.setText("0");
|
return;
|
}
|
try {
|
double guest_visit_valid_timeDouble = Double.parseDouble(guest_visit_valid_timeStr);
|
guest_visit_valid_timeDouble = guest_visit_valid_timeDouble - 0.5;
|
if (guest_visit_valid_timeDouble < 0) {
|
guest_visit_valid_timeDouble = 0;
|
}
|
guest_visit_valid_time.setText(guest_visit_valid_timeDouble + "");
|
} catch (Exception e) {
|
e.printStackTrace();
|
guest_visit_valid_time.setText("0");
|
}
|
}
|
|
@Click
|
public void plus() {
|
String guest_visit_valid_timeStr = guest_visit_valid_time.getText().toString();
|
if (TextUtils.isEmpty(guest_visit_valid_timeStr)) {
|
guest_visit_valid_time.setText("0.5");
|
return;
|
}
|
try {
|
double guest_visit_valid_timeDouble = Double.parseDouble(guest_visit_valid_timeStr);
|
guest_visit_valid_timeDouble = guest_visit_valid_timeDouble + 0.5;
|
if (guest_visit_valid_timeDouble < 0) {
|
guest_visit_valid_timeDouble = 0;
|
}
|
guest_visit_valid_time.setText(guest_visit_valid_timeDouble + "");
|
} catch (Exception e) {
|
e.printStackTrace();
|
guest_visit_valid_time.setText("0.5");
|
}
|
}
|
|
@Click
|
public void guest_visit_valid_time() {
|
if (checkedPerson == null) {
|
validTime = System.currentTimeMillis();
|
}
|
try {
|
validTime = sdf.parse(guest_visit_valid_time.getText().toString()).getTime();
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
if (validTime == 0) {
|
validTime = System.currentTimeMillis();
|
}
|
DateEditUtilForValidTime.selectTime(validTime, validTime, false, (start_time, end_time) -> {
|
validTime = start_time;
|
guest_visit_valid_time.setText(getDateString(validTime));
|
}, true);
|
}
|
|
@Click
|
public void guest_all_device() {
|
mainActivity().fragment_device_list_dialog_small.showDeviceListDialog();
|
}
|
|
public String getDateString(long time) {
|
return DateUtil.formatTime(time, "yyyy/MM/dd HH:mm");
|
}
|
|
@Click
|
public void guest_exit_time() {
|
if (exitTime == 0) {
|
exitTime = System.currentTimeMillis();
|
}
|
DateEditUtilForValidTime.selectTime(exitTime, exitTime, false, (start_time, end_time) -> {
|
exitTime = start_time;
|
guest_exit_time.setText(getDateString(exitTime));
|
});
|
}
|
|
@Click
|
public void guest_exit_time_clear() {
|
guest_exit_time.setText("");
|
}
|
|
@AfterViews
|
public void afterViews() {
|
respondent_org.setAdapter(respondentOrgTreeAdapter);
|
respondentOrgTreeAdapter.setOrgSelectedListener(this::orgSelected);
|
initRespondent();
|
initGuestGridView1();
|
initGuestGridView2();
|
camera1FaceListAdapter = new Camera1FaceListAdapter();
|
|
ArrayAdapter<String> guestSignUpRuleAdapter = new ArrayAdapter<>(getContext(), com.basic.security.utils.ResolutionAdaptation.spinner_item_small_text(), signUpRuleArray);
|
guest_sign_up_rule.setPopupBackgroundResource(com.basic.security.utils.RUtils.R_color_press_menu_text);
|
guest_sign_up_rule.setAdapter(guestSignUpRuleAdapter);
|
guest_sign_up_rule.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
register_rule = signUpRuleArray[position];
|
if (position == 1) {
|
String checkedTimeRuleId = "";
|
if (checkedGuest != null) {
|
checkedTimeRuleId = checkedGuest.getString("checked_time_rule_id");
|
}
|
if (!guest_sign_up_rule_from_init) {
|
mainActivity().fragment_time_rule_list_dialog
|
.showTimeRuleListDialog(checkedTimeRuleId, (selectedTimeRuleId) -> {
|
guestTimeRuleId = selectedTimeRuleId;
|
});
|
}
|
guest_sign_up_rule_from_init = false;
|
}
|
}
|
|
public void onNothingSelected(AdapterView<?> parent) {
|
}
|
});
|
ArrayAdapter<String> guestVisitAdapter = new ArrayAdapter<String>(getContext(), com.basic.security.utils.ResolutionAdaptation.spinner_item_small_text(), guestVisitStatusArray);
|
guest_visit_status.setPopupBackgroundResource(com.basic.security.utils.RUtils.R_color_press_menu_text);
|
guest_visit_status.setAdapter(guestVisitAdapter);
|
guest_visit_status.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
|
String guestVisitStatus = guestVisitStatusArray[position];
|
if (1 != 1) {
|
if ("访问中".equals(guestVisitStatus)) {
|
guest_exit_time.setText("");
|
}
|
if ("已离开".equals(guestVisitStatus)) {
|
guest_exit_time.setText(getDateString(System.currentTimeMillis()));
|
}
|
}
|
}
|
|
public void onNothingSelected(AdapterView<?> parent) {
|
}
|
});
|
}
|
|
public void show() {
|
super.show();
|
if (GuestManager.twoCameras()) {
|
((View) guest_list_two.getParent()).setVisibility(View.VISIBLE);
|
} else {
|
if (Constants.indoorOutdoorInOne) {
|
((View) guest_list_two.getParent()).setVisibility(View.GONE);
|
}
|
}
|
respondent_face_CheckedId = "";
|
respondentCheckedPosition = -1;
|
for (View faceChecked : respondent_face_checkedList) {
|
faceChecked.setVisibility(View.GONE);
|
}
|
faceOneCheckedPosition = -1;
|
faceOneCheckedId = "";
|
for (View faceChecked : face_one_checkedList) {
|
faceChecked.setVisibility(View.GONE);
|
}
|
faceTwoCheckedPosition = -1;
|
faceTwoCheckedId = "";
|
for (View faceChecked : face_two_checkedList) {
|
faceChecked.setVisibility(View.GONE);
|
}
|
mainActivity().fragment_camera.showCameraInGuestMode(true);
|
if (Constants.indoorOutdoorInOne) {
|
mainActivity().fragment_camera.cameraEnterGuestMode();
|
}
|
loadData = true;
|
if (loadData) {
|
loadData();
|
}
|
}
|
|
public void loadData() {
|
selectedRespondentOrg = null;
|
initRemoteDeviceCamera();
|
reloadCameraList();
|
initGuestIdentity(null);
|
selected_org.setText("组织机构");
|
loadRespondentFromDB();
|
initGuest(null);
|
respondentOrgTreeAdapter.clearUI();
|
switchToOneCameraLayout(1);
|
}
|
|
public void hide() {
|
super.hide();
|
mainActivity().fragment_camera.showCameraInGuestMode(false);
|
if (Constants.indoorOutdoorInOne) {
|
mainActivity().fragment_camera.cameraExitGuestMode();
|
}
|
}
|
|
private void initRemoteDeviceCamera() {
|
}
|
|
public void addGuestListS(DetectedResult detectedResult) {
|
if (detectedResult == null || detectedResult.facePositions == null || detectedResult.facePositions.size() == 0) {
|
return;
|
}
|
List<Map<String, String>> faces = detectedResult.facePositionsJsonS();
|
addGuestList(faces, 1, detectedResult.getFrameBitmap(), detectedResult.featureByteArrayOutputStream.toByteArray());
|
}
|
|
public void addGuestList(List<Map<String, String>> faces, int guestListCameraType, Bitmap frameImage, byte[] featureArray) {
|
if (faces == null) {
|
return;
|
}
|
int savedCount = 0;
|
for (Map<String, String> face : faces) {
|
try {
|
ModelAdapter lastGuest = GuestManager.findGuestListRecentOne(guestListCameraType);
|
String personId = face.get(FaceMessage.personId);
|
ModelAdapter guest = new ModelAdapter();
|
guest.setIdWithUuid();
|
guest.setString(Guest.camera_id, guestListCameraType + "");
|
guest.setString(Guest.create_time, System.currentTimeMillis() + "");
|
guest.setString(Constants.TABLE, Guest.tableName);
|
guest.setString(Guest.name, face.get(FaceMessage.personName));
|
guest.setString(Guest.score, face.get(FaceMessage.score));
|
String trackId = face.get(FaceMessage.track_id);
|
if (trackId == null) {
|
trackId = "";
|
}
|
guest.setString(Guest.track_id, trackId);
|
double score = Double.parseDouble(face.get(FaceMessage.score));
|
double dbScore = 0;
|
String dbTrackId = "";
|
if (lastGuest != null) {
|
dbScore = Double.parseDouble(lastGuest.getString(Guest.score));
|
dbTrackId = lastGuest.getString(Guest.track_id);
|
}
|
if (Constants.TRUE.equals(face.get(FaceMessage.verifiedIdCard))) {
|
guest.setString(Guest.verified_id_card, Constants.TRUE);
|
String idCardNumber = face.get(FaceMessage.idCardNumber);
|
if (!TextUtils.isEmpty(idCardNumber)) {
|
guest.setString(Guest.id_card_number, idCardNumber);
|
}
|
} else {
|
guest.setString(Guest.verified_id_card, Constants.FALSE);
|
}
|
if (TextUtils.isEmpty(personId)) {
|
guest.setString(Guest.person_id, "");
|
String featureData = face.get(FaceMessage.featureData);
|
String photoData = face.get(FaceMessage.photoData);
|
if (!Constants.TRUE.equals(face.get(FaceMessage.verifiedIdCard))) {
|
if (lastGuest != null && trackId.equals(dbTrackId) && score < dbScore) {
|
continue;
|
}
|
}
|
try {
|
if (featureArray != null && featureArray.length > 0) {
|
String featureIndexStr = face.get(FaceMessage.featureIndex);
|
int start = Integer.parseInt(featureIndexStr.split(",")[0]);
|
int end = Integer.parseInt(featureIndexStr.split(",")[1]);
|
byte[] feature = new byte[]{};
|
if (featureArray.length == end) {
|
feature = featureArray;
|
} else {
|
if (end < featureArray.length) {
|
feature = Arrays.copyOfRange(featureArray, start, end);
|
}
|
}
|
try {
|
if (!Constants.TRUE.equals(face.get(FaceMessage.verifiedIdCard))) {
|
if (lastGuest != null) {
|
byte[] lastGuestByteArray = lastGuest.getBlob(Guest.camera_image_feature);
|
if (lastGuestByteArray != null) {
|
double compareFeatureScore = FaceId.instance.compareFeature(feature, lastGuestByteArray);
|
if (compareFeatureScore > 80 && score <= dbScore) {
|
continue;
|
}
|
}
|
}
|
}
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
guest.setBlob(Guest.camera_image_feature, feature);
|
}
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
} else {
|
if (lastGuest != null && personId.equals(lastGuest.getString(Guest.person_id))) {
|
continue;
|
}
|
guest.setString(Guest.person_id, personId);
|
}
|
int x1 = Integer.parseInt(face.get(FaceMessage.x1));
|
int x2 = Integer.parseInt(face.get(FaceMessage.x2));
|
int y1 = Integer.parseInt(face.get(FaceMessage.y1));
|
int y2 = Integer.parseInt(face.get(FaceMessage.y2));
|
Bitmap faceBitmap = Bitmap.createBitmap(frameImage, x1, y1, x2 - x1, y2 - y1);
|
jpgBaos.reset();
|
faceBitmap.compress(Bitmap.CompressFormat.JPEG, 100, jpgBaos);
|
try {
|
byte[] faceByteArray = jpgBaos.toByteArray();
|
ImageFormat mimeType = Imaging.guessFormat(faceByteArray);
|
if (mimeType != ImageFormats.JPEG) {
|
continue;
|
}
|
guest.setBlob(Guest.camera_image_path, faceByteArray);
|
} catch (Exception e) {
|
System1.out.println("GuestModeFragment.addGuestList " + e.getMessage());
|
continue;
|
}
|
savedCount++;
|
GuestManager.saveGuest(guest);
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
}
|
if (savedCount > 0) {
|
guestListLock.lock();
|
if (guestListCameraType == 1) {
|
reloadCameraOneList();
|
}
|
if (guestListCameraType == 2) {
|
reloadCameraTwoList();
|
}
|
guestListLock.unlock();
|
}
|
}
|
|
public void reloadCameraList() {
|
BaseApplication.getApplication().executorService.execute(() -> {
|
guestListLock.lock();
|
notifyDataSetChangedInListOne(GuestManager.findGuestList("1"));
|
notifyDataSetChangedInListTwo(GuestManager.findGuestList("2"));
|
guestListLock.unlock();
|
});
|
}
|
|
public void reloadCameraOneList() {
|
BaseApplication.getApplication().executorService.execute(() -> {
|
guestListLock.lock();
|
notifyDataSetChangedInListOne(GuestManager.findGuestList("1"));
|
guestListLock.unlock();
|
});
|
}
|
|
public void reloadCameraTwoList() {
|
BaseApplication.getApplication().executorService.execute(() -> {
|
guestListLock.lock();
|
notifyDataSetChangedInListTwo(GuestManager.findGuestList("2"));
|
guestListLock.unlock();
|
});
|
}
|
|
@UiThread
|
public void notifyDataSetChangedInListTwo(List<ModelAdapter> camera2GuestList) {
|
if (camera2GuestList != null) {
|
this.camera2GuestList.clear();
|
this.camera2GuestList.addAll(camera2GuestList);
|
try {
|
for (View face_checked1 : face_two_checkedList) {
|
face_checked1.setVisibility(View.GONE);
|
}
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
guest_list_two_data.clear();
|
guest_list_two_data.addAll(camera2GuestList);
|
}
|
guest_list_two_adapter.notifyDataSetChanged();
|
camera1FaceListAdapter.notifyDataSetChanged();
|
}
|
|
@UiThread
|
public void notifyDataSetChangedInListOne(List<ModelAdapter> camera1GuestList) {
|
if (camera1GuestList != null) {
|
this.camera1GuestList.clear();
|
this.camera1GuestList.addAll(camera1GuestList);
|
try {
|
for (View face_checked1 : face_one_checkedList) {
|
face_checked1.setVisibility(View.GONE);
|
}
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
guest_list_one_data.clear();
|
guest_list_one_data.addAll(camera1GuestList);
|
}
|
guest_list_one_adapter.notifyDataSetChanged();
|
camera1FaceListAdapter.notifyDataSetChanged();
|
}
|
|
@Click
|
public void cancel() {
|
rl_show_organization.setVisibility(View.GONE);
|
}
|
|
@Click
|
void next() {
|
int position = guest_identity.getFirstVisiblePosition();
|
if (position + 2 > allIdentityList.size()) {
|
position = allIdentityList.size();
|
} else {
|
position += 2;
|
}
|
guest_identity.setSelection(position);
|
}
|
|
@UiThread
|
public void switchToTwoCameraLayout() {
|
guest_list_one.setNumColumns(3);
|
guest_list_one.setVisibility(View.VISIBLE);
|
if (!Constants.landscape) {
|
if (mainActivity.currentFragment == this) {
|
Set<View> fragment_guest_mode_border_set = mainActivity.backgroundAndBorderViews.get(mainActivity.fragment_guest_mode);
|
BackgroundAndBorderFragment background_and_border_fragment = mainActivity().fragment_background_and_border;
|
synchronized (fragment_guest_mode_border_set_lock) {
|
fragment_guest_mode_border_set.remove(background_and_border_fragment.topBackground5);
|
fragment_guest_mode_border_set.remove(background_and_border_fragment.topBlurView5);
|
fragment_guest_mode_border_set.add(background_and_border_fragment.topBackground5_left);
|
fragment_guest_mode_border_set.add(background_and_border_fragment.topBlurView5_left);
|
fragment_guest_mode_border_set.add(background_and_border_fragment.topBackground5_right);
|
fragment_guest_mode_border_set.add(background_and_border_fragment.topBlurView5_right);
|
}
|
background_and_border_fragment.topBackground5_left.setVisibility(View.VISIBLE);
|
background_and_border_fragment.topBlurView5_left.setVisibility(View.VISIBLE);
|
background_and_border_fragment.topBackground5_right.setVisibility(View.VISIBLE);
|
background_and_border_fragment.topBlurView5_right.setVisibility(View.VISIBLE);
|
background_and_border_fragment.topBackground5.setVisibility(View.GONE);
|
background_and_border_fragment.topBlurView5.setVisibility(View.GONE);
|
}
|
}
|
}
|
|
@UiThread
|
public void switchToOneCameraLayout(int cameraIndex) {
|
try {
|
if (cameraIndex == 1) {
|
guest_list_one.setNumColumns(6);
|
guest_list_one.setVisibility(View.VISIBLE);
|
} else {
|
guest_list_one.setVisibility(View.GONE);
|
}
|
if (Constants.landscape) {
|
} else {
|
if (mainActivity.currentFragment == this) {
|
Set<View> fragment_guest_mode_border_set = mainActivity.backgroundAndBorderViews.get(mainActivity.fragment_guest_mode);
|
BackgroundAndBorderFragment background_and_border_fragment = mainActivity().fragment_background_and_border;
|
synchronized (fragment_guest_mode_border_set_lock) {
|
fragment_guest_mode_border_set.remove(background_and_border_fragment.topBackground5_left);
|
fragment_guest_mode_border_set.remove(background_and_border_fragment.topBlurView5_left);
|
fragment_guest_mode_border_set.remove(background_and_border_fragment.topBackground5_right);
|
fragment_guest_mode_border_set.remove(background_and_border_fragment.topBlurView5_right);
|
fragment_guest_mode_border_set.add(background_and_border_fragment.topBackground5);
|
fragment_guest_mode_border_set.add(background_and_border_fragment.topBlurView5);
|
}
|
background_and_border_fragment.topBackground5_left.setVisibility(View.GONE);
|
background_and_border_fragment.topBlurView5_left.setVisibility(View.GONE);
|
background_and_border_fragment.topBackground5_right.setVisibility(View.GONE);
|
background_and_border_fragment.topBlurView5_right.setVisibility(View.GONE);
|
background_and_border_fragment.topBackground5.setVisibility(View.VISIBLE);
|
background_and_border_fragment.topBlurView5.setVisibility(View.VISIBLE);
|
}
|
}
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
}
|
|
public class Camera1FaceListAdapter extends BaseAdapter {
|
public int getCount() {
|
return camera1GuestList == null ? 0 : camera1GuestList.size();
|
}
|
|
public Object getItem(int position) {
|
return camera1GuestList.get(position);
|
}
|
|
public long getItemId(int position) {
|
return position;
|
}
|
|
public View getView(int position, View convertView, ViewGroup parent) {
|
ViewHolder viewHolder;
|
if (convertView == null) {
|
convertView = LayoutInflater.from(getContext()).inflate(com.basic.security.utils.ResolutionAdaptation.face_view_image(), null);
|
viewHolder = new ViewHolder();
|
viewHolder.imageView = convertView.findViewById(com.basic.security.utils.RUtils.R_id_face);
|
convertView.setTag(viewHolder);
|
} else {
|
viewHolder = (ViewHolder) convertView.getTag();
|
}
|
byte[] blob = camera1GuestList.get(position).getBlob("camera_image_path");
|
Bitmap bitmap = null;
|
if (blob != null) {
|
try {
|
if (blob.length != 0) {
|
bitmap = BitmapFactory.decodeByteArray(blob, 0, blob.length);
|
}
|
} catch (Exception e) {
|
e.printStackTrace();
|
bitmap = BitmapFactory.decodeResource(mainActivity().getResources(), com.basic.security.utils.RUtils.R_drawable_u1280);
|
}
|
} else {
|
bitmap = BitmapFactory.decodeResource(mainActivity().getResources(), com.basic.security.utils.RUtils.R_drawable_u1280);
|
}
|
viewHolder.imageView.setImageBitmap(bitmap);
|
return convertView;
|
}
|
|
class ViewHolder {
|
ImageView imageView;
|
}
|
}
|
}
|